This is an automated email from the ASF dual-hosted git repository. rnettleton pushed a commit to branch trunk in repository https://gitbox.apache.org/repos/asf/ambari.git
The following commit(s) were added to refs/heads/trunk by this push: new ab70364 [AMBARI-24059] Ambari Views auto create instance should support matching to all known stacks (#1502) ab70364 is described below commit ab70364cf6432f71952f36d012e16cb2373f9a94 Author: Robert Nettleton <rnettle...@hortonworks.com> AuthorDate: Mon Jun 11 14:08:52 2018 -0400 [AMBARI-24059] Ambari Views auto create instance should support matching to all known stacks (#1502) * [AMBARI-24059] Ambari Views auto create instance should support matching to all known stacks * Updating after review comments. --- .../apache/ambari/server/view/ViewRegistry.java | 6 ++++ .../ambari/server/view/ViewRegistryTest.java | 35 ++++++++++++++++++---- 2 files changed, 35 insertions(+), 6 deletions(-) diff --git a/ambari-server/src/main/java/org/apache/ambari/server/view/ViewRegistry.java b/ambari-server/src/main/java/org/apache/ambari/server/view/ViewRegistry.java index 138ebcd..cd871b3 100644 --- a/ambari-server/src/main/java/org/apache/ambari/server/view/ViewRegistry.java +++ b/ambari-server/src/main/java/org/apache/ambari/server/view/ViewRegistry.java @@ -1136,6 +1136,12 @@ public class ViewRegistry { String configStackId = autoConfig.getStackId(); if (configStackId != null) { + if (configStackId.equals("*")) { + // always return true when the auto-instance is configured to match + // against all stacks + return true; + } + StackId id = new StackId(configStackId); if (id.getStackName().equals(stackId.getStackName())) { diff --git a/ambari-server/src/test/java/org/apache/ambari/server/view/ViewRegistryTest.java b/ambari-server/src/test/java/org/apache/ambari/server/view/ViewRegistryTest.java index a28d419..7703aaf 100644 --- a/ambari-server/src/test/java/org/apache/ambari/server/view/ViewRegistryTest.java +++ b/ambari-server/src/test/java/org/apache/ambari/server/view/ViewRegistryTest.java @@ -198,6 +198,17 @@ public class ViewRegistryTest { " </auto-instance>\n" + "</view>"; + private static final String AUTO_VIEW_WILD_ALL_STACKS_XML = "<view>\n" + + " <name>MY_VIEW</name>\n" + + " <label>My View!</label>\n" + + " <version>1.0.0</version>\n" + + " <auto-instance>\n" + + " <name>AUTO-INSTANCE</name>\n" + + " <stack-id>*</stack-id>\n" + + " <services><service>HIVE</service><service>HDFS</service></services>\n" + + " </auto-instance>\n" + + "</view>"; + private static final String AUTO_VIEW_BAD_STACK_XML = "<view>\n" + " <name>MY_VIEW</name>\n" + " <label>My View!</label>\n" + @@ -209,6 +220,8 @@ public class ViewRegistryTest { " </auto-instance>\n" + "</view>"; + private static final String EXPECTED_HDP_2_0_STACK_NAME = "HDP-2.0"; + // registry mocks private static final ViewDAO viewDAO = createMock(ViewDAO.class); private static final ViewInstanceDAO viewInstanceDAO = createNiceMock(ViewInstanceDAO.class); @@ -226,6 +239,7 @@ public class ViewRegistryTest { private static final Clusters clusters = createNiceMock(Clusters.class); + @Before public void resetGlobalMocks() { ViewRegistry.initInstance(getRegistry(viewInstanceOperationHandler, viewDAO, viewInstanceDAO, userDAO, memberDAO, privilegeDAO, @@ -1347,7 +1361,7 @@ public class ViewRegistryTest { serviceNames.add("HDFS"); serviceNames.add("HIVE"); - testOnAmbariEventServiceCreation(AUTO_VIEW_XML, serviceNames, true); + testOnAmbariEventServiceCreation(AUTO_VIEW_XML, serviceNames, EXPECTED_HDP_2_0_STACK_NAME,true); } @Test @@ -1356,7 +1370,16 @@ public class ViewRegistryTest { serviceNames.add("HDFS"); serviceNames.add("HIVE"); - testOnAmbariEventServiceCreation(AUTO_VIEW_WILD_STACK_XML, serviceNames, true); + testOnAmbariEventServiceCreation(AUTO_VIEW_WILD_STACK_XML, serviceNames, EXPECTED_HDP_2_0_STACK_NAME,true); + } + + @Test + public void testOnAmbariEventServiceCreation_widcardAllStacks() throws Exception { + Set<String> serviceNames = new HashSet<>(); + serviceNames.add("HDFS"); + serviceNames.add("HIVE"); + + testOnAmbariEventServiceCreation(AUTO_VIEW_WILD_ALL_STACKS_XML, serviceNames, "HDF-3.1", true); } @Test @@ -1365,7 +1388,7 @@ public class ViewRegistryTest { serviceNames.add("HDFS"); serviceNames.add("HIVE"); - testOnAmbariEventServiceCreation(AUTO_VIEW_BAD_STACK_XML, serviceNames, false); + testOnAmbariEventServiceCreation(AUTO_VIEW_BAD_STACK_XML, serviceNames, EXPECTED_HDP_2_0_STACK_NAME, false); } @Test @@ -1374,7 +1397,7 @@ public class ViewRegistryTest { serviceNames.add("STORM"); serviceNames.add("HIVE"); - testOnAmbariEventServiceCreation(AUTO_VIEW_XML, serviceNames, false); + testOnAmbariEventServiceCreation(AUTO_VIEW_XML, serviceNames, EXPECTED_HDP_2_0_STACK_NAME, false); } @Test @@ -1879,7 +1902,7 @@ public class ViewRegistryTest { return viewInstanceDefinition; } - private void testOnAmbariEventServiceCreation(String xml, Set<String> serviceNames, boolean success) throws Exception { + private void testOnAmbariEventServiceCreation(String xml, Set<String> serviceNames, String stackName, boolean success) throws Exception { ViewConfig config = ViewConfigTest.getConfig(xml); ViewEntity viewDefinition = ViewEntityTest.getViewEntity(config); @@ -1890,7 +1913,7 @@ public class ViewRegistryTest { ViewInstanceEntity viewInstanceEntity = createNiceMock(ViewInstanceEntity.class); Cluster cluster = createNiceMock(Cluster.class); Service service = createNiceMock(Service.class); - StackId stackId = new StackId("HDP-2.0"); + StackId stackId = new StackId(stackName); Map<String, Service> serviceMap = new HashMap<>(); -- To stop receiving notification emails like this one, please contact rnettle...@apache.org.