Search in sources :

Example 6 with QuerySpecification

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

the class LongRunEndToEndAzureStatsAggregation method verifyTimeBinMetrics.

/**
 * Performs check to verify time bin metrics are available for every compute resource and also
 * checks the occurrence of estimated charges for one of the resource metrics.
 */
private void verifyTimeBinMetrics(ServiceDocumentQueryResult res) {
    List<Object> results = new ArrayList<>();
    for (String computeResourceLink : res.documentLinks) {
        for (String metricName : AzureTestUtil.getMetricNames()) {
            QuerySpecification querySpec = new QuerySpecification();
            querySpec.query = QueryTask.Query.Builder.create().addKindFieldClause(ResourceMetrics.class).addFieldClause(ServiceDocument.FIELD_NAME_SELF_LINK, UriUtils.buildUriPath(ResourceMetricsService.FACTORY_LINK, computeResourceLink), QueryTerm.MatchType.PREFIX).addRangeClause(QuerySpecification.buildCompositeFieldName(ResourceMetrics.FIELD_NAME_ENTRIES, metricName), NumericRange.createDoubleRange(0.0, Double.MAX_VALUE, true, true)).build();
            QueryTask qt = QueryTask.Builder.createDirectTask().addOption(QueryOption.TOP_RESULTS).addOption(QueryOption.INCLUDE_ALL_VERSIONS).setResultLimit(1).addOption(QueryOption.EXPAND_CONTENT).addOption(QueryOption.SORT).orderDescending(ServiceDocument.FIELD_NAME_SELF_LINK, ServiceDocumentDescription.TypeName.STRING).setQuery(querySpec.query).build();
            this.host.createQueryTaskService(qt, false, true, qt, null);
            if (qt.results.documentLinks.size() > 0 && qt.results.documentLinks.get(0) != null) {
                results.add(qt.results.documents.get(qt.results.documentLinks.get(0)));
            }
        }
    }
    long expectedExpirationTime = Utils.getNowMicrosUtc() + TimeUnit.DAYS.toMicros(DEFAULT_RETENTION_LIMIT_DAYS);
    for (Object aggrDocument : results) {
        ResourceMetrics aggrMetric = Utils.fromJson(aggrDocument, ResourceMetrics.class);
        // Make sure all the documents have expiration time set.
        assertTrue("Expiration time is not correctly set.", aggrMetric.documentExpirationTimeMicros < expectedExpirationTime);
        // The assertion here checks whether we are aggregating only on latest value. To
        // that effect, here is the breakdown for the check:
        // count = num of resources: one value for each resource
        // sum = null: not specified in the aggregate type set
        assertNotNull("Value is not set", aggrMetric.entries.get(0));
    }
}
Also used : QuerySpecification(com.vmware.xenon.services.common.QueryTask.QuerySpecification) AzureTestUtil.getResourceMetrics(com.vmware.photon.controller.model.adapters.azure.instance.AzureTestUtil.getResourceMetrics) ResourceMetrics(com.vmware.photon.controller.model.monitoring.ResourceMetricsService.ResourceMetrics) QueryTask(com.vmware.xenon.services.common.QueryTask) ArrayList(java.util.ArrayList)

Example 7 with QuerySpecification

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

the class TestAWSSetupUtils method deleteVMs.

/**
 * Deletes the VM that is present on an endpoint and represented by the passed in ID.
 *
 * @param documentSelfLink
 * @param isMock
 * @param host
 * @param deleteDocumentOnly
 * @throws Throwable
 */
public static void deleteVMs(String documentSelfLink, boolean isMock, VerificationHost host, boolean deleteDocumentOnly) throws Throwable {
    ResourceRemovalTaskState deletionState = new ResourceRemovalTaskState();
    QuerySpecification resourceQuerySpec = new QueryTask.QuerySpecification();
    // query all ComputeState resources for the cluster
    resourceQuerySpec.query.setTermPropertyName(ServiceDocument.FIELD_NAME_SELF_LINK).setTermMatchValue(documentSelfLink);
    deletionState.resourceQuerySpec = resourceQuerySpec;
    deletionState.isMockRequest = isMock;
    // Waiting for default request timeout in minutes for the machine to be turned OFF on AWS.
    deletionState.documentExpirationTimeMicros = Utils.getNowMicrosUtc() + TimeUnit.MINUTES.toMicros(AWS_VM_REQUEST_TIMEOUT_MINUTES);
    if (deleteDocumentOnly) {
        deletionState.options = EnumSet.of(TaskOption.DOCUMENT_CHANGES_ONLY);
    }
    deletionState = TestUtils.doPost(host, deletionState, ResourceRemovalTaskState.class, UriUtils.buildUri(host, ResourceRemovalTaskService.FACTORY_LINK));
    ProvisioningUtils.waitForTaskCompletion(host, deletionState.documentSelfLink, ResourceRemovalTaskState.class);
    // check that the VMs are gone
    ServiceDocumentQueryResult serviceDocumentQueryResult = ProvisioningUtils.queryAllFactoryResources(host, ComputeService.FACTORY_LINK);
    List<String> documentLinks = serviceDocumentQueryResult.documentLinks;
    assertFalse(documentLinks.contains(documentSelfLink));
}
Also used : QuerySpecification(com.vmware.xenon.services.common.QueryTask.QuerySpecification) ResourceRemovalTaskState(com.vmware.photon.controller.model.tasks.ResourceRemovalTaskService.ResourceRemovalTaskState) ServiceDocumentQueryResult(com.vmware.xenon.common.ServiceDocumentQueryResult)

