Search in sources :

Example 1 with INSTANCE_1_SELF_LINK

use of com.vmware.photon.controller.model.adapters.awsadapter.MockCostStatsAdapterService.INSTANCE_1_SELF_LINK in project photon-model by vmware.

the class TestAWSCostAdapterService method verifyCollectedStats.

private void verifyCollectedStats(List<ComputeStats> statsList) {
    Map<String, ComputeStats> computeStatsByLink = statsList.stream().collect(Collectors.toMap(e -> e.computeLink, Function.identity(), (allStats, stats) -> {
        allStats.statValues.putAll(stats.statValues);
        return allStats;
    }));
    ComputeStats account1Stats = computeStatsByLink.get(account1SelfLink);
    ComputeStats account2Stats = computeStatsByLink.get(account2SelfLink);
    String normalizedStatKeyValue = AWSStatsNormalizer.getNormalizedStatKeyValue(AWSConstants.COST);
    // verify account costs
    assertTrue(account1Stats.statValues.get(normalizedStatKeyValue).get(0).latestValue == account1TotalCost);
    assertTrue(account2Stats.statValues.get(normalizedStatKeyValue).get(0).latestValue == account2TotalCost);
    // check that service level stats exist
    String serviceCode = AwsServices.EC2_Instance_Usage.getName().replaceAll(" ", "");
    String serviceResourceCostMetric = String.format(AWSConstants.SERVICE_RESOURCE_COST, serviceCode);
    assertTrue(!account1Stats.statValues.get(serviceResourceCostMetric).isEmpty());
    String serviceCode2 = AwsServices.EC2_Others.getName().replaceAll(" ", "");
    String serviceOtherCostMetric = String.format(AWSConstants.SERVICE_OTHER_COST, serviceCode2);
    assertTrue(!account1Stats.statValues.get(serviceOtherCostMetric).isEmpty());
    String serviceMonthlyOtherCostMetric = String.format(AWSConstants.SERVICE_MONTHLY_OTHER_COST, serviceCode2);
    assertTrue(!account1Stats.statValues.get(serviceMonthlyOtherCostMetric).isEmpty());
    String serviceReservedRecurringCostMetric = String.format(AWSConstants.SERVICE_RESERVED_RECURRING_COST, serviceCode2);
    assertTrue(!account1Stats.statValues.get(serviceReservedRecurringCostMetric).isEmpty());
    ComputeStats instance1Stats = computeStatsByLink.get(INSTANCE_1_SELF_LINK);
    ComputeStats instance2Stats = computeStatsByLink.get(INSTANCE_2_SELF_LINK);
    assertEquals(instance1TotalCost, instance1Stats.statValues.get(normalizedStatKeyValue).get(0).latestValue, 0);
    assertEquals(instance2TotalCost, instance2Stats.statValues.get(normalizedStatKeyValue).get(0).latestValue, 0);
    String normalizedReservedInstanceStatKeyValue = AWSStatsNormalizer.getNormalizedStatKeyValue(AWSConstants.RESERVED_INSTANCE_DURATION);
    assertEquals(1.0, instance1Stats.statValues.get(normalizedReservedInstanceStatKeyValue).get(0).latestValue, 0);
    assertEquals(1.0, instance1Stats.statValues.get(normalizedReservedInstanceStatKeyValue).get(0).latestValue, 0);
    // Check that stat values are accompanied with Units.
    for (String key : account1Stats.statValues.keySet()) {
        List<ServiceStat> stats = account1Stats.statValues.get(key);
        for (ServiceStat stat : stats) {
            assertTrue("Unit is empty", !stat.unit.isEmpty());
        }
    }
}
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) ServiceStat(com.vmware.xenon.common.ServiceStats.ServiceStat) ComputeStats(com.vmware.photon.controller.model.adapterapi.ComputeStatsResponse.ComputeStats)

Aggregations

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 PhotonModelAdaptersRegistryAdapters (com.vmware.photon.controller.model.adapters.registry.PhotonModelAdaptersRegistryAdapters)1 PhotonModelConstants (com.vmware.photon.controller.model.constants.PhotonModelConstants)1 BaseModelTest (com.vmware.photon.controller.model.helpers.BaseModelTest)1 ResourceMetricsService (com.vmware.photon.controller.model.monitoring.ResourceMetricsService)1 ResourceMetrics (com.vmware.photon.controller.model.monitoring.ResourceMetricsService.ResourceMetrics)1 ComputeState (com.vmware.photon.controller.model.resources.ComputeService.ComputeState)1 EndpointState (com.vmware.photon.controller.model.resources.EndpointService.EndpointState)1 ResourcePoolState (com.vmware.photon.controller.model.resources.ResourcePoolService.ResourcePoolState)1 EndpointAllocationTaskService (com.vmware.photon.controller.model.tasks.EndpointAllocationTaskService)1 EndpointAllocationTaskState (com.vmware.photon.controller.model.tasks.EndpointAllocationTaskService.EndpointAllocationTaskState)1 PhotonModelTaskServices (com.vmware.photon.controller.model.tasks.PhotonModelTaskServices)1 TaskOption (com.vmware.photon.controller.model.tasks.TaskOption)1 SingleResourceStatsCollectionTaskService (com.vmware.photon.controller.model.tasks.monitoring.SingleResourceStatsCollectionTaskService)1