Search in sources :

Example 11 with Query

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

the class SslTrustCertificateServiceUtils method loadCertificates.

static void loadCertificates(ServiceHost host, Consumer<SslTrustCertificateState> consumer) {
    Query.Builder query = Query.Builder.create().addKindFieldClause(SslTrustCertificateState.class);
    QueryStrategy<SslTrustCertificateState> queryLocalStates = new QueryUtils.QueryByPages<>(host, query.build(), SslTrustCertificateState.class, null, null).setMaxPageSize(QUERY_RESULT_LIMIT);
    queryLocalStates.queryDocuments(c -> {
        try {
            host.log(Level.FINE, "Processing '%s'.", c);
            SslTrustCertificateState sslTrustCert = Utils.fromJson(c, SslTrustCertificateState.class);
            host.log(Level.FINE, "Certificate with '%s', issuer '%s' and alias '%s' loaded.", sslTrustCert.commonName, sslTrustCert.issuerName, sslTrustCert.getAlias());
            consumer.accept(sslTrustCert);
        } catch (Exception e) {
            host.log(Level.WARNING, "cannot deserialize " + c);
        }
    });
}
Also used : Query(com.vmware.xenon.services.common.QueryTask.Query) QueryUtils(com.vmware.photon.controller.model.query.QueryUtils) SslTrustCertificateState(com.vmware.photon.controller.model.security.service.SslTrustCertificateService.SslTrustCertificateState)

Example 12 with Query

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

the class ResourceUtilsTest method testExpandTags.