Example 8 with QuerySpecification

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

the class TestAWSSetupUtils method deleteVMsOnThisEndpoint.

/**
 * A utility method that deletes the VMs on the specified endpoint filtered by the instanceIds
 * that are passed in. It expects peerURI and tenantLinks to be populated.
 *
 * @throws Throwable
 */
public static void deleteVMsOnThisEndpoint(VerificationHost host, URI peerURI, boolean isMock, String parentComputeLink, List<String> instanceIdsToDelete, List<String> tenantLinks) throws Throwable {
    host.testStart(1);
    ResourceRemovalTaskState deletionState = new ResourceRemovalTaskState();
    deletionState.tenantLinks = tenantLinks;
    // All AWS Compute States AND Ids in (Ids to delete)
    QuerySpecification compositeQuery = new QueryTask.QuerySpecification();
    // Document Kind = Compute State AND Parent Compute Link = AWS
    QueryTask.Query awsComputeStatesQuery = new QueryTask.Query();
    awsComputeStatesQuery = Query.Builder.create().addKindFieldClause(ComputeService.ComputeState.class).addFieldClause(ComputeState.FIELD_NAME_PARENT_LINK, parentComputeLink).build();
    compositeQuery.query.addBooleanClause(awsComputeStatesQuery);
    if (instanceIdsToDelete != null && instanceIdsToDelete.size() > 0) {
        // Instance Ids in List of instance Ids to delete
        QueryTask.Query instanceIdFilterParentQuery = new QueryTask.Query();
        for (String instanceId : instanceIdsToDelete) {
            if (!instanceId.startsWith(AWS_INSTANCE_PREFIX)) {
                continue;
            }
            QueryTask.Query instanceIdFilter = new QueryTask.Query().setTermPropertyName(ComputeState.FIELD_NAME_ID).setTermMatchValue(instanceId);
            instanceIdFilter.occurance = QueryTask.Query.Occurance.SHOULD_OCCUR;
            instanceIdFilterParentQuery.addBooleanClause(instanceIdFilter);
        }
        instanceIdFilterParentQuery.occurance = Occurance.MUST_OCCUR;
        compositeQuery.query.addBooleanClause(instanceIdFilterParentQuery);
    }
    deletionState.resourceQuerySpec = compositeQuery;
    deletionState.isMockRequest = isMock;
    host.send(Operation.createPost(createServiceURI(host, peerURI, ResourceRemovalTaskService.FACTORY_LINK)).setBody(deletionState).setCompletion(host.getCompletion()));
    // Re-setting the test timeout value so that it clean up spawned instances even if it has
    // timed out based on the original value.
    host.setTimeoutSeconds(500);
    host.testWait();
}
Also used : QuerySpecification(com.vmware.xenon.services.common.QueryTask.QuerySpecification) ComputeState(com.vmware.photon.controller.model.resources.ComputeService.ComputeState) QueryTask(com.vmware.xenon.services.common.QueryTask) Query(com.vmware.xenon.services.common.QueryTask.Query) Query(com.vmware.xenon.services.common.QueryTask.Query) ResourceRemovalTaskState(com.vmware.photon.controller.model.tasks.ResourceRemovalTaskService.ResourceRemovalTaskState)

Aggregations

QuerySpecification (com.vmware.xenon.services.common.QueryTask.QuerySpecification)8 ResourceRemovalTaskState (com.vmware.photon.controller.model.tasks.ResourceRemovalTaskService.ResourceRemovalTaskState)6 ComputeState (com.vmware.photon.controller.model.resources.ComputeService.ComputeState)3 QueryTask (com.vmware.xenon.services.common.QueryTask)3 ArrayList (java.util.ArrayList)3 ComputeDescription (com.vmware.photon.controller.model.resources.ComputeDescriptionService.ComputeDescription)2 Query (com.vmware.xenon.services.common.QueryTask.Query)2 Lists (com.google.common.collect.Lists)1 AddressSpace (com.microsoft.azure.management.network.AddressSpace)1 LoadBalancerInner (com.microsoft.azure.management.network.implementation.LoadBalancerInner)1 LoadBalancersInner (com.microsoft.azure.management.network.implementation.LoadBalancersInner)1 VirtualNetworkInner (com.microsoft.azure.management.network.implementation.VirtualNetworkInner)1 VirtualNetworksInner (com.microsoft.azure.management.network.implementation.VirtualNetworksInner)1 ResourceGroupInner (com.microsoft.azure.management.resources.implementation.ResourceGroupInner)1 ResourceGroupsInner (com.microsoft.azure.management.resources.implementation.ResourceGroupsInner)1 ComputeProperties (com.vmware.photon.controller.model.ComputeProperties)1 PhotonModelMetricServices (com.vmware.photon.controller.model.PhotonModelMetricServices)1 LoadBalancerInstanceRequest (com.vmware.photon.controller.model.adapterapi.LoadBalancerInstanceRequest)1 SecurityGroupInstanceRequest (com.vmware.photon.controller.model.adapterapi.SecurityGroupInstanceRequest)1 InstanceRequestType (com.vmware.photon.controller.model.adapterapi.SubnetInstanceRequest.InstanceRequestType)1