Search in sources :

Example 1 with GCPMetricResponse

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);
    }
}
Also used : GCPUriPaths(com.vmware.photon.controller.model.adapters.gcp.GCPUriPaths) AuthCredentialsServiceState(com.vmware.xenon.services.common.AuthCredentialsService.AuthCredentialsServiceState) Date(java.util.Date) URISyntaxException(java.net.URISyntaxException) SimpleDateFormat(java.text.SimpleDateFormat) GCPUtils(com.vmware.photon.controller.model.adapters.gcp.utils.GCPUtils) ResourceGroupState(com.vmware.photon.controller.model.resources.ResourceGroupService.ResourceGroupState) ArrayList(java.util.ArrayList) SingleResourceStatsCollectionTaskState(com.vmware.photon.controller.model.tasks.monitoring.SingleResourceStatsCollectionTaskService.SingleResourceStatsCollectionTaskState) Utils(com.vmware.xenon.common.Utils) GeneralSecurityException(java.security.GeneralSecurityException) AuthCredentialsService(com.vmware.xenon.services.common.AuthCredentialsService) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) GCPMetricResponse(com.vmware.photon.controller.model.adapters.gcp.podo.stats.GCPMetricResponse) URI(java.net.URI) ComputeStats(com.vmware.photon.controller.model.adapterapi.ComputeStatsResponse.ComputeStats) ParseException(java.text.ParseException) GCPAccessTokenResponse(com.vmware.photon.controller.model.adapters.gcp.podo.authorization.GCPAccessTokenResponse) AdapterUtils(com.vmware.photon.controller.model.adapters.util.AdapterUtils) ComputeStatsRequest(com.vmware.photon.controller.model.adapterapi.ComputeStatsRequest) StatelessService(com.vmware.xenon.common.StatelessService) TimeZone(java.util.TimeZone) EncryptionUtils(com.vmware.photon.controller.model.security.util.EncryptionUtils) Operation(com.vmware.xenon.common.Operation) TaskManager(com.vmware.photon.controller.model.adapters.util.TaskManager) IOException(java.io.IOException) TimeSeries(com.vmware.photon.controller.model.adapters.gcp.podo.stats.TimeSeries) ServiceStat(com.vmware.xenon.common.ServiceStats.ServiceStat) GCPStatsNormalizer(com.vmware.photon.controller.model.adapters.gcp.utils.GCPStatsNormalizer) GCPConstants(com.vmware.photon.controller.model.adapters.gcp.constants.GCPConstants) TimeUnit(java.util.concurrent.TimeUnit) Consumer(java.util.function.Consumer) List(java.util.List) ConcurrentSkipListMap(java.util.concurrent.ConcurrentSkipListMap) ComputeStateWithDescription(com.vmware.photon.controller.model.resources.ComputeService.ComputeStateWithDescription) UriUtils(com.vmware.xenon.common.UriUtils) Collections(java.util.Collections) PhotonModelUriUtils.createInventoryUri(com.vmware.photon.controller.model.util.PhotonModelUriUtils.createInventoryUri) SingleResourceTaskCollectionStage(com.vmware.photon.controller.model.tasks.monitoring.SingleResourceStatsCollectionTaskService.SingleResourceTaskCollectionStage) JSONWebToken(com.vmware.photon.controller.model.adapters.gcp.utils.JSONWebToken) GCPMetricResponse(com.vmware.photon.controller.model.adapters.gcp.podo.stats.GCPMetricResponse) URI(java.net.URI)

Aggregations

ComputeStatsRequest (com.vmware.photon.controller.model.adapterapi.ComputeStatsRequest)1 ComputeStats (com.vmware.photon.controller.model.adapterapi.ComputeStatsResponse.ComputeStats)1 GCPUriPaths (com.vmware.photon.controller.model.adapters.gcp.GCPUriPaths)1 GCPConstants (com.vmware.photon.controller.model.adapters.gcp.constants.GCPConstants)1 GCPAccessTokenResponse (com.vmware.photon.controller.model.adapters.gcp.podo.authorization.GCPAccessTokenResponse)1 GCPMetricResponse (com.vmware.photon.controller.model.adapters.gcp.podo.stats.GCPMetricResponse)1 TimeSeries (com.vmware.photon.controller.model.adapters.gcp.podo.stats.TimeSeries)1 GCPStatsNormalizer (com.vmware.photon.controller.model.adapters.gcp.utils.GCPStatsNormalizer)1 GCPUtils (com.vmware.photon.controller.model.adapters.gcp.utils.GCPUtils)1 JSONWebToken (com.vmware.photon.controller.model.adapters.gcp.utils.JSONWebToken)1 AdapterUtils (com.vmware.photon.controller.model.adapters.util.AdapterUtils)1 TaskManager (com.vmware.photon.controller.model.adapters.util.TaskManager)1 ComputeStateWithDescription (com.vmware.photon.controller.model.resources.ComputeService.ComputeStateWithDescription)1 ResourceGroupState (com.vmware.photon.controller.model.resources.ResourceGroupService.ResourceGroupState)1 EncryptionUtils (com.vmware.photon.controller.model.security.util.EncryptionUtils)1 SingleResourceStatsCollectionTaskState (com.vmware.photon.controller.model.tasks.monitoring.SingleResourceStatsCollectionTaskService.SingleResourceStatsCollectionTaskState)1 SingleResourceTaskCollectionStage (com.vmware.photon.controller.model.tasks.monitoring.SingleResourceStatsCollectionTaskService.SingleResourceTaskCollectionStage)1 PhotonModelUriUtils.createInventoryUri (com.vmware.photon.controller.model.util.PhotonModelUriUtils.createInventoryUri)1 Operation (com.vmware.xenon.common.Operation)1 ServiceStat (com.vmware.xenon.common.ServiceStats.ServiceStat)1