use of com.vmware.photon.controller.model.adapters.gcp.podo.stats.GCPMetricResponse in project photon-model by vmware.
the class GCPStatsService method getStats.
/**
* Makes request to the monitoring API to get stats.
* @param statsData The GCPStatsDataHolder instance containing statsRequest.
* @param nextStage The next stage of StatsCollectionStage for the service.
*/
private void getStats(GCPStatsDataHolder statsData, StatsCollectionStage nextStage) {
for (String[] metricInfo : METRIC_NAMES_UNITS) {
URI uri;
/*
* Do not specify instance id in the metric request URI if the given resource is
* a compute host and specify aggregation parameters in the metric request URI
* in order to get host level stats.
*/
if (statsData.isComputeHost) {
uri = getRequestUriForHost(metricInfo[0], statsData);
} else {
uri = getRequestUriForVM(metricInfo[0], statsData);
}
if (uri == null) {
statsData.error = new IllegalStateException("The request URI is null.");
statsData.stage = StatsCollectionStage.ERROR;
handleStatsRequest(statsData);
}
Operation.createGet(uri).addRequestHeader(Operation.AUTHORIZATION_HEADER, GCPConstants.AUTH_HEADER_BEARER_PREFIX + statsData.accessToken).setCompletion((o, e) -> {
if (e != null) {
handleError(statsData, e);
return;
}
GCPMetricResponse response = o.getBody(GCPMetricResponse.class);
storeAndSendStats(statsData, metricInfo, response, nextStage);
}).sendWith(this);
}
}
Aggregations