Search in sources :

Example 6 with ComputeImageJob

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

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

the class HostService method osInstall.

/**
 * Install operating system on the host.
 *
 * @param hostId
 *            host URI
 * @param param
 *            OS install data
 * @brief Install operating system on the host
 * @return TaskResourceRep (asynchronous call)
 */
@PUT
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{id}/os-install")
public TaskResourceRep osInstall(@PathParam("id") URI hostId, OsInstallParam param) {
    // validate params
    ArgValidator.checkFieldUriType(hostId, Host.class, "id");
    ArgValidator.checkFieldNotNull(param.getComputeImage(), "compute_image");
    // get data
    ComputeImage img = queryObject(ComputeImage.class, param.getComputeImage(), true);
    ArgValidator.checkEntity(img, param.getComputeImage(), isIdEmbeddedInURL(param.getComputeImage()));
    if (!ComputeImageStatus.AVAILABLE.name().equals(img.getComputeImageStatus())) {
        throw APIException.badRequests.invalidParameterComputeImageIsNotAvailable(img.getId());
    }
    ArgValidator.checkFieldNotEmpty(param.getHostIp(), "host_ip");
    Host host = queryObject(Host.class, hostId, true);
    ArgValidator.checkEntity(host, hostId, isIdEmbeddedInURL(hostId));
    // COP-28718 Fixed by making sure that the host we are installing OS does not cause an IP conflict
    // by throwing appropriate exception.
    verifyHostForDuplicateIP(host, param);
    // only support os install on hosts with compute elements
    if (NullColumnValueGetter.isNullURI(host.getComputeElement())) {
        throw APIException.badRequests.invalidParameterHostHasNoComputeElement();
    }
    if (!host.getType().equals(Host.HostType.No_OS.name()) && !param.getForceInstallation()) {
        throw APIException.badRequests.invalidParameterHostAlreadyHasOs(host.getType());
    }
    if (!StringUtils.isNotBlank(param.getRootPassword())) {
        throw APIException.badRequests.hostPasswordNotSet();
    } else {
        host.setPassword(param.getRootPassword());
        host.setUsername("root");
    }
    // check that CS has os install network
    ComputeElement ce = queryObject(ComputeElement.class, host.getComputeElement(), true);
    ArgValidator.checkEntity(ce, host.getComputeElement(), isIdEmbeddedInURL(host.getComputeElement()));
    if (ce.getUuid() == null) {
        throw APIException.badRequests.computeElementHasNoUuid();
    }
    ComputeSystem cs = queryObject(ComputeSystem.class, ce.getComputeSystem(), true);
    ArgValidator.checkEntity(cs, ce.getComputeSystem(), isIdEmbeddedInURL(ce.getComputeSystem()));
    verifyImagePresentOnImageServer(cs, img);
    if (!StringUtils.isNotBlank(cs.getOsInstallNetwork())) {
        throw APIException.badRequests.osInstallNetworkNotSet();
    }
    if (!cs.getVlans().contains(cs.getOsInstallNetwork())) {
        throw APIException.badRequests.osInstallNetworkNotValid(cs.getOsInstallNetwork());
    }
    // check that there is no os install in progress for this host
    URIQueryResultList jobUriList = new URIQueryResultList();
    _dbClient.queryByConstraint(ContainmentConstraint.Factory.getComputeImageJobsByHostConstraint(host.getId()), jobUriList);
    Iterator<URI> iterator = jobUriList.iterator();
    while (iterator.hasNext()) {
        ComputeImageJob existingJob = _dbClient.queryObject(ComputeImageJob.class, iterator.next());
        if (!existingJob.getInactive() && existingJob.getJobStatus().equals(ComputeImageJob.JobStatus.CREATED.name())) {
            throw APIException.badRequests.osInstallAlreadyInProgress();
        }
    }
    // openssl passwd -1 (MD5 encryption of password)
    String passwordHash = Md5Crypt.md5Crypt(host.getPassword().getBytes());
    // create session
    ComputeImageJob job = new ComputeImageJob();
    job.setId(URIUtil.createId(ComputeImageJob.class));
    job.setComputeImageId(img.getId());
    job.setHostId(host.getId());
    job.setPasswordHash(passwordHash);
    job.setHostName(param.getHostName());
    job.setHostIp(param.getHostIp());
    job.setNetmask(param.getNetmask());
    job.setGateway(param.getGateway());
    job.setNtpServer(param.getNtpServer());
    job.setDnsServers(param.getDnsServers());
    job.setManagementNetwork(param.getManagementNetwork());
    job.setPxeBootIdentifier(ImageServerUtils.uuidFromString(host.getUuid()).toString());
    job.setComputeImageServerId(cs.getComputeImageServer());
    // volume id is optional
    if (!NullColumnValueGetter.isNullURI(param.getVolume()) || !NullColumnValueGetter.isNullURI(host.getBootVolumeId())) {
        Volume vol = null;
        if (!NullColumnValueGetter.isNullURI(param.getVolume())) {
            vol = queryObject(Volume.class, param.getVolume(), true);
            host.setBootVolumeId(vol.getId());
        } else {
            vol = queryObject(Volume.class, host.getBootVolumeId(), true);
        }
        job.setVolumeId(vol.getId());
        StorageSystem st = queryObject(StorageSystem.class, vol.getStorageController(), true);
        // XtremIO uses some other ID type (e.g. 514f0c5dc9600016)
        if (st != null && DiscoveredDataObject.Type.xtremio.name().equals(st.getSystemType())) {
            _log.info("xtremio volume id {}", vol.getNativeId());
            job.setBootDevice(vol.getNativeId());
        } else {
            _log.info("volume id {}", vol.getWWN());
            job.setBootDevice(ImageServerUtils.uuidFromString(vol.getWWN()).toString());
        }
    }
    host.setProvisioningStatus(ProvisioningJobStatus.IN_PROGRESS.toString());
    _dbClient.persistObject(host);
    _dbClient.createObject(job);
    // create task
    String taskId = UUID.randomUUID().toString();
    Operation op = new Operation();
    op.setResourceType(ResourceOperationTypeEnum.INSTALL_OPERATING_SYSTEM);
    _dbClient.createTaskOpStatus(Host.class, host.getId(), taskId, op);
    ImageServerController controller = getController(ImageServerController.class, null);
    AsyncTask task = new AsyncTask(Host.class, host.getId(), taskId);
    try {
        controller.installOperatingSystem(task, job.getId());
    } catch (InternalException e) {
        _log.error("Did not install OS due to controller error", e);
        job.setJobStatus(ComputeImageJob.JobStatus.FAILED.name());
        _dbClient.persistObject(job);
        _dbClient.error(Host.class, host.getId(), taskId, e);
    }
    return toTask(host, taskId, op);
}
Also used : AsyncTask(com.emc.storageos.volumecontroller.AsyncTask) ArrayAffinityAsyncTask(com.emc.storageos.volumecontroller.ArrayAffinityAsyncTask) Host(com.emc.storageos.db.client.model.Host) Operation(com.emc.storageos.db.client.model.Operation) URI(java.net.URI) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList) ComputeImage(com.emc.storageos.db.client.model.ComputeImage) InternalException(com.emc.storageos.svcs.errorhandling.resources.InternalException) ImageServerController(com.emc.storageos.imageservercontroller.ImageServerController) UnManagedVolume(com.emc.storageos.db.client.model.UnManagedDiscoveredObjects.UnManagedVolume) Volume(com.emc.storageos.db.client.model.Volume) ComputeElement(com.emc.storageos.db.client.model.ComputeElement) ComputeImageJob(com.emc.storageos.db.client.model.ComputeImageJob) ComputeSystem(com.emc.storageos.db.client.model.ComputeSystem) StorageSystem(com.emc.storageos.db.client.model.StorageSystem) Path(javax.ws.rs.Path) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) PUT(javax.ws.rs.PUT)

