ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tbeerbo...@apache.org
Subject [1/2] AMBARI-3670 - Hosts should roll up host_components status into its status
Date Mon, 04 Nov 2013 10:04:49 GMT
Updated Branches:
  refs/heads/trunk c13df4d7d -> 69010c808


http://git-wip-us.apache.org/repos/asf/incubator-ambari/blob/69010c80/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/HostResourceProviderTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/HostResourceProviderTest.java b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/HostResourceProviderTest.java
index 88d8d40..cbdcb0e 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/HostResourceProviderTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/HostResourceProviderTest.java
@@ -18,32 +18,55 @@
 
 package org.apache.ambari.server.controller.internal;
 
+import com.google.gson.Gson;
+import com.google.inject.Injector;
+import org.apache.ambari.server.AmbariException;
+import org.apache.ambari.server.HostNotFoundException;
+import org.apache.ambari.server.api.services.AmbariMetaInfo;
 import org.apache.ambari.server.controller.AmbariManagementController;
-import org.apache.ambari.server.controller.HostRequest;
+import org.apache.ambari.server.controller.AmbariManagementControllerImpl;
 import org.apache.ambari.server.controller.HostResponse;
 import org.apache.ambari.server.controller.RequestStatusResponse;
+import org.apache.ambari.server.controller.HostRequest;
+import org.apache.ambari.server.controller.ServiceComponentHostRequest;
+import org.apache.ambari.server.controller.ServiceComponentHostResponse;
 import org.apache.ambari.server.controller.spi.Predicate;
 import org.apache.ambari.server.controller.spi.Request;
 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.Cluster;
+import org.apache.ambari.server.state.Clusters;
+import org.apache.ambari.server.state.ComponentInfo;
+import org.apache.ambari.server.state.Host;
 import org.apache.ambari.server.state.HostHealthStatus;
-import org.easymock.EasyMock;
+import org.apache.ambari.server.state.StackId;
+import org.easymock.Capture;
 import org.junit.Assert;
 import org.junit.Test;
 
+import java.util.Collections;
 import java.util.HashSet;
 import java.util.LinkedHashMap;
 import java.util.LinkedHashSet;
+import java.util.LinkedList;
+import java.util.List;
 import java.util.Map;
 import java.util.Set;
 
+import static org.easymock.EasyMock.anyObject;
+import static org.easymock.EasyMock.capture;
 import static org.easymock.EasyMock.createMock;
 import static org.easymock.EasyMock.createNiceMock;
