From 3a34bf2915a0a52500ca8fea6c8340089137e91a Mon Sep 17 00:00:00 2001 From: Michael Stead Date: Mon, 9 Dec 2024 14:51:11 -0400 Subject: [PATCH] Remove hardware measurement type from billable usage and remittance This patch removes the hardware measurement type from billable usage and remittance since it does not apply to remittance in general. --- ...ement-type-from-billable-usage-remittance.xml | 16 ++++++++++++++++ src/main/resources/liquibase/changelog.xml | 1 + .../data/BillableUsageRemittanceEntity.java | 3 --- .../data/BillableUsageRemittanceFilter.java | 1 - .../data/BillableUsageRemittanceRepository.java | 14 -------------- .../usage/data/RemittanceSummaryProjection.java | 1 - .../usage/services/BillableUsageMapper.java | 1 - .../usage/services/BillableUsageService.java | 1 - .../BillableUsageRemittanceRepositoryTest.java | 13 +------------ .../usage/services/BillableUsageMapperTest.java | 1 - .../usage/services/BillableUsageServiceTest.java | 1 - swatch-core/schemas/billable_usage.yaml | 3 --- 12 files changed, 18 insertions(+), 38 deletions(-) create mode 100644 src/main/resources/liquibase/202412091327-drop-hardware-measurement-type-from-billable-usage-remittance.xml diff --git a/src/main/resources/liquibase/202412091327-drop-hardware-measurement-type-from-billable-usage-remittance.xml b/src/main/resources/liquibase/202412091327-drop-hardware-measurement-type-from-billable-usage-remittance.xml new file mode 100644 index 0000000000..99bd77a5be --- /dev/null +++ b/src/main/resources/liquibase/202412091327-drop-hardware-measurement-type-from-billable-usage-remittance.xml @@ -0,0 +1,16 @@ + + + + Drop the hardware_measurement_type column from billable_usage_remittance table. + + + + + + + + diff --git a/src/main/resources/liquibase/changelog.xml b/src/main/resources/liquibase/changelog.xml index 525edda8d2..fa1dac7d85 100644 --- a/src/main/resources/liquibase/changelog.xml +++ b/src/main/resources/liquibase/changelog.xml @@ -175,5 +175,6 @@ + diff --git a/swatch-billable-usage/src/main/java/com/redhat/swatch/billable/usage/data/BillableUsageRemittanceEntity.java b/swatch-billable-usage/src/main/java/com/redhat/swatch/billable/usage/data/BillableUsageRemittanceEntity.java index 360460cbd3..16b5ecf99a 100644 --- a/swatch-billable-usage/src/main/java/com/redhat/swatch/billable/usage/data/BillableUsageRemittanceEntity.java +++ b/swatch-billable-usage/src/main/java/com/redhat/swatch/billable/usage/data/BillableUsageRemittanceEntity.java @@ -85,9 +85,6 @@ public class BillableUsageRemittanceEntity implements Serializable { @Column(name = "tally_id") private UUID tallyId; - @Column(name = "hardware_measurement_type") - private String hardwareMeasurementType; - @Column(name = "status") private RemittanceStatus status; diff --git a/swatch-billable-usage/src/main/java/com/redhat/swatch/billable/usage/data/BillableUsageRemittanceFilter.java b/swatch-billable-usage/src/main/java/com/redhat/swatch/billable/usage/data/BillableUsageRemittanceFilter.java index 88143b5895..ef1c3ace13 100644 --- a/swatch-billable-usage/src/main/java/com/redhat/swatch/billable/usage/data/BillableUsageRemittanceFilter.java +++ b/swatch-billable-usage/src/main/java/com/redhat/swatch/billable/usage/data/BillableUsageRemittanceFilter.java @@ -46,7 +46,6 @@ public class BillableUsageRemittanceFilter { private String metricId; private String billingProvider; private String billingAccountId; - private String hardwareMeasurementType; private OffsetDateTime beginning; private OffsetDateTime ending; private String accumulationPeriod; diff --git a/swatch-billable-usage/src/main/java/com/redhat/swatch/billable/usage/data/BillableUsageRemittanceRepository.java b/swatch-billable-usage/src/main/java/com/redhat/swatch/billable/usage/data/BillableUsageRemittanceRepository.java index 8474f84bd6..475b540300 100644 --- a/swatch-billable-usage/src/main/java/com/redhat/swatch/billable/usage/data/BillableUsageRemittanceRepository.java +++ b/swatch-billable-usage/src/main/java/com/redhat/swatch/billable/usage/data/BillableUsageRemittanceRepository.java @@ -64,7 +64,6 @@ public List getRemittanceSummaries( root.get(BillableUsageRemittanceEntity_.METRIC_ID), root.get(BillableUsageRemittanceEntity_.ORG_ID), root.get(BillableUsageRemittanceEntity_.PRODUCT_ID), - root.get(BillableUsageRemittanceEntity_.HARDWARE_MEASUREMENT_TYPE), root.get(BillableUsageRemittanceEntity_.STATUS), root.get(BillableUsageRemittanceEntity_.ERROR_CODE)); } @@ -81,7 +80,6 @@ public List getRemittanceSummaries( root.get(BillableUsageRemittanceEntity_.BILLING_PROVIDER), root.get(BillableUsageRemittanceEntity_.BILLING_ACCOUNT_ID), root.get(BillableUsageRemittanceEntity_.METRIC_ID), - root.get(BillableUsageRemittanceEntity_.HARDWARE_MEASUREMENT_TYPE), root.get(BillableUsageRemittanceEntity_.STATUS), root.get(BillableUsageRemittanceEntity_.ERROR_CODE))); return entityManager.createQuery(query).getResultList(); @@ -171,10 +169,6 @@ private Specification buildSearchSpecification( if (Objects.nonNull(filter.getSla())) { searchCriteria = searchCriteria.and(matchingSla(filter.getSla())); } - if (Objects.nonNull(filter.getHardwareMeasurementType())) { - searchCriteria = - searchCriteria.and(matchingHardwareMeasurementType(filter.getHardwareMeasurementType())); - } if (filter.isExcludeFailures()) { searchCriteria = searchCriteria.and(excludesFailures()); } @@ -193,14 +187,6 @@ private Specification excludesFailures() { root.get(BillableUsageRemittanceEntity_.status), RemittanceStatus.FAILED)); } - private Specification matchingHardwareMeasurementType( - String hardwareMeasurementType) { - return (root, query, builder) -> - builder.equal( - root.get(BillableUsageRemittanceEntity_.hardwareMeasurementType), - hardwareMeasurementType); - } - private static Specification matchingProductId(String productId) { return (root, query, builder) -> builder.equal(root.get(BillableUsageRemittanceEntity_.productId), productId); diff --git a/swatch-billable-usage/src/main/java/com/redhat/swatch/billable/usage/data/RemittanceSummaryProjection.java b/swatch-billable-usage/src/main/java/com/redhat/swatch/billable/usage/data/RemittanceSummaryProjection.java index 2f9789e19c..fad2d686f3 100644 --- a/swatch-billable-usage/src/main/java/com/redhat/swatch/billable/usage/data/RemittanceSummaryProjection.java +++ b/swatch-billable-usage/src/main/java/com/redhat/swatch/billable/usage/data/RemittanceSummaryProjection.java @@ -41,7 +41,6 @@ public class RemittanceSummaryProjection { private String billingProvider; private String billingAccountId; private String metricId; - private String hardwareMeasurementType; private RemittanceStatus status; private RemittanceErrorCode errorCode; } diff --git a/swatch-billable-usage/src/main/java/com/redhat/swatch/billable/usage/services/BillableUsageMapper.java b/swatch-billable-usage/src/main/java/com/redhat/swatch/billable/usage/services/BillableUsageMapper.java index e1b26ffe76..ec9b20dfa0 100644 --- a/swatch-billable-usage/src/main/java/com/redhat/swatch/billable/usage/services/BillableUsageMapper.java +++ b/swatch-billable-usage/src/main/java/com/redhat/swatch/billable/usage/services/BillableUsageMapper.java @@ -112,7 +112,6 @@ private BillableUsage toBillableUsage( .withBillingAccountId(snapshot.getBillingAccountId()) .withMetricId(measurement.getMetricId()) .withValue(measurement.getValue()) - .withHardwareMeasurementType(measurement.getHardwareMeasurementType()) .withCurrentTotal(measurement.getCurrentTotal()); } diff --git a/swatch-billable-usage/src/main/java/com/redhat/swatch/billable/usage/services/BillableUsageService.java b/swatch-billable-usage/src/main/java/com/redhat/swatch/billable/usage/services/BillableUsageService.java index 22d9f0ad21..4a091d0fe1 100644 --- a/swatch-billable-usage/src/main/java/com/redhat/swatch/billable/usage/services/BillableUsageService.java +++ b/swatch-billable-usage/src/main/java/com/redhat/swatch/billable/usage/services/BillableUsageService.java @@ -235,7 +235,6 @@ private void createRemittance( .usage(usage.getUsage().value()) .remittancePendingDate(clock.now()) .tallyId(usage.getTallyId()) - .hardwareMeasurementType(usage.getHardwareMeasurementType()) .status( contractCoverage.isGratis() ? RemittanceStatus.GRATIS : RemittanceStatus.PENDING) .build(); diff --git a/swatch-billable-usage/src/test/java/com/redhat/swatch/billable/usage/data/BillableUsageRemittanceRepositoryTest.java b/swatch-billable-usage/src/test/java/com/redhat/swatch/billable/usage/data/BillableUsageRemittanceRepositoryTest.java index 7d47264e0a..1bbae093c9 100644 --- a/swatch-billable-usage/src/test/java/com/redhat/swatch/billable/usage/data/BillableUsageRemittanceRepositoryTest.java +++ b/swatch-billable-usage/src/test/java/com/redhat/swatch/billable/usage/data/BillableUsageRemittanceRepositoryTest.java @@ -135,7 +135,6 @@ private BillableUsageRemittanceEntity remittance( .accumulationPeriod(AccumulationPeriodFormatter.toMonthId(remittanceDate)) .remittancePendingDate(remittanceDate) .remittedPendingValue(value) - .hardwareMeasurementType("AWS") .build(); } @@ -335,7 +334,6 @@ void getMonthlySummary() { .totalRemittedPendingValue(24.0) .sla(remittance1.getSla()) .usage(remittance1.getUsage()) - .hardwareMeasurementType("AWS") .build(); var expectedSummary2 = @@ -350,7 +348,6 @@ void getMonthlySummary() { .totalRemittedPendingValue(15.0) .sla(remittance3.getSla()) .usage(remittance3.getUsage()) - .hardwareMeasurementType("AWS") .build(); List results = repository.getRemittanceSummaries(filter1); @@ -370,7 +367,6 @@ void testRemittanceFilterUsedByBillableUsageService() { String billingProvider = "aws"; String billingAccountId = "ba123456789"; String remittancePendingDateStr = "2024-06-19T16:52:17.526219+00:00"; - String hardwareMeasurementType = "AWS"; var billableUsageNoExpected = BillableUsageRemittanceEntity.builder() @@ -387,7 +383,6 @@ void testRemittanceFilterUsedByBillableUsageService() { OffsetDateTime.parse( remittancePendingDateStr, DateTimeFormatter.ISO_OFFSET_DATE_TIME)) .tallyId(UUID.randomUUID()) - .hardwareMeasurementType(hardwareMeasurementType) .status(RemittanceStatus.PENDING) .build(); @@ -406,7 +401,6 @@ void testRemittanceFilterUsedByBillableUsageService() { OffsetDateTime.parse( remittancePendingDateStr, DateTimeFormatter.ISO_OFFSET_DATE_TIME)) .tallyId(UUID.randomUUID()) - .hardwareMeasurementType(hardwareMeasurementType) .status(RemittanceStatus.PENDING) .build(); @@ -426,7 +420,6 @@ void testRemittanceFilterUsedByBillableUsageService() { OffsetDateTime.parse( remittancePendingDateStr, DateTimeFormatter.ISO_OFFSET_DATE_TIME)) .tallyId(UUID.randomUUID()) - .hardwareMeasurementType("PHYSICAL") .status(RemittanceStatus.SUCCEEDED) .build(); repository.persist( @@ -446,8 +439,7 @@ void testRemittanceFilterUsedByBillableUsageService() { .withMetricId(metricId) .withProductId(productTag) .withUsage(BillableUsage.Usage.PRODUCTION) - .withSla(BillableUsage.Sla.PREMIUM) - .withHardwareMeasurementType("PHYSICAL"); + .withSla(BillableUsage.Sla.PREMIUM); // Build the filter the same way that we do in the billable usage in the service. var filter = BillableUsageRemittanceFilter.totalRemittedFilter(incomingUsage); @@ -470,8 +462,6 @@ void testRemittanceFilterUsedByBillableUsageService() { .totalRemittedPendingValue(expectedRemittedPendingValue) .sla(billableUsageRemittanceFromRhelemeter.getSla()) .usage(billableUsageRemittanceFromRhelemeter.getUsage()) - .hardwareMeasurementType( - billableUsageRemittanceFromRhelemeter.getHardwareMeasurementType()) .status(billableUsageRemittanceFromRhelemeter.getStatus()) .build(); @@ -490,7 +480,6 @@ void testRemittanceFilterUsedByBillableUsageService() { .totalRemittedPendingValue(billableUsageRemittanceFromCost.getRemittedPendingValue()) .sla(billableUsageRemittanceFromCost.getSla()) .usage(billableUsageRemittanceFromCost.getUsage()) - .hardwareMeasurementType(billableUsageRemittanceFromCost.getHardwareMeasurementType()) .status(billableUsageRemittanceFromCost.getStatus()) .build(); diff --git a/swatch-billable-usage/src/test/java/com/redhat/swatch/billable/usage/services/BillableUsageMapperTest.java b/swatch-billable-usage/src/test/java/com/redhat/swatch/billable/usage/services/BillableUsageMapperTest.java index bc9f5e8a60..62c5d2d2e2 100644 --- a/swatch-billable-usage/src/test/java/com/redhat/swatch/billable/usage/services/BillableUsageMapperTest.java +++ b/swatch-billable-usage/src/test/java/com/redhat/swatch/billable/usage/services/BillableUsageMapperTest.java @@ -194,7 +194,6 @@ void shouldProduceBillableUsageWhenOrgIdPresent() { .withBillingAccountId(expectedBillingAccountId) .withMetricId(expectedMetricId) .withValue(42.0) - .withHardwareMeasurementType("PHYSICAL") .withCurrentTotal(expectedCurrentTotal); var summary = diff --git a/swatch-billable-usage/src/test/java/com/redhat/swatch/billable/usage/services/BillableUsageServiceTest.java b/swatch-billable-usage/src/test/java/com/redhat/swatch/billable/usage/services/BillableUsageServiceTest.java index ce80d72ffa..f22e2ccf20 100644 --- a/swatch-billable-usage/src/test/java/com/redhat/swatch/billable/usage/services/BillableUsageServiceTest.java +++ b/swatch-billable-usage/src/test/java/com/redhat/swatch/billable/usage/services/BillableUsageServiceTest.java @@ -593,7 +593,6 @@ void givenExistingRemittanceForUsage( .usage(usage.getUsage().value()) .remittancePendingDate(remittancePendingDate) .tallyId(usage.getTallyId()) - .hardwareMeasurementType(usage.getHardwareMeasurementType()) .status(status) .build(); // Remitted value should be set to usages metric_value rather than billing_value diff --git a/swatch-core/schemas/billable_usage.yaml b/swatch-core/schemas/billable_usage.yaml index d906e1b344..703d6f583d 100644 --- a/swatch-core/schemas/billable_usage.yaml +++ b/swatch-core/schemas/billable_usage.yaml @@ -79,9 +79,6 @@ properties: vendor_product_code: description: Field used to specify a unique contract type: string - hardware_measurement_type: - type: string - format: string currentTotal: description: Sum of all measurements between the start of the month to the snapshot date. type: number