Search in sources :

Example 1 with ResourcePoolData

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);
}
Also used : ResourcePoolData(com.vmware.photon.controller.model.tasks.helpers.ResourcePoolQueryHelper.QueryResult.ResourcePoolData)

Example 2 with ResourcePoolData

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);
        }
    }
}
Also used : ComputeState(com.vmware.photon.controller.model.resources.ComputeService.ComputeState) ResourcePoolData(com.vmware.photon.controller.model.tasks.helpers.ResourcePoolQueryHelper.QueryResult.ResourcePoolData) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) Map(java.util.Map)

Example 3 with ResourcePoolData

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);
}
Also used : QueryByPages(com.vmware.photon.controller.model.query.QueryUtils.QueryByPages) Collection(java.util.Collection) ServiceTypeCluster(com.vmware.photon.controller.model.util.ClusterUtil.ServiceTypeCluster) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) ResourcePoolData(com.vmware.photon.controller.model.tasks.helpers.ResourcePoolQueryHelper.QueryResult.ResourcePoolData) Set(java.util.Set) ResourcePoolState(com.vmware.photon.controller.model.resources.ResourcePoolService.ResourcePoolState) ServiceDocument(com.vmware.xenon.common.ServiceDocument) HashMap(java.util.HashMap) Collectors(java.util.stream.Collectors) ServiceHost(com.vmware.xenon.common.ServiceHost) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Objects(java.util.Objects) Consumer(java.util.function.Consumer) List(java.util.List) Stream(java.util.stream.Stream) Query(com.vmware.xenon.services.common.QueryTask.Query) UriPaths(com.vmware.photon.controller.model.UriPaths) ComputeState(com.vmware.photon.controller.model.resources.ComputeService.ComputeState) Map(java.util.Map) DeferredResult(com.vmware.xenon.common.DeferredResult) Collections(java.util.Collections) ComputeState(com.vmware.photon.controller.model.resources.ComputeService.ComputeState) Query(com.vmware.xenon.services.common.QueryTask.Query) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ResourcePoolData(com.vmware.photon.controller.model.tasks.helpers.ResourcePoolQueryHelper.QueryResult.ResourcePoolData) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) Map(java.util.Map) DeferredResult(com.vmware.xenon.common.DeferredResult)

Aggregations

ResourcePoolData (com.vmware.photon.controller.model.tasks.helpers.ResourcePoolQueryHelper.QueryResult.ResourcePoolData)3 ComputeState (com.vmware.photon.controller.model.resources.ComputeService.ComputeState)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 UriPaths (com.vmware.photon.controller.model.UriPaths)1 QueryByPages (com.vmware.photon.controller.model.query.QueryUtils.QueryByPages)1 ResourcePoolState (com.vmware.photon.controller.model.resources.ResourcePoolService.ResourcePoolState)1 ServiceTypeCluster (com.vmware.photon.controller.model.util.ClusterUtil.ServiceTypeCluster)1 DeferredResult (com.vmware.xenon.common.DeferredResult)1 ServiceDocument (com.vmware.xenon.common.ServiceDocument)1 ServiceHost (com.vmware.xenon.common.ServiceHost)1 Query (com.vmware.xenon.services.common.QueryTask.Query)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Objects (java.util.Objects)1 Set (java.util.Set)1