Search in sources :

Example 1 with ComputeImageCompleter

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);
    }
}
Also used : ServiceError(com.emc.storageos.svcs.errorhandling.model.ServiceError) ComputeImageCompleter(com.emc.storageos.imageservercontroller.ComputeImageCompleter) ComputeImageServer(com.emc.storageos.db.client.model.ComputeImageServer) Workflow(com.emc.storageos.workflow.Workflow) TaskCompleter(com.emc.storageos.volumecontroller.TaskCompleter) URI(java.net.URI) InternalException(com.emc.storageos.svcs.errorhandling.resources.InternalException) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) MalformedURLException(java.net.MalformedURLException) ImageServerControllerException(com.emc.storageos.imageservercontroller.exceptions.ImageServerControllerException)

Example 2 with ComputeImageCompleter

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);
    }
}
Also used : ServiceError(com.emc.storageos.svcs.errorhandling.model.ServiceError) ComputeImageCompleter(com.emc.storageos.imageservercontroller.ComputeImageCompleter) ComputeImageServer(com.emc.storageos.db.client.model.ComputeImageServer) Workflow(com.emc.storageos.workflow.Workflow) TaskCompleter(com.emc.storageos.volumecontroller.TaskCompleter) URI(java.net.URI) InternalException(com.emc.storageos.svcs.errorhandling.resources.InternalException) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) MalformedURLException(java.net.MalformedURLException) ImageServerControllerException(com.emc.storageos.imageservercontroller.exceptions.ImageServerControllerException)

Aggregations

ComputeImageServer (com.emc.storageos.db.client.model.ComputeImageServer)2 DeviceControllerException (com.emc.storageos.exceptions.DeviceControllerException)2 ComputeImageCompleter (com.emc.storageos.imageservercontroller.ComputeImageCompleter)2 ImageServerControllerException (com.emc.storageos.imageservercontroller.exceptions.ImageServerControllerException)2 ServiceError (com.emc.storageos.svcs.errorhandling.model.ServiceError)2 InternalException (com.emc.storageos.svcs.errorhandling.resources.InternalException)2 TaskCompleter (com.emc.storageos.volumecontroller.TaskCompleter)2 Workflow (com.emc.storageos.workflow.Workflow)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 MalformedURLException (java.net.MalformedURLException)2 URI (java.net.URI)2