use of com.vmware.photon.controller.model.resources.ComputeService.ComputeState in project photon-model by vmware.
the class EndpointRemovalTaskServiceTest method createComputeState.
private static void createComputeState(BaseModelTest test, String endpointLink, List<String> tenantLinks) throws Throwable {
ComputeState cs = new ComputeState();
cs.id = UUID.randomUUID().toString();
cs.name = "computeState";
cs.descriptionLink = "descriptionLink";
cs.tenantLinks = tenantLinks;
cs.endpointLink = endpointLink;
cs.endpointLinks = new HashSet<String>();
cs.endpointLinks.add(endpointLink);
test.postServiceSynchronously(ComputeService.FACTORY_LINK, cs, ComputeService.ComputeState.class);
}
use of com.vmware.photon.controller.model.resources.ComputeService.ComputeState in project photon-model by vmware.
the class ResourceIPDeallocationTaskService method getComputeResource.
private DeferredResult<ResourceIPDeallocationContext> getComputeResource(ResourceIPDeallocationContext ctx) {
Operation op = Operation.createGet(ComputeService.ComputeStateWithDescription.buildUri(UriUtils.buildUri(getHost(), ctx.resourceLink)));
return sendWithDeferredResult(op, ComputeState.class).thenApply(computeState -> {
ctx.computeResource = computeState;
logFine("Retrieved resource [%s]", ctx.resourceLink);
return ctx;
});
}
use of com.vmware.photon.controller.model.resources.ComputeService.ComputeState in project photon-model by vmware.
the class TagGroomerTaskServiceTest method createComputesWithTags.
/**
* Create n computes associated with specific tags
*/
private void createComputesWithTags(int count, List<String> tagLinks) {
ComputeState computeState = new ComputeState();
computeState.descriptionLink = "description-link";
computeState.id = UUID.randomUUID().toString();
computeState.name = computeState.id;
computeState.tagLinks = new HashSet<>();
for (int i = 0; i < count; i++) {
computeState.tagLinks.add(tagLinks.get(i));
Operation op = Operation.createPost(UriUtils.buildUri(this.host, ComputeService.FACTORY_LINK)).setBody(computeState);
this.host.waitForResponse(op);
// clear tagLinks and assign new one on the next round
computeState.tagLinks.clear();
}
}
use of com.vmware.photon.controller.model.resources.ComputeService.ComputeState 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.resources.ComputeService.ComputeState in project photon-model by vmware.
the class ResourceGroomerTaskServiceTest method createComputes.
/**
* Create given number of computes with given endpointLinks and tenantLink.
*/
private List<String> createComputes(int count, Set<String> endpointLinks, String tenantLink, String endpointLink) {
List<String> computeLinks = new ArrayList<>();
ComputeState computeState = new ComputeState();
computeState.descriptionLink = "description-link";
computeState.id = UUID.randomUUID().toString();
computeState.name = computeState.id;
computeState.tenantLinks = Collections.singletonList(tenantLink);
computeState.endpointLinks = endpointLinks;
computeState.endpointLink = endpointLink;
for (int i = 0; i < count; i++) {
Operation op = Operation.createPost(UriUtils.buildUri(this.host, ComputeService.FACTORY_LINK)).setBody(computeState);
Operation response = this.host.waitForResponse(op);
if (response.getStatusCode() == Operation.STATUS_CODE_OK) {
computeLinks.add(response.getBody(ComputeState.class).documentSelfLink);
}
}
return computeLinks;
}
Aggregations