Search in sources :

Example 16 with StatelessService

use of com.vmware.xenon.common.StatelessService 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 17 with StatelessService

use of com.vmware.xenon.common.StatelessService in project photon-model by vmware.

the class TestAWSEnumerationAtScale method issueMockStatsRequest.

/**
 * Verify whether the mock stats gathered are correct or not.
 * @param vm The AWS VM compute state.
 * @throws Throwable
 */
private void issueMockStatsRequest(ComputeService.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) {
                ComputeStatsResponse resp = op.getBody(ComputeStatsResponse.class);
                if (resp.statsList.size() != 1) {
                    TestAWSEnumerationAtScale.this.host.failIteration(new IllegalStateException("response size was incorrect."));
                    return;
                }
                if (resp.statsList.get(0).statValues.size() != MOCK_STATS_SIZE) {
                    TestAWSEnumerationAtScale.this.host.failIteration(new IllegalStateException("incorrect number of metrics received."));
                    return;
                }
                if (!resp.statsList.get(0).computeLink.equals(vm.documentSelfLink)) {
                    TestAWSEnumerationAtScale.this.host.failIteration(new IllegalStateException("Incorrect resourceReference returned."));
                    return;
                }
                verifyCollectedMockStats(resp);
                TestAWSEnumerationAtScale.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, vm.documentSelfLink);
    statsRequest.isMockRequest = this.isMock;
    statsRequest.nextStage = SingleResourceTaskCollectionStage.UPDATE_STATS.name();
    statsRequest.taskReference = UriUtils.buildUri(this.host, servicePath);
    this.host.sendAndWait(Operation.createPatch(UriUtils.buildUri(this.host, AWSMockStatsService.SELF_LINK)).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

StatelessService (com.vmware.xenon.common.StatelessService)17 Operation (com.vmware.xenon.common.Operation)14 AuthCredentialsServiceState (com.vmware.xenon.services.common.AuthCredentialsService.AuthCredentialsServiceState)6 ComputeStatsRequest (com.vmware.photon.controller.model.adapterapi.ComputeStatsRequest)5 ComputeStatsResponse (com.vmware.photon.controller.model.adapterapi.ComputeStatsResponse)5 URI (java.net.URI)4 AmazonEC2AsyncClient (com.amazonaws.services.ec2.AmazonEC2AsyncClient)3 ResourceOperation (com.vmware.photon.controller.model.adapters.registry.operations.ResourceOperation)3 ComputeState (com.vmware.photon.controller.model.resources.ComputeService.ComputeState)3 EndpointState (com.vmware.photon.controller.model.resources.EndpointService.EndpointState)3 AsyncHandler (com.amazonaws.handlers.AsyncHandler)2 AmazonCloudWatchAsyncClient (com.amazonaws.services.cloudwatch.AmazonCloudWatchAsyncClient)2 DescribeAlarmsRequest (com.amazonaws.services.cloudwatch.model.DescribeAlarmsRequest)2 DescribeAlarmsResult (com.amazonaws.services.cloudwatch.model.DescribeAlarmsResult)2 AmazonElasticLoadBalancingAsyncClient (com.amazonaws.services.elasticloadbalancing.AmazonElasticLoadBalancingAsyncClient)2 AmazonS3Client (com.amazonaws.services.s3.AmazonS3Client)2 TransferManager (com.amazonaws.services.s3.transfer.TransferManager)2 PhotonModelMetricServices (com.vmware.photon.controller.model.PhotonModelMetricServices)2 PhotonModelServices (com.vmware.photon.controller.model.PhotonModelServices)2 UriPaths (com.vmware.photon.controller.model.UriPaths)2