Search in sources :

Example 11 with SingleResourceStatsCollectionTaskState

use of com.vmware.photon.controller.model.tasks.monitoring.SingleResourceStatsCollectionTaskService.SingleResourceStatsCollectionTaskState in project photon-model by vmware.

the class AzureComputeStatsGatherer method patchEmptyResponse.

private void patchEmptyResponse(AzureStatsDataHolder statsData) {
    // Patch back to the Parent with empty response
    SingleResourceStatsCollectionTaskState respBody = new SingleResourceStatsCollectionTaskState();
    statsData.statsResponse.computeLink = statsData.computeDesc.documentSelfLink;
    respBody.taskStage = SingleResourceTaskCollectionStage.valueOf(statsData.statsRequest.nextStage);
    respBody.statsAdapterReference = UriUtils.buildUri(getHost(), SELF_LINK);
    respBody.statsList = new ArrayList<>();
    this.sendRequest(Operation.createPatch(statsData.statsRequest.taskReference).setBody(respBody));
}
Also used : SingleResourceStatsCollectionTaskState(com.vmware.photon.controller.model.tasks.monitoring.SingleResourceStatsCollectionTaskService.SingleResourceStatsCollectionTaskState)

Example 12 with SingleResourceStatsCollectionTaskState

use of com.vmware.photon.controller.model.tasks.monitoring.SingleResourceStatsCollectionTaskService.SingleResourceStatsCollectionTaskState in project photon-model by vmware.

the class AzureStatsService method getComputeHostStats.

/**
 * Get metrics at the compute host level.
 * @param statsData
 */
private void getComputeHostStats(AzureStatsDataHolder statsData) {
    ComputeStatsRequest statsRequest = statsData.statsRequest;
    Collection<Operation> opCollection = new ArrayList<>();
    Operation computeStatsOp = Operation.createPatch(UriUtils.buildUri(getHost(), AzureUriPaths.AZURE_COMPUTE_HOST_STATS_GATHERER)).setBody(statsRequest).setReferer(getUri());
    opCollection.add(computeStatsOp);
    Operation storageStatsOp = Operation.createPatch(UriUtils.buildUri(getHost(), AzureUriPaths.AZURE_COMPUTE_HOST_STORAGE_STATS_GATHERER)).setBody(statsRequest).setReferer(getUri());
    opCollection.add(storageStatsOp);
    OperationJoin.create(opCollection).setCompletion((ops, exs) -> {
        if (exs != null) {
            exs.values().forEach(ex -> logWarning(() -> String.format("Error: %s", ex.getMessage())));
            sendFailurePatch(statsData, exs.values().iterator().next());
            return;
        }
        SingleResourceStatsCollectionTaskState statsResponse = new SingleResourceStatsCollectionTaskState();
        statsResponse.taskStage = SingleResourceTaskCollectionStage.valueOf(statsData.statsRequest.nextStage);
        statsResponse.statsList = new ArrayList<>();
        statsResponse.statsAdapterReference = UriUtils.buildUri(getHost(), SELF_LINK);
        for (Map.Entry<Long, Operation> op : ops.entrySet()) {
            ComputeStatsResponse.ComputeStats stats = op.getValue().getBody(ComputeStatsResponse.ComputeStats.class);
            if (stats != null) {
                if (statsResponse.statsList == null || statsResponse.statsList.size() == 0) {
                    statsResponse.statsList.add(stats);
                } else {
                    for (Map.Entry<String, List<ServiceStat>> entry : stats.statValues.entrySet()) {
                        statsResponse.statsList.get(0).statValues.put(entry.getKey(), entry.getValue());
                    }
                }
            }
        }
        this.sendRequest(Operation.createPatch(statsData.statsRequest.taskReference).setBody(statsResponse));
        logFine(() -> "Finished collection of compute host stats");
    }).sendWith(this);
}
Also used : AdapterUtils(com.vmware.photon.controller.model.adapters.util.AdapterUtils) ComputeStatsResponse(com.vmware.photon.controller.model.adapterapi.ComputeStatsResponse) ComputeDescription(com.vmware.photon.controller.model.resources.ComputeDescriptionService.ComputeDescription) ComputeStatsRequest(com.vmware.photon.controller.model.adapterapi.ComputeStatsRequest) StatelessService(com.vmware.xenon.common.StatelessService) Collection(java.util.Collection) Operation(com.vmware.xenon.common.Operation) TaskManager(com.vmware.photon.controller.model.adapters.util.TaskManager) AzureUriPaths(com.vmware.photon.controller.model.adapters.azure.AzureUriPaths) ServiceStat(com.vmware.xenon.common.ServiceStats.ServiceStat) ArrayList(java.util.ArrayList) ComputeType(com.vmware.photon.controller.model.resources.ComputeDescriptionService.ComputeDescription.ComputeType) SingleResourceStatsCollectionTaskState(com.vmware.photon.controller.model.tasks.monitoring.SingleResourceStatsCollectionTaskService.SingleResourceStatsCollectionTaskState) Consumer(java.util.function.Consumer) List(java.util.List) ComputeStateWithDescription(com.vmware.photon.controller.model.resources.ComputeService.ComputeStateWithDescription) Map(java.util.Map) UriUtils(com.vmware.xenon.common.UriUtils) URI(java.net.URI) OperationJoin(com.vmware.xenon.common.OperationJoin) SingleResourceTaskCollectionStage(com.vmware.photon.controller.model.tasks.monitoring.SingleResourceStatsCollectionTaskService.SingleResourceTaskCollectionStage) ServiceStat(com.vmware.xenon.common.ServiceStats.ServiceStat) ComputeStatsRequest(com.vmware.photon.controller.model.adapterapi.ComputeStatsRequest) ArrayList(java.util.ArrayList) SingleResourceStatsCollectionTaskState(com.vmware.photon.controller.model.tasks.monitoring.SingleResourceStatsCollectionTaskService.SingleResourceStatsCollectionTaskState) Operation(com.vmware.xenon.common.Operation)

