Search in sources :

Example 1 with TimeSeries

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));
    }
}
Also used : ServiceStat(com.vmware.xenon.common.ServiceStats.ServiceStat) TimeSeries(com.vmware.photon.controller.model.adapters.gcp.podo.stats.TimeSeries) ArrayList(java.util.ArrayList) SingleResourceStatsCollectionTaskState(com.vmware.photon.controller.model.tasks.monitoring.SingleResourceStatsCollectionTaskService.SingleResourceStatsCollectionTaskState) ParseException(java.text.ParseException)

Aggregations

TimeSeries (com.vmware.photon.controller.model.adapters.gcp.podo.stats.TimeSeries)1 SingleResourceStatsCollectionTaskState (com.vmware.photon.controller.model.tasks.monitoring.SingleResourceStatsCollectionTaskService.SingleResourceStatsCollectionTaskState)1 ServiceStat (com.vmware.xenon.common.ServiceStats.ServiceStat)1 ParseException (java.text.ParseException)1 ArrayList (java.util.ArrayList)1