use of com.vmware.photon.controller.model.adapterapi.ComputeStatsRequest in project photon-model by vmware.
the class VSphereAdapterStatsService 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);
ProvisionContext.populateContextThen(this, createInitialContext(statsRequest, op), ctx -> {
if (statsRequest.isMockRequest) {
// patch status to parent task
persistStats(mockStats(), statsRequest);
ctx.mgr.patchTask(TaskStage.FINISHED);
return;
}
collectStats(ctx, statsRequest);
});
}
use of com.vmware.photon.controller.model.adapterapi.ComputeStatsRequest in project photon-model by vmware.
the class AzureStatsService method getVMDescription.
private void getVMDescription(AzureStatsDataHolder statsData) {
Consumer<Operation> onSuccess = (op) -> {
statsData.computeDesc = op.getBody(ComputeStateWithDescription.class);
boolean isComputeHost = isComputeHost(statsData.computeDesc.description);
// response directly to the task which called it.
if (!isComputeHost) {
ComputeStatsRequest statsRequest = statsData.statsRequest;
Operation statsOp = Operation.createPatch(UriUtils.buildUri(getHost(), AzureUriPaths.AZURE_COMPUTE_STATS_GATHERER)).setBody(statsRequest);
sendRequest(statsOp);
return;
}
getComputeHostStats(statsData);
};
URI computeUri = UriUtils.extendUriWithQuery(statsData.statsRequest.resourceReference, UriUtils.URI_PARAM_ODATA_EXPAND, Boolean.TRUE.toString());
AdapterUtils.getServiceState(this, computeUri, onSuccess, getFailureConsumer(statsData));
}
use of com.vmware.photon.controller.model.adapterapi.ComputeStatsRequest in project photon-model by vmware.
the class AzureStatsService 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;
}
AzureStatsDataHolder statsData = new AzureStatsDataHolder();
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 AzureStatsService method getComputeHostStats.
/**
* Get metrics at the compute host level.
* @param statsData
*/
private void getComputeHostStats(AzureStatsDataHolder statsData) {
ComputeStatsRequest statsRequest = statsData.statsRequest;
Collection<Operation> opCollection = new ArrayList<>();
Operation computeStatsOp = Operation.createPatch(UriUtils.buildUri(getHost(), AzureUriPaths.AZURE_COMPUTE_HOST_STATS_GATHERER)).setBody(statsRequest).setReferer(getUri());
opCollection.add(computeStatsOp);
Operation storageStatsOp = Operation.createPatch(UriUtils.buildUri(getHost(), AzureUriPaths.AZURE_COMPUTE_HOST_STORAGE_STATS_GATHERER)).setBody(statsRequest).setReferer(getUri());
opCollection.add(storageStatsOp);
OperationJoin.create(opCollection).setCompletion((ops, exs) -> {
if (exs != null) {
exs.values().forEach(ex -> logWarning(() -> String.format("Error: %s", ex.getMessage())));
sendFailurePatch(statsData, exs.values().iterator().next());
return;
}
SingleResourceStatsCollectionTaskState statsResponse = new SingleResourceStatsCollectionTaskState();
statsResponse.taskStage = SingleResourceTaskCollectionStage.valueOf(statsData.statsRequest.nextStage);
statsResponse.statsList = new ArrayList<>();
statsResponse.statsAdapterReference = UriUtils.buildUri(getHost(), SELF_LINK);
for (Map.Entry<Long, Operation> op : ops.entrySet()) {
ComputeStatsResponse.ComputeStats stats = op.getValue().getBody(ComputeStatsResponse.ComputeStats.class);
if (stats != null) {
if (statsResponse.statsList == null || statsResponse.statsList.size() == 0) {
statsResponse.statsList.add(stats);
} else {
for (Map.Entry<String, List<ServiceStat>> entry : stats.statValues.entrySet()) {
statsResponse.statsList.get(0).statValues.put(entry.getKey(), entry.getValue());
}
}
}
}
this.sendRequest(Operation.createPatch(statsData.statsRequest.taskReference).setBody(statsResponse));
logFine(() -> "Finished collection of compute host stats");
}).sendWith(this);
}
use of com.vmware.photon.controller.model.adapterapi.ComputeStatsRequest 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()));
}
Aggregations