Search in sources :

Example 51 with QueryTask

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

the class AzureSubscriptionsEnumerationServiceTest method executQuerySynchronously.

private QueryTask executQuerySynchronously(QueryTask task) throws Throwable {
    task.documentExpirationTimeMicros = Utils.fromNowMicrosUtc(TimeUnit.DAYS.toMicros(1));
    URI queryTaskUri = this.host.createQueryTaskService(UriUtils.buildUri(this.host.getUri(), ServiceUriPaths.CORE_QUERY_TASKS), task, false, false, task, null);
    // Wait for query task to have data
    QueryTask queryTaskResponse = null;
    Date exp = this.host.getTestExpiration();
    while (new Date().before(exp)) {
        queryTaskResponse = this.host.getServiceState(null, QueryTask.class, queryTaskUri);
        if (queryTaskResponse.results != null && queryTaskResponse.results.documentLinks != null && !queryTaskResponse.results.documentLinks.isEmpty()) {
            break;
        }
        Thread.sleep(100);
    }
    return queryTaskResponse;
}
Also used : QueryTask(com.vmware.xenon.services.common.QueryTask) URI(java.net.URI) Date(java.util.Date)

Example 52 with QueryTask

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

the class TestAzureLongRunningEnumeration method getDocumentCount.

/**
 * Returns the count of resource documents for given Resource type.
 */
private long getDocumentCount(Class<? extends ServiceDocument> T) {
    QueryTask.Query.Builder qBuilder = QueryTask.Query.Builder.create().addKindFieldClause(T);
    QueryTask queryTask = QueryTask.Builder.createDirectTask().addOption(QueryTask.QuerySpecification.QueryOption.COUNT).setQuery(qBuilder.build()).build();
    this.host.createQueryTaskService(queryTask, false, true, queryTask, null);
    return queryTask.results.documentCount;
}
Also used : QueryTask(com.vmware.xenon.services.common.QueryTask) Query(com.vmware.xenon.services.common.QueryTask.Query) PhotonModelUtils.createOriginTagQuery(com.vmware.photon.controller.model.resources.util.PhotonModelUtils.createOriginTagQuery)

Example 53 with QueryTask

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

the class TestAzureResourceDeduplication method getDocumentLinks.

private List<String> getDocumentLinks(Class resourceState, String endpointLink) {
    QueryTask.Query.Builder qBuilder = QueryTask.Query.Builder.create().addKindFieldClause(resourceState);
    if (endpointLink != null && !endpointLink.equals("")) {
        qBuilder.addFieldClause(ENDPOINT_LINKS_FIELD_CLAUSE, endpointLink);
    } else {
        qBuilder.addFieldClause(ENDPOINT_LINKS_FIELD_CLAUSE, "*", QueryTask.QueryTerm.MatchType.WILDCARD, QueryTask.Query.Occurance.MUST_NOT_OCCUR);
    }
    QueryTask queryTask = QueryTask.Builder.createDirectTask().addOption(QueryTask.QuerySpecification.QueryOption.EXPAND_CONTENT).setQuery(qBuilder.build()).build();
    this.host.createQueryTaskService(queryTask, false, true, queryTask, null);
    return queryTask.results.documentLinks;
}
Also used : QueryTask(com.vmware.xenon.services.common.QueryTask)

Example 54 with QueryTask

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

the class GCPTestUtil method queryComputeStatesWithPowerState.

/**
 * Method to query the number of local compute states with given power state.
 * @param host The test service host.
 * @param resourcePool The default resource pool.
 * @param parentCompute The default compute host.
 * @param powerState The given power state.
 * @param instanceNames The assumed names of compute states.
 */
