@Test public void testDeleteResourcesBadServiceState() throws Exception { AmbariManagementController managementController = createMock(AmbariManagementController.class); Clusters clusters = createNiceMock(Clusters.class); Cluster cluster = createNiceMock(Cluster.class); Service service = createNiceMock(Service.class); String serviceName = "Service100"; expect(managementController.getClusters()).andReturn(clusters).anyTimes(); expect(clusters.getCluster("Cluster100")).andReturn(cluster).anyTimes(); expect(cluster.getClusterId()).andReturn(2L).anyTimes(); expect(cluster.getService(serviceName)).andReturn(service).anyTimes(); expect(service.getDesiredState()).andReturn(State.STARTED).anyTimes(); expect(service.getName()).andReturn(serviceName).anyTimes(); expect(service.getServiceComponents()).andReturn(new HashMap<String, ServiceComponent>()); expect(service.getCluster()).andReturn(cluster); cluster.deleteService(serviceName); replay(managementController, clusters, cluster, service); SecurityContextHolder.getContext().setAuthentication(TestAuthenticationFactory.createAdministrator()); ResourceProvider provider = getServiceProvider(managementController); AbstractResourceProviderTest.TestObserver observer = new AbstractResourceProviderTest.TestObserver(); ((ObservableResourceProvider)provider).addObserver(observer); Predicate predicate = new PredicateBuilder().property(ServiceResourceProvider.SERVICE_CLUSTER_NAME_PROPERTY_ID).equals("Cluster100").and() .property(ServiceResourceProvider.SERVICE_SERVICE_NAME_PROPERTY_ID).equals(serviceName).toPredicate(); provider.deleteResources(new RequestImpl(null, null, null, null), predicate); ResourceProviderEvent lastEvent = observer.getLastEvent(); Assert.assertNotNull(lastEvent); Assert.assertEquals(Resource.Type.Service, lastEvent.getResourceType()); Assert.assertEquals(ResourceProviderEvent.Type.Delete, lastEvent.getType()); Assert.assertEquals(predicate, lastEvent.getPredicate()); Assert.assertNull(lastEvent.getRequest()); verify(managementController, clusters, cluster, service); }
private ServiceRequest getRequest(Map<String, Object> properties) { ServiceRequest svcRequest = new ServiceRequest( (String) properties.get(SERVICE_CLUSTER_NAME_PROPERTY_ID), (String) properties.get(SERVICE_SERVICE_NAME_PROPERTY_ID), (String) properties.get(SERVICE_SERVICE_STATE_PROPERTY_ID), (String) properties.get(SERVICE_CREDENTIAL_STORE_ENABLED_PROPERTY_ID)); Object o = properties.get(SERVICE_MAINTENANCE_STATE_PROPERTY_ID); if (null != o) { svcRequest.setMaintenanceState(o.toString()); } o = properties.get(SERVICE_CREDENTIAL_STORE_SUPPORTED_PROPERTY_ID); if (null != o) { svcRequest.setMaintenanceState(o.toString()); } return svcRequest; }
ServiceResourceProvider extends AbstractControllerResourceProvider { private ServiceRequest getRequest(Map<String, Object> properties) { ServiceRequest svcRequest = new ServiceRequest( (String) properties.get(SERVICE_CLUSTER_NAME_PROPERTY_ID), (String) properties.get(SERVICE_SERVICE_NAME_PROPERTY_ID), (String) properties.get(SERVICE_SERVICE_STATE_PROPERTY_ID), (String) properties.get(SERVICE_CREDENTIAL_STORE_ENABLED_PROPERTY_ID)); Object o = properties.get(SERVICE_MAINTENANCE_STATE_PROPERTY_ID); if (null != o) { svcRequest.setMaintenanceState(o.toString()); } o = properties.get(SERVICE_CREDENTIAL_STORE_SUPPORTED_PROPERTY_ID); if (null != o) { svcRequest.setMaintenanceState(o.toString()); } return svcRequest; } }
ServiceResourceProvider extends AbstractControllerResourceProvider { private ServiceRequest getRequest(Map<String, Object> properties) { ServiceRequest svcRequest = new ServiceRequest( (String) properties.get(SERVICE_CLUSTER_NAME_PROPERTY_ID), (String) properties.get(SERVICE_SERVICE_NAME_PROPERTY_ID), (String) properties.get(SERVICE_SERVICE_STATE_PROPERTY_ID), (String) properties.get(SERVICE_CREDENTIAL_STORE_ENABLED_PROPERTY_ID)); Object o = properties.get(SERVICE_MAINTENANCE_STATE_PROPERTY_ID); if (null != o) { svcRequest.setMaintenanceState(o.toString()); } o = properties.get(SERVICE_CREDENTIAL_STORE_SUPPORTED_PROPERTY_ID); if (null != o) { svcRequest.setMaintenanceState(o.toString()); } return svcRequest; } @AssistedInject  ServiceResourceProvider(@Assisted Set<String> propertyIds,
                          @Assisted Map<Resource.Type, String> keyPropertyIds,
                          @Assisted AmbariManagementController managementController,
                          MaintenanceStateHelper maintenanceStateHelper); }