+import static org.easymock.EasyMock.createStrictMock;
 import static org.easymock.EasyMock.expect;
 import static org.easymock.EasyMock.replay;
 import static org.easymock.EasyMock.verify;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertSame;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
 
 /**
  * HostResourceProvider tests.
@@ -54,13 +77,13 @@ public class HostResourceProviderTest {
     Resource.Type type = Resource.Type.Host;
 
     AmbariManagementController managementController = createMock(AmbariManagementController.class);
+    Clusters clusters = createNiceMock(Clusters.class);
     RequestStatusResponse response = createNiceMock(RequestStatusResponse.class);
 
-    managementController.createHosts(
-        AbstractResourceProviderTest.Matcher.getHostRequestSet("Host100", "Cluster100", null));
+    expect(managementController.getClusters()).andReturn(clusters);
 
     // replay
-    replay(managementController, response);
+    replay(managementController, response, clusters);
 
     ResourceProvider provider = AbstractControllerResourceProvider.getResourceProvider(
         type,
@@ -85,7 +108,7 @@ public class HostResourceProviderTest {
     provider.createResources(request);
 
     // verify
-    verify(managementController, response);
+    verify(managementController, response, clusters);
   }
 
   @Test
@@ -93,28 +116,65 @@ public class HostResourceProviderTest {
     Resource.Type type = Resource.Type.Host;
 
     AmbariManagementController managementController = createMock(AmbariManagementController.class);
+    Clusters clusters = createNiceMock(Clusters.class);
+    Cluster cluster = createNiceMock(Cluster.class);
+    Host host1 = createNiceMock(Host.class);
+    Host host2 = createNiceMock(Host.class);
+    Host host3 = createNiceMock(Host.class);
+    HostHealthStatus healthStatus = createNiceMock(HostHealthStatus.class);
+    AmbariMetaInfo ambariMetaInfo = createNiceMock(AmbariMetaInfo.class);
+
+    HostResponse hostResponse1 = createNiceMock(HostResponse.class);
+    HostResponse hostResponse2 = createNiceMock(HostResponse.class);
+    HostResponse hostResponse3 = createNiceMock(HostResponse.class);
 
-    Set<HostResponse> allResponse = new HashSet<HostResponse>();
-    allResponse.add(new HostResponse("Host100", "Cluster100",
-        "", "", 2, 1, "", "", "", 100000L, 200000L, null, 10L,
-        0L, "rack info", null, null,
-        new HostHealthStatus(HostHealthStatus.HealthStatus.HEALTHY, "HEALTHY"), "HEALTHY"));
-    allResponse.add(new HostResponse("Host101", "Cluster100",
-        "", "", 2, 1, "", "", "", 100000L, 200000L, null, 10L,
-        0L, "rack info", null, null,
-        new HostHealthStatus(HostHealthStatus.HealthStatus.HEALTHY, "HEALTHY"), "HEALTHY"));
-    allResponse.add(new HostResponse("Host102", "Cluster100",
-        "", "", 2, 1, "", "", "", 100000L, 200000L, null, 10L,
-        0L, "rack info", null, null,
-        new HostHealthStatus(HostHealthStatus.HealthStatus.HEALTHY, "HEALTHY"), "HEALTHY"));
+    List<Host> hosts = new LinkedList<Host>();
+    hosts.add(host1);
+    hosts.add(host2);
+    hosts.add(host3);
+
+    Set<Cluster> clusterSet = new HashSet<Cluster>();
+    clusterSet.add(cluster);
 
     // set expectations
-    expect(managementController.getHosts(
-        AbstractResourceProviderTest.Matcher.getHostRequestSet(null, "Cluster100", null))).
-        andReturn(allResponse).once();
+    expect(managementController.getClusters()).andReturn(clusters).anyTimes();
+    expect(managementController.getAmbariMetaInfo()).andReturn(ambariMetaInfo).anyTimes();
+    expect(managementController.getHostComponents((Set<ServiceComponentHostRequest>) anyObject())).andReturn(Collections.<ServiceComponentHostResponse>emptySet()).anyTimes();
+
+    expect(clusters.getHosts()).andReturn(hosts).anyTimes();
+
+    expect(clusters.getCluster("Cluster100")).andReturn(cluster).anyTimes();
+
+    expect(clusters.getClustersForHost("Host100")).andReturn(clusterSet).anyTimes();
+    expect(clusters.getClustersForHost("Host101")).andReturn(clusterSet).anyTimes();
+    expect(clusters.getClustersForHost("Host102")).andReturn(clusterSet).anyTimes();
+
+    expect(host1.getHostName()).andReturn("Host100").anyTimes();
+    expect(host2.getHostName()).andReturn("Host101").anyTimes();
+    expect(host3.getHostName()).andReturn("Host102").anyTimes();
+
+    expect(host1.convertToResponse()).andReturn(hostResponse1);
+    expect(host2.convertToResponse()).andReturn(hostResponse2);
+    expect(host3.convertToResponse()).andReturn(hostResponse3);
+
+    expect(hostResponse1.getClusterName()).andReturn("Cluster100").anyTimes();
+    expect(hostResponse2.getClusterName()).andReturn("Cluster100").anyTimes();
+    expect(hostResponse3.getClusterName()).andReturn("Cluster100").anyTimes();
+    expect(hostResponse1.getHostname()).andReturn("Host100").anyTimes();
+    expect(hostResponse2.getHostname()).andReturn("Host101").anyTimes();
+    expect(hostResponse3.getHostname()).andReturn("Host102").anyTimes();
+    expect(hostResponse1.getHealthStatus()).andReturn(healthStatus).anyTimes();
+    expect(hostResponse2.getHealthStatus()).andReturn(healthStatus).anyTimes();
+    expect(hostResponse3.getHealthStatus()).andReturn(healthStatus).anyTimes();
+
+    expect(healthStatus.getHealthStatus()).andReturn(HostHealthStatus.HealthStatus.HEALTHY).anyTimes();
+    expect(healthStatus.getHealthReport()).andReturn("HEALTHY").anyTimes();
 
     // replay
-    replay(managementController);
+    replay(managementController, clusters, cluster,
+        host1, host2, host3,
+        hostResponse1, hostResponse2, hostResponse3,
+        healthStatus, ambariMetaInfo);
 
     ResourceProvider provider = AbstractControllerResourceProvider.getResourceProvider(
         type,
@@ -134,44 +194,444 @@ public class HostResourceProviderTest {
     Set<Resource> resources = provider.getResources(request, predicate);
 
     Assert.assertEquals(3, resources.size());
-    Set<String> names = new HashSet<String>();
     for (Resource resource : resources) {
       String clusterName = (String) resource.getPropertyValue(HostResourceProvider.HOST_CLUSTER_NAME_PROPERTY_ID);
       Assert.assertEquals("Cluster100", clusterName);
-      names.add((String) resource.getPropertyValue(HostResourceProvider.HOST_NAME_PROPERTY_ID));
     }
-    // Make sure that all of the response objects got moved into resources
-    for (HostResponse response : allResponse ) {
-      Assert.assertTrue(names.contains(response.getHostname()));
+
+    // verify
+    verify(managementController, clusters, cluster,
+        host1, host2, host3,
+        hostResponse1, hostResponse2, hostResponse3,
+        healthStatus, ambariMetaInfo);
+  }
+
+  @Test
+  public void testGetResources_Status_Healthy() throws Exception {
+    Resource.Type type = Resource.Type.Host;
+
+    AmbariManagementController managementController = createMock(AmbariManagementController.class);
+    Clusters clusters = createNiceMock(Clusters.class);
+    Cluster cluster = createNiceMock(Cluster.class);
+    Host host1 = createNiceMock(Host.class);
+    HostHealthStatus healthStatus = createNiceMock(HostHealthStatus.class);
+    AmbariMetaInfo ambariMetaInfo = createNiceMock(AmbariMetaInfo.class);
+    StackId stackId = createNiceMock(StackId.class);
+    ComponentInfo componentInfo = createNiceMock(ComponentInfo.class);
+
+    HostResponse hostResponse1 = createNiceMock(HostResponse.class);
+
+    List<Host> hosts = new LinkedList<Host>();
+    hosts.add(host1);
+
+    Set<Cluster> clusterSet = new HashSet<Cluster>();
+    clusterSet.add(cluster);
+
+    ServiceComponentHostResponse shr1 = new ServiceComponentHostResponse("Cluster100", "Service100", "Component100", "Host100", null, null, "STARTED", "", null, null);
+    ServiceComponentHostResponse shr2 = new ServiceComponentHostResponse("Cluster100", "Service100", "Component102", "Host100", null, null, "STARTED", "", null, null);
+    ServiceComponentHostResponse shr3 = new ServiceComponentHostResponse("Cluster100", "Service100", "Component103", "Host100", null, null, "STARTED", "", null, null);
+
+    Set<ServiceComponentHostResponse> responses = new HashSet<ServiceComponentHostResponse>();
+    responses.add(shr1);
+    responses.add(shr2);
+    responses.add(shr3);
+
+    // set expectations
+    expect(managementController.getClusters()).andReturn(clusters).anyTimes();
+    expect(managementController.getAmbariMetaInfo()).andReturn(ambariMetaInfo).anyTimes();
+    expect(managementController.getHostComponents((Set<ServiceComponentHostRequest>) anyObject())).andReturn(responses).anyTimes();
+
+    expect(clusters.getHosts()).andReturn(hosts).anyTimes();
+
+    expect(clusters.getCluster("Cluster100")).andReturn(cluster).anyTimes();
+
+    expect(clusters.getClustersForHost("Host100")).andReturn(clusterSet).anyTimes();
+
+    expect(cluster.getDesiredStackVersion()).andReturn(stackId);
+
+    expect(host1.getHostName()).andReturn("Host100").anyTimes();
+
+    expect(host1.convertToResponse()).andReturn(hostResponse1);
+
+    expect(hostResponse1.getClusterName()).andReturn("Cluster100").anyTimes();
+    expect(hostResponse1.getHostname()).andReturn("Host100").anyTimes();
+    expect(hostResponse1.getHealthStatus()).andReturn(healthStatus).anyTimes();
+
+    expect(healthStatus.getHealthStatus()).andReturn(HostHealthStatus.HealthStatus.HEALTHY).anyTimes();
+    expect(healthStatus.getHealthReport()).andReturn("HEALTHY").anyTimes();
+
+
+    expect(ambariMetaInfo.getComponentCategory((String) anyObject(), (String) anyObject(),
+        (String) anyObject(), (String) anyObject())).andReturn(componentInfo).anyTimes();
+
+    expect(componentInfo.getCategory()).andReturn("MASTER").anyTimes();
+
+
+    // replay
+    replay(managementController, clusters, cluster,
+        host1,
+        hostResponse1, stackId, componentInfo,
+        healthStatus, ambariMetaInfo);
+
+    ResourceProvider provider = AbstractControllerResourceProvider.getResourceProvider(
+        type,
+        PropertyHelper.getPropertyIds(type),
+        PropertyHelper.getKeyPropertyIds(type),
+        managementController);
+
+    Set<String> propertyIds = new HashSet<String>();
+
+    propertyIds.add(HostResourceProvider.HOST_CLUSTER_NAME_PROPERTY_ID);
+    propertyIds.add(HostResourceProvider.HOST_NAME_PROPERTY_ID);
+    propertyIds.add(HostResourceProvider.HOST_HOST_STATUS_PROPERTY_ID);
+
+    Predicate predicate =
+        new PredicateBuilder().property(HostResourceProvider.HOST_CLUSTER_NAME_PROPERTY_ID).equals("Cluster100").
+            toPredicate();
+    Request request = PropertyHelper.getReadRequest(propertyIds);
+    Set<Resource> resources = provider.getResources(request, predicate);
+
+    Assert.assertEquals(1, resources.size());
+    for (Resource resource : resources) {
+      String clusterName = (String) resource.getPropertyValue(HostResourceProvider.HOST_CLUSTER_NAME_PROPERTY_ID);
+      Assert.assertEquals("Cluster100", clusterName);
+      String status = (String) resource.getPropertyValue(HostResourceProvider.HOST_HOST_STATUS_PROPERTY_ID);
+      Assert.assertEquals("HEALTHY", status);
+    }
+
+    // verify
+    verify(managementController, clusters, cluster,
+        host1,
+        hostResponse1, stackId, componentInfo,
+        healthStatus, ambariMetaInfo);
+  }
+
+  @Test
+  public void testGetResources_Status_Unhealthy() throws Exception {
+    Resource.Type type = Resource.Type.Host;
+
+    AmbariManagementController managementController = createMock(AmbariManagementController.class);
+    Clusters clusters = createNiceMock(Clusters.class);
+    Cluster cluster = createNiceMock(Cluster.class);
+    Host host1 = createNiceMock(Host.class);
+    HostHealthStatus healthStatus = createNiceMock(HostHealthStatus.class);
+    AmbariMetaInfo ambariMetaInfo = createNiceMock(AmbariMetaInfo.class);
+    StackId stackId = createNiceMock(StackId.class);
+    ComponentInfo componentInfo = createNiceMock(ComponentInfo.class);
+
+    HostResponse hostResponse1 = createNiceMock(HostResponse.class);
+
+    List<Host> hosts = new LinkedList<Host>();
+    hosts.add(host1);
+
+    Set<Cluster> clusterSet = new HashSet<Cluster>();
+    clusterSet.add(cluster);
+
+    ServiceComponentHostResponse shr1 = new ServiceComponentHostResponse("Cluster100", "Service100", "Component100", "Host100", null, null, "STARTED", "", null, null);
+    ServiceComponentHostResponse shr2 = new ServiceComponentHostResponse("Cluster100", "Service100", "Component102", "Host100", null, null, "INSTALLED", "", null, null);
+    ServiceComponentHostResponse shr3 = new ServiceComponentHostResponse("Cluster100", "Service100", "Component103", "Host100", null, null, "STARTED", "", null, null);
+
+    Set<ServiceComponentHostResponse> responses = new HashSet<ServiceComponentHostResponse>();
+    responses.add(shr1);
+    responses.add(shr2);
+    responses.add(shr3);
+
+    // set expectations
+    expect(managementController.getClusters()).andReturn(clusters).anyTimes();
+    expect(managementController.getAmbariMetaInfo()).andReturn(ambariMetaInfo).anyTimes();
+    expect(managementController.getHostComponents((Set<ServiceComponentHostRequest>) anyObject())).andReturn(responses).anyTimes();
+
+    expect(clusters.getHosts()).andReturn(hosts).anyTimes();
+
+    expect(clusters.getCluster("Cluster100")).andReturn(cluster).anyTimes();
+
+    expect(clusters.getClustersForHost("Host100")).andReturn(clusterSet).anyTimes();
+
+    expect(cluster.getDesiredStackVersion()).andReturn(stackId);
+
+    expect(host1.getHostName()).andReturn("Host100").anyTimes();
+
+    expect(host1.convertToResponse()).andReturn(hostResponse1);
+
+    expect(hostResponse1.getClusterName()).andReturn("Cluster100").anyTimes();
+    expect(hostResponse1.getHostname()).andReturn("Host100").anyTimes();
+    expect(hostResponse1.getHealthStatus()).andReturn(healthStatus).anyTimes();
+
+    expect(healthStatus.getHealthStatus()).andReturn(HostHealthStatus.HealthStatus.HEALTHY).anyTimes();
+    expect(healthStatus.getHealthReport()).andReturn("HEALTHY").anyTimes();
+
+
+    expect(ambariMetaInfo.getComponentCategory((String) anyObject(), (String) anyObject(),
+        (String) anyObject(), (String) anyObject())).andReturn(componentInfo).anyTimes();
+
+    expect(componentInfo.getCategory()).andReturn("MASTER").anyTimes();
+
+
+    // replay
+    replay(managementController, clusters, cluster,
+        host1,
+        hostResponse1, stackId, componentInfo,
+        healthStatus, ambariMetaInfo);
+
+    ResourceProvider provider = AbstractControllerResourceProvider.getResourceProvider(
+        type,
+        PropertyHelper.getPropertyIds(type),
+        PropertyHelper.getKeyPropertyIds(type),
+        managementController);
+
+    Set<String> propertyIds = new HashSet<String>();
+
+    propertyIds.add(HostResourceProvider.HOST_CLUSTER_NAME_PROPERTY_ID);
+    propertyIds.add(HostResourceProvider.HOST_NAME_PROPERTY_ID);
+    propertyIds.add(HostResourceProvider.HOST_HOST_STATUS_PROPERTY_ID);
+
+    Predicate predicate =
+        new PredicateBuilder().property(HostResourceProvider.HOST_CLUSTER_NAME_PROPERTY_ID).equals("Cluster100").
+            toPredicate();
+    Request request = PropertyHelper.getReadRequest(propertyIds);
+    Set<Resource> resources = provider.getResources(request, predicate);
+
+    Assert.assertEquals(1, resources.size());
+    for (Resource resource : resources) {
+      String clusterName = (String) resource.getPropertyValue(HostResourceProvider.HOST_CLUSTER_NAME_PROPERTY_ID);
+      Assert.assertEquals("Cluster100", clusterName);
+      String status = (String) resource.getPropertyValue(HostResourceProvider.HOST_HOST_STATUS_PROPERTY_ID);
+      Assert.assertEquals("UNHEALTHY", status);
     }
 
     // verify
-    verify(managementController);
+    verify(managementController, clusters, cluster,
+        host1,
+        hostResponse1, stackId, componentInfo,
+        healthStatus, ambariMetaInfo);
   }
-  
+
+  @Test
+  public void testGetResources_Status_Unknown() throws Exception {
+    Resource.Type type = Resource.Type.Host;
+
+    AmbariManagementController managementController = createMock(AmbariManagementController.class);
+    Clusters clusters = createNiceMock(Clusters.class);
+    Cluster cluster = createNiceMock(Cluster.class);
+    Host host1 = createNiceMock(Host.class);
+    HostHealthStatus healthStatus = createNiceMock(HostHealthStatus.class);
+    AmbariMetaInfo ambariMetaInfo = createNiceMock(AmbariMetaInfo.class);
+
+    HostResponse hostResponse1 = createNiceMock(HostResponse.class);
+
+    List<Host> hosts = new LinkedList<Host>();
+    hosts.add(host1);
+
+    Set<Cluster> clusterSet = new HashSet<Cluster>();
+    clusterSet.add(cluster);
+
+    // set expectations
+    expect(managementController.getClusters()).andReturn(clusters).anyTimes();
+    expect(managementController.getAmbariMetaInfo()).andReturn(ambariMetaInfo).anyTimes();
+
+    expect(clusters.getHosts()).andReturn(hosts).anyTimes();
+
+    expect(clusters.getCluster("Cluster100")).andReturn(cluster).anyTimes();
+
+    expect(clusters.getClustersForHost("Host100")).andReturn(clusterSet).anyTimes();
+
+    expect(host1.getHostName()).andReturn("Host100").anyTimes();
+
+    expect(host1.convertToResponse()).andReturn(hostResponse1);
+
+    expect(hostResponse1.getClusterName()).andReturn("Cluster100").anyTimes();
+    expect(hostResponse1.getHostname()).andReturn("Host100").anyTimes();
+    expect(hostResponse1.getHealthStatus()).andReturn(healthStatus).anyTimes();
+
+    expect(healthStatus.getHealthStatus()).andReturn(HostHealthStatus.HealthStatus.UNKNOWN).anyTimes();
+    expect(healthStatus.getHealthReport()).andReturn("UNKNOWN").anyTimes();
+
+
+    // replay
+    replay(managementController, clusters, cluster,
+        host1,
+        hostResponse1,
+        healthStatus, ambariMetaInfo);
+
+    ResourceProvider provider = AbstractControllerResourceProvider.getResourceProvider(
+        type,
+        PropertyHelper.getPropertyIds(type),
+        PropertyHelper.getKeyPropertyIds(type),
+        managementController);
+
+    Set<String> propertyIds = new HashSet<String>();
+
+    propertyIds.add(HostResourceProvider.HOST_CLUSTER_NAME_PROPERTY_ID);
+    propertyIds.add(HostResourceProvider.HOST_NAME_PROPERTY_ID);
+    propertyIds.add(HostResourceProvider.HOST_HOST_STATUS_PROPERTY_ID);
+
+    Predicate predicate =
+        new PredicateBuilder().property(HostResourceProvider.HOST_CLUSTER_NAME_PROPERTY_ID).equals("Cluster100").
+            toPredicate();
+    Request request = PropertyHelper.getReadRequest(propertyIds);
+    Set<Resource> resources = provider.getResources(request, predicate);
+
+    Assert.assertEquals(1, resources.size());
+    for (Resource resource : resources) {
+      String clusterName = (String) resource.getPropertyValue(HostResourceProvider.HOST_CLUSTER_NAME_PROPERTY_ID);
+      Assert.assertEquals("Cluster100", clusterName);
+      String status = (String) resource.getPropertyValue(HostResourceProvider.HOST_HOST_STATUS_PROPERTY_ID);
+      Assert.assertEquals("UNKNOWN", status);
+    }
+
+    // verify
+    verify(managementController, clusters, cluster,
+        host1,
+        hostResponse1,
+        healthStatus, ambariMetaInfo);
+  }
+
+  @Test
+  public void testGetResources_Status_Alert() throws Exception {
+    Resource.Type type = Resource.Type.Host;
+
+    AmbariManagementController managementController = createMock(AmbariManagementController.class);
+    Clusters clusters = createNiceMock(Clusters.class);
+    Cluster cluster = createNiceMock(Cluster.class);
+    Host host1 = createNiceMock(Host.class);
+    HostHealthStatus healthStatus = createNiceMock(HostHealthStatus.class);
+    AmbariMetaInfo ambariMetaInfo = createNiceMock(AmbariMetaInfo.class);
+    StackId stackId = createNiceMock(StackId.class);
+    ComponentInfo componentInfo = createNiceMock(ComponentInfo.class);
+
+    HostResponse hostResponse1 = createNiceMock(HostResponse.class);
+
+    List<Host> hosts = new LinkedList<Host>();
+    hosts.add(host1);
+
+    Set<Cluster> clusterSet = new HashSet<Cluster>();
+    clusterSet.add(cluster);
+
+    ServiceComponentHostResponse shr1 = new ServiceComponentHostResponse("Cluster100", "Service100", "Component100", "Host100", null, null, "STARTED", "", null, null);
+    ServiceComponentHostResponse shr2 = new ServiceComponentHostResponse("Cluster100", "Service100", "Component102", "Host100", null, null, "INSTALLED", "", null, null);
+    ServiceComponentHostResponse shr3 = new ServiceComponentHostResponse("Cluster100", "Service100", "Component103", "Host100", null, null, "STARTED", "", null, null);
+
+    Set<ServiceComponentHostResponse> responses = new HashSet<ServiceComponentHostResponse>();
+    responses.add(shr1);
+    responses.add(shr2);
+    responses.add(shr3);
+
+    // set expectations
+    expect(managementController.getClusters()).andReturn(clusters).anyTimes();
+    expect(managementController.getAmbariMetaInfo()).andReturn(ambariMetaInfo).anyTimes();
+    expect(managementController.getHostComponents((Set<ServiceComponentHostRequest>) anyObject())).andReturn(responses).anyTimes();
+
+    expect(clusters.getHosts()).andReturn(hosts).anyTimes();
+
+    expect(clusters.getCluster("Cluster100")).andReturn(cluster).anyTimes();
+
+    expect(clusters.getClustersForHost("Host100")).andReturn(clusterSet).anyTimes();
+
+    expect(cluster.getDesiredStackVersion()).andReturn(stackId);
+
+    expect(host1.getHostName()).andReturn("Host100").anyTimes();
+
+    expect(host1.convertToResponse()).andReturn(hostResponse1);
+
+    expect(hostResponse1.getClusterName()).andReturn("Cluster100").anyTimes();
+    expect(hostResponse1.getHostname()).andReturn("Host100").anyTimes();
+    expect(hostResponse1.getHealthStatus()).andReturn(healthStatus).anyTimes();
+
+    expect(healthStatus.getHealthStatus()).andReturn(HostHealthStatus.HealthStatus.HEALTHY).anyTimes();
+    expect(healthStatus.getHealthReport()).andReturn("HEALTHY").anyTimes();
+
+
+    expect(ambariMetaInfo.getComponentCategory((String) anyObject(), (String) anyObject(),
+        (String) anyObject(), (String) anyObject())).andReturn(componentInfo).anyTimes();
+
+    expect(componentInfo.getCategory()).andReturn("SLAVE").anyTimes();
+
+
+    // replay
+    replay(managementController, clusters, cluster,
+        host1,
+        hostResponse1, stackId, componentInfo,
+        healthStatus, ambariMetaInfo);
+
+    ResourceProvider provider = AbstractControllerResourceProvider.getResourceProvider(
+        type,
+        PropertyHelper.getPropertyIds(type),
+        PropertyHelper.getKeyPropertyIds(type),
+        managementController);
+
+    Set<String> propertyIds = new HashSet<String>();
+
+    propertyIds.add(HostResourceProvider.HOST_CLUSTER_NAME_PROPERTY_ID);
+    propertyIds.add(HostResourceProvider.HOST_NAME_PROPERTY_ID);
+    propertyIds.add(HostResourceProvider.HOST_HOST_STATUS_PROPERTY_ID);
+
+    Predicate predicate =
+        new PredicateBuilder().property(HostResourceProvider.HOST_CLUSTER_NAME_PROPERTY_ID).equals("Cluster100").
+            toPredicate();
+    Request request = PropertyHelper.getReadRequest(propertyIds);
+    Set<Resource> resources = provider.getResources(request, predicate);
+
+    Assert.assertEquals(1, resources.size());
+    for (Resource resource : resources) {
+      String clusterName = (String) resource.getPropertyValue(HostResourceProvider.HOST_CLUSTER_NAME_PROPERTY_ID);
+      Assert.assertEquals("Cluster100", clusterName);
+      String status = (String) resource.getPropertyValue(HostResourceProvider.HOST_HOST_STATUS_PROPERTY_ID);
+      Assert.assertEquals("ALERT", status);
+    }
+
+    // verify
+    verify(managementController, clusters, cluster,
+        host1,
+        hostResponse1, stackId, componentInfo,
+        healthStatus, ambariMetaInfo);
+  }
+
   @Test
   public void testUpdateDesiredConfig() throws Exception {
 
     AmbariManagementController managementController = createMock(AmbariManagementController.class);
-    RequestStatusResponse response = createNiceMock(RequestStatusResponse.class);
+    Clusters clusters = createNiceMock(Clusters.class);
+    Cluster cluster = createNiceMock(Cluster.class);
+    Host host1 = createNiceMock(Host.class);
+    HostHealthStatus healthStatus = createNiceMock(HostHealthStatus.class);
+    AmbariMetaInfo ambariMetaInfo = createNiceMock(AmbariMetaInfo.class);
 
-    HostResponse hr = new HostResponse("Host100", "Cluster100",
-        "", "", 2, 1, "", "", "", 100000L, 200000L, null, 10L,
-        0L, "rack info", null, null,
-        new HostHealthStatus(HostHealthStatus.HealthStatus.HEALTHY, "HEALTHY"), "HEALTHY");
-    
-    Set<HostResponse> hostResponseSet = new HashSet<HostResponse>();
-    hostResponseSet.add(hr);
+    HostResponse hostResponse1 = createNiceMock(HostResponse.class);
+
+    List<Host> hosts = new LinkedList<Host>();
+    hosts.add(host1);
+
+    Set<Cluster> clusterSet = new HashSet<Cluster>();
+    clusterSet.add(cluster);
 
     // set expectations
-    expect(managementController.getHosts(
-        AbstractResourceProviderTest.Matcher.getHostRequestSet("Host100", "Cluster100", null))).
-        andReturn(hostResponseSet);
-    managementController.updateHosts(EasyMock.<Set<HostRequest>>anyObject());
+    expect(managementController.getClusters()).andReturn(clusters).anyTimes();
+    expect(managementController.getAmbariMetaInfo()).andReturn(ambariMetaInfo).anyTimes();
+    expect(managementController.getHostComponents((Set<ServiceComponentHostRequest>) anyObject())).andReturn(Collections.<ServiceComponentHostResponse>emptySet()).anyTimes();
+
+    expect(clusters.getHosts()).andReturn(hosts).anyTimes();
+    expect(clusters.getHost("Host100")).andReturn(host1).anyTimes();
+
+    expect(clusters.getCluster("Cluster100")).andReturn(cluster).anyTimes();
+
+    expect(clusters.getClustersForHost("Host100")).andReturn(clusterSet).anyTimes();
+
+    expect(host1.getHostName()).andReturn("Host100").anyTimes();
+
+    expect(host1.convertToResponse()).andReturn(hostResponse1);
+
+    expect(hostResponse1.getClusterName()).andReturn("Cluster100").anyTimes();
+    expect(hostResponse1.getHostname()).andReturn("Host100").anyTimes();
+    expect(hostResponse1.getHealthStatus()).andReturn(healthStatus).anyTimes();
+
+    expect(healthStatus.getHealthStatus()).andReturn(HostHealthStatus.HealthStatus.HEALTHY).anyTimes();
+    expect(healthStatus.getHealthReport()).andReturn("HEALTHY").anyTimes();
 
     // replay
-    replay(managementController, response);
-    
+    replay(managementController, clusters, cluster,
+        host1,
+        hostResponse1,
+        healthStatus, ambariMetaInfo);
 
     Map<String, Object> properties = new LinkedHashMap<String, Object>();
 
@@ -199,7 +659,10 @@ public class HostResourceProviderTest {
     provider.updateResources(request, predicate);
     
     // verify
-    verify(managementController, response);    
+    verify(managementController, clusters, cluster,
+        host1,
+        hostResponse1,
+        healthStatus, ambariMetaInfo);
   }
 
   @Test
@@ -207,22 +670,49 @@ public class HostResourceProviderTest {
     Resource.Type type = Resource.Type.Host;
 
     AmbariManagementController managementController = createMock(AmbariManagementController.class);
-    RequestStatusResponse response = createNiceMock(RequestStatusResponse.class);
+    Clusters clusters = createNiceMock(Clusters.class);
+    Cluster cluster = createNiceMock(Cluster.class);
+    Host host1 = createNiceMock(Host.class);
+    HostHealthStatus healthStatus = createNiceMock(HostHealthStatus.class);
+    AmbariMetaInfo ambariMetaInfo = createNiceMock(AmbariMetaInfo.class);
+
+    HostResponse hostResponse1 = createNiceMock(HostResponse.class);
+
+    List<Host> hosts = new LinkedList<Host>();
+    hosts.add(host1);
 
-    Set<HostResponse> hostResponseSet = new HashSet<HostResponse>();
-    hostResponseSet.add(new HostResponse("Host100", "Cluster100",
-        "", "", 2, 1, "", "", "", 100000L, 200000L, null, 10L,
-        0L, "rack info", null, null,
-        new HostHealthStatus(HostHealthStatus.HealthStatus.HEALTHY, "HEALTHY"), "HEALTHY"));
+    Set<Cluster> clusterSet = new HashSet<Cluster>();
+    clusterSet.add(cluster);
 
     // set expectations
-    expect(managementController.getHosts(
-        AbstractResourceProviderTest.Matcher.getHostRequestSet("Host100", "Cluster100", null))).
-        andReturn(hostResponseSet);
-    managementController.updateHosts(EasyMock.<Set<HostRequest>>anyObject());
+    expect(managementController.getClusters()).andReturn(clusters).anyTimes();
+    expect(managementController.getAmbariMetaInfo()).andReturn(ambariMetaInfo).anyTimes();
+    expect(managementController.getHostComponents((Set<ServiceComponentHostRequest>) anyObject())).andReturn(Collections.<ServiceComponentHostResponse>emptySet()).anyTimes();
+
+    expect(clusters.getHosts()).andReturn(hosts).anyTimes();
+    expect(clusters.getHost("Host100")).andReturn(host1).anyTimes();
+
+    expect(clusters.getCluster("Cluster100")).andReturn(cluster).anyTimes();
+
+    expect(clusters.getClustersForHost("Host100")).andReturn(clusterSet).anyTimes();
+
+    expect(host1.getHostName()).andReturn("Host100").anyTimes();
+
+    expect(host1.convertToResponse()).andReturn(hostResponse1);
+
+    expect(hostResponse1.getClusterName()).andReturn("Cluster100").anyTimes();
+    expect(hostResponse1.getHostname()).andReturn("Host100").anyTimes();
+    expect(hostResponse1.getHealthStatus()).andReturn(healthStatus).anyTimes();
+
+    expect(healthStatus.getHealthStatus()).andReturn(HostHealthStatus.HealthStatus.HEALTHY).anyTimes();
+    expect(healthStatus.getHealthReport()).andReturn("HEALTHY").anyTimes();
 
     // replay
-    replay(managementController, response);
+    replay(managementController, clusters, cluster,
+        host1,
+        hostResponse1,
+        healthStatus, ambariMetaInfo);
+
 
     ResourceProvider provider = AbstractControllerResourceProvider.getResourceProvider(
         type,
@@ -244,7 +734,10 @@ public class HostResourceProviderTest {
     provider.updateResources(request, predicate);
 
     // verify
-    verify(managementController, response);
+    verify(managementController, clusters, cluster,
+        host1,
+        hostResponse1,
+        healthStatus, ambariMetaInfo);
   }
 
   @Test
@@ -252,12 +745,34 @@ public class HostResourceProviderTest {
     Resource.Type type = Resource.Type.Host;
 
     AmbariManagementController managementController = createMock(AmbariManagementController.class);
+    Clusters clusters = createNiceMock(Clusters.class);
+    Cluster cluster = createNiceMock(Cluster.class);
+    Host host1 = createNiceMock(Host.class);
+    HostHealthStatus healthStatus = createNiceMock(HostHealthStatus.class);
+
+    List<Host> hosts = new LinkedList<Host>();
+    hosts.add(host1);
+
+    Set<Cluster> clusterSet = new HashSet<Cluster>();
 
     // set expectations
-    managementController.deleteHosts(AbstractResourceProviderTest.Matcher.getHostRequestSet("Host100", null, null));
+    expect(managementController.getClusters()).andReturn(clusters).anyTimes();
+    expect(clusters.getHosts()).andReturn(hosts).anyTimes();
+    expect(clusters.getHost("Host100")).andReturn(host1).anyTimes();
+
+    expect(clusters.getCluster("Cluster100")).andReturn(cluster).anyTimes();
+
+    expect(clusters.getClustersForHost("Host100")).andReturn(clusterSet).anyTimes();
+
+    expect(host1.getHostName()).andReturn("Host100").anyTimes();
+
+    expect(healthStatus.getHealthStatus()).andReturn(HostHealthStatus.HealthStatus.HEALTHY).anyTimes();
+    expect(healthStatus.getHealthReport()).andReturn("HEALTHY").anyTimes();
 
     // replay
-    replay(managementController);
+    replay(managementController, clusters, cluster,
+        host1,
+        healthStatus);
 
     ResourceProvider provider = AbstractControllerResourceProvider.getResourceProvider(
         type,
@@ -282,6 +797,239 @@ public class HostResourceProviderTest {
     Assert.assertNull(lastEvent.getRequest());
 
     // verify
-    verify(managementController);
+    verify(managementController, clusters, cluster,
+        host1,
+        healthStatus);
+  }
+
+  public static HostResourceProvider getHostProvider(AmbariManagementController managementController) {
+    Resource.Type type = Resource.Type.Host;
+
+    return (HostResourceProvider) AbstractControllerResourceProvider.getResourceProvider(
+        type,
+        PropertyHelper.getPropertyIds(type),
+        PropertyHelper.getKeyPropertyIds(type),
+        managementController);
+  }
+
+  @Test
+  public void testGetHosts() throws Exception {
+    // member state mocks
+    Injector injector = createStrictMock(Injector.class);
+    Capture<AmbariManagementController> controllerCapture = new Capture<AmbariManagementController>();
+    Clusters clusters = createNiceMock(Clusters.class);
+
+    Cluster cluster = createNiceMock(Cluster.class);
+    Host host = createNiceMock(Host.class);
+    HostResponse response = createNiceMock(HostResponse.class);
+
+    Set<Cluster> setCluster = Collections.singleton(cluster);
+
+    // requests
+    HostRequest request1 = new HostRequest("host1", "cluster1", Collections.<String, String>emptyMap());
+
+    Set<HostRequest> setRequests = new HashSet<HostRequest>();
+    setRequests.add(request1);
+
+    // expectations
+    // constructor init
+    injector.injectMembers(capture(controllerCapture));
+    expect(injector.getInstance(Gson.class)).andReturn(null);
+
+    // getHosts
+    expect(clusters.getCluster("cluster1")).andReturn(cluster);
+    expect(clusters.getHost("host1")).andReturn(host);
+    expect(host.getHostName()).andReturn("host1").anyTimes();
+    expect(clusters.getClustersForHost("host1")).andReturn(setCluster);
+    expect(host.convertToResponse()).andReturn(response);
+    response.setClusterName("cluster1");
+
+    // replay mocks
+    replay(injector, clusters, cluster, host, response);
+
+    //test
+    AmbariManagementController controller = new AmbariManagementControllerImpl(null, clusters, injector);
+    Set<HostResponse> setResponses = getHosts(controller, setRequests);
+
+    // assert and verify
+    assertSame(controller, controllerCapture.getValue());
+    assertEquals(1, setResponses.size());
+    assertTrue(setResponses.contains(response));
+
+    verify(injector, clusters, cluster, host, response);
+  }
+
+  /**
+   * Ensure that HostNotFoundException is propagated in case where there is a single request.
+   */
+  @Test
+  public void testGetHosts___HostNotFoundException() throws Exception {
+    // member state mocks
+    Injector injector = createStrictMock(Injector.class);
+    Capture<AmbariManagementController> controllerCapture = new Capture<AmbariManagementController>();
+    Clusters clusters = createNiceMock(Clusters.class);
+
+    Cluster cluster = createNiceMock(Cluster.class);
+
+    // requests
+    HostRequest request1 = new HostRequest("host1", "cluster1", Collections.<String, String>emptyMap());
+    Set<HostRequest> setRequests = Collections.singleton(request1);
+
+    // expectations
+    // constructor init
+    injector.injectMembers(capture(controllerCapture));
+    expect(injector.getInstance(Gson.class)).andReturn(null);
+
+    // getHosts
+    expect(clusters.getCluster("cluster1")).andReturn(cluster);
+    expect(clusters.getHost("host1")).andThrow(new HostNotFoundException("host1"));
+
+    // replay mocks
+    replay(injector, clusters, cluster);
+
+    //test
+    AmbariManagementController controller = new AmbariManagementControllerImpl(null, clusters, injector);
+
+    // assert that exception is thrown in case where there is a single request
+    try {
+      getHosts(controller, setRequests);
+      fail("expected HostNotFoundException");
+    } catch (HostNotFoundException e) {
+      // expected
+    }
+    assertSame(controller, controllerCapture.getValue());
+    verify(injector, clusters, cluster);
+  }
+
+  /**
+   * Ensure that HostNotFoundException is propagated in case where there is a single request.
+   */
+  @Test
+  public void testGetHosts___HostNotFoundException_HostNotAssociatedWithCluster() throws Exception {
+    // member state mocks
+    Injector injector = createStrictMock(Injector.class);
+    Capture<AmbariManagementController> controllerCapture = new Capture<AmbariManagementController>();
+    Clusters clusters = createNiceMock(Clusters.class);
+
+    Cluster cluster = createNiceMock(Cluster.class);
+    Host host = createNiceMock(Host.class);
+
+    // requests
+    HostRequest request1 = new HostRequest("host1", "cluster1", Collections.<String, String>emptyMap());
+    Set<HostRequest> setRequests = Collections.singleton(request1);
+
+    // expectations
+    // constructor init
+    injector.injectMembers(capture(controllerCapture));
+    expect(injector.getInstance(Gson.class)).andReturn(null);
+
+    // getHosts
+    expect(clusters.getCluster("cluster1")).andReturn(cluster);
+    expect(clusters.getHost("host1")).andReturn(host);
+    expect(host.getHostName()).andReturn("host1").anyTimes();
+    // because cluster is not in set will result in HostNotFoundException
+    expect(clusters.getClustersForHost("host1")).andReturn(Collections.<Cluster>emptySet());
+
+    // replay mocks
+    replay(injector, clusters, cluster, host);
+
+    //test
+    AmbariManagementController controller = new AmbariManagementControllerImpl(null, clusters, injector);
+
+    // assert that exception is thrown in case where there is a single request
+    try {
+      getHosts(controller, setRequests);
+      fail("expected HostNotFoundException");
+    } catch (HostNotFoundException e) {
+      // expected
+    }
+    assertSame(controller, controllerCapture.getValue());
+    verify(injector, clusters, cluster, host);
+  }
+
+
+  /**
+   * Ensure that HostNotFoundException is handled where there are multiple requests as would be the
+   * case when an OR predicate is provided in the query.
+   */
+  @Test
+  public void testGetHosts___OR_Predicate_HostNotFoundException() throws Exception {
+    // member state mocks
+    Injector injector = createStrictMock(Injector.class);
+    Capture<AmbariManagementController> controllerCapture = new Capture<AmbariManagementController>();
+    Clusters clusters = createNiceMock(Clusters.class);
+
+    Cluster cluster = createNiceMock(Cluster.class);
+    Host host1 = createNiceMock(Host.class);
+    Host host2 = createNiceMock(Host.class);
+    HostResponse response = createNiceMock(HostResponse.class);
+    HostResponse response2 = createNiceMock(HostResponse.class);
+
+    // requests
+    HostRequest request1 = new HostRequest("host1", "cluster1", Collections.<String, String>emptyMap());
+    HostRequest request2 = new HostRequest("host2", "cluster1", Collections.<String, String>emptyMap());
+    HostRequest request3 = new HostRequest("host3", "cluster1", Collections.<String, String>emptyMap());
+    HostRequest request4 = new HostRequest("host4", "cluster1", Collections.<String, String>emptyMap());
+
+    Set<HostRequest> setRequests = new HashSet<HostRequest>();
+    setRequests.add(request1);
+    setRequests.add(request2);
+    setRequests.add(request3);
+    setRequests.add(request4);
+
+    // expectations
+    // constructor init
+    injector.injectMembers(capture(controllerCapture));
+    expect(injector.getInstance(Gson.class)).andReturn(null);
+
+    // getHosts
+    expect(clusters.getCluster("cluster1")).andReturn(cluster).times(4);
+
+    expect(clusters.getHost("host1")).andReturn(host1);
+    expect(host1.getHostName()).andReturn("host1").anyTimes();
+    expect(clusters.getClustersForHost("host1")).andReturn(Collections.singleton(cluster));
+    expect(host1.convertToResponse()).andReturn(response);
+    response.setClusterName("cluster1");
+
+    expect(clusters.getHost("host2")).andReturn(host2);
+    expect(host2.getHostName()).andReturn("host2").anyTimes();
+    expect(clusters.getClustersForHost("host2")).andReturn(Collections.singleton(cluster));
+    expect(host2.convertToResponse()).andReturn(response2);
+    response2.setClusterName("cluster1");
+
+    expect(clusters.getHost("host3")).andThrow(new HostNotFoundException("host3"));
+    expect(clusters.getHost("host4")).andThrow(new HostNotFoundException("host4"));
+
+    // replay mocks
+    replay(injector, clusters, cluster, host1, host2, response, response2);
+
+    //test
+    AmbariManagementController controller = new AmbariManagementControllerImpl(null, clusters, injector);
+    Set<HostResponse> setResponses = getHosts(controller, setRequests);
+
+    // assert and verify
+    assertSame(controller, controllerCapture.getValue());
+    assertEquals(2, setResponses.size());
+    assertTrue(setResponses.contains(response));
+    assertTrue(setResponses.contains(response2));
+
+    verify(injector, clusters, cluster, host1, host2, response, response2);
+  }
+
+  public static void createHosts(AmbariManagementController controller, Set<HostRequest> requests) throws AmbariException {
+    HostResourceProvider provider = getHostProvider(controller);
+    provider.createHosts(requests);
+  }
+
+  public static Set<HostResponse> getHosts(AmbariManagementController controller,
+                                                 Set<HostRequest> requests) throws AmbariException {
+    HostResourceProvider provider = getHostProvider(controller);
+    return provider.getHosts(requests);
+  }
+
+  public static void deleteHosts(AmbariManagementController controller, Set<HostRequest> requests)
+      throws AmbariException {
+    HostResourceProvider provider = getHostProvider(controller);
+    provider.deleteHosts(requests);
   }
 }

