@Test public void testGuessOperationLevel() { Injector injector = createStrictMock(Injector.class); MaintenanceStateHelper maintenanceStateHelper = createMockBuilder(MaintenanceStateHelper.class) .withConstructor(injector) .createNiceMock(); replay(maintenanceStateHelper); Assert.assertEquals(Resource.Type.Cluster, maintenanceStateHelper.guessOperationLevel(null)); RequestResourceFilter resourceFilter = new RequestResourceFilter(null, null, null); Assert.assertEquals(Resource.Type.Cluster, maintenanceStateHelper.guessOperationLevel(resourceFilter)); resourceFilter = new RequestResourceFilter("HDFS", null, null); Assert.assertEquals(Resource.Type.Service, maintenanceStateHelper.guessOperationLevel(resourceFilter)); resourceFilter = new RequestResourceFilter("HDFS", "NAMENODE", null); Assert.assertEquals(Resource.Type.Service, maintenanceStateHelper.guessOperationLevel(resourceFilter)); ArrayList<String> hosts = new ArrayList<String>(); hosts.add("host1"); hosts.add("host2"); resourceFilter = new RequestResourceFilter("HDFS", null, hosts); Assert.assertEquals(Resource.Type.Cluster, maintenanceStateHelper.guessOperationLevel(resourceFilter)); resourceFilter = new RequestResourceFilter(null, null, hosts); Assert.assertEquals(Resource.Type.Host, maintenanceStateHelper.guessOperationLevel(resourceFilter)); resourceFilter = new RequestResourceFilter("HDFS", "NAMENODE", hosts); Assert.assertEquals(Resource.Type.HostComponent, maintenanceStateHelper.guessOperationLevel(resourceFilter)); }
public Resource.Type guessOperationLevel(RequestResourceFilter filter) { Resource.Type result; if (filter == null) { result = Resource.Type.Cluster; } else { boolean serviceDefined = filter.getServiceName() != null; boolean componentDefined = filter.getComponentName() != null; boolean hostsDefined = filter.getHostNames() != null && filter.getHostNames().size() > 0; if (hostsDefined & componentDefined) { result = Resource.Type.HostComponent; } else if (!serviceDefined & hostsDefined) { result = Resource.Type.Host; } else if (serviceDefined & !hostsDefined) { result = Resource.Type.Service; } else { result = Resource.Type.Cluster; } } return result; }
MaintenanceStateHelper { public Resource.Type guessOperationLevel(RequestResourceFilter filter) { Resource.Type result; if (filter == null) { result = Resource.Type.Cluster; } else { boolean serviceDefined = filter.getServiceName() != null; boolean componentDefined = filter.getComponentName() != null; boolean hostsDefined = filter.getHostNames() != null && filter.getHostNames().size() > 0; if (hostsDefined & componentDefined) { result = Resource.Type.HostComponent; } else if (!serviceDefined & hostsDefined) { result = Resource.Type.Host; } else if (serviceDefined & !hostsDefined) { result = Resource.Type.Service; } else { result = Resource.Type.Cluster; } } return result; } }
MaintenanceStateHelper { public Resource.Type guessOperationLevel(RequestResourceFilter filter) { Resource.Type result; if (filter == null) { result = Resource.Type.Cluster; } else { boolean serviceDefined = filter.getServiceName() != null; boolean componentDefined = filter.getComponentName() != null; boolean hostsDefined = filter.getHostNames() != null && filter.getHostNames().size() > 0; if (hostsDefined & componentDefined) { result = Resource.Type.HostComponent; } else if (!serviceDefined & hostsDefined) { result = Resource.Type.Host; } else if (serviceDefined & !hostsDefined) { result = Resource.Type.Service; } else { result = Resource.Type.Cluster; } } return result; } @Inject  MaintenanceStateHelper(Injector injector); }
MaintenanceStateHelper { public Resource.Type guessOperationLevel(RequestResourceFilter filter) { Resource.Type result; if (filter == null) { result = Resource.Type.Cluster; } else { boolean serviceDefined = filter.getServiceName() != null; boolean componentDefined = filter.getComponentName() != null; boolean hostsDefined = filter.getHostNames() != null && filter.getHostNames().size() > 0; if (hostsDefined & componentDefined) { result = Resource.Type.HostComponent; } else if (!serviceDefined & hostsDefined) { result = Resource.Type.Host; } else if (serviceDefined & !hostsDefined) { result = Resource.Type.Service; } else { result = Resource.Type.Cluster; } } return result; } @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 Resource.Type guessOperationLevel(RequestResourceFilter filter) { Resource.Type result; if (filter == null) { result = Resource.Type.Cluster; } else { boolean serviceDefined = filter.getServiceName() != null; boolean componentDefined = filter.getComponentName() != null; boolean hostsDefined = filter.getHostNames() != null && filter.getHostNames().size() > 0; if (hostsDefined & componentDefined) { result = Resource.Type.HostComponent; } else if (!serviceDefined & hostsDefined) { result = Resource.Type.Host; } else if (serviceDefined & !hostsDefined) { result = Resource.Type.Service; } else { result = Resource.Type.Cluster; } } return result; } @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);  }