use of com.vmware.photon.controller.model.query.QueryUtils.QueryByPages 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.photon.controller.model.query.QueryUtils.QueryByPages in project photon-model by vmware.
the class AzureNetworkEnumerationAdapterService method disassociateSubnetStates.
/**
* Delete subnet states that no longer exist in Azure.
* <p>
* 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 and belong
* to networks touched by this enumeration cycle (either created/updated/deleted).
*/
private void disassociateSubnetStates(NetworkEnumContext context, NetworkEnumStages next) {
Builder qBuilder = Query.Builder.create().addKindFieldClause(SubnetState.class).addFieldClause(SubnetState.FIELD_NAME_LIFECYCLE_STATE, LifecycleState.PROVISIONING.name(), MatchType.TERM, Occurance.MUST_NOT_OCCUR).addRangeClause(SubnetState.FIELD_NAME_UPDATE_TIME_MICROS, NumericRange.createLessThanRange(context.enumerationStartTimeInMicros));
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);
disassociateResourceStates(queryLocalStates, context, next);
}
use of com.vmware.photon.controller.model.query.QueryUtils.QueryByPages 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.photon.controller.model.query.QueryUtils.QueryByPages 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.photon.controller.model.query.QueryUtils.QueryByPages in project photon-model by vmware.
the class AzureNetworkEnumerationAdapterService method disassociateNetworkStates.
/**
* Delete local network states that no longer exist in Azure.
* <p>
* 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.
*/
private void disassociateNetworkStates(NetworkEnumContext context, NetworkEnumStages next) {
Builder qBuilder = Query.Builder.create().addKindFieldClause(NetworkState.class).addRangeClause(NetworkState.FIELD_NAME_UPDATE_TIME_MICROS, NumericRange.createLessThanRange(context.enumerationStartTimeInMicros));
QueryByPages<NetworkState> queryLocalStates = new QueryByPages<>(getHost(), qBuilder.build(), NetworkState.class, context.parentCompute.tenantLinks, null, /* endpoint */
context.parentCompute.documentSelfLink).setMaxPageSize(QueryUtils.MAX_RESULT_LIMIT).setClusterType(ServiceTypeCluster.INVENTORY_SERVICE);
disassociateResourceStates(queryLocalStates, context, next);
}
Aggregations