Search in sources :

Example 16 with ComputeImageServer

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

the class ImageServerControllerImpl method verifyComputeImageServer.

/**
 * This method verifies if the given image Server is a valid imageServer.
 *
 * @param imageServerId {@link URI} of ComputeImageServer
 * @param stepId workflow stepid being executed.
 */
public void verifyComputeImageServer(URI imageServerId, String stepId) {
    log.info("entering method verifyComputeImageServer");
    WorkflowStepCompleter.stepExecuting(stepId);
    ComputeImageServer imageServer = dbClient.queryObject(ComputeImageServer.class, imageServerId);
    if (verifyImageServer(imageServer)) {
        imageServer.setComputeImageServerStatus(ComputeImageServer.ComputeImageServerStatus.AVAILABLE.name());
        dbClient.updateObject(imageServer);
        WorkflowStepCompleter.stepSucceded(stepId);
    } else {
        log.error("Unable to verify imageserver");
        imageServer.setComputeImageServerStatus(ComputeImageServer.ComputeImageServerStatus.NOT_AVAILABLE.name());
        dbClient.updateObject(imageServer);
        WorkflowStepCompleter.stepFailed(stepId, ImageServerControllerException.exceptions.unexpectedException(OperationTypeEnum.IMAGESERVER_VERIFY_IMPORT_IMAGES.name(), new Exception("Unable to verify imageserver")));
    }
}
Also used : ComputeImageServer(com.emc.storageos.db.client.model.ComputeImageServer) 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 17 with ComputeImageServer

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

the class ImageServerControllerImpl method waitForFinishMethod.

/**
 * Utility wait method to check os install status
 * @param jobId {@link URI} job id
 * @param hostName {@link String} host name for error reporting
 * @param stepId {@link String} step id
 */
public void waitForFinishMethod(URI jobId, String hostName, String stepId) {
    log.info("waitForFinishMethod {}, {} ", jobId, hostName);
    try {
        WorkflowStepCompleter.stepExecuting(stepId);
        ComputeImageJob job = dbClient.queryObject(ComputeImageJob.class, jobId);
        ComputeImageServer imageServer = dbClient.queryObject(ComputeImageServer.class, job.getComputeImageServerId());
        if (job.getJobStartTime() == null) {
            log.info("starting the job");
            job.setJobStartTime(System.currentTimeMillis());
            dbClient.updateObject(job);
        } else {
            log.info("resuming the job");
        }
        OsInstallStatus status = null;
        while (System.currentTimeMillis() - job.getJobStartTime() < imageServer.getOsInstallTimeoutMs() && status == null) {
            try {
                log.info("sleep for {} ms", imageServer.getJobPollingIntervalMs());
                Thread.sleep(imageServer.getJobPollingIntervalMs());
            } catch (InterruptedException e) {
                log.error(e.getMessage(), e);
            }
            log.info("check status for {}, after {} sec", job.getPxeBootIdentifier(), (System.currentTimeMillis() - job.getJobStartTime()) / 1000);
            status = osInstallStatusPoller.getOsInstallStatus(job.getPxeBootIdentifier());
        }
        if (status != null) {
            // it is success or failure - do clean up
            ImageServerDialog d = null;
            try {
                SSHSession session = new SSHSession();
                session.connect(imageServer.getImageServerIp(), imageServer.getSshPort(), imageServer.getImageServerUser(), imageServer.getImageServerPassword());
                d = new ImageServerDialog(session, imageServer.getSshTimeoutMs());
                d.init();
                d.rm(imageServer.getTftpBootDir() + HTTP_SUCCESS_DIR + job.getPxeBootIdentifier());
                d.rm(imageServer.getTftpBootDir() + HTTP_FAILURE_DIR + job.getPxeBootIdentifier());
                d.rm(imageServer.getTftpBootDir() + HTTP_KICKSTART_DIR + job.getPxeBootIdentifier());
                d.rm(imageServer.getTftpBootDir() + HTTP_FIRSTBOOT_DIR + job.getPxeBootIdentifier());
                d.rm(imageServer.getTftpBootDir() + PXELINUX_CFG_DIR + job.getPxeBootIdentifier());
                d.rm(imageServer.getTftpBootDir() + PXELINUX_CFG_DIR + job.getPxeBootIdentifier() + ".boot.cfg");
            } catch (Exception e) {
                log.error("exception when trying to poll for status", e);
            } finally {
                try {
                    if (d != null && d.isConnected()) {
                        d.close();
                    }
                } catch (Exception e) {
                    log.error(FAILED_TO_CLOSE_STR, e);
                }
            }
        }
        log.info("job status: {}", status);
        if (status == OsInstallStatus.SUCCESS) {
            log.info("session {} - marking job as SUCCESS", job.getPxeBootIdentifier());
            job.setJobStatus(JobStatus.SUCCESS.name());
            dbClient.updateObject(job);
            WorkflowStepCompleter.stepSucceded(stepId);
        } else if (status == OsInstallStatus.FAILURE) {
            log.info("session {} - marking job as FAILED", job.getPxeBootIdentifier());
            job.setJobStatus(JobStatus.FAILED.name());
            dbClient.updateObject(job);
            WorkflowStepCompleter.stepFailed(stepId, ImageServerControllerException.exceptions.osInstallationFailed(hostName, "failure in the post-install"));
        } else {
            // timed out
            log.info("session {} - marking job as TIMEDOUT", job.getPxeBootIdentifier());
            job.setJobStatus(JobStatus.TIMEDOUT.name());
            dbClient.updateObject(job);
            WorkflowStepCompleter.stepFailed(stepId, ImageServerControllerException.exceptions.osInstallationTimedOut(hostName, imageServer.getOsInstallTimeoutMs() / 1000));
        }
    } catch (InternalException e) {
        log.error("Exception waiting for finish: " + e.getMessage(), e);
        WorkflowStepCompleter.stepFailed(stepId, e);
    } catch (Exception e) {
        log.error("Unexpected exception waiting for finish: " + e.getMessage(), e);
        String opName = ResourceOperationTypeEnum.INSTALL_OPERATING_SYSTEM.getName();
        WorkflowStepCompleter.stepFailed(stepId, ImageServerControllerException.exceptions.unexpectedException(opName, e));
    }
}
Also used : SSHSession(com.emc.storageos.networkcontroller.SSHSession) OsInstallStatus(com.emc.storageos.imageservercontroller.impl.OsInstallStatusPoller.OsInstallStatus) ComputeImageServer(com.emc.storageos.db.client.model.ComputeImageServer) ComputeImageJob(com.emc.storageos.db.client.model.ComputeImageJob) 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) InternalException(com.emc.storageos.svcs.errorhandling.resources.InternalException)

