Search in sources :

Example 1 with Builder

use of com.vmware.xenon.services.common.QueryTask.Query.Builder 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);
}
Also used : QueryByPages(com.vmware.photon.controller.model.query.QueryUtils.QueryByPages) Builder(com.vmware.xenon.services.common.QueryTask.Query.Builder) SubnetState(com.vmware.photon.controller.model.resources.SubnetService.SubnetState)

Example 2 with Builder

use of com.vmware.xenon.services.common.QueryTask.Query.Builder 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));
}
Also used : 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) ServiceTypeCluster(com.vmware.photon.controller.model.util.ClusterUtil.ServiceTypeCluster) AzureUriPaths(com.vmware.photon.controller.model.adapters.azure.AzureUriPaths) SubnetStateWithParentVNetId(com.vmware.photon.controller.model.adapters.azure.enumeration.AzureNetworkEnumerationAdapterService.NetworkEnumContext.SubnetStateWithParentVNetId) LifecycleState(com.vmware.photon.controller.model.support.LifecycleState) StringUtils(org.apache.commons.lang3.StringUtils) ResourceGroupState(com.vmware.photon.controller.model.resources.ResourceGroupService.ResourceGroupState) MatchType(com.vmware.xenon.services.common.QueryTask.QueryTerm.MatchType) Utils(com.vmware.xenon.common.Utils) SubnetState(com.vmware.photon.controller.model.resources.SubnetService.SubnetState) Map(java.util.Map) URI(java.net.URI) TagsUtil.newTagState(com.vmware.photon.controller.model.adapters.util.TagsUtil.newTagState) VirtualNetworkListResult(com.vmware.photon.controller.model.adapters.azure.model.network.VirtualNetworkListResult) AzureConstants(com.vmware.photon.controller.model.adapters.azure.constants.AzureConstants) SubnetService(com.vmware.photon.controller.model.resources.SubnetService) StatelessService(com.vmware.xenon.common.StatelessService) DEFAULT_INSTANCE_ADAPTER_REFERENCE(com.vmware.photon.controller.model.adapters.azure.constants.AzureConstants.DEFAULT_INSTANCE_ADAPTER_REFERENCE) 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) Collectors(java.util.stream.Collectors) NETWORK_REST_API_VERSION(com.vmware.photon.controller.model.adapters.azure.constants.AzureConstants.NETWORK_REST_API_VERSION) List(java.util.List) AzureUtils(com.vmware.photon.controller.model.adapters.azure.utils.AzureUtils) Stream(java.util.stream.Stream) TagService(com.vmware.photon.controller.model.resources.TagService) CompletionHandler(com.vmware.xenon.common.Operation.CompletionHandler) AddressSpace(com.vmware.photon.controller.model.adapters.azure.model.network.AddressSpace) DeferredResult(com.vmware.xenon.common.DeferredResult) UriUtils(com.vmware.xenon.common.UriUtils) Entry(java.util.Map.Entry) TagsUtil.setTagLinksToResourceState(com.vmware.photon.controller.model.adapters.util.TagsUtil.setTagLinksToResourceState) AzureUtils.getAzureConfig(com.vmware.photon.controller.model.adapters.azure.utils.AzureUtils.getAzureConfig) NumericRange(com.vmware.xenon.services.common.QueryTask.NumericRange) Builder(com.vmware.xenon.services.common.QueryTask.Query.Builder) LIST_VIRTUAL_NETWORKS_URI(com.vmware.photon.controller.model.adapters.azure.constants.AzureConstants.LIST_VIRTUAL_NETWORKS_URI) ComputeProperties(com.vmware.photon.controller.model.ComputeProperties) ResourceGroupStateType(com.vmware.photon.controller.model.adapters.azure.constants.AzureConstants.ResourceGroupStateType) QueryByPages(com.vmware.photon.controller.model.query.QueryUtils.QueryByPages) HashMap(java.util.HashMap) PhotonModelUtils(com.vmware.photon.controller.model.resources.util.PhotonModelUtils) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) TagState(com.vmware.photon.controller.model.resources.TagService.TagState) AuthCredentialsService(com.vmware.xenon.services.common.AuthCredentialsService) 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) EnumerationStages(com.vmware.photon.controller.model.adapters.util.enums.EnumerationStages) TagsUtil.updateLocalTagStates(com.vmware.photon.controller.model.adapters.util.TagsUtil.updateLocalTagStates) VirtualNetwork(com.vmware.photon.controller.model.adapters.azure.model.network.VirtualNetwork) BiConsumer(java.util.function.BiConsumer) EnumerationAction(com.vmware.photon.controller.model.adapterapi.EnumerationAction) AzureResourceType(com.vmware.photon.controller.model.adapters.azure.constants.AzureConstants.AzureResourceType) AdapterUtils(com.vmware.photon.controller.model.adapters.util.AdapterUtils) ResourceState(com.vmware.photon.controller.model.resources.ResourceState) Subnet(com.vmware.photon.controller.model.adapters.azure.model.network.Subnet) AdapterUriUtil(com.vmware.photon.controller.model.adapters.util.AdapterUriUtil) Operation(com.vmware.xenon.common.Operation) QueryUtils(com.vmware.photon.controller.model.query.QueryUtils) NetworkService(com.vmware.photon.controller.model.resources.NetworkService) ComputeStateWithDescription(com.vmware.photon.controller.model.resources.ComputeService.ComputeStateWithDescription) PhotonModelConstants(com.vmware.photon.controller.model.constants.PhotonModelConstants) ComputeEnumerateAdapterRequest(com.vmware.photon.controller.model.adapters.util.ComputeEnumerateAdapterRequest) ApplicationTokenCredentials(com.microsoft.azure.credentials.ApplicationTokenCredentials) NetworkState(com.vmware.photon.controller.model.resources.NetworkService.NetworkState) Collections(java.util.Collections) OperationJoin(com.vmware.xenon.common.OperationJoin) QueryByPages(com.vmware.photon.controller.model.query.QueryUtils.QueryByPages) Builder(com.vmware.xenon.services.common.QueryTask.Query.Builder) SubnetState(com.vmware.photon.controller.model.resources.SubnetService.SubnetState)

