Search in sources :

Example 1 with EndpointAllocationTaskState

use of com.vmware.photon.controller.model.tasks.EndpointAllocationTaskService.EndpointAllocationTaskState in project photon-model by vmware.

the class TestAWSCostAdapterService method verifyPersistedStats.

private void verifyPersistedStats(EndpointAllocationTaskState completeState, String metric, int expectedCount) {
    this.host.waitFor("Timeout waiting for stats", () -> {
        QueryTask.QuerySpecification querySpec = new QueryTask.QuerySpecification();
        querySpec.query = QueryTask.Query.Builder.create().addKindFieldClause(ResourceMetrics.class).addFieldClause(ServiceDocument.FIELD_NAME_SELF_LINK, UriUtils.buildUriPath(ResourceMetricsService.FACTORY_LINK, UriUtils.getLastPathSegment(completeState.endpointState.computeLink)), QueryTask.QueryTerm.MatchType.PREFIX).addRangeClause(buildCompositeFieldName(ResourceMetrics.FIELD_NAME_ENTRIES, metric), createDoubleRange(0.0, Double.MAX_VALUE, true, true)).build();
        querySpec.options.add(QueryTask.QuerySpecification.QueryOption.EXPAND_CONTENT);
        ServiceDocumentQueryResult result = this.host.createAndWaitSimpleDirectQuery(querySpec, expectedCount, expectedCount);
        boolean statsCollected = true;
        for (Object metrics : result.documents.values()) {
            ResourceMetrics rawMetrics = Utils.fromJson(metrics, ResourceMetrics.class);
            Double rawMetric = rawMetrics.entries.get(metric);
            if (rawMetric != null) {
                continue;
            }
            statsCollected = false;
        }
        if (metric.equalsIgnoreCase(AWSConstants.COST)) {
            List<ResourceMetrics> accountOneTimeCharges = result.documents.values().stream().map(o -> Utils.fromJson(o, ResourceMetrics.class)).filter(m -> m.entries.containsKey(PhotonModelConstants.ACCOUNT_ONE_TIME_CHARGES)).collect(Collectors.toList());
            if (accountOneTimeCharges.size() != result.documentCount) {
                statsCollected = false;
            }
        }
        return statsCollected;
    });
}
Also used : DateTimeZone(org.joda.time.DateTimeZone) BaseModelTest(com.vmware.photon.controller.model.helpers.BaseModelTest) QueryTask(com.vmware.xenon.services.common.QueryTask) StatsCollectionTaskState(com.vmware.photon.controller.model.tasks.monitoring.StatsCollectionTaskService.StatsCollectionTaskState) ServiceDocument(com.vmware.xenon.common.ServiceDocument) EndpointAllocationTaskService(com.vmware.photon.controller.model.tasks.EndpointAllocationTaskService) SingleResourceStatsCollectionTaskState(com.vmware.photon.controller.model.tasks.monitoring.SingleResourceStatsCollectionTaskService.SingleResourceStatsCollectionTaskState) CommandLineArgumentParser(com.vmware.xenon.common.CommandLineArgumentParser) Utils(com.vmware.xenon.common.Utils) QuerySpecification.buildCompositeFieldName(com.vmware.xenon.services.common.QueryTask.QuerySpecification.buildCompositeFieldName) Map(java.util.Map) After(org.junit.After) ServiceDocumentQueryResult(com.vmware.xenon.common.ServiceDocumentQueryResult) StatsCollectionTaskService(com.vmware.photon.controller.model.tasks.monitoring.StatsCollectionTaskService) EnumSet(java.util.EnumSet) EndpointState(com.vmware.photon.controller.model.resources.EndpointService.EndpointState) EndpointAllocationTaskState(com.vmware.photon.controller.model.tasks.EndpointAllocationTaskService.EndpointAllocationTaskState) ComputeStatsRequest(com.vmware.photon.controller.model.adapterapi.ComputeStatsRequest) StatelessService(com.vmware.xenon.common.StatelessService) INSTANCE_1_SELF_LINK(com.vmware.photon.controller.model.adapters.awsadapter.MockCostStatsAdapterService.INSTANCE_1_SELF_LINK) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) List(java.util.List) UriUtils(com.vmware.xenon.common.UriUtils) TaskState(com.vmware.xenon.common.TaskState) AwsServices(com.vmware.photon.controller.model.adapters.awsadapter.util.AWSCsvBillParser.AwsServices) TaskOption(com.vmware.photon.controller.model.tasks.TaskOption) ResourceMetrics(com.vmware.photon.controller.model.monitoring.ResourceMetricsService.ResourceMetrics) ResourcePoolState(com.vmware.photon.controller.model.resources.ResourcePoolService.ResourcePoolState) HashMap(java.util.HashMap) ResourceMetricsService(com.vmware.photon.controller.model.monitoring.ResourceMetricsService) Function(java.util.function.Function) ArrayList(java.util.ArrayList) EndpointConfigRequest(com.vmware.photon.controller.model.adapterapi.EndpointConfigRequest) NumericRange.createDoubleRange(com.vmware.xenon.services.common.QueryTask.NumericRange.createDoubleRange) ComputeState(com.vmware.photon.controller.model.resources.ComputeService.ComputeState) ComputeStats(com.vmware.photon.controller.model.adapterapi.ComputeStatsResponse.ComputeStats) PhotonModelTaskServices(com.vmware.photon.controller.model.tasks.PhotonModelTaskServices) Operation(com.vmware.xenon.common.Operation) Assert.assertTrue(org.junit.Assert.assertTrue) SingleResourceStatsCollectionTaskService(com.vmware.photon.controller.model.tasks.monitoring.SingleResourceStatsCollectionTaskService) Test(org.junit.Test) ServiceStat(com.vmware.xenon.common.ServiceStats.ServiceStat) LocalDate(org.joda.time.LocalDate) PhotonModelAdaptersRegistryAdapters(com.vmware.photon.controller.model.adapters.registry.PhotonModelAdaptersRegistryAdapters) AWSStatsNormalizer(com.vmware.photon.controller.model.adapters.awsadapter.util.AWSStatsNormalizer) PhotonModelConstants(com.vmware.photon.controller.model.constants.PhotonModelConstants) INSTANCE_2_SELF_LINK(com.vmware.photon.controller.model.adapters.awsadapter.MockCostStatsAdapterService.INSTANCE_2_SELF_LINK) Collections(java.util.Collections) Assert.assertEquals(org.junit.Assert.assertEquals) ResourceMetrics(com.vmware.photon.controller.model.monitoring.ResourceMetricsService.ResourceMetrics) QueryTask(com.vmware.xenon.services.common.QueryTask) ServiceDocumentQueryResult(com.vmware.xenon.common.ServiceDocumentQueryResult)

