Search in sources :

Example 6 with ComputeStatsRequest

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

the class TestAzureProvisionTask method issueStatsRequest.

private void issueStatsRequest(ComputeState vm) 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 (!TestAzureProvisionTask.this.isMock) {
                    ComputeStatsResponse resp = op.getBody(ComputeStatsResponse.class);
                    if (resp.statsList.size() != 1) {
                        TestAzureProvisionTask.this.host.failIteration(new IllegalStateException("response size was incorrect."));
                        return;
                    }
                    if (resp.statsList.get(0).statValues.size() == 0) {
                        TestAzureProvisionTask.this.host.failIteration(new IllegalStateException("incorrect number of metrics received."));
                        return;
                    }
                    if (!resp.statsList.get(0).computeLink.equals(vm.documentSelfLink)) {
                        TestAzureProvisionTask.this.host.failIteration(new IllegalStateException("Incorrect computeReference returned."));
                        return;
                    }
                }
                TestAzureProvisionTask.this.host.completeIteration();
            }
        }
    };
    String servicePath = UUID.randomUUID().toString();
    Operation startOp = Operation.createPost(UriUtils.buildUri(getHost(), servicePath));
    getHost().startService(startOp, parentService);
    ComputeStatsRequest statsRequest = new ComputeStatsRequest();
    statsRequest.resourceReference = UriUtils.buildUri(getHost(), vm.documentSelfLink);
    statsRequest.isMockRequest = this.isMock;
    statsRequest.taskReference = UriUtils.buildUri(getHost(), servicePath);
    getHost().sendAndWait(Operation.createPatch(UriUtils.buildUri(getHost(), AzureUriPaths.AZURE_STATS_ADAPTER)).setBody(statsRequest).setReferer(getHost().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)

Example 7 with ComputeStatsRequest

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

the class TestAzureEnumerationTask method issueStatsRequest.

private void issueStatsRequest(String selfLink, boolean isComputeHost) 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 (!TestAzureEnumerationTask.this.isMock) {
                    ComputeStatsResponse resp = op.getBody(ComputeStatsResponse.class);
                    if (resp == null) {
                        TestAzureEnumerationTask.this.host.failIteration(new IllegalStateException("response was null."));
                        return;
                    }
                    if (resp.statsList.size() != 1) {
                        TestAzureEnumerationTask.this.host.failIteration(new IllegalStateException("response size was incorrect."));
                        return;
                    }
                    if (resp.statsList.get(0).statValues.size() == 0) {
                        TestAzureEnumerationTask.this.host.failIteration(new IllegalStateException("incorrect number of metrics received."));
                        return;
                    }
                    if (!resp.statsList.get(0).computeLink.equals(selfLink)) {
                        TestAzureEnumerationTask.this.host.failIteration(new IllegalStateException("Incorrect resourceReference returned."));
                        return;
                    }
                    // Verify all the stats are obtained
                    verifyStats(resp, isComputeHost);
                    // Persist stats on Verification Host for testing the computeHost stats.
                    URI persistStatsUri = UriUtils.buildUri(getHost(), ResourceMetricsService.FACTORY_LINK);
                    ResourceMetricsService.ResourceMetrics resourceMetric = new ResourceMetricsService.ResourceMetrics();
                    resourceMetric.documentSelfLink = StatsUtil.getMetricKey(selfLink, Utils.getNowMicrosUtc());
                    resourceMetric.entries = new HashMap<>();
                    resourceMetric.timestampMicrosUtc = Utils.getNowMicrosUtc();
                    for (String key : resp.statsList.get(0).statValues.keySet()) {
                        List<ServiceStat> stats = resp.statsList.get(0).statValues.get(key);
                        for (ServiceStat stat : stats) {
                            if (stat == null) {
                                continue;
                            }
                            resourceMetric.entries.put(key, stat.latestValue);
                        }
                    }
                    TestAzureEnumerationTask.this.host.sendRequest(Operation.createPost(persistStatsUri).setReferer(TestAzureEnumerationTask.this.host.getUri()).setBodyNoCloning(resourceMetric));
                }
                TestAzureEnumerationTask.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.nextStage = SingleResourceTaskCollectionStage.UPDATE_STATS.name();
    statsRequest.isMockRequest = this.isMock;
    statsRequest.taskReference = UriUtils.buildUri(this.host, servicePath);
    this.host.sendAndWait(Operation.createPatch(UriUtils.buildUri(this.host, AzureUriPaths.AZURE_STATS_ADAPTER)).setBody(statsRequest).setReferer(this.host.getUri()));
}
Also used : ResourceMetricsService(com.vmware.photon.controller.model.monitoring.ResourceMetricsService) StatelessService(com.vmware.xenon.common.StatelessService) Operation(com.vmware.xenon.common.Operation) AzureTestUtil.randomString(com.vmware.photon.controller.model.adapters.azure.instance.AzureTestUtil.randomString) URI(java.net.URI) ComputeStatsResponse(com.vmware.photon.controller.model.adapterapi.ComputeStatsResponse) ServiceStat(com.vmware.xenon.common.ServiceStats.ServiceStat) ComputeStatsRequest(com.vmware.photon.controller.model.adapterapi.ComputeStatsRequest)

Example 8 with ComputeStatsRequest

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

the class GCPStatsService method handlePatch.

/**
 * The REST PATCH request handler. This is the entry of starting stats collection.
 * @param patch Operation which should contain request body.
 */
@Override
public void handlePatch(Operation patch) {
    setOperationHandlerInvokeTimeStat(patch);
    if (!patch.hasBody()) {
        patch.fail(new IllegalArgumentException("body is required"));
        return;
    }
    patch.complete();
    ComputeStatsRequest statsRequest = patch.getBody(ComputeStatsRequest.class);
    GCPStatsDataHolder statsData = new GCPStatsDataHolder(patch);
    statsData.statsRequest = statsRequest;
    statsData.taskManager = new TaskManager(this, statsRequest.taskReference, statsRequest.resourceLink());
    // If mock mode is enabled, patch back to the parent.
    if (statsData.statsRequest.isMockRequest) {
        statsData.stage = StatsCollectionStage.FINISHED;
        handleStatsRequest(statsData);
    } else {
        statsData.stage = StatsCollectionStage.VM_DESC;
        handleStatsRequest(statsData);
    }
}
Also used : ComputeStatsRequest(com.vmware.photon.controller.model.adapterapi.ComputeStatsRequest) TaskManager(com.vmware.photon.controller.model.adapters.util.TaskManager)

Example 9 with ComputeStatsRequest

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

the class AWSStatsService 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;
    }
    AWSStatsDataHolder statsData = new AWSStatsDataHolder();
    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 10 with ComputeStatsRequest

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

the class AWSCostStatsService 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;
    }
    AWSCostStatsCreationContext statsData = new AWSCostStatsCreationContext(statsRequest);
    statsData.taskManager = taskManager;
    handleCostStatsCreationRequest(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