Example 3 with Builder

use of com.vmware.xenon.services.common.QueryTask.Query.Builder 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);
}
Also used : QueryByPages(com.vmware.photon.controller.model.query.QueryUtils.QueryByPages) Builder(com.vmware.xenon.services.common.QueryTask.Query.Builder) NetworkState(com.vmware.photon.controller.model.resources.NetworkService.NetworkState)

Example 4 with Builder

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

the class VSphereNetworkEnumerationHelper method queryForNetwork.

private static QueryTask queryForNetwork(EnumerationProgress ctx, NetworkOverlay net) {
    URI adapterManagementReference = ctx.getRequest().adapterManagementReference;
    String regionId = ctx.getRegionId();
    Builder builder = Builder.create().addFieldClause(NetworkState.FIELD_NAME_ADAPTER_MANAGEMENT_REFERENCE, adapterManagementReference.toString()).addKindFieldClause(NetworkState.class).addFieldClause(NetworkState.FIELD_NAME_REGION_ID, regionId).addCompositeFieldClause(ComputeState.FIELD_NAME_CUSTOM_PROPERTIES, CustomProperties.MOREF, VimUtils.convertMoRefToString(net.getId()), Occurance.MUST_OCCUR);
    QueryUtils.addEndpointLink(builder, NetworkState.class, ctx.getRequest().endpointLink);
    QueryUtils.addTenantLinks(builder, ctx.getTenantLinks());
    return QueryTask.Builder.createDirectTask().setQuery(builder.build()).setResultLimit(1).build();
}
Also used : Builder(com.vmware.xenon.services.common.QueryTask.Query.Builder) URI(java.net.URI)

Example 5 with Builder

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

the class VSphereNetworkEnumerationHelper method queryForSubnet.

private static QueryTask queryForSubnet(EnumerationProgress ctx, NetworkOverlay portgroup, ManagedObjectReference parent) {
    String moref = VimUtils.convertMoRefToString(portgroup.getId());
    Builder builder = Builder.create().addKindFieldClause(SubnetState.class).addCompositeFieldClause(ResourceState.FIELD_NAME_CUSTOM_PROPERTIES, CustomProperties.MOREF, moref);
    if (parent != null) {
        String dvsLink = buildStableDvsLink(parent, ctx.getRequest().endpointLink);
        builder.addFieldClause(SubnetState.FIELD_NAME_NETWORK_LINK, dvsLink);
    }
    QueryUtils.addEndpointLink(builder, NetworkState.class, ctx.getRequest().endpointLink);
    QueryUtils.addTenantLinks(builder, ctx.getTenantLinks());
    return QueryTask.Builder.createDirectTask().setQuery(builder.build()).build();
}
Also used : Builder(com.vmware.xenon.services.common.QueryTask.Query.Builder) SubnetState(com.vmware.photon.controller.model.resources.SubnetService.SubnetState)

Aggregations

Builder (com.vmware.xenon.services.common.QueryTask.Query.Builder)14 QueryByPages (com.vmware.photon.controller.model.query.QueryUtils.QueryByPages)3 ResourceGroupState (com.vmware.photon.controller.model.resources.ResourceGroupService.ResourceGroupState)3 SubnetState (com.vmware.photon.controller.model.resources.SubnetService.SubnetState)3 NetworkState (com.vmware.photon.controller.model.resources.NetworkService.NetworkState)2 QueryTask (com.vmware.xenon.services.common.QueryTask)2 URI (java.net.URI)2 ApplicationTokenCredentials (com.microsoft.azure.credentials.ApplicationTokenCredentials)1 ComputeProperties (com.vmware.photon.controller.model.ComputeProperties)1 ComputeEnumerateResourceRequest (com.vmware.photon.controller.model.adapterapi.ComputeEnumerateResourceRequest)1 EnumerationAction (com.vmware.photon.controller.model.adapterapi.EnumerationAction)1 AzureUriPaths (com.vmware.photon.controller.model.adapters.azure.AzureUriPaths)1 AzureConstants (com.vmware.photon.controller.model.adapters.azure.constants.AzureConstants)1 AUTH_HEADER_BEARER_PREFIX (com.vmware.photon.controller.model.adapters.azure.constants.AzureConstants.AUTH_HEADER_BEARER_PREFIX)1 AzureResourceType (com.vmware.photon.controller.model.adapters.azure.constants.AzureConstants.AzureResourceType)1 DEFAULT_INSTANCE_ADAPTER_REFERENCE (com.vmware.photon.controller.model.adapters.azure.constants.AzureConstants.DEFAULT_INSTANCE_ADAPTER_REFERENCE)1 LIST_VIRTUAL_NETWORKS_URI (com.vmware.photon.controller.model.adapters.azure.constants.AzureConstants.LIST_VIRTUAL_NETWORKS_URI)1 NETWORK_REST_API_VERSION (com.vmware.photon.controller.model.adapters.azure.constants.AzureConstants.NETWORK_REST_API_VERSION)1 QUERY_PARAM_API_VERSION (com.vmware.photon.controller.model.adapters.azure.constants.AzureConstants.QUERY_PARAM_API_VERSION)1 ResourceGroupStateType (com.vmware.photon.controller.model.adapters.azure.constants.AzureConstants.ResourceGroupStateType)1