Example 13 with SingleResourceStatsCollectionTaskState

use of com.vmware.photon.controller.model.tasks.monitoring.SingleResourceStatsCollectionTaskService.SingleResourceStatsCollectionTaskState in project photon-model by vmware.

the class TestAWSCostAdapterService method issueStatsRequest.

private void issueStatsRequest(ComputeState account) throws Throwable {
    List<ComputeStats> allStats = new ArrayList<>();
    // spin up a stateless service that acts as the parent link to patch back to
    StatelessService parentService = new StatelessService() {

        @Override
        public void handleRequest(Operation op) {
            if (op.getAction() == Action.PATCH) {
                if (TestAWSCostAdapterService.this.isMock) {
                    SingleResourceStatsCollectionTaskState resp = op.getBody(SingleResourceStatsCollectionTaskState.class);
                    allStats.addAll(resp.statsList);
                    if (resp.isFinalBatch) {
                        verifyCollectedStats(allStats);
                        TestAWSCostAdapterService.this.host.completeIteration();
                    }
                } else {
                    TestAWSCostAdapterService.this.host.completeIteration();
                }
            }
        }
    };
    sendStatsRequest(account, parentService);
}
Also used : ComputeStats(com.vmware.photon.controller.model.adapterapi.ComputeStatsResponse.ComputeStats) StatelessService(com.vmware.xenon.common.StatelessService) ArrayList(java.util.ArrayList) SingleResourceStatsCollectionTaskState(com.vmware.photon.controller.model.tasks.monitoring.SingleResourceStatsCollectionTaskService.SingleResourceStatsCollectionTaskState) Operation(com.vmware.xenon.common.Operation)

Example 14 with SingleResourceStatsCollectionTaskState

use of com.vmware.photon.controller.model.tasks.monitoring.SingleResourceStatsCollectionTaskService.SingleResourceStatsCollectionTaskState in project photon-model by vmware.

the class SingleResourceStatsCollectionTaskService method getDescriptions.

private void getDescriptions(SingleResourceStatsCollectionTaskState currentState) {
    URI computeDescUri = ComputeStateWithDescription.buildUri(UriUtils.extendUri(ClusterUtil.getClusterUri(getHost(), ServiceTypeCluster.INVENTORY_SERVICE), currentState.computeLink));
    sendRequest(Operation.createGet(computeDescUri).setCompletion((getOp, getEx) -> {
        if (getEx != null) {
            TaskUtils.sendFailurePatch(this, currentState, getEx);
            return;
        }
        ComputeStateWithDescription computeStateWithDesc = getOp.getBody(ComputeStateWithDescription.class);
        ComputeStatsRequest statsRequest = new ComputeStatsRequest();
        statsRequest.isMockRequest = currentState.options != null ? currentState.options.contains(TaskOption.IS_MOCK) : false;
        URI patchUri = null;
        Object patchBody = null;
        ComputeDescription description = computeStateWithDesc.description;
        URI statsAdapterReference = null;
        List<String> tenantLinks = new ArrayList<>();
        if (description != null) {
            tenantLinks = description.tenantLinks;
            // provided
            if (currentState.statsAdapterReference == null) {
                statsAdapterReference = description.statsAdapterReference;
            } else if (description.statsAdapterReferences != null) {
                for (URI uri : description.statsAdapterReferences) {
                    if (uri.getPath().equals(currentState.statsAdapterReference.getPath())) {
                        statsAdapterReference = currentState.statsAdapterReference;
                        break;
                    }
                }
            }
        }
        if (statsAdapterReference != null) {
            statsRequest.nextStage = SingleResourceTaskCollectionStage.UPDATE_STATS.name();
            statsRequest.resourceReference = UriUtils.extendUri(ClusterUtil.getClusterUri(getHost(), ServiceTypeCluster.INVENTORY_SERVICE), computeStateWithDesc.documentSelfLink);
            statsRequest.taskReference = getUri();
            patchUri = statsAdapterReference;
            populateLastCollectionTimeForMetricsInStatsRequest(currentState, statsRequest, patchUri, tenantLinks);
        } else {
            // no adapter associated with this resource, just patch completion
            SingleResourceStatsCollectionTaskState nextStageState = new SingleResourceStatsCollectionTaskState();
            nextStageState.taskInfo = new TaskState();
            nextStageState.taskInfo.stage = TaskStage.FINISHED;
            patchUri = getUri();
            patchBody = nextStageState;
            sendStatsRequestToAdapter(currentState, patchUri, patchBody);
        }
    }));
}
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) ComputeStatsRequest(com.vmware.photon.controller.model.adapterapi.ComputeStatsRequest) ComputeStateWithDescription(com.vmware.photon.controller.model.resources.ComputeService.ComputeStateWithDescription) ComputeDescription(com.vmware.photon.controller.model.resources.ComputeDescriptionService.ComputeDescription) SingleResourceStatsCollectionTaskState(com.vmware.photon.controller.model.tasks.monitoring.SingleResourceStatsCollectionTaskService.SingleResourceStatsCollectionTaskState) List(java.util.List) ArrayList(java.util.ArrayList) URI(java.net.URI) SingleResourceStatsCollectionTaskState(com.vmware.photon.controller.model.tasks.monitoring.SingleResourceStatsCollectionTaskService.SingleResourceStatsCollectionTaskState) TaskState(com.vmware.xenon.common.TaskState)