@Test
public void testExpandTags() throws Throwable {
    TagState tag1 = new TagState();
    tag1.key = "A";
    tag1.value = "1";
    tag1 = postServiceSynchronously(TagService.FACTORY_LINK, tag1, TagState.class);
    TagState tag2 = new TagState();
    tag2.key = "A";
    tag2.value = "2";
    tag2 = postServiceSynchronously(TagService.FACTORY_LINK, tag2, TagState.class);
    TagState tag3 = new TagState();
    tag3.key = "A";
    tag3.value = "3";
    tag3 = postServiceSynchronously(TagService.FACTORY_LINK, tag3, TagState.class);
    // validate expansion on POST
    ComputeState compute = new ComputeState();
    compute.descriptionLink = "cdLink";
    compute.tagLinks = new HashSet<>();
    compute.tagLinks.add(tag1.documentSelfLink);
    compute.tagLinks.add(tag2.documentSelfLink);
    compute = postServiceSynchronously(ComputeService.FACTORY_LINK, compute, ComputeState.class);
    Collection<String> tags = compute.expandedTags.stream().map(t -> t.tag).collect(Collectors.toList());
    assertEquals(2, tags.size());
    assertTrue(tags.containsAll(Arrays.asList("A\n1", "A\n2")));
    // validate tags cannot be modified directly
    compute.expandedTags.remove(1);
    assertEquals(1, compute.expandedTags.size());
    putServiceSynchronously(compute.documentSelfLink, compute);
    compute = getServiceSynchronously(compute.documentSelfLink, ComputeState.class);
    tags = compute.expandedTags.stream().map(t -> t.tag).collect(Collectors.toList());
    assertEquals(2, tags.size());
    assertTrue(tags.containsAll(Arrays.asList("A\n1", "A\n2")));
    // validate expansion on PUT
    compute.tagLinks.remove(tag2.documentSelfLink);
    compute.tagLinks.add(tag3.documentSelfLink);
    putServiceSynchronously(compute.documentSelfLink, compute);
    compute = getServiceSynchronously(compute.documentSelfLink, ComputeState.class);
    tags = compute.expandedTags.stream().map(t -> t.tag).collect(Collectors.toList());
    assertEquals(2, tags.size());
    assertTrue(tags.containsAll(Arrays.asList("A\n1", "A\n3")));
    // validate expansion on PATCH
    ComputeState patchState = new ComputeState();
    patchState.tagLinks = new HashSet<>();
    patchState.tagLinks.add(tag2.documentSelfLink);
    compute = patchServiceSynchronously(compute.documentSelfLink, patchState, ComputeState.class);
    tags = compute.expandedTags.stream().map(t -> t.tag).collect(Collectors.toList());
    assertEquals(3, tags.size());
    assertTrue(tags.containsAll(Arrays.asList("A\n1", "A\n2", "A\n3")));
    // validate expansion through custom PATCH body
    Map<String, Collection<Object>> itemsToRemove = new HashMap<>();
    itemsToRemove.put(ResourceState.FIELD_NAME_TAG_LINKS, Arrays.asList(tag2.documentSelfLink, tag3.documentSelfLink));
    patchServiceSynchronously(compute.documentSelfLink, ServiceStateCollectionUpdateRequest.create(null, itemsToRemove));
    compute = getServiceSynchronously(compute.documentSelfLink, ComputeState.class);
    tags = compute.expandedTags.stream().map(t -> t.tag).collect(Collectors.toList());
    assertEquals(1, tags.size());
    assertTrue(tags.containsAll(Arrays.asList("A\n1")));
    // validate query (case-insensitive) (Note: only 1 tag can be found with Xenon 1.6.1)
    Query tagQuery = Query.Builder.create().addFieldClause(TagInfo.COMPOSITE_FIELD_NAME_TAG, "a*", MatchType.WILDCARD).build();
    QueryTask tagQueryTask = QueryTask.Builder.createDirectTask().setQuery(tagQuery).addOption(QueryOption.EXPAND_CONTENT).build();
    tagQueryTask = postServiceSynchronously(ServiceUriPaths.CORE_LOCAL_QUERY_TASKS, tagQueryTask, QueryTask.class);
    assertEquals(1, tagQueryTask.results.documentLinks.size());
    assertEquals(1, tagQueryTask.results.documents.size());
    assertEquals(compute.documentSelfLink, tagQueryTask.results.documentLinks.get(0));
    ComputeState foundCompute = Utils.fromJson(tagQueryTask.results.documents.values().iterator().next(), ComputeState.class);
    assertEquals(1, foundCompute.expandedTags.size());
    assertEquals("A\n1", foundCompute.expandedTags.get(0).tag);
}
Also used : Arrays(java.util.Arrays) BaseModelTest(com.vmware.photon.controller.model.helpers.BaseModelTest) QueryTask(com.vmware.xenon.services.common.QueryTask) HashMap(java.util.HashMap) MatchType(com.vmware.xenon.services.common.QueryTask.QueryTerm.MatchType) ArrayList(java.util.ArrayList) ServiceUriPaths(com.vmware.xenon.services.common.ServiceUriPaths) HashSet(java.util.HashSet) TagState(com.vmware.photon.controller.model.resources.TagService.TagState) Utils(com.vmware.xenon.common.Utils) ServiceStateCollectionUpdateRequest(com.vmware.xenon.common.ServiceStateCollectionUpdateRequest) Query(com.vmware.xenon.services.common.QueryTask.Query) ComputeState(com.vmware.photon.controller.model.resources.ComputeService.ComputeState) Map(java.util.Map) PropertyUsageOption(com.vmware.xenon.common.ServiceDocumentDescription.PropertyUsageOption) Collection(java.util.Collection) Operation(com.vmware.xenon.common.Operation) Assert.assertTrue(org.junit.Assert.assertTrue) DiskState(com.vmware.photon.controller.model.resources.DiskService.DiskState) Test(org.junit.Test) Collectors(java.util.stream.Collectors) Assert.assertNull(org.junit.Assert.assertNull) TagInfo(com.vmware.photon.controller.model.resources.ResourceState.TagInfo) UriUtils(com.vmware.xenon.common.UriUtils) QueryOption(com.vmware.xenon.services.common.QueryTask.QuerySpecification.QueryOption) ServiceDocumentDescription(com.vmware.xenon.common.ServiceDocumentDescription) Assert.assertEquals(org.junit.Assert.assertEquals) ComputeState(com.vmware.photon.controller.model.resources.ComputeService.ComputeState) QueryTask(com.vmware.xenon.services.common.QueryTask) Query(com.vmware.xenon.services.common.QueryTask.Query) HashMap(java.util.HashMap) Collection(java.util.Collection) TagState(com.vmware.photon.controller.model.resources.TagService.TagState) BaseModelTest(com.vmware.photon.controller.model.helpers.BaseModelTest) Test(org.junit.Test)

