use of com.vmware.photon.controller.model.tasks.monitoring.SingleResourceStatsCollectionTaskService.SingleResourceStatsCollectionTaskState in project photon-model by vmware.
the class AzureComputeStatsGatherer method patchEmptyResponse.
private void patchEmptyResponse(AzureStatsDataHolder statsData) {
// Patch back to the Parent with empty response
SingleResourceStatsCollectionTaskState respBody = new SingleResourceStatsCollectionTaskState();
statsData.statsResponse.computeLink = statsData.computeDesc.documentSelfLink;
respBody.taskStage = SingleResourceTaskCollectionStage.valueOf(statsData.statsRequest.nextStage);
respBody.statsAdapterReference = UriUtils.buildUri(getHost(), SELF_LINK);
respBody.statsList = new ArrayList<>();
this.sendRequest(Operation.createPatch(statsData.statsRequest.taskReference).setBody(respBody));
}
use of com.vmware.photon.controller.model.tasks.monitoring.SingleResourceStatsCollectionTaskService.SingleResourceStatsCollectionTaskState 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.tasks.monitoring.SingleResourceStatsCollectionTaskService.SingleResourceStatsCollectionTaskState 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.photon.controller.model.tasks.monitoring.SingleResourceStatsCollectionTaskService.SingleResourceStatsCollectionTaskState 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);
}
}));
}
use of com.vmware.photon.controller.model.tasks.monitoring.SingleResourceStatsCollectionTaskService.SingleResourceStatsCollectionTaskState in project photon-model by vmware.
the class SingleResourceStatsCollectionTaskService method handlePatch.
@Override
public void handlePatch(Operation patch) {
SingleResourceStatsCollectionTaskState currentState = getState(patch);
SingleResourceStatsCollectionTaskState patchState = patch.getBody(SingleResourceStatsCollectionTaskState.class);
updateState(currentState, patchState);
patch.setBody(currentState);
patch.complete();
switch(currentState.taskInfo.stage) {
case CREATED:
break;
case STARTED:
handleStagePatch(currentState);
break;
case FINISHED:
case FAILED:
case CANCELLED:
// this is a one shot task, self delete
sendRequest(Operation.createPatch(currentState.parentTaskReference).setBody(currentState.parentPatchBody).setCompletion((patchOp, patchEx) -> {
if (patchEx != null) {
logWarning(() -> String.format("Patching parent task failed %s", Utils.toString(patchEx)));
}
sendRequest(Operation.createDelete(getUri()));
logFine(() -> "Finished single resource stats collection");
}));
break;
default:
break;
}
}
Aggregations