Example 15 with SingleResourceStatsCollectionTaskState

use of com.vmware.photon.controller.model.tasks.monitoring.SingleResourceStatsCollectionTaskService.SingleResourceStatsCollectionTaskState in project photon-model by vmware.

the class SingleResourceStatsCollectionTaskService method handlePatch.

@Override
public void handlePatch(Operation patch) {
    SingleResourceStatsCollectionTaskState currentState = getState(patch);
    SingleResourceStatsCollectionTaskState patchState = patch.getBody(SingleResourceStatsCollectionTaskState.class);
    updateState(currentState, patchState);
    patch.setBody(currentState);
    patch.complete();
    switch(currentState.taskInfo.stage) {
        case CREATED:
            break;
        case STARTED:
            handleStagePatch(currentState);
            break;
        case FINISHED:
        case FAILED:
        case CANCELLED:
            // this is a one shot task, self delete
            sendRequest(Operation.createPatch(currentState.parentTaskReference).setBody(currentState.parentPatchBody).setCompletion((patchOp, patchEx) -> {
                if (patchEx != null) {
                    logWarning(() -> String.format("Patching parent task failed %s", Utils.toString(patchEx)));
                }
                sendRequest(Operation.createDelete(getUri()));
                logFine(() -> "Finished single resource stats collection");
            }));
            break;
        default:
            break;
    }
}
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) SingleResourceStatsCollectionTaskState(com.vmware.photon.controller.model.tasks.monitoring.SingleResourceStatsCollectionTaskService.SingleResourceStatsCollectionTaskState)

Aggregations

SingleResourceStatsCollectionTaskState (com.vmware.photon.controller.model.tasks.monitoring.SingleResourceStatsCollectionTaskService.SingleResourceStatsCollectionTaskState)17 ServiceStat (com.vmware.xenon.common.ServiceStats.ServiceStat)11 Operation (com.vmware.xenon.common.Operation)10 ArrayList (java.util.ArrayList)10 List (java.util.List)9 ComputeStatsRequest (com.vmware.photon.controller.model.adapterapi.ComputeStatsRequest)8 ComputeStats (com.vmware.photon.controller.model.adapterapi.ComputeStatsResponse.ComputeStats)8 UriUtils (com.vmware.xenon.common.UriUtils)8 URI (java.net.URI)8 QueryUtils (com.vmware.photon.controller.model.query.QueryUtils)7 ComputeStateWithDescription (com.vmware.photon.controller.model.resources.ComputeService.ComputeStateWithDescription)7 ClusterUtil (com.vmware.photon.controller.model.util.ClusterUtil)7 ServiceTypeCluster (com.vmware.photon.controller.model.util.ClusterUtil.ServiceTypeCluster)7 Utils (com.vmware.xenon.common.Utils)7 QueryTask (com.vmware.xenon.services.common.QueryTask)7 Query (com.vmware.xenon.services.common.QueryTask.Query)7 Map (java.util.Map)7 TimeUnit (java.util.concurrent.TimeUnit)7 UriPaths (com.vmware.photon.controller.model.UriPaths)6 PhotonModelConstants (com.vmware.photon.controller.model.constants.PhotonModelConstants)6