Search in sources :

Example 1 with OsInstallStatus

use of com.emc.storageos.imageservercontroller.impl.OsInstallStatusPoller.OsInstallStatus 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)

Aggregations

ComputeImageJob (com.emc.storageos.db.client.model.ComputeImageJob)1 ComputeImageServer (com.emc.storageos.db.client.model.ComputeImageServer)1 DeviceControllerException (com.emc.storageos.exceptions.DeviceControllerException)1 ImageServerControllerException (com.emc.storageos.imageservercontroller.exceptions.ImageServerControllerException)1 OsInstallStatus (com.emc.storageos.imageservercontroller.impl.OsInstallStatusPoller.OsInstallStatus)1 SSHSession (com.emc.storageos.networkcontroller.SSHSession)1 InternalException (com.emc.storageos.svcs.errorhandling.resources.InternalException)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 MalformedURLException (java.net.MalformedURLException)1