Search in sources :

Example 11 with ServiceDocumentQueryResult

use of com.vmware.xenon.common.ServiceDocumentQueryResult in project photon-model by vmware.

the class TestAWSSetupUtils method getInternalTagsByType.

public static ServiceDocumentQueryResult getInternalTagsByType(VerificationHost host, String type) {
    Query query = Query.Builder.create().addKindFieldClause(TagService.TagState.class).addFieldClause(TagService.TagState.FIELD_NAME_KEY, PhotonModelConstants.TAG_KEY_TYPE).addFieldClause(TagService.TagState.FIELD_NAME_VALUE, type).build();
    Query externalQuery = new Query().setTermPropertyName(TagService.TagState.FIELD_NAME_EXTERNAL).setTermMatchValue(Boolean.FALSE.toString());
    externalQuery.occurance = Query.Occurance.SHOULD_OCCUR;
    Query originQuery = new Query().addBooleanClause(Query.Builder.create().addCollectionItemClause(TagService.TagState.FIELD_NAME_ORIGIN, DISCOVERED.toString(), Occurance.MUST_NOT_OCCUR).addCollectionItemClause(TagService.TagState.FIELD_NAME_ORIGIN, SYSTEM.toString(), Query.Occurance.SHOULD_OCCUR).addCollectionItemClause(TagService.TagState.FIELD_NAME_ORIGIN, USER_DEFINED.toString(), Query.Occurance.SHOULD_OCCUR).build()).setOccurance(Query.Occurance.SHOULD_OCCUR);
    Query originOrExternalQuery = new Query().addBooleanClause(externalQuery).addBooleanClause(originQuery).setOccurance(Query.Occurance.MUST_OCCUR);
    query.addBooleanClause(originOrExternalQuery);
    QueryTask queryTask = QueryTask.Builder.createDirectTask().setQuery(query).addOption(QuerySpecification.QueryOption.EXPAND_CONTENT).addOption(QuerySpecification.QueryOption.TOP_RESULTS).setResultLimit(getQueryResultLimit()).build();
    queryTask.documentSelfLink = UUID.randomUUID().toString();
    host.createQueryTaskService(queryTask, false, true, queryTask, null);
    ServiceDocumentQueryResult results = queryTask.results;
    return results;
}
Also used : QueryTask(com.vmware.xenon.services.common.QueryTask) Query(com.vmware.xenon.services.common.QueryTask.Query) ServiceDocumentQueryResult(com.vmware.xenon.common.ServiceDocumentQueryResult)

Example 12 with ServiceDocumentQueryResult

use of com.vmware.xenon.common.ServiceDocumentQueryResult in project photon-model by vmware.

the class AzureTestUtil method assertResourceExists.

/**
 * Assert that a resource with the provided name exist in the document store.
 *
 * @param factoryLink
 *            Factory link to the stateful service which states to check.
 * @param name
 *            name of the resource to assert if exists.
 * @param shouldExists
 *            whether to assert if a resource exists or not.
 */
public static void assertResourceExists(VerificationHost host, String factoryLink, String name, boolean shouldExists) {
    ServiceDocumentQueryResult result = host.getExpandedFactoryState(UriUtils.buildUri(host, factoryLink));
    boolean exists = false;
    for (Object document : result.documents.values()) {
        ResourceState state = Utils.fromJson(document, ResourceState.class);
        if (name.equals(state.name)) {
            exists = true;
            break;
        }
    }
    assertEquals("Expected: " + shouldExists + ", but was: " + exists, shouldExists, exists);
}
Also used : ResourceState(com.vmware.photon.controller.model.resources.ResourceState) ServiceDocumentQueryResult(com.vmware.xenon.common.ServiceDocumentQueryResult)

Example 13 with ServiceDocumentQueryResult

use of com.vmware.xenon.common.ServiceDocumentQueryResult in project photon-model by vmware.

the class AzureTestUtil method assertDiskExist.

/**
 * Assert that a managed / un-managed disk with the provided name exist in the document store.
 *
 * @param factoryLink
 *            Factory link to the stateful service which states to check.
 * @param name
 *            name of the resource to assert if exists.
 * @param shouldExists
 *            whether to assert if a resource exists or not.
 */
public static void assertDiskExist(VerificationHost host, String factoryLink, String name, boolean shouldExists) {
    ServiceDocumentQueryResult result = host.getExpandedFactoryState(UriUtils.buildUri(host, factoryLink));
    boolean exists = false;
    for (Object document : result.documents.values()) {
        DiskState diskState = Utils.fromJson(document, DiskState.class);
        if (diskState.name.contains(name)) {
            exists = true;
            break;
        }
    }
    assertEquals("Expected: " + shouldExists + ", but was: " + exists, shouldExists, exists);
}
Also used : DiskState(com.vmware.photon.controller.model.resources.DiskService.DiskState) ServiceDocumentQueryResult(com.vmware.xenon.common.ServiceDocumentQueryResult)

Example 14 with ServiceDocumentQueryResult

use of com.vmware.xenon.common.ServiceDocumentQueryResult in project photon-model by vmware.

the class AzureTestUtil method assertResourceDisassociated.

