Search in sources :

Example 16 with QueryByPages

use of com.vmware.photon.controller.model.query.QueryUtils.QueryByPages in project photon-model by vmware.

the class TestAzureEnumerationTask method getSubnetStates.

/**
 * Get all SubnetStates within passed NetworkState. In other words, get all subnet states that
 * refer the network state passed.
 */
// TODO : Duplicated from AWS TestUtils. Please advice where to put common test utils
public static List<SubnetState> getSubnetStates(VerificationHost host, NetworkState networkState) {
    Query queryForReferrers = QueryUtils.queryForReferrers(networkState.documentSelfLink, SubnetState.class, SubnetState.FIELD_NAME_NETWORK_LINK);
    QueryByPages<SubnetState> querySubnetStatesReferrers = new QueryByPages<>(host, queryForReferrers, SubnetState.class, networkState.tenantLinks, networkState.endpointLink);
    DeferredResult<List<SubnetState>> subnetDR = querySubnetStatesReferrers.collectDocuments(Collectors.toList());
    return waitToComplete(subnetDR);
}
Also used : QueryByPages(com.vmware.photon.controller.model.query.QueryUtils.QueryByPages) Query(com.vmware.xenon.services.common.QueryTask.Query) PhotonModelUtils.createOriginTagQuery(com.vmware.photon.controller.model.resources.util.PhotonModelUtils.createOriginTagQuery) ArrayList(java.util.ArrayList) List(java.util.List) SubnetState(com.vmware.photon.controller.model.resources.SubnetService.SubnetState)

Example 17 with QueryByPages

use of com.vmware.photon.controller.model.query.QueryUtils.QueryByPages in project photon-model by vmware.

the class EndpointEnumerationProcess method disassociateLocalResourceStates.

/**
 * Disassociate stale local resource states. The logic works by recording a timestamp when
 * enumeration starts. This timestamp is used to lookup resources which have not been touched as
 * part of current enumeration cycle. Resources not associated with any endpointLink will be
 * removed by the groomer task.
 * <p>
 * Here is the list of criteria used to locate the stale local resources states:
 * <ul>
 * <li>Add local documents' kind:
 * {@code qBuilder.addKindFieldClause(context.localStateClass)}</li>
 * <li>Add time stamp older than current enumeration cycle:
 * {@code qBuilder.addRangeClause(ServiceDocument.FIELD_NAME_UPDATE_TIME_MICROS, createLessThanRange(context.enumStartTimeInMicros))}</li>
 * <li>Add {@code tenantLinks} and {@code endpointLink} criteria as defined by
 * {@code QueryTemplate}</li>
 * <li>Add descendant specific criteria as defined by
 * {@link #customizeLocalStatesQuery(com.vmware.xenon.services.common.QueryTask.Query.Builder)}</li>
 * </ul>
 */
