Search in sources :

Example 91 with QueryTask

use of com.vmware.xenon.services.common.QueryTask in project photon-model by vmware.

the class TestVSphereEnumerationTask method findRandomVm.

private ComputeState findRandomVm() throws InterruptedException, TimeoutException, ExecutionException {
    Query q = Query.Builder.create().addCompositeFieldClause(ComputeState.FIELD_NAME_CUSTOM_PROPERTIES, CustomProperties.TYPE, VimNames.TYPE_VM).addKindFieldClause(ComputeState.class).build();
    QueryTask qt = QueryTask.Builder.createDirectTask().setQuery(q).addOption(QueryOption.EXPAND_CONTENT).build();
    Operation op = QueryUtils.createQueryTaskOperation(this.host, qt, ServiceTypeCluster.INVENTORY_SERVICE);
    QueryTask result = this.host.waitForResponse(op).getBody(QueryTask.class);
    Object firstResult = result.results.documents.values().iterator().next();
    return Utils.fromJson(firstResult, ComputeState.class);
}
Also used : ComputeState(com.vmware.photon.controller.model.resources.ComputeService.ComputeState) QueryTask(com.vmware.xenon.services.common.QueryTask) Query(com.vmware.xenon.services.common.QueryTask.Query) Operation(com.vmware.xenon.common.Operation)

Example 92 with QueryTask

use of com.vmware.xenon.services.common.QueryTask in project photon-model by vmware.

the class TestVSphereEnumerationTask method verifyCIGapForComputeResource.

private void verifyCIGapForComputeResource() {
    Query.Builder builder = Query.Builder.create().addKindFieldClause(ComputeState.class).addCompositeFieldClause(ComputeState.FIELD_NAME_CUSTOM_PROPERTIES, CustomProperties.TYPE, VimNames.TYPE_CLUSTER_COMPUTE_RESOURCE);
    QueryTask task = QueryTask.Builder.createDirectTask().setQuery(builder.build()).build();
    withTaskResults(task, result -> {
        if (result.documentLinks.isEmpty()) {
            assertTrue("Could not enumerate Compute Cluster Resource", !result.documentLinks.isEmpty());
        } else {
            int randInt = getRandomIntWithinBounds(result.documentCount.intValue());
            ComputeState sd = Utils.fromJson(result.documents.get(result.documentLinks.get(randInt)), ComputeState.class);
            assertNotNull(sd.customProperties.get(CustomProperties.CR_VSAN_CONFIG_ID), sd.customProperties.get(CustomProperties.CR_VSAN_CONFIG_ID));
            assertNotNull(sd.customProperties.get(CustomProperties.CR_IS_VSAN_ENABLED), sd.customProperties.get(CustomProperties.CR_IS_VSAN_ENABLED));
        }
    });
}
Also used : ComputeState(com.vmware.photon.controller.model.resources.ComputeService.ComputeState) QueryTask(com.vmware.xenon.services.common.QueryTask) Query(com.vmware.xenon.services.common.QueryTask.Query)

Example 93 with QueryTask

use of com.vmware.xenon.services.common.QueryTask in project photon-model by vmware.

the class ResourceGroomerTaskServiceTest method getComputeCount.

/**
 * Query count of computes with all given endpointLinks in a set and tenantLink.
 */
public long getComputeCount(Set<String> endpointLinks, String tenantLink) {
    Query.Builder query = Query.Builder.create().addCollectionItemClause(ResourceState.FIELD_NAME_TENANT_LINKS, tenantLink);
    for (String endpointLink : endpointLinks) {
        query.addCollectionItemClause(ResourceState.FIELD_NAME_ENDPOINT_LINKS, endpointLink);
    }
    QueryTask queryTask = QueryTask.Builder.createDirectTask().setQuery(query.build()).addOption(QueryOption.COUNT).build();
    Operation postQuery = Operation.createPost(UriUtils.buildUri(this.host, ServiceUriPaths.CORE_LOCAL_QUERY_TASKS)).setBody(queryTask).setReferer(this.host.getUri());
    Operation queryResponse = this.host.waitForResponse(postQuery);
    if (queryResponse.getStatusCode() != 200) {
        return -1;
    }
    QueryTask response = queryResponse.getBody(QueryTask.class);
    return response.results.documentCount;
}
Also used : QueryTask(com.vmware.xenon.services.common.QueryTask) Query(com.vmware.xenon.services.common.QueryTask.Query) Operation(com.vmware.xenon.common.Operation)

Example 94 with QueryTask

use of com.vmware.xenon.services.common.QueryTask in project photon-model by vmware.

