use of com.vmware.xenon.services.common.QueryTask.Query in project photon-model by vmware.
the class AzureSubscriptionsEnumerationService method fetchExistingResources.
private void fetchExistingResources(AzureSubscriptionsEnumerationContext enumerationContext, AzureCostComputeEnumerationStages nextStage) {
Query azureComputesQuery = createQueryForAzureSubscriptionComputes(enumerationContext);
QueryByPages<ComputeState> querySubscriptionsComputes = new QueryByPages<>(getHost(), azureComputesQuery, ComputeState.class, enumerationContext.parent.tenantLinks);
querySubscriptionsComputes.setClusterType(ServiceTypeCluster.INVENTORY_SERVICE);
// Use max page size cause we collect ComputeStates
querySubscriptionsComputes.setMaxPageSize(QueryUtils.MAX_RESULT_LIMIT);
querySubscriptionsComputes.queryDocuments(computeState -> {
if (computeState.customProperties != null && computeState.customProperties.containsKey(AzureConstants.AZURE_SUBSCRIPTION_ID_KEY)) {
String subscriptionUuid = computeState.customProperties.get(AzureConstants.AZURE_SUBSCRIPTION_ID_KEY);
enumerationContext.idToSubscription.remove(subscriptionUuid);
}
}).whenComplete((aVoid, t) -> {
if (t != null) {
getFailureConsumer(enumerationContext).accept(t);
return;
}
enumerationContext.stage = nextStage;
handleAzureSubscriptionsEnumerationRequest(enumerationContext);
});
}
use of com.vmware.xenon.services.common.QueryTask.Query in project photon-model by vmware.
the class AzureNetworkEnumerationAdapterService method querySubnetStates.
/**
* Query subnet states stored in the local document store based on the retrieved azure subnets.
*/
private void querySubnetStates(NetworkEnumContext context, NetworkEnumStages next) {
if (context.subnets == null || context.subnets.isEmpty()) {
handleSubStage(context, next);
return;
}
logFine(() -> "Query Subnet States from local document store.");
Builder qBuilder = Query.Builder.create().addKindFieldClause(SubnetState.class).addInClause(SubnetState.FIELD_NAME_ID, context.subnets.keySet());
QueryByPages<SubnetState> queryLocalStates = new QueryByPages<>(getHost(), qBuilder.build(), SubnetState.class, context.parentCompute.tenantLinks, null, /* endpoint */
context.parentCompute.documentSelfLink).setMaxPageSize(QueryUtils.MAX_RESULT_LIMIT).setClusterType(ServiceTypeCluster.INVENTORY_SERVICE);
queryLocalStates.queryDocuments(subnet -> context.subnetStates.put(subnet.id, subnet.documentSelfLink)).whenComplete(thenHandleSubStage(context, next));
}
use of com.vmware.xenon.services.common.QueryTask.Query in project photon-model by vmware.
the class AzureNetworkEnumerationAdapterService method queryResourceGroupStates.
/**
* Query resource group states stored in the local document store based on the retrieved azure
* virtual networks.
*/
private void queryResourceGroupStates(NetworkEnumContext context, NetworkEnumStages next) {
List<String> resourceGroupIds = context.virtualNetworks.values().stream().map(vNet -> AzureUtils.getResourceGroupId(vNet.id)).collect(Collectors.toList());
Query.Builder qBuilder = Builder.create().addKindFieldClause(ResourceGroupState.class).addInClause(ResourceGroupState.FIELD_NAME_ID, resourceGroupIds).addCompositeFieldClause(ResourceGroupState.FIELD_NAME_CUSTOM_PROPERTIES, ComputeProperties.RESOURCE_TYPE_KEY, ResourceGroupStateType.AzureResourceGroup.name());
QueryByPages<ResourceGroupState> queryLocalStates = new QueryByPages<>(getHost(), qBuilder.build(), ResourceGroupState.class, context.parentCompute.tenantLinks, null, /* endpoint */
context.parentCompute.documentSelfLink).setMaxPageSize(QueryUtils.MAX_RESULT_LIMIT).setClusterType(ServiceTypeCluster.INVENTORY_SERVICE);
queryLocalStates.queryDocuments(rg -> context.resourceGroupStates.put(rg.id, rg.documentSelfLink)).whenComplete(thenHandleSubStage(context, next));
}
use of com.vmware.xenon.services.common.QueryTask.Query in project photon-model by vmware.
the class TestVSphereImageEnumerationTask method testRefresh.
@Test
public void testRefresh() throws Throwable {
// Create a resource pool where the VM will be housed
this.resourcePool = createResourcePool();
this.auth = createAuth();
this.computeHostDescription = createComputeDescription();
this.computeHost = createComputeHost(this.computeHostDescription);
EndpointState ep = createEndpointState(this.computeHost, this.computeHostDescription);
this.endpoint = TestUtils.doPost(this.host, ep, EndpointState.class, UriUtils.buildUri(this.host, EndpointService.FACTORY_LINK));
doRefresh();
captureFactoryState("initial");
Query q = Query.Builder.create().addKindFieldClause(ImageState.class).build();
ImageState anImage = null;
try {
anImage = findFirstMatching(q, ImageState.class);
} catch (Exception ignore) {
}
if (anImage != null) {
assertFalse(anImage.tenantLinks.isEmpty());
}
doRefresh();
captureFactoryState("updated");
}
use of com.vmware.xenon.services.common.QueryTask.Query in project photon-model by vmware.
the class SslTrustCertificateServiceUtils method getQueryTask.
private static QueryTask getQueryTask() {
Query computeQuery = Query.Builder.create().addKindFieldClause(SslTrustCertificateState.class).build();
QueryTask task = QueryTask.Builder.create().addOption(QueryOption.CONTINUOUS).addOption(QueryOption.EXPAND_CONTENT).setQuery(computeQuery).build();
task.documentSelfLink = QUERY_TASK_SELF_LINK_PREFIX;
task.documentExpirationTimeMicros = Utils.fromNowMicrosUtc(TimeUnit.DAYS.toMicros(QUERY_TASK_EXPIRATION_DAYS));
return task;
}
Aggregations