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;
});
}
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);
}
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;
});
}
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;
});
}
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;
}
Aggregations