@POST @Path("/{id}/deactivate") @Consumes({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) @CheckPermission(roles = {Role.SYSTEM_ADMIN, Role.RESTRICTED_SYSTEM_ADMIN}) public Response deleteStorageProvider(@PathParam("id") URI id) { // Validate the provider ArgValidator.checkFieldUriType(id, StorageProvider.class, "id"); StorageProvider provider = _dbClient.queryObject(StorageProvider.class, id); ArgValidator.checkEntityNotNull(provider, id, isIdEmbeddedInURL(id)); // Verify the provider can be removed without leaving "dangling" storages. StringSet providerStorageSystems = provider.getStorageSystems(); if (null != providerStorageSystems && !providerStorageSystems.isEmpty()) { // First we need to verify that all related storage systems has at least 2 providers for (String system : providerStorageSystems) { StorageSystem storageSys = _dbClient.queryObject(StorageSystem.class, URI.create(system)); if (storageSys != null && !storageSys.getInactive() && storageSys.getProviders() != null && storageSys.getProviders().size() == 1) { throw APIException.badRequests.cannotDeleteProviderWithManagedStorageSystems( storageSys.getId()); } } // Next we can clear this provider from storage systems. for (String system : providerStorageSystems) { StorageSystem storageSys = _dbClient.queryObject(StorageSystem.class, URI.create(system)); provider.removeStorageSystem(_dbClient, storageSys); } } StringSet decommissionedSystems = provider.getDecommissionedSystems(); if (null != decommissionedSystems && !decommissionedSystems.isEmpty()) { for (String decommissioned : decommissionedSystems) { DecommissionedResource oldRes = _dbClient.queryObject(DecommissionedResource.class, URI.create(decommissioned)); if (oldRes != null) { _dbClient.markForDeletion(oldRes); } } } // Set to inactive. _dbClient.markForDeletion(provider); auditOp( OperationTypeEnum.DELETE_STORAGEPROVIDER, true, null, provider.getId().toString(), provider.getLabel(), provider.getIPAddress(), provider.getPortNumber(), provider.getUserName(), provider.getInterfaceType()); return Response.ok().build(); }