Search in sources :

Example 66 with Cluster

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

Example 67 with Cluster

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

the class HostMapper method map.

public static ExportGroupRestRep map(ExportGroup from, List<Initiator> initiators, Map<String, Integer> volumes, List<Host> hosts, List<Cluster> clusters, List<ExportPathParams> exportPathParams) {
    if (from == null) {
        return null;
    }
    ExportGroupRestRep to = new ExportGroupRestRep();
    mapDataObjectFields(from, to);
    if (initiators != null) {
        for (Initiator initiator : initiators) {
            to.getInitiators().add(map(initiator));
        }
    }
    if (volumes != null) {
        for (Map.Entry<String, Integer> entry : volumes.entrySet()) {
            ExportBlockParam volume = new ExportBlockParam();
            volume.setId(URI.create(entry.getKey()));
            Integer lun = entry.getValue();
            if (lun != null && lun != ExportGroup.LUN_UNASSIGNED) {
                volume.setLun(lun);
            }
            to.getVolumes().add(volume);
        }
    }
    if (hosts != null) {
        for (Host host : hosts) {
            to.getHosts().add(map(host));
        }
    }
    if (clusters != null) {
        for (Cluster cluster : clusters) {
            to.getClusters().add(map(cluster));
        }
    }
    if (exportPathParams != null && !exportPathParams.isEmpty()) {
        for (ExportPathParams pathParam : exportPathParams) {
            ExportPathParametersRep pathParamRep = map(pathParam);
            for (Map.Entry<String, String> entry : from.getPathParameters().entrySet()) {
                if (entry.getValue().equals(pathParam.getId().toString())) {
                    pathParamRep.getBlockObjects().add(entry.getKey());
                }
            }
            to.getPathParams().add(pathParamRep);
        }
    }
    if (from.getProject() != null) {
        to.setProject(toRelatedResource(ResourceTypeEnum.PROJECT, from.getProject().getURI()));
    }
    if (from.getTenant() != null) {
        to.setTenant(toRelatedResource(ResourceTypeEnum.TENANT, from.getTenant().getURI()));
    }
    to.setVirtualArray(toRelatedResource(ResourceTypeEnum.VARRAY, from.getVirtualArray()));
    if (from.getType() != null) {
        to.setType(from.getType());
    }
    to.setGeneratedName(from.getGeneratedName());
    if (from.getAltVirtualArrays() != null && !from.getAltVirtualArrays().isEmpty()) {
        // The alternate virtual array is a map from Storage System URI to Virtual Array URI
        List<StringHashMapEntry> toVirtualArrays = new ArrayList<StringHashMapEntry>();
        for (Map.Entry<String, String> entry : from.getAltVirtualArrays().entrySet()) {
            StringHashMapEntry toEntry = new StringHashMapEntry();
            toEntry.setName(entry.getKey());
            toEntry.setValue(entry.getValue());
            toVirtualArrays.add(toEntry);
        }
        to.setAltVirtualArrays(toVirtualArrays);
    }
    return to;
}
Also used : ArrayList(java.util.ArrayList) Cluster(com.emc.storageos.db.client.model.Cluster) Host(com.emc.storageos.db.client.model.Host) StringHashMapEntry(com.emc.storageos.model.StringHashMapEntry) ExportBlockParam(com.emc.storageos.model.block.export.ExportBlockParam) ExportGroupRestRep(com.emc.storageos.model.block.export.ExportGroupRestRep) Initiator(com.emc.storageos.db.client.model.Initiator) ExportPathParametersRep(com.emc.storageos.model.block.export.ExportPathParametersRep) Map(java.util.Map) StringMap(com.emc.storageos.db.client.model.StringMap) ExportPathParams(com.emc.storageos.db.client.model.ExportPathParams)

Aggregations

Cluster (com.emc.storageos.db.client.model.Cluster)67 Host (com.emc.storageos.db.client.model.Host)38 URI (java.net.URI)26 InternalException (com.emc.storageos.svcs.errorhandling.resources.InternalException)20 VcenterDataCenter (com.emc.storageos.db.client.model.VcenterDataCenter)19 Initiator (com.emc.storageos.db.client.model.Initiator)15 DeviceControllerException (com.emc.storageos.exceptions.DeviceControllerException)15 Path (javax.ws.rs.Path)14 Produces (javax.ws.rs.Produces)14 VcenterControllerException (com.emc.storageos.vcentercontroller.exceptions.VcenterControllerException)13 VcenterObjectConnectionException (com.emc.storageos.vcentercontroller.exceptions.VcenterObjectConnectionException)13 VcenterObjectNotFoundException (com.emc.storageos.vcentercontroller.exceptions.VcenterObjectNotFoundException)13 ArrayList (java.util.ArrayList)13 Vcenter (com.emc.storageos.db.client.model.Vcenter)12 VcenterServerConnectionException (com.emc.storageos.vcentercontroller.exceptions.VcenterServerConnectionException)11 HashSet (java.util.HashSet)9 MapCluster (com.emc.storageos.api.mapper.functions.MapCluster)8 VcenterApiClient (com.emc.storageos.vcentercontroller.VcenterApiClient)8 GET (javax.ws.rs.GET)8 URIQueryResultList (com.emc.storageos.db.client.constraint.URIQueryResultList)6