Repository: ambari Updated Branches: refs/heads/trunk ac290e259 -> d6a4a68d0
AMBARI-7318. ClusterHostInfo host indexes should be hostnames in download client configs (dlysnichenko) Project: http://git-wip-us.apache.org/repos/asf/ambari/repo Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/d6a4a68d Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/d6a4a68d Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/d6a4a68d Branch: refs/heads/trunk Commit: d6a4a68d0fbf0d076b201e4b4d635330dab530b8 Parents: ac290e2 Author: Lisnichenko Dmitro <dlysniche...@hortonworks.com> Authored: Wed Sep 17 16:54:31 2014 +0300 Committer: Lisnichenko Dmitro <dlysniche...@hortonworks.com> Committed: Wed Sep 17 16:54:31 2014 +0300 ---------------------------------------------------------------------- .../internal/ClientConfigResourceProvider.java | 35 ++++++++++++++++++-- .../ClientConfigResourceProviderTest.java | 24 ++++++++++---- 2 files changed, 49 insertions(+), 10 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ambari/blob/d6a4a68d/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ClientConfigResourceProvider.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ClientConfigResourceProvider.java b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ClientConfigResourceProvider.java index 366b5e1..34f4d6f 100644 --- a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ClientConfigResourceProvider.java +++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ClientConfigResourceProvider.java @@ -18,7 +18,6 @@ package org.apache.ambari.server.controller.internal; import com.google.gson.Gson; -import com.google.inject.Inject; import com.google.inject.assistedinject.Assisted; import com.google.inject.assistedinject.AssistedInject; import com.google.inject.persist.Transactional; @@ -213,6 +212,7 @@ public class ClientConfigResourceProvider extends AbstractControllerResourceProv clusterHostInfo = StageUtils.getClusterHostInfo(managementController.getClusters().getHostsForCluster(cluster.getClusterName()), cluster); serviceInfo = managementController.getAmbariMetaInfo().getServiceInfo(stackId.getStackName(), stackId.getStackVersion(), serviceName); + clusterHostInfo = substituteHostIndexes(clusterHostInfo); osFamily = clusters.getHost(hostName).getOsFamily(); TreeMap<String, String> hostLevelParams = new TreeMap<String, String>(); @@ -248,11 +248,11 @@ public class ClientConfigResourceProvider extends AbstractControllerResourceProv } String packageList = gson.toJson(packages); hostLevelParams.put(PACKAGE_LIST, packageList); - + Set<String> userSet = configHelper.getPropertyValuesWithPropertyType(stackId, PropertyType.USER, cluster); String userList = gson.toJson(userSet); hostLevelParams.put(USER_LIST, userList); - + Set<String> groupSet = configHelper.getPropertyValuesWithPropertyType(stackId, PropertyType.GROUP, cluster); String groupList = gson.toJson(groupSet); hostLevelParams.put(GROUP_LIST, groupList); @@ -324,6 +324,35 @@ public class ClientConfigResourceProvider extends AbstractControllerResourceProv return resources; } + private static Map<String, Set<String>> substituteHostIndexes(Map<String, Set<String>> clusterHostInfo) throws SystemException { + Set<String> keysToSkip = new HashSet<String>(Arrays.asList("all_hosts", "all_ping_ports", + "ambari_server_host")); + String[] allHosts = {}; + if (clusterHostInfo.get("all_hosts") != null) { + allHosts = clusterHostInfo.get("all_hosts").toArray(new String[clusterHostInfo.get("all_hosts").size()]); + } + Set<String> keys = clusterHostInfo.keySet(); + for (String key : keys) { + if (keysToSkip.contains(key)) { + continue; + } + Set<String> hosts = new HashSet<String>(); + Set<String> currentHostsIndexes = clusterHostInfo.get(key); + if (currentHostsIndexes == null) { + continue; + } + for (String hostIndex : currentHostsIndexes) { + try { + hosts.add(allHosts[Integer.parseInt(hostIndex)]); + } catch (ArrayIndexOutOfBoundsException ex) { + throw new SystemException("Failed to fill cluster host info ", ex); + } + } + clusterHostInfo.put(key, hosts); + } + return clusterHostInfo; + } + @Override public RequestStatus updateResources(final Request request, Predicate predicate) throws SystemException, UnsupportedPropertyException, NoSuchResourceException, NoSuchParentResourceException { http://git-wip-us.apache.org/repos/asf/ambari/blob/d6a4a68d/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ClientConfigResourceProviderTest.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ClientConfigResourceProviderTest.java b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ClientConfigResourceProviderTest.java index 214bf10..916e0de 100644 --- a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ClientConfigResourceProviderTest.java +++ b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ClientConfigResourceProviderTest.java @@ -26,6 +26,7 @@ import org.apache.ambari.server.controller.utilities.PredicateBuilder; import org.apache.ambari.server.controller.utilities.PropertyHelper; import org.apache.ambari.server.state.*; import org.apache.ambari.server.state.PropertyInfo; +import org.apache.ambari.server.utils.StageUtils; import org.easymock.EasyMock; import org.junit.Assert; import org.junit.Test; @@ -36,6 +37,7 @@ import org.powermock.modules.junit4.PowerMockRunner; import java.io.File; import java.io.PrintWriter; +import java.lang.reflect.Method; import java.util.*; import static org.easymock.EasyMock.*; @@ -44,7 +46,7 @@ import static org.easymock.EasyMock.*; * TaskResourceProvider tests. */ @RunWith(PowerMockRunner.class) -@PrepareForTest( {ClientConfigResourceProvider.class} ) +@PrepareForTest( {ClientConfigResourceProvider.class, StageUtils.class} ) public class ClientConfigResourceProviderTest { @Test public void testCreateResources() throws Exception { @@ -218,17 +220,29 @@ public class ClientConfigResourceProviderTest { expect(clusterConfig.getType()).andReturn(Configuration.HIVE_CONFIG_TAG).anyTimes(); expect(configHelper.getEffectiveConfigAttributes(cluster, configTags)).andReturn(attributes); expect(configuration.getProperty("server.tmp.dir")).andReturn(Configuration.SERVER_TMP_DIR_DEFAULT); - //!!!! Map<String,String> props = new HashMap<String, String>(); props.put(Configuration.HIVE_METASTORE_PASSWORD_PROPERTY, "pass"); props.put("key","value"); expect(clusterConfig.getProperties()).andReturn(props); expect(configHelper.getEffectiveDesiredTags(cluster, hostName)).andReturn(allConfigTags); - //!!!! expect(cluster.getClusterName()).andReturn(clusterName); expect(managementController.getHostComponents((Set<ServiceComponentHostRequest>) anyObject())).andReturn(responses).anyTimes(); expect(cluster.getCurrentStackVersion()).andReturn(stackId); + PowerMock.mockStaticPartial(StageUtils.class, "getClusterHostInfo"); + Map<String, Set<String>> clusterHostInfo = new HashMap<String, Set<String>>(); + Set<String> all_hosts = new HashSet<String>(Arrays.asList("Host100","Host101","Host102")); + Set<String> some_hosts = new HashSet<String>(Arrays.asList("0","2")); + Set<String> clusterHostTypes = new HashSet<String>(Arrays.asList("nm_hosts", "hs_host", + "namenode_host", "rm_host", "snamenode_host", "slave_hosts", "zookeeper_hosts")); + for (String hostTypes: clusterHostTypes) { + clusterHostInfo.put(hostTypes,some_hosts); + } + Map<String, Host> stringHostMap = new HashMap<String, Host>(); + stringHostMap.put(hostName, host); + clusterHostInfo.put("all_hosts",all_hosts); + expect(StageUtils.getClusterHostInfo(stringHostMap,cluster)).andReturn(clusterHostInfo); + expect(stackId.getStackName()).andReturn(stackName).anyTimes(); expect(stackId.getStackVersion()).andReturn(stackVersion).anyTimes(); @@ -242,10 +256,6 @@ public class ClientConfigResourceProviderTest { expect(ambariMetaInfo.getStackRoot()).andReturn(new File(stackRoot)); expect(cluster.getAllConfigs()).andReturn(clusterConfigs); expect(clusters.getHostsForCluster(clusterName)).andReturn(hosts); - expect(cluster.getServices()).andReturn(services); - expect(service.getServiceComponents()).andReturn(serviceComponentMap); - expect(serviceComponent.getName()).andReturn(componentName); - expect(serviceComponent.getServiceComponentHosts()).andReturn(serviceComponentHosts); expect(clusters.getHost(hostName)).andReturn(host); HashMap<String, String> rcaParams = new HashMap<String, String>();