Example 13 with Query

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

the class QueryUtilsTest method doTest.

private void doTest(ComputeDescription cd, Set<String> expected, List<String> tenantLinks) {
    Query queryForReferrers = QueryUtils.queryForReferrers(cd.documentSelfLink, ComputeState.class, ComputeState.FIELD_NAME_DESCRIPTION_LINK);
    // The classes under testing: QueryByPages and QueryTop
    List<QueryTemplate<?, ComputeState>> queryStrategies = Arrays.asList(new QueryByPages<>(getHost(), queryForReferrers, ComputeState.class, tenantLinks), new QueryTop<>(getHost(), queryForReferrers, ComputeState.class, tenantLinks));
    // Test collectDocuments/queryDocuments/collectLinks/queryLinks per strategy
    for (QueryTemplate<?, ComputeState> queryStrategy : queryStrategies) {
        for (boolean isDirect : Arrays.asList(true, false)) {
            final String msg = queryStrategy.getClass().getSimpleName() + ":" + isDirect;
            {
                // Test collectDocuments, which internally also tests queryDocuments
                DeferredResult<Set<String>> documentLinksDR = queryStrategy.setDirect(isDirect).collectDocuments(mapping(cs -> cs.documentSelfLink, toSet()));
                Set<String> actual = waitToComplete(documentLinksDR);
                assertThat(msg, actual, equalTo(expected));
            }
            {
                // Test collectLinks, which internally also tests queryLinks
                DeferredResult<Set<String>> documentLinksDR = queryStrategy.setDirect(isDirect).collectLinks(toSet());
                Set<String> actual = waitToComplete(documentLinksDR);
                assertThat(msg, actual, equalTo(expected));
            }
        }
    }
}
Also used : QueryTemplate(com.vmware.photon.controller.model.query.QueryUtils.QueryTemplate) ComputeState(com.vmware.photon.controller.model.resources.ComputeService.ComputeState) Set(java.util.Set) HashSet(java.util.HashSet) Collectors.toSet(java.util.stream.Collectors.toSet) Query(com.vmware.xenon.services.common.QueryTask.Query) DeferredResult(com.vmware.xenon.common.DeferredResult)

Example 14 with Query

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

the class AzureStorageEnumerationAdapterService method disassociateDiskStates.

/*
     * Disassociate local disk states that no longer exist in Azure
     *
     * The logic works by recording a timestamp when enumeration starts. This timestamp is used to
     * lookup resources which haven't been touched as part of current enumeration cycle. The other
     * data point this method uses is the blob discovered as part of get blob call.
     *
     * A disassociate on a disk state is invoked only if it meets two criteria: - Timestamp older
     * than current enumeration cycle. - blob is not present on Azure.
     */
