Search in sources :

Example 1 with ServiceDocumentQueryResult

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

the class LongRunEndToEndStatsAggregationTest method testStatsAggregation.

/**
 * Test to perform end to end stats aggregation with stats adapter.
 * Performs enumeration against a real AWS endpoint if provided and then executes stats collection.
 * Test is then performed with periodic execution of stats collection and aggregation.
 * Verifies the compute types of resources and their stats for last successful collection time.
 * Verifies in memory stats generation for resource aggregate metric documents.
 * Verifies expiration time for resource aggregate metric documents.
 * Verifies resource metric entries and its time bin entries for resource aggregate metric documents.
 * Also, verifies Estimated Charges value for given AWS endpoint.
 */
@Test
public void testStatsAggregation() throws Throwable {
    this.host.log("Running test: " + this.currentTestName);
    if (this.isMock) {
        return;
    }
    this.host.log(STAT_NAME_MEMORY_ON_HOST_IN_MB + SEPARATOR + this.maxMemoryInMb);
    // perform stats aggregation before stats collection takes place.
    // As no stats collection is performed yet, ResourceAggregateMetric document count will be 0.
    resourceStatsAggregation(this.host, this.computeHost.resourcePoolLink);
    ServiceDocumentQueryResult aggrRes = this.host.getFactoryState(UriUtils.buildUri(this.host, ResourceMetricsService.FACTORY_LINK));
    assertEquals(0, aggrRes.documentLinks.size());
    // perform enumeration on given AWS endpoint.
    enumerateResources(this.host, this.computeHost, this.endpointState, this.isMock, TEST_CASE_INITIAL);
    // periodically perform stats aggregation on given AWS endpoint
    runStatsCollectionAndAggregationLogNodeStatsPeriodically();
    this.host.log(Level.INFO, "Waiting for multiple stats aggregation runs...");
    this.host.waitFor("Timeout while waiting for test run duration", () -> {
        TimeUnit.MINUTES.sleep(this.testRunDurationInMinutes);
        this.host.getScheduledExecutor().shutdown();
        this.host.getScheduledExecutor().awaitTermination(EXECUTOR_TERMINATION_WAIT_DURATION_MINUTES, TimeUnit.MINUTES);
        return true;
    });
}
Also used : ServiceDocumentQueryResult(com.vmware.xenon.common.ServiceDocumentQueryResult) Test(org.junit.Test)

Example 2 with ServiceDocumentQueryResult

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

the class LongRunEndToEndStatsCollectionTest method testStatsCollection.

/**
 * Test to perform end to end stats collection with stats adapter.
 * Performs enumeration against a real AWS endpoint if provided and then executes 2 sessions of
 * periodic stats collection.
 * Log the stats for Cpu and Memory usage.
 * Verifies the compute types of resources and their stats for last successful collection time.
 * Also, verifies Estimated Charges value for given AWS endpoint.
 */