Example 8 with ComputeImageJob

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

the class ComputeImageService method deleteComputeImage.

/**
 * Delete existing compute image.
 *
 * @param id
 *            compute image URN.
 * @brief Delete compute image
 * @return Async task remove the image from multiple image serevers returned in response body
 */
@POST
@Path("/{id}/deactivate")
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@CheckPermission(roles = { Role.SYSTEM_ADMIN, Role.RESTRICTED_SYSTEM_ADMIN })
public TaskResourceRep deleteComputeImage(@PathParam("id") URI id, @QueryParam("force") String force) {
    log.info("deleteComputeImage: {}", id);
    ComputeImage ci = queryObject(ComputeImage.class, id, true);
    ArgValidator.checkEntity(ci, id, isIdEmbeddedInURL(id));
    if (ComputeImage.ComputeImageStatus.AVAILABLE.name().equals(ci.getComputeImageStatus())) {
        if (force == null || !force.equals("true")) {
            // make sure there are no active jobs associated with this image
            URIQueryResultList ceUriList = new URIQueryResultList();
            _dbClient.queryByConstraint(ContainmentConstraint.Factory.getComputeImageJobsByComputeImageConstraint(ci.getId()), ceUriList);
            Iterator<URI> iterator = ceUriList.iterator();
            while (iterator.hasNext()) {
                ComputeImageJob job = _dbClient.queryObject(ComputeImageJob.class, iterator.next());
                if (job.getJobStatus().equals(ComputeImageJob.JobStatus.CREATED.name())) {
                    throw APIException.badRequests.cannotDeleteComputeWhileInUse();
                }
            }
        }
        auditOp(OperationTypeEnum.DELETE_COMPUTE_IMAGE, true, AuditLogManager.AUDITOP_BEGIN, ci.getId().toString(), ci.getImageUrl());
        return doRemoveImage(ci);
    } else if (ComputeImage.ComputeImageStatus.IN_PROGRESS.name().equals(ci.getComputeImageStatus())) {
        if (force == null || !force.equals("true")) {
            throw APIException.badRequests.resourceCannotBeDeleted(ci.getLabel());
        } else {
            // delete is forced
            deleteImageFromImageServers(ci);
            _dbClient.markForDeletion(ci);
            auditOp(OperationTypeEnum.DELETE_COMPUTE_IMAGE, true, null, ci.getId().toString(), ci.getImageUrl());
            return getReadyOp(ci, ResourceOperationTypeEnum.REMOVE_IMAGE);
        }
    } else {
        // NOT_AVAILABLE
        deleteImageFromImageServers(ci);
        _dbClient.markForDeletion(ci);
        auditOp(OperationTypeEnum.DELETE_COMPUTE_IMAGE, true, null, ci.getId().toString(), ci.getImageUrl());
        return getReadyOp(ci, ResourceOperationTypeEnum.REMOVE_IMAGE);
    }
}
Also used : ComputeImageJob(com.emc.storageos.db.client.model.ComputeImageJob) URI(java.net.URI) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList) ComputeImage(com.emc.storageos.db.client.model.ComputeImage) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

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