@Test public void testServiceOperationsAllowance() throws Exception { Injector injector = createStrictMock(Injector.class); MaintenanceStateHelper maintenanceStateHelper = createMockBuilder(MaintenanceStateHelper.class) .withConstructor(injector) .createNiceMock(); Service service = createMock(Service.class); expect(service.getMaintenanceState()).andReturn(MaintenanceState.ON); expect(service.getMaintenanceState()).andReturn(MaintenanceState.OFF); replay(maintenanceStateHelper, service); Assert.assertEquals(false, maintenanceStateHelper.isOperationAllowed(Resource.Type.Cluster, service)); Assert.assertEquals(true, maintenanceStateHelper.isOperationAllowed(Resource.Type.Service, service)); Assert.assertEquals(true, maintenanceStateHelper.isOperationAllowed(Resource.Type.Host, service)); Assert.assertEquals(true, maintenanceStateHelper.isOperationAllowed(Resource.Type.HostComponent, service)); Assert.assertEquals(true, maintenanceStateHelper.isOperationAllowed(Resource.Type.Cluster, service)); Assert.assertEquals(true, maintenanceStateHelper.isOperationAllowed(Resource.Type.Service, service)); Assert.assertEquals(true, maintenanceStateHelper.isOperationAllowed(Resource.Type.Host, service)); Assert.assertEquals(true, maintenanceStateHelper.isOperationAllowed(Resource.Type.HostComponent, service)); verify(maintenanceStateHelper, service); }
public boolean isOperationAllowed(Cluster cluster, RequestOperationLevel levelObj, RequestResourceFilter reqFilter, String serviceName, String componentName, String hostname) throws AmbariException { Resource.Type level; if (levelObj == null) { level = guessOperationLevel(reqFilter); } else { level = levelObj.getLevel(); } return isOperationAllowed(cluster, level, serviceName, componentName, hostname); }
MaintenanceStateHelper { public boolean isOperationAllowed(Cluster cluster, RequestOperationLevel levelObj, RequestResourceFilter reqFilter, String serviceName, String componentName, String hostname) throws AmbariException { Resource.Type level; if (levelObj == null) { level = guessOperationLevel(reqFilter); } else { level = levelObj.getLevel(); } return isOperationAllowed(cluster, level, serviceName, componentName, hostname); } }
MaintenanceStateHelper { public boolean isOperationAllowed(Cluster cluster, RequestOperationLevel levelObj, RequestResourceFilter reqFilter, String serviceName, String componentName, String hostname) throws AmbariException { Resource.Type level; if (levelObj == null) { level = guessOperationLevel(reqFilter); } else { level = levelObj.getLevel(); } return isOperationAllowed(cluster, level, serviceName, componentName, hostname); } @Inject  MaintenanceStateHelper(Injector injector); }
MaintenanceStateHelper { public boolean isOperationAllowed(Cluster cluster, RequestOperationLevel levelObj, RequestResourceFilter reqFilter, String serviceName, String componentName, String hostname) throws AmbariException { Resource.Type level; if (levelObj == null) { level = guessOperationLevel(reqFilter); } else { level = levelObj.getLevel(); } return isOperationAllowed(cluster, level, serviceName, componentName, hostname); } @Inject  MaintenanceStateHelper(Injector injector); boolean isOperationAllowed(Cluster cluster,
      RequestOperationLevel levelObj, RequestResourceFilter reqFilter,
      String serviceName, String componentName, String hostname); boolean isOperationAllowed(Resource.Type level, Service service); boolean isOperationAllowed(Host host, long clusterId,
      Resource.Type level); MaintenanceState getEffectiveState(ServiceComponentHost sch, Host host); MaintenanceState getEffectiveState(ServiceComponentHost sch); MaintenanceState getEffectiveState(long clusterId, Alert alert); Set<Map<String, String>> getMaintenanceHostComponents(
      Clusters clusters, Cluster cluster); boolean isOperationAllowed(Resource.Type operationLevel,
      ServiceComponentHost sch); Resource.Type guessOperationLevel(RequestResourceFilter filter); Set<String> filterHostsInMaintenanceState(Set<String> candidateHosts,
      HostPredicate condition); }
MaintenanceStateHelper { public boolean isOperationAllowed(Cluster cluster, RequestOperationLevel levelObj, RequestResourceFilter reqFilter, String serviceName, String componentName, String hostname) throws AmbariException { Resource.Type level; if (levelObj == null) { level = guessOperationLevel(reqFilter); } else { level = levelObj.getLevel(); } return isOperationAllowed(cluster, level, serviceName, componentName, hostname); } @Inject  MaintenanceStateHelper(Injector injector); boolean isOperationAllowed(Cluster cluster,
      RequestOperationLevel levelObj, RequestResourceFilter reqFilter,
      String serviceName, String componentName, String hostname); boolean isOperationAllowed(Resource.Type level, Service service); boolean isOperationAllowed(Host host, long clusterId,
      Resource.Type level); MaintenanceState getEffectiveState(ServiceComponentHost sch, Host host); MaintenanceState getEffectiveState(ServiceComponentHost sch); MaintenanceState getEffectiveState(long clusterId, Alert alert); Set<Map<String, String>> getMaintenanceHostComponents(
      Clusters clusters, Cluster cluster); boolean isOperationAllowed(Resource.Type operationLevel,
      ServiceComponentHost sch); Resource.Type guessOperationLevel(RequestResourceFilter filter); Set<String> filterHostsInMaintenanceState(Set<String> candidateHosts,
      HostPredicate condition);  }