Search in sources :

Example 46 with ComputeElement

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

the class HostService method findComputeElementsUsedInCluster.

private Map<URI, List<ComputeElement>> findComputeElementsUsedInCluster(URI clusterId) throws DatabaseException {
    Map<URI, List<ComputeElement>> computeSystemToComputeElementMap = new HashMap<URI, List<ComputeElement>>();
    HostList hostList = clusterService.getClusterHosts(clusterId);
    List<NamedRelatedResourceRep> list = hostList.getHosts();
    for (NamedRelatedResourceRep hostRep : list) {
        HostRestRep host = getHost(hostRep.getId());
        RelatedResourceRep computeElement = host.getComputeElement();
        if (computeElement == null) {
            // this can happen if cluster has hosts that were not provisioned by vipr
            continue;
        }
        ComputeElement ce = _dbClient.queryObject(ComputeElement.class, computeElement.getId());
        URI computeSystem = ce.getComputeSystem();
        List<ComputeElement> usedComputeElements;
        if (computeSystemToComputeElementMap.containsKey(computeSystem)) {
            usedComputeElements = computeSystemToComputeElementMap.get(computeSystem);
        } else {
            usedComputeElements = new ArrayList<ComputeElement>();
        }
        usedComputeElements.add(ce);
        computeSystemToComputeElementMap.put(computeSystem, usedComputeElements);
    }
    return computeSystemToComputeElementMap;
}
Also used : HostRestRep(com.emc.storageos.model.host.HostRestRep) NamedRelatedResourceRep(com.emc.storageos.model.NamedRelatedResourceRep) RelatedResourceRep(com.emc.storageos.model.RelatedResourceRep) LinkedHashMap(java.util.LinkedHashMap) HashMap(java.util.HashMap) ComputeElement(com.emc.storageos.db.client.model.ComputeElement) UnManagedExportMaskList(com.emc.storageos.model.block.UnManagedExportMaskList) UnManagedVolumeList(com.emc.storageos.model.block.UnManagedVolumeList) NamedElementQueryResultList(com.emc.storageos.db.client.constraint.NamedElementQueryResultList) InitiatorList(com.emc.storageos.model.host.InitiatorList) ArrayList(java.util.ArrayList) TaskList(com.emc.storageos.model.TaskList) MountInfoList(com.emc.storageos.model.file.MountInfoList) HostList(com.emc.storageos.model.host.HostList) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList) List(java.util.List) BulkList(com.emc.storageos.api.service.impl.response.BulkList) LinkedList(java.util.LinkedList) IpInterfaceList(com.emc.storageos.model.host.IpInterfaceList) HostList(com.emc.storageos.model.host.HostList) NamedRelatedResourceRep(com.emc.storageos.model.NamedRelatedResourceRep) URI(java.net.URI)

Example 47 with ComputeElement

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

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

the class ComputeElementService method getComputeElement.

/**
 * Gets the data for a compute element.
 *
 * @param id the URN of a ViPR compute element.
 *
 * @brief Show compute element
 * @return A ComputeElementRestRep reference specifying the data for the
 *         compute element with the passed id.
 */
@GET
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{id}")
@CheckPermission(roles = { Role.SYSTEM_ADMIN, Role.SYSTEM_MONITOR })
public ComputeElementRestRep getComputeElement(@PathParam("id") URI id) {
    ArgValidator.checkFieldUriType(id, ComputeElement.class, "id");
    ComputeElement ce = queryResource(id);
    ArgValidator.checkEntity(ce, id, isIdEmbeddedInURL(id));
    Host associatedHost = getAssociatedHost(ce, _dbClient);
    Cluster cluster = null;
    if (associatedHost != null && !NullColumnValueGetter.isNullURI(associatedHost.getCluster())) {
        cluster = _dbClient.queryObject(Cluster.class, associatedHost.getCluster());
    }
    return ComputeMapper.map(ce, associatedHost, cluster);
}
Also used : ComputeElement(com.emc.storageos.db.client.model.ComputeElement) Cluster(com.emc.storageos.db.client.model.Cluster) Host(com.emc.storageos.db.client.model.Host) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Example 49 with ComputeElement

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

the class ComputeElementService method queryRegisteredResource.

/**
 * Gets the compute element with the passed id from the database.
 *
 * @param id the URN of a ViPR compute element.
 *
 * @return A reference to the registered compute element.
 *
 * @throws BadRequestException When the compute element is not registered.
 */
protected ComputeElement queryRegisteredResource(URI id) {
    ArgValidator.checkUri(id);
    ComputeElement ce = _dbClient.queryObject(ComputeElement.class, id);
    ArgValidator.checkEntityNotNull(ce, id, isIdEmbeddedInURL(id));
    if (!RegistrationStatus.REGISTERED.toString().equalsIgnoreCase(ce.getRegistrationStatus())) {
        throw APIException.badRequests.resourceNotRegistered(ComputeElement.class.getSimpleName(), id);
    }
    return ce;
}
Also used : ComputeElement(com.emc.storageos.db.client.model.ComputeElement)