Example 2 with EndpointAllocationTaskState

use of com.vmware.photon.controller.model.tasks.EndpointAllocationTaskService.EndpointAllocationTaskState in project photon-model by vmware.

the class EndpointRemovalTaskServiceTest method createEndpoint.

private static EndpointState createEndpoint(BaseModelTest test) throws Throwable {
    EndpointState endpoint = createEndpointState();
    // Create endpoint
    EndpointAllocationTaskState startState = createEndpointAllocationRequest(endpoint);
    startState.adapterReference = UriUtils.buildUri(test.getHost(), MockSuccessEndpointAdapter.SELF_LINK);
    EndpointAllocationTaskState returnState = test.postServiceSynchronously(EndpointAllocationTaskService.FACTORY_LINK, startState, EndpointAllocationTaskState.class);
    EndpointAllocationTaskState completeState = test.waitForServiceState(EndpointAllocationTaskState.class, returnState.documentSelfLink, state -> TaskState.TaskStage.FINISHED.ordinal() <= state.taskInfo.stage.ordinal());
    assertThat(completeState.taskInfo.stage, is(TaskState.TaskStage.FINISHED));
    EndpointAllocationTaskState taskState = getServiceSynchronously(test, completeState.documentSelfLink, EndpointAllocationTaskState.class);
    assertNotNull(taskState);
    assertNotNull(taskState.endpointState);
    ServiceDocument endpointState = taskState.endpointState;
    assertNotNull(endpointState.documentSelfLink);
    return getServiceSynchronously(test, endpointState.documentSelfLink, EndpointState.class);
}
Also used : EndpointState(com.vmware.photon.controller.model.resources.EndpointService.EndpointState) EndpointAllocationTaskState(com.vmware.photon.controller.model.tasks.EndpointAllocationTaskService.EndpointAllocationTaskState) ServiceDocument(com.vmware.xenon.common.ServiceDocument)

Example 3 with EndpointAllocationTaskState

use of com.vmware.photon.controller.model.tasks.EndpointAllocationTaskService.EndpointAllocationTaskState in project photon-model by vmware.

the class EndpointServiceTests method testCreateAndThenValidate.

public void testCreateAndThenValidate(EndpointService.EndpointState ep) throws Throwable {
    EndpointAllocationTaskState createEndpoint = new EndpointAllocationTaskState();
    createEndpoint.endpointState = ep;
    createEndpoint.options = this.isMock ? EnumSet.of(TaskOption.IS_MOCK) : null;
    EndpointAllocationTaskState outTask = TestUtils.doPost(this.host, createEndpoint, EndpointAllocationTaskState.class, UriUtils.buildUri(this.host, EndpointAllocationTaskService.FACTORY_LINK));
    this.host.waitForFinishedTask(EndpointAllocationTaskState.class, outTask.documentSelfLink);
    EndpointAllocationTaskState taskState = getServiceSynchronously(outTask.documentSelfLink, EndpointAllocationTaskState.class);
    assertNotNull(taskState);
    assertNotNull(taskState.endpointState);
    ServiceDocument endpointState = taskState.endpointState;
    assertNotNull(endpointState.documentSelfLink);
    // check endpoint document was created
    EndpointService.EndpointState endpoint = getServiceSynchronously(endpointState.documentSelfLink, EndpointService.EndpointState.class);
    // now do validation
    EndpointAllocationTaskState validateEndpoint = new EndpointAllocationTaskState();
    validateEndpoint.endpointState = endpoint;
    validateEndpoint.options = this.isMock ? EnumSet.of(TaskOption.IS_MOCK) : EnumSet.noneOf(TaskOption.class);
    validateEndpoint.options.add(TaskOption.VALIDATE_ONLY);
    EndpointAllocationTaskState validateEndpointTask = TestUtils.doPost(this.host, validateEndpoint, EndpointAllocationTaskState.class, UriUtils.buildUri(this.host, EndpointAllocationTaskService.FACTORY_LINK));
    this.host.waitForFinishedTask(EndpointAllocationTaskState.class, validateEndpointTask.documentSelfLink);
}
Also used : EndpointAllocationTaskState(com.vmware.photon.controller.model.tasks.EndpointAllocationTaskService.EndpointAllocationTaskState) ServiceDocument(com.vmware.xenon.common.ServiceDocument) EndpointService(com.vmware.photon.controller.model.resources.EndpointService) EndpointState(com.vmware.photon.controller.model.resources.EndpointService.EndpointState)

