use of com.emc.storageos.imageservercontroller.ComputeImageCompleter in project coprhd-controller by CoprHD.
the class ImageServerControllerImpl method importImageToServers.
/**
* Import image to all available imageServer
*
* @param task {@link AsyncTask} instance
*/
@Override
public void importImageToServers(AsyncTask task) throws InternalException {
log.info("importImage");
URI ciId = task._id;
boolean wfHasSteps = false;
Workflow workflow = workflowService.getNewWorkflow(this, IMPORT_IMAGE_WF, true, task._opId);
TaskCompleter completer = new ComputeImageCompleter(ciId, task._opId, OperationTypeEnum.CREATE_COMPUTE_IMAGE, EVENT_SERVICE_TYPE);
try {
List<URI> ids = dbClient.queryByType(ComputeImageServer.class, true);
for (URI imageServerId : ids) {
log.info("import to server:" + imageServerId.toString());
ComputeImageServer imageServer = dbClient.queryObject(ComputeImageServer.class, imageServerId);
if (imageServer.getComputeImages() == null || !imageServer.getComputeImages().contains(ciId.toString())) {
log.info("verify Image Server");
String verifyServerStepId = workflow.createStep(IMAGESERVER_VERIFICATION_STEP, String.format("Verifying ImageServer %s", imageServerId), null, imageServerId, imageServerId.toString(), this.getClass(), new Workflow.Method("verifyComputeImageServer", imageServerId), new Workflow.Method(ROLLBACK_NOTHING_METHOD), null);
workflow.createStep(IMPORT_IMAGE_TO_SERVER_STEP, String.format("Importing image for %s", imageServerId), verifyServerStepId, imageServerId, imageServerId.toString(), this.getClass(), new Workflow.Method("importImageMethod", ciId, imageServer, null), new Workflow.Method(ROLLBACK_NOTHING_METHOD), null);
wfHasSteps = true;
}
}
if (wfHasSteps) {
workflow.executePlan(completer, SUCCESS);
}
} catch (Exception e) {
log.error("importImage caught an exception.", e);
ServiceError serviceError = DeviceControllerException.errors.jobFailed(e);
completer.error(dbClient, serviceError);
}
}
use of com.emc.storageos.imageservercontroller.ComputeImageCompleter in project coprhd-controller by CoprHD.
the class ImageServerControllerImpl method deleteImage.
/**
* Delete image from all available imageServers
*
* @param task {@link AsyncTask} instance
*/
@Override
public void deleteImage(AsyncTask task) throws InternalException {
log.info("deleteImage " + task._id);
URI ciId = task._id;
TaskCompleter completer = null;
try {
completer = new ComputeImageCompleter(ciId, task._opId, OperationTypeEnum.DELETE_COMPUTE_IMAGE, EVENT_SERVICE_TYPE);
Workflow workflow = workflowService.getNewWorkflow(this, DELETE_IMAGE_WF, true, task._opId);
List<URI> ids = dbClient.queryByType(ComputeImageServer.class, true);
for (URI imageServerId : ids) {
ComputeImageServer imageServer = dbClient.queryObject(ComputeImageServer.class, imageServerId);
if (imageServer.getComputeImages() != null && imageServer.getComputeImages().contains(ciId.toString())) {
boolean imageServerVerified = verifyImageServer(imageServer);
if (!imageServerVerified) {
throw ImageServerControllerException.exceptions.imageServerNotSetup("Can't delete image: " + imageServerErrorMsg);
}
workflow.createStep(DELETE_IMAGE_STEP, String.format("removing image %s", ciId), null, ciId, ciId.toString(), this.getClass(), new Workflow.Method("deleteImageMethod", ciId, imageServer.getId()), new Workflow.Method(ROLLBACK_NOTHING_METHOD), null);
}
// So this cleanup needs to be performed.
if (imageServer.getFailedComputeImages() != null && imageServer.getFailedComputeImages().contains(ciId.toString())) {
imageServer.getFailedComputeImages().remove(ciId.toString());
dbClient.updateObject(imageServer);
}
}
workflow.executePlan(completer, SUCCESS);
} catch (Exception e) {
log.error("deleteImage caught an exception.", e);
ServiceError serviceError = DeviceControllerException.errors.jobFailed(e);
completer.error(dbClient, serviceError);
}
}
Aggregations