ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nc...@apache.org
Subject [16/23] ambari git commit: AMBARI-14593. Ambari not showing active/standby status for Resource manager when custom ports are used (dlysnichenko)
Date Mon, 11 Jan 2016 14:38:52 GMT
AMBARI-14593. Ambari not showing active/standby status for Resource manager when custom ports
are used (dlysnichenko)


Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/35073a28
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/35073a28
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/35073a28

Branch: refs/heads/branch-dev-patch-upgrade
Commit: 35073a28173e89004fb0a4347d4150b5c169122e
Parents: c76a47a
Author: Lisnichenko Dmitro <dlysnichenko@hortonworks.com>
Authored: Mon Jan 11 15:17:52 2016 +0200
Committer: Lisnichenko Dmitro <dlysnichenko@hortonworks.com>
Committed: Mon Jan 11 15:19:10 2016 +0200

----------------------------------------------------------------------
 .../internal/HttpProxyPropertyProvider.java     | 58 ++++++++++++++++++--
 .../internal/HttpPropertyProviderTest.java      | 56 ++++++++++++++++++-
 2 files changed, 107 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/35073a28/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/HttpProxyPropertyProvider.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/HttpProxyPropertyProvider.java
b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/HttpProxyPropertyProvider.java
index 302a54b..e92536c 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/HttpProxyPropertyProvider.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/HttpProxyPropertyProvider.java
@@ -65,8 +65,18 @@ public class HttpProxyPropertyProvider extends BaseProvider implements
PropertyP
   private static final String PROPERTY_YARN_HTTP_POLICY_VALUE_HTTPS_ONLY = "HTTPS_ONLY";
   private static final String PROPERTY_HADOOP_SSL_ENABLED_VALUE_TRUE = "true";
 
+
+  private static final String PROPERTY_RESOURCEMANAGER_WEBAPP_ADDRESS = "yarn.resourcemanager.webapp.address";
+  private static final String PROPERTY_RESOURCEMANAGER_WEBAPP_HTTPS_ADDRESS = "yarn.resourcemanager.webapp.https.address";
+  // resource manager HA properties
+
+  private static final String PROPERTY_RESOURCEMANAGER_HA_RM_IDS = "yarn.resourcemanager.ha.rm-ids";
+  private static final String PROPERTY_RESOURCEMANAGER_HOSTNAME_TEMPLATE = "yarn.resourcemanager.hostname.%s";
+  private static final String PROPERTY_RESOURCEMANAGER_WEBAPP_ADDRESS_TEMPLATE = "yarn.resourcemanager.webapp.address.%s";
+  private static final String PROPERTY_RESOURCEMANAGER_WEBAPP_HTTPS_ADDRESS_TEMPLATE = "yarn.resourcemanager.webapp.https.address.%s";
+
   static {
-    URL_TEMPLATES.put(COMPONENT_RESOURCEMANAGER, "http://%s:8088/ws/v1/cluster/info");
+    URL_TEMPLATES.put(COMPONENT_RESOURCEMANAGER, "http://%s:%s/ws/v1/cluster/info");
     
     MAPPINGS.put(COMPONENT_RESOURCEMANAGER, PropertyHelper.getPropertyId("HostRoles", "ha_state"));
 
@@ -125,7 +135,7 @@ public class HttpProxyPropertyProvider extends BaseProvider implements
PropertyP
           MAPPINGS.containsKey(componentName.toString()) &&
           URL_TEMPLATES.containsKey(componentName.toString())) {
         
-        String template = getTemplate(componentName.toString(), clusterName.toString());
+        String template = getTemplate(componentName.toString(), clusterName.toString(), hostName.toString());
         String propertyId = MAPPINGS.get(componentName.toString());
         String url = String.format(template, hostName);
         
@@ -136,7 +146,7 @@ public class HttpProxyPropertyProvider extends BaseProvider implements
PropertyP
     return resources;
   }
 
