Search in sources :

Example 1 with DecommissionedResource

use of com.emc.storageos.db.client.model.DecommissionedResource in project coprhd-controller by CoprHD.

the class StorageProviderService method getDecommissionedResources.

/**
 * Get zone role assignments
 *
 * @brief List zone role assignments
 * @return Role assignment details
 */
@GET
@Path("/deactivated-systems")
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@CheckPermission(roles = { Role.SECURITY_ADMIN, Role.RESTRICTED_SECURITY_ADMIN })
public DecommissionedResources getDecommissionedResources() {
    List<URI> resList = _dbClient.queryByType(DecommissionedResource.class, true);
    DecommissionedResources results = new DecommissionedResources();
    for (URI res : resList) {
        DecommissionedResource resource = _dbClient.queryObject(DecommissionedResource.class, res);
        if ("StorageSystem".equals(resource.getType())) {
            results.addResource(map(resource));
        }
    }
    return results;
}
Also used : DecommissionedResource(com.emc.storageos.db.client.model.DecommissionedResource) URI(java.net.URI) DecommissionedResources(com.emc.storageos.model.varray.DecommissionedResources) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Example 2 with DecommissionedResource

use of com.emc.storageos.db.client.model.DecommissionedResource in project coprhd-controller by CoprHD.

the class StorageProviderService method deleteStorageProvider.

/**
 * Delete Storage Provider
 *
 * @param id
 * @brief Delete a storage provider
 * @return
 */
@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();
}
Also used : StringSet(com.emc.storageos.db.client.model.StringSet) DecommissionedResource(com.emc.storageos.db.client.model.DecommissionedResource) MapStorageProvider(com.emc.storageos.api.mapper.functions.MapStorageProvider) StorageProvider(com.emc.storageos.db.client.model.StorageProvider) StorageSystem(com.emc.storageos.db.client.model.StorageSystem) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Example 3 with DecommissionedResource

use of com.emc.storageos.db.client.model.DecommissionedResource in project coprhd-controller by CoprHD.

the class SMISProviderService method deleteSMISProvider.

/**
 * Allows the user to deactivate an SMI-S provider.
 * <p>
 * The method is deprecated. Use /vdc/storage-providers/{id}/deactivate instead.
 *
 * @param id the URN of a ViPR SMI-S provider
 *
 * @brief Delete SMI-S provider
 * @return Status indicating success or failure.
 */
@POST
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{id}/deactivate")
@CheckPermission(roles = { Role.SYSTEM_ADMIN })
public Response deleteSMISProvider(@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.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_SMISPROVIDER, true, null, provider.getId().toString(), provider.getLabel(), provider.getIPAddress(), provider.getPortNumber(), provider.getUserName());
    return Response.ok().build();
}
Also used : StringSet(com.emc.storageos.db.client.model.StringSet) DecommissionedResource(com.emc.storageos.db.client.model.DecommissionedResource) StorageProvider(com.emc.storageos.db.client.model.StorageProvider) StorageSystem(com.emc.storageos.db.client.model.StorageSystem) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces) Consumes(javax.ws.rs.Consumes) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Example 4 with DecommissionedResource

use of com.emc.storageos.db.client.model.DecommissionedResource in project coprhd-controller by CoprHD.

the class SMISProviderService method getDecommissionedResources.

/**
 * Get zone role assignments
 * The method is deprecated. Use /vdc/storage-providers/deactivated-systems
 *
 * @brief List zone role assignments
 * @return Role assignment details
 */
@GET
@Path("/deactivated-systems")
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@CheckPermission(roles = { Role.SECURITY_ADMIN })
public DecommissionedResources getDecommissionedResources() {
    List<URI> resList = _dbClient.queryByType(DecommissionedResource.class, true);
    DecommissionedResources results = new DecommissionedResources();
    for (URI res : resList) {
        DecommissionedResource resource = _dbClient.queryObject(DecommissionedResource.class, res);
        if ("StorageSystem".equals(resource.getType())) {
            results.addResource(map(resource));
        }
    }
    return results;
}
Also used : DecommissionedResource(com.emc.storageos.db.client.model.DecommissionedResource) URI(java.net.URI) DecommissionedResources(com.emc.storageos.model.varray.DecommissionedResources) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Example 5 with DecommissionedResource

use of com.emc.storageos.db.client.model.DecommissionedResource in project coprhd-controller by CoprHD.

the class StorageSystemService method deleteStorageSystem.

/**
 * Remove a storage system. The method would remove the storage system from the
 * system control and will remove all resources associated with the storage system from the database.
 * Note that resources (pools, ports, volumes, etc.) are not removed from the storage system physically,
 * but become unavailable for the user.
 *
 * @param id the URN of a ViPR storage system
 * @prereq none
 * @brief Delete storage system
 * @return An asynchronous task.
 *
 * @throws DatabaseException When an error occurs querying the database.
 */