private void disassociateDiskStates(StorageEnumContext context, StorageEnumStages next) {
    Query.Builder qBuilder = Query.Builder.create().addKindFieldClause(DiskState.class).addFieldClause(DiskState.FIELD_NAME_COMPUTE_HOST_LINK, context.parentCompute.documentSelfLink).addRangeClause(DiskState.FIELD_NAME_UPDATE_TIME_MICROS, QueryTask.NumericRange.createLessThanRange(context.enumerationStartTimeInMicros));
    Query.Builder typeFilterQuery = Query.Builder.create(Occurance.MUST_OCCUR);
    Query blobFilter = Query.Builder.create(Occurance.SHOULD_OCCUR).addFieldClause(AZURE_STORAGE_TYPE, AZURE_STORAGE_BLOBS).build();
    QueryTask.Query diskFilter = QueryTask.Query.Builder.create(QueryTask.Query.Occurance.SHOULD_OCCUR).addFieldClause(AZURE_STORAGE_TYPE, AZURE_STORAGE_DISKS).build();
    typeFilterQuery.addClause(blobFilter);
    typeFilterQuery.addClause(diskFilter);
    qBuilder.addClause(typeFilterQuery.build());
    QueryByPages<DiskState> queryLocalStates = new QueryByPages<>(getHost(), qBuilder.build(), DiskState.class, context.parentCompute.tenantLinks, context.request.endpointLink).setMaxPageSize(getQueryResultLimit());
    queryLocalStates.setClusterType(ServiceTypeCluster.INVENTORY_SERVICE);
    List<DeferredResult<Operation>> ops = new ArrayList<>();
    queryLocalStates.queryDocuments(ds -> {
        if (context.blobIds.contains(ds.id)) {
            return;
        }
        ops.add(disassociateIfNotAttachedToCompute(context, ds));
    }).thenCompose(r -> DeferredResult.allOf(ops)).whenComplete((r, e) -> {
        logFine(() -> "Finished disassociation of disk states for Azure");
        context.subStage = next;
        handleSubStage(context);
    });
}
Also used : STORAGE_ACCOUNT_REST_API_VERSION(com.vmware.photon.controller.model.adapters.azure.constants.AzureConstants.STORAGE_ACCOUNT_REST_API_VERSION) Arrays(java.util.Arrays) QUERY_PARAM_API_VERSION(com.vmware.photon.controller.model.adapters.azure.constants.AzureConstants.QUERY_PARAM_API_VERSION) ComputeEnumerateResourceRequest(com.vmware.photon.controller.model.adapterapi.ComputeEnumerateResourceRequest) AZURE_STORAGE_BLOBS(com.vmware.photon.controller.model.adapters.azure.constants.AzureConstants.AZURE_STORAGE_BLOBS) ServiceTypeCluster(com.vmware.photon.controller.model.util.ClusterUtil.ServiceTypeCluster) StringUtils(org.apache.commons.lang3.StringUtils) ResourceGroupState(com.vmware.photon.controller.model.resources.ResourceGroupService.ResourceGroupState) Azure(com.microsoft.azure.management.Azure) Utils(com.vmware.xenon.common.Utils) Map(java.util.Map) StorageDescription(com.vmware.photon.controller.model.resources.StorageDescriptionService.StorageDescription) COMPUTE_HOST_LINK_PROP_NAME(com.vmware.photon.controller.model.ComputeProperties.COMPUTE_HOST_LINK_PROP_NAME) EnumSet(java.util.EnumSet) ListBlobItem(com.microsoft.azure.storage.blob.ListBlobItem) AZURE_STORAGE_ACCOUNT_KEY1(com.vmware.photon.controller.model.adapters.azure.constants.AzureConstants.AZURE_STORAGE_ACCOUNT_KEY1) StorageAccountListKeysResultInner(com.microsoft.azure.management.storage.implementation.StorageAccountListKeysResultInner) StatelessService(com.vmware.xenon.common.StatelessService) Set(java.util.Set) AdapterUtils.getDeletionState(com.vmware.photon.controller.model.adapters.util.AdapterUtils.getDeletionState) AZURE_STORAGE_CONTAINER_LEASE_STATUS(com.vmware.photon.controller.model.adapters.azure.constants.AzureConstants.AZURE_STORAGE_CONTAINER_LEASE_STATUS) TagService(com.vmware.photon.controller.model.resources.TagService) StorageDescriptionService(com.vmware.photon.controller.model.resources.StorageDescriptionService) CompletionHandler(com.vmware.xenon.common.Operation.CompletionHandler) DeferredResult(com.vmware.xenon.common.DeferredResult) UriUtils(com.vmware.xenon.common.UriUtils) ComputeService(com.vmware.photon.controller.model.resources.ComputeService) AZURE_STORAGE_CONTAINER_LEASE_STATE(com.vmware.photon.controller.model.adapters.azure.constants.AzureConstants.AZURE_STORAGE_CONTAINER_LEASE_STATE) ComputeProperties(com.vmware.photon.controller.model.ComputeProperties) ResourceGroupStateType(com.vmware.photon.controller.model.adapters.azure.constants.AzureConstants.ResourceGroupStateType) PhotonModelUtils(com.vmware.photon.controller.model.resources.util.PhotonModelUtils) ArrayList(java.util.ArrayList) StorageException(com.microsoft.azure.storage.StorageException) TagState(com.vmware.photon.controller.model.resources.TagService.TagState) Query(com.vmware.xenon.services.common.QueryTask.Query) AUTH_HEADER_BEARER_PREFIX(com.vmware.photon.controller.model.adapters.azure.constants.AzureConstants.AUTH_HEADER_BEARER_PREFIX) UriPaths(com.vmware.photon.controller.model.UriPaths) EnumerationStages(com.vmware.photon.controller.model.adapters.util.enums.EnumerationStages) CloudBlobContainer(com.microsoft.azure.storage.blob.CloudBlobContainer) StorageErrorCode(com.microsoft.azure.storage.StorageErrorCode) EnumUtils(org.apache.commons.lang3.EnumUtils) AZURE_STORAGE_CONTAINER_LEASE_LAST_MODIFIED(com.vmware.photon.controller.model.adapters.azure.constants.AzureConstants.AZURE_STORAGE_CONTAINER_LEASE_LAST_MODIFIED) AdapterUtils(com.vmware.photon.controller.model.adapters.util.AdapterUtils) LIST_STORAGE_ACCOUNTS(com.vmware.photon.controller.model.adapters.azure.constants.AzureConstants.LIST_STORAGE_ACCOUNTS) ResourceState(com.vmware.photon.controller.model.resources.ResourceState) QueryUtils(com.vmware.photon.controller.model.query.QueryUtils) ResultSegment(com.microsoft.azure.storage.ResultSegment) EMPTY_STR(com.vmware.photon.controller.model.constants.PhotonModelConstants.EMPTY_STR) ContainerListingDetails(com.microsoft.azure.storage.blob.ContainerListingDetails) UnknownHostException(java.net.UnknownHostException) QueryTop(com.vmware.photon.controller.model.query.QueryUtils.QueryTop) ComputeStateWithDescription(com.vmware.photon.controller.model.resources.ComputeService.ComputeStateWithDescription) ComputeEnumerateAdapterRequest(com.vmware.photon.controller.model.adapters.util.ComputeEnumerateAdapterRequest) QuerySpecification(com.vmware.xenon.services.common.QueryTask.QuerySpecification) PhotonModelUriUtils.createInventoryUri(com.vmware.photon.controller.model.util.PhotonModelUriUtils.createInventoryUri) AuthCredentialsServiceState(com.vmware.xenon.services.common.AuthCredentialsService.AuthCredentialsServiceState) ResultContinuation(com.microsoft.azure.storage.ResultContinuation) URISyntaxException(java.net.URISyntaxException) QueryTask(com.vmware.xenon.services.common.QueryTask) AzureUriPaths(com.vmware.photon.controller.model.adapters.azure.AzureUriPaths) DEFAULT_DISK_TYPE(com.vmware.photon.controller.model.adapters.azure.constants.AzureConstants.DEFAULT_DISK_TYPE) AzureSdkClients(com.vmware.photon.controller.model.adapters.azure.utils.AzureSdkClients) CUSTOM_PROP_ENDPOINT_LINK(com.vmware.photon.controller.model.constants.PhotonModelConstants.CUSTOM_PROP_ENDPOINT_LINK) URI(java.net.URI) TagsUtil.newTagState(com.vmware.photon.controller.model.adapters.util.TagsUtil.newTagState) AzureConstants(com.vmware.photon.controller.model.adapters.azure.constants.AzureConstants) AzureConstants.getQueryResultLimit(com.vmware.photon.controller.model.adapters.azure.constants.AzureConstants.getQueryResultLimit) Collection(java.util.Collection) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) AZURE_STORAGE_CONTAINERS(com.vmware.photon.controller.model.adapters.azure.constants.AzureConstants.AZURE_STORAGE_CONTAINERS) DiskState(com.vmware.photon.controller.model.resources.DiskService.DiskState) Occurance(com.vmware.xenon.services.common.QueryTask.Query.Occurance) UUID(java.util.UUID) CloudStorageAccount(com.microsoft.azure.storage.CloudStorageAccount) Collectors(java.util.stream.Collectors) ResourceGroupService(com.vmware.photon.controller.model.resources.ResourceGroupService) List(java.util.List) AzureUtils(com.vmware.photon.controller.model.adapters.azure.utils.AzureUtils) AzureUtils.getResourceGroupName(com.vmware.photon.controller.model.adapters.azure.utils.AzureUtils.getResourceGroupName) TAG_KEY_TYPE(com.vmware.photon.controller.model.constants.PhotonModelConstants.TAG_KEY_TYPE) QueryOption(com.vmware.xenon.services.common.QueryTask.QuerySpecification.QueryOption) DiskService(com.vmware.photon.controller.model.resources.DiskService) Default(com.vmware.photon.controller.model.adapters.azure.utils.AzureDeferredResultServiceCallback.Default) QueryByPages(com.vmware.photon.controller.model.query.QueryUtils.QueryByPages) HashMap(java.util.HashMap) Level(java.util.logging.Level) HashSet(java.util.HashSet) AZURE_STORAGE_TYPE(com.vmware.photon.controller.model.adapters.azure.constants.AzureConstants.AZURE_STORAGE_TYPE) AuthCredentialsService(com.vmware.xenon.services.common.AuthCredentialsService) EnumerationAction(com.vmware.photon.controller.model.adapterapi.EnumerationAction) AzureResourceType(com.vmware.photon.controller.model.adapters.azure.constants.AzureConstants.AzureResourceType) STORAGE_CONNECTION_STRING(com.vmware.photon.controller.model.adapters.azure.constants.AzureConstants.STORAGE_CONNECTION_STRING) ExecutorService(java.util.concurrent.ExecutorService) StorageAccountResultList(com.vmware.photon.controller.model.adapters.azure.model.storage.StorageAccountResultList) CloudBlobClient(com.microsoft.azure.storage.blob.CloudBlobClient) AdapterUriUtil(com.vmware.photon.controller.model.adapters.util.AdapterUriUtil) Operation(com.vmware.xenon.common.Operation) AZURE_STORAGE_DISKS(com.vmware.photon.controller.model.adapters.azure.constants.AzureConstants.AZURE_STORAGE_DISKS) StorageAccountsInner(com.microsoft.azure.management.storage.implementation.StorageAccountsInner) TimeUnit(java.util.concurrent.TimeUnit) Consumer(java.util.function.Consumer) StorageCredentials(com.microsoft.azure.storage.StorageCredentials) AzureUtils.canonizeId(com.vmware.photon.controller.model.adapters.azure.utils.AzureUtils.canonizeId) BlobListingDetails(com.microsoft.azure.storage.blob.BlobListingDetails) AzureDeferredResultServiceCallback(com.vmware.photon.controller.model.adapters.azure.utils.AzureDeferredResultServiceCallback) StorageAccountInner(com.microsoft.azure.management.storage.implementation.StorageAccountInner) StorageAccount(com.vmware.photon.controller.model.adapters.azure.model.storage.StorageAccount) OperationJoin(com.vmware.xenon.common.OperationJoin) CloudBlob(com.microsoft.azure.storage.blob.CloudBlob) QueryTask(com.vmware.xenon.services.common.QueryTask) Query(com.vmware.xenon.services.common.QueryTask.Query) Query(com.vmware.xenon.services.common.QueryTask.Query) DiskState(com.vmware.photon.controller.model.resources.DiskService.DiskState) ArrayList(java.util.ArrayList) DeferredResult(com.vmware.xenon.common.DeferredResult)

