use of com.vmware.photon.controller.model.tasks.helpers.ResourcePoolQueryHelper.QueryResult.ResourcePoolData in project photon-model by vmware.
the class ResourcePoolQueryHelper method storeResourcePool.
/**
* Stores the retrieved resource pool states into the QueryResult instance.
*/
private void storeResourcePool(ResourcePoolState rp) {
ResourcePoolData rpData = new ResourcePoolData();
rpData.resourcePoolState = rp;
rpData.computeStateLinks = new HashSet<>();
this.result.resourcesPools.put(rp.documentSelfLink, rpData);
}
use of com.vmware.photon.controller.model.tasks.helpers.ResourcePoolQueryHelper.QueryResult.ResourcePoolData in project photon-model by vmware.
the class ResourcePoolQueryHelper method storeComputes.
/**
* Stores the retrieved compute states into the QueryResult instance.
* The rpLink may be null in case the given computes do not fall into any resource pool.
*/
private void storeComputes(String rpLink, Map<String, ComputeState> computes) {
if (rpLink != null) {
ResourcePoolData rpData = this.result.resourcesPools.get(rpLink);
rpData.computeStateLinks.addAll(computes.keySet());
}
for (Map.Entry<String, ComputeState> computeEntry : computes.entrySet()) {
String computeLink = computeEntry.getKey();
ComputeState compute = computeEntry.getValue();
this.result.computesByLink.put(computeLink, compute);
// make sure rpLinksByComputeLink has an empty item even for computes with no rp link
Set<String> rpLinks = this.result.rpLinksByComputeLink.get(computeLink);
if (rpLinks == null) {
rpLinks = new HashSet<String>();
this.result.rpLinksByComputeLink.put(computeLink, rpLinks);
}
if (rpLink != null) {
rpLinks.add(rpLink);
}
}
}
use of com.vmware.photon.controller.model.tasks.helpers.ResourcePoolQueryHelper.QueryResult.ResourcePoolData in project photon-model by vmware.
the class ResourcePoolQueryHelper method executeRpQueries.
/**
* Executes the resource pool queries in parallel and then collects the result.
*/
private DeferredResult<Void> executeRpQueries() {
List<DeferredResult<Void>> rpQueryDRs = new ArrayList<>(this.result.resourcesPools.size());
Map<String, Map<String, ComputeState>> computeMapByRpLink = new ConcurrentHashMap<>();
for (ResourcePoolData rpData : this.result.resourcesPools.values()) {
String rpLink = rpData.resourcePoolState.documentSelfLink;
Query rpQuery = rpData.resourcePoolState.query;
Query.Builder queryBuilder = Query.Builder.create().addClause(rpQuery);
if (this.computeLinks != null && !this.computeLinks.isEmpty()) {
queryBuilder.addInClause(ServiceDocument.FIELD_NAME_SELF_LINK, this.computeLinks);
} else if (this.additionalQueryClausesProvider != null) {
this.additionalQueryClausesProvider.accept(queryBuilder);
}
QueryByPages<ComputeState> computeQuery = new QueryByPages<>(this.host, queryBuilder.build(), ComputeState.class, this.tenantLinks).setMaxPageSize(PAGE_SIZE);
computeQuery.setClusterType(ServiceTypeCluster.INVENTORY_SERVICE);
DeferredResult<Map<String, ComputeState>> rpQueryDR;
if (this.expandComputes) {
rpQueryDR = computeQuery.collectDocuments(Collectors.toMap(cs -> cs.documentSelfLink, cs -> cs));
} else {
// manually collect links since Collectors.toMap() does not allow null values
Map<String, ComputeState> computesMap = new HashMap<>();
rpQueryDR = computeQuery.queryLinks(csLink -> computesMap.put(csLink, null)).thenApply(ignore -> computesMap);
}
rpQueryDRs.add(rpQueryDR.thenAccept(computesMap -> computeMapByRpLink.put(rpLink, computesMap)));
}
return DeferredResult.allOf(rpQueryDRs).thenAccept(ignore -> computeMapByRpLink.forEach(this::storeComputes)).thenApply(ignore -> (Void) null);
}
Aggregations