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;
}
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());
}
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;
}
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;
}
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;
}
Aggregations