Updated Branches: refs/heads/branch-1.4.3 0d0291bc9 -> 106deef1f
AMBARI-4224. When issuing Start/Stop of host components then predicate stale_config=true does not work Project: http://git-wip-us.apache.org/repos/asf/ambari/repo Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/106deef1 Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/106deef1 Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/106deef1 Branch: refs/heads/branch-1.4.3 Commit: 106deef1f5d989a7e0c888ea8c5517aa4c4e1a2b Parents: 0d0291b Author: Sumit Mohanty <[email protected]> Authored: Fri Jan 3 15:12:50 2014 -0800 Committer: Sumit Mohanty <[email protected]> Committed: Fri Jan 3 15:12:50 2014 -0800 ---------------------------------------------------------------------- .../AmbariManagementControllerImpl.java | 9 ++- .../AmbariManagementControllerTest.java | 83 ++++++++++++-------- 2 files changed, 55 insertions(+), 37 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ambari/blob/106deef1/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariManagementControllerImpl.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariManagementControllerImpl.java b/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariManagementControllerImpl.java index 0435322..29140f3 100644 --- a/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariManagementControllerImpl.java +++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariManagementControllerImpl.java @@ -678,6 +678,9 @@ public class AmbariManagementControllerImpl implements continue; } ServiceComponentHostResponse r = sch.convertToResponse(); + if (filterBasedConfigStaleness && r.isStaleConfig() != staleConfig) { + continue; + } response.add(r); } catch (ServiceComponentHostNotFoundException e) { if (request.getServiceName() != null && request.getComponentName() != null) { @@ -957,9 +960,9 @@ public class AmbariManagementControllerImpl implements ArrayList<ServiceComponentHost>(); if (changedScHosts != null && !changedScHosts.isEmpty()) { for (String sc : changedScHosts.keySet()) { - for (State s : changedScHosts.get(sc).keySet()) - if (s == State.STARTED) { - serviceComponentHosts.addAll(changedScHosts.get(sc).get(s)); + for (State state : changedScHosts.get(sc).keySet()) + if (state == State.STARTED) { + serviceComponentHosts.addAll(changedScHosts.get(sc).get(state)); } } } http://git-wip-us.apache.org/repos/asf/ambari/blob/106deef1/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerTest.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerTest.java b/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerTest.java index aba1140..552a669 100644 --- a/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerTest.java +++ b/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerTest.java @@ -2103,11 +2103,17 @@ public class AmbariManagementControllerTest { } @Test - public void testGetServiceComponentHostsWithFilter() throws AmbariException { + public void testGetServiceComponentHostsWithStaleConfigFilter() throws AmbariException { + + final String host1 = "h1"; + final String host2 = "h2"; String clusterName = "foo1"; - createCluster(clusterName); - clusters.getCluster(clusterName) - .setDesiredStackVersion(new StackId("HDP-2.0.5")); + setupClusterWithHosts(clusterName, "HDP-2.0.5", + new ArrayList<String>() {{ + add(host1); + add(host2); + }}, + "centos5"); String serviceName = "HDFS"; createService(clusterName, serviceName, null); String componentName1 = "NAMENODE"; @@ -2121,20 +2127,16 @@ public class AmbariManagementControllerTest { createServiceComponent(clusterName, serviceName, componentName3, State.INIT); - String host1 = "h1"; - clusters.addHost(host1); - clusters.getHost("h1").setOsType("centos5"); - clusters.getHost("h1").setState(HostState.HEALTHY); - clusters.getHost("h1").persist(); - - clusters.mapHostToCluster(host1, clusterName); - createServiceComponentHost(clusterName, serviceName, componentName1, host1, null); createServiceComponentHost(clusterName, serviceName, componentName2, host1, null); createServiceComponentHost(clusterName, serviceName, componentName3, host1, null); + createServiceComponentHost(clusterName, serviceName, componentName2, + host2, null); + createServiceComponentHost(clusterName, serviceName, componentName3, + host2, null); // Install installService(clusterName, serviceName, false, false); @@ -2144,7 +2146,7 @@ public class AmbariManagementControllerTest { configs.put("a", "b"); ConfigurationRequest cr1; - cr1 = new ConfigurationRequest(clusterName, "hdfs-site","version1", + cr1 = new ConfigurationRequest(clusterName, "hdfs-site", "version1", configs); ClusterRequest crReq = new ClusterRequest(null, clusterName, null, null); crReq.setDesiredConfig(cr1); @@ -2154,47 +2156,60 @@ public class AmbariManagementControllerTest { startService(clusterName, serviceName, false, false); //Update actual config + HashMap<String, Map<String, String>> actualConfig = new HashMap<String, Map<String, String>>() {{ + put("hdfs-site", new HashMap<String, String>() {{ + put("tag", "version1"); + }}); + }}; + HashMap<String, Map<String, String>> actualConfigOld = new + HashMap<String, Map<String, String>>() {{ + put("hdfs-site", new HashMap<String, String>() {{ + put("tag", "version0"); + }}); + }}; + Service s1 = clusters.getCluster(clusterName).getService(serviceName); - ServiceComponentHost sch1 = s1.getServiceComponent(componentName1) - .getServiceComponentHost(host1); - ServiceComponentHost sch2 = s1.getServiceComponent(componentName2) - .getServiceComponentHost(host1); - ServiceComponentHost sch3 = s1.getServiceComponent(componentName3) - .getServiceComponentHost(host1); - sch1.updateActualConfigs(new HashMap<String, Map<String,String>>() {{ - put("hdfs-site", new HashMap<String,String>() {{ put("tag", "version1"); }}); - }}); - sch2.updateActualConfigs(new HashMap<String, Map<String,String>>() {{ - put("hdfs-site", new HashMap<String,String>() {{ put("tag", "version1"); }}); - }}); - sch3.updateActualConfigs(new HashMap<String, Map<String,String>>() {{ - put("hdfs-site", new HashMap<String,String>() {{ put("tag", "version2"); }}); - }}); + s1.getServiceComponent(componentName1).getServiceComponentHost(host1).updateActualConfigs(actualConfig); + s1.getServiceComponent(componentName2).getServiceComponentHost(host1).updateActualConfigs(actualConfig); + s1.getServiceComponent(componentName3).getServiceComponentHost(host1).updateActualConfigs(actualConfigOld); + s1.getServiceComponent(componentName2).getServiceComponentHost(host2).updateActualConfigs(actualConfigOld); + s1.getServiceComponent(componentName3).getServiceComponentHost(host2).updateActualConfigs(actualConfig); ServiceComponentHostRequest r = new ServiceComponentHostRequest(clusterName, null, null, null, null); Set<ServiceComponentHostResponse> resps = controller.getHostComponents(Collections.singleton(r)); - Assert.assertEquals(3, resps.size()); + Assert.assertEquals(5, resps.size()); //Get all host components with stale config = true r = new ServiceComponentHostRequest(clusterName, null, null, null, null); r.setStaleConfig("true"); resps = controller.getHostComponents(Collections.singleton(r)); - Assert.assertEquals(1, resps.size()); + Assert.assertEquals(2, resps.size()); //Get all host components with stale config = false r = new ServiceComponentHostRequest(clusterName, null, null, null, null); r.setStaleConfig("false"); resps = controller.getHostComponents(Collections.singleton(r)); + Assert.assertEquals(3, resps.size()); + + //Get all host components with stale config = false and hostname filter + r = new ServiceComponentHostRequest(clusterName, null, null, host1, null); + r.setStaleConfig("false"); + resps = controller.getHostComponents(Collections.singleton(r)); Assert.assertEquals(2, resps.size()); - } + //Get all host components with stale config = false and hostname filter + r = new ServiceComponentHostRequest(clusterName, null, null, host2, null); + r.setStaleConfig("true"); + resps = controller.getHostComponents(Collections.singleton(r)); + Assert.assertEquals(1, resps.size()); + } private Cluster setupClusterWithHosts(String clusterName, String stackId, List<String> hosts, - String osType) throws AmbariException { - clusters.addCluster(clusterName); + String osType) throws AmbariException { + ClusterRequest r = new ClusterRequest(null, clusterName, stackId, null); + controller.createCluster(r); Cluster c1 = clusters.getCluster(clusterName); - c1.setDesiredStackVersion(new StackId(stackId)); for (String host : hosts) { clusters.addHost(host); clusters.getHost(host).setOsType(osType);
