Search in sources :

Example 1 with ComputeImageJob

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

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

the class ImageServerControllerImpl method preOsInstallImageServerCheck.

/**
 * Performs preOs install check on the imageServer
 * @param jobId {@link URI} job id
 * @param stepId {@link String} step id
 */
public void preOsInstallImageServerCheck(URI jobId, String stepId) {
    log.info("preOsInstallImageServerCheck {} ", 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("verify the image is still there");
        if (!d.directoryExists(imageServer.getTftpBootDir() + img.getPathToDirectory())) {
            log.error("the image is missing");
            throw ImageServerControllerException.exceptions.computeImageIsMissing(img.getPathToDirectory());
        }
        String pid = d.getServerPid("67");
        if (pid == null) {
            // dhcp down
            throw ImageServerControllerException.exceptions.dhcpServerNotRunning();
        }
        pid = d.getServerPid("69");
        if (pid == null) {
            // tftp down
            throw ImageServerControllerException.exceptions.tftpServerNotRunning();
        }
        log.info("make sure the python server is running");
        pid = d.getServerPid(imageServer.getImageServerHttpPort());
        if (pid == null) {
            log.warn("python server is not running, attempt to start it");
            d.cd(imageServer.getTftpBootDir() + HTTP_DIR);
            d.nohup(String.format("python %s", SERVER_PY_FILE));
            pid = d.getServerPid(imageServer.getImageServerHttpPort());
            if (pid == null) {
                throw ImageServerControllerException.exceptions.httpPythonServerNotRunning();
            }
        }
        WorkflowStepCompleter.stepSucceded(stepId);
    } catch (InternalException e) {
        log.error("Exception during image server check pre os install: " + e.getMessage(), e);
        WorkflowStepCompleter.stepFailed(stepId, e);
    } catch (Exception e) {
        log.error("Unexpected exception during image server check pre os install: " + 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 3 with ComputeImageJob

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

the class OsInstallCompleter method complete.

@Override
protected void complete(DbClient dbClient, Status status, ServiceCoded coded) throws DeviceControllerException {
    log.info("OsInstallCompleter.complete {} {}", status.name(), coded);
    Host host = dbClient.queryObject(Host.class, getId());
    ComputeImageJob job = dbClient.queryObject(ComputeImageJob.class, jobId);
    AuditLogManager auditMgr = AuditLogManagerFactory.getAuditLogManager();
    if (status == Status.ready && job.getJobStatus().equals(JobStatus.SUCCESS.name())) {
        // set host type based on image type
        ComputeImage image = dbClient.queryObject(ComputeImage.class, job.getComputeImageId());
        if (image.getImageType().equals(ComputeImage.ImageType.esx.name())) {
            host.setType(Host.HostType.Esx.name());
            host.setOsVersion(image.getOsVersion());
        } else if (image.getImageType().equals(ComputeImage.ImageType.linux.name())) {
            host.setType(Host.HostType.Linux.name());
            host.setOsVersion(String.format("%s %s", image.getOsName(), image.getOsVersion()));
        }
        /*
             * Create the IpInterface that represents the IpAddress that's
             * supposed to come on the ESX Management Network (for ESX
             * installations)
             */
        IpInterface ipInterface = new IpInterface();
        ipInterface.setHost(host.getId());
        ipInterface.setId(URIUtil.createId(IpInterface.class));
        ipInterface.setIpAddress(job.getHostIp());
        ipInterface.setLabel(job.getHostName());
        ipInterface.setNetmask(job.getNetmask());
        ipInterface.setProtocol(HostInterface.Protocol.IPV4.toString());
        ipInterface.setRegistrationStatus(DiscoveredDataObject.RegistrationStatus.REGISTERED.toString());
        dbClient.createObject(ipInterface);
        /*
             * End create IpInterface. Consider making this a seperate method.
             */
        host.setCompatibilityStatus(CompatibilityStatus.COMPATIBLE.name());
        host.setProvisioningStatus(ProvisioningJobStatus.COMPLETE.toString());
        dbClient.persistObject(host);
        dbClient.ready(Host.class, getId(), getOpId());
        auditMgr.recordAuditLog(null, null, serviceType, OperationTypeEnum.INSTALL_COMPUTE_IMAGE, System.currentTimeMillis(), AuditLogManager.AUDITLOG_SUCCESS, AuditLogManager.AUDITOP_END, host.getId(), job.getId());
    } else {
        host.setProvisioningStatus(ProvisioningJobStatus.ERROR.toString());
        dbClient.persistObject(host);
        job.setJobStatus(JobStatus.FAILED.name());
        dbClient.persistObject(job);
        dbClient.error(Host.class, getId(), getOpId(), coded);
        auditMgr.recordAuditLog(null, null, serviceType, OperationTypeEnum.INSTALL_COMPUTE_IMAGE, System.currentTimeMillis(), AuditLogManager.AUDITLOG_FAILURE, AuditLogManager.AUDITOP_END, host.getId(), job.getId());
    }
}
Also used : IpInterface(com.emc.storageos.db.client.model.IpInterface) AuditLogManager(com.emc.storageos.security.audit.AuditLogManager) Host(com.emc.storageos.db.client.model.Host) ComputeImageJob(com.emc.storageos.db.client.model.ComputeImageJob) ComputeImage(com.emc.storageos.db.client.model.ComputeImage)

Example 4 with ComputeImageJob

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

the class ComputeImageServerService method checkActiveJobsForImageServer.

/**
 * Check if the given imageServer has any active computeImageJob
 * if so throws an appropriate exception
 * @param imageServerURI
 */
private void checkActiveJobsForImageServer(URI imageServerURI) {
    log.info("Check if any active ComputeImageJobs are present for imageServer id {} ", imageServerURI);
    // make sure there are no active jobs associated with this imageserver
    URIQueryResultList computeImageJobsUriList = new URIQueryResultList();
    _dbClient.queryByConstraint(ContainmentConstraint.Factory.getComputeImageJobsByComputeImageServerConstraint(imageServerURI), computeImageJobsUriList);
    Iterator<URI> iterator = computeImageJobsUriList.iterator();
    while (iterator.hasNext()) {
        ComputeImageJob job = _dbClient.queryObject(ComputeImageJob.class, iterator.next());
        if (job.getJobStatus().equals(ComputeImageJob.JobStatus.CREATED.name())) {
            throw APIException.badRequests.cannotDeleteOrUpdateImageServerWhileInUse();
        }
    }
}
Also used : ComputeImageJob(com.emc.storageos.db.client.model.ComputeImageJob) URI(java.net.URI) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList)

Example 5 with ComputeImageJob

use of com.emc.storageos.db.client.model.ComputeImageJob 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)8 ComputeImage (com.emc.storageos.db.client.model.ComputeImage)6 InternalException (com.emc.storageos.svcs.errorhandling.resources.InternalException)5 ComputeImageServer (com.emc.storageos.db.client.model.ComputeImageServer)4 DeviceControllerException (com.emc.storageos.exceptions.DeviceControllerException)4 ImageServerControllerException (com.emc.storageos.imageservercontroller.exceptions.ImageServerControllerException)4 UnsupportedEncodingException (java.io.UnsupportedEncodingException)4 MalformedURLException (java.net.MalformedURLException)4 URIQueryResultList (com.emc.storageos.db.client.constraint.URIQueryResultList)3 Host (com.emc.storageos.db.client.model.Host)3 SSHSession (com.emc.storageos.networkcontroller.SSHSession)3 URI (java.net.URI)3 ComputeElement (com.emc.storageos.db.client.model.ComputeElement)2 ComputeSystem (com.emc.storageos.db.client.model.ComputeSystem)2 Consumes (javax.ws.rs.Consumes)2 Path (javax.ws.rs.Path)2 Produces (javax.ws.rs.Produces)2 IpInterface (com.emc.storageos.db.client.model.IpInterface)1 Operation (com.emc.storageos.db.client.model.Operation)1 StorageSystem (com.emc.storageos.db.client.model.StorageSystem)1