You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by sm...@apache.org on 2016/12/09 21:57:10 UTC
[18/51] [abbrv] ambari git commit: AMBARI-18450. Putting a service or
process in Maintenance Mode does not take it off of the list.(vbrodetskyi)
AMBARI-18450. Putting a service or process in Maintenance Mode does not take it off of the <Restart All Required> list.(vbrodetskyi)
Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/4f3a67d9
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/4f3a67d9
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/4f3a67d9
Branch: refs/heads/branch-feature-AMBARI-18901
Commit: 4f3a67d987d759f4ecf28f163cf994a373f4a2ff
Parents: a9a05f7
Author: Vitaly Brodetskyi <vb...@hortonworks.com>
Authored: Thu Dec 8 17:33:06 2016 +0200
Committer: Vitaly Brodetskyi <vb...@hortonworks.com>
Committed: Thu Dec 8 17:33:06 2016 +0200
----------------------------------------------------------------------
.../AmbariManagementControllerImpl.java | 32 ++++++++-
.../AmbariManagementControllerImplTest.java | 74 ++++++++++++++++++++
2 files changed, 104 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ambari/blob/4f3a67d9/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 c9a3e04..c3cd82e 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
@@ -1247,7 +1247,12 @@ public class AmbariManagementControllerImpl implements AmbariManagementControlle
throw new HostNotFoundException(cluster.getClusterName(), sch.getHostName());
}
- r.setMaintenanceState(maintenanceStateHelper.getEffectiveState(sch, host).name());
+ MaintenanceState effectiveMaintenanceState = maintenanceStateHelper.getEffectiveState(sch, host);
+ if(filterByMaintenanceState(request, effectiveMaintenanceState)) {
+ continue;
+ }
+ r.setMaintenanceState(effectiveMaintenanceState.name());
+
response.add(r);
} catch (ServiceComponentHostNotFoundException e) {
if (request.getServiceName() == null || request.getComponentName() == null) {
@@ -1298,7 +1303,12 @@ public class AmbariManagementControllerImpl implements AmbariManagementControlle
throw new HostNotFoundException(cluster.getClusterName(), sch.getHostName());
}
- r.setMaintenanceState(maintenanceStateHelper.getEffectiveState(sch, host).name());
+ MaintenanceState effectiveMaintenanceState = maintenanceStateHelper.getEffectiveState(sch, host);
+ if(filterByMaintenanceState(request, effectiveMaintenanceState)) {
+ continue;
+ }
+ r.setMaintenanceState(effectiveMaintenanceState.name());
+
response.add(r);
}
}
@@ -1307,6 +1317,24 @@ public class AmbariManagementControllerImpl implements AmbariManagementControlle
return response;
}
+ private boolean filterByMaintenanceState(ServiceComponentHostRequest request, MaintenanceState effectiveMaintenanceState) {
+ if (request.getMaintenanceState() != null) {
+ MaintenanceState desiredMaintenanceState = MaintenanceState.valueOf(request.getMaintenanceState());
+ if (desiredMaintenanceState.equals(MaintenanceState.ON)) {
+ /*
+ * if we want components with ON state it can be one of IMPLIED_FROM_SERVICE,
+ * IMPLIED_FROM_SERVICE_AND_HOST, IMPLIED_FROM_HOST, ON, ro simply - not OFF
+ */
+ if (effectiveMaintenanceState.equals(MaintenanceState.OFF)) {
+ return true;
+ }
+ } else if (!desiredMaintenanceState.equals(effectiveMaintenanceState)){
+ return true;
+ }
+ }
+ return false;
+ }
+
@Override
public MaintenanceState getEffectiveMaintenanceState(ServiceComponentHost sch)
throws AmbariException {
http://git-wip-us.apache.org/repos/asf/ambari/blob/4f3a67d9/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 2507a46..78b804c 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
@@ -1218,6 +1218,80 @@ public class AmbariManagementControllerImplTest {
}
@Test
+ public void testGetHostComponents___ServiceComponentHostFilteredByMaintenanceState() throws Exception {
+ // member state mocks
+ Injector injector = createStrictMock(Injector.class);
+ Capture<AmbariManagementController> controllerCapture = new Capture<AmbariManagementController>();
+ StackId stack = createNiceMock(StackId.class);
+
+ Cluster cluster = createNiceMock(Cluster.class);
+ final Host host = createNiceMock(Host.class);
+ Service service = createNiceMock(Service.class);
+ ServiceComponent component = createNiceMock(ServiceComponent.class);
+ MaintenanceStateHelper maintHelper = createNiceMock(MaintenanceStateHelper.class);
+ final ServiceComponentHost componentHost1 = createNiceMock(ServiceComponentHost.class);
+ ServiceComponentHostResponse response1 = createNiceMock(ServiceComponentHostResponse.class);
+
+ // requests
+ ServiceComponentHostRequest request1 = new ServiceComponentHostRequest(
+ "cluster1", null, "component1", "host1", null);
+ request1.setMaintenanceState("ON");
+
+
+ Set<ServiceComponentHostRequest> setRequests = new HashSet<ServiceComponentHostRequest>();
+ setRequests.add(request1);
+
+ // expectations
+ // constructor init
+ injector.injectMembers(capture(controllerCapture));
+ expect(injector.getInstance(Gson.class)).andReturn(null);
+ expect(injector.getInstance(MaintenanceStateHelper.class)).andReturn(maintHelper);
+ expect(injector.getInstance(KerberosHelper.class)).andReturn(createNiceMock(KerberosHelper.class));
+ expect(maintHelper.getEffectiveState(
+ anyObject(ServiceComponentHost.class),
+ anyObject(Host.class))).andReturn(MaintenanceState.IMPLIED_FROM_SERVICE).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(cluster.getClusterName()).andReturn("cl1");
+ expect(stack.getStackName()).andReturn("stackName");
+ expect(stack.getStackVersion()).andReturn("stackVersion");
+
+ expect(ambariMetaInfo.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.getServiceComponentHosts()).andReturn(new HashMap<String, ServiceComponentHost>() {{
+ put("host1", componentHost1);
+ }});
+
+ expect(componentHost1.convertToResponse(null)).andReturn(response1);
+ expect(componentHost1.getHostName()).andReturn("host1");
+
+ // replay mocks
+ replay(maintHelper, injector, clusters, cluster, host, stack, ambariMetaInfo,
+ service, component, componentHost1, response1);
+
+ //test
+ AmbariManagementController controller = new AmbariManagementControllerImpl(null, clusters, injector);
+ setAmbariMetaInfo(ambariMetaInfo, controller);
+
+ Set<ServiceComponentHostResponse> responses = controller.getHostComponents(setRequests);
+
+ // assert and verify
+ assertSame(controller, controllerCapture.getValue());
+ assertTrue(responses.size() == 1);
+ verify(injector, clusters, cluster, host, stack, ambariMetaInfo, service, component, componentHost1, response1);
+ }
+
+ @Test
public void testGetHostComponents___OR_Predicate_ServiceComponentHostNotFoundException() throws Exception {
// member state mocks
Injector injector = createStrictMock(Injector.class);