Search in sources :

Example 1 with ComputeStatsRequest

use of com.vmware.photon.controller.model.adapterapi.ComputeStatsRequest in project photon-model by vmware.

the class AzureComputeStatsGatherer method handlePatch.

@Override
public void handlePatch(Operation op) {
    if (!op.hasBody()) {
        op.fail(new IllegalArgumentException("body is required"));
        return;
    }
    op.complete();
    ComputeStatsRequest statsRequest = op.getBody(ComputeStatsRequest.class);
    TaskManager taskManager = new TaskManager(this, statsRequest.taskReference, statsRequest.resourceLink());
    AzureStatsDataHolder statsData = new AzureStatsDataHolder();
    statsData.statsRequest = statsRequest;
    statsData.taskManager = taskManager;
    // TODO: https://jira-hzn.eng.vmware.com/browse/VSYM-1336
    getVMDescription(statsData);
}
Also used : ComputeStatsRequest(com.vmware.photon.controller.model.adapterapi.ComputeStatsRequest) TaskManager(com.vmware.photon.controller.model.adapters.util.TaskManager)

Example 2 with ComputeStatsRequest

use of com.vmware.photon.controller.model.adapterapi.ComputeStatsRequest in project photon-model by vmware.

the class AzureCostStatsService method handlePatch.

@Override
public void handlePatch(Operation op) {
    if (!op.hasBody()) {
        op.fail(new IllegalArgumentException("body is required."));
        return;
    }
    op.complete();
    ComputeStatsRequest statsRequest = op.getBody(ComputeStatsRequest.class);
    TaskManager taskManager = new TaskManager(this, statsRequest.taskReference, statsRequest.resourceLink());
    if (statsRequest.isMockRequest) {
        // patch status to parent task
        taskManager.finishTask();
        return;
    }
    Context context = new Context(statsRequest);
    context.taskManager = taskManager;
    handleRequest(context);
}
Also used : OperationContext(com.vmware.xenon.common.OperationContext) ComputeStatsRequest(com.vmware.photon.controller.model.adapterapi.ComputeStatsRequest) TaskManager(com.vmware.photon.controller.model.adapters.util.TaskManager)

Example 3 with ComputeStatsRequest

use of com.vmware.photon.controller.model.adapterapi.ComputeStatsRequest in project photon-model by vmware.

the class SingleResourceStatsCollectionTaskService method populateLastCollectionTimeForMetricsInStatsRequest.

/**
 * Gets the last collection for a compute for a given adapter URI.
 * As a first step, the in memory stats for the compute are queried and if the metric
 * for the last collection time is found, then the timestamp for that is returned.
 *
 * Else, the ResoureMetric table is queried and the latest version of the metric is used
 * to determine the last collection time for the stats.
 */
