Search in sources :

Example 16 with ComputeStatsRequest

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

the class TestAWSProvisionTask method issueStatsRequest.

private void issueStatsRequest(ComputeState vm, Long lastCollectionTime) 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 (!TestAWSProvisionTask.this.isMock) {
                    ComputeStatsResponse resp = op.getBody(ComputeStatsResponse.class);
                    if (resp.statsList.size() != 1) {
                        TestAWSProvisionTask.this.host.failIteration(new IllegalStateException("response size was incorrect."));
                        return;
                    }
                    // Size == 1, because APICallCount
                    if (resp.statsList.get(0).statValues.size() == 1) {
                        TestAWSProvisionTask.this.host.failIteration(new IllegalStateException("incorrect number of metrics received."));
                        return;
                    }
                    if (lastCollectionTime != null) {
                        if (resp.statsList.get(0).statValues.get(PhotonModelConstants.CPU_UTILIZATION_PERCENT).size() < 2) {
                            TestAWSProvisionTask.this.host.failIteration(new IllegalStateException("incorrect number of data points received when collection window is specified."));
                            return;
                        }
                    }
                    if (!resp.statsList.get(0).computeLink.equals(vm.documentSelfLink)) {
                        TestAWSProvisionTask.this.host.failIteration(new IllegalStateException("Incorrect resourceReference returned."));
                        return;
                    }
                    verifyCollectedStats(resp, lastCollectionTime);
                }
                TestAWSProvisionTask.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);
    if (lastCollectionTime != null) {
        statsRequest.lastCollectionTimeMicrosUtc = lastCollectionTime;
    }
    this.host.sendAndWait(Operation.createPatch(UriUtils.buildUri(this.host, AWSUriPaths.AWS_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)

Example 17 with ComputeStatsRequest

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

the class TestAWSCostAdapterService method sendStatsRequest.

private void sendStatsRequest(ComputeState account, StatelessService parentService) throws Throwable {
    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, account.documentSelfLink);
    statsRequest.taskReference = UriUtils.buildUri(this.host, servicePath);
    statsRequest.isMockRequest = !this.isMock;
    statsRequest.nextStage = SingleResourceStatsCollectionTaskService.SingleResourceTaskCollectionStage.UPDATE_STATS.name();
    this.host.sendAndWait(Operation.createPatch(UriUtils.buildUri(this.host, MockCostStatsAdapterService.SELF_LINK)).setBody(statsRequest).setReferer(this.host.getUri()));
}
Also used : ComputeStatsRequest(com.vmware.photon.controller.model.adapterapi.ComputeStatsRequest) Operation(com.vmware.xenon.common.Operation)

Example 18 with ComputeStatsRequest

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

Example 19 with ComputeStatsRequest

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

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