Example 18 with ComputeImageServer

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

the class ImageServerControllerImpl method preparePxeBootMethod.

/**
 * Prepare pxe boot method, copies the conf file
 * @param jobId {@link URI} job id
 * @param stepId {@link String} step id
 */
public void preparePxeBootMethod(URI jobId, String stepId) {
    log.info("preparePxeBootMethod {} ", jobId);
    ImageServerDialog d = null;
    try {
        WorkflowStepCompleter.stepExecuting(stepId);
        ComputeImageJob job = dbClient.queryObject(ComputeImageJob.class, jobId);
        ComputeImage img = dbClient.queryObject(ComputeImage.class, job.getComputeImageId());
        ComputeImageServer imageServer = dbClient.queryObject(ComputeImageServer.class, job.getComputeImageServerId());
        SSHSession session = new SSHSession();
        session.connect(imageServer.getImageServerIp(), imageServer.getSshPort(), imageServer.getImageServerUser(), imageServer.getImageServerPassword());
        d = new ImageServerDialog(session, imageServer.getSshTimeoutMs());
        d.init();
        log.info("connected to image server");
        log.info("putting pxe conf file");
        pxeIntegrationService.createSession(d, job, img, imageServer);
        WorkflowStepCompleter.stepSucceded(stepId);
    } catch (InternalException e) {
        log.error("Exception preparing pxe boot: " + e.getMessage(), e);
        WorkflowStepCompleter.stepFailed(stepId, e);
    } catch (Exception e) {
        log.error("Unexpected exception preparing pxe boot: " + e.getMessage(), e);
        String opName = ResourceOperationTypeEnum.INSTALL_OPERATING_SYSTEM.getName();
        WorkflowStepCompleter.stepFailed(stepId, ImageServerControllerException.exceptions.unexpectedException(opName, e));
    } finally {
        try {
            if (d != null && d.isConnected()) {
                d.close();
            }
        } catch (Exception e) {
            log.error(FAILED_TO_CLOSE_STR, e);
        }
    }
}
Also used : SSHSession(com.emc.storageos.networkcontroller.SSHSession) ComputeImageServer(com.emc.storageos.db.client.model.ComputeImageServer) ComputeImageJob(com.emc.storageos.db.client.model.ComputeImageJob) 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) InternalException(com.emc.storageos.svcs.errorhandling.resources.InternalException)

