use of com.vmware.photon.controller.model.tasks.monitoring.SingleResourceStatsCollectionTaskService.SingleResourceStatsCollectionTaskState 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.tasks.monitoring.SingleResourceStatsCollectionTaskService.SingleResourceStatsCollectionTaskState in project photon-model by vmware.
the class AWSStatsService method sendStats.
private void sendStats(AWSStatsDataHolder statsData) {
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<>();
respBody.statsList.add(statsData.statsResponse);
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 AWSMockStatsService method getMockStats.
/**
* Gets mock EC2 statistics.
*
* @param statsData The context object for mock stats.
* @param metricNames The metrics names to gather stats for.
*/
private void getMockStats(AWSMockStatsDataHolder statsData, String[] metricNames) {
for (String metricName : metricNames) {
// start feeding mock stats data
if (MOCK_STATS_MAP.get(metricName) != null) {
logFine(() -> String.format("Retrieving %s mock metric from AWS", metricName));
List<ServiceStat> statValue = MOCK_STATS_MAP.get(metricName);
statsData.statsResponse.statValues.put(AWSStatsNormalizer.getNormalizedStatKeyValue(metricName), statValue);
}
}
SingleResourceStatsCollectionTaskState respBody = new SingleResourceStatsCollectionTaskState();
statsData.statsResponse.computeLink = statsData.computeState.documentSelfLink;
respBody.statsAdapterReference = UriUtils.buildUri(getHost(), SELF_LINK);
respBody.taskStage = SingleResourceTaskCollectionStage.valueOf(statsData.statsRequest.nextStage);
respBody.statsList = new ArrayList<>();
respBody.statsList.add(statsData.statsResponse);
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 GCPStatsService method storeAndSendStats.
/**
* Stores the stats in current GCPStatsDataHolder instance and patches back the response
* to the caller task.
* @param statsData The GCPStatsDataHolder instance containing statsRequest.
* @param metricInfo Metric name and unit pair from METRIC_NAMES_UNITS array.
* @param response The response from the monitoring API associated with metric in
* the current metricInfo pair.
* @param nextStage The next stage of StatsCollectionStage for the service.
*/
private void storeAndSendStats(GCPStatsDataHolder statsData, String[] metricInfo, GCPMetricResponse response, StatsCollectionStage nextStage) {
ServiceStat stat = new ServiceStat();
List<ServiceStat> datapoint = new ArrayList<>();
if (response.timeSeries != null) {
TimeSeries ts = response.timeSeries[0];
stat.latestValue = ts.points[0].value.int64Value == null ? Double.parseDouble(ts.points[0].value.doubleValue) : Double.parseDouble(ts.points[0].value.int64Value);
stat.unit = GCPStatsNormalizer.getNormalizedUnitValue(metricInfo[1]);
try {
stat.sourceTimeMicrosUtc = getTimestampInMicros(ts.points[0].interval.startTime);
} catch (ParseException e) {
handleError(statsData, e);
return;
}
datapoint = Collections.singletonList(stat);
}
statsData.statsResponse.statValues.put(GCPStatsNormalizer.getNormalizedStatKeyValue(metricInfo[0]), datapoint);
// After all the metrics are collected, send them as a response to the caller task.
if (statsData.numResponses.incrementAndGet() == METRIC_NAMES_UNITS.length) {
SingleResourceStatsCollectionTaskState respBody = new SingleResourceStatsCollectionTaskState();
statsData.statsResponse.computeLink = statsData.computeDesc.documentSelfLink;
respBody.taskStage = SingleResourceTaskCollectionStage.valueOf(statsData.statsRequest.nextStage);
respBody.statsList = Collections.singletonList(statsData.statsResponse);
setOperationDurationStat(statsData.gcpStatsCollectionOperation);
statsData.gcpStatsCollectionOperation.complete();
respBody.statsAdapterReference = UriUtils.buildUri(getHost(), SELF_LINK);
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 VSphereAdapterStatsService method persistStats.
private void persistStats(List<ServiceStat> stats, ComputeStatsRequest statsRequest) {
ComputeStats cs = new ComputeStats();
cs.computeLink = statsRequest.resourceReference.toString();
cs.statValues = new HashMap<>();
if (stats != null) {
for (ServiceStat stat : stats) {
cs.statValues.put(stat.name, Collections.singletonList(stat));
}
}
SingleResourceStatsCollectionTaskState respBody = new SingleResourceStatsCollectionTaskState();
respBody.statsList = new ArrayList<>();
respBody.statsList.add(cs);
respBody.taskStage = SingleResourceTaskCollectionStage.valueOf(statsRequest.nextStage);
respBody.statsAdapterReference = UriUtils.buildUri(getHost(), SELF_LINK);
// Verify if this makes sense? These tasks should always be local to deployment?
this.sendRequest(Operation.createPatch(statsRequest.taskReference).setBody(respBody));
}
Aggregations