@Test
public void testStatsCollection() throws Throwable {
    this.host.log("Running test: " + this.currentTestName);
    // if mock, simply return.
    if (this.isMock) {
        return;
    }
    this.host.log(STAT_NAME_MEMORY_ON_HOST_IN_MB + SEPARATOR + this.maxMemoryInMb);
    SingleResourceStatsCollectionTaskService service = new SingleResourceStatsCollectionTaskService();
    // generate stats link using stats adapter
    String statsLink = UriUtils.getLastPathSegment(AWSUriPaths.AWS_STATS_ADAPTER);
    this.lastSuccessfulCollectionTimeKey = service.getLastCollectionMetricKeyForAdapterLink(statsLink, true);
    // perform resource stats collection before enumeration takes place on given AWS endpoint
    resourceStatsCollection(this.host, this.isMock, this.computeHost.resourcePoolLink);
    // will try to fetch the compute state resources
    ServiceDocumentQueryResult result = this.host.getFactoryState(UriUtils.buildExpandLinksQueryUri(UriUtils.buildUri(this.host, ComputeService.FACTORY_LINK)));
    // will have only 1 document of type 'ENDPOINT_HOST'
    assertEquals(1, result.documents.size());
    JsonObject jsonObject = (JsonObject) result.documents.get(result.documentLinks.get(0));
    assertEquals(ComputeType.ENDPOINT_HOST.toString(), jsonObject.get("type").getAsString());
    // perform resource enumeration on given AWS endpoint
    enumerateResources(this.host, this.computeHost, this.endpointState, this.isMock, TEST_CASE_RUN);
    // periodically perform stats collection on given AWS endpoint
    runStatsCollectionLogNodeStatsPeriodically();
    this.host.log(Level.INFO, "Waiting for multiple stats collection runs...");
    // Keep the host running for some time, specified by testRunDurationInMinutes parameter.
    this.host.waitFor("Timeout while waiting for test run duration", () -> {
        TimeUnit.MINUTES.sleep(this.testRunDurationInMinutes);
        return true;
    });
    // fetch all the compute state resources
    ServiceDocumentQueryResult res = this.host.getFactoryState(UriUtils.buildExpandLinksQueryUri(UriUtils.buildUri(this.host, ComputeService.FACTORY_LINK)));
    // total compute resources
    this.totalComputeResources = res.documents.size();
    this.currentTimeMicros = Utils.getNowMicrosUtc();
    // query and verify resource metrics obtained for first iteration of stats collection
    verifyMetricStats(res, this.statsToCheckInit);
    // periodically perform more cycles of resource stats collection on given AWS endpoint
    this.host.log(Level.INFO, "Waiting for multiple stats collection second runs...");
    // Keep the host running for some time, specified by testRunDurationInMinutes parameter.
    this.host.waitFor("Timeout while waiting for second test run duration", () -> {
        TimeUnit.MINUTES.sleep(this.testRunDurationInMinutes);
        this.host.getScheduledExecutor().shutdown();
        this.host.getScheduledExecutor().awaitTermination(EXECUTOR_TERMINATION_WAIT_DURATION_MINUTES, TimeUnit.MINUTES);
        return true;
    });
    // query and verify resource metrics obtained for second iteration of stats collection
    verifyMetricStats(res, this.statsToCheckLater);
    // the values will change only if new values are captured from AWS during stats collection.
    assertTrue("LastUpdate time obtained during first cycle of stats collection should be" + " less than or equal to the value during second cycle", this.statsToCheckInit.serviceStat.lastUpdateMicrosUtc <= this.statsToCheckLater.serviceStat.lastUpdateMicrosUtc);
    assertTrue("LatestValue obtained during first cycle of stats collection should be " + "less than or equal to the value during second cycle", this.statsToCheckInit.serviceStat.latestValue <= this.statsToCheckLater.serviceStat.latestValue);
    assertTrue("Document version obtained during initial cycles of stats collection should be" + " less than or equal to that obtained during later stats collection cycle", this.statsToCheckInit.serviceStat.version <= this.statsToCheckInit.serviceStat.version);
    assertTrue("EstimatedCharges obtained during first cycle of stats collection should be" + " less than or equal to that obtained during second stats collection cycle", this.statsToCheckInit.estimatedCharges <= this.statsToCheckLater.estimatedCharges);
}
Also used : SingleResourceStatsCollectionTaskService(com.vmware.photon.controller.model.tasks.monitoring.SingleResourceStatsCollectionTaskService) JsonObject(com.google.gson.JsonObject) ServiceDocumentQueryResult(com.vmware.xenon.common.ServiceDocumentQueryResult) Test(org.junit.Test)

Example 3 with ServiceDocumentQueryResult

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

the class TestAWSMissingEnumerationResourcesService method getLinkedAccountComputeDescs.