Example 4 with EndpointAllocationTaskState

use of com.vmware.photon.controller.model.tasks.EndpointAllocationTaskService.EndpointAllocationTaskState in project photon-model by vmware.

the class EndpointAllocationTaskServiceTest method createEndpointAllocationRequest.

private static EndpointAllocationTaskState createEndpointAllocationRequest(EndpointState endpoint) {
    EndpointAllocationTaskState endpointAllocationTaskState = new EndpointAllocationTaskState();
    endpointAllocationTaskState.endpointState = endpoint;
    if (endpoint != null) {
        endpointAllocationTaskState.tenantLinks = endpoint.tenantLinks;
    }
    return endpointAllocationTaskState;
}
Also used : EndpointAllocationTaskState(com.vmware.photon.controller.model.tasks.EndpointAllocationTaskService.EndpointAllocationTaskState)

Example 5 with EndpointAllocationTaskState

use of com.vmware.photon.controller.model.tasks.EndpointAllocationTaskService.EndpointAllocationTaskState in project photon-model by vmware.

the class EndpointServiceTests method testValidateCredentials.

public void testValidateCredentials(EndpointService.EndpointState endpoint) throws Throwable {
    EndpointAllocationTaskState validateEndpoint = new EndpointAllocationTaskState();
    validateEndpoint.options = this.isMock ? EnumSet.of(TaskOption.VALIDATE_ONLY, TaskOption.IS_MOCK) : EnumSet.of(TaskOption.VALIDATE_ONLY);
    validateEndpoint.endpointState = endpoint;
    EndpointAllocationTaskState outTask = TestUtils.doPost(this.host, validateEndpoint, EndpointAllocationTaskState.class, UriUtils.buildUri(this.host, EndpointAllocationTaskService.FACTORY_LINK));
    this.host.waitForFinishedTask(EndpointAllocationTaskState.class, outTask.documentSelfLink);
}
Also used : EndpointAllocationTaskState(com.vmware.photon.controller.model.tasks.EndpointAllocationTaskService.EndpointAllocationTaskState)

Aggregations

EndpointAllocationTaskState (com.vmware.photon.controller.model.tasks.EndpointAllocationTaskService.EndpointAllocationTaskState)21 EndpointState (com.vmware.photon.controller.model.resources.EndpointService.EndpointState)14 ServiceDocument (com.vmware.xenon.common.ServiceDocument)6 ComputeState (com.vmware.photon.controller.model.resources.ComputeService.ComputeState)4 TaskState (com.vmware.xenon.common.TaskState)4 ResourcePoolState (com.vmware.photon.controller.model.resources.ResourcePoolService.ResourcePoolState)3 Before (org.junit.Before)3 EndpointType (com.vmware.photon.controller.model.constants.PhotonModelConstants.EndpointType)2 BaseModelTest (com.vmware.photon.controller.model.helpers.BaseModelTest)2 EndpointService (com.vmware.photon.controller.model.resources.EndpointService)2 Operation (com.vmware.xenon.common.Operation)2 QueryTask (com.vmware.xenon.services.common.QueryTask)2 HashMap (java.util.HashMap)2 ComputeStatsRequest (com.vmware.photon.controller.model.adapterapi.ComputeStatsRequest)1 ComputeStats (com.vmware.photon.controller.model.adapterapi.ComputeStatsResponse.ComputeStats)1 EndpointConfigRequest (com.vmware.photon.controller.model.adapterapi.EndpointConfigRequest)1 INSTANCE_1_SELF_LINK (com.vmware.photon.controller.model.adapters.awsadapter.MockCostStatsAdapterService.INSTANCE_1_SELF_LINK)1 INSTANCE_2_SELF_LINK (com.vmware.photon.controller.model.adapters.awsadapter.MockCostStatsAdapterService.INSTANCE_2_SELF_LINK)1 AwsServices (com.vmware.photon.controller.model.adapters.awsadapter.util.AWSCsvBillParser.AwsServices)1 AWSStatsNormalizer (com.vmware.photon.controller.model.adapters.awsadapter.util.AWSStatsNormalizer)1