Search in sources :

Example 41 with ComputeSystem

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

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

the class VirtualArrayService method getServiceProfileTemplatesForComputeSystem.

private List<NamedRelatedResourceRep> getServiceProfileTemplatesForComputeSystem(URI computeSystemId, URI varrayId) {
    List<NamedRelatedResourceRep> templates = new ArrayList<NamedRelatedResourceRep>();
    ComputeSystem computeSystem = _dbClient.queryObject(ComputeSystem.class, computeSystemId);
    VirtualArray varray = _dbClient.queryObject(VirtualArray.class, varrayId);
    _log.debug("Finding SPTs from Compute System:" + computeSystem.getLabel() + " valid for varray:" + varray.getLabel());
    List<NamedRelatedResourceRep> spts = computeSystemService.getServiceProfileTemplatesForComputeSystem(computeSystem, _dbClient);
    StringSet varrays = new StringSet();
    varrays.add(varrayId.toString());
    // Filter SPTs that are not valid for the varrays for the UCS in this vcp
    for (NamedRelatedResourceRep spt : spts) {
        if (computeSystemService.isServiceProfileTemplateValidForVarrays(varrays, spt.getId())) {
            templates.add(spt);
            _log.debug("SPT " + spt.getName() + " is valid for the varray:" + varray.getLabel());
        } else {
            _log.debug("SPT " + spt.getName() + " is not valid for the varray:" + varray.getLabel());
        }
    }
    return templates;
}
Also used : MapVirtualArray(com.emc.storageos.api.mapper.functions.MapVirtualArray) VirtualArray(com.emc.storageos.db.client.model.VirtualArray) ArrayList(java.util.ArrayList) VirtualArrayList(com.emc.storageos.model.varray.VirtualArrayList) StringSet(com.emc.storageos.db.client.model.StringSet) NamedRelatedResourceRep(com.emc.storageos.model.NamedRelatedResourceRep) ComputeSystem(com.emc.storageos.db.client.model.ComputeSystem)

Example 43 with ComputeSystem

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

the class VirtualArrayService method getComputeSystems.

/**
 * Fetches all Compute Systems that are visible in the vArray
 *
 * First determine physical connectivity to any switches in the vArrray.
 * 1. From the vArray, determine the networks. (Call this Network Set)
 * 2. From the networks, get the physical switches that are attached.
 * 3. For each physical switch, iterate through the networks and get the FC endpoints.
 * 4. Look for any of the FIC ports in any of the FC endpoints on any of the
 * networks on the physical switch. When a FIC port matches, call this FIC
 * Port.
 * 5. If found, then there is physical connectivity.
 *
 * With physical connectivity Established:
 * 1. Given the FIC Port from step (4), pull the VSAN or VSANs assigned to
 * it on UCS.
 * 2. If the set contains one of the networks from the Network
 * Set in (1), we have connectivity to that vArray.
 *
 * @param id
 *            the URN of a ViPR VirtualArray.
 * @brief List all Compute Systems that are visible in the vArray
 * @return List of Compute Systems
 */