ServiceResourceProvider extends AbstractControllerResourceProvider { private ServiceRequest getRequest(Map<String, Object> properties) { ServiceRequest svcRequest = new ServiceRequest( (String) properties.get(SERVICE_CLUSTER_NAME_PROPERTY_ID), (String) properties.get(SERVICE_SERVICE_NAME_PROPERTY_ID), (String) properties.get(SERVICE_SERVICE_STATE_PROPERTY_ID), (String) properties.get(SERVICE_CREDENTIAL_STORE_ENABLED_PROPERTY_ID)); Object o = properties.get(SERVICE_MAINTENANCE_STATE_PROPERTY_ID); if (null != o) { svcRequest.setMaintenanceState(o.toString()); } o = properties.get(SERVICE_CREDENTIAL_STORE_SUPPORTED_PROPERTY_ID); if (null != o) { svcRequest.setMaintenanceState(o.toString()); } return svcRequest; } @AssistedInject  ServiceResourceProvider(@Assisted Set<String> propertyIds,
                          @Assisted Map<Resource.Type, String> keyPropertyIds,
                          @Assisted AmbariManagementController managementController,
                          MaintenanceStateHelper maintenanceStateHelper); @Override Set<String> checkPropertyIds(Set<String> propertyIds); void createServices(Set<ServiceRequest> requests); }
ServiceResourceProvider extends AbstractControllerResourceProvider { private ServiceRequest getRequest(Map<String, Object> properties) { ServiceRequest svcRequest = new ServiceRequest( (String) properties.get(SERVICE_CLUSTER_NAME_PROPERTY_ID), (String) properties.get(SERVICE_SERVICE_NAME_PROPERTY_ID), (String) properties.get(SERVICE_SERVICE_STATE_PROPERTY_ID), (String) properties.get(SERVICE_CREDENTIAL_STORE_ENABLED_PROPERTY_ID)); Object o = properties.get(SERVICE_MAINTENANCE_STATE_PROPERTY_ID); if (null != o) { svcRequest.setMaintenanceState(o.toString()); } o = properties.get(SERVICE_CREDENTIAL_STORE_SUPPORTED_PROPERTY_ID); if (null != o) { svcRequest.setMaintenanceState(o.toString()); } return svcRequest; } @AssistedInject  ServiceResourceProvider(@Assisted Set<String> propertyIds,
                          @Assisted Map<Resource.Type, String> keyPropertyIds,
                          @Assisted AmbariManagementController managementController,
                          MaintenanceStateHelper maintenanceStateHelper); @Override Set<String> checkPropertyIds(Set<String> propertyIds); void createServices(Set<ServiceRequest> requests); static final String SERVICE_CLUSTER_NAME_PROPERTY_ID; static final String SERVICE_SERVICE_NAME_PROPERTY_ID; static final String SERVICE_SERVICE_STATE_PROPERTY_ID; static final String SERVICE_MAINTENANCE_STATE_PROPERTY_ID; static final String SERVICE_CREDENTIAL_STORE_SUPPORTED_PROPERTY_ID; static final String SERVICE_CREDENTIAL_STORE_ENABLED_PROPERTY_ID; static final String SERVICE_ATTRIBUTES_PROPERTY_ID; }