Search in sources :

Example 1 with ComputeSystem

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

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

the class HostService method getHost.

/**
 * Gets the information for one host.
 *
 * @param id
 *            the URN of a ViPR Host
 * @brief Show host
 * @return All the non-null attributes of the host.
 * @throws DatabaseException
 *             when a DB error occurs.
 */
@GET
@Path("/{id}")
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public HostRestRep getHost(@PathParam("id") URI id) throws DatabaseException {
    Host host = queryObject(Host.class, id, false);
    // check the user permissions
    verifyAuthorizedInTenantOrg(host.getTenant(), getUserFromContext());
    ComputeElement computeElement = null;
    UCSServiceProfile serviceProfile = null;
    ComputeSystem computeSystem = null;
    if (!NullColumnValueGetter.isNullURI(host.getComputeElement())) {
        computeElement = queryObject(ComputeElement.class, host.getComputeElement(), false);
    }
    if (!NullColumnValueGetter.isNullURI(host.getServiceProfile())) {
        serviceProfile = queryObject(UCSServiceProfile.class, host.getServiceProfile(), false);
    }
    if (serviceProfile != null) {
        computeSystem = queryObject(ComputeSystem.class, serviceProfile.getComputeSystem(), false);
    } else if (computeElement != null) {
        computeSystem = queryObject(ComputeSystem.class, computeElement.getComputeSystem(), false);
    }
    return map(host, computeElement, serviceProfile, computeSystem);
}
Also used : UCSServiceProfile(com.emc.storageos.db.client.model.UCSServiceProfile) ComputeElement(com.emc.storageos.db.client.model.ComputeElement) Host(com.emc.storageos.db.client.model.Host) ComputeSystem(com.emc.storageos.db.client.model.ComputeSystem) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 3 with ComputeSystem

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

the class ComputeSystemService method deregisterComputeSystem.

/**
 * De-registers a previously registered Compute System. (Creation and
 * Discovery of the Compute System marks the Compute System "Registered" by
 * default)
 *
 * @param id
 *            the URN of a ViPR Compute System
 * @brief Deregister compute system
 * @return A detailed representation of the Compute System
 * @throws ControllerException
 */
@POST
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{id}/deregister")
@CheckPermission(roles = { Role.SYSTEM_ADMIN, Role.RESTRICTED_SYSTEM_ADMIN })
public ComputeSystemRestRep deregisterComputeSystem(@PathParam("id") URI id) throws ControllerException {
    // Validate the storage system.
    ArgValidator.checkUri(id);
    ComputeSystem cs = _dbClient.queryObject(ComputeSystem.class, id);
    ArgValidator.checkEntity(cs, id, isIdEmbeddedInURL(id));
    if (!RegistrationStatus.UNREGISTERED.toString().equalsIgnoreCase(cs.getRegistrationStatus())) {
        cs.setRegistrationStatus(RegistrationStatus.UNREGISTERED.toString());
        _dbClient.persistObject(cs);
        // Fetch all unprovisioned blades for this CS; remove them from any CVPs they are part of
        ComputeElementListRestRep result = getComputeElements(cs.getId());
        List<ComputeElementRestRep> blades = result.getList();
        List<URI> unprovisionedBlades = new ArrayList<URI>();
        for (ComputeElementRestRep ce : blades) {
            if (ce.getAvailable()) {
                unprovisionedBlades.add(ce.getId());
                _log.debug("Found unprovisioned blade:" + ce.getName());
            }
        }
        List<URI> cvpIds = _dbClient.queryByType(ComputeVirtualPool.class, true);
        Iterator<ComputeVirtualPool> iter = _dbClient.queryIterativeObjects(ComputeVirtualPool.class, cvpIds);
        while (iter.hasNext()) {
            ComputeVirtualPool cvp = iter.next();
            _log.debug("Remove unprovisioned blades from cvp: " + cvp.getLabel());
            StringSet currentElements = new StringSet();
            if (cvp.getMatchedComputeElements() != null) {
                currentElements.addAll(cvp.getMatchedComputeElements());
                for (URI bladeId : unprovisionedBlades) {
                    currentElements.remove(bladeId.toString());
                }
            }
            cvp.setMatchedComputeElements(currentElements);
            _dbClient.updateAndReindexObject(cvp);
            _log.debug("Removed ces from cvp");
        }
        recordAndAudit(cs, OperationTypeEnum.DEREGISTER_COMPUTE_SYSTEM, true, null);
    }
    return getComputeSystem(id);
}
Also used : ComputeElementListRestRep(com.emc.storageos.model.compute.ComputeElementListRestRep) ArrayList(java.util.ArrayList) StringSet(com.emc.storageos.db.client.model.StringSet) ComputeElementRestRep(com.emc.storageos.model.compute.ComputeElementRestRep) URI(java.net.URI) ComputeSystem(com.emc.storageos.db.client.model.ComputeSystem) ComputeVirtualPool(com.emc.storageos.db.client.model.ComputeVirtualPool) Path(javax.ws.rs.Path) ComputeSanBootImagePath(com.emc.storageos.db.client.model.ComputeSanBootImagePath) ComputeLanBootImagePath(com.emc.storageos.db.client.model.ComputeLanBootImagePath) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Example 4 with ComputeSystem

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

