ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From vbrodets...@apache.org
Subject git commit: AMBARI-6581. Provide API to support which RM is Active/Passive.(vbrodetskyi)
Date Thu, 24 Jul 2014 10:01:06 GMT
Repository: ambari
Updated Branches:
  refs/heads/trunk 86878cdac -> c8ba4f3e5


AMBARI-6581. Provide API to support which RM is Active/Passive.(vbrodetskyi)


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

Branch: refs/heads/trunk
Commit: c8ba4f3e566558a58358998bba5f1c437b5513db
Parents: 86878cd
Author: Vitaly Brodetskyi <vbrodetskyi@hortonworks.com>
Authored: Thu Jul 24 12:04:24 2014 +0300
Committer: Vitaly Brodetskyi <vbrodetskyi@hortonworks.com>
Committed: Thu Jul 24 12:04:24 2014 +0300

----------------------------------------------------------------------
 .../api/query/SubResourcePredicateVisitor.java  |  1 +
 .../internal/HostComponentResourceProvider.java | 37 +++++-----
 .../internal/HttpProxyPropertyProvider.java     | 78 +++++++++++++++++---
 .../HostComponentResourceProviderTest.java      | 23 ++++--
 .../internal/HttpPropertyProviderTest.java      | 63 +++++++++++++++-
 .../internal/JMXHostProviderTest.java           |  7 +-
 6 files changed, 168 insertions(+), 41 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/c8ba4f3e/ambari-server/src/main/java/org/apache/ambari/server/api/query/SubResourcePredicateVisitor.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/api/query/SubResourcePredicateVisitor.java
