Search in sources :

Example 6 with HostList

use of com.emc.storageos.model.host.HostList in project coprhd-controller by CoprHD.

the class VcenterService method getVcenterHosts.

/**
 * List the hosts of a vCenter.
 *
 * @param id the URN of a ViPR vCenter
 * @prereq none
 * @brief List vCenter hosts
 * @return The list of hosts of the vCenter.
 * @throws DatabaseException when a DB error occurs.
 */
@GET
@Path("/{id}/hosts")
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public HostList getVcenterHosts(@PathParam("id") URI id) throws DatabaseException {
    Vcenter vcenter = queryObject(Vcenter.class, id, false);
    ArgValidator.checkEntity(vcenter, id, isIdEmbeddedInURL(id));
    // check the user permissions for this tenant org
    verifyAuthorizedInTenantOrg(_permissionsHelper.convertToACLEntries(vcenter.getAcls()));
    URI tenantId = URI.create(getUserFromContext().getTenantId());
    List<NamedElementQueryResultList.NamedElement> vCentersDataCenters = filterTenantResourcesByTenant(tenantId, VcenterDataCenter.class, listChildren(id, VcenterDataCenter.class, DATAOBJECT_NAME_FIELD, "vcenter"));
    HostList list = new HostList();
    Iterator<NamedElementQueryResultList.NamedElement> dataCentersIterator = vCentersDataCenters.iterator();
    while (dataCentersIterator.hasNext()) {
        NamedElementQueryResultList.NamedElement dataCenterElement = dataCentersIterator.next();
        list.getHosts().addAll(map(ResourceTypeEnum.HOST, listChildren(dataCenterElement.getId(), Host.class, DATAOBJECT_NAME_FIELD, "vcenterDataCenter")));
    }
    return list;
}
Also used : MapVcenter(com.emc.storageos.api.mapper.functions.MapVcenter) HostList(com.emc.storageos.model.host.HostList) URI(java.net.URI) NamedElementQueryResultList(com.emc.storageos.db.client.constraint.NamedElementQueryResultList) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 7 with HostList

use of com.emc.storageos.model.host.HostList in project coprhd-controller by CoprHD.

the class Hosts method listByTenant.

/**
 * Lists the hosts by tenant.
 * <p>
 * API Call: <tt>GET /compute/hosts?tenant={tenantId}</tt>
 *
 * @param tenantId
 *            the ID of the tenant.
 * @return the list of host references.
 */
@Override
public List<NamedRelatedResourceRep> listByTenant(URI tenantId) {
    UriBuilder uriBuilder = client.uriBuilder(baseUrl);
    if (tenantId != null) {
        uriBuilder.queryParam(TENANT_PARAM, tenantId);
    }
    HostList response = client.getURI(HostList.class, uriBuilder.build());
    return defaultList(response.getHosts());
}
Also used : HostList(com.emc.storageos.model.host.HostList) UriBuilder(javax.ws.rs.core.UriBuilder)

Example 8 with HostList

use of com.emc.storageos.model.host.HostList in project coprhd-controller by CoprHD.

the class ApiTestVcenter method getHostsByTenantApi.

private HostList getHostsByTenantApi(BalancedWebResource user, URI tenantId, int expectedStatus) {
    ClientResponse clientResponse = user.path(getHostTenantApi(tenantId)).get(ClientResponse.class);
    Assert.assertEquals(expectedStatus, clientResponse.getStatus());
    if (expectedStatus != HttpStatus.SC_OK) {
        return null;
    }
    HostList hostList = clientResponse.getEntity(HostList.class);
    Assert.assertNotNull(hostList);
    return hostList;
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) HostList(com.emc.storageos.model.host.HostList)

Example 9 with HostList

use of com.emc.storageos.model.host.HostList in project coprhd-controller by CoprHD.

the class VcenterDataCenterService method getVcenterDataCenterHosts.

/**
 * List the hosts in a vCenter data center.
 *
 * @param id the URN of a ViPR vCenter data center
 * @prereq none
 * @brief List vCenter data center hosts
 * @return The list of hosts of the vCenter data center.
 * @throws DatabaseException when a DB error occurs.
 */
@GET
@Path("/{id}/hosts")
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public HostList getVcenterDataCenterHosts(@PathParam("id") URI id) throws DatabaseException {
    VcenterDataCenter dataCenter = queryResource(id);
    // check the user permissions
    verifyAuthorizedInTenantOrg(dataCenter.getTenant(), getUserFromContext());
    // add all hosts in the data center
    HostList list = new HostList();
    list.setHosts(map(ResourceTypeEnum.HOST, listChildren(dataCenter.getId(), Host.class, "label", "vcenterDataCenter")));
    return list;
}
Also used : MapVcenterDataCenter(com.emc.storageos.api.mapper.functions.MapVcenterDataCenter) HostList(com.emc.storageos.model.host.HostList) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 10 with HostList

use of com.emc.storageos.model.host.HostList 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)

Aggregations

HostList (com.emc.storageos.model.host.HostList)11 GET (javax.ws.rs.GET)7 Produces (javax.ws.rs.Produces)7 Path (javax.ws.rs.Path)6 URI (java.net.URI)3 MapCluster (com.emc.storageos.api.mapper.functions.MapCluster)2 NamedElementQueryResultList (com.emc.storageos.db.client.constraint.NamedElementQueryResultList)2 Cluster (com.emc.storageos.db.client.model.Cluster)2 ClientResponse (com.sun.jersey.api.client.ClientResponse)2 MapVcenter (com.emc.storageos.api.mapper.functions.MapVcenter)1 MapVcenterDataCenter (com.emc.storageos.api.mapper.functions.MapVcenterDataCenter)1 BulkList (com.emc.storageos.api.service.impl.response.BulkList)1 URIQueryResultList (com.emc.storageos.db.client.constraint.URIQueryResultList)1 ComputeElement (com.emc.storageos.db.client.model.ComputeElement)1 Host (com.emc.storageos.db.client.model.Host)1 TenantOrg (com.emc.storageos.db.client.model.TenantOrg)1 VolumeGroup (com.emc.storageos.db.client.model.VolumeGroup)1 NamedRelatedResourceRep (com.emc.storageos.model.NamedRelatedResourceRep)1 RelatedResourceRep (com.emc.storageos.model.RelatedResourceRep)1 TaskList (com.emc.storageos.model.TaskList)1