Search in sources :

Example 16 with ComputeImage

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

the class ComputeImageCompleter method complete.

@Override
protected void complete(DbClient dbClient, Status status, ServiceCoded coded) throws DeviceControllerException {
    log.info("ComputeImageCompleter.complete {}", status.name());
    ComputeImage ci = dbClient.queryObject(ComputeImage.class, getId());
    AuditLogManager auditMgr = AuditLogManagerFactory.getAuditLogManager();
    if (status == Status.error) {
        if (opType == OperationTypeEnum.CREATE_COMPUTE_IMAGE) {
            boolean available = false;
            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(ci.getId().toString())) {
                    available = true;
                    break;
                }
            }
            if (available) {
                ci.setComputeImageStatus(ComputeImageStatus.AVAILABLE.name());
            } else {
                ci.setComputeImageStatus(ComputeImageStatus.NOT_AVAILABLE.name());
            }
            ci.setLastImportStatusMessage(coded.getMessage());
            dbClient.persistObject(ci);
        }
        dbClient.error(ComputeImage.class, getId(), getOpId(), coded);
        auditMgr.recordAuditLog(null, null, serviceType, opType, System.currentTimeMillis(), AuditLogManager.AUDITLOG_FAILURE, AuditLogManager.AUDITOP_END, ci.getId().toString(), ci.getImageUrl(), ci.getComputeImageStatus());
    } else {
        if (opType == OperationTypeEnum.DELETE_COMPUTE_IMAGE) {
            dbClient.markForDeletion(ci);
        } else if (opType == OperationTypeEnum.CREATE_COMPUTE_IMAGE) {
            ci.setComputeImageStatus(ComputeImageStatus.AVAILABLE.name());
            ci.setLastImportStatusMessage("Success");
            dbClient.persistObject(ci);
        }
        dbClient.ready(ComputeImage.class, getId(), getOpId());
        auditMgr.recordAuditLog(null, null, serviceType, opType, System.currentTimeMillis(), AuditLogManager.AUDITLOG_SUCCESS, AuditLogManager.AUDITOP_END, ci.getId().toString(), ci.getImageUrl(), ci.getComputeImageStatus());
    }
}
Also used : ComputeImageServer(com.emc.storageos.db.client.model.ComputeImageServer) AuditLogManager(com.emc.storageos.security.audit.AuditLogManager) URI(java.net.URI) ComputeImage(com.emc.storageos.db.client.model.ComputeImage)

Example 17 with ComputeImage

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

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

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

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

the class ComputeImageServerService method deleteComputeImageServer.

/**
 * Delete the Compute image server
 *
 * @param id
 *            the URN of compute image server
 *
 * @brief Delete an image server
 * @return {@link Response} instance
 */
@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 Response deleteComputeImageServer(@PathParam("id") URI id) {
    // Validate the imageServer
    log.info("Delete computeImageServer id {} ", id);
    ArgValidator.checkFieldUriType(id, ComputeImageServer.class, "id");
    ComputeImageServer imageServer = _dbClient.queryObject(ComputeImageServer.class, id);
    ArgValidator.checkEntityNotNull(imageServer, id, isIdEmbeddedInURL(id));
    // make sure there are no active jobs associated with this imageserver
    checkActiveJobsForImageServer(id);
    // Remove the association with the ComputeSystem and then delete the
    // imageServer
    List<URI> imageServerURIList = _dbClient.queryByType(ComputeImageServer.class, true);
    ArrayList<URI> tempList = Lists.newArrayList(imageServerURIList.iterator());
    if (tempList.size() > 1) {
        removeImageServerFromComputeSystem(id);
    } else if (tempList.size() == 1) {
        // If the imageServer being deleted is the last one,
        // then check if there are any valid AVAILABLE images, if so
        // throw exception because user cannot delete all imageServers when
        // there are valid images available.
        boolean hasValidImages = false;
        List<URI> imageURIList = _dbClient.queryByType(ComputeImage.class, true);
        Iterator<ComputeImage> imageItr = _dbClient.queryIterativeObjects(ComputeImage.class, imageURIList);
        while (imageItr.hasNext()) {
            ComputeImage computeImage = (ComputeImage) imageItr.next();
            if (ComputeImageStatus.AVAILABLE.name().equals(computeImage.getComputeImageStatus())) {
                hasValidImages = true;
                break;
            }
        }
        if (hasValidImages) {
            throw APIException.badRequests.cannotDeleteImageServer();
        } else {
            removeImageServerFromComputeSystem(id);
        }
    }
    // Set to inactive.
    _dbClient.markForDeletion(imageServer);
    auditOp(OperationTypeEnum.DELETE_COMPUTE_IMAGESERVER, true, null, imageServer.getId().toString(), imageServer.getImageServerIp(), imageServer.getImageServerUser());
    return Response.ok().build();
}
Also used : ComputeImageServer(com.emc.storageos.db.client.model.ComputeImageServer) Iterator(java.util.Iterator) ComputeImageServerList(com.emc.storageos.model.compute.ComputeImageServerList) List(java.util.List) ArrayList(java.util.ArrayList) BulkList(com.emc.storageos.api.service.impl.response.BulkList) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList) URI(java.net.URI) 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

ComputeImage (com.emc.storageos.db.client.model.ComputeImage)22 URI (java.net.URI)10 ComputeImageServer (com.emc.storageos.db.client.model.ComputeImageServer)8 InternalException (com.emc.storageos.svcs.errorhandling.resources.InternalException)7 Produces (javax.ws.rs.Produces)7 ComputeImageJob (com.emc.storageos.db.client.model.ComputeImageJob)6 DeviceControllerException (com.emc.storageos.exceptions.DeviceControllerException)6 ImageServerControllerException (com.emc.storageos.imageservercontroller.exceptions.ImageServerControllerException)6 UnsupportedEncodingException (java.io.UnsupportedEncodingException)6 MalformedURLException (java.net.MalformedURLException)6 Consumes (javax.ws.rs.Consumes)5 Path (javax.ws.rs.Path)5 SSHSession (com.emc.storageos.networkcontroller.SSHSession)4 CheckPermission (com.emc.storageos.security.authorization.CheckPermission)4 URIQueryResultList (com.emc.storageos.db.client.constraint.URIQueryResultList)3 Host (com.emc.storageos.db.client.model.Host)3 POST (javax.ws.rs.POST)3 DbClient (com.emc.storageos.db.client.DbClient)2 ComputeElement (com.emc.storageos.db.client.model.ComputeElement)2 ComputeSystem (com.emc.storageos.db.client.model.ComputeSystem)2