Search in sources :

Example 11 with ComputeStatsRequest

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

the class VSphereAdapterStatsService 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);
    ProvisionContext.populateContextThen(this, createInitialContext(statsRequest, op), ctx -> {
        if (statsRequest.isMockRequest) {
            // patch status to parent task
            persistStats(mockStats(), statsRequest);
            ctx.mgr.patchTask(TaskStage.FINISHED);
            return;
        }
        collectStats(ctx, statsRequest);
    });
}
Also used : ComputeStatsRequest(com.vmware.photon.controller.model.adapterapi.ComputeStatsRequest)

Example 12 with ComputeStatsRequest

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

the class AzureStatsService method getVMDescription.

private void getVMDescription(AzureStatsDataHolder statsData) {
    Consumer<Operation> onSuccess = (op) -> {
        statsData.computeDesc = op.getBody(ComputeStateWithDescription.class);
        boolean isComputeHost = isComputeHost(statsData.computeDesc.description);
        // response directly to the task which called it.
        if (!isComputeHost) {
            ComputeStatsRequest statsRequest = statsData.statsRequest;
            Operation statsOp = Operation.createPatch(UriUtils.buildUri(getHost(), AzureUriPaths.AZURE_COMPUTE_STATS_GATHERER)).setBody(statsRequest);
            sendRequest(statsOp);
            return;
        }
        getComputeHostStats(statsData);
    };
    URI computeUri = UriUtils.extendUriWithQuery(statsData.statsRequest.resourceReference, UriUtils.URI_PARAM_ODATA_EXPAND, Boolean.TRUE.toString());
    AdapterUtils.getServiceState(this, computeUri, onSuccess, getFailureConsumer(statsData));
}
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) ComputeStatsRequest(com.vmware.photon.controller.model.adapterapi.ComputeStatsRequest) Operation(com.vmware.xenon.common.Operation) URI(java.net.URI)

Example 13 with ComputeStatsRequest

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

the class AzureStatsService method handlePatch.

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

Example 14 with ComputeStatsRequest

use of com.vmware.photon.controller.model.adapterapi.ComputeStatsRequest 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 15 with ComputeStatsRequest

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

the class TestGCPStatsCollection method issueStatsRequest.

/**
 * Creates a stateless service which will call GCPStatsService to collect stats of the
 * resource specified by the argument.
 * Receives response back and patches it to the caller service.
 * @param selfLink The self link to the document of enumerated resource.
 * @throws Throwable
 */
public void issueStatsRequest(String selfLink) throws Throwable {
    // 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 (!TestGCPStatsCollection.this.isMock) {
                    ComputeStatsResponse resp = op.getBody(ComputeStatsResponse.class);
                    if (resp == null) {
                        TestGCPStatsCollection.this.host.failIteration(new IllegalStateException("response was null."));
                        return;
                    }
                    if (resp.statsList.size() != 1) {
                        TestGCPStatsCollection.this.host.failIteration(new IllegalStateException("response size was incorrect."));
                        return;
                    }
                    if (resp.statsList.get(0).statValues.size() != 9) {
                        TestGCPStatsCollection.this.host.failIteration(new IllegalStateException("incorrect number of metrics received."));
                        return;
                    }
                    if (!resp.statsList.get(0).computeLink.equals(selfLink)) {
                        TestGCPStatsCollection.this.host.failIteration(new IllegalStateException("Incorrect resourceReference returned."));
                        return;
                    }
                }
                TestGCPStatsCollection.this.host.completeIteration();
            }
        }
    };
    String servicePath = UUID.randomUUID().toString();
    Operation startOp = Operation.createPost(UriUtils.buildUri(this.host, servicePath));
    this.host.startService(startOp, parentService);
    ComputeStatsRequest statsRequest = new ComputeStatsRequest();
    statsRequest.resourceReference = UriUtils.buildUri(this.host, selfLink);
    statsRequest.isMockRequest = this.isMock;
    statsRequest.taskReference = UriUtils.buildUri(this.host, servicePath);
    this.host.sendAndWait(Operation.createPatch(UriUtils.buildUri(this.host, GCPUriPaths.GCP_STATS_ADAPTER)).setBody(statsRequest).setReferer(this.host.getUri()));
}
Also used : ComputeStatsResponse(com.vmware.photon.controller.model.adapterapi.ComputeStatsResponse) ComputeStatsRequest(com.vmware.photon.controller.model.adapterapi.ComputeStatsRequest) StatelessService(com.vmware.xenon.common.StatelessService) Operation(com.vmware.xenon.common.Operation)

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