Search in sources :

Example 1 with ComputeImageServer

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

the class ImageServerControllerImpl method installOperatingSystem.

/**
 * Install OS
 * @param task {@link AsyncTask}
 * @param computeImageJob {@link URI} compute imageJob id
 * @throws InternalException
 */
@Override
public void installOperatingSystem(AsyncTask task, URI computeImageJob) throws InternalException {
    log.info("installOperatingSystem");
    Host host = dbClient.queryObject(Host.class, task._id);
    ComputeElement ce = dbClient.queryObject(ComputeElement.class, host.getComputeElement());
    ComputeSystem cs = dbClient.queryObject(ComputeSystem.class, ce.getComputeSystem());
    ComputeImageJob job = dbClient.queryObject(ComputeImageJob.class, computeImageJob);
    ComputeImageServer imageServer = dbClient.queryObject(ComputeImageServer.class, job.getComputeImageServerId());
    ComputeImage img = dbClient.queryObject(ComputeImage.class, job.getComputeImageId());
    TaskCompleter completer = null;
    try {
        completer = new OsInstallCompleter(host.getId(), task._opId, job.getId(), EVENT_SERVICE_TYPE);
        boolean imageServerVerified = verifyImageServer(imageServer);
        if (!imageServerVerified) {
            throw ImageServerControllerException.exceptions.imageServerNotSetup("Can't install operating system: " + imageServerErrorMsg);
        }
        Workflow workflow = workflowService.getNewWorkflow(this, OS_INSTALL_WF, true, task._opId);
        String waitFor = null;
        waitFor = workflow.createStep(OS_INSTALL_IMAGE_SERVER_CHECK_STEP, "image server check pre os install", waitFor, img.getId(), img.getImageType(), this.getClass(), new Workflow.Method("preOsInstallImageServerCheck", job.getId()), new Workflow.Method(ROLLBACK_NOTHING_METHOD), null);
        waitFor = workflow.createStep(OS_INSTALL_PREPARE_PXE_STEP, "prepare pxe boot", waitFor, img.getId(), img.getImageType(), this.getClass(), new Workflow.Method("preparePxeBootMethod", job.getId()), new Workflow.Method(ROLLBACK_NOTHING_METHOD), null);
        String prepStepId = workflow.createStepId();
        waitFor = computeDeviceController.addStepsPreOsInstall(workflow, waitFor, cs.getId(), host.getId(), prepStepId);
        waitFor = workflow.createStep(OS_INSTALL_WAIT_FOR_FINISH_STEP, "wait for os install to finish", waitFor, img.getId(), img.getImageType(), this.getClass(), new Workflow.Method("waitForFinishMethod", job.getId(), host.getHostName()), new Workflow.Method(ROLLBACK_NOTHING_METHOD), null);
        waitFor = computeDeviceController.addStepsPostOsInstall(workflow, waitFor, cs.getId(), ce.getId(), host.getId(), prepStepId, job.getVolumeId());
        workflow.executePlan(completer, SUCCESS);
    } catch (Exception e) {
        log.error("installOperatingSystem caught an exception.", e);
        ServiceError serviceError = DeviceControllerException.errors.jobFailed(e);
        completer.error(dbClient, serviceError);
    }
}
Also used : ServiceError(com.emc.storageos.svcs.errorhandling.model.ServiceError) ComputeImageServer(com.emc.storageos.db.client.model.ComputeImageServer) Workflow(com.emc.storageos.workflow.Workflow) Host(com.emc.storageos.db.client.model.Host) 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) ComputeImage(com.emc.storageos.db.client.model.ComputeImage) OsInstallCompleter(com.emc.storageos.imageservercontroller.OsInstallCompleter) ComputeElement(com.emc.storageos.db.client.model.ComputeElement) ComputeImageJob(com.emc.storageos.db.client.model.ComputeImageJob) TaskCompleter(com.emc.storageos.volumecontroller.TaskCompleter) ComputeSystem(com.emc.storageos.db.client.model.ComputeSystem)

Example 2 with ComputeImageServer

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

the class ImageServerControllerImpl method verifyImageServerAndImportExistingImages.

/**
 * Method to verify and import images on the imageserver
 *
 * @param task {@link AsyncTask} instance
 * @param opName operation Name
 */
