use of com.vmware.photon.controller.model.adapterapi.ComputeStatsRequest in project photon-model by vmware.
the class AzureComputeStatsGatherer 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());
AzureStatsDataHolder statsData = new AzureStatsDataHolder();
statsData.statsRequest = statsRequest;
statsData.taskManager = taskManager;
// TODO: https://jira-hzn.eng.vmware.com/browse/VSYM-1336
getVMDescription(statsData);
}
use of com.vmware.photon.controller.model.adapterapi.ComputeStatsRequest in project photon-model by vmware.
the class AzureCostStatsService 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;
}
Context context = new Context(statsRequest);
context.taskManager = taskManager;
handleRequest(context);
}
use of com.vmware.photon.controller.model.adapterapi.ComputeStatsRequest in project photon-model by vmware.
the class SingleResourceStatsCollectionTaskService method populateLastCollectionTimeForMetricsInStatsRequest.
/**
* Gets the last collection for a compute for a given adapter URI.
* As a first step, the in memory stats for the compute are queried and if the metric
* for the last collection time is found, then the timestamp for that is returned.
*
* Else, the ResoureMetric table is queried and the latest version of the metric is used
* to determine the last collection time for the stats.
*/
private void populateLastCollectionTimeForMetricsInStatsRequest(SingleResourceStatsCollectionTaskState currentState, ComputeStatsRequest computeStatsRequest, URI patchUri, List<String> tenantLinks) {
URI computeStatsUri = UriUtils.buildStatsUri(UriUtils.extendUri(ClusterUtil.getClusterUri(getHost(), ServiceTypeCluster.INVENTORY_SERVICE), currentState.computeLink));
Operation.createGet(computeStatsUri).setCompletion((o, e) -> {
if (e != null) {
logSevere(() -> String.format("Could not get the last collection time from" + " in memory stats: %s", Utils.toString(e)));
// get the value from the persisted store.
populateLastCollectionTimeFromPersistenceStore(currentState, computeStatsRequest, patchUri, tenantLinks);
return;
}
ServiceStats serviceStats = o.getBody(ServiceStats.class);
String statsAdapterLink = getAdapterLinkFromURI(patchUri);
String lastSuccessfulRunMetricKey = getLastCollectionMetricKeyForAdapterLink(statsAdapterLink, true);
if (serviceStats.entries.containsKey(lastSuccessfulRunMetricKey)) {
ServiceStat lastRunStat = serviceStats.entries.get(lastSuccessfulRunMetricKey);
computeStatsRequest.lastCollectionTimeMicrosUtc = lastRunStat.sourceTimeMicrosUtc;
sendStatsRequestToAdapter(currentState, patchUri, computeStatsRequest);
} else {
populateLastCollectionTimeFromPersistenceStore(currentState, computeStatsRequest, patchUri, tenantLinks);
}
}).sendWith(this);
}
use of com.vmware.photon.controller.model.adapterapi.ComputeStatsRequest in project photon-model by vmware.
the class MockStatsAdapter method handleRequest.
@Override
public void handleRequest(Operation op) {
if (!op.hasBody()) {
op.fail(new IllegalArgumentException("body is required"));
return;
}
switch(op.getAction()) {
case PATCH:
op.complete();
ComputeStatsRequest statsRequest = op.getBody(ComputeStatsRequest.class);
SingleResourceStatsCollectionTaskState statsResponse = new SingleResourceStatsCollectionTaskState();
Map<String, List<ServiceStat>> statValues = new HashMap<>();
double currentCounter = this.counter.incrementAndGet();
ServiceStat key1 = new ServiceStat();
key1.latestValue = currentCounter;
long timestampMicros = Utils.getNowMicrosUtc();
key1.sourceTimeMicrosUtc = timestampMicros;
key1.unit = UNIT_1;
statValues.put(KEY_1, Collections.singletonList(key1));
sendBatchResponse(statsRequest, statsResponse, statValues, false);
statValues.clear();
ServiceStat key2 = new ServiceStat();
key2.latestValue = currentCounter;
key2.sourceTimeMicrosUtc = timestampMicros;
key2.unit = UNIT_2;
statValues.put(KEY_2, Collections.singletonList(key2));
sendBatchResponse(statsRequest, statsResponse, statValues, true);
break;
default:
super.handleRequest(op);
}
}
use of com.vmware.photon.controller.model.adapterapi.ComputeStatsRequest in project photon-model by vmware.
the class AWSMockStatsService 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);
AWSMockStatsDataHolder statsData = new AWSMockStatsDataHolder();
statsData.statsRequest = statsRequest;
statsData.taskManager = new TaskManager(this, statsRequest.taskReference, statsRequest.resourceLink());
if (statsRequest.isMockRequest) {
// patch status to parent task
statsData.taskManager.finishTask();
return;
}
getVMDescription(statsData);
}
Aggregations