/**
 * Assert that a resource with the provided name exist in the document store.
 *
 * @param factoryLink
 *            Factory link to the stateful service which states to check.
 * @param name
 *            name of the resource to assert if exists.
 * @param isDisassociated
 *            whether to assert if a resource exists or not.
 */
public static void assertResourceDisassociated(VerificationHost host, String factoryLink, String name, boolean isDisassociated) {
    ServiceDocumentQueryResult result = host.getExpandedFactoryState(UriUtils.buildUri(host, factoryLink));
    boolean disassociated = false;
    for (Object document : result.documents.values()) {
        // Read doc as ServiceDocument to access its 'documentKind'
        ServiceDocument serviceDoc = Utils.fromJson(document, ServiceDocument.class);
        Class<? extends ResourceState> resourceClass = ENDPOINT_LINK_EXPLICIT_SUPPORT.stream().filter(clazz -> serviceDoc.documentKind.equals(Utils.buildKind(clazz))).findFirst().orElse(null);
        if (resourceClass != null) {
            // Read doc as ResourceState to access its 'endpointLinks'
            ResourceState resource = Utils.fromJson(document, resourceClass);
            if (Objects.equals(name, resource.name) && resource.endpointLinks.isEmpty()) {
                String endpointLink = PhotonModelUtils.getEndpointLink(resource);
                if (endpointLink == null || endpointLink.isEmpty()) {
                    disassociated = true;
                    break;
                }
            }
        }
    }
    assertEquals("isDisassociated", isDisassociated, disassociated);
}
Also used : ServiceDocument(com.vmware.xenon.common.ServiceDocument) ResourceState(com.vmware.photon.controller.model.resources.ResourceState) ServiceDocumentQueryResult(com.vmware.xenon.common.ServiceDocumentQueryResult)

Example 15 with ServiceDocumentQueryResult

use of com.vmware.xenon.common.ServiceDocumentQueryResult in project photon-model by vmware.

the class LongRunEndToEndAzureStatsAggregation method runStatsCollectionAndAggregationLogNodeStatsPeriodically.

/**
 * Periodically runs stats collection and aggregation and logs node stats.
 */
private void runStatsCollectionAndAggregationLogNodeStatsPeriodically() {
    this.host.getScheduledExecutor().scheduleAtFixedRate(() -> {
        try {
            this.host.log(Level.INFO, "Running azure stats collection...");
            // perform stats collection on given Azure endpoint.
            resourceStatsCollection(this.host, this.isMock, computeHost.resourcePoolLink);
            ServiceDocumentQueryResult res = this.host.getFactoryState(UriUtils.buildExpandLinksQueryUri(UriUtils.buildUri(this.host, ComputeService.FACTORY_LINK)));
            this.host.log(Level.INFO, "Running azure stats aggregation...");
            resourceStatsAggregation(this.host, computeHost.resourcePoolLink);
            logNodeStats(this.host.getServiceStats(this.nodeStatsUri));
            ServiceDocumentQueryResult aggrResult = this.host.getExpandedFactoryState(UriUtils.buildUri(this.host, ResourceMetricsService.FACTORY_LINK));
            // check compute resource has stats generated for all the metric keys
            checkInMemoryStatsPresent(res);
            // check expiration time for aggregate metric documents
            checkExpirationTime(aggrResult);
            // check to verify appropriate resource metrics entries are present for compute resources.
            verifyResourceMetricEntries(res);
            // verify time bin metrics for every compute resource and endpoint estimated charges
            verifyTimeBinMetrics(res);
        } catch (Throwable e) {
            this.host.log(Level.WARNING, "Error running stats aggregation in test" + e.getMessage());
        }
    }, 0, this.aggregationFrequencyInMinutes, TimeUnit.MINUTES);
}
Also used : ServiceDocumentQueryResult(com.vmware.xenon.common.ServiceDocumentQueryResult)

Aggregations

ServiceDocumentQueryResult (com.vmware.xenon.common.ServiceDocumentQueryResult)64 Test (org.junit.Test)26 ComputeState (com.vmware.photon.controller.model.resources.ComputeService.ComputeState)25 ArrayList (java.util.ArrayList)15 QueryTask (com.vmware.xenon.services.common.QueryTask)14 EndpointState (com.vmware.photon.controller.model.resources.EndpointService.EndpointState)13 Operation (com.vmware.xenon.common.Operation)13 ComputeDescription (com.vmware.photon.controller.model.resources.ComputeDescriptionService.ComputeDescription)12 DiskState (com.vmware.photon.controller.model.resources.DiskService.DiskState)12 HashMap (java.util.HashMap)12 BaseModelTest (com.vmware.photon.controller.model.helpers.BaseModelTest)11 ResourcePoolState (com.vmware.photon.controller.model.resources.ResourcePoolService.ResourcePoolState)11 URI (java.net.URI)11 Map (java.util.Map)11 List (java.util.List)10 StatsCollectionTaskState (com.vmware.photon.controller.model.tasks.monitoring.StatsCollectionTaskService.StatsCollectionTaskState)8 UriUtils (com.vmware.xenon.common.UriUtils)8 Utils (com.vmware.xenon.common.Utils)8 QueryUtils (com.vmware.photon.controller.model.query.QueryUtils)7 ServiceStat (com.vmware.xenon.common.ServiceStats.ServiceStat)7