protected DeferredResult<T> disassociateLocalResourceStates(T context) {
    final String msg = "Disassociate %ss that no longer exist in the endpoint: %s";
    context.service.logFine(() -> String.format(msg, context.localStateClass.getSimpleName(), "STARTING"));
    Query.Builder qBuilder = Query.Builder.create().addKindFieldClause(context.localStateClass).addRangeClause(ServiceDocument.FIELD_NAME_UPDATE_TIME_MICROS, createLessThanRange(context.enumStartTimeInMicros));
    if (getEndpointRegion() != null) {
        // Limit documents within end-point region
        qBuilder.addFieldClause(ResourceState.FIELD_NAME_REGION_ID, getEndpointRegion());
    }
    if (!this.enumExternalResourcesIds.isEmpty() && this.enumExternalResourcesIds.size() <= MAX_RESOURCES_TO_QUERY_ON_DELETE) {
        // do not load resources from enumExternalResourcesIds
        qBuilder.addInClause(ResourceState.FIELD_NAME_ID, this.enumExternalResourcesIds, Occurance.MUST_NOT_OCCUR);
    }
    // Delegate to descendants to any doc specific criteria
    customizeLocalStatesQuery(qBuilder);
    QueryByPages<LOCAL_STATE> queryLocalStates = new QueryByPages<>(context.service.getHost(), qBuilder.build(), context.localStateClass, isApplyInfraFields() ? context.endpointState.tenantLinks : null, isApplyEndpointLink() ? context.endpointState.documentSelfLink : null, null).setQueryTaskTenantLinks(context.endpointState.tenantLinks);
    queryLocalStates.setClusterType(ServiceTypeCluster.INVENTORY_SERVICE);
    List<DeferredResult<Operation>> disassociateDRs = new ArrayList<>();
    // Delete stale resources.
    return queryLocalStates.queryDocuments(localState -> {
        if (!shouldDelete(localState)) {
            return;
        }
        // Deleting the localResourceState is done by disassociating the
        // endpointLink from the localResourceState. If the localResourceState
        // isn't associated with any other endpointLink, it should be eventually
        // deleted by the groomer task
        Operation disassociateOp = PhotonModelUtils.createRemoveEndpointLinksOperation(context.service, context.endpointState.documentSelfLink, localState);
        if (disassociateOp == null) {
            return;
        }
        // NOTE: The original Op is set with completion that must be executed.
        // Since sendWithDeferredResult is used we must manually call it, otherwise it's
        // just ignored.
        CompletionHandler disassociateOpCompletion = disassociateOp.getCompletion();
        DeferredResult<Operation> disassociateDR = context.service.sendWithDeferredResult(disassociateOp).whenComplete(disassociateOpCompletion::handle).whenComplete((o, e) -> {
            final String message = "Disassociate stale %s state";
            if (e != null) {
                context.service.logWarning(message + ": FAILED with %s", localState.documentSelfLink, Utils.toString(e));
            } else {
                context.service.log(Level.FINEST, message + ": SUCCESS", localState.documentSelfLink);
            }
        });
        disassociateDRs.add(disassociateDR);
    }).thenCompose(ignore -> DeferredResult.allOf(disassociateDRs)).thenApply(ignore -> context);
}
Also used : AuthCredentialsServiceState(com.vmware.xenon.services.common.AuthCredentialsService.AuthCredentialsServiceState) QueryByPages(com.vmware.photon.controller.model.query.QueryUtils.QueryByPages) ServiceTypeCluster(com.vmware.photon.controller.model.util.ClusterUtil.ServiceTypeCluster) Collectors.counting(java.util.stream.Collectors.counting) Collectors.groupingBy(java.util.stream.Collectors.groupingBy) ServiceDocument(com.vmware.xenon.common.ServiceDocument) HashMap(java.util.HashMap) PhotonModelUtils(com.vmware.photon.controller.model.resources.util.PhotonModelUtils) Function(java.util.function.Function) TagsUtil(com.vmware.photon.controller.model.adapters.util.TagsUtil) ArrayList(java.util.ArrayList) Level(java.util.logging.Level) HashSet(java.util.HashSet) LinkedHashMap(java.util.LinkedHashMap) Utils(com.vmware.xenon.common.Utils) PhotonModelUtils.updateEndpointLinks(com.vmware.photon.controller.model.resources.util.PhotonModelUtils.updateEndpointLinks) EndpointConfigRequest(com.vmware.photon.controller.model.adapterapi.EndpointConfigRequest) Query(com.vmware.xenon.services.common.QueryTask.Query) UriPaths(com.vmware.photon.controller.model.UriPaths) Map(java.util.Map) EndpointType(com.vmware.photon.controller.model.constants.PhotonModelConstants.EndpointType) URI(java.net.URI) AssertUtil(com.vmware.photon.controller.model.util.AssertUtil) EndpointState(com.vmware.photon.controller.model.resources.EndpointService.EndpointState) ResourceState(com.vmware.photon.controller.model.resources.ResourceState) StatelessService(com.vmware.xenon.common.StatelessService) Operation(com.vmware.xenon.common.Operation) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Set(java.util.Set) Occurance(com.vmware.xenon.services.common.QueryTask.Query.Occurance) AdapterUtils.getDeletionState(com.vmware.photon.controller.model.adapters.util.AdapterUtils.getDeletionState) NumericRange.createLessThanRange(com.vmware.xenon.services.common.QueryTask.NumericRange.createLessThanRange) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) List(java.util.List) PhotonModelUtils.setEndpointLink(com.vmware.photon.controller.model.resources.util.PhotonModelUtils.setEndpointLink) CompletionHandler(com.vmware.xenon.common.Operation.CompletionHandler) DeferredResult(com.vmware.xenon.common.DeferredResult) PhotonModelUriUtils.createInventoryUri(com.vmware.photon.controller.model.util.PhotonModelUriUtils.createInventoryUri) Query(com.vmware.xenon.services.common.QueryTask.Query) ArrayList(java.util.ArrayList) Operation(com.vmware.xenon.common.Operation) CompletionHandler(com.vmware.xenon.common.Operation.CompletionHandler) DeferredResult(com.vmware.xenon.common.DeferredResult)

