@Test public void testPerform() throws Exception { final ServicesMaintenanceModeCheck servicesMaintenanceModeCheck = new ServicesMaintenanceModeCheck(); servicesMaintenanceModeCheck.clustersProvider = new Provider<Clusters>() { @Override public Clusters get() { return clusters; } }; servicesMaintenanceModeCheck.ambariMetaInfo = new Provider<AmbariMetaInfo>() { @Override public AmbariMetaInfo get() { return Mockito.mock(AmbariMetaInfo.class); } }; final Cluster cluster = Mockito.mock(Cluster.class); Mockito.when(cluster.getClusterId()).thenReturn(1L); Mockito.when(cluster.getCurrentStackVersion()).thenReturn(new StackId("HDP", "2.2")); Mockito.when(clusters.getCluster("cluster")).thenReturn(cluster); final Service service = Mockito.mock(Service.class); Mockito.when(cluster.getServices()).thenReturn(Collections.singletonMap("service", service)); Mockito.when(service.isClientOnlyService()).thenReturn(false); Mockito.when(service.getDesiredState()).thenReturn(State.UNKNOWN); PrerequisiteCheck check = new PrerequisiteCheck(null, null); servicesMaintenanceModeCheck.perform(check, new PrereqCheckRequest("cluster")); Assert.assertEquals(PrereqCheckStatus.PASS, check.getStatus()); Mockito.when(service.getDesiredState()).thenReturn(State.STARTED); check = new PrerequisiteCheck(null, null); servicesMaintenanceModeCheck.perform(check, new PrereqCheckRequest("cluster")); Assert.assertEquals(PrereqCheckStatus.PASS, check.getStatus()); }
@Override public void perform(PrerequisiteCheck prerequisiteCheck, PrereqCheckRequest request) throws AmbariException { final String clusterName = request.getClusterName(); final Cluster cluster = clustersProvider.get().getCluster(clusterName); for (Map.Entry<String, Service> serviceEntry : cluster.getServices().entrySet()) { final Service service = serviceEntry.getValue(); if (!service.isClientOnlyService() && service.getMaintenanceState() == MaintenanceState.ON) { prerequisiteCheck.getFailedOn().add(service.getName()); } } if (!prerequisiteCheck.getFailedOn().isEmpty()) { prerequisiteCheck.setStatus(PrereqCheckStatus.FAIL); prerequisiteCheck.setFailReason(getFailReason(prerequisiteCheck, request)); } }
ServicesMaintenanceModeCheck extends AbstractCheckDescriptor { @Override public void perform(PrerequisiteCheck prerequisiteCheck, PrereqCheckRequest request) throws AmbariException { final String clusterName = request.getClusterName(); final Cluster cluster = clustersProvider.get().getCluster(clusterName); for (Map.Entry<String, Service> serviceEntry : cluster.getServices().entrySet()) { final Service service = serviceEntry.getValue(); if (!service.isClientOnlyService() && service.getMaintenanceState() == MaintenanceState.ON) { prerequisiteCheck.getFailedOn().add(service.getName()); } } if (!prerequisiteCheck.getFailedOn().isEmpty()) { prerequisiteCheck.setStatus(PrereqCheckStatus.FAIL); prerequisiteCheck.setFailReason(getFailReason(prerequisiteCheck, request)); } } }
ServicesMaintenanceModeCheck extends AbstractCheckDescriptor { @Override public void perform(PrerequisiteCheck prerequisiteCheck, PrereqCheckRequest request) throws AmbariException { final String clusterName = request.getClusterName(); final Cluster cluster = clustersProvider.get().getCluster(clusterName); for (Map.Entry<String, Service> serviceEntry : cluster.getServices().entrySet()) { final Service service = serviceEntry.getValue(); if (!service.isClientOnlyService() && service.getMaintenanceState() == MaintenanceState.ON) { prerequisiteCheck.getFailedOn().add(service.getName()); } } if (!prerequisiteCheck.getFailedOn().isEmpty()) { prerequisiteCheck.setStatus(PrereqCheckStatus.FAIL); prerequisiteCheck.setFailReason(getFailReason(prerequisiteCheck, request)); } } ServicesMaintenanceModeCheck(); }
ServicesMaintenanceModeCheck extends AbstractCheckDescriptor { @Override public void perform(PrerequisiteCheck prerequisiteCheck, PrereqCheckRequest request) throws AmbariException { final String clusterName = request.getClusterName(); final Cluster cluster = clustersProvider.get().getCluster(clusterName); for (Map.Entry<String, Service> serviceEntry : cluster.getServices().entrySet()) { final Service service = serviceEntry.getValue(); if (!service.isClientOnlyService() && service.getMaintenanceState() == MaintenanceState.ON) { prerequisiteCheck.getFailedOn().add(service.getName()); } } if (!prerequisiteCheck.getFailedOn().isEmpty()) { prerequisiteCheck.setStatus(PrereqCheckStatus.FAIL); prerequisiteCheck.setFailReason(getFailReason(prerequisiteCheck, request)); } } ServicesMaintenanceModeCheck(); @Override void perform(PrerequisiteCheck prerequisiteCheck, PrereqCheckRequest request); }
ServicesMaintenanceModeCheck extends AbstractCheckDescriptor { @Override public void perform(PrerequisiteCheck prerequisiteCheck, PrereqCheckRequest request) throws AmbariException { final String clusterName = request.getClusterName(); final Cluster cluster = clustersProvider.get().getCluster(clusterName); for (Map.Entry<String, Service> serviceEntry : cluster.getServices().entrySet()) { final Service service = serviceEntry.getValue(); if (!service.isClientOnlyService() && service.getMaintenanceState() == MaintenanceState.ON) { prerequisiteCheck.getFailedOn().add(service.getName()); } } if (!prerequisiteCheck.getFailedOn().isEmpty()) { prerequisiteCheck.setStatus(PrereqCheckStatus.FAIL); prerequisiteCheck.setFailReason(getFailReason(prerequisiteCheck, request)); } } ServicesMaintenanceModeCheck(); @Override void perform(PrerequisiteCheck prerequisiteCheck, PrereqCheckRequest request);  }