You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by sw...@apache.org on 2014/03/11 01:09:36 UTC
git commit: AMBARI-5005. API call to get host status takes 30
seconds. (swagle)
Repository: ambari
Updated Branches:
refs/heads/trunk f53763b37 -> 1e83c740d
AMBARI-5005. API call to get host status takes 30 seconds. (swagle)
Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/1e83c740
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/1e83c740
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/1e83c740
Branch: refs/heads/trunk
Commit: 1e83c740d2ddec7e8f3225b3cd2674eace26ef9c
Parents: f53763b
Author: Siddharth Wagle <sw...@hortonworks.com>
Authored: Mon Mar 10 17:09:23 2014 -0700
Committer: Siddharth Wagle <sw...@hortonworks.com>
Committed: Mon Mar 10 17:09:23 2014 -0700
----------------------------------------------------------------------
.../ambari/server/agent/HeartBeatHandler.java | 2 +-
.../AmbariManagementControllerImpl.java | 47 +++--
.../controller/MaintenanceStateHelper.java | 33 +++-
.../server/state/ServiceComponentImpl.java | 3 +-
.../server/state/cluster/ClustersImpl.java | 2 +-
.../ambari/server/state/host/HostImpl.java | 8 +-
.../AmbariManagementControllerImplTest.java | 175 +++++++++++++------
.../AmbariManagementControllerTest.java | 14 +-
.../internal/ComponentResourceProviderTest.java | 6 +-
.../internal/HostResourceProviderTest.java | 21 ++-
10 files changed, 214 insertions(+), 97 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ambari/blob/1e83c740/ambari-server/src/main/java/org/apache/ambari/server/agent/HeartBeatHandler.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/agent/HeartBeatHandler.java b/ambari-server/src/main/java/org/apache/ambari/server/agent/HeartBeatHandler.java
index b0258a4..9461965 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/agent/HeartBeatHandler.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/agent/HeartBeatHandler.java
@@ -258,7 +258,7 @@ public class HeartBeatHandler {
String category = componentInfo.getCategory();
- if (MaintenanceState.OFF == psh.getEffectiveState(scHost)) {
+ if (MaintenanceState.OFF == psh.getEffectiveState(scHost, host)) {
if (category.equals("MASTER")) {
++masterCount;
if (status.equals("STARTED")) {
http://git-wip-us.apache.org/repos/asf/ambari/blob/1e83c740/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariManagementControllerImpl.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariManagementControllerImpl.java b/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariManagementControllerImpl.java
index 69b58f7..5f85d83 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariManagementControllerImpl.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariManagementControllerImpl.java
@@ -189,6 +189,8 @@ public class AmbariManagementControllerImpl implements AmbariManagementControlle
@Inject
private ExecutionScheduleManager executionScheduleManager;
+ private MaintenanceStateHelper maintenanceStateHelper;
+
final private String masterHostname;
final private Integer masterPort;
final private String masterProtocol;
@@ -222,6 +224,7 @@ public class AmbariManagementControllerImpl implements AmbariManagementControlle
this.gson = injector.getInstance(Gson.class);
LOG.info("Initializing the AmbariManagementControllerImpl");
this.masterHostname = InetAddress.getLocalHost().getCanonicalHostName();
+ this.maintenanceStateHelper = injector.getInstance(MaintenanceStateHelper.class);
if(configs != null)
{
@@ -717,7 +720,9 @@ public class AmbariManagementControllerImpl implements AmbariManagementControlle
}
checkDesiredState = true;
}
-
+
+ Map<String, Host> hosts = clusters.getHostsForCluster(cluster.getClusterName());
+
for (Service s : services) {
// filter on component name if provided
Set<ServiceComponent> components = new HashSet<ServiceComponent>();
@@ -736,12 +741,20 @@ public class AmbariManagementControllerImpl implements AmbariManagementControlle
// filter on hostname if provided
// filter on desired state if provided
+ Map<String, ServiceComponentHost> serviceComponentHostMap =
+ sc.getServiceComponentHosts();
+
if (request.getHostname() != null) {
try {
- ServiceComponentHost sch = sc.getServiceComponentHost(
- request.getHostname());
- if (checkDesiredState
- && (desiredStateToCheck != sch.getDesiredState())) {
+ if (serviceComponentHostMap == null
+ || !serviceComponentHostMap.containsKey(request.getHostname())) {
+ throw new ServiceComponentHostNotFoundException(cluster.getClusterName(),
+ s.getName(), sc.getName(), request.getHostname());
+ }
+
+ ServiceComponentHost sch = serviceComponentHostMap.get(request.getHostname());
+
+ if (checkDesiredState && (desiredStateToCheck != sch.getDesiredState())) {
continue;
}
if (request.getAdminState() != null) {
@@ -756,7 +769,13 @@ public class AmbariManagementControllerImpl implements AmbariManagementControlle
if (filterBasedConfigStaleness && r.isStaleConfig() != staleConfig) {
continue;
}
- r.setMaintenanceState(getEffectiveMaintenanceState(sch).name());
+
+ Host host = hosts.get(sch.getHostName());
+ if (host == null) {
+ throw new HostNotFoundException(cluster.getClusterName(), sch.getHostName());
+ }
+
+ r.setMaintenanceState(maintenanceStateHelper.getEffectiveState(sch, host).name());
response.add(r);
} catch (ServiceComponentHostNotFoundException e) {
if (request.getServiceName() != null && request.getComponentName() != null) {
@@ -769,10 +788,8 @@ public class AmbariManagementControllerImpl implements AmbariManagementControlle
}
}
} else {
- for (ServiceComponentHost sch :
- sc.getServiceComponentHosts().values()) {
- if (checkDesiredState
- && (desiredStateToCheck != sch.getDesiredState())) {
+ for (ServiceComponentHost sch : serviceComponentHostMap.values()) {
+ if (checkDesiredState && (desiredStateToCheck != sch.getDesiredState())) {
continue;
}
@@ -788,8 +805,13 @@ public class AmbariManagementControllerImpl implements AmbariManagementControlle
if (filterBasedConfigStaleness && r.isStaleConfig() != staleConfig) {
continue;
}
+
+ Host host = hosts.get(sch.getHostName());
+ if (host == null) {
+ throw new HostNotFoundException(cluster.getClusterName(), sch.getHostName());
+ }
- r.setMaintenanceState(getEffectiveMaintenanceState(sch).name());
+ r.setMaintenanceState(maintenanceStateHelper.getEffectiveState(sch, host).name());
response.add(r);
}
}
@@ -801,9 +823,8 @@ public class AmbariManagementControllerImpl implements AmbariManagementControlle
@Override
public MaintenanceState getEffectiveMaintenanceState(ServiceComponentHost sch)
throws AmbariException {
- MaintenanceStateHelper msh = injector.getInstance(MaintenanceStateHelper.class);
- return msh.getEffectiveState(sch);
+ return maintenanceStateHelper.getEffectiveState(sch);
}
http://git-wip-us.apache.org/repos/asf/ambari/blob/1e83c740/ambari-server/src/main/java/org/apache/ambari/server/controller/MaintenanceStateHelper.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/MaintenanceStateHelper.java b/ambari-server/src/main/java/org/apache/ambari/server/controller/MaintenanceStateHelper.java
index 2b30b9f..833e176 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/controller/MaintenanceStateHelper.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/MaintenanceStateHelper.java
@@ -55,25 +55,40 @@ public class MaintenanceStateHelper {
}
/**
- * Gets the effective state for a HostComponents
+ * Get effective state of HostComponent
* @param sch the host component
+ * @param host the host
* @return the maintenance state
* @throws AmbariException
*/
- public MaintenanceState getEffectiveState(ServiceComponentHost sch) throws AmbariException {
+ public MaintenanceState getEffectiveState(ServiceComponentHost sch,
+ Host host) throws AmbariException {
Cluster cluster = clusters.getCluster(sch.getClusterName());
Service service = cluster.getService(sch.getServiceName());
-
- Map<String, Host> map = clusters.getHostsForCluster(cluster.getClusterName());
- if (null == map)
- return MaintenanceState.OFF;
-
- Host host = clusters.getHostsForCluster(cluster.getClusterName()).get(sch.getHostName());
+
if (null == host) // better not
throw new HostNotFoundException(cluster.getClusterName(), sch.getHostName());
-
+
return getEffectiveState(cluster.getClusterId(), service, host, sch);
}
+
+ /**
+ * Gets the effective state for a HostComponent
+ * @param sch the host component
+ * @return the maintenance state
+ * @throws AmbariException
+ */
+ public MaintenanceState getEffectiveState(ServiceComponentHost sch) throws AmbariException {
+ Cluster cluster = clusters.getCluster(sch.getClusterName());
+
+ Map<String, Host> map = clusters.getHostsForCluster(cluster.getClusterName());
+ if (null == map)
+ return MaintenanceState.OFF;
+
+ Host host = map.get(sch.getHostName());
+
+ return getEffectiveState(sch, host);
+ }
/**
* @param clusterId the cluster id
http://git-wip-us.apache.org/repos/asf/ambari/blob/1e83c740/ambari-server/src/main/java/org/apache/ambari/server/state/ServiceComponentImpl.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/state/ServiceComponentImpl.java b/ambari-server/src/main/java/org/apache/ambari/server/state/ServiceComponentImpl.java
index 9226cf1..7d22584 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/state/ServiceComponentImpl.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/state/ServiceComponentImpl.java
@@ -204,8 +204,7 @@ public class ServiceComponentImpl implements ServiceComponent {
}
@Override
- public Map<String, ServiceComponentHost>
- getServiceComponentHosts() {
+ public Map<String, ServiceComponentHost> getServiceComponentHosts() {
clusterGlobalLock.readLock().lock();
try {
readWriteLock.readLock().lock();
http://git-wip-us.apache.org/repos/asf/ambari/blob/1e83c740/ambari-server/src/main/java/org/apache/ambari/server/state/cluster/ClustersImpl.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/state/cluster/ClustersImpl.java b/ambari-server/src/main/java/org/apache/ambari/server/state/cluster/ClustersImpl.java
index 24e5b1a..64fabf5 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/state/cluster/ClustersImpl.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/state/cluster/ClustersImpl.java
@@ -103,7 +103,7 @@ public class ClustersImpl implements Clusters {
LOG.info("Initializing the ClustersImpl");
}
- void checkLoaded() {
+ void checkLoaded() {
if (!clustersLoaded) {
w.lock();
try {
http://git-wip-us.apache.org/repos/asf/ambari/blob/1e83c740/ambari-server/src/main/java/org/apache/ambari/server/state/host/HostImpl.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/state/host/HostImpl.java b/ambari-server/src/main/java/org/apache/ambari/server/state/host/HostImpl.java
index d151e8b..319b288 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/state/host/HostImpl.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/state/host/HostImpl.java
@@ -549,12 +549,8 @@ public class HostImpl implements Host {
@Override
public String getHostName() {
- try {
- readLock.lock();
- return hostEntity.getHostName();
- } finally {
- readLock.unlock();
- }
+ // Not an updatable attribute - No locking necessary
+ return hostEntity.getHostName();
}
@Override
http://git-wip-us.apache.org/repos/asf/ambari/blob/1e83c740/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerImplTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerImplTest.java b/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerImplTest.java
index c99bfa1..b412245 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerImplTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerImplTest.java
@@ -18,6 +18,7 @@
package org.apache.ambari.server.controller;
+import static org.easymock.EasyMock.anyObject;
import static org.easymock.EasyMock.capture;
import static org.easymock.EasyMock.createNiceMock;
import static org.easymock.EasyMock.createStrictMock;
@@ -37,6 +38,7 @@ import java.util.HashSet;
import java.util.Map;
import java.util.Set;
+import junit.framework.Assert;
import org.apache.ambari.server.AmbariException;
import org.apache.ambari.server.ClusterNotFoundException;
import org.apache.ambari.server.HostNotFoundException;
@@ -74,6 +76,7 @@ public class AmbariManagementControllerImplTest {
// set expectations
injector.injectMembers(capture(controllerCapture));
expect(injector.getInstance(Gson.class)).andReturn(null);
+ expect(injector.getInstance(MaintenanceStateHelper.class)).andReturn(null);
//replay
replay(injector);
@@ -148,6 +151,7 @@ public class AmbariManagementControllerImplTest {
// constructor init
injector.injectMembers(capture(controllerCapture));
expect(injector.getInstance(Gson.class)).andReturn(null);
+ expect(injector.getInstance(MaintenanceStateHelper.class)).andReturn(null);
// getCluster
expect(clusters.getCluster("cluster1")).andReturn(cluster);
@@ -187,6 +191,7 @@ public class AmbariManagementControllerImplTest {
// constructor init
injector.injectMembers(capture(controllerCapture));
expect(injector.getInstance(Gson.class)).andReturn(null);
+ expect(injector.getInstance(MaintenanceStateHelper.class)).andReturn(null);
// getCluster
expect(clusters.getCluster("cluster1")).andThrow(new ClusterNotFoundException("cluster1"));
@@ -240,6 +245,7 @@ public class AmbariManagementControllerImplTest {
// constructor init
injector.injectMembers(capture(controllerCapture));
expect(injector.getInstance(Gson.class)).andReturn(null);
+ expect(injector.getInstance(MaintenanceStateHelper.class)).andReturn(null);
// getCluster
expect(clusters.getCluster("cluster1")).andThrow(new ClusterNotFoundException("cluster1"));
@@ -275,10 +281,10 @@ public class AmbariManagementControllerImplTest {
AmbariMetaInfo metaInfo = createStrictMock(AmbariMetaInfo.class);
Cluster cluster = createNiceMock(Cluster.class);
- Host host = createNiceMock(Host.class);
+ final Host host = createNiceMock(Host.class);
Service service = createNiceMock(Service.class);
ServiceComponent component = createNiceMock(ServiceComponent.class);
- ServiceComponentHost componentHost = createNiceMock(ServiceComponentHost.class);
+ final ServiceComponentHost componentHost = createNiceMock(ServiceComponentHost.class);
ServiceComponentHostResponse response = createNiceMock(ServiceComponentHostResponse.class);
MaintenanceStateHelper maintHelper = createNiceMock(MaintenanceStateHelper.class);
@@ -296,11 +302,13 @@ public class AmbariManagementControllerImplTest {
injector.injectMembers(capture(controllerCapture));
expect(injector.getInstance(Gson.class)).andReturn(null);
- expect(injector.getInstance(MaintenanceStateHelper.class)).andReturn(maintHelper);
+ expect(injector.getInstance(MaintenanceStateHelper.class)).andReturn(maintHelper).anyTimes();
// getHostComponent
expect(clusters.getCluster("cluster1")).andReturn(cluster);
expect(clusters.getClustersForHost("host1")).andReturn(Collections.singleton(cluster));
+ expect(clusters.getHostsForCluster((String) anyObject())).andReturn(
+ new HashMap<String, Host>() {{ put("host1", host); }}).anyTimes();
expect(cluster.getDesiredStackVersion()).andReturn(stack);
expect(stack.getStackName()).andReturn("stackName");
@@ -309,13 +317,18 @@ public class AmbariManagementControllerImplTest {
expect(metaInfo.getComponentToService("stackName", "stackVersion", "component1")).andReturn("service1");
expect(cluster.getService("service1")).andReturn(service);
expect(service.getServiceComponent("component1")).andReturn(component);
- expect(component.getName()).andReturn("component1").anyTimes();
- expect(component.getServiceComponentHost("host1")).andReturn(componentHost);
+ expect(component.getName()).andReturn("component1");
+ expect(component.getServiceComponentHosts()).andReturn(
+ new HashMap<String, ServiceComponentHost>() {{
+ put("host1", componentHost);
+ }});
expect(componentHost.convertToResponse()).andReturn(response);
+ expect(componentHost.getHostName()).andReturn("host1").anyTimes();
+ expect(maintHelper.getEffectiveState(componentHost, host)).andReturn(MaintenanceState.OFF);
// replay mocks
replay(maintHelper, injector, clusters, cluster, host, response, stack,
- metaInfo, service, component, componentHost);
+ metaInfo, service, component, componentHost);
//test
AmbariManagementController controller = new AmbariManagementControllerImpl(null, clusters, injector);
@@ -348,6 +361,7 @@ public class AmbariManagementControllerImplTest {
Host host = createNiceMock(Host.class);
Service service = createNiceMock(Service.class);
ServiceComponent component = createNiceMock(ServiceComponent.class);
+ MaintenanceStateHelper maintHelper = createNiceMock(MaintenanceStateHelper.class);
// requests
ServiceComponentHostRequest request1 = new ServiceComponentHostRequest(
@@ -361,6 +375,7 @@ public class AmbariManagementControllerImplTest {
// constructor init
injector.injectMembers(capture(controllerCapture));
expect(injector.getInstance(Gson.class)).andReturn(null);
+ expect(injector.getInstance(MaintenanceStateHelper.class)).andReturn(maintHelper);
// getHostComponent
expect(clusters.getCluster("cluster1")).andReturn(cluster);
@@ -374,11 +389,11 @@ public class AmbariManagementControllerImplTest {
expect(cluster.getService("service1")).andReturn(service);
expect(service.getServiceComponent("component1")).andReturn(component);
expect(component.getName()).andReturn("component1").anyTimes();
- expect(component.getServiceComponentHost("host1")).andThrow(
- new ServiceComponentHostNotFoundException("cluster1", "service1", "component1", "host1"));
+ expect(component.getServiceComponentHosts()).andReturn(null);
// replay mocks
- replay(injector, clusters, cluster, host, stack, metaInfo, service, component);
+ replay(maintHelper, injector, clusters, cluster, host, stack, metaInfo,
+ service, component);
//test
AmbariManagementController controller = new AmbariManagementControllerImpl(null, clusters, injector);
@@ -410,20 +425,26 @@ public class AmbariManagementControllerImplTest {
AmbariMetaInfo metaInfo = createNiceMock(AmbariMetaInfo.class);
Cluster cluster = createNiceMock(Cluster.class);
- Host host = createNiceMock(Host.class);
+ final Host host = createNiceMock(Host.class);
Service service = createNiceMock(Service.class);
ServiceComponent component = createNiceMock(ServiceComponent.class);
ServiceComponent component2 = createNiceMock(ServiceComponent.class);
ServiceComponent component3 = createNiceMock(ServiceComponent.class);
- ServiceComponentHost componentHost1 = createNiceMock(ServiceComponentHost.class);
- ServiceComponentHost componentHost2 = createNiceMock(ServiceComponentHost.class);
+ final ServiceComponentHost componentHost1 = createNiceMock(ServiceComponentHost.class);
+ final ServiceComponentHost componentHost2 = createNiceMock(ServiceComponentHost.class);
ServiceComponentHostResponse response1 = createNiceMock(ServiceComponentHostResponse.class);
ServiceComponentHostResponse response2 = createNiceMock(ServiceComponentHostResponse.class);
MaintenanceStateHelper stateHelper = createNiceMock(MaintenanceStateHelper.class);
- expect(stateHelper.getEffectiveState(capture(new Capture<ServiceComponentHost>())
- )).andReturn(MaintenanceState.OFF).anyTimes();
-
+ expect(stateHelper.getEffectiveState(
+ anyObject(ServiceComponentHost.class),
+ anyObject(Host.class))).andReturn(MaintenanceState.OFF).anyTimes();
+
+ expect(clusters.getHostsForCluster((String) anyObject())).andReturn(
+ new HashMap<String, Host>() {{
+ put("host1", host);
+ }}).anyTimes();
+
// requests
ServiceComponentHostRequest request1 = new ServiceComponentHostRequest(
"cluster1", null, "component1", "host1", null);
@@ -456,24 +477,29 @@ public class AmbariManagementControllerImplTest {
expect(stack.getStackName()).andReturn("stackName").anyTimes();
expect(stack.getStackVersion()).andReturn("stackVersion").anyTimes();
-
expect(metaInfo.getComponentToService("stackName", "stackVersion", "component1")).andReturn("service1");
expect(service.getServiceComponent("component1")).andReturn(component);
expect(component.getName()).andReturn("component1");
- expect(component.getServiceComponentHost("host1")).andReturn(componentHost1);
+ expect(component.getServiceComponentHosts()).andReturn(
+ new HashMap<String, ServiceComponentHost>() {{
+ put("host1", componentHost1);
+ }});
expect(componentHost1.convertToResponse()).andReturn(response1);
+ expect(componentHost1.getHostName()).andReturn("host1");
expect(metaInfo.getComponentToService("stackName", "stackVersion", "component2")).andReturn("service1");
expect(service.getServiceComponent("component2")).andReturn(component2);
expect(component2.getName()).andReturn("component2");
- expect(component2.getServiceComponentHost("host1")).andThrow(
- new ServiceComponentHostNotFoundException("cluster1", "service1", "component2", "host1"));
-
+ expect(component2.getServiceComponentHosts()).andReturn(null);
+ expect(componentHost2.getHostName()).andReturn("host1");
expect(metaInfo.getComponentToService("stackName", "stackVersion", "component3")).andReturn("service1");
expect(service.getServiceComponent("component3")).andReturn(component3);
expect(component3.getName()).andReturn("component3");
- expect(component3.getServiceComponentHost("host1")).andReturn(componentHost2);
+ expect(component3.getServiceComponentHosts()).andReturn(
+ new HashMap<String, ServiceComponentHost>() {{
+ put("host1", componentHost2);
+ }});
expect(componentHost2.convertToResponse()).andReturn(response2);
// replay mocks
@@ -511,19 +537,20 @@ public class AmbariManagementControllerImplTest {
AmbariMetaInfo metaInfo = createNiceMock(AmbariMetaInfo.class);
Cluster cluster = createNiceMock(Cluster.class);
- Host host = createNiceMock(Host.class);
+ final Host host = createNiceMock(Host.class);
Service service = createNiceMock(Service.class);
ServiceComponent component = createNiceMock(ServiceComponent.class);
ServiceComponent component2 = createNiceMock(ServiceComponent.class);
ServiceComponent component3 = createNiceMock(ServiceComponent.class);
- ServiceComponentHost componentHost1 = createNiceMock(ServiceComponentHost.class);
- ServiceComponentHost componentHost2 = createNiceMock(ServiceComponentHost.class);
+ final ServiceComponentHost componentHost1 = createNiceMock(ServiceComponentHost.class);
+ final ServiceComponentHost componentHost2 = createNiceMock(ServiceComponentHost.class);
ServiceComponentHostResponse response1 = createNiceMock(ServiceComponentHostResponse.class);
ServiceComponentHostResponse response2 = createNiceMock(ServiceComponentHostResponse.class);
MaintenanceStateHelper maintHelper = createNiceMock(MaintenanceStateHelper.class);
- expect(maintHelper.getEffectiveState(capture(
- new Capture<ServiceComponentHost>()))).andReturn(MaintenanceState.OFF).anyTimes();
+ expect(maintHelper.getEffectiveState(
+ anyObject(ServiceComponentHost.class),
+ anyObject(Host.class))).andReturn(MaintenanceState.OFF).anyTimes();
// requests
ServiceComponentHostRequest request1 = new ServiceComponentHostRequest(
@@ -550,19 +577,24 @@ public class AmbariManagementControllerImplTest {
// getHostComponent
expect(clusters.getCluster("cluster1")).andReturn(cluster).times(3);
expect(clusters.getClustersForHost("host1")).andReturn(Collections.singleton(cluster)).anyTimes();
- //expect(cluster.getService("service1")).andReturn(service).times(3);
-
expect(cluster.getDesiredStackVersion()).andReturn(stack).anyTimes();
expect(stack.getStackName()).andReturn("stackName").anyTimes();
expect(stack.getStackVersion()).andReturn("stackVersion").anyTimes();
-
+ expect(clusters.getHostsForCluster((String) anyObject())).andReturn(
+ new HashMap<String, Host>() {{
+ put("host1", host);
+ }}).anyTimes();
expect(metaInfo.getComponentToService("stackName", "stackVersion", "component1")).andReturn("service1");
expect(cluster.getService("service1")).andReturn(service);
expect(service.getServiceComponent("component1")).andReturn(component);
expect(component.getName()).andReturn("component1");
- expect(component.getServiceComponentHost("host1")).andReturn(componentHost1);
+ expect(component.getServiceComponentHosts()).andReturn(new
+ HashMap<String, ServiceComponentHost>() {{
+ put("host1", componentHost1);
+ }});
expect(componentHost1.convertToResponse()).andReturn(response1);
+ expect(componentHost1.getHostName()).andReturn("host1");
expect(metaInfo.getComponentToService("stackName", "stackVersion", "component2")).andReturn("service2");
expect(cluster.getService("service2")).andThrow(new ServiceNotFoundException("cluster1", "service2"));
@@ -571,8 +603,12 @@ public class AmbariManagementControllerImplTest {
expect(cluster.getService("service1")).andReturn(service);
expect(service.getServiceComponent("component3")).andReturn(component3);
expect(component3.getName()).andReturn("component3");
- expect(component3.getServiceComponentHost("host1")).andReturn(componentHost2);
+ expect(component3.getServiceComponentHosts()).andReturn(new
+ HashMap<String, ServiceComponentHost>() {{
+ put("host1", componentHost2);
+ }});
expect(componentHost2.convertToResponse()).andReturn(response2);
+ expect(componentHost2.getHostName()).andReturn("host1");
// replay mocks
replay(maintHelper, injector, clusters, cluster, host, stack, metaInfo,
@@ -609,21 +645,22 @@ public class AmbariManagementControllerImplTest {
AmbariMetaInfo metaInfo = createNiceMock(AmbariMetaInfo.class);
Cluster cluster = createNiceMock(Cluster.class);
- Host host = createNiceMock(Host.class);
+ final Host host = createNiceMock(Host.class);
Service service = createNiceMock(Service.class);
Service service2 = createNiceMock(Service.class);
ServiceComponent component = createNiceMock(ServiceComponent.class);
ServiceComponent component2 = createNiceMock(ServiceComponent.class);
ServiceComponent component3 = createNiceMock(ServiceComponent.class);
- ServiceComponentHost componentHost1 = createNiceMock(ServiceComponentHost.class);
- ServiceComponentHost componentHost2 = createNiceMock(ServiceComponentHost.class);
+ final ServiceComponentHost componentHost1 = createNiceMock(ServiceComponentHost.class);
+ final ServiceComponentHost componentHost2 = createNiceMock(ServiceComponentHost.class);
ServiceComponentHostResponse response1 = createNiceMock(ServiceComponentHostResponse.class);
ServiceComponentHostResponse response2 = createNiceMock(ServiceComponentHostResponse.class);
MaintenanceStateHelper maintHelper = createNiceMock(MaintenanceStateHelper.class);
- expect(maintHelper.getEffectiveState(capture(
- new Capture<ServiceComponentHost>()))).andReturn(MaintenanceState.OFF).anyTimes();
+ expect(maintHelper.getEffectiveState(
+ anyObject(ServiceComponentHost.class),
+ anyObject(Host.class))).andReturn(MaintenanceState.OFF).anyTimes();
// requests
ServiceComponentHostRequest request1 = new ServiceComponentHostRequest(
@@ -650,7 +687,10 @@ public class AmbariManagementControllerImplTest {
// getHostComponent
expect(clusters.getCluster("cluster1")).andReturn(cluster).times(3);
expect(clusters.getClustersForHost("host1")).andReturn(Collections.singleton(cluster)).anyTimes();
-
+ expect(clusters.getHostsForCluster((String) anyObject())).andReturn(
+ new HashMap<String, Host>() {{
+ put("host1", host);
+ }}).anyTimes();
expect(cluster.getDesiredStackVersion()).andReturn(stack).anyTimes();
expect(stack.getStackName()).andReturn("stackName").anyTimes();
expect(stack.getStackVersion()).andReturn("stackVersion").anyTimes();
@@ -660,8 +700,12 @@ public class AmbariManagementControllerImplTest {
expect(cluster.getService("service1")).andReturn(service);
expect(service.getServiceComponent("component1")).andReturn(component);
expect(component.getName()).andReturn("component1");
- expect(component.getServiceComponentHost("host1")).andReturn(componentHost1);
+ expect(component.getServiceComponentHosts()).andReturn(
+ new HashMap<String, ServiceComponentHost>() {{
+ put("host1", componentHost1);
+ }});
expect(componentHost1.convertToResponse()).andReturn(response1);
+ expect(componentHost1.getHostName()).andReturn("host1");
expect(metaInfo.getComponentToService("stackName", "stackVersion", "component2")).andReturn("service2");
expect(cluster.getService("service2")).andReturn(service2);
@@ -672,13 +716,17 @@ public class AmbariManagementControllerImplTest {
expect(cluster.getService("service1")).andReturn(service);
expect(service.getServiceComponent("component3")).andReturn(component3);
expect(component3.getName()).andReturn("component3");
- expect(component3.getServiceComponentHost("host1")).andReturn(componentHost2);
+ expect(component3.getServiceComponentHosts()).andReturn(
+ new HashMap<String, ServiceComponentHost>() {{
+ put("host1", componentHost2);
+ }});
expect(componentHost2.convertToResponse()).andReturn(response2);
+ expect(componentHost2.getHostName()).andReturn("host1");
// replay mocks
replay(maintHelper, injector, clusters, cluster, host, stack, metaInfo,
- service, service2, component, component2, component3, componentHost1,
- componentHost2, response1, response2);
+ service, service2, component, component2, component3, componentHost1,
+ componentHost2, response1, response2);
//test
AmbariManagementController controller = new AmbariManagementControllerImpl(null, clusters, injector);
@@ -710,20 +758,21 @@ public class AmbariManagementControllerImplTest {
AmbariMetaInfo metaInfo = createNiceMock(AmbariMetaInfo.class);
Cluster cluster = createNiceMock(Cluster.class);
- Host host = createNiceMock(Host.class);
+ final Host host = createNiceMock(Host.class);
Service service = createNiceMock(Service.class);
Service service2 = createNiceMock(Service.class);
ServiceComponent component = createNiceMock(ServiceComponent.class);
ServiceComponent component2 = createNiceMock(ServiceComponent.class);
ServiceComponent component3 = createNiceMock(ServiceComponent.class);
- ServiceComponentHost componentHost1 = createNiceMock(ServiceComponentHost.class);
- ServiceComponentHost componentHost2 = createNiceMock(ServiceComponentHost.class);
+ final ServiceComponentHost componentHost1 = createNiceMock(ServiceComponentHost.class);
+ final ServiceComponentHost componentHost2 = createNiceMock(ServiceComponentHost.class);
ServiceComponentHostResponse response1 = createNiceMock(ServiceComponentHostResponse.class);
ServiceComponentHostResponse response2 = createNiceMock(ServiceComponentHostResponse.class);
MaintenanceStateHelper maintHelper = createNiceMock(MaintenanceStateHelper.class);
expect(maintHelper.getEffectiveState(
- capture(new Capture<ServiceComponentHost>()))).andReturn(MaintenanceState.OFF).anyTimes();
+ anyObject(ServiceComponentHost.class),
+ anyObject(Host.class))).andReturn(MaintenanceState.OFF).anyTimes();
// requests
ServiceComponentHostRequest request1 = new ServiceComponentHostRequest(
@@ -749,7 +798,10 @@ public class AmbariManagementControllerImplTest {
// getHostComponent
expect(clusters.getCluster("cluster1")).andReturn(cluster).times(3);
- //expect(clusters.getClustersForHost("host1")).andReturn(Collections.singleton(cluster)).anyTimes();
+ expect(clusters.getHostsForCluster((String) anyObject())).andReturn(
+ new HashMap<String, Host>() {{
+ put("host1", host);
+ }}).anyTimes();
expect(cluster.getDesiredStackVersion()).andReturn(stack).anyTimes();
expect(stack.getStackName()).andReturn("stackName").anyTimes();
@@ -761,6 +813,7 @@ public class AmbariManagementControllerImplTest {
expect(component.getName()).andReturn("component1");
expect(component.getServiceComponentHosts()).andReturn(Collections.singletonMap("foo", componentHost1));
expect(componentHost1.convertToResponse()).andReturn(response1);
+ expect(componentHost1.getHostName()).andReturn("host1");
expect(clusters.getClustersForHost("host2")).andThrow(new HostNotFoundException("host2"));
@@ -770,6 +823,7 @@ public class AmbariManagementControllerImplTest {
expect(component3.getName()).andReturn("component3");
expect(component3.getServiceComponentHosts()).andReturn(Collections.singletonMap("foo", componentHost2));
expect(componentHost2.convertToResponse()).andReturn(response2);
+ expect(componentHost2.getHostName()).andReturn("host1");
// replay mocks
replay(maintHelper, injector, clusters, cluster, host, stack, metaInfo,
@@ -785,6 +839,7 @@ public class AmbariManagementControllerImplTest {
f.set(controller, metaInfo);
Set<ServiceComponentHostResponse> setResponses = controller.getHostComponents(setRequests);
+ Assert.assertNotNull(setResponses);
// assert and verify
assertSame(controller, controllerCapture.getValue());
@@ -804,6 +859,7 @@ public class AmbariManagementControllerImplTest {
Clusters clusters = createNiceMock(Clusters.class);
StackId stack = createNiceMock(StackId.class);
AmbariMetaInfo metaInfo = createNiceMock(AmbariMetaInfo.class);
+ MaintenanceStateHelper maintHelper = createNiceMock(MaintenanceStateHelper.class);
Cluster cluster = createNiceMock(Cluster.class);
@@ -827,13 +883,14 @@ public class AmbariManagementControllerImplTest {
// constructor init
injector.injectMembers(capture(controllerCapture));
expect(injector.getInstance(Gson.class)).andReturn(null);
+ expect(injector.getInstance(MaintenanceStateHelper.class)).andReturn(maintHelper);
// getHostComponent
expect(clusters.getCluster("cluster1")).andReturn(cluster);
expect(clusters.getClustersForHost("host1")).andThrow(new HostNotFoundException("host1"));
// replay mocks
- replay(injector, clusters, cluster, stack, metaInfo);
+ replay(maintHelper, injector, clusters, cluster, stack, metaInfo);
//test
AmbariManagementController controller = new AmbariManagementControllerImpl(null, clusters, injector);
@@ -864,6 +921,7 @@ public class AmbariManagementControllerImplTest {
Clusters clusters = createNiceMock(Clusters.class);
StackId stack = createNiceMock(StackId.class);
AmbariMetaInfo metaInfo = createNiceMock(AmbariMetaInfo.class);
+ MaintenanceStateHelper maintHelper = createNiceMock(MaintenanceStateHelper.class);
// requests
ServiceComponentHostRequest request1 = new ServiceComponentHostRequest(
@@ -885,12 +943,13 @@ public class AmbariManagementControllerImplTest {
// constructor init
injector.injectMembers(capture(controllerCapture));
expect(injector.getInstance(Gson.class)).andReturn(null);
+ expect(injector.getInstance(MaintenanceStateHelper.class)).andReturn(maintHelper);
// getHostComponent
expect(clusters.getCluster("cluster1")).andThrow(new ClusterNotFoundException("cluster1"));
// replay mocks
- replay(injector, clusters, stack, metaInfo);
+ replay(maintHelper, injector, clusters, stack, metaInfo);
//test
AmbariManagementController controller = new AmbariManagementControllerImpl(null, clusters, injector);
@@ -931,7 +990,8 @@ public class AmbariManagementControllerImplTest {
ServiceComponentHostResponse response2 = createNiceMock(ServiceComponentHostResponse.class);
MaintenanceStateHelper maintHelper = createNiceMock(MaintenanceStateHelper.class);
expect(maintHelper.getEffectiveState(
- capture(new Capture<ServiceComponentHost>()))).andReturn(MaintenanceState.OFF).anyTimes();
+ anyObject(ServiceComponentHost.class),
+ anyObject(Host.class))).andReturn(MaintenanceState.OFF).anyTimes();
// requests
ServiceComponentHostRequest request1 = new ServiceComponentHostRequest(
@@ -954,7 +1014,10 @@ public class AmbariManagementControllerImplTest {
// getHostComponent
expect(clusters.getCluster("cluster1")).andReturn(cluster);
-
+ expect(clusters.getHostsForCluster((String) anyObject())).andReturn(
+ new HashMap<String, Host>() {{
+ put("host1", createNiceMock(Host.class));
+ }}).anyTimes();
expect(cluster.getDesiredStackVersion()).andReturn(stack);
expect(stack.getStackName()).andReturn("stackName");
expect(stack.getStackVersion()).andReturn("stackVersion");
@@ -967,6 +1030,8 @@ public class AmbariManagementControllerImplTest {
expect(component.getServiceComponentHosts()).andReturn(mapHostComponents);
expect(componentHost1.convertToResponse()).andReturn(response1);
expect(componentHost2.convertToResponse()).andReturn(response2);
+ expect(componentHost1.getHostName()).andReturn("host1");
+ expect(componentHost2.getHostName()).andReturn("host1");
// replay mocks
replay(maintHelper, injector, clusters, cluster, response1, response2,
@@ -1013,7 +1078,8 @@ public class AmbariManagementControllerImplTest {
ServiceComponentHostResponse response3 = createNiceMock(ServiceComponentHostResponse.class);
MaintenanceStateHelper maintHelper = createNiceMock(MaintenanceStateHelper.class);
expect(maintHelper.getEffectiveState(
- capture(new Capture<ServiceComponentHost>()))).andReturn(MaintenanceState.OFF).anyTimes();
+ anyObject(ServiceComponentHost.class),
+ anyObject(Host.class))).andReturn(MaintenanceState.OFF).anyTimes();
// requests
ServiceComponentHostRequest request1 = new ServiceComponentHostRequest(
@@ -1040,6 +1106,10 @@ public class AmbariManagementControllerImplTest {
// getHostComponent
expect(clusters.getCluster("cluster1")).andReturn(cluster);
+ expect(clusters.getHostsForCluster((String) anyObject())).andReturn(
+ new HashMap<String, Host>() {{
+ put("host1", createNiceMock(Host.class));
+ }}).anyTimes();
expect(cluster.getServices()).andReturn(mapServices);
expect(service1.getServiceComponents()).andReturn(Collections.singletonMap("foo", component1));
@@ -1051,6 +1121,9 @@ public class AmbariManagementControllerImplTest {
expect(component1.getServiceComponentHosts()).andReturn(mapHostComponents);
expect(componentHost1.convertToResponse()).andReturn(response1);
expect(componentHost2.convertToResponse()).andReturn(response2);
+ expect(componentHost1.getHostName()).andReturn("host1");
+ expect(componentHost2.getHostName()).andReturn("host1");
+ expect(componentHost3.getHostName()).andReturn("host1");
expect(component2.getServiceComponentHosts()).andReturn(Collections.singletonMap("foobar", componentHost3));
expect(componentHost3.convertToResponse()).andReturn(response3);
http://git-wip-us.apache.org/repos/asf/ambari/blob/1e83c740/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerTest.java b/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerTest.java
index 3c1632c..c2192d0 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerTest.java
@@ -9256,6 +9256,7 @@ public class AmbariManagementControllerTest {
Injector injector = createStrictMock(Injector.class);
Capture<AmbariManagementController> controllerCapture = new Capture<AmbariManagementController>();
Clusters clusters = createNiceMock(Clusters.class);
+ MaintenanceStateHelper maintHelper = createNiceMock(MaintenanceStateHelper.class);
Cluster cluster = createNiceMock(Cluster.class);
Service service = createNiceMock(Service.class);
@@ -9271,6 +9272,7 @@ public class AmbariManagementControllerTest {
// constructor init
injector.injectMembers(capture(controllerCapture));
expect(injector.getInstance(Gson.class)).andReturn(null);
+ expect(injector.getInstance(MaintenanceStateHelper.class)).andReturn(maintHelper);
// getServices
expect(clusters.getCluster("cluster1")).andReturn(cluster);
@@ -9278,7 +9280,7 @@ public class AmbariManagementControllerTest {
expect(service.convertToResponse()).andReturn(response);
// replay mocks
- replay(injector, clusters, cluster, service, response);
+ replay(maintHelper, injector, clusters, cluster, service, response);
//test
AmbariManagementController controller = new AmbariManagementControllerImpl(null, clusters, injector);
@@ -9301,7 +9303,7 @@ public class AmbariManagementControllerTest {
Injector injector = createStrictMock(Injector.class);
Capture<AmbariManagementController> controllerCapture = new Capture<AmbariManagementController>();
Clusters clusters = createNiceMock(Clusters.class);
-
+ MaintenanceStateHelper maintHelper = createNiceMock(MaintenanceStateHelper.class);
Cluster cluster = createNiceMock(Cluster.class);
// requests
@@ -9313,13 +9315,14 @@ public class AmbariManagementControllerTest {
// constructor init
injector.injectMembers(capture(controllerCapture));
expect(injector.getInstance(Gson.class)).andReturn(null);
+ expect(injector.getInstance(MaintenanceStateHelper.class)).andReturn(maintHelper);
// getServices
expect(clusters.getCluster("cluster1")).andReturn(cluster);
expect(cluster.getService("service1")).andThrow(new ServiceNotFoundException("custer1", "service1"));
// replay mocks
- replay(injector, clusters, cluster);
+ replay(maintHelper, injector, clusters, cluster);
//test
AmbariManagementController controller = new AmbariManagementControllerImpl(null, clusters, injector);
@@ -9346,6 +9349,7 @@ public class AmbariManagementControllerTest {
Injector injector = createStrictMock(Injector.class);
Capture<AmbariManagementController> controllerCapture = new Capture<AmbariManagementController>();
Clusters clusters = createNiceMock(Clusters.class);
+ MaintenanceStateHelper maintHelper = createNiceMock(MaintenanceStateHelper.class);
Cluster cluster = createNiceMock(Cluster.class);
Service service1 = createNiceMock(Service.class);
@@ -9369,6 +9373,7 @@ public class AmbariManagementControllerTest {
// constructor init
injector.injectMembers(capture(controllerCapture));
expect(injector.getInstance(Gson.class)).andReturn(null);
+ expect(injector.getInstance(MaintenanceStateHelper.class)).andReturn(maintHelper);
// getServices
expect(clusters.getCluster("cluster1")).andReturn(cluster).times(4);
@@ -9380,7 +9385,8 @@ public class AmbariManagementControllerTest {
expect(service1.convertToResponse()).andReturn(response);
expect(service2.convertToResponse()).andReturn(response2);
// replay mocks
- replay(injector, clusters, cluster, service1, service2, response, response2);
+ replay(maintHelper, injector, clusters, cluster, service1, service2,
+ response, response2);
//test
AmbariManagementController controller = new AmbariManagementControllerImpl(null, clusters, injector);
http://git-wip-us.apache.org/repos/asf/ambari/blob/1e83c740/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ComponentResourceProviderTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ComponentResourceProviderTest.java b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ComponentResourceProviderTest.java
index 2cc1165..76c6ae3 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ComponentResourceProviderTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ComponentResourceProviderTest.java
@@ -48,6 +48,7 @@ import org.apache.ambari.server.ServiceComponentNotFoundException;
import org.apache.ambari.server.api.services.AmbariMetaInfo;
import org.apache.ambari.server.controller.AmbariManagementController;
import org.apache.ambari.server.controller.AmbariManagementControllerImpl;
+import org.apache.ambari.server.controller.MaintenanceStateHelper;
import org.apache.ambari.server.controller.RequestStatusResponse;
import org.apache.ambari.server.controller.ServiceComponentRequest;
import org.apache.ambari.server.controller.ServiceComponentResponse;
@@ -491,7 +492,7 @@ public class ComponentResourceProviderTest {
Injector injector = createStrictMock(Injector.class);
Capture<AmbariManagementController> controllerCapture = new Capture<AmbariManagementController>();
Clusters clusters = createNiceMock(Clusters.class);
-
+ MaintenanceStateHelper maintHelper = createNiceMock(MaintenanceStateHelper.class);
Cluster cluster = createNiceMock(Cluster.class);
Service service = createNiceMock(Service.class);
@@ -506,6 +507,7 @@ public class ComponentResourceProviderTest {
// constructor init
injector.injectMembers(capture(controllerCapture));
expect(injector.getInstance(Gson.class)).andReturn(null);
+ expect(injector.getInstance(MaintenanceStateHelper.class)).andReturn(maintHelper);
// getComponents
expect(clusters.getCluster("cluster1")).andReturn(cluster);
@@ -513,7 +515,7 @@ public class ComponentResourceProviderTest {
expect(service.getServiceComponent("component1")).andThrow(
new ServiceComponentNotFoundException("cluster1", "service1", "component1"));
// replay mocks
- replay(injector, clusters, cluster, service);
+ replay(maintHelper, injector, clusters, cluster, service);
//test
AmbariManagementController controller = new AmbariManagementControllerImpl(null, clusters, injector);
http://git-wip-us.apache.org/repos/asf/ambari/blob/1e83c740/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 049af58..5455201 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
@@ -26,6 +26,7 @@ import org.apache.ambari.server.api.services.AmbariMetaInfo;
import org.apache.ambari.server.controller.AmbariManagementController;
import org.apache.ambari.server.controller.AmbariManagementControllerImpl;
import org.apache.ambari.server.controller.HostResponse;
+import org.apache.ambari.server.controller.MaintenanceStateHelper;
import org.apache.ambari.server.controller.RequestStatusResponse;
import org.apache.ambari.server.controller.HostRequest;
import org.apache.ambari.server.controller.ResourceProviderFactory;
@@ -928,7 +929,7 @@ public class HostResourceProviderTest {
Injector injector = createStrictMock(Injector.class);
Capture<AmbariManagementController> controllerCapture = new Capture<AmbariManagementController>();
Clusters clusters = createNiceMock(Clusters.class);
-
+ MaintenanceStateHelper maintHelper = createNiceMock(MaintenanceStateHelper.class);
Cluster cluster = createNiceMock(Cluster.class);
Host host = createNiceMock(Host.class);
HostResponse response = createNiceMock(HostResponse.class);
@@ -945,6 +946,7 @@ public class HostResourceProviderTest {
// constructor init
injector.injectMembers(capture(controllerCapture));
expect(injector.getInstance(Gson.class)).andReturn(null);
+ expect(injector.getInstance(MaintenanceStateHelper.class)).andReturn(maintHelper);
// getHosts
expect(clusters.getCluster("cluster1")).andReturn(cluster);
@@ -955,7 +957,7 @@ public class HostResourceProviderTest {
response.setClusterName("cluster1");
// replay mocks
- replay(injector, clusters, cluster, host, response);
+ replay(maintHelper, injector, clusters, cluster, host, response);
//test
AmbariManagementController controller = new AmbariManagementControllerImpl(null, clusters, injector);
@@ -978,7 +980,7 @@ public class HostResourceProviderTest {
Injector injector = createStrictMock(Injector.class);
Capture<AmbariManagementController> controllerCapture = new Capture<AmbariManagementController>();
Clusters clusters = createNiceMock(Clusters.class);
-
+ MaintenanceStateHelper maintHelper = createNiceMock(MaintenanceStateHelper.class);
Cluster cluster = createNiceMock(Cluster.class);
// requests
@@ -989,13 +991,14 @@ public class HostResourceProviderTest {
// constructor init
injector.injectMembers(capture(controllerCapture));
expect(injector.getInstance(Gson.class)).andReturn(null);
+ expect(injector.getInstance(MaintenanceStateHelper.class)).andReturn(maintHelper);
// getHosts
expect(clusters.getCluster("cluster1")).andReturn(cluster);
expect(clusters.getHost("host1")).andThrow(new HostNotFoundException("host1"));
// replay mocks
- replay(injector, clusters, cluster);
+ replay(maintHelper, injector, clusters, cluster);
//test
AmbariManagementController controller = new AmbariManagementControllerImpl(null, clusters, injector);
@@ -1020,7 +1023,7 @@ public class HostResourceProviderTest {
Injector injector = createStrictMock(Injector.class);
Capture<AmbariManagementController> controllerCapture = new Capture<AmbariManagementController>();
Clusters clusters = createNiceMock(Clusters.class);
-
+ MaintenanceStateHelper maintHelper = createNiceMock(MaintenanceStateHelper.class);
Cluster cluster = createNiceMock(Cluster.class);
Host host = createNiceMock(Host.class);
@@ -1032,6 +1035,7 @@ public class HostResourceProviderTest {
// constructor init
injector.injectMembers(capture(controllerCapture));
expect(injector.getInstance(Gson.class)).andReturn(null);
+ expect(injector.getInstance(MaintenanceStateHelper.class)).andReturn(maintHelper);
// getHosts
expect(clusters.getCluster("cluster1")).andReturn(cluster);
@@ -1041,7 +1045,7 @@ public class HostResourceProviderTest {
expect(clusters.getClustersForHost("host1")).andReturn(Collections.<Cluster>emptySet());
// replay mocks
- replay(injector, clusters, cluster, host);
+ replay(maintHelper, injector, clusters, cluster, host);
//test
AmbariManagementController controller = new AmbariManagementControllerImpl(null, clusters, injector);
@@ -1068,7 +1072,7 @@ public class HostResourceProviderTest {
Injector injector = createStrictMock(Injector.class);
Capture<AmbariManagementController> controllerCapture = new Capture<AmbariManagementController>();
Clusters clusters = createNiceMock(Clusters.class);
-
+ MaintenanceStateHelper maintHelper = createNiceMock(MaintenanceStateHelper.class);
Cluster cluster = createNiceMock(Cluster.class);
Host host1 = createNiceMock(Host.class);
Host host2 = createNiceMock(Host.class);
@@ -1091,6 +1095,7 @@ public class HostResourceProviderTest {
// constructor init
injector.injectMembers(capture(controllerCapture));
expect(injector.getInstance(Gson.class)).andReturn(null);
+ expect(injector.getInstance(MaintenanceStateHelper.class)).andReturn(maintHelper);
// getHosts
expect(clusters.getCluster("cluster1")).andReturn(cluster).times(4);
@@ -1111,7 +1116,7 @@ public class HostResourceProviderTest {
expect(clusters.getHost("host4")).andThrow(new HostNotFoundException("host4"));
// replay mocks
- replay(injector, clusters, cluster, host1, host2, response, response2);
+ replay(maintHelper, injector, clusters, cluster, host1, host2, response, response2);
//test
AmbariManagementController controller = new AmbariManagementControllerImpl(null, clusters, injector);