the class ComputeSystemService method deleteComputeSystem.

/**
 * Deletes a Compute System and the discovered information about it from
 * ViPR
 *
 * @param id
 *            the URN of a ViPR Compute System to be deleted
 * @brief Delete compute system
 * @return TaskResourceRep (asynchronous call)
 * @throws DatabaseException
 */
@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 deleteComputeSystem(@PathParam("id") URI id) throws DatabaseException {
    ComputeSystem cs = queryObject(ComputeSystem.class, id, true);
    ArgValidator.checkEntity(cs, id, isIdEmbeddedInURL(id));
    if (!RegistrationStatus.UNREGISTERED.toString().equals(cs.getRegistrationStatus())) {
        throw APIException.badRequests.invalidParameterCannotDeactivateRegisteredComputeSystem(cs.getId());
    }
    List<String> provHosts = getProvisionedBlades(cs);
    if (!provHosts.isEmpty()) {
        throw APIException.badRequests.unableToDeactivateProvisionedComputeSystem(cs.getLabel(), org.springframework.util.StringUtils.collectionToCommaDelimitedString(provHosts));
    }
    ComputeController controller = getController(ComputeController.class, cs.getSystemType());
    controller.clearDeviceSession(cs.getId());
    String taskId = UUID.randomUUID().toString();
    Operation op = _dbClient.createTaskOpStatus(ComputeSystem.class, cs.getId(), taskId, ResourceOperationTypeEnum.DELETE_COMPUTE_SYSTEM);
    PurgeRunnable.executePurging(_dbClient, _dbPurger, _asynchJobService.getExecutorService(), cs, 0, /* _retry_attempts */
    taskId, 60);
    recordAndAudit(cs, OperationTypeEnum.DELETE_COMPUTE_SYSTEM, true, AuditLogManager.AUDITOP_BEGIN);
    return toTask(cs, taskId, op);
}
Also used : ComputeController(com.emc.storageos.computecontroller.ComputeController) Operation(com.emc.storageos.db.client.model.Operation) ComputeSystem(com.emc.storageos.db.client.model.ComputeSystem) Path(javax.ws.rs.Path) ComputeSanBootImagePath(com.emc.storageos.db.client.model.ComputeSanBootImagePath) ComputeLanBootImagePath(com.emc.storageos.db.client.model.ComputeLanBootImagePath) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Example 5 with ComputeSystem

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

the class ComputeSystemService method createComputeSystem.

/**
 * Creates and discovers a Compute System in ViPR
 *
 * @param param
 *            An instance of {@link ComputeSystemCreate} representing a
 *            Compute System to be created, not null
 * @see ComputeSystemCreate
 * @brief Create compute system
 * @return Returns an instance of {@link TaskResourceRep} which represents
 *         the Task created for Discovery. The task can then be queried to
 *         know status and progress
 * @throws DatabaseException
 */