@GET
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{id}/compute-systems")
@CheckPermission(roles = { Role.SYSTEM_ADMIN, Role.SYSTEM_MONITOR }, acls = { ACL.USE })
public ComputeSystemBulkRep getComputeSystems(@PathParam("id") URI id) {
    _log.info("get connected CS for vArray: {}", id);
    // Get and validate the varray with the passed id.
    ArgValidator.checkFieldUriType(id, VirtualArray.class, "id");
    VirtualArray varray = _dbClient.queryObject(VirtualArray.class, id);
    ArgValidator.checkEntityNotNull(varray, id, isIdEmbeddedInURL(id));
    BulkIdParam matchingCsIds = new BulkIdParam();
    // get varray networks
    List<Network> networks = CustomQueryUtility.queryActiveResourcesByRelation(_dbClient, id, Network.class, "connectedVirtualArrays");
    // collect network vsanIds and switch ids
    Set<String> networkVsanIds = new HashSet<>();
    Set<String> nsIds = new HashSet<>();
    for (Network network : networks) {
        if (StorageProtocol.Transport.FC.name().equalsIgnoreCase(network.getTransportType()) && DiscoveredSystemObject.RegistrationStatus.REGISTERED.name().equals(network.getRegistrationStatus())) {
            networkVsanIds.add(network.getNativeId());
            if (network.getNetworkSystems() != null) {
                nsIds.addAll(network.getNetworkSystems());
            }
        }
    }
    _log.info("vArray has these networks: {}", networkVsanIds);
    // use only registered network systems
    Set<URI> nsUris = new HashSet<>();
    for (String nsUri : nsIds) {
        nsUris.add(URI.create(nsUri));
    }
    List<NetworkSystem> nsList = _dbClient.queryObject(NetworkSystem.class, nsUris);
    for (NetworkSystem ns : nsList) {
        if (!DiscoveredSystemObject.RegistrationStatus.REGISTERED.name().equals(ns.getRegistrationStatus())) {
            nsIds.remove(ns.getId().toString());
        }
    }
    _log.info("the networks run on these network systems: {}", nsIds);
    if (networkVsanIds.isEmpty() || nsIds.isEmpty()) {
        // no networks in the array - exit early
        return new ComputeSystemBulkRep();
    }
    // for every switch get FCEndpoint.remotePortName(s)
    Set<String> connectedEndpoints = new HashSet<String>();
    for (String nsId : nsIds) {
        URIQueryResultList uriList = new URIQueryResultList();
        _dbClient.queryByConstraint(ContainmentConstraint.Factory.getNetworkSystemFCPortConnectionConstraint(URI.create(nsId)), uriList);
        List<URI> epIds = new ArrayList<URI>();
        Iterator<URI> iter = uriList.iterator();
        while (iter.hasNext()) {
            epIds.add(iter.next());
        }
        List<FCEndpoint> eps = _dbClient.queryObjectField(FCEndpoint.class, "remotePortName", epIds);
        for (FCEndpoint ep : eps) {
            connectedEndpoints.add(ep.getRemotePortName());
        }
    }
    _log.debug("all connected endpoints: {}", connectedEndpoints);
    // get all CS
    List<URI> csIds = _dbClient.queryByType(ComputeSystem.class, true);
    List<ComputeSystem> csList = _dbClient.queryObject(ComputeSystem.class, csIds);
    for (ComputeSystem cs : csList) {
        if (!DiscoveredSystemObject.RegistrationStatus.REGISTERED.name().equals(cs.getRegistrationStatus())) {
            // skip not registered CS
            continue;
        }
        boolean connected = false;
        _log.info("evaluating uplinks of cs: {}", cs.getLabel());
        // loop thru UplinkPorts to find matches
        URIQueryResultList uris = new URIQueryResultList();
        _dbClient.queryByConstraint(ContainmentConstraint.Factory.getComputeSystemComputeFabricUplinkPortConstraint(cs.getId()), uris);
        List<ComputeFabricUplinkPort> uplinkPorts = _dbClient.queryObject(ComputeFabricUplinkPort.class, uris, true);
        for (ComputeFabricUplinkPort port : uplinkPorts) {
            if (connectedEndpoints.contains(port.getWwpn())) {
                _log.info("found matching endpoint: {}", port.getWwpn());
                if (!Collections.disjoint(port.getVsans(), networkVsanIds)) {
                    _log.info("and networks overlap: {}", port.getVsans());
                    matchingCsIds.getIds().add(cs.getId());
                    connected = true;
                    break;
                }
            }
        }
        if (connected) {
            // skip uplink port channel matching as we are already connected
            continue;
        }
        // now loop thru UplinkPortChannels to find matches
        uris = new URIQueryResultList();
        _dbClient.queryByConstraint(ContainmentConstraint.Factory.getComputeSystemComputeUplinkPortChannelConstraint(cs.getId()), uris);
        List<ComputeFabricUplinkPortChannel> uplinkPortChannels = _dbClient.queryObject(ComputeFabricUplinkPortChannel.class, uris, true);
        for (ComputeFabricUplinkPortChannel port : uplinkPortChannels) {
            if (connectedEndpoints.contains(port.getWwpn())) {
                _log.info("found matching endpoint: {}", port.getWwpn());
                if (!Collections.disjoint(port.getVsans(), networkVsanIds)) {
                    _log.info("and networks overlap: {}", port.getVsans());
                    matchingCsIds.getIds().add(cs.getId());
                    connected = true;
                    break;
                }
            }
        }
    }
    _log.info("these CS are connected to the vArray: {}", matchingCsIds.getIds());
    if (matchingCsIds.getIds().isEmpty()) {
        return new ComputeSystemBulkRep();
    }
    ComputeSystemBulkRep computeSystemReps = computeSystemService.getBulkResources(matchingCsIds);
    return mapValidServiceProfileTemplatesToComputeSystem(computeSystemReps, varray.getId());
}
Also used : MapVirtualArray(com.emc.storageos.api.mapper.functions.MapVirtualArray) VirtualArray(com.emc.storageos.db.client.model.VirtualArray) BulkIdParam(com.emc.storageos.model.BulkIdParam) ComputeFabricUplinkPort(com.emc.storageos.db.client.model.ComputeFabricUplinkPort) ArrayList(java.util.ArrayList) VirtualArrayList(com.emc.storageos.model.varray.VirtualArrayList) URI(java.net.URI) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList) Network(com.emc.storageos.db.client.model.Network) ComputeSystemBulkRep(com.emc.storageos.model.compute.ComputeSystemBulkRep) ComputeFabricUplinkPortChannel(com.emc.storageos.db.client.model.ComputeFabricUplinkPortChannel) ComputeSystem(com.emc.storageos.db.client.model.ComputeSystem) HashSet(java.util.HashSet) NetworkSystem(com.emc.storageos.db.client.model.NetworkSystem) FCEndpoint(com.emc.storageos.db.client.model.FCEndpoint) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Example 44 with ComputeSystem

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

