use of com.vmware.photon.controller.model.adapterapi.ComputeStatsResponse in project photon-model by vmware.
the class TestAzureProvisionTask method issueStatsRequest.
private void issueStatsRequest(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) {
if (!TestAzureProvisionTask.this.isMock) {
ComputeStatsResponse resp = op.getBody(ComputeStatsResponse.class);
if (resp.statsList.size() != 1) {
TestAzureProvisionTask.this.host.failIteration(new IllegalStateException("response size was incorrect."));
return;
}
if (resp.statsList.get(0).statValues.size() == 0) {
TestAzureProvisionTask.this.host.failIteration(new IllegalStateException("incorrect number of metrics received."));
return;
}
if (!resp.statsList.get(0).computeLink.equals(vm.documentSelfLink)) {
TestAzureProvisionTask.this.host.failIteration(new IllegalStateException("Incorrect computeReference returned."));
return;
}
}
TestAzureProvisionTask.this.host.completeIteration();
}
}
};
String servicePath = UUID.randomUUID().toString();
Operation startOp = Operation.createPost(UriUtils.buildUri(getHost(), servicePath));
getHost().startService(startOp, parentService);
ComputeStatsRequest statsRequest = new ComputeStatsRequest();
statsRequest.resourceReference = UriUtils.buildUri(getHost(), vm.documentSelfLink);
statsRequest.isMockRequest = this.isMock;
statsRequest.taskReference = UriUtils.buildUri(getHost(), servicePath);
getHost().sendAndWait(Operation.createPatch(UriUtils.buildUri(getHost(), AzureUriPaths.AZURE_STATS_ADAPTER)).setBody(statsRequest).setReferer(getHost().getUri()));
}
use of com.vmware.photon.controller.model.adapterapi.ComputeStatsResponse in project photon-model by vmware.
the class TestAzureEnumerationTask method issueStatsRequest.
private void issueStatsRequest(String selfLink, boolean isComputeHost) 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 (!TestAzureEnumerationTask.this.isMock) {
ComputeStatsResponse resp = op.getBody(ComputeStatsResponse.class);
if (resp == null) {
TestAzureEnumerationTask.this.host.failIteration(new IllegalStateException("response was null."));
return;
}
if (resp.statsList.size() != 1) {
TestAzureEnumerationTask.this.host.failIteration(new IllegalStateException("response size was incorrect."));
return;
}
if (resp.statsList.get(0).statValues.size() == 0) {
TestAzureEnumerationTask.this.host.failIteration(new IllegalStateException("incorrect number of metrics received."));
return;
}
if (!resp.statsList.get(0).computeLink.equals(selfLink)) {
TestAzureEnumerationTask.this.host.failIteration(new IllegalStateException("Incorrect resourceReference returned."));
return;
}
// Verify all the stats are obtained
verifyStats(resp, isComputeHost);
// Persist stats on Verification Host for testing the computeHost stats.
URI persistStatsUri = UriUtils.buildUri(getHost(), ResourceMetricsService.FACTORY_LINK);
ResourceMetricsService.ResourceMetrics resourceMetric = new ResourceMetricsService.ResourceMetrics();
resourceMetric.documentSelfLink = StatsUtil.getMetricKey(selfLink, Utils.getNowMicrosUtc());
resourceMetric.entries = new HashMap<>();
resourceMetric.timestampMicrosUtc = Utils.getNowMicrosUtc();
for (String key : resp.statsList.get(0).statValues.keySet()) {
List<ServiceStat> stats = resp.statsList.get(0).statValues.get(key);
for (ServiceStat stat : stats) {
if (stat == null) {
continue;
}
resourceMetric.entries.put(key, stat.latestValue);
}
}
TestAzureEnumerationTask.this.host.sendRequest(Operation.createPost(persistStatsUri).setReferer(TestAzureEnumerationTask.this.host.getUri()).setBodyNoCloning(resourceMetric));
}
TestAzureEnumerationTask.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, selfLink);
statsRequest.nextStage = SingleResourceTaskCollectionStage.UPDATE_STATS.name();
statsRequest.isMockRequest = this.isMock;
statsRequest.taskReference = UriUtils.buildUri(this.host, servicePath);
this.host.sendAndWait(Operation.createPatch(UriUtils.buildUri(this.host, AzureUriPaths.AZURE_STATS_ADAPTER)).setBody(statsRequest).setReferer(this.host.getUri()));
}
use of com.vmware.photon.controller.model.adapterapi.ComputeStatsResponse in project photon-model by vmware.
the class TestGCPStatsCollection method issueStatsRequest.
/**
* Creates a stateless service which will call GCPStatsService to collect stats of the
* resource specified by the argument.
* Receives response back and patches it to the caller service.
* @param selfLink The self link to the document of enumerated resource.
* @throws Throwable
*/
public void issueStatsRequest(String selfLink) 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 (!TestGCPStatsCollection.this.isMock) {
ComputeStatsResponse resp = op.getBody(ComputeStatsResponse.class);
if (resp == null) {
TestGCPStatsCollection.this.host.failIteration(new IllegalStateException("response was null."));
return;
}
if (resp.statsList.size() != 1) {
TestGCPStatsCollection.this.host.failIteration(new IllegalStateException("response size was incorrect."));
return;
}
if (resp.statsList.get(0).statValues.size() != 9) {
TestGCPStatsCollection.this.host.failIteration(new IllegalStateException("incorrect number of metrics received."));
return;
}
if (!resp.statsList.get(0).computeLink.equals(selfLink)) {
TestGCPStatsCollection.this.host.failIteration(new IllegalStateException("Incorrect resourceReference returned."));
return;
}
}
TestGCPStatsCollection.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, selfLink);
statsRequest.isMockRequest = this.isMock;
statsRequest.taskReference = UriUtils.buildUri(this.host, servicePath);
this.host.sendAndWait(Operation.createPatch(UriUtils.buildUri(this.host, GCPUriPaths.GCP_STATS_ADAPTER)).setBody(statsRequest).setReferer(this.host.getUri()));
}
use of com.vmware.photon.controller.model.adapterapi.ComputeStatsResponse 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.ComputeStatsResponse 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