private static void queryComputeStatesWithPowerState(VerificationHost host, ResourcePoolState resourcePool, ComputeState parentCompute, PowerState powerState, Set<String> instanceNames) {
    Query query = QueryTask.Query.Builder.create().addKindFieldClause(ComputeState.class).addFieldClause(ComputeState.FIELD_NAME_RESOURCE_POOL_LINK, resourcePool.documentSelfLink).addFieldClause(ComputeState.FIELD_NAME_PARENT_LINK, parentCompute.documentSelfLink).build();
    QueryTask q = QueryTask.Builder.createDirectTask().addOption(QueryTask.QuerySpecification.QueryOption.EXPAND_CONTENT).setQuery(query).build();
    host.sendRequest(QueryUtils.createQueryTaskOperation(host, q, ServiceTypeCluster.INVENTORY_SERVICE).setReferer(host.getUri()).setCompletion((o, e) -> {
        if (e != null) {
            host.log(Level.WARNING, String.format("Error: %s", e.getMessage()));
            return;
        }
        QueryTask queryTask = o.getBody(QueryTask.class);
        if (queryTask.results.documentCount > 0) {
            queryTask.results.documents.values().forEach(s -> {
                ComputeState computeState = Utils.fromJson(s, ComputeState.class);
                if (computeState.powerState == powerState) {
                    instanceNames.remove(computeState.name);
                }
            });
        }
    }));
}
Also used : PowerState(com.vmware.photon.controller.model.resources.ComputeService.PowerState) Date(java.util.Date) GCPUtils.privateKeyFromPkcs8(com.vmware.photon.controller.model.adapters.gcp.utils.GCPUtils.privateKeyFromPkcs8) ServiceTypeCluster(com.vmware.photon.controller.model.util.ClusterUtil.ServiceTypeCluster) QueryTask(com.vmware.xenon.services.common.QueryTask) CPU_PLATFORM(com.vmware.photon.controller.model.adapters.gcp.constants.GCPConstants.CPU_PLATFORM) VerificationHost(com.vmware.xenon.common.test.VerificationHost) DEFAULT_IMAGE_REFERENCE(com.vmware.photon.controller.model.adapters.gcp.constants.GCPConstants.DEFAULT_IMAGE_REFERENCE) ServiceDocument(com.vmware.xenon.common.ServiceDocument) Random(java.util.Random) OPERATION_STATUS_DONE(com.vmware.photon.controller.model.adapters.gcp.constants.GCPConstants.OPERATION_STATUS_DONE) ResourceGroupState(com.vmware.photon.controller.model.resources.ResourceGroupService.ResourceGroupState) ServiceAccount(com.google.api.services.compute.model.ServiceAccount) ComputeType(com.vmware.photon.controller.model.resources.ComputeDescriptionService.ComputeDescription.ComputeType) AttachedDisk(com.google.api.services.compute.model.AttachedDisk) ENVIRONMENT_NAME_GCP(com.vmware.photon.controller.model.resources.ComputeDescriptionService.ComputeDescription.ENVIRONMENT_NAME_GCP) Utils(com.vmware.xenon.common.Utils) GeneralSecurityException(java.security.GeneralSecurityException) DISK_TYPE_PERSISTENT(com.vmware.photon.controller.model.adapters.gcp.constants.GCPConstants.DISK_TYPE_PERSISTENT) ResourcePoolService(com.vmware.photon.controller.model.resources.ResourcePoolService) URI(java.net.URI) ResourceEnumerationTaskService(com.vmware.photon.controller.model.tasks.ResourceEnumerationTaskService) Instances(com.google.api.services.compute.Compute.Instances) ComputeDescription(com.vmware.photon.controller.model.resources.ComputeDescriptionService.ComputeDescription) TimeZone(java.util.TimeZone) JacksonFactory(com.google.api.client.json.jackson2.JacksonFactory) HttpTransport(com.google.api.client.http.HttpTransport) TestUtils(com.vmware.photon.controller.model.tasks.TestUtils) Set(java.util.Set) GoogleNetHttpTransport(com.google.api.client.googleapis.javanet.GoogleNetHttpTransport) NetworkInterface(com.google.api.services.compute.model.NetworkInterface) UUID(java.util.UUID) AttachedDiskInitializeParams(com.google.api.services.compute.model.AttachedDiskInitializeParams) ServiceStats(com.vmware.xenon.common.ServiceStats) DEFAULT_CPU_PLATFORM(com.vmware.photon.controller.model.adapters.gcp.constants.GCPConstants.DEFAULT_CPU_PLATFORM) ResourceGroupService(com.vmware.photon.controller.model.resources.ResourceGroupService) List(java.util.List) ProvisioningUtils.getVMCount(com.vmware.photon.controller.model.tasks.ProvisioningUtils.getVMCount) UriUtils(com.vmware.xenon.common.UriUtils) ComputeService(com.vmware.photon.controller.model.resources.ComputeService) DiskService(com.vmware.photon.controller.model.resources.DiskService) Compute(com.google.api.services.compute.Compute) GoogleCredential(com.google.api.client.googleapis.auth.oauth2.GoogleCredential) Instance(com.google.api.services.compute.model.Instance) InstanceList(com.google.api.services.compute.model.InstanceList) SimpleDateFormat(java.text.SimpleDateFormat) ResourcePoolState(com.vmware.photon.controller.model.resources.ResourcePoolService.ResourcePoolState) HashMap(java.util.HashMap) ComputeDescriptionService(com.vmware.photon.controller.model.resources.ComputeDescriptionService) DEFAULT_AUTH_TYPE(com.vmware.photon.controller.model.adapters.gcp.constants.GCPConstants.DEFAULT_AUTH_TYPE) ArrayList(java.util.ArrayList) Level(java.util.logging.Level) HashSet(java.util.HashSet) AuthCredentialsService(com.vmware.xenon.services.common.AuthCredentialsService) Query(com.vmware.xenon.services.common.QueryTask.Query) AccessConfig(com.google.api.services.compute.model.AccessConfig) GCPEnumerationAdapterService(com.vmware.photon.controller.model.adapters.gcp.enumeration.GCPEnumerationAdapterService) ComputeState(com.vmware.photon.controller.model.resources.ComputeService.ComputeState) ResourceEnumerationTaskState(com.vmware.photon.controller.model.tasks.ResourceEnumerationTaskService.ResourceEnumerationTaskState) Operation(com.vmware.xenon.common.Operation) QueryUtils(com.vmware.photon.controller.model.query.QueryUtils) IOException(java.io.IOException) ComputeScopes(com.google.api.services.compute.ComputeScopes) ProvisioningUtils.createServiceURI(com.vmware.photon.controller.model.tasks.ProvisioningUtils.createServiceURI) GCPConstants(com.vmware.photon.controller.model.adapters.gcp.constants.GCPConstants) TimeUnit(java.util.concurrent.TimeUnit) JsonFactory(com.google.api.client.json.JsonFactory) Collections(java.util.Collections) 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 55 with QueryTask

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