http://git-wip-us.apache.org/repos/asf/incubator-ambari/blob/69010c80/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/RootServiceHostComponentResourceProviderTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/RootServiceHostComponentResourceProviderTest.java b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/RootServiceHostComponentResourceProviderTest.java
index baa6178..cb7051c 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/RootServiceHostComponentResourceProviderTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/RootServiceHostComponentResourceProviderTest.java
@@ -19,26 +19,31 @@
 
 package org.apache.ambari.server.controller.internal;
 
+import static org.easymock.EasyMock.anyObject;
 import static org.easymock.EasyMock.createMock;
+import static org.easymock.EasyMock.createNiceMock;
 import static org.easymock.EasyMock.expect;
 import static org.easymock.EasyMock.replay;
 import static org.easymock.EasyMock.verify;
 
-import java.util.Collections;
 import java.util.HashSet;
+import java.util.LinkedList;
+import java.util.List;
 import java.util.Set;
 
+import org.apache.ambari.server.controller.AbstractRootServiceResponseFactory;
 import org.apache.ambari.server.controller.AmbariManagementController;
+import org.apache.ambari.server.controller.HostResponse;
 import org.apache.ambari.server.controller.RootServiceHostComponentRequest;
 import org.apache.ambari.server.controller.RootServiceHostComponentResponse;