@POST
@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 createComputeSystem(ComputeSystemCreate param) throws DatabaseException {
    // check device type
    ArgValidator.checkFieldValueFromSystemType(param.getSystemType(), "system_type", Arrays.asList(ComputeSystem.Type.ucs));
    ComputeSystem.Type deviceType = ComputeSystem.Type.valueOf(param.getSystemType());
    ArgValidator.checkFieldNotNull(param.getName(), "name");
    ArgValidator.checkFieldValidIP(param.getIpAddress(), "ip_address");
    ArgValidator.checkFieldNotNull(param.getPortNumber(), "port_number");
    ArgValidator.checkFieldNotNull(param.getUserName(), "user_name");
    ArgValidator.checkFieldNotNull(param.getPassword(), "password");
    // Check for existing device.
    checkForDuplicateDevice(null, param.getIpAddress(), param.getPortNumber(), param.getName());
    ComputeSystem cs = new ComputeSystem();
    URI id = URIUtil.createId(ComputeSystem.class);
    cs.setId(id);
    cs.setLabel(param.getName());
    cs.setIpAddress(param.getIpAddress());
    cs.setPortNumber(param.getPortNumber());
    cs.setSecure(param.getUseSSL());
    cs.setUsername(param.getUserName());
    cs.setPassword(param.getPassword());
    cs.setSystemType(deviceType.name());
    if (param.getOsInstallNetwork() != null) {
        cs.setOsInstallNetwork(param.getOsInstallNetwork());
    }
    URI imageServerURI = param.getComputeImageServer();
    associateImageServerToComputeSystem(imageServerURI, cs);
    cs.setNativeGuid(NativeGUIDGenerator.generateNativeGuid(cs));
    cs.setRegistrationStatus(DiscoveredDataObject.RegistrationStatus.REGISTERED.name());
    _dbClient.createObject(cs);
    recordAndAudit(cs, OperationTypeEnum.CREATE_COMPUTE_SYSTEM, true, AuditLogManager.AUDITOP_BEGIN);
    return doDiscoverComputeSystem(cs);
}
Also used : URI(java.net.URI) ComputeSystem(com.emc.storageos.db.client.model.ComputeSystem) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Aggregations

ComputeSystem (com.emc.storageos.db.client.model.ComputeSystem)50 ComputeElement (com.emc.storageos.db.client.model.ComputeElement)15 URI (java.net.URI)15 Host (com.emc.storageos.db.client.model.Host)14 InternalException (com.emc.storageos.svcs.errorhandling.resources.InternalException)13 Produces (javax.ws.rs.Produces)13 ComputeSystemControllerException (com.emc.storageos.computesystemcontroller.exceptions.ComputeSystemControllerException)12 Path (javax.ws.rs.Path)11 CheckPermission (com.emc.storageos.security.authorization.CheckPermission)10 ImageServerControllerException (com.emc.storageos.imageservercontroller.exceptions.ImageServerControllerException)8 ComputeLanBootImagePath (com.emc.storageos.db.client.model.ComputeLanBootImagePath)7 ComputeSanBootImagePath (com.emc.storageos.db.client.model.ComputeSanBootImagePath)7 VcenterControllerException (com.emc.storageos.vcentercontroller.exceptions.VcenterControllerException)7 VcenterObjectConnectionException (com.emc.storageos.vcentercontroller.exceptions.VcenterObjectConnectionException)7 VcenterObjectNotFoundException (com.emc.storageos.vcentercontroller.exceptions.VcenterObjectNotFoundException)7 ClientGeneralException (com.emc.cloud.platform.clientlib.ClientGeneralException)6 DeviceControllerException (com.emc.storageos.exceptions.DeviceControllerException)6 MalformedURLException (java.net.MalformedURLException)6 POST (javax.ws.rs.POST)6 URL (java.net.URL)5