use of com.vmware.photon.controller.model.query.QueryUtils.QueryByPages in project photon-model by vmware.
the class AzureComputeEnumerationAdapterService method queryForComputeStates.
/**
* Query all compute states for the cluster filtered by the received set of instance Ids.
*/
private void queryForComputeStates(EnumerationContext ctx, ComputeEnumerationSubStages next) {
if (ctx.virtualMachines.isEmpty() && ctx.regions.isEmpty()) {
ctx.subStage = ComputeEnumerationSubStages.DISASSOCIATE_COMPUTE_STATES;
handleSubStage(ctx);
return;
}
Query.Builder qBuilder = Query.Builder.create().addKindFieldClause(ComputeState.class).addFieldClause(ComputeState.FIELD_NAME_PARENT_LINK, ctx.request.resourceLink());
Query.Builder instanceIdFilterParentQuery = Query.Builder.create(Occurance.MUST_OCCUR);
for (String instanceId : ctx.virtualMachines.keySet()) {
Query instanceIdFilter = Query.Builder.create(Occurance.SHOULD_OCCUR).addFieldClause(ComputeState.FIELD_NAME_ID, instanceId).build();
instanceIdFilterParentQuery.addClause(instanceIdFilter);
}
// also get compute states representing regions
for (RegionInfo region : ctx.regions.values()) {
Query instanceIdFilter = Query.Builder.create(Occurance.SHOULD_OCCUR).addFieldClause(ComputeState.FIELD_NAME_ID, region.regionId).build();
instanceIdFilterParentQuery.addClause(instanceIdFilter);
}
qBuilder.addClause(instanceIdFilterParentQuery.build());
QueryByPages<ComputeState> queryLocalStates = new QueryByPages<>(getHost(), qBuilder.build(), ComputeState.class, ctx.parentCompute.tenantLinks, // endpointLink
null, ctx.parentCompute.documentSelfLink).setMaxPageSize(QueryUtils.MAX_RESULT_LIMIT).setClusterType(ServiceTypeCluster.INVENTORY_SERVICE);
queryLocalStates.queryDocuments(c -> ctx.computeStates.put(c.id, c)).whenComplete(thenHandleSubStage(ctx, next));
}
use of com.vmware.photon.controller.model.query.QueryUtils.QueryByPages in project photon-model by vmware.
the class AzureSubscriptionsEnumerationService method updateExistingResources.
private void updateExistingResources(AzureSubscriptionsEnumerationContext enumerationContext, AzureCostComputeEnumerationStages nextStage) {
// Query the subscriptions which we want to create to check if they already exist
Query azureSubscriptionEndpointQuery = createQueryForAzureSubscriptionEndpoints(enumerationContext);
// Use max page size since we are collectDocuments EndpointStates
QueryByPages<EndpointState> querySubscriptionEndpoints = new QueryByPages<>(getHost(), azureSubscriptionEndpointQuery, EndpointState.class, enumerationContext.parent.tenantLinks).setMaxPageSize(QueryUtils.MAX_RESULT_LIMIT).setClusterType(ServiceTypeCluster.INVENTORY_SERVICE);
querySubscriptionEndpoints.collectDocuments(Collectors.toList()).whenComplete((subscriptionEndpoints, t) -> {
if (t != null) {
getFailureConsumer(enumerationContext).accept(t);
return;
}
if (subscriptionEndpoints.isEmpty()) {
enumerationContext.stage = nextStage;
handleAzureSubscriptionsEnumerationRequest(enumerationContext);
return;
}
queryExistingComputeStatesOfEndpoints(enumerationContext, nextStage, subscriptionEndpoints);
});
}
use of com.vmware.photon.controller.model.query.QueryUtils.QueryByPages 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);
}
use of com.vmware.photon.controller.model.query.QueryUtils.QueryByPages in project photon-model by vmware.
the class ResourcePoolQueryHelper method handleMissingComputes.
/**
* With the given compute links, finds which ones are not already retrieved as part of a
* resource pool, and loads the corresponding ComputeState documents into the result.
*/
private DeferredResult<Void> handleMissingComputes(Collection<String> allComputeLinks) {
Collection<String> missingComputeLinks = new HashSet<>(allComputeLinks);
missingComputeLinks.removeAll(this.result.computesByLink.keySet());
if (missingComputeLinks.isEmpty()) {
return DeferredResult.completed(null);
}
Query query = Query.Builder.create().addKindFieldClause(ComputeState.class).addInClause(ServiceDocument.FIELD_NAME_SELF_LINK, missingComputeLinks).build();
QueryByPages<ComputeState> queryByPages = new QueryByPages<>(this.host, query, ComputeState.class, this.tenantLinks);
queryByPages.setClusterType(ServiceTypeCluster.INVENTORY_SERVICE);
return queryByPages.setMaxPageSize(PAGE_SIZE).collectDocuments(Collectors.toMap(cs -> cs.documentSelfLink, cs -> cs)).thenAccept(computesMap -> storeComputes(null, computesMap));
}
Aggregations