the class ClientUtils method getDatastoresForProfile.

public static void getDatastoresForProfile(Service service, String storagePolicyLink, String endpointLink, List<String> tenantLinks, Consumer<Throwable> failure, Consumer<ServiceDocumentQueryResult> handler) {
    QueryTask.Query.Builder builder = QueryTask.Query.Builder.create().addKindFieldClause(StorageDescriptionService.StorageDescription.class);
    builder.addCollectionItemClause(StorageDescriptionService.StorageDescription.FIELD_NAME_GROUP_LINKS, storagePolicyLink);
    QueryUtils.addEndpointLink(builder, StorageDescriptionService.StorageDescription.class, endpointLink);
    QueryUtils.addTenantLinks(builder, getTenantLinks(tenantLinks));
    QueryTask task = QueryTask.Builder.createDirectTask().setQuery(builder.build()).build();
    task.querySpec.options = EnumSet.of(QueryTask.QuerySpecification.QueryOption.EXPAND_CONTENT);
    QueryUtils.startInventoryQueryTask(service, task).whenComplete((queryTask, e) -> {
        if (e != null) {
            service.getHost().log(Level.WARNING, "Error processing task %s", task.documentSelfLink);
            failure.accept(e);
            return;
        }
        handler.accept(queryTask.results);
    });
}
Also used : QueryTask(com.vmware.xenon.services.common.QueryTask) StorageDescriptionService(com.vmware.photon.controller.model.resources.StorageDescriptionService)

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