use of com.vmware.xenon.common.StatelessService in project photon-model by vmware.
the class TestAWSCostAdapterService method issueStatsRequest.
private void issueStatsRequest(ComputeState account) throws Throwable {
List<ComputeStats> allStats = new ArrayList<>();
// spin up a stateless service that acts as the parent link to patch back to
StatelessService parentService = new StatelessService() {
@Override
public void handleRequest(Operation op) {
if (op.getAction() == Action.PATCH) {
if (TestAWSCostAdapterService.this.isMock) {
SingleResourceStatsCollectionTaskState resp = op.getBody(SingleResourceStatsCollectionTaskState.class);
allStats.addAll(resp.statsList);
if (resp.isFinalBatch) {
verifyCollectedStats(allStats);
TestAWSCostAdapterService.this.host.completeIteration();
}
} else {
TestAWSCostAdapterService.this.host.completeIteration();
}
}
}
};
sendStatsRequest(account, parentService);
}
use of com.vmware.xenon.common.StatelessService in project photon-model by vmware.
the class TestAWSEnumerationAtScale method issueMockStatsRequest.
/**
* Verify whether the mock stats gathered are correct or not.
* @param vm The AWS VM compute state.
* @throws Throwable
*/
private void issueMockStatsRequest(ComputeService.ComputeState vm) throws Throwable {
// spin up a stateless service that acts as the parent link to patch back to
StatelessService parentService = new StatelessService() {
@Override
public void handleRequest(Operation op) {
if (op.getAction() == Action.PATCH) {
ComputeStatsResponse resp = op.getBody(ComputeStatsResponse.class);
if (resp.statsList.size() != 1) {
TestAWSEnumerationAtScale.this.host.failIteration(new IllegalStateException("response size was incorrect."));
return;
}
if (resp.statsList.get(0).statValues.size() != MOCK_STATS_SIZE) {
TestAWSEnumerationAtScale.this.host.failIteration(new IllegalStateException("incorrect number of metrics received."));
return;
}
if (!resp.statsList.get(0).computeLink.equals(vm.documentSelfLink)) {
TestAWSEnumerationAtScale.this.host.failIteration(new IllegalStateException("Incorrect resourceReference returned."));
return;
}
verifyCollectedMockStats(resp);
TestAWSEnumerationAtScale.this.host.completeIteration();
}
}
};
String servicePath = UUID.randomUUID().toString();
Operation startOp = Operation.createPost(UriUtils.buildUri(this.host, servicePath));
this.host.startService(startOp, parentService);
ComputeStatsRequest statsRequest = new ComputeStatsRequest();
statsRequest.resourceReference = UriUtils.buildUri(this.host, vm.documentSelfLink);
statsRequest.isMockRequest = this.isMock;
statsRequest.nextStage = SingleResourceTaskCollectionStage.UPDATE_STATS.name();
statsRequest.taskReference = UriUtils.buildUri(this.host, servicePath);
this.host.sendAndWait(Operation.createPatch(UriUtils.buildUri(this.host, AWSMockStatsService.SELF_LINK)).setBody(statsRequest).setReferer(this.host.getUri()));
}
Aggregations