@Override
public void verifyImageServerAndImportExistingImages(AsyncTask task, String opName) {
    TaskCompleter completer = null;
    log.info("Verifying imageServer and importing any existing images on to the server");
    try {
        URI computeImageServerID = task._id;
        completer = new ComputeImageServerCompleter(computeImageServerID, task._opId, OperationTypeEnum.IMAGESERVER_VERIFY_IMPORT_IMAGES, EVENT_SERVICE_TYPE);
        Workflow workflow = workflowService.getNewWorkflow(this, IMAGESERVER_VERIFY_IMPORT_IMAGE_WF, true, task._opId);
        workflow.createStep(IMAGESERVER_VERIFICATION_STEP, String.format("Verfiying ImageServer %s", computeImageServerID), null, computeImageServerID, computeImageServerID.toString(), this.getClass(), new Workflow.Method("verifyComputeImageServer", computeImageServerID), new Workflow.Method(ROLLBACK_NOTHING_METHOD), null);
        List<ComputeImage> computeImageList = getAllComputeImages();
        if (!CollectionUtils.isEmpty(computeImageList)) {
            ComputeImageServer imageServer = dbClient.queryObject(ComputeImageServer.class, computeImageServerID);
            for (ComputeImage computeImage : computeImageList) {
                if (null == imageServer.getComputeImages() || !imageServer.getComputeImages().contains(computeImage.getId().toString())) {
                    StringBuilder msg = new StringBuilder("Importing image ");
                    msg.append(computeImage.getLabel()).append(" on to imageServer - ");
                    msg.append(imageServer.getImageServerIp()).append(".");
                    workflow.createStep(IMAGESERVER_IMPORT_IMAGES_STEP, msg.toString(), IMAGESERVER_VERIFICATION_STEP, computeImageServerID, computeImageServerID.toString(), this.getClass(), new Workflow.Method("importImageMethod", computeImage.getId(), imageServer, opName), new Workflow.Method(ROLLBACK_NOTHING_METHOD), null);
                }
            }
        }
        workflow.executePlan(completer, SUCCESS);
    } catch (Exception ex) {
        log.error("Unexpected exception waiting for finish: " + ex.getMessage(), ex);
    }
}
Also used : ComputeImageServer(com.emc.storageos.db.client.model.ComputeImageServer) Workflow(com.emc.storageos.workflow.Workflow) TaskCompleter(com.emc.storageos.volumecontroller.TaskCompleter) URI(java.net.URI) ComputeImageServerCompleter(com.emc.storageos.imageservercontroller.ComputeImageServerCompleter) 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) ComputeImage(com.emc.storageos.db.client.model.ComputeImage)

Example 3 with ComputeImageServer

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

the class ImageServerControllerImpl method updateFailedImages.

/**
 * Updates the imageServer with the image that failed import, this method updates
 * it as failed only after making sure that the image was not previously successful.
 * @param imageServerURI {@link URI} imageServerURI instance to which import was made.
 * @param image {@link ComputeImage} instance that failed the import.
 */
private void updateFailedImages(URI imageServerURI, ComputeImage image) {
    if (null != imageServerURI && null != image) {
        String imageURIStr = image.getId().toString();
        log.info("updateFailedImages : update failed image import details.");
        // first fetch updated imageServer details from DB and
        // verify if image was previously loaded successfully on to
        // the imageServer, if so then skip updating it as failed else
        // update it as failed.
        ComputeImageServer imageServer = dbClient.queryObject(ComputeImageServer.class, imageServerURI);
        if (imageServer.getComputeImages() == null || !imageServer.getComputeImages().contains(imageURIStr)) {
            // update the imageServer with the failed image.
            if (imageServer.getFailedComputeImages() == null) {
                imageServer.setFailedComputeImages(new StringSet());
            }
            log.info("Image - {} failed to import on imageServer - {}", image.getLabel(), imageServer.getLabel());
            imageServer.getFailedComputeImages().add(imageURIStr);
            dbClient.updateObject(imageServer);
        }
    }
}
Also used : ComputeImageServer(com.emc.storageos.db.client.model.ComputeImageServer) StringSet(com.emc.storageos.db.client.model.StringSet)

Example 4 with ComputeImageServer

use of com.emc.storageos.db.client.model.ComputeImageServer 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)

Example 5 with ComputeImageServer

use of com.emc.storageos.db.client.model.ComputeImageServer 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)

Aggregations

ComputeImageServer (com.emc.storageos.db.client.model.ComputeImageServer)26 URI (java.net.URI)13 DeviceControllerException (com.emc.storageos.exceptions.DeviceControllerException)9 ImageServerControllerException (com.emc.storageos.imageservercontroller.exceptions.ImageServerControllerException)9 InternalException (com.emc.storageos.svcs.errorhandling.resources.InternalException)9 UnsupportedEncodingException (java.io.UnsupportedEncodingException)9 MalformedURLException (java.net.MalformedURLException)9 ComputeImage (com.emc.storageos.db.client.model.ComputeImage)8 Produces (javax.ws.rs.Produces)6 SSHSession (com.emc.storageos.networkcontroller.SSHSession)5 ArrayList (java.util.ArrayList)5 ComputeImageJob (com.emc.storageos.db.client.model.ComputeImageJob)4 CheckPermission (com.emc.storageos.security.authorization.CheckPermission)4 TaskCompleter (com.emc.storageos.volumecontroller.TaskCompleter)4 Workflow (com.emc.storageos.workflow.Workflow)4 Path (javax.ws.rs.Path)4 StringSet (com.emc.storageos.db.client.model.StringSet)3 ServiceError (com.emc.storageos.svcs.errorhandling.model.ServiceError)3 Consumes (javax.ws.rs.Consumes)3 GET (javax.ws.rs.GET)3