b/ambari-server/src/main/java/org/apache/ambari/server/api/query/SubResourcePredicateVisitor.java
index ebeae8b..070cb40 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/api/query/SubResourcePredicateVisitor.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/api/query/SubResourcePredicateVisitor.java
@@ -101,6 +101,7 @@ public class SubResourcePredicateVisitor implements PredicateVisitor {
 
   @Override
   public void acceptUnaryPredicate(UnaryPredicate predicate) {
+    //TODO implement subresource parsing not only for ComparisonPredicate
     if (predicate.getPredicate() instanceof ComparisonPredicate) {
       ComparisonPredicate innerPredicate = (ComparisonPredicate) predicate.getPredicate();
       String propertyId = innerPredicate.getPropertyId();

http://git-wip-us.apache.org/repos/asf/ambari/blob/c8ba4f3e/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/HostComponentResourceProvider.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/HostComponentResourceProvider.java
b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/HostComponentResourceProvider.java
index 89d53ae..732203a 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/HostComponentResourceProvider.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/HostComponentResourceProvider.java
@@ -24,6 +24,7 @@ import java.util.Iterator;
 import java.util.Map;
 import java.util.Set;
 
+import com.google.inject.Injector;
 import org.apache.ambari.server.AmbariException;
 import org.apache.ambari.server.configuration.ComponentSSLConfiguration;
 import org.apache.ambari.server.controller.AmbariManagementController;
@@ -80,26 +81,10 @@ public class HostComponentResourceProvider extends AbstractControllerResourcePro
       = "HostRoles/maintenance_state";
   
   //Component name mappings
-  private static final Map<String, PropertyProvider> HOST_COMPONENT_PROPERTIES_PROVIDER
= new HashMap<String, PropertyProvider>();
+  private final Map<String, PropertyProvider> HOST_COMPONENT_PROPERTIES_PROVIDER =
new HashMap<String, PropertyProvider>();
   private static final int HOST_COMPONENT_HTTP_PROPERTY_REQUEST_CONNECT_TIMEOUT = 1500; 
 //milliseconds
   private static final int HOST_COMPONENT_HTTP_PROPERTY_REQUEST_READ_TIMEOUT = 10000;  //milliseconds
 
-  static {
-    ComponentSSLConfiguration configuration = ComponentSSLConfiguration.instance();
-    URLStreamProvider streamProvider = new URLStreamProvider(
-        HOST_COMPONENT_HTTP_PROPERTY_REQUEST_CONNECT_TIMEOUT,
-        HOST_COMPONENT_HTTP_PROPERTY_REQUEST_READ_TIMEOUT,
-        configuration.getTruststorePath(), configuration.getTruststorePassword(), configuration.getTruststoreType());
-
-    HOST_COMPONENT_PROPERTIES_PROVIDER.put(
-        "NAGIOS_SERVER",
-        new HttpProxyPropertyProvider(
-            streamProvider, configuration,
-            PropertyHelper.getPropertyId("HostRoles", "cluster_name"),
-            PropertyHelper.getPropertyId("HostRoles", "host_name"),
-            PropertyHelper.getPropertyId("HostRoles", "component_name")));
-  }
-
   //Parameters from the predicate
   private static final String QUERY_PARAMETERS_RUN_SMOKE_TEST_ID =
       "params/run_smoke_test";
@@ -122,8 +107,24 @@ public class HostComponentResourceProvider extends AbstractControllerResourcePro
   @AssistedInject
   public HostComponentResourceProvider(@Assisted Set<String> propertyIds,
                                        @Assisted Map<Resource.Type, String> keyPropertyIds,
-                                       @Assisted AmbariManagementController managementController)
{
+                                       @Assisted AmbariManagementController managementController,
+                                       Injector injector) {
     super(propertyIds, keyPropertyIds, managementController);
+    ComponentSSLConfiguration configuration = ComponentSSLConfiguration.instance();
+    URLStreamProvider streamProvider = new URLStreamProvider(
+            HOST_COMPONENT_HTTP_PROPERTY_REQUEST_CONNECT_TIMEOUT,
+            HOST_COMPONENT_HTTP_PROPERTY_REQUEST_READ_TIMEOUT,
+            configuration.getTruststorePath(), configuration.getTruststorePassword(), configuration.getTruststoreType());
+
+    HttpProxyPropertyProvider httpPropertyProvider = new HttpProxyPropertyProvider(streamProvider,
+            configuration, injector,
+            PropertyHelper.getPropertyId("HostRoles", "cluster_name"),
+            PropertyHelper.getPropertyId("HostRoles", "host_name"),
+            PropertyHelper.getPropertyId("HostRoles", "component_name"));
+
+    HOST_COMPONENT_PROPERTIES_PROVIDER.put("NAGIOS_SERVER", httpPropertyProvider);
+
+    HOST_COMPONENT_PROPERTIES_PROVIDER.put("RESOURCEMANAGER", httpPropertyProvider);
   }
 
   // ----- ResourceProvider ------------------------------------------------

http://git-wip-us.apache.org/repos/asf/ambari/blob/c8ba4f3e/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 d39518c..3cd336c 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
@@ -26,6 +26,8 @@ import java.util.Map;
 import java.util.Set;
 
 import com.google.gson.JsonSyntaxException;
+import com.google.inject.Injector;
+import org.apache.ambari.server.AmbariException;
 import org.apache.ambari.server.configuration.ComponentSSLConfiguration;
 import org.apache.ambari.server.controller.spi.Predicate;
 import org.apache.ambari.server.controller.spi.PropertyProvider;
@@ -34,6 +36,8 @@ import org.apache.ambari.server.controller.spi.Resource;
 import org.apache.ambari.server.controller.spi.SystemException;
 import org.apache.ambari.server.controller.utilities.PropertyHelper;
 import org.apache.ambari.server.controller.utilities.StreamProvider;
+import org.apache.ambari.server.state.Cluster;
+import org.apache.ambari.server.state.Clusters;
 import org.apache.commons.io.IOUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -51,11 +55,26 @@ public class HttpProxyPropertyProvider extends BaseProvider implements
PropertyP
 
   private static final Map<String, String> URL_TEMPLATES = new HashMap<String, String>();
   private static final Map<String, String> MAPPINGS = new HashMap<String, String>();
+  private static final Map<String, String> PROPERTIES_TO_FILTER = new HashMap<String,
String>();
+
+  private static final String COMPONENT_RESOURCEMANAGER = "RESOURCEMANAGER";
+  private static final String COMPONENT_NAGIOS_SERVER = "NAGIOS_SERVER";
+  private static final String CONFIG_YARN_SITE = "yarn-site";
+  private static final String CONFIG_CORE_SITE = "core-site";
+  private static final String PROPERTY_YARN_HTTP_POLICY = "yarn.http.policy";
+  private static final String PROPERTY_HADOOP_SSL_ENABLED = "hadoop.ssl.enabled";
+  private static final String PROPERTY_YARN_HTTP_POLICY_VALUE_HTTPS_ONLY = "HTTPS_ONLY";
+  private static final String PROPERTY_HADOOP_SSL_ENABLED_VALUE_TRUE = "true";
 
   static {
-    URL_TEMPLATES.put("NAGIOS_SERVER", "http://%s/ambarinagios/nagios/nagios_alerts.php?q1=alerts&alert_type=all");
+    URL_TEMPLATES.put(COMPONENT_NAGIOS_SERVER, "http://%s/ambarinagios/nagios/nagios_alerts.php?q1=alerts&"
+
+            "alert_type=all");
+    URL_TEMPLATES.put(COMPONENT_RESOURCEMANAGER, "http://%s:8088/ws/v1/cluster/info");
     
-    MAPPINGS.put("NAGIOS_SERVER", PropertyHelper.getPropertyId("HostRoles", "nagios_alerts"));
+    MAPPINGS.put(COMPONENT_NAGIOS_SERVER, PropertyHelper.getPropertyId("HostRoles", "nagios_alerts"));
+    MAPPINGS.put(COMPONENT_RESOURCEMANAGER, PropertyHelper.getPropertyId("HostRoles", "ha_state"));
+
+    PROPERTIES_TO_FILTER.put(COMPONENT_RESOURCEMANAGER, "clusterInfo/haState");
   }
 
   private final ComponentSSLConfiguration configuration;
@@ -65,10 +84,14 @@ public class HttpProxyPropertyProvider extends BaseProvider implements
PropertyP
   private String clusterNamePropertyId = null;
   private String hostNamePropertyId = null;
   private String componentNamePropertyId = null;
+
+  private Injector injector;
+  private Clusters clusters;
   
   public HttpProxyPropertyProvider(
       StreamProvider stream,
       ComponentSSLConfiguration configuration,
+      Injector inject,
       String clusterNamePropertyId,
       String hostNamePropertyId,
       String componentNamePropertyId) {
@@ -79,6 +102,8 @@ public class HttpProxyPropertyProvider extends BaseProvider implements
PropertyP
     this.clusterNamePropertyId = clusterNamePropertyId;
     this.hostNamePropertyId = hostNamePropertyId;
     this.componentNamePropertyId = componentNamePropertyId;
+    this.injector = inject;
+    this.clusters = injector.getInstance(Clusters.class);
   }
 
   /**
@@ -98,12 +123,13 @@ public class HttpProxyPropertyProvider extends BaseProvider implements
PropertyP
       
       Object hostName = resource.getPropertyValue(hostNamePropertyId);
       Object componentName = resource.getPropertyValue(componentNamePropertyId);
-      
+      Object clusterName = resource.getPropertyValue(clusterNamePropertyId);
+
       if (null != hostName && null != componentName &&
           MAPPINGS.containsKey(componentName.toString()) &&
           URL_TEMPLATES.containsKey(componentName.toString())) {
         
-        String template = getTemplate(componentName.toString());
+        String template = getTemplate(componentName.toString(), clusterName.toString());
         String propertyId = MAPPINGS.get(componentName.toString());
         String url = String.format(template, hostName);
         
@@ -114,25 +140,59 @@ public class HttpProxyPropertyProvider extends BaseProvider implements
PropertyP
     return resources;
   }
 
-  private String getTemplate(String key) {
-
-    String template = URL_TEMPLATES.get(key);
+  private String getTemplate(String componentName, String clusterName) throws SystemException
{
+    String template = URL_TEMPLATES.get(componentName);
 
-    if (key.equals("NAGIOS_SERVER")) {
+    if (componentName.equals(COMPONENT_NAGIOS_SERVER)) {
       if (configuration.isNagiosSSL()) {
         template = template.replace("http", "https");
       }
+    } else if (componentName.equals(COMPONENT_RESOURCEMANAGER)) {
+      try {
+        Cluster cluster = this.clusters.getCluster(clusterName);
+        Map<String, String> yarnConfigProperties = cluster.getDesiredConfigByType(CONFIG_YARN_SITE).getProperties();
+        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))
{
+          template = template.replace("http", "https");
+        }
+      } 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);
+      }
     }
     return template;
   }
 
+  private Object getPropertyValueToSet(Map<String, Object> propertyValueFromJson, Object
componentName) throws SystemException {
+    Object result = propertyValueFromJson;
+    //TODO need refactoring for universalization
+    try {
+      if (PROPERTIES_TO_FILTER.get(componentName) != null) {
+        for (String key : PROPERTIES_TO_FILTER.get(componentName).split("/")) {
+          result = ((Map)result).get(key);
+        }
+      }
+    } catch (ClassCastException e) {
+        LOG.error(String.format("Error getting property value for %s. %s", PROPERTIES_TO_FILTER.get(componentName),
+              e.getMessage()));
+        throw new SystemException(String.format("Error getting property value for %s.",
+                PROPERTIES_TO_FILTER.get(componentName)),e);
+    }
+    return result;
+  }
+
   private void getHttpResponse(Resource r, String url, String propertyIdToSet) throws SystemException
{
     InputStream in = null;
     try {
       in = streamProvider.readFrom(url);
       Type mapType = new TypeToken<Map<String, Object>>(){}.getType();
       Map<String, Object> propertyValueFromJson = new Gson().fromJson(IOUtils.toString(in,
"UTF-8"), mapType);
-      r.setProperty(propertyIdToSet, propertyValueFromJson);
+      Object propertyValueToSet = getPropertyValueToSet(propertyValueFromJson,
+              r.getPropertyValue(componentNamePropertyId));
+      r.setProperty(propertyIdToSet, propertyValueToSet);
     }
     catch (IOException ioe) {
       LOG.error("Error reading HTTP response from " + url);

http://git-wip-us.apache.org/repos/asf/ambari/blob/c8ba4f3e/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/HostComponentResourceProviderTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/HostComponentResourceProviderTest.java
b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/HostComponentResourceProviderTest.java
index 08a72bb..abe30cc 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/HostComponentResourceProviderTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/HostComponentResourceProviderTest.java
@@ -18,6 +18,7 @@
 
 package org.apache.ambari.server.controller.internal;
 
+import com.google.inject.Injector;
 import org.apache.ambari.server.controller.AmbariManagementController;
 import org.apache.ambari.server.controller.RequestStatusResponse;
 import org.apache.ambari.server.controller.ResourceProviderFactory;
@@ -29,8 +30,10 @@ import org.apache.ambari.server.controller.spi.Resource;
 import org.apache.ambari.server.controller.spi.ResourceProvider;
 import org.apache.ambari.server.controller.utilities.PredicateBuilder;
 import org.apache.ambari.server.controller.utilities.PropertyHelper;
+import org.apache.ambari.server.state.Clusters;
 import org.apache.ambari.server.state.StackId;
 import org.apache.ambari.server.state.State;
+import org.apache.ambari.server.state.cluster.ClustersImpl;
 import org.easymock.EasyMock;
 import org.junit.Assert;
 import org.junit.Test;
@@ -62,17 +65,18 @@ public class HostComponentResourceProviderTest {
     AmbariManagementController managementController = createMock(AmbariManagementController.class);
     RequestStatusResponse response = createNiceMock(RequestStatusResponse.class);
     ResourceProviderFactory resourceProviderFactory = createNiceMock(ResourceProviderFactory.class);
-    HostComponentResourceProvider hostComponentResourceProvider = 
+    Injector injector = createNiceMock(Injector.class);
+    HostComponentResourceProvider hostComponentResourceProvider =
         new HostComponentResourceProvider(PropertyHelper.getPropertyIds(type),
         PropertyHelper.getKeyPropertyIds(type),
-        managementController);
-    
+        managementController, injector);
+
     AbstractControllerResourceProvider.init(resourceProviderFactory);
 
     managementController.createHostComponents(
         AbstractResourceProviderTest.Matcher.getHostComponentRequestSet(
             "Cluster100", "Service100", "Component100", "Host100", null, null));
-    
+
     expect(resourceProviderFactory.getHostComponentResourceProvider(anyObject(Set.class),
         anyObject(Map.class),
         eq(managementController))).
@@ -236,6 +240,7 @@ public class HostComponentResourceProviderTest {
     AmbariManagementController managementController = createMock(AmbariManagementController.class);
     RequestStatusResponse response = createNiceMock(RequestStatusResponse.class);
     ResourceProviderFactory resourceProviderFactory = createNiceMock(ResourceProviderFactory.class);
+    Injector injector = createNiceMock(Injector.class);
 
     Map<String, String> mapRequestProps = new HashMap<String, String>();
     mapRequestProps.put("context", "Called from a test");
@@ -247,7 +252,7 @@ public class HostComponentResourceProviderTest {
     HostComponentResourceProvider provider = 
         new HostComponentResourceProvider(PropertyHelper.getPropertyIds(type),
         PropertyHelper.getKeyPropertyIds(type),
-        managementController);
+        managementController, injector);
 
     // set expectations
     expect(managementController.getHostComponents(
@@ -287,11 +292,12 @@ public class HostComponentResourceProviderTest {
 
     AmbariManagementController managementController = createMock(AmbariManagementController.class);
     RequestStatusResponse response = createNiceMock(RequestStatusResponse.class);
+    Injector injector = createNiceMock(Injector.class);
     
     HostComponentResourceProvider provider = 
         new HostComponentResourceProvider(PropertyHelper.getPropertyIds(type),
         PropertyHelper.getKeyPropertyIds(type),
-        managementController);
+        managementController, injector);
 
     // set expectations
     expect(managementController.deleteHostComponents(
@@ -336,11 +342,12 @@ public class HostComponentResourceProviderTest {
     Map<Resource.Type, String> keyPropertyIds = new HashMap<Resource.Type, String>();
 
     AmbariManagementController managementController = createMock(AmbariManagementController.class);
+    Injector injector = createNiceMock(Injector.class);
 
-    HostComponentResourceProvider provider = 
+    HostComponentResourceProvider provider =
         new HostComponentResourceProvider(propertyIds,
         keyPropertyIds,
-        managementController);
+        managementController, injector);
 
     Set<String> unsupported = provider.checkPropertyIds(Collections.singleton("foo"));
     Assert.assertTrue(unsupported.isEmpty());

http://git-wip-us.apache.org/repos/asf/ambari/blob/c8ba4f3e/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 ba08dfc..6883514 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
@@ -22,6 +22,7 @@ import java.io.ByteArrayInputStream;
 import java.io.IOException;
 import java.io.InputStream;
 import java.util.Arrays;
+import java.util.HashMap;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.HashSet;
@@ -29,17 +30,25 @@ import java.util.List;
 import java.util.Map;
 import java.util.Set;
 
+import com.google.inject.Injector;
 import org.apache.ambari.server.configuration.ComponentSSLConfiguration;
 import org.apache.ambari.server.configuration.ComponentSSLConfigurationTest;
 import org.apache.ambari.server.controller.spi.Request;
 import org.apache.ambari.server.controller.spi.Resource;
 import org.apache.ambari.server.controller.utilities.PropertyHelper;
 import org.apache.ambari.server.controller.utilities.StreamProvider;
+import org.apache.ambari.server.state.Cluster;
+import org.apache.ambari.server.state.Clusters;
+import org.apache.ambari.server.state.Config;
 import org.junit.Assert;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.junit.runners.Parameterized;
 
+import static org.easymock.EasyMock.createNiceMock;
+import static org.easymock.EasyMock.expect;
+import static org.easymock.EasyMock.replay;
+
 @RunWith(Parameterized.class)
 public class HttpPropertyProviderTest {
   private static final String PROPERTY_ID_CLUSTER_NAME = PropertyHelper.getPropertyId("HostRoles",
"cluster_name");
@@ -74,6 +83,50 @@ public class HttpPropertyProviderTest {
   }
 
   @Test
+  public void testReadResourceManager() 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");
+
+
+    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, "ec2-54-234-33-50.compute-1.amazonaws.com");
+    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://ec2-54-234-33-50.compute-1.amazonaws.com:8088"
+
+            "/ws/v1/cluster/info"));
+  }
+
+  @Test
   public void testReadNagiosServer() throws Exception {
 
     TestStreamProvider streamProvider = new TestStreamProvider(false);
@@ -171,16 +224,18 @@ public class HttpPropertyProviderTest {
   
   private Resource doPopulate(String componentName,
       Set<String> requestProperties, StreamProvider streamProvider) throws Exception
{
+    Injector injector = createNiceMock(Injector.class);
 
     HttpProxyPropertyProvider propProvider = new HttpProxyPropertyProvider(
-       streamProvider, configuration,
+       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, "ec2-54-234-33-50.compute-1.amazonaws.com");
+    resource.setProperty(PROPERTY_ID_CLUSTER_NAME, "testCluster");
     resource.setProperty(PROPERTY_ID_COMPONENT_NAME, componentName);
     
     Request request = PropertyHelper.getReadRequest(requestProperties);
@@ -189,7 +244,7 @@ public class HttpPropertyProviderTest {
 
     return resource;
   }
-  
+
   private static class TestStreamProvider implements StreamProvider {
     private boolean throwError = false;
     private String lastSpec = null;
@@ -210,7 +265,7 @@ public class HttpPropertyProviderTest {
         throw new IOException("Fake error");
       }
       
-      String responseStr = "{\"alerts\": [{\"Alert Body\": \"Body\"}],"
+      String responseStr = "{\"alerts\": [{\"Alert Body\": \"Body\"}],\"clusterInfo\": [{\"haState\":
\"ACTIVE\"}],"
           + " \"hostcounts\": {\"up_hosts\":\"1\", \"down_hosts\":\"0\"}}";
         return new ByteArrayInputStream(responseStr.getBytes("UTF-8"));
     }

http://git-wip-us.apache.org/repos/asf/ambari/blob/c8ba4f3e/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/JMXHostProviderTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/JMXHostProviderTest.java
b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/JMXHostProviderTest.java
index 6e8cb9f..5f4b55c 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/JMXHostProviderTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/JMXHostProviderTest.java
@@ -57,6 +57,7 @@ import com.google.inject.persist.PersistService;
 
 import static org.easymock.EasyMock.createNiceMock;
 import static org.easymock.EasyMock.replay;
+import static org.easymock.EasyMock.expect;
 
 public class JMXHostProviderTest {
   private Injector injector;
@@ -385,9 +386,11 @@ public class JMXHostProviderTest {
       .Cluster), PropertyHelper.getKeyPropertyIds(Resource.Type.Cluster),
       controller);
 
+    Injector injector = createNiceMock(Injector.class);
     MaintenanceStateHelper maintenanceStateHelper = createNiceMock(MaintenanceStateHelper.class);
     {
-      replay(maintenanceStateHelper);
+      expect(injector.getInstance(Clusters.class)).andReturn(null);
+      replay(maintenanceStateHelper, injector);
     }
 
     ResourceProvider serviceResourceProvider = new ServiceResourceProvider(PropertyHelper
@@ -397,7 +400,7 @@ public class JMXHostProviderTest {
     ResourceProvider hostCompResourceProvider = new
       HostComponentResourceProvider(PropertyHelper.getPropertyIds(Resource
       .Type.HostComponent), PropertyHelper.getKeyPropertyIds(Resource.Type
-      .HostComponent), controller);
+      .HostComponent), controller, injector);
 
     ResourceProvider configResourceProvider = new
       ConfigurationResourceProvider(PropertyHelper.getPropertyIds(Resource


Mime
View raw message