Example 18 with QueryByPages

use of com.vmware.photon.controller.model.query.QueryUtils.QueryByPages in project photon-model by vmware.

the class TestAWSImageEnumerationTask method afterTest.

@After
public final void afterTest() throws Throwable {
    QueryByPages<ImageState> queryAll = new QueryByPages<ImageState>(getHost(), Builder.create().addKindFieldClause(ImageState.class).build(), ImageState.class, null);
    queryAll.setMaxPageSize(QueryUtils.DEFAULT_MAX_RESULT_LIMIT);
    AtomicInteger counter = new AtomicInteger(0);
    waitToComplete(queryAll.queryLinks(imageLink -> {
        try {
            deleteServiceSynchronously(imageLink);
            counter.incrementAndGet();
        } catch (Throwable e) {
            throw new RuntimeException(e);
        }
    }));
    getHost().log(Level.INFO, "[" + this.currentTestName.getMethodName() + "] Deleted " + counter + " ImageStates");
}
Also used : AuthCredentialsServiceState(com.vmware.xenon.services.common.AuthCredentialsService.AuthCredentialsServiceState) Arrays(java.util.Arrays) BaseModelTest(com.vmware.photon.controller.model.helpers.BaseModelTest) EndpointAllocationTaskService(com.vmware.photon.controller.model.tasks.EndpointAllocationTaskService) CommandLineArgumentParser(com.vmware.xenon.common.CommandLineArgumentParser) Utils(com.vmware.xenon.common.Utils) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) BlockDeviceMapping(com.amazonaws.services.ec2.model.BlockDeviceMapping) DescribeImagesRequest(com.amazonaws.services.ec2.model.DescribeImagesRequest) EndpointService(com.vmware.photon.controller.model.resources.EndpointService) After(org.junit.After) TestUtils.getExecutor(com.vmware.photon.controller.model.adapters.awsadapter.TestUtils.getExecutor) ProvisioningUtils.queryDocumentsAndAssertExpectedCount(com.vmware.photon.controller.model.tasks.ProvisioningUtils.queryDocumentsAndAssertExpectedCount) ImageService(com.vmware.photon.controller.model.resources.ImageService) ServiceDocumentQueryResult(com.vmware.xenon.common.ServiceDocumentQueryResult) EnumSet(java.util.EnumSet) EndpointState(com.vmware.photon.controller.model.resources.EndpointService.EndpointState) EndpointAllocationTaskState(com.vmware.photon.controller.model.tasks.EndpointAllocationTaskService.EndpointAllocationTaskState) TestUtils(com.vmware.photon.controller.model.tasks.TestUtils) Description(org.junit.runner.Description) Collectors(java.util.stream.Collectors) List(java.util.List) EbsBlockDevice(com.amazonaws.services.ec2.model.EbsBlockDevice) UriUtils(com.vmware.xenon.common.UriUtils) PhotonModelUtils.waitToComplete(com.vmware.photon.controller.model.resources.util.PhotonModelUtils.waitToComplete) TaskState(com.vmware.xenon.common.TaskState) TaskOption(com.vmware.photon.controller.model.tasks.TaskOption) Builder(com.vmware.xenon.services.common.QueryTask.Query.Builder) PRIVATE_KEY_KEY(com.vmware.photon.controller.model.adapterapi.EndpointConfigRequest.PRIVATE_KEY_KEY) QueryByPages(com.vmware.photon.controller.model.query.QueryUtils.QueryByPages) Stopwatch(org.junit.rules.Stopwatch) HashMap(java.util.HashMap) PRIVATE_KEYID_KEY(com.vmware.photon.controller.model.adapterapi.EndpointConfigRequest.PRIVATE_KEYID_KEY) Level(java.util.logging.Level) HashSet(java.util.HashSet) TagState(com.vmware.photon.controller.model.resources.TagService.TagState) TestName(org.junit.rules.TestName) Image(com.amazonaws.services.ec2.model.Image) Filter(com.amazonaws.services.ec2.model.Filter) PaginatingIterator(com.vmware.photon.controller.model.adapters.awsadapter.enumeration.AWSImageEnumerationAdapterService.PaginatingIterator) EndpointType(com.vmware.photon.controller.model.constants.PhotonModelConstants.EndpointType) DescribeImagesResult(com.amazonaws.services.ec2.model.DescribeImagesResult) Assume(org.junit.Assume) Before(org.junit.Before) PhotonModelTaskServices(com.vmware.photon.controller.model.tasks.PhotonModelTaskServices) QueryUtils(com.vmware.photon.controller.model.query.QueryUtils) ImageEnumerationTaskService(com.vmware.photon.controller.model.tasks.ImageEnumerationTaskService) Test(org.junit.Test) QueryTop(com.vmware.photon.controller.model.query.QueryUtils.QueryTop) TimeUnit(java.util.concurrent.TimeUnit) Rule(org.junit.Rule) Ignore(org.junit.Ignore) PhotonModelAdaptersRegistryAdapters(com.vmware.photon.controller.model.adapters.registry.PhotonModelAdaptersRegistryAdapters) ImageEnumerationTaskState(com.vmware.photon.controller.model.tasks.ImageEnumerationTaskService.ImageEnumerationTaskState) ImageState(com.vmware.photon.controller.model.resources.ImageService.ImageState) Assert(org.junit.Assert) AmazonEC2AsyncClient(com.amazonaws.services.ec2.AmazonEC2AsyncClient) QueryByPages(com.vmware.photon.controller.model.query.QueryUtils.QueryByPages) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ImageState(com.vmware.photon.controller.model.resources.ImageService.ImageState) After(org.junit.After)