@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 TaskResourceRep deleteStorageSystem(@PathParam("id") URI id) throws DatabaseException {
    StorageSystem system = _dbClient.queryObject(StorageSystem.class, id);
    ArgValidator.checkEntityNotNull(system, id, isIdEmbeddedInURL(id));
    if (!RegistrationStatus.UNREGISTERED.toString().equals(system.getRegistrationStatus())) {
        throw APIException.badRequests.cannotDeactivateStorageSystem();
    }
    // Ensure the storage system has no active RecoverPoint volumes under management.
    if (RPHelper.containsActiveRpVolumes(id, _dbClient)) {
        throw APIException.badRequests.cannotDeactivateStorageSystemActiveRpVolumes();
    }
    if (DiscoveredDataObject.DataCollectionJobStatus.IN_PROGRESS.toString().equals(system.getDiscoveryStatus()) || DiscoveredDataObject.DataCollectionJobStatus.SCHEDULED.toString().equals(system.getDiscoveryStatus())) {
        throw APIException.serviceUnavailable.cannotDeactivateStorageSystemWhileInDiscover(system.getId());
    }
    String taskId = UUID.randomUUID().toString();
    Operation op = _dbClient.createTaskOpStatus(StorageSystem.class, system.getId(), taskId, ResourceOperationTypeEnum.DELETE_STORAGE_SYSTEM);
    // Otherwise, the created decommissioned object will not be cleared when the provider is removed and added back.
    if (StringUtils.isNotBlank(system.getNativeGuid()) && system.isStorageSystemManagedByProvider() && !NullColumnValueGetter.isNullURI(system.getActiveProviderURI())) {
        DecommissionedResource oldStorage = null;
        List<URI> oldResources = _dbClient.queryByConstraint(AlternateIdConstraint.Factory.getDecommissionedResourceIDConstraint(id.toString()));
        if (oldResources != null) {
            List<DecommissionedResource> objects = _dbClient.queryObject(DecommissionedResource.class, oldResources);
            for (DecommissionedResource decomObj : objects) {
                if (!decomObj.getInactive()) {
                    oldStorage = decomObj;
                    break;
                }
            }
        }
        if (oldStorage == null) {
            oldStorage = new DecommissionedResource();
            oldStorage.setNativeGuid(system.getNativeGuid());
            oldStorage.setType(TypeMap.getCFName(StorageSystem.class));
            oldStorage.setUser(getUserFromContext().getName());
            oldStorage.setDecommissionedId(system.getId());
            oldStorage.setLabel(system.getLabel());
            oldStorage.setId(URIUtil.createId(DecommissionedResource.class));
            _dbClient.createObject(oldStorage);
        }
        StorageProvider provider = _dbClient.queryObject(StorageProvider.class, system.getActiveProviderURI());
        if (provider != null) {
            StringSet providerDecomSys = provider.getDecommissionedSystems();
            if (providerDecomSys == null) {
                providerDecomSys = new StringSet();
                provider.setDecommissionedSystems(providerDecomSys);
            }
            providerDecomSys.add(oldStorage.getId().toString());
            _dbClient.updateObject(provider);
        }
    }
    PurgeRunnable.executePurging(_dbClient, _dbPurger, _asynchJobService.getExecutorService(), system, _retry_attempts, taskId, 60);
    return toTask(system, taskId, op);
}
Also used : StringSet(com.emc.storageos.db.client.model.StringSet) DecommissionedResource(com.emc.storageos.db.client.model.DecommissionedResource) Operation(com.emc.storageos.db.client.model.Operation) StorageProvider(com.emc.storageos.db.client.model.StorageProvider) URI(java.net.URI) StorageSystem(com.emc.storageos.db.client.model.StorageSystem) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Aggregations

DecommissionedResource (com.emc.storageos.db.client.model.DecommissionedResource)5 CheckPermission (com.emc.storageos.security.authorization.CheckPermission)5 Path (javax.ws.rs.Path)5 Produces (javax.ws.rs.Produces)5 StorageProvider (com.emc.storageos.db.client.model.StorageProvider)3 StorageSystem (com.emc.storageos.db.client.model.StorageSystem)3 StringSet (com.emc.storageos.db.client.model.StringSet)3 URI (java.net.URI)3 Consumes (javax.ws.rs.Consumes)3 POST (javax.ws.rs.POST)3 DecommissionedResources (com.emc.storageos.model.varray.DecommissionedResources)2 GET (javax.ws.rs.GET)2 MapStorageProvider (com.emc.storageos.api.mapper.functions.MapStorageProvider)1 Operation (com.emc.storageos.db.client.model.Operation)1