-import org.apache.ambari.server.controller.spi.Predicate;
 import org.apache.ambari.server.controller.spi.Request;
 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.easymock.EasyMock;
-import org.junit.Assert;
+import org.apache.ambari.server.state.Cluster;
+import org.apache.ambari.server.state.Clusters;
+import org.apache.ambari.server.state.Host;
+import org.apache.ambari.server.state.HostHealthStatus;
 import org.junit.Test;
 
 public class RootServiceHostComponentResourceProviderTest {
@@ -48,21 +53,55 @@ public class RootServiceHostComponentResourceProviderTest {
     Resource.Type type = Resource.Type.RootServiceHostComponent;
 
     AmbariManagementController managementController = createMock(AmbariManagementController.class);
+    Clusters clusters = createNiceMock(Clusters.class);
+    Cluster cluster = createNiceMock(Cluster.class);
+    Host host1 = createNiceMock(Host.class);
+    HostHealthStatus healthStatus = createNiceMock(HostHealthStatus.class);
 
-    Set<RootServiceHostComponentResponse> allResponse = new HashSet<RootServiceHostComponentResponse>();
-    allResponse.add(new RootServiceHostComponentResponse("host1", "component1", "HEALTHY", "1.1.1", Collections.<String,String>emptyMap()));
-    allResponse.add(new RootServiceHostComponentResponse("host2", "component2", "HEALTHY", "1.1.1", Collections.<String,String>emptyMap()));
-    allResponse.add(new RootServiceHostComponentResponse("host3", "component3", "HEARBEAT_LOST", "1.1.1", Collections.<String,String>emptyMap()));
+    HostResponse hostResponse1 = createNiceMock(HostResponse.class);
 
-    Set<RootServiceHostComponentResponse> nameResponse = new HashSet<RootServiceHostComponentResponse>();
-    nameResponse.add(new RootServiceHostComponentResponse("host4", "component4", "HEALTHY", "1.1.1", Collections.<String,String>emptyMap()));
+    RootServiceHostComponentResponse response = createNiceMock(RootServiceHostComponentResponse.class);
 
+    AbstractRootServiceResponseFactory factory = createNiceMock(AbstractRootServiceResponseFactory.class);
+
+    List<Host> hosts = new LinkedList<Host>();
+    hosts.add(host1);
+
+    Set<Cluster> clusterSet = new HashSet<Cluster>();
+    clusterSet.add(cluster);
+
+    Set<RootServiceHostComponentResponse> responseSet = new HashSet<RootServiceHostComponentResponse>();
+    responseSet.add(response);
 
     // set expectations
-    expect(managementController.getRootServiceHostComponents(EasyMock.<Set<RootServiceHostComponentRequest>>anyObject())).andReturn(allResponse).once();
-    expect(managementController.getRootServiceHostComponents(EasyMock.<Set<RootServiceHostComponentRequest>>anyObject())).andReturn(nameResponse).once();
+    expect(managementController.getRootServiceResponseFactory()).andReturn(factory).anyTimes();
+    expect(managementController.getClusters()).andReturn(clusters).anyTimes();
+    expect(clusters.getHosts()).andReturn(hosts).anyTimes();
+
+    expect(factory.getRootServiceHostComponent((RootServiceHostComponentRequest) anyObject(), (Set<HostResponse>) anyObject())).
+        andReturn(responseSet).anyTimes();
+
+    expect(clusters.getCluster("Cluster100")).andReturn(cluster).anyTimes();
+
+    expect(clusters.getClustersForHost("Host100")).andReturn(clusterSet).anyTimes();
+
+    expect(host1.getHostName()).andReturn("Host100").anyTimes();
+
+    expect(host1.convertToResponse()).andReturn(hostResponse1).anyTimes();
+
+    expect(hostResponse1.getClusterName()).andReturn("Cluster100").anyTimes();
+    expect(hostResponse1.getHostname()).andReturn("Host100").anyTimes();
+    expect(hostResponse1.getHealthStatus()).andReturn(healthStatus).anyTimes();
+
+    expect(healthStatus.getHealthStatus()).andReturn(HostHealthStatus.HealthStatus.HEALTHY).anyTimes();
+    expect(healthStatus.getHealthReport()).andReturn("HEALTHY").anyTimes();
+
     // replay
-    replay(managementController);
+    replay(managementController, clusters, cluster,
+        host1,
+        hostResponse1,
+        healthStatus, factory, response);
+
 
     ResourceProvider provider = AbstractControllerResourceProvider.getResourceProvider(
         type,
@@ -79,36 +118,17 @@ public class RootServiceHostComponentResourceProviderTest {
     propertyIds.add(RootServiceHostComponentResourceProvider.PROPERTIES_PROPERTY_ID);
     propertyIds.add(RootServiceHostComponentResourceProvider.COMPONENT_VERSION_PROPERTY_ID);
     
-    
     // create the request
     Request request = PropertyHelper.getReadRequest(propertyIds);
 
     // get all ... no predicate
-    Set<Resource> resources = provider.getResources(request, null);
-
-    Assert.assertEquals(allResponse.size(), resources.size());
-    for (Resource resource : resources) {
-      String hostName = (String) resource.getPropertyValue(RootServiceHostComponentResourceProvider.HOST_NAME_PROPERTY_ID);
-      String componentName = (String) resource.getPropertyValue(RootServiceHostComponentResourceProvider.COMPONENT_NAME_PROPERTY_ID);
-      String componentState = (String) resource.getPropertyValue(RootServiceHostComponentResourceProvider.COMPONENT_STATE_PROPERTY_ID);
-      String componentVersion = (String) resource.getPropertyValue(RootServiceHostComponentResourceProvider.COMPONENT_VERSION_PROPERTY_ID);
-      Assert.assertTrue(allResponse.contains(new RootServiceHostComponentResponse(hostName, componentName, componentState, componentVersion,
-          Collections.<String, String>emptyMap())));
-    }
-
-    // get service named service4
-    Predicate predicate =
-        new PredicateBuilder().property(RootServiceHostComponentResourceProvider.COMPONENT_NAME_PROPERTY_ID).
-        equals("component4").toPredicate();
-    resources = provider.getResources(request, predicate);
-
-    Assert.assertEquals(1, resources.size());
-    Assert.assertEquals("component4", resources.iterator().next().
-        getPropertyValue(RootServiceHostComponentResourceProvider.COMPONENT_NAME_PROPERTY_ID));
-
+    provider.getResources(request, null);
 
     // verify
-    verify(managementController);
+    verify(managementController, clusters, cluster,
+        host1,
+        hostResponse1,
+        healthStatus, factory, response);
   }
 
 }


Mime
View raw message