use of com.vmware.photon.controller.model.adapters.gcp.podo.stats.TimeSeries 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));
}
}
Aggregations