Search in sources :

Example 21 with ComputeImage

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

the class ComputeImageService method deleteComputeImage.

/**
 * Delete existing compute image.
 *
 * @param id
 *            compute image URN.
 * @brief Delete compute image
 * @return Async task remove the image from multiple image serevers returned in response body
 */
@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 deleteComputeImage(@PathParam("id") URI id, @QueryParam("force") String force) {
    log.info("deleteComputeImage: {}", id);
    ComputeImage ci = queryObject(ComputeImage.class, id, true);
    ArgValidator.checkEntity(ci, id, isIdEmbeddedInURL(id));
    if (ComputeImage.ComputeImageStatus.AVAILABLE.name().equals(ci.getComputeImageStatus())) {
        if (force == null || !force.equals("true")) {
            // make sure there are no active jobs associated with this image
            URIQueryResultList ceUriList = new URIQueryResultList();
            _dbClient.queryByConstraint(ContainmentConstraint.Factory.getComputeImageJobsByComputeImageConstraint(ci.getId()), ceUriList);
            Iterator<URI> iterator = ceUriList.iterator();
            while (iterator.hasNext()) {
                ComputeImageJob job = _dbClient.queryObject(ComputeImageJob.class, iterator.next());
                if (job.getJobStatus().equals(ComputeImageJob.JobStatus.CREATED.name())) {
                    throw APIException.badRequests.cannotDeleteComputeWhileInUse();
                }
            }
        }
        auditOp(OperationTypeEnum.DELETE_COMPUTE_IMAGE, true, AuditLogManager.AUDITOP_BEGIN, ci.getId().toString(), ci.getImageUrl());
        return doRemoveImage(ci);
    } else if (ComputeImage.ComputeImageStatus.IN_PROGRESS.name().equals(ci.getComputeImageStatus())) {
        if (force == null || !force.equals("true")) {
            throw APIException.badRequests.resourceCannotBeDeleted(ci.getLabel());
        } else {
            // delete is forced
            deleteImageFromImageServers(ci);
            _dbClient.markForDeletion(ci);
            auditOp(OperationTypeEnum.DELETE_COMPUTE_IMAGE, true, null, ci.getId().toString(), ci.getImageUrl());
            return getReadyOp(ci, ResourceOperationTypeEnum.REMOVE_IMAGE);
        }
    } else {
        // NOT_AVAILABLE
        deleteImageFromImageServers(ci);
        _dbClient.markForDeletion(ci);
        auditOp(OperationTypeEnum.DELETE_COMPUTE_IMAGE, true, null, ci.getId().toString(), ci.getImageUrl());
        return getReadyOp(ci, ResourceOperationTypeEnum.REMOVE_IMAGE);
    }
}
Also used : ComputeImageJob(com.emc.storageos.db.client.model.ComputeImageJob) URI(java.net.URI) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList) ComputeImage(com.emc.storageos.db.client.model.ComputeImage) 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 22 with ComputeImage

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

the class ComputeImageService method getComputeImage.

/**
 * Show compute image attribute.
 *
 * @param id
 *            the URN of compute image
 * @brief Show compute image
 * @return Compute image details
 */
@GET
@Path("/{id}")
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public ComputeImageRestRep getComputeImage(@PathParam("id") URI id) {
    ArgValidator.checkFieldUriType(id, ComputeImage.class, "id");
    ComputeImage ci = queryResource(id);
    List<ComputeImageServer> successfulServers = new ArrayList<ComputeImageServer>();
    List<ComputeImageServer> failedServers = new ArrayList<ComputeImageServer>();
    getImageImportStatus(ci, successfulServers, failedServers);
    return ComputeMapper.map(ci, successfulServers, failedServers);
}
Also used : ComputeImageServer(com.emc.storageos.db.client.model.ComputeImageServer) ArrayList(java.util.ArrayList) ComputeImage(com.emc.storageos.db.client.model.ComputeImage) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Aggregations

ComputeImage (com.emc.storageos.db.client.model.ComputeImage)22 URI (java.net.URI)10 ComputeImageServer (com.emc.storageos.db.client.model.ComputeImageServer)8 InternalException (com.emc.storageos.svcs.errorhandling.resources.InternalException)7 Produces (javax.ws.rs.Produces)7 ComputeImageJob (com.emc.storageos.db.client.model.ComputeImageJob)6 DeviceControllerException (com.emc.storageos.exceptions.DeviceControllerException)6 ImageServerControllerException (com.emc.storageos.imageservercontroller.exceptions.ImageServerControllerException)6 UnsupportedEncodingException (java.io.UnsupportedEncodingException)6 MalformedURLException (java.net.MalformedURLException)6 Consumes (javax.ws.rs.Consumes)5 Path (javax.ws.rs.Path)5 SSHSession (com.emc.storageos.networkcontroller.SSHSession)4 CheckPermission (com.emc.storageos.security.authorization.CheckPermission)4 URIQueryResultList (com.emc.storageos.db.client.constraint.URIQueryResultList)3 Host (com.emc.storageos.db.client.model.Host)3 POST (javax.ws.rs.POST)3 DbClient (com.emc.storageos.db.client.DbClient)2 ComputeElement (com.emc.storageos.db.client.model.ComputeElement)2 ComputeSystem (com.emc.storageos.db.client.model.ComputeSystem)2