use of com.vmware.photon.controller.model.adapterapi.ComputeStatsRequest in project photon-model by vmware.
the class TestAWSProvisionTask method issueStatsRequest.
private void issueStatsRequest(ComputeState vm, Long lastCollectionTime) 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) {
if (!TestAWSProvisionTask.this.isMock) {
ComputeStatsResponse resp = op.getBody(ComputeStatsResponse.class);
if (resp.statsList.size() != 1) {
TestAWSProvisionTask.this.host.failIteration(new IllegalStateException("response size was incorrect."));
return;
}
// Size == 1, because APICallCount
if (resp.statsList.get(0).statValues.size() == 1) {
TestAWSProvisionTask.this.host.failIteration(new IllegalStateException("incorrect number of metrics received."));
return;
}
if (lastCollectionTime != null) {
if (resp.statsList.get(0).statValues.get(PhotonModelConstants.CPU_UTILIZATION_PERCENT).size() < 2) {
TestAWSProvisionTask.this.host.failIteration(new IllegalStateException("incorrect number of data points received when collection window is specified."));
return;
}
}
if (!resp.statsList.get(0).computeLink.equals(vm.documentSelfLink)) {
TestAWSProvisionTask.this.host.failIteration(new IllegalStateException("Incorrect resourceReference returned."));
return;
}
verifyCollectedStats(resp, lastCollectionTime);
}
TestAWSProvisionTask.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);
if (lastCollectionTime != null) {
statsRequest.lastCollectionTimeMicrosUtc = lastCollectionTime;
}
this.host.sendAndWait(Operation.createPatch(UriUtils.buildUri(this.host, AWSUriPaths.AWS_STATS_ADAPTER)).setBody(statsRequest).setReferer(this.host.getUri()));
}
use of com.vmware.photon.controller.model.adapterapi.ComputeStatsRequest in project photon-model by vmware.
the class TestAWSCostAdapterService method sendStatsRequest.
private void sendStatsRequest(ComputeState account, StatelessService parentService) throws Throwable {
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, account.documentSelfLink);
statsRequest.taskReference = UriUtils.buildUri(this.host, servicePath);
statsRequest.isMockRequest = !this.isMock;
statsRequest.nextStage = SingleResourceStatsCollectionTaskService.SingleResourceTaskCollectionStage.UPDATE_STATS.name();
this.host.sendAndWait(Operation.createPatch(UriUtils.buildUri(this.host, MockCostStatsAdapterService.SELF_LINK)).setBody(statsRequest).setReferer(this.host.getUri()));
}
use of com.vmware.photon.controller.model.adapterapi.ComputeStatsRequest 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()));
}
use of com.vmware.photon.controller.model.adapterapi.ComputeStatsRequest in project photon-model by vmware.
the class SingleResourceStatsCollectionTaskService method getDescriptions.
private void getDescriptions(SingleResourceStatsCollectionTaskState currentState) {
URI computeDescUri = ComputeStateWithDescription.buildUri(UriUtils.extendUri(ClusterUtil.getClusterUri(getHost(), ServiceTypeCluster.INVENTORY_SERVICE), currentState.computeLink));
sendRequest(Operation.createGet(computeDescUri).setCompletion((getOp, getEx) -> {
if (getEx != null) {
TaskUtils.sendFailurePatch(this, currentState, getEx);
return;
}
ComputeStateWithDescription computeStateWithDesc = getOp.getBody(ComputeStateWithDescription.class);
ComputeStatsRequest statsRequest = new ComputeStatsRequest();
statsRequest.isMockRequest = currentState.options != null ? currentState.options.contains(TaskOption.IS_MOCK) : false;
URI patchUri = null;
Object patchBody = null;
ComputeDescription description = computeStateWithDesc.description;
URI statsAdapterReference = null;
List<String> tenantLinks = new ArrayList<>();
if (description != null) {
tenantLinks = description.tenantLinks;
// provided
if (currentState.statsAdapterReference == null) {
statsAdapterReference = description.statsAdapterReference;
} else if (description.statsAdapterReferences != null) {
for (URI uri : description.statsAdapterReferences) {
if (uri.getPath().equals(currentState.statsAdapterReference.getPath())) {
statsAdapterReference = currentState.statsAdapterReference;
break;
}
}
}
}
if (statsAdapterReference != null) {
statsRequest.nextStage = SingleResourceTaskCollectionStage.UPDATE_STATS.name();
statsRequest.resourceReference = UriUtils.extendUri(ClusterUtil.getClusterUri(getHost(), ServiceTypeCluster.INVENTORY_SERVICE), computeStateWithDesc.documentSelfLink);
statsRequest.taskReference = getUri();
patchUri = statsAdapterReference;
populateLastCollectionTimeForMetricsInStatsRequest(currentState, statsRequest, patchUri, tenantLinks);
} else {
// no adapter associated with this resource, just patch completion
SingleResourceStatsCollectionTaskState nextStageState = new SingleResourceStatsCollectionTaskState();
nextStageState.taskInfo = new TaskState();
nextStageState.taskInfo.stage = TaskStage.FINISHED;
patchUri = getUri();
patchBody = nextStageState;
sendStatsRequestToAdapter(currentState, patchUri, patchBody);
}
}));
}
Aggregations