private void populateLastCollectionTimeForMetricsInStatsRequest(SingleResourceStatsCollectionTaskState currentState, ComputeStatsRequest computeStatsRequest, URI patchUri, List<String> tenantLinks) {
    URI computeStatsUri = UriUtils.buildStatsUri(UriUtils.extendUri(ClusterUtil.getClusterUri(getHost(), ServiceTypeCluster.INVENTORY_SERVICE), currentState.computeLink));
    Operation.createGet(computeStatsUri).setCompletion((o, e) -> {
        if (e != null) {
            logSevere(() -> String.format("Could not get the last collection time from" + " in memory stats: %s", Utils.toString(e)));
            // get the value from the persisted store.
            populateLastCollectionTimeFromPersistenceStore(currentState, computeStatsRequest, patchUri, tenantLinks);
            return;
        }
        ServiceStats serviceStats = o.getBody(ServiceStats.class);
        String statsAdapterLink = getAdapterLinkFromURI(patchUri);
        String lastSuccessfulRunMetricKey = getLastCollectionMetricKeyForAdapterLink(statsAdapterLink, true);
        if (serviceStats.entries.containsKey(lastSuccessfulRunMetricKey)) {
            ServiceStat lastRunStat = serviceStats.entries.get(lastSuccessfulRunMetricKey);
            computeStatsRequest.lastCollectionTimeMicrosUtc = lastRunStat.sourceTimeMicrosUtc;
            sendStatsRequestToAdapter(currentState, patchUri, computeStatsRequest);
        } else {
            populateLastCollectionTimeFromPersistenceStore(currentState, computeStatsRequest, patchUri, tenantLinks);
        }
    }).sendWith(this);
}
Also used : Service(com.vmware.xenon.common.Service) ServiceTypeCluster(com.vmware.photon.controller.model.util.ClusterUtil.ServiceTypeCluster) QueryTask(com.vmware.xenon.services.common.QueryTask) ServiceDocument(com.vmware.xenon.common.ServiceDocument) AggregationType(com.vmware.xenon.common.ServiceStats.TimeSeriesStats.AggregationType) MatchType(com.vmware.xenon.services.common.QueryTask.QueryTerm.MatchType) SingleResourceStatsCollectionTaskState(com.vmware.photon.controller.model.tasks.monitoring.SingleResourceStatsCollectionTaskService.SingleResourceStatsCollectionTaskState) Utils(com.vmware.xenon.common.Utils) TaskFactoryService(com.vmware.xenon.services.common.TaskFactoryService) Map(java.util.Map) URI(java.net.URI) EnumSet(java.util.EnumSet) ComputeDescription(com.vmware.photon.controller.model.resources.ComputeDescriptionService.ComputeDescription) ComputeStatsRequest(com.vmware.photon.controller.model.adapterapi.ComputeStatsRequest) ServiceStats(com.vmware.xenon.common.ServiceStats) List(java.util.List) TimeSeriesStats(com.vmware.xenon.common.ServiceStats.TimeSeriesStats) UriUtils(com.vmware.xenon.common.UriUtils) Entry(java.util.Map.Entry) QueryOption(com.vmware.xenon.services.common.QueryTask.QuerySpecification.QueryOption) TaskState(com.vmware.xenon.common.TaskState) TaskOption(com.vmware.photon.controller.model.tasks.TaskOption) FactoryService(com.vmware.xenon.common.FactoryService) NumericRange(com.vmware.xenon.services.common.QueryTask.NumericRange) TaskService(com.vmware.xenon.services.common.TaskService) ResourceMetrics(com.vmware.photon.controller.model.monitoring.ResourceMetricsService.ResourceMetrics) TaskUtils(com.vmware.photon.controller.model.tasks.TaskUtils) InMemoryResourceMetric(com.vmware.photon.controller.model.monitoring.InMemoryResourceMetricService.InMemoryResourceMetric) HashMap(java.util.HashMap) PhotonModelUtils(com.vmware.photon.controller.model.resources.util.PhotonModelUtils) ResourceMetricsService(com.vmware.photon.controller.model.monitoring.ResourceMetricsService) ArrayList(java.util.ArrayList) ServiceUriPaths(com.vmware.xenon.services.common.ServiceUriPaths) Query(com.vmware.xenon.services.common.QueryTask.Query) UriPaths(com.vmware.photon.controller.model.UriPaths) PropertyUsageOption(com.vmware.xenon.common.ServiceDocumentDescription.PropertyUsageOption) ComputeStats(com.vmware.photon.controller.model.adapterapi.ComputeStatsResponse.ComputeStats) OperationSequence(com.vmware.xenon.common.OperationSequence) Operation(com.vmware.xenon.common.Operation) QueryUtils(com.vmware.photon.controller.model.query.QueryUtils) TypeName(com.vmware.xenon.common.ServiceDocumentDescription.TypeName) ServiceStat(com.vmware.xenon.common.ServiceStats.ServiceStat) TaskStage(com.vmware.xenon.common.TaskState.TaskStage) TimeUnit(java.util.concurrent.TimeUnit) InMemoryResourceMetricService(com.vmware.photon.controller.model.monitoring.InMemoryResourceMetricService) ClusterUtil(com.vmware.photon.controller.model.util.ClusterUtil) ComputeStateWithDescription(com.vmware.photon.controller.model.resources.ComputeService.ComputeStateWithDescription) PhotonModelConstants(com.vmware.photon.controller.model.constants.PhotonModelConstants) Comparator(java.util.Comparator) QuerySpecification(com.vmware.xenon.services.common.QueryTask.QuerySpecification) ServiceStat(com.vmware.xenon.common.ServiceStats.ServiceStat) ServiceStats(com.vmware.xenon.common.ServiceStats) URI(java.net.URI)