-  private String getTemplate(String componentName, String clusterName) throws SystemException
{
+  private String getTemplate(String componentName, String clusterName, String hostName) throws
SystemException {
     String template = URL_TEMPLATES.get(componentName);
 
     if (componentName.equals(COMPONENT_RESOURCEMANAGER)) {
@@ -146,10 +156,41 @@ public class HttpProxyPropertyProvider extends BaseProvider implements
PropertyP
         Map<String, String> coreConfigProperties = cluster.getDesiredConfigByType(CONFIG_CORE_SITE).getProperties();
         String yarnHttpPolicy = yarnConfigProperties.get(PROPERTY_YARN_HTTP_POLICY);
         String hadoopSslEnabled = coreConfigProperties.get(PROPERTY_HADOOP_SSL_ENABLED);
-        if ((yarnHttpPolicy != null && yarnHttpPolicy.equals(PROPERTY_YARN_HTTP_POLICY_VALUE_HTTPS_ONLY))
||
-             hadoopSslEnabled != null && hadoopSslEnabled.equals(PROPERTY_HADOOP_SSL_ENABLED_VALUE_TRUE))
{
+        boolean useHttps = (yarnHttpPolicy != null && yarnHttpPolicy.equals(PROPERTY_YARN_HTTP_POLICY_VALUE_HTTPS_ONLY))
||
+            hadoopSslEnabled != null && hadoopSslEnabled.equals(PROPERTY_HADOOP_SSL_ENABLED_VALUE_TRUE);
+        if (useHttps) {
           template = template.replace("http", "https");
         }
+        // determine correct port, we don't want to use hardcoded one
+        String port;
+        if(!yarnConfigProperties.containsKey(PROPERTY_RESOURCEMANAGER_HA_RM_IDS)) {
+          //non ha mode
+          if(useHttps) {
+            port = getPortFromProperty(yarnConfigProperties, PROPERTY_RESOURCEMANAGER_WEBAPP_HTTPS_ADDRESS,
"8090");
+          } else {
+            port = getPortFromProperty(yarnConfigProperties, PROPERTY_RESOURCEMANAGER_WEBAPP_ADDRESS,
"8088");
+          }
+        } else {
+          // ha mode
+          String rmId = null;
+          for(String id : yarnConfigProperties.get(PROPERTY_RESOURCEMANAGER_HA_RM_IDS).split(","))
{
+            String hostNameProperty = String.format(PROPERTY_RESOURCEMANAGER_HOSTNAME_TEMPLATE,
id);
+            String hostNameById =  yarnConfigProperties.get(hostNameProperty);
+            if(hostNameById.equals(hostName)){
+              rmId = id;
+              break;
+            }
+          }
+          if(useHttps) {
+            String httpsAddressPoperty = String.format(PROPERTY_RESOURCEMANAGER_WEBAPP_HTTPS_ADDRESS_TEMPLATE,
rmId);
+            port = getPortFromProperty(yarnConfigProperties, httpsAddressPoperty, "8090");
+          } else {
+            String httpAddressPoperty = String.format(PROPERTY_RESOURCEMANAGER_WEBAPP_ADDRESS_TEMPLATE,
rmId);
+            port = getPortFromProperty(yarnConfigProperties, httpAddressPoperty, "8088");
+          }
+
+        }
+        template = String.format(template, "%s", port);
       } catch (AmbariException e) {
           LOG.debug(String.format("Could not load cluster with name %s. %s", clusterName,
e.getMessage()));
           throw new SystemException(String.format("Could not load cluster with name %s.",
clusterName),e);
@@ -158,6 +199,13 @@ public class HttpProxyPropertyProvider extends BaseProvider implements
PropertyP
     return template;
   }
 
+  private String getPortFromProperty(Map<String, String> propertyMap, String property,
String defaultValue) {
+    if(propertyMap.containsKey(property))
+      return propertyMap.get(property).split(":")[1];
+    else
+      return defaultValue;
+  }
+
   private Object getPropertyValueToSet(Map<String, Object> propertyValueFromJson, Object
componentName) throws SystemException {
     Object result = propertyValueFromJson;
     //TODO need refactoring for universalization

http://git-wip-us.apache.org/repos/asf/ambari/blob/35073a28/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/HttpPropertyProviderTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/HttpPropertyProviderTest.java
b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/HttpPropertyProviderTest.java
index 154d125..b622728 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/HttpPropertyProviderTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/HttpPropertyProviderTest.java
@@ -91,7 +91,8 @@ public class HttpPropertyProviderTest {
 
     Map<String, String> map = new HashMap<String, String>();
     map.put("yarn.http.policy", "HTTPS_ONLY");
-
+    map.put("yarn.resourcemanager.webapp.https.address", "ec2-54-234-33-50.compute-1.amazonaws.com:8999");
+    map.put("yarn.resourcemanager.webapp.address", "ec2-54-234-33-50.compute-1.amazonaws.com:8088");
 
     expect(injector.getInstance(Clusters.class)).andReturn(clusters);
     expect(clusters.getCluster("testCluster")).andReturn(cluster);
@@ -119,11 +120,62 @@ public class HttpPropertyProviderTest {
     propProvider.populateResources(Collections.singleton(resource), request, null);
 
     Assert.assertTrue(resource.getPropertiesMap().get("HostRoles").get("ha_state").equals("ACTIVE"));
-    Assert.assertTrue(streamProvider.getLastSpec().equals("https://ec2-54-234-33-50.compute-1.amazonaws.com:8088"
+
+    Assert.assertTrue(streamProvider.getLastSpec().equals("https://ec2-54-234-33-50.compute-1.amazonaws.com:8999"
+
             "/ws/v1/cluster/info"));
   }
 
   @Test
+  public void testReadResourceManagerHA() throws Exception {
+
+    TestStreamProvider streamProvider = new TestStreamProvider(false);
+    Clusters clusters = createNiceMock(Clusters.class);
+    Cluster cluster = createNiceMock(Cluster.class);
+    Injector injector = createNiceMock(Injector.class);
+    Config config1 = createNiceMock(Config.class);
+    Config config2 = createNiceMock(Config.class);
+
+    Map<String, String> map = new HashMap<String, String>();
+    map.put("yarn.http.policy", "HTTPS_ONLY");
+    map.put("yarn.resourcemanager.ha.rm-ids", "rm1,rm2");
+    map.put("yarn.resourcemanager.hostname.rm1", "lc6402.ambari.apache.org");
+    map.put("yarn.resourcemanager.hostname.rm2", "lc6403.ambari.apache.org");
+    map.put("yarn.resourcemanager.webapp.address.rm1", "lc6402.ambari.apache.org:8099");
+    map.put("yarn.resourcemanager.webapp.address.rm2", "lc6403.ambari.apache.org:8099");
+    map.put("yarn.resourcemanager.webapp.https.address.rm1", "lc6402.ambari.apache.org:8066");
+    map.put("yarn.resourcemanager.webapp.https.address.rm2", "lc6403.ambari.apache.org:8066");
+
+    expect(injector.getInstance(Clusters.class)).andReturn(clusters);
+    expect(clusters.getCluster("testCluster")).andReturn(cluster);
+    expect(cluster.getDesiredConfigByType("yarn-site")).andReturn(config1).anyTimes();
+    expect(cluster.getDesiredConfigByType("core-site")).andReturn(config2).anyTimes();
+    expect(config1.getProperties()).andReturn(map).anyTimes();
+    expect(config2.getProperties()).andReturn(new HashMap<String, String>()).anyTimes();
+
+    replay(injector, clusters, cluster, config1, config2);
+
+    HttpProxyPropertyProvider propProvider = new HttpProxyPropertyProvider(
+        streamProvider, configuration, injector,
+        PROPERTY_ID_CLUSTER_NAME,
+        PROPERTY_ID_HOST_NAME,
+        PROPERTY_ID_COMPONENT_NAME);
+
+    Resource resource = new ResourceImpl(Resource.Type.HostComponent);
+
+    resource.setProperty(PROPERTY_ID_HOST_NAME, "lc6402.ambari.apache.org");
+    resource.setProperty(PROPERTY_ID_CLUSTER_NAME, "testCluster");
+    resource.setProperty(PROPERTY_ID_COMPONENT_NAME, "RESOURCEMANAGER");
+
+    Request request = PropertyHelper.getReadRequest(Collections.<String>emptySet());
+
+    propProvider.populateResources(Collections.singleton(resource), request, null);
+
+    Assert.assertTrue(resource.getPropertiesMap().get("HostRoles").get("ha_state").equals("ACTIVE"));
+    Assert.assertTrue(streamProvider.getLastSpec().equals("https://lc6402.ambari.apache.org:8066"
+
+        "/ws/v1/cluster/info"));
+  }
+
+
+  @Test
   public void testReadGangliaServer() throws Exception {
     Resource resource = doPopulate("GANGLIA_SERVER",
         Collections.<String> emptySet(), new TestStreamProvider(false));


Mime
View raw message