Example 19 with QueryByPages

use of com.vmware.photon.controller.model.query.QueryUtils.QueryByPages in project photon-model by vmware.

the class AzureStorageEnumerationAdapterService method getLocalStorageAccountDescriptions.

/**
 * Query all storage descriptions for the cluster filtered by the received set of storage
 * account Ids
 */
private void getLocalStorageAccountDescriptions(StorageEnumContext context, StorageEnumStages next) {
    if (context.storageAccountsToUpdateCreate.isEmpty()) {
        context.subStage = StorageEnumStages.CREATE_STORAGE_DESCRIPTIONS;
        handleSubStage(context);
        return;
    }
    context.storageDescriptions.clear();
    Query.Builder qBuilder = Query.Builder.create().addKindFieldClause(StorageDescription.class);
    Query.Builder instanceIdFilterParentQuery = Query.Builder.create(Occurance.MUST_OCCUR);
    for (Map.Entry<String, StorageAccount> account : context.storageAccountsToUpdateCreate.entrySet()) {
        Query instanceIdFilter = Query.Builder.create(Occurance.SHOULD_OCCUR).addFieldClause(StorageDescription.FIELD_NAME_ID, canonizeId(account.getValue().id)).build();
        instanceIdFilterParentQuery.addClause(instanceIdFilter);
    }
    qBuilder.addClause(instanceIdFilterParentQuery.build());
    QueryByPages<StorageDescription> queryLocalStates = new QueryByPages<>(getHost(), qBuilder.build(), StorageDescription.class, context.parentCompute.tenantLinks, null, /* endpointLink */
    context.parentCompute.documentSelfLink).setMaxPageSize(QueryUtils.MAX_RESULT_LIMIT).setClusterType(ServiceTypeCluster.INVENTORY_SERVICE);
    queryLocalStates.collectDocuments(Collectors.toList()).whenComplete((sds, ex) -> {
        if (ex != null) {
            handleError(context, ex);
            return;
        }
        logFine(() -> String.format("Found %d matching storage descriptions for Azure" + " storage accounts", sds.size()));
        List<DeferredResult<AuthCredentialsServiceState>> results = sds.stream().map(sd -> {
            context.storageDescriptions.put(sd.id, sd);
            // populate connectionStrings
            if (!context.storageConnectionStrings.containsKey(sd.id)) {
                return loadStorageAuth(context, sd);
            } else {
                return DeferredResult.<AuthCredentialsServiceState>completed(null);
            }
        }).collect(Collectors.toList());
        DeferredResult.allOf(results).whenComplete((creds, e) -> {
            if (e != null) {
                logWarning(() -> String.format("Failed to get storage description" + " credentials: %s", e.getMessage()));
            }
            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) QueryByPages(com.vmware.photon.controller.model.query.QueryUtils.QueryByPages) Query(com.vmware.xenon.services.common.QueryTask.Query) CloudStorageAccount(com.microsoft.azure.storage.CloudStorageAccount) StorageAccount(com.vmware.photon.controller.model.adapters.azure.model.storage.StorageAccount) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) StorageDescription(com.vmware.photon.controller.model.resources.StorageDescriptionService.StorageDescription) DeferredResult(com.vmware.xenon.common.DeferredResult)

Example 20 with QueryByPages

use of com.vmware.photon.controller.model.query.QueryUtils.QueryByPages in project photon-model by vmware.

the class TestAzureImageEnumerationTask method testPublicImageEnumeration_all.

@Test
public void testPublicImageEnumeration_all() throws Throwable {
    Assume.assumeFalse(this.isMock);
    Assume.assumeTrue(this.enableLongRunning);
    // This test takes about 30 mins!
    getHost().setTimeoutSeconds((int) TimeUnit.MINUTES.toSeconds(40));
    ImageEnumerationTaskState task = kickOffImageEnumeration(this.endpointState, PUBLIC, null);
    // Validate at least 4.5K image states are created
    QueryByPages<ImageState> queryAll = new QueryByPages<ImageState>(getHost(), Builder.create().addKindFieldClause(ImageState.class).build(), ImageState.class, task.tenantLinks);
    queryAll.setMaxPageSize(QueryUtils.DEFAULT_MAX_RESULT_LIMIT);
    Long imagesCount = PhotonModelUtils.waitToComplete(queryAll.collectLinks(Collectors.counting()));
    Assert.assertTrue("Expected at least " + 4_500 + " images, but found only " + imagesCount, imagesCount > 4_500);
}
Also used : QueryByPages(com.vmware.photon.controller.model.query.QueryUtils.QueryByPages) ImageEnumerationTaskState(com.vmware.photon.controller.model.tasks.ImageEnumerationTaskService.ImageEnumerationTaskState) ImageState(com.vmware.photon.controller.model.resources.ImageService.ImageState) AzureBaseTest(com.vmware.photon.controller.model.adapters.azure.base.AzureBaseTest) Test(org.junit.Test)

Aggregations

QueryByPages (com.vmware.photon.controller.model.query.QueryUtils.QueryByPages)29 Query (com.vmware.xenon.services.common.QueryTask.Query)22 List (java.util.List)18 ArrayList (java.util.ArrayList)17 HashSet (java.util.HashSet)17 Collectors (java.util.stream.Collectors)16 Utils (com.vmware.xenon.common.Utils)15 HashMap (java.util.HashMap)15 Map (java.util.Map)15 QueryUtils (com.vmware.photon.controller.model.query.QueryUtils)14 ServiceTypeCluster (com.vmware.photon.controller.model.util.ClusterUtil.ServiceTypeCluster)14 DeferredResult (com.vmware.xenon.common.DeferredResult)14 Set (java.util.Set)14 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)14 PhotonModelUtils (com.vmware.photon.controller.model.resources.util.PhotonModelUtils)13 Operation (com.vmware.xenon.common.Operation)13 AzureConstants (com.vmware.photon.controller.model.adapters.azure.constants.AzureConstants)12 ResourceState (com.vmware.photon.controller.model.resources.ResourceState)12 TagState (com.vmware.photon.controller.model.resources.TagService.TagState)12 StringUtils (org.apache.commons.lang3.StringUtils)12