Example 15 with Query

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

the class TagGroomerTaskService method getDiscoveredNotDeletedTagStates.

/**
 * Collect all tag states with origins ["DISCOVERED"] that have not been soft deleted, and
 * perform soft deletion of stale ones by page.
 *
 * If the tag has multiple origins, do not delete the tag.
 */
private void getDiscoveredNotDeletedTagStates(TagDeletionRequest task, SubStage next) {
    Query query = Query.Builder.create().addKindFieldClause(TagState.class).build();
    Map<String, Query.Occurance> origin = new HashMap<>();
    origin.put(DISCOVERED.toString(), Query.Occurance.MUST_OCCUR);
    origin.put(SYSTEM.toString(), Query.Occurance.MUST_NOT_OCCUR);
    origin.put(USER_DEFINED.toString(), Query.Occurance.MUST_NOT_OCCUR);
    Query externalQuery = createOriginTagQuery(Boolean.TRUE, origin);
    query.addBooleanClause(externalQuery);
    query.addBooleanClause(new Query().setTermPropertyName(TagState.FIELD_NAME_DELETED).setTermMatchValue(Boolean.FALSE.toString()));
    QueryTask queryTask = QueryTask.Builder.createDirectTask().setQuery(query).addOption(QueryOption.EXPAND_CONTENT).setResultLimit(QUERY_RESULT_LIMIT).build();
    QueryUtils.startInventoryQueryTask(this, queryTask).whenComplete((response, e) -> {
        if (e != null) {
            task.failureMessage = e.getMessage();
            task.subStage = SubStage.FAILED;
            sendSelfPatch(task);
            return;
        }
        if (response.results != null && response.results.nextPageLink != null) {
            task.tagsNextPageLink = response.results.nextPageLink;
            task.subStage = next;
        } else {
            task.subStage = SubStage.FINISHED;
        }
        sendSelfPatch(task);
    });
}
Also used : QueryTask(com.vmware.xenon.services.common.QueryTask) PhotonModelUtils.createOriginTagQuery(com.vmware.photon.controller.model.resources.util.PhotonModelUtils.createOriginTagQuery) Query(com.vmware.xenon.services.common.QueryTask.Query) HashMap(java.util.HashMap) TagState(com.vmware.photon.controller.model.resources.TagService.TagState)

Aggregations

Query (com.vmware.xenon.services.common.QueryTask.Query)81 QueryTask (com.vmware.xenon.services.common.QueryTask)50 Operation (com.vmware.xenon.common.Operation)39 ArrayList (java.util.ArrayList)29 HashMap (java.util.HashMap)26 ComputeState (com.vmware.photon.controller.model.resources.ComputeService.ComputeState)25 Utils (com.vmware.xenon.common.Utils)22 List (java.util.List)21 Map (java.util.Map)21 QueryUtils (com.vmware.photon.controller.model.query.QueryUtils)20 UriUtils (com.vmware.xenon.common.UriUtils)20 HashSet (java.util.HashSet)20 QueryByPages (com.vmware.photon.controller.model.query.QueryUtils.QueryByPages)19 ServiceTypeCluster (com.vmware.photon.controller.model.util.ClusterUtil.ServiceTypeCluster)18 Set (java.util.Set)18 URI (java.net.URI)17 OperationJoin (com.vmware.xenon.common.OperationJoin)16 StatelessService (com.vmware.xenon.common.StatelessService)16 Collections (java.util.Collections)15 Collectors (java.util.stream.Collectors)15