Example 19 with ComputeImageServer

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

the class ImageServerControllerImpl method deleteImageMethod.

/**
 * Deletes a given image from the imageServer
 * @param ciId {@link URI} compute image id
 * @param imageServerId {@link URI} compute image server id
 * @param stepId {@link String} step id
 */
public void deleteImageMethod(URI ciId, URI imageServerId, String stepId) {
    log.info("deleteImageMethod {}", ciId);
    ImageServerDialog d = null;
    try {
        WorkflowStepCompleter.stepExecuting(stepId);
        ComputeImageServer imageServer = dbClient.queryObject(ComputeImageServer.class, imageServerId);
        ComputeImage ci = dbClient.queryObject(ComputeImage.class, ciId);
        SSHSession session = new SSHSession();
        session.connect(imageServer.getImageServerIp(), imageServer.getSshPort(), imageServer.getImageServerUser(), imageServer.getImageServerPassword());
        d = new ImageServerDialog(session, imageServer.getSshTimeoutMs());
        d.init();
        log.info("connected to image server");
        log.info("calling image server to delete image");
        d.rm(imageServer.getTftpBootDir() + ci.getPathToDirectory());
        log.info("delete done");
        if (imageServer.getComputeImages() != null && imageServer.getComputeImages().contains(ciId.toString())) {
            imageServer.getComputeImages().remove(ciId.toString());
            dbClient.updateObject(imageServer);
        }
        WorkflowStepCompleter.stepSucceded(stepId);
    } catch (InternalException e) {
        log.error("Exception deleting image: " + e.getMessage(), e);
        WorkflowStepCompleter.stepFailed(stepId, e);
    } catch (Exception e) {
        log.error("Unexpected exception deleting image: " + e.getMessage(), e);
        String opName = ResourceOperationTypeEnum.REMOVE_IMAGE.getName();
        WorkflowStepCompleter.stepFailed(stepId, ImageServerControllerException.exceptions.unexpectedException(opName, e));
    } finally {
        try {
            if (d != null && d.isConnected()) {
                d.close();
            }
        } catch (Exception e) {
            log.error(FAILED_TO_CLOSE_STR, e);
        }
    }
}
Also used : SSHSession(com.emc.storageos.networkcontroller.SSHSession) ComputeImageServer(com.emc.storageos.db.client.model.ComputeImageServer) 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) InternalException(com.emc.storageos.svcs.errorhandling.resources.InternalException)

Example 20 with ComputeImageServer

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

the class HostService method verifyImagePresentOnImageServer.

/**
 * Method to check if the selected image is present on the
 * ComputeImageServer which is associated with the CoputeSystem
 *
 * @param cs
 *            {@link ComputeSystem}
 * @param img
 *            {@link ComputeImage} instance selected
 * @throws APIException
 */
private void verifyImagePresentOnImageServer(ComputeSystem cs, ComputeImage img) throws APIException {
    URI imageServerURI = cs.getComputeImageServer();
    _log.info("Verify if selected image {} exists on imageServer {}", img.getLabel(), imageServerURI);
    if (NullColumnValueGetter.isNullURI(imageServerURI)) {
        _log.info("Compute system {} does not have an image server associated with it. Cannot proceed with OS install.", img.getLabel());
        throw APIException.badRequests.noImageServerAssociatedToComputeSystem(cs.getLabel());
    } else {
        ComputeImageServer imageServer = queryObject(ComputeImageServer.class, imageServerURI, true);
        StringSet computeImagesSet = imageServer.getComputeImages();
        if (computeImagesSet == null || !computeImagesSet.contains(img.getId().toString())) {
            _log.info("Selected image {} does not exist on imageServer {}", img.getLabel(), imageServer.getLabel());
            throw APIException.badRequests.imageNotPresentOnComputeImageServer(img.getLabel(), imageServer.getLabel());
        }
        _log.info("Selected image {} exists on imageServer {}", img.getLabel(), imageServer.getLabel());
    }
}
Also used : ComputeImageServer(com.emc.storageos.db.client.model.ComputeImageServer) StringSet(com.emc.storageos.db.client.model.StringSet) URI(java.net.URI)

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