private void getLinkedAccountComputeDescs(Request request, int expectedCount) {
    this.host.waitFor("Timeout waiting for getLinkedAccountComputeDescriptions()", () -> {
        ServiceDocumentQueryResult result = this.host.createAndWaitSimpleDirectQuery(getQuerySpecForComputeDesc(request), expectedCount, expectedCount);
        Collection<Object> values = result.documents.values();
        if (values.size() != expectedCount) {
            return false;
        }
        for (Object computeDesc : result.documents.values()) {
            ComputeDescription cDesc = Utils.fromJson(computeDesc, ComputeDescription.class);
            linkedAccountDescriptions.put(cDesc.name, cDesc);
            if (!cDesc.endpointLink.equals(request.primaryAccountCompute.endpointLink)) {
                return false;
            }
        }
        return true;
    });
}
Also used : ComputeDescription(com.vmware.photon.controller.model.resources.ComputeDescriptionService.ComputeDescription) ServiceDocumentQueryResult(com.vmware.xenon.common.ServiceDocumentQueryResult)

Example 4 with ServiceDocumentQueryResult

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

the class TestAWSCostAdapterService method verifyPersistedStats.

private void verifyPersistedStats(EndpointAllocationTaskState completeState, String metric, int expectedCount) {
    this.host.waitFor("Timeout waiting for stats", () -> {
        QueryTask.QuerySpecification querySpec = new QueryTask.QuerySpecification();
        querySpec.query = QueryTask.Query.Builder.create().addKindFieldClause(ResourceMetrics.class).addFieldClause(ServiceDocument.FIELD_NAME_SELF_LINK, UriUtils.buildUriPath(ResourceMetricsService.FACTORY_LINK, UriUtils.getLastPathSegment(completeState.endpointState.computeLink)), QueryTask.QueryTerm.MatchType.PREFIX).addRangeClause(buildCompositeFieldName(ResourceMetrics.FIELD_NAME_ENTRIES, metric), createDoubleRange(0.0, Double.MAX_VALUE, true, true)).build();
        querySpec.options.add(QueryTask.QuerySpecification.QueryOption.EXPAND_CONTENT);
        ServiceDocumentQueryResult result = this.host.createAndWaitSimpleDirectQuery(querySpec, expectedCount, expectedCount);
        boolean statsCollected = true;
        for (Object metrics : result.documents.values()) {
            ResourceMetrics rawMetrics = Utils.fromJson(metrics, ResourceMetrics.class);
            Double rawMetric = rawMetrics.entries.get(metric);
            if (rawMetric != null) {
                continue;
            }
            statsCollected = false;
        }
        if (metric.equalsIgnoreCase(AWSConstants.COST)) {
            List<ResourceMetrics> accountOneTimeCharges = result.documents.values().stream().map(o -> Utils.fromJson(o, ResourceMetrics.class)).filter(m -> m.entries.containsKey(PhotonModelConstants.ACCOUNT_ONE_TIME_CHARGES)).collect(Collectors.toList());
            if (accountOneTimeCharges.size() != result.documentCount) {
                statsCollected = false;
            }
        }
        return statsCollected;
    });
}
Also used : DateTimeZone(org.joda.time.DateTimeZone) BaseModelTest(com.vmware.photon.controller.model.helpers.BaseModelTest) QueryTask(com.vmware.xenon.services.common.QueryTask) StatsCollectionTaskState(com.vmware.photon.controller.model.tasks.monitoring.StatsCollectionTaskService.StatsCollectionTaskState) ServiceDocument(com.vmware.xenon.common.ServiceDocument) EndpointAllocationTaskService(com.vmware.photon.controller.model.tasks.EndpointAllocationTaskService) SingleResourceStatsCollectionTaskState(com.vmware.photon.controller.model.tasks.monitoring.SingleResourceStatsCollectionTaskService.SingleResourceStatsCollectionTaskState) CommandLineArgumentParser(com.vmware.xenon.common.CommandLineArgumentParser) Utils(com.vmware.xenon.common.Utils) QuerySpecification.buildCompositeFieldName(com.vmware.xenon.services.common.QueryTask.QuerySpecification.buildCompositeFieldName) Map(java.util.Map) After(org.junit.After) ServiceDocumentQueryResult(com.vmware.xenon.common.ServiceDocumentQueryResult) StatsCollectionTaskService(com.vmware.photon.controller.model.tasks.monitoring.StatsCollectionTaskService) EnumSet(java.util.EnumSet) EndpointState(com.vmware.photon.controller.model.resources.EndpointService.EndpointState) EndpointAllocationTaskState(com.vmware.photon.controller.model.tasks.EndpointAllocationTaskService.EndpointAllocationTaskState) ComputeStatsRequest(com.vmware.photon.controller.model.adapterapi.ComputeStatsRequest) StatelessService(com.vmware.xenon.common.StatelessService) INSTANCE_1_SELF_LINK(com.vmware.photon.controller.model.adapters.awsadapter.MockCostStatsAdapterService.INSTANCE_1_SELF_LINK) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) List(java.util.List) UriUtils(com.vmware.xenon.common.UriUtils) TaskState(com.vmware.xenon.common.TaskState) AwsServices(com.vmware.photon.controller.model.adapters.awsadapter.util.AWSCsvBillParser.AwsServices) TaskOption(com.vmware.photon.controller.model.tasks.TaskOption) ResourceMetrics(com.vmware.photon.controller.model.monitoring.ResourceMetricsService.ResourceMetrics) ResourcePoolState(com.vmware.photon.controller.model.resources.ResourcePoolService.ResourcePoolState) HashMap(java.util.HashMap) ResourceMetricsService(com.vmware.photon.controller.model.monitoring.ResourceMetricsService) Function(java.util.function.Function) ArrayList(java.util.ArrayList) EndpointConfigRequest(com.vmware.photon.controller.model.adapterapi.EndpointConfigRequest) NumericRange.createDoubleRange(com.vmware.xenon.services.common.QueryTask.NumericRange.createDoubleRange) ComputeState(com.vmware.photon.controller.model.resources.ComputeService.ComputeState) ComputeStats(com.vmware.photon.controller.model.adapterapi.ComputeStatsResponse.ComputeStats) PhotonModelTaskServices(com.vmware.photon.controller.model.tasks.PhotonModelTaskServices) Operation(com.vmware.xenon.common.Operation) Assert.assertTrue(org.junit.Assert.assertTrue) SingleResourceStatsCollectionTaskService(com.vmware.photon.controller.model.tasks.monitoring.SingleResourceStatsCollectionTaskService) Test(org.junit.Test) ServiceStat(com.vmware.xenon.common.ServiceStats.ServiceStat) LocalDate(org.joda.time.LocalDate) PhotonModelAdaptersRegistryAdapters(com.vmware.photon.controller.model.adapters.registry.PhotonModelAdaptersRegistryAdapters) AWSStatsNormalizer(com.vmware.photon.controller.model.adapters.awsadapter.util.AWSStatsNormalizer) PhotonModelConstants(com.vmware.photon.controller.model.constants.PhotonModelConstants) INSTANCE_2_SELF_LINK(com.vmware.photon.controller.model.adapters.awsadapter.MockCostStatsAdapterService.INSTANCE_2_SELF_LINK) Collections(java.util.Collections) Assert.assertEquals(org.junit.Assert.assertEquals) ResourceMetrics(com.vmware.photon.controller.model.monitoring.ResourceMetricsService.ResourceMetrics) QueryTask(com.vmware.xenon.services.common.QueryTask) ServiceDocumentQueryResult(com.vmware.xenon.common.ServiceDocumentQueryResult)

Example 5 with ServiceDocumentQueryResult

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

the class ProvisioningUtils method getResourceStates.

public static <K extends ResourceState> Map<String, K> getResourceStates(VerificationHost host, URI peerURI, String serviceFactoryLink, Class<K> resourceStateClass) throws Throwable {
    Map<String, K> elementStateMap = new HashMap<>();
    ServiceDocumentQueryResult res;
    res = host.getFactoryState(UriUtils.buildExpandLinksQueryUri(createServiceURI(host, peerURI, serviceFactoryLink)));
    if (res != null && res.documentCount > 0) {
        for (Object s : res.documents.values()) {
            K elementState = Utils.fromJson(s, resourceStateClass);
            elementStateMap.put(elementState.id, elementState);
        }
    }
    return elementStateMap;
}
Also used : HashMap(java.util.HashMap) 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