the class ComputeSystemUtils method queryRegisteredSystem.

/**
 * Gets the compute system with the passed id from the database.
 *
 * @param id
 *            the URN of a ViPR compute system
 *
 * @return A detailed representation of the registered ComputeSystem.
 *
 * @throws BadRequestException
 *             When the compute system is not registered.
 */
public static ComputeSystem queryRegisteredSystem(URI id, DbClient _dbClient, boolean isIdEmbeddedInURL) {
    ArgValidator.checkUri(id);
    ComputeSystem system = _dbClient.queryObject(ComputeSystem.class, id);
    ArgValidator.checkEntityNotNull(system, id, isIdEmbeddedInURL);
    if (!RegistrationStatus.REGISTERED.toString().equalsIgnoreCase(system.getRegistrationStatus())) {
        throw APIException.badRequests.resourceNotRegistered(ComputeSystem.class.getSimpleName(), id);
    }
    return system;
}
Also used : ComputeSystem(com.emc.storageos.db.client.model.ComputeSystem)

Example 45 with ComputeSystem

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

the class ComputeImageServerService method removeImageServerFromComputeSystem.

/**
 * Removes the given imageServerId from each ComputeSystem present,
 * if the computeSystem has the given imageServerId as it association or relation.
 * Disassociate's  the imageServer from the computeSystem.
 * @param imageServerID {@link URI} computeImageServer id
 */
private void removeImageServerFromComputeSystem(URI imageServerID) {
    // Remove the association with the ComputeSystem and then delete
    // the imageServer
    List<URI> computeSystemURIList = _dbClient.queryByType(ComputeSystem.class, true);
    if (computeSystemURIList != null && computeSystemURIList.iterator().hasNext()) {
        List<ComputeSystem> computeSystems = _dbClient.queryObject(ComputeSystem.class, computeSystemURIList);
        if (!CollectionUtils.isEmpty(computeSystems)) {
            for (ComputeSystem computeSystem : computeSystems) {
                if (computeSystem.getComputeImageServer() != null && computeSystem.getComputeImageServer().equals(imageServerID)) {
                    computeSystem.setComputeImageServer(NullColumnValueGetter.getNullURI());
                    _dbClient.updateObject(computeSystem);
                    log.info("Disassociating imageServer {} from ComputeSystem id {} ", imageServerID, computeSystem.getId());
                }
            }
        }
    }
}
Also used : URI(java.net.URI) ComputeSystem(com.emc.storageos.db.client.model.ComputeSystem)

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