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);
}
}
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);
}
Aggregations