use of com.vmware.photon.controller.model.adapterapi.ComputeStatsRequest 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.ComputeStatsRequest 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.ComputeStatsRequest in project photon-model by vmware.
the class GCPStatsService method handlePatch.
/**
* The REST PATCH request handler. This is the entry of starting stats collection.
* @param patch Operation which should contain request body.
*/
@Override
public void handlePatch(Operation patch) {
setOperationHandlerInvokeTimeStat(patch);
if (!patch.hasBody()) {
patch.fail(new IllegalArgumentException("body is required"));
return;
}
patch.complete();
ComputeStatsRequest statsRequest = patch.getBody(ComputeStatsRequest.class);
GCPStatsDataHolder statsData = new GCPStatsDataHolder(patch);
statsData.statsRequest = statsRequest;
statsData.taskManager = new TaskManager(this, statsRequest.taskReference, statsRequest.resourceLink());
// If mock mode is enabled, patch back to the parent.
if (statsData.statsRequest.isMockRequest) {
statsData.stage = StatsCollectionStage.FINISHED;
handleStatsRequest(statsData);
} else {
statsData.stage = StatsCollectionStage.VM_DESC;
handleStatsRequest(statsData);
}
}
use of com.vmware.photon.controller.model.adapterapi.ComputeStatsRequest in project photon-model by vmware.
the class AWSStatsService method handlePatch.
@Override
public void handlePatch(Operation op) {
if (!op.hasBody()) {
op.fail(new IllegalArgumentException("body is required"));
return;
}
ComputeStatsRequest statsRequest = op.getBody(ComputeStatsRequest.class);
op.complete();
TaskManager taskManager = new TaskManager(this, statsRequest.taskReference, statsRequest.resourceLink());
if (statsRequest.isMockRequest) {
// patch status to parent task
taskManager.finishTask();
return;
}
AWSStatsDataHolder statsData = new AWSStatsDataHolder();
statsData.statsRequest = statsRequest;
statsData.taskManager = taskManager;
getVMDescription(statsData);
}
use of com.vmware.photon.controller.model.adapterapi.ComputeStatsRequest in project photon-model by vmware.
the class AWSCostStatsService method handlePatch.
@Override
public void handlePatch(Operation op) {
if (!op.hasBody()) {
op.fail(new IllegalArgumentException("body is required"));
return;
}
op.complete();
ComputeStatsRequest statsRequest = op.getBody(ComputeStatsRequest.class);
TaskManager taskManager = new TaskManager(this, statsRequest.taskReference, statsRequest.resourceLink());
if (statsRequest.isMockRequest) {
// patch status to parent task
taskManager.finishTask();
return;
}
AWSCostStatsCreationContext statsData = new AWSCostStatsCreationContext(statsRequest);
statsData.taskManager = taskManager;
handleCostStatsCreationRequest(statsData);
}
Aggregations