Example 50 with ComputeElement

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

the class ComputeSystemService method getComputeElements.

/**
 * Fetches all the Compute Elements belonging to a Compute System in ViPR
 *
 * @param id
 *            the URN of a ViPR Compute System
 * @brief Show compute elements
 * @return A detailed representation of compute elements
 * @throws InternalException
 */
@GET
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{id}/compute-elements")
@CheckPermission(roles = { Role.SYSTEM_ADMIN, Role.SYSTEM_MONITOR })
public ComputeElementListRestRep getComputeElements(@PathParam("id") URI id) throws InternalException {
    ComputeElementListRestRep result = new ComputeElementListRestRep();
    ArgValidator.checkFieldUriType(id, ComputeSystem.class, "id");
    ComputeSystem cs = queryResource(id);
    URIQueryResultList ceUriList = new URIQueryResultList();
    _dbClient.queryByConstraint(ContainmentConstraint.Factory.getComputeSystemComputeElemetsConstraint(cs.getId()), ceUriList);
    Iterator<URI> iterator = ceUriList.iterator();
    Collection<URI> hostIds = _dbClient.queryByType(Host.class, true);
    Collection<Host> hosts = _dbClient.queryObjectFields(Host.class, Arrays.asList("label", "computeElement", "cluster"), ControllerUtils.getFullyImplementedCollection(hostIds));
    while (iterator.hasNext()) {
        ComputeElement ce = _dbClient.queryObject(ComputeElement.class, iterator.next());
        if (ce != null) {
            Host associatedHost = null;
            for (Host host : hosts) {
                if (!NullColumnValueGetter.isNullURI(host.getComputeElement()) && host.getComputeElement().equals(ce.getId())) {
                    associatedHost = host;
                    break;
                }
            }
            Cluster cluster = null;
            if (associatedHost != null && !NullColumnValueGetter.isNullURI(associatedHost.getCluster())) {
                cluster = _dbClient.queryObject(Cluster.class, associatedHost.getCluster());
            }
            ComputeElementRestRep rest = map(ce, associatedHost, cluster);
            if (rest != null) {
                result.getList().add(rest);
            }
        }
    }
    return result;
}
Also used : ComputeElementListRestRep(com.emc.storageos.model.compute.ComputeElementListRestRep) ComputeElement(com.emc.storageos.db.client.model.ComputeElement) Cluster(com.emc.storageos.db.client.model.Cluster) Host(com.emc.storageos.db.client.model.Host) ComputeElementRestRep(com.emc.storageos.model.compute.ComputeElementRestRep) URI(java.net.URI) ComputeSystem(com.emc.storageos.db.client.model.ComputeSystem) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList) Path(javax.ws.rs.Path) ComputeSanBootImagePath(com.emc.storageos.db.client.model.ComputeSanBootImagePath) ComputeLanBootImagePath(com.emc.storageos.db.client.model.ComputeLanBootImagePath) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Aggregations

ComputeElement (com.emc.storageos.db.client.model.ComputeElement)52 Host (com.emc.storageos.db.client.model.Host)24 URI (java.net.URI)20 ComputeSystem (com.emc.storageos.db.client.model.ComputeSystem)15 InternalException (com.emc.storageos.svcs.errorhandling.resources.InternalException)12 DeviceControllerException (com.emc.storageos.exceptions.DeviceControllerException)11 ClientGeneralException (com.emc.cloud.platform.clientlib.ClientGeneralException)10 ComputeSystemControllerException (com.emc.storageos.computesystemcontroller.exceptions.ComputeSystemControllerException)10 LsServer (com.emc.cloud.platform.ucs.out.model.LsServer)9 MalformedURLException (java.net.MalformedURLException)9 Produces (javax.ws.rs.Produces)9 ComputeSystemControllerTimeoutException (com.emc.storageos.computesystemcontroller.exceptions.ComputeSystemControllerTimeoutException)8 HashMap (java.util.HashMap)8 Path (javax.ws.rs.Path)8 URIQueryResultList (com.emc.storageos.db.client.constraint.URIQueryResultList)7 CheckPermission (com.emc.storageos.security.authorization.CheckPermission)7 ComputeVirtualPool (com.emc.storageos.db.client.model.ComputeVirtualPool)6 UCSServiceProfile (com.emc.storageos.db.client.model.UCSServiceProfile)6 UCSServiceProfileTemplate (com.emc.storageos.db.client.model.UCSServiceProfileTemplate)6 Cluster (com.emc.storageos.db.client.model.Cluster)4