From 03d24d4315e3e2b27c67aec415e9191c897c1db8 Mon Sep 17 00:00:00 2001 From: Guillaume Duval Date: Wed, 20 Nov 2024 16:20:31 +0100 Subject: [PATCH] Removing IAggregationCommand interface --- .../DailyEmailAggregationJob.java | 12 ++-- .../db/EmailAggregationRepository.java | 8 +-- .../DailyEmailAggregationJobTest.java | 11 ++-- .../DailyEventAggregationJobTest.java | 39 ++++++------ .../db/EmailAggregationRepositoryTest.java | 12 ++-- .../models/AggregationCommand.java | 15 +++-- .../models/EventAggregationCommand.java | 60 ------------------- .../models/IAggregationCommand.java | 15 ----- .../email/EmailAggregationProcessor.java | 9 ++- 9 files changed, 52 insertions(+), 129 deletions(-) delete mode 100644 common/src/main/java/com/redhat/cloud/notifications/models/EventAggregationCommand.java delete mode 100644 common/src/main/java/com/redhat/cloud/notifications/models/IAggregationCommand.java diff --git a/aggregator/src/main/java/com/redhat/cloud/notifications/DailyEmailAggregationJob.java b/aggregator/src/main/java/com/redhat/cloud/notifications/DailyEmailAggregationJob.java index 9af6c98197..3a9fe59d99 100644 --- a/aggregator/src/main/java/com/redhat/cloud/notifications/DailyEmailAggregationJob.java +++ b/aggregator/src/main/java/com/redhat/cloud/notifications/DailyEmailAggregationJob.java @@ -9,7 +9,7 @@ import com.redhat.cloud.notifications.ingress.Metadata; import com.redhat.cloud.notifications.ingress.Parser; import com.redhat.cloud.notifications.ingress.Payload; -import com.redhat.cloud.notifications.models.IAggregationCommand; +import com.redhat.cloud.notifications.models.AggregationCommand; import io.prometheus.client.CollectorRegistry; import io.prometheus.client.Gauge; import io.prometheus.client.exporter.PushGateway; @@ -82,11 +82,11 @@ public void processDailyEmail() { } else { aggregationOrgConfigRepository.createMissingDefaultConfiguration(defaultDailyDigestTime); } - List aggregationCommands = processAggregateEmailsWithOrgPref(now, registry); + List aggregationCommands = processAggregateEmailsWithOrgPref(now, registry); Log.infof("found %s commands", aggregationCommands.size()); Log.debugf("Aggregation commands: %s", aggregationCommands); - aggregationCommands.stream().collect(Collectors.groupingBy(IAggregationCommand::getOrgId)) + aggregationCommands.stream().collect(Collectors.groupingBy(AggregationCommand::getOrgId)) .values().forEach(this::sendIt); List orgIdsToUpdate = aggregationCommands.stream().map(aggregationCommand -> aggregationCommand.getOrgId()).collect(Collectors.toList()); @@ -139,9 +139,9 @@ protected LocalDateTime computeScheduleExecutionTime() { } } - List processAggregateEmailsWithOrgPref(LocalDateTime endTime, CollectorRegistry registry) { + List processAggregateEmailsWithOrgPref(LocalDateTime endTime, CollectorRegistry registry) { - List pendingAggregationCommands; + List pendingAggregationCommands; if (aggregatorConfig.isAggregationBasedOnEventEnabled()) { pendingAggregationCommands = emailAggregationResources.getApplicationsWithPendingAggregationAccordingOrgPref(endTime); } else { @@ -157,7 +157,7 @@ List processAggregateEmailsWithOrgPref(LocalDateTime endTim return pendingAggregationCommands; } - private void sendIt(List aggregationCommands) { + private void sendIt(List aggregationCommands) { List eventList = new ArrayList<>(); aggregationCommands.stream().forEach(aggregationCommand -> { diff --git a/aggregator/src/main/java/com/redhat/cloud/notifications/db/EmailAggregationRepository.java b/aggregator/src/main/java/com/redhat/cloud/notifications/db/EmailAggregationRepository.java index 9a2afcaafe..241127db2f 100644 --- a/aggregator/src/main/java/com/redhat/cloud/notifications/db/EmailAggregationRepository.java +++ b/aggregator/src/main/java/com/redhat/cloud/notifications/db/EmailAggregationRepository.java @@ -2,9 +2,7 @@ import com.redhat.cloud.notifications.models.AggregationCommand; import com.redhat.cloud.notifications.models.EmailAggregationKey; -import com.redhat.cloud.notifications.models.EventAggregationCommand; import com.redhat.cloud.notifications.models.EventAggregationCriteria; -import com.redhat.cloud.notifications.models.IAggregationCommand; import jakarta.enterprise.context.ApplicationScoped; import jakarta.inject.Inject; import jakarta.persistence.EntityManager; @@ -25,7 +23,7 @@ public class EmailAggregationRepository { @Inject EntityManager entityManager; - public List getApplicationsWithPendingAggregationAccordinfOrgPref(LocalDateTime now) { + public List getApplicationsWithPendingAggregationAccordinfOrgPref(LocalDateTime now) { // Must takes every EmailAggregation supposed to be processed on last 15 min // it covers cases when aggregation job may be run with few minutes late (ie: 05:01, 07,32) String query = "SELECT DISTINCT ea.orgId, ea.bundleName, ea.applicationName, acp.lastRun FROM EmailAggregation ea, AggregationOrgConfig acp WHERE " + @@ -47,7 +45,7 @@ public List getApplicationsWithPendingAggregationAccordinfO .collect(toList()); } - public List getApplicationsWithPendingAggregationAccordingOrgPref(LocalDateTime now) { + public List getApplicationsWithPendingAggregationAccordingOrgPref(LocalDateTime now) { String query = "SELECT DISTINCT ev.orgId, ev.bundleId, ev.applicationId, acp.lastRun, bu.name, ap.name FROM Event ev " + "join Application ap on ev.applicationId = ap.id join Bundle bu on ev.bundleId = bu.id " + "left join AggregationOrgConfig acp on ev.orgId = acp.orgId " + @@ -61,7 +59,7 @@ public List getApplicationsWithPendingAggregationAccordingO List records = hqlQuery.getResultList(); return records.stream() - .map(emailAggregationRecord -> new EventAggregationCommand( + .map(emailAggregationRecord -> new AggregationCommand( new EventAggregationCriteria((String) emailAggregationRecord[0], (UUID) emailAggregationRecord[1], (UUID) emailAggregationRecord[2], (String) emailAggregationRecord[4], (String) emailAggregationRecord[5]), (LocalDateTime) emailAggregationRecord[3], now, diff --git a/aggregator/src/test/java/com/redhat/cloud/notifications/DailyEmailAggregationJobTest.java b/aggregator/src/test/java/com/redhat/cloud/notifications/DailyEmailAggregationJobTest.java index 48ca2358ab..40b3364ebb 100644 --- a/aggregator/src/test/java/com/redhat/cloud/notifications/DailyEmailAggregationJobTest.java +++ b/aggregator/src/test/java/com/redhat/cloud/notifications/DailyEmailAggregationJobTest.java @@ -7,7 +7,6 @@ import com.redhat.cloud.notifications.ingress.Parser; import com.redhat.cloud.notifications.models.AggregationCommand; import com.redhat.cloud.notifications.models.AggregationOrgConfig; -import com.redhat.cloud.notifications.models.IAggregationCommand; import io.prometheus.client.CollectorRegistry; import io.prometheus.client.Gauge; import io.quarkus.test.common.QuarkusTestResource; @@ -259,7 +258,7 @@ void shouldProcessFourAggregations() { helpers.addEmailAggregation("someOrgId", "unknown-bundle", "unknown-application", "somePolicyId", "someHostId"); helpers.addAggregationOrgConfig(someOrgIdToProceed); - final List emailAggregations = testee.processAggregateEmailsWithOrgPref(LocalDateTime.now(UTC), new CollectorRegistry()); + final List emailAggregations = testee.processAggregateEmailsWithOrgPref(LocalDateTime.now(UTC), new CollectorRegistry()); assertEquals(4, emailAggregations.size()); } @@ -271,7 +270,7 @@ void shouldProcessOneAggregationOnly() { helpers.addEmailAggregation("someOrgId", "rhel", "policies", "somePolicyId", "someHostId"); helpers.addAggregationOrgConfig(someOrgIdToProceed); - final List emailAggregations = testee.processAggregateEmailsWithOrgPref(LocalDateTime.now(UTC), new CollectorRegistry()); + final List emailAggregations = testee.processAggregateEmailsWithOrgPref(LocalDateTime.now(UTC), new CollectorRegistry()); assertEquals(1, emailAggregations.size()); @@ -289,7 +288,7 @@ void shouldNotIncreaseAggregationsWhenPolicyIdIsDifferent() { helpers.addEmailAggregation("shouldBeIgnoredOrgId", "someRhel", "somePolicies", "policyId1", "someHostId"); helpers.addAggregationOrgConfig(someOrgIdToProceed); - final List emailAggregations = testee.processAggregateEmailsWithOrgPref(LocalDateTime.now(UTC), new CollectorRegistry()); + final List emailAggregations = testee.processAggregateEmailsWithOrgPref(LocalDateTime.now(UTC), new CollectorRegistry()); assertEquals(1, emailAggregations.size()); } @@ -301,7 +300,7 @@ void shouldNotIncreaseAggregationsWhenHostIdIsDifferent() { helpers.addEmailAggregation("shouldBeIgnoredOrgId", "someRhel", "somePolicies", "somePolicyId", "hostId2"); helpers.addAggregationOrgConfig(someOrgIdToProceed); - List emailAggregations = null; + List emailAggregations = null; emailAggregations = testee.processAggregateEmailsWithOrgPref(LocalDateTime.now(UTC), new CollectorRegistry()); assertEquals(1, emailAggregations.size()); } @@ -309,7 +308,7 @@ void shouldNotIncreaseAggregationsWhenHostIdIsDifferent() { @Test void shouldProcessZeroAggregations() { helpers.addAggregationOrgConfig(someOrgIdToProceed); - final List emailAggregations = testee.processAggregateEmailsWithOrgPref(LocalDateTime.now(UTC), new CollectorRegistry()); + final List emailAggregations = testee.processAggregateEmailsWithOrgPref(LocalDateTime.now(UTC), new CollectorRegistry()); assertEquals(0, emailAggregations.size()); } diff --git a/aggregator/src/test/java/com/redhat/cloud/notifications/DailyEventAggregationJobTest.java b/aggregator/src/test/java/com/redhat/cloud/notifications/DailyEventAggregationJobTest.java index 7499dd5918..d3821bd56c 100644 --- a/aggregator/src/test/java/com/redhat/cloud/notifications/DailyEventAggregationJobTest.java +++ b/aggregator/src/test/java/com/redhat/cloud/notifications/DailyEventAggregationJobTest.java @@ -7,11 +7,11 @@ import com.redhat.cloud.notifications.ingress.Action; import com.redhat.cloud.notifications.ingress.Event; import com.redhat.cloud.notifications.ingress.Parser; +import com.redhat.cloud.notifications.models.AggregationCommand; import com.redhat.cloud.notifications.models.AggregationOrgConfig; import com.redhat.cloud.notifications.models.Application; -import com.redhat.cloud.notifications.models.EventAggregationCommand; +import com.redhat.cloud.notifications.models.EventAggregationCriteria; import com.redhat.cloud.notifications.models.EventType; -import com.redhat.cloud.notifications.models.IAggregationCommand; import com.redhat.cloud.notifications.models.SubscriptionType; import io.prometheus.client.CollectorRegistry; import io.prometheus.client.Gauge; @@ -98,14 +98,17 @@ void initAggregationParameters() { dailyEmailAggregationJob.defaultDailyDigestTime = LocalTime.now(ZoneOffset.UTC); } - List getRecordsFromKafka() { - List aggregationCommands = new ArrayList<>(); + List getRecordsFromKafka() { + List aggregationCommands = new ArrayList<>(); InMemorySink results = connector.sink(DailyEmailAggregationJob.EGRESS_CHANNEL); for (Message message : results.received()) { Action action = Parser.decode(String.valueOf(message.getPayload())); for (Event event : action.getEvents()) { - aggregationCommands.add(objectMapper.convertValue(event.getPayload().getAdditionalProperties(), EventAggregationCommand.class)); + AggregationCommand aggCommand = objectMapper.convertValue(event.getPayload().getAdditionalProperties(), AggregationCommand.class); + EventAggregationCriteria aggregationCriteria = objectMapper.convertValue(event.getPayload().getAdditionalProperties().get("aggregationKey"), EventAggregationCriteria.class); + aggCommand.setAggregationKey(aggregationCriteria); + aggregationCommands.add(aggCommand); } } @@ -123,7 +126,7 @@ void shouldSentFourAggregationsToKafkaTopic() { dailyEmailAggregationJob.processDailyEmail(); - List listCommand = getRecordsFromKafka(); + List listCommand = getRecordsFromKafka(); assertEquals(4, listCommand.size()); checkAggCommand(listCommand, "anotherOrgId", "rhel", "policies"); checkAggCommand(listCommand, "anotherOrgId", "rhel", "unknown-application"); @@ -145,7 +148,7 @@ void shouldSentTwoAggregationsToKafkaTopic() { // Because we added time preferences for orgId someOrgId two hours in the past, those messages must be ignored dailyEmailAggregationJob.processDailyEmail(); - List listCommand = getRecordsFromKafka(); + List listCommand = getRecordsFromKafka(); assertEquals(2, listCommand.size()); checkAggCommand(listCommand, "anotherOrgId", "rhel", "policies"); @@ -177,13 +180,13 @@ void shouldSentTwoAggregationsToKafkaTopic() { checkAggCommand(listCommand, "someOrgId", "rhel", "unknown-application"); } - private void checkAggCommand(List commands, String orgId, String bundleName, String applicationName) { + private void checkAggCommand(List commands, String orgId, String bundleName, String applicationName) { Application application = resourceHelpers.findApp(bundleName, applicationName); assertTrue(commands.stream().anyMatch( com -> orgId.equals(com.getAggregationKey().getOrgId()) && - application.getBundleId().equals(com.getAggregationKey().getBundleId()) && - application.getId().equals(com.getAggregationKey().getApplicationId()) && + application.getBundleId().equals(((EventAggregationCriteria) com.getAggregationKey()).getBundleId()) && + application.getId().equals(((EventAggregationCriteria) com.getAggregationKey()).getApplicationId()) && DAILY.equals(com.getSubscriptionType()) )); } @@ -284,7 +287,7 @@ void shouldProcessFourAggregations() { addEventEmailAggregation("someOrgId", "unknown-bundle", "unknown-application", "somePolicyId", "someHostId"); helpers.addAggregationOrgConfig(someOrgIdToProceed); - final List emailAggregations = dailyEmailAggregationJob.processAggregateEmailsWithOrgPref(LocalDateTime.now(UTC), new CollectorRegistry()); + final List emailAggregations = dailyEmailAggregationJob.processAggregateEmailsWithOrgPref(LocalDateTime.now(UTC), new CollectorRegistry()); assertEquals(4, emailAggregations.size()); } @@ -296,15 +299,15 @@ void shouldProcessOneAggregationOnly() { addEventEmailAggregation("someOrgId", "rhel", "policies", "somePolicyId", "someHostId"); helpers.addAggregationOrgConfig(someOrgIdToProceed); - final List emailAggregations = dailyEmailAggregationJob.processAggregateEmailsWithOrgPref(LocalDateTime.now(UTC), new CollectorRegistry()); + final List emailAggregations = dailyEmailAggregationJob.processAggregateEmailsWithOrgPref(LocalDateTime.now(UTC), new CollectorRegistry()); assertEquals(1, emailAggregations.size()); - final EventAggregationCommand aggregationCommand = (EventAggregationCommand) emailAggregations.get(0); + final AggregationCommand aggregationCommand = (AggregationCommand) emailAggregations.get(0); assertEquals("someOrgId", aggregationCommand.getAggregationKey().getOrgId()); Application application = resourceHelpers.findApp("rhel", "policies"); - assertEquals(application.getBundleId(), aggregationCommand.getAggregationKey().getBundleId()); - assertEquals(application.getId(), aggregationCommand.getAggregationKey().getApplicationId()); + assertEquals(application.getBundleId(), ((EventAggregationCriteria) aggregationCommand.getAggregationKey()).getBundleId()); + assertEquals(application.getId(), ((EventAggregationCriteria) aggregationCommand.getAggregationKey()).getApplicationId()); assertEquals(DAILY, aggregationCommand.getSubscriptionType()); } @@ -315,7 +318,7 @@ void shouldNotIncreaseAggregationsWhenPolicyIdIsDifferent() { addEventEmailAggregation("shouldBeIgnoredOrgId", "some-rhel", "some-policies", "policyId1", "someHostId"); helpers.addAggregationOrgConfig(someOrgIdToProceed); - final List emailAggregations = dailyEmailAggregationJob.processAggregateEmailsWithOrgPref(LocalDateTime.now(UTC), new CollectorRegistry()); + final List emailAggregations = dailyEmailAggregationJob.processAggregateEmailsWithOrgPref(LocalDateTime.now(UTC), new CollectorRegistry()); assertEquals(1, emailAggregations.size()); } @@ -327,14 +330,14 @@ void shouldNotIncreaseAggregationsWhenHostIdIsDifferent() { addEventEmailAggregation("shouldBeIgnoredOrgId", "some-rhel", "some-policies", "somePolicyId", "hostId2"); helpers.addAggregationOrgConfig(someOrgIdToProceed); - List emailAggregations = dailyEmailAggregationJob.processAggregateEmailsWithOrgPref(LocalDateTime.now(UTC), new CollectorRegistry()); + List emailAggregations = dailyEmailAggregationJob.processAggregateEmailsWithOrgPref(LocalDateTime.now(UTC), new CollectorRegistry()); assertEquals(1, emailAggregations.size()); } @Test void shouldProcessZeroAggregations() { helpers.addAggregationOrgConfig(someOrgIdToProceed); - final List emailAggregations = dailyEmailAggregationJob.processAggregateEmailsWithOrgPref(LocalDateTime.now(UTC), new CollectorRegistry()); + final List emailAggregations = dailyEmailAggregationJob.processAggregateEmailsWithOrgPref(LocalDateTime.now(UTC), new CollectorRegistry()); assertEquals(0, emailAggregations.size()); } diff --git a/aggregator/src/test/java/com/redhat/cloud/notifications/db/EmailAggregationRepositoryTest.java b/aggregator/src/test/java/com/redhat/cloud/notifications/db/EmailAggregationRepositoryTest.java index d1ab154ea3..da2faf17cd 100644 --- a/aggregator/src/test/java/com/redhat/cloud/notifications/db/EmailAggregationRepositoryTest.java +++ b/aggregator/src/test/java/com/redhat/cloud/notifications/db/EmailAggregationRepositoryTest.java @@ -2,14 +2,14 @@ import com.redhat.cloud.notifications.TestLifecycleManager; import com.redhat.cloud.notifications.helpers.ResourceHelpers; +import com.redhat.cloud.notifications.models.AggregationCommand; import com.redhat.cloud.notifications.models.AggregationOrgConfig; import com.redhat.cloud.notifications.models.Application; import com.redhat.cloud.notifications.models.EmailAggregation; import com.redhat.cloud.notifications.models.EmailAggregationKey; import com.redhat.cloud.notifications.models.Event; -import com.redhat.cloud.notifications.models.EventAggregationCommand; +import com.redhat.cloud.notifications.models.EventAggregationCriteria; import com.redhat.cloud.notifications.models.EventType; -import com.redhat.cloud.notifications.models.IAggregationCommand; import com.redhat.cloud.notifications.models.SubscriptionType; import io.quarkus.test.common.QuarkusTestResource; import io.quarkus.test.junit.QuarkusTest; @@ -76,7 +76,7 @@ void testApplicationsWithPendingAggregationAccordinfOrgPref() { EmailAggregationKey key = new EmailAggregationKey(ORG_ID, BUNDLE_NAME, APP_NAME); - List keys = emailAggregationResources.getApplicationsWithPendingAggregationAccordinfOrgPref(end); + List keys = emailAggregationResources.getApplicationsWithPendingAggregationAccordinfOrgPref(end); assertEquals(4, keys.size()); assertEquals(ORG_ID, keys.get(0).getOrgId()); assertEquals(BUNDLE_NAME, keys.get(0).getAggregationKey().getBundle()); @@ -108,11 +108,11 @@ void testApplicationsWithPendingAggregationAccordingOrgPref() { addEventEmailAggregation(ORG_ID, "other-bundle", APP_NAME, PAYLOAD2); addEventEmailAggregation(ORG_ID, BUNDLE_NAME, "other-app", PAYLOAD2); - List keys = emailAggregationResources.getApplicationsWithPendingAggregationAccordingOrgPref(end); + List keys = emailAggregationResources.getApplicationsWithPendingAggregationAccordingOrgPref(end); assertEquals(4, keys.size()); Application application = resourceHelpers.findApp(BUNDLE_NAME, APP_NAME); - List matchedKeys = keys.stream().filter(k -> ORG_ID.equals(k.getOrgId())).filter(k -> ((EventAggregationCommand) k).getAggregationKey().getApplicationId().equals(application.getId())).collect(Collectors.toList()); + List matchedKeys = keys.stream().filter(k -> ORG_ID.equals(k.getOrgId())).filter(k -> (((EventAggregationCriteria) k.getAggregationKey()).getApplicationId().equals(application.getId()))).collect(Collectors.toList()); assertEquals(1, matchedKeys.size()); assertEquals(BUNDLE_NAME, matchedKeys.get(0).getAggregationKey().getBundle()); assertEquals(APP_NAME, matchedKeys.get(0).getAggregationKey().getApplication()); @@ -122,7 +122,7 @@ void testApplicationsWithPendingAggregationAccordingOrgPref() { keys = emailAggregationResources.getApplicationsWithPendingAggregationAccordingOrgPref(end); assertEquals(3, keys.size()); - matchedKeys = keys.stream().filter(k -> ORG_ID.equals(k.getOrgId())).filter(k -> ((EventAggregationCommand) k).getAggregationKey().getApplicationId().equals(application.getId())).collect(Collectors.toList()); + matchedKeys = keys.stream().filter(k -> ORG_ID.equals(k.getOrgId())).filter(k -> (((EventAggregationCriteria) k.getAggregationKey()).getApplicationId().equals(application.getId()))).collect(Collectors.toList()); assertEquals(0, matchedKeys.size()); } diff --git a/common/src/main/java/com/redhat/cloud/notifications/models/AggregationCommand.java b/common/src/main/java/com/redhat/cloud/notifications/models/AggregationCommand.java index c3485a70a7..40e2239c5c 100644 --- a/common/src/main/java/com/redhat/cloud/notifications/models/AggregationCommand.java +++ b/common/src/main/java/com/redhat/cloud/notifications/models/AggregationCommand.java @@ -3,10 +3,10 @@ import jakarta.validation.constraints.NotNull; import java.time.LocalDateTime; -public class AggregationCommand implements IAggregationCommand { +public class AggregationCommand { @NotNull - private final EmailAggregationKey aggregationKey; + private T aggregationKey; @NotNull private final LocalDateTime start; @@ -17,38 +17,37 @@ public class AggregationCommand implements IAggregationCommand { @NotNull private final SubscriptionType subscriptionType; - public AggregationCommand(EmailAggregationKey aggregationKey, LocalDateTime start, LocalDateTime end, SubscriptionType subscriptionType) { + public AggregationCommand(T aggregationKey, LocalDateTime start, LocalDateTime end, SubscriptionType subscriptionType) { this.aggregationKey = aggregationKey; this.start = start; this.end = end; this.subscriptionType = subscriptionType; } + public void setAggregationKey(@NotNull T aggregationKey) { + this.aggregationKey = aggregationKey; + } + public EmailAggregationKey getAggregationKey() { return aggregationKey; } - @Override public LocalDateTime getStart() { return start; } - @Override public LocalDateTime getEnd() { return end; } - @Override public SubscriptionType getSubscriptionType() { return subscriptionType; } - @Override public String getOrgId() { return aggregationKey.getOrgId(); } - @Override public String toString() { return "AggregationCommand{" + "aggregationKey=" + aggregationKey + diff --git a/common/src/main/java/com/redhat/cloud/notifications/models/EventAggregationCommand.java b/common/src/main/java/com/redhat/cloud/notifications/models/EventAggregationCommand.java deleted file mode 100644 index 5078da855f..0000000000 --- a/common/src/main/java/com/redhat/cloud/notifications/models/EventAggregationCommand.java +++ /dev/null @@ -1,60 +0,0 @@ -package com.redhat.cloud.notifications.models; - -import jakarta.validation.constraints.NotNull; -import java.time.LocalDateTime; - -public class EventAggregationCommand implements IAggregationCommand { - - @NotNull - private final EventAggregationCriteria aggregationKey; - - @NotNull - private final LocalDateTime start; - - @NotNull - private final LocalDateTime end; - - @NotNull - private final SubscriptionType subscriptionType; - - public EventAggregationCommand(EventAggregationCriteria aggregationKey, LocalDateTime start, LocalDateTime end, SubscriptionType subscriptionType) { - this.aggregationKey = aggregationKey; - this.start = start; - this.end = end; - this.subscriptionType = subscriptionType; - } - - public EventAggregationCriteria getAggregationKey() { - return aggregationKey; - } - - @Override - public LocalDateTime getStart() { - return start; - } - - @Override - public LocalDateTime getEnd() { - return end; - } - - @Override - public SubscriptionType getSubscriptionType() { - return subscriptionType; - } - - @Override - public String getOrgId() { - return aggregationKey.getOrgId(); - } - - @Override - public String toString() { - return "AggregationCommand{" + - "aggregationKey=" + aggregationKey + - ", start=" + start + - ", end=" + end + - ", subscriptionType=" + subscriptionType + - '}'; - } -} diff --git a/common/src/main/java/com/redhat/cloud/notifications/models/IAggregationCommand.java b/common/src/main/java/com/redhat/cloud/notifications/models/IAggregationCommand.java deleted file mode 100644 index 4dc42fa5d3..0000000000 --- a/common/src/main/java/com/redhat/cloud/notifications/models/IAggregationCommand.java +++ /dev/null @@ -1,15 +0,0 @@ -package com.redhat.cloud.notifications.models; - -import java.time.LocalDateTime; - -public interface IAggregationCommand { - LocalDateTime getStart(); - - LocalDateTime getEnd(); - - SubscriptionType getSubscriptionType(); - - String getOrgId(); - - T getAggregationKey(); -} diff --git a/engine/src/main/java/com/redhat/cloud/notifications/processors/email/EmailAggregationProcessor.java b/engine/src/main/java/com/redhat/cloud/notifications/processors/email/EmailAggregationProcessor.java index 43bd9660a8..a78f128dcb 100644 --- a/engine/src/main/java/com/redhat/cloud/notifications/processors/email/EmailAggregationProcessor.java +++ b/engine/src/main/java/com/redhat/cloud/notifications/processors/email/EmailAggregationProcessor.java @@ -18,7 +18,6 @@ import com.redhat.cloud.notifications.models.EndpointType; import com.redhat.cloud.notifications.models.Event; import com.redhat.cloud.notifications.models.EventType; -import com.redhat.cloud.notifications.models.IAggregationCommand; import com.redhat.cloud.notifications.models.SubscriptionType; import com.redhat.cloud.notifications.models.Template; import com.redhat.cloud.notifications.processors.ConnectorSender; @@ -199,7 +198,7 @@ public void processAggregationAsync(Event event) { public void processAggregationSync(Event event) { - List aggregationCommands = new ArrayList<>(); + List aggregationCommands = new ArrayList<>(); Timer.Sample consumedTimer = Timer.start(registry); try { @@ -245,7 +244,7 @@ public void processAggregationSync(Event event) { } } - private void processBundleAggregation(List aggregationCommands, Event aggregatorEvent) { + private void processBundleAggregation(List aggregationCommands, Event aggregatorEvent) { final String bundleName = aggregationCommands.get(0).getAggregationKey().getBundle(); // Patch event display name for event log rendering Bundle bundle = bundleRepository.getBundle(bundleName) @@ -264,7 +263,7 @@ private void processBundleAggregation(List aggregationComma //Store every aggregated application data for each user Map> userData = new HashMap<>(); - for (IAggregationCommand applicationAggregationCommand : aggregationCommands) { + for (AggregationCommand applicationAggregationCommand : aggregationCommands) { Log.debugf("Processing aggregation command: %s", applicationAggregationCommand); try { @@ -358,7 +357,7 @@ private void processBundleAggregation(List aggregationComma } }); - for (IAggregationCommand applicationAggregationCommand : aggregationCommands) { + for (AggregationCommand applicationAggregationCommand : aggregationCommands) { emailAggregationRepository.purgeOldAggregation(applicationAggregationCommand.getAggregationKey(), applicationAggregationCommand.getEnd()); } }