the class ResourceGroomerTaskServiceTest method getComputeCount.

/**
 * Query count of computes with all given endpointLinks in a set and tenantLink.
 */
public long getComputeCount(String endpointLink, String tenantLink) {
    Query.Builder query = Query.Builder.create().addFieldClause(ResourceState.FIELD_NAME_ENDPOINT_LINK, endpointLink).addCollectionItemClause(ResourceState.FIELD_NAME_TENANT_LINKS, tenantLink);
    QueryTask queryTask = QueryTask.Builder.createDirectTask().setQuery(query.build()).addOption(QueryOption.COUNT).build();
    Operation postQuery = Operation.createPost(UriUtils.buildUri(this.host, ServiceUriPaths.CORE_LOCAL_QUERY_TASKS)).setBody(queryTask).setReferer(this.host.getUri());
    Operation queryResponse = this.host.waitForResponse(postQuery);
    if (queryResponse.getStatusCode() != 200) {
        return -1;
    }
    QueryTask response = queryResponse.getBody(QueryTask.class);
    return response.results.documentCount;
}
Also used : QueryTask(com.vmware.xenon.services.common.QueryTask) Query(com.vmware.xenon.services.common.QueryTask.Query) Operation(com.vmware.xenon.common.Operation)

Example 95 with QueryTask

use of com.vmware.xenon.services.common.QueryTask in project photon-model by vmware.

the class StatsCollectionTaskServiceTest method getResourceMetrics.

/**
 * Queries all ResourceMetric documents with the prefix provided.
 * Sorts the documents by documentSelfLink.
 * Returns the first document.
 */
private ResourceMetrics getResourceMetrics(VerificationHost host, String resourceLink, String metricKey) {
    QueryTask qt = QueryTask.Builder.createDirectTask().addOption(QueryOption.TOP_RESULTS).addOption(QueryOption.INCLUDE_ALL_VERSIONS).setResultLimit(1).addOption(QueryOption.EXPAND_CONTENT).addOption(QueryOption.SORT).orderDescending(ServiceDocument.FIELD_NAME_SELF_LINK, TypeName.STRING).setQuery(Query.Builder.create().addKindFieldClause(ResourceMetrics.class).addCompositeFieldClause(ResourceMetrics.FIELD_NAME_CUSTOM_PROPERTIES, ResourceMetrics.PROPERTY_RESOURCE_LINK, resourceLink).addRangeClause(QuerySpecification.buildCompositeFieldName(ResourceMetrics.FIELD_NAME_ENTRIES, metricKey), NumericRange.createDoubleRange(Double.MIN_VALUE, Double.MAX_VALUE, true, true)).build()).build();
    host.createQueryTaskService(qt, false, true, qt, null);
    String documentLink = qt.results.documentLinks.get(0);
    ResourceMetrics resourceMetric = Utils.fromJson(qt.results.documents.get(documentLink), ResourceMetrics.class);
    return resourceMetric;
}
Also used : ResourceMetrics(com.vmware.photon.controller.model.monitoring.ResourceMetricsService.ResourceMetrics) QueryTask(com.vmware.xenon.services.common.QueryTask)

Aggregations

QueryTask (com.vmware.xenon.services.common.QueryTask)147 Query (com.vmware.xenon.services.common.QueryTask.Query)62 Operation (com.vmware.xenon.common.Operation)61 ComputeState (com.vmware.photon.controller.model.resources.ComputeService.ComputeState)39 ArrayList (java.util.ArrayList)26 QueryUtils (com.vmware.photon.controller.model.query.QueryUtils)20 List (java.util.List)20 ResourceMetrics (com.vmware.photon.controller.model.monitoring.ResourceMetricsService.ResourceMetrics)19 UriUtils (com.vmware.xenon.common.UriUtils)18 Utils (com.vmware.xenon.common.Utils)17 HashSet (java.util.HashSet)16 HashMap (java.util.HashMap)14 QueryOption (com.vmware.xenon.services.common.QueryTask.QuerySpecification.QueryOption)12 TimeUnit (java.util.concurrent.TimeUnit)12 ComputeEnumerateResourceRequest (com.vmware.photon.controller.model.adapterapi.ComputeEnumerateResourceRequest)11 AdapterUtils (com.vmware.photon.controller.model.adapters.util.AdapterUtils)11 ComputeDescription (com.vmware.photon.controller.model.resources.ComputeDescriptionService.ComputeDescription)11 ServiceTypeCluster (com.vmware.photon.controller.model.util.ClusterUtil.ServiceTypeCluster)11 URI (java.net.URI)11 Set (java.util.Set)11