use of com.vmware.photon.controller.model.tasks.monitoring.StatsAggregationTaskService.StatsAggregationTaskState in project photon-model by vmware.
the class StatsAggregationTaskServiceTest method testStatsAggregation.
private void testStatsAggregation(boolean testOnCluster) throws Throwable {
VerificationHost metricHost = null;
if (testOnCluster) {
metricHost = this.setupMetricHost();
}
// Use this.host if metricHost is null.
VerificationHost verificationHost = (metricHost == null ? this.host : metricHost);
// create a resource pool
ResourcePoolState rpState = new ResourcePoolState();
rpState.name = "testName";
ResourcePoolState rpReturnState = postServiceSynchronously(ResourcePoolService.FACTORY_LINK, rpState, ResourcePoolState.class);
ComputeDescription cDesc = new ComputeDescription();
cDesc.name = rpState.name;
cDesc.statsAdapterReference = UriUtils.buildUri(this.host, MockStatsAdapter.SELF_LINK);
ComputeDescription descReturnState = postServiceSynchronously(ComputeDescriptionService.FACTORY_LINK, cDesc, ComputeDescription.class);
ComputeState computeState = new ComputeState();
computeState.name = rpState.name;
computeState.descriptionLink = descReturnState.documentSelfLink;
computeState.resourcePoolLink = rpReturnState.documentSelfLink;
List<String> computeLinks = new ArrayList<>();
for (int i = 0; i < this.numResources; i++) {
ComputeState res = postServiceSynchronously(ComputeService.FACTORY_LINK, computeState, ComputeState.class);
computeLinks.add(res.documentSelfLink);
}
// kick off an aggregation task when stats are not populated
StatsAggregationTaskState aggregationTaskState = new StatsAggregationTaskState();
Query taskQuery = Query.Builder.create().addFieldClause(ComputeState.FIELD_NAME_RESOURCE_POOL_LINK, rpReturnState.documentSelfLink).build();
aggregationTaskState.query = taskQuery;
aggregationTaskState.metricNames = Collections.singleton(MockStatsAdapter.KEY_1);
aggregationTaskState.taskInfo = TaskState.createDirect();
postServiceSynchronously(StatsAggregationTaskService.FACTORY_LINK, aggregationTaskState, StatsAggregationTaskState.class);
this.host.waitFor("Error waiting for stats", () -> {
ServiceDocumentQueryResult aggrRes = verificationHost.getFactoryState(UriUtils.buildUri(verificationHost, ResourceMetricsService.FACTORY_LINK));
// Expect 0 stats because they're not collected yet
if (aggrRes.documentCount == 0) {
return true;
}
return false;
});
StatsCollectionTaskState collectionTaskState = new StatsCollectionTaskState();
collectionTaskState.resourcePoolLink = rpReturnState.documentSelfLink;
collectionTaskState.taskInfo = TaskState.createDirect();
postServiceSynchronously(StatsCollectionTaskService.FACTORY_LINK, collectionTaskState, StatsCollectionTaskState.class);
int numberOfRawMetrics = this.numResources * 4;
// kick off an aggregation task
aggregationTaskState = new StatsAggregationTaskState();
aggregationTaskState.query = taskQuery;
aggregationTaskState.metricNames = Collections.singleton(MockStatsAdapter.KEY_1);
aggregationTaskState.taskInfo = TaskState.createDirect();
postServiceSynchronously(StatsAggregationTaskService.FACTORY_LINK, aggregationTaskState, StatsAggregationTaskState.class);
this.host.waitFor("Error waiting for stats", () -> {
ServiceDocumentQueryResult aggrRes = verificationHost.getFactoryState(UriUtils.buildUri(verificationHost, ResourceMetricsService.FACTORY_LINK));
if (aggrRes.documentCount == this.numResources + numberOfRawMetrics) {
return true;
}
return false;
});
// verify that the aggregation tasks have been deleted
this.host.waitFor("Timeout waiting for task to expire", () -> {
ServiceDocumentQueryResult res = this.host.getFactoryState(UriUtils.buildUri(this.host, StatsAggregationTaskService.FACTORY_LINK));
if (res.documentLinks.size() == 0) {
return true;
}
return false;
});
if (testOnCluster) {
this.cleanUpMetricHost(metricHost);
}
}
use of com.vmware.photon.controller.model.tasks.monitoring.StatsAggregationTaskService.StatsAggregationTaskState in project photon-model by vmware.
the class MetricsClusterTest method testStatsCollectorCreation.
@Test
public void testStatsCollectorCreation() throws Throwable {
// create a resource pool
ResourcePoolState rpState = new ResourcePoolState();
rpState.name = UUID.randomUUID().toString();
ResourcePoolState rpReturnState = postServiceSynchronously(ResourcePoolService.FACTORY_LINK, rpState, ResourcePoolState.class);
// create a compute description for all the computes
ComputeDescription cDesc = new ComputeDescription();
cDesc.name = UUID.randomUUID().toString();
cDesc.statsAdapterReference = UriUtils.buildUri(this.host, MockStatsAdapter.SELF_LINK);
ComputeDescription descReturnState = postServiceSynchronously(ComputeDescriptionService.FACTORY_LINK, cDesc, ComputeDescription.class);
// create multiple computes
ComputeState computeState = new ComputeState();
computeState.name = UUID.randomUUID().toString();
computeState.descriptionLink = descReturnState.documentSelfLink;
computeState.resourcePoolLink = rpReturnState.documentSelfLink;
List<String> computeLinks = new ArrayList<>(this.numResources);
for (int i = 0; i < this.numResources; i++) {
ComputeState res = postServiceSynchronously(ComputeService.FACTORY_LINK, computeState, ComputeState.class);
computeLinks.add(res.documentSelfLink);
}
// Run a stats collection on the resources
StatsCollectionTaskState collectionTaskState = new StatsCollectionTaskState();
collectionTaskState.resourcePoolLink = rpReturnState.documentSelfLink;
collectionTaskState.options = EnumSet.of(TaskOption.SELF_DELETE_ON_COMPLETION);
collectionTaskState.taskInfo = TaskState.createDirect();
postServiceSynchronously(StatsCollectionTaskService.FACTORY_LINK, collectionTaskState, StatsCollectionTaskState.class);
int numberOfRawMetrics = this.numResources * 4;
// verify that the collection tasks have been deleted
this.host.waitFor("Timeout waiting for task to expire", () -> {
ServiceDocumentQueryResult collectRes = this.host.getFactoryState(UriUtils.buildUri(this.host, StatsCollectionTaskService.FACTORY_LINK));
if (collectRes.documentLinks.size() == 0) {
return true;
}
return false;
});
// Get a Count on this.host() for Resource metrics
Long resourceHostResourceMetricCount = this.getDocumentCount(this.host, ResourceMetricsService.FACTORY_LINK);
// Get a Count on this.metricHost() for ResourceMetrics
Long metricHostResourceMetricCount = this.getDocumentCount(this.metricHost, ResourceMetricsService.FACTORY_LINK);
// Count should be 0 on this.host()
assertEquals(0, resourceHostResourceMetricCount.intValue());
// Count should be something on this.metricHost()
assertEquals(this.numResources * 4, metricHostResourceMetricCount.intValue());
// Kick off an Aggregation Task - Verifies that the ResourceMetricQueries are going to the right cluster.
StatsAggregationTaskState aggregationTaskState = new StatsAggregationTaskState();
Query taskQuery = Query.Builder.create().addFieldClause(ComputeState.FIELD_NAME_RESOURCE_POOL_LINK, rpReturnState.documentSelfLink).build();
aggregationTaskState.query = taskQuery;
aggregationTaskState.metricNames = Collections.singleton(MockStatsAdapter.KEY_1);
aggregationTaskState.taskInfo = TaskState.createDirect();
postServiceSynchronously(StatsAggregationTaskService.FACTORY_LINK, aggregationTaskState, StatsAggregationTaskState.class);
// verify that the aggregation tasks have been deleted
this.host.waitFor("Timeout waiting for task to expire", () -> {
ServiceDocumentQueryResult res = this.host.getFactoryState(UriUtils.buildUri(this.host, StatsAggregationTaskService.FACTORY_LINK));
if (res.documentLinks.size() == 0) {
return true;
}
return false;
});
this.host.waitFor("Error waiting for stats", () -> {
ServiceDocumentQueryResult aggrRes = this.metricHost.getFactoryState(UriUtils.buildUri(this.metricHost, ResourceMetricsService.FACTORY_LINK));
if (aggrRes.documentCount == (this.numResources + numberOfRawMetrics)) {
return true;
}
return false;
});
// Get a Count on this.host() for Aggregate metrics
Long resourceHostAggregateMetricCount = this.getDocumentCount(this.host, ResourceMetricsService.FACTORY_LINK);
// Get a Count on this.metricHost() for Aggregate Metrics
Long metricHostAggregateMetricCount = this.getDocumentCount(this.metricHost, ResourceMetricsService.FACTORY_LINK);
// Count should be 0 on this.host()
assertEquals(0, resourceHostAggregateMetricCount.intValue());
// Count should be something on this.metricHost()
assertEquals((this.numResources + numberOfRawMetrics), metricHostAggregateMetricCount.intValue());
}
use of com.vmware.photon.controller.model.tasks.monitoring.StatsAggregationTaskService.StatsAggregationTaskState in project photon-model by vmware.
the class AzureTestUtil method resourceStatsAggregation.
/**
* Performs stats collection for given resourcePoolLink.
*/
public static void resourceStatsAggregation(VerificationHost host, String resourcePoolLink) throws Throwable {
host.testStart(1);
StatsAggregationTaskState statsAggregationTaskState = new StatsAggregationTaskState();
QueryTask.Query taskQuery = QueryTask.Query.Builder.create().addKindFieldClause(ComputeState.class).addFieldClause(ComputeState.FIELD_NAME_RESOURCE_POOL_LINK, resourcePoolLink).build();
statsAggregationTaskState.query = taskQuery;
statsAggregationTaskState.taskInfo = TaskState.createDirect();
statsAggregationTaskState.metricNames = getMetricNames();
host.send(Operation.createPost(UriUtils.buildUri(host, StatsAggregationTaskService.FACTORY_LINK)).setBody(statsAggregationTaskState).setCompletion(host.getCompletion()));
host.testWait();
}
use of com.vmware.photon.controller.model.tasks.monitoring.StatsAggregationTaskService.StatsAggregationTaskState in project photon-model by vmware.
the class TestAWSSetupUtils method resourceStatsAggregation.
/**
* Performs stats aggregation for given resourcePoolLink
*/
public static void resourceStatsAggregation(VerificationHost host, String resourcePoolLink) throws Throwable {
host.testStart(1);
StatsAggregationTaskState statsAggregationTaskState = new StatsAggregationTaskState();
Query taskQuery = Query.Builder.create().addKindFieldClause(ComputeState.class).addFieldClause(ComputeState.FIELD_NAME_RESOURCE_POOL_LINK, resourcePoolLink).build();
statsAggregationTaskState.query = taskQuery;
statsAggregationTaskState.taskInfo = TaskState.createDirect();
statsAggregationTaskState.metricNames = getMetricNames();
host.send(Operation.createPost(UriUtils.buildUri(host, StatsAggregationTaskService.FACTORY_LINK)).setBody(statsAggregationTaskState).setCompletion(host.getCompletion()));
host.testWait();
}
Aggregations