Example 4 with ComputeStatsRequest

use of com.vmware.photon.controller.model.adapterapi.ComputeStatsRequest 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);
    }
}
Also used : ServiceStat(com.vmware.xenon.common.ServiceStats.ServiceStat) ComputeStatsRequest(com.vmware.photon.controller.model.adapterapi.ComputeStatsRequest) HashMap(java.util.HashMap) SingleResourceStatsCollectionTaskState(com.vmware.photon.controller.model.tasks.monitoring.SingleResourceStatsCollectionTaskService.SingleResourceStatsCollectionTaskState) ArrayList(java.util.ArrayList) List(java.util.List)

Example 5 with ComputeStatsRequest

use of com.vmware.photon.controller.model.adapterapi.ComputeStatsRequest in project photon-model by vmware.

the class AWSMockStatsService method handlePatch.

@Override
public void handlePatch(Operation op) {
    if (!op.hasBody()) {
        op.fail(new IllegalArgumentException("body is required"));
        return;
    }
    op.complete();
    ComputeStatsRequest statsRequest = op.getBody(ComputeStatsRequest.class);
    AWSMockStatsDataHolder statsData = new AWSMockStatsDataHolder();
    statsData.statsRequest = statsRequest;
    statsData.taskManager = new TaskManager(this, statsRequest.taskReference, statsRequest.resourceLink());
    if (statsRequest.isMockRequest) {
        // patch status to parent task
        statsData.taskManager.finishTask();
        return;
    }
    getVMDescription(statsData);
}
Also used : ComputeStatsRequest(com.vmware.photon.controller.model.adapterapi.ComputeStatsRequest) TaskManager(com.vmware.photon.controller.model.adapters.util.TaskManager)

Aggregations

ComputeStatsRequest (com.vmware.photon.controller.model.adapterapi.ComputeStatsRequest)19 Operation (com.vmware.xenon.common.Operation)10 TaskManager (com.vmware.photon.controller.model.adapters.util.TaskManager)9 ComputeStatsResponse (com.vmware.photon.controller.model.adapterapi.ComputeStatsResponse)7 StatelessService (com.vmware.xenon.common.StatelessService)7 ServiceStat (com.vmware.xenon.common.ServiceStats.ServiceStat)6 SingleResourceStatsCollectionTaskState (com.vmware.photon.controller.model.tasks.monitoring.SingleResourceStatsCollectionTaskService.SingleResourceStatsCollectionTaskState)5 URI (java.net.URI)5 ArrayList (java.util.ArrayList)5 List (java.util.List)5 ComputeDescription (com.vmware.photon.controller.model.resources.ComputeDescriptionService.ComputeDescription)4 ComputeStateWithDescription (com.vmware.photon.controller.model.resources.ComputeService.ComputeStateWithDescription)4 UriUtils (com.vmware.xenon.common.UriUtils)4 ResourceMetricsService (com.vmware.photon.controller.model.monitoring.ResourceMetricsService)3 Map (java.util.Map)3 UriPaths (com.vmware.photon.controller.model.UriPaths)2 ComputeStats (com.vmware.photon.controller.model.adapterapi.ComputeStatsResponse.ComputeStats)2 AzureUriPaths (com.vmware.photon.controller.model.adapters.azure.AzureUriPaths)2 AdapterUtils (com.vmware.photon.controller.model.adapters.util.AdapterUtils)2 PhotonModelConstants (com.vmware.photon.controller.model.constants.PhotonModelConstants)2