@Test public void testCutOffHosts() throws AmbariException { MaintenanceStateHelper.HostPredicate predicate = createMock(MaintenanceStateHelper.HostPredicate.class); expect(predicate.shouldHostBeRemoved(eq("host1"))).andReturn(true); expect(predicate.shouldHostBeRemoved(eq("host2"))).andReturn(false); expect(predicate.shouldHostBeRemoved(eq("host3"))).andReturn(true); expect(predicate.shouldHostBeRemoved(eq("host4"))).andReturn(false); Set<String> candidates = new HashSet<String>(); candidates.add("host1"); candidates.add("host2"); candidates.add("host3"); candidates.add("host4"); Injector injector = createStrictMock(Injector.class); MaintenanceStateHelper maintenanceStateHelper = createMockBuilder(MaintenanceStateHelper.class) .withConstructor(injector) .createNiceMock(); replay(predicate, maintenanceStateHelper); Set<String> ignored = maintenanceStateHelper.filterHostsInMaintenanceState(candidates, predicate); verify(predicate, maintenanceStateHelper); Assert.assertEquals(candidates.size(), 2); Assert.assertTrue(candidates.contains("host2")); Assert.assertTrue(candidates.contains("host4")); Assert.assertEquals(ignored.size(), 2); Assert.assertTrue(ignored.contains("host1")); Assert.assertTrue(ignored.contains("host3")); }
public Set<String> filterHostsInMaintenanceState(Set<String> candidateHosts, HostPredicate condition) throws AmbariException { Set<String> removedHosts = new HashSet<String>(); for (String hostname : candidateHosts) { if (condition.shouldHostBeRemoved(hostname)) { removedHosts.add(hostname); } } candidateHosts.removeAll(removedHosts); return removedHosts; }
MaintenanceStateHelper { public Set<String> filterHostsInMaintenanceState(Set<String> candidateHosts, HostPredicate condition) throws AmbariException { Set<String> removedHosts = new HashSet<String>(); for (String hostname : candidateHosts) { if (condition.shouldHostBeRemoved(hostname)) { removedHosts.add(hostname); } } candidateHosts.removeAll(removedHosts); return removedHosts; } }
MaintenanceStateHelper { public Set<String> filterHostsInMaintenanceState(Set<String> candidateHosts, HostPredicate condition) throws AmbariException { Set<String> removedHosts = new HashSet<String>(); for (String hostname : candidateHosts) { if (condition.shouldHostBeRemoved(hostname)) { removedHosts.add(hostname); } } candidateHosts.removeAll(removedHosts); return removedHosts; } @Inject  MaintenanceStateHelper(Injector injector); }
MaintenanceStateHelper { public Set<String> filterHostsInMaintenanceState(Set<String> candidateHosts, HostPredicate condition) throws AmbariException { Set<String> removedHosts = new HashSet<String>(); for (String hostname : candidateHosts) { if (condition.shouldHostBeRemoved(hostname)) { removedHosts.add(hostname); } } candidateHosts.removeAll(removedHosts); return removedHosts; } @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 Set<String> filterHostsInMaintenanceState(Set<String> candidateHosts, HostPredicate condition) throws AmbariException { Set<String> removedHosts = new HashSet<String>(); for (String hostname : candidateHosts) { if (condition.shouldHostBeRemoved(hostname)) { removedHosts.add(hostname); } } candidateHosts.removeAll(removedHosts); return removedHosts; } @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);  }