use of com.redhat.cloud.notifications.models.EmailAggregation in project notifications-backend by RedHatInsights.
the class ResourceHelpers method addEmailAggregation.
public Boolean addEmailAggregation(String accountId, String orgId, String bundleName, String applicationName, JsonObject payload) {
EmailAggregation aggregation = new EmailAggregation();
aggregation.setAccountId(accountId);
aggregation.setOrgId(orgId);
aggregation.setBundleName(bundleName);
aggregation.setApplicationName(applicationName);
aggregation.setPayload(payload);
return emailAggregationRepository.addEmailAggregation(aggregation);
}
use of com.redhat.cloud.notifications.models.EmailAggregation in project notifications-backend by RedHatInsights.
the class EmailAggregationRepositoryTest method testAllMethodsWithOrgIdUsageEnabled.
@Test
void testAllMethodsWithOrgIdUsageEnabled() {
System.setProperty("notifications.use-org-id", "true");
LocalDateTime start = LocalDateTime.now(UTC).minusHours(1L);
LocalDateTime end = LocalDateTime.now(UTC).plusHours(1L);
EmailAggregationKey key = new EmailAggregationKey(ACCOUNT_ID, ORG_ID, BUNDLE_NAME, APP_NAME);
statelessSessionFactory.withSession(statelessSession -> {
clearEmailAggregations();
resourceHelpers.addEmailAggregation(ACCOUNT_ID, ORG_ID, BUNDLE_NAME, APP_NAME, PAYLOAD1);
resourceHelpers.addEmailAggregation(ACCOUNT_ID, ORG_ID, BUNDLE_NAME, APP_NAME, PAYLOAD2);
resourceHelpers.addEmailAggregation("other-account", ORG_ID, BUNDLE_NAME, APP_NAME, PAYLOAD2);
resourceHelpers.addEmailAggregation(ACCOUNT_ID, ORG_ID, "other-bundle", APP_NAME, PAYLOAD2);
resourceHelpers.addEmailAggregation(ACCOUNT_ID, ORG_ID, BUNDLE_NAME, "other-app", PAYLOAD2);
List<EmailAggregation> aggregations = emailAggregationRepository.getEmailAggregation(key, start, end);
assertEquals(2, aggregations.size());
assertTrue(aggregations.stream().map(EmailAggregation::getAccountId).allMatch(ACCOUNT_ID::equals));
assertTrue(aggregations.stream().map(EmailAggregation::getBundleName).allMatch(BUNDLE_NAME::equals));
assertTrue(aggregations.stream().map(EmailAggregation::getApplicationName).allMatch(APP_NAME::equals));
assertEquals(1, aggregations.stream().map(EmailAggregation::getPayload).filter(PAYLOAD1::equals).count());
assertEquals(1, aggregations.stream().map(EmailAggregation::getPayload).filter(PAYLOAD2::equals).count());
List<EmailAggregationKey> keys = getApplicationsWithPendingAggregation(start, end);
assertEquals(4, keys.size());
assertEquals(ORG_ID, aggregations.get(0).getOrgId());
assertEquals(ACCOUNT_ID, keys.get(0).getAccountId());
assertEquals(BUNDLE_NAME, keys.get(0).getBundle());
assertEquals(APP_NAME, keys.get(0).getApplication());
assertEquals(2, emailAggregationRepository.purgeOldAggregation(key, end));
assertEquals(0, emailAggregationRepository.getEmailAggregation(key, start, end).size());
assertEquals(3, getApplicationsWithPendingAggregation(start, end).size());
clearEmailAggregations();
});
}
use of com.redhat.cloud.notifications.models.EmailAggregation in project notifications-backend by RedHatInsights.
the class EmailAggregationResourcesTest method addEmailAggregation.
private void addEmailAggregation(String accountId, String bundleName, String applicationName, JsonObject payload) {
EmailAggregation aggregation = new EmailAggregation();
aggregation.setAccountId(accountId);
aggregation.setBundleName(bundleName);
aggregation.setApplicationName(applicationName);
aggregation.setPayload(payload);
resourceHelpers.addEmailAggregation(aggregation);
}
use of com.redhat.cloud.notifications.models.EmailAggregation in project notifications-backend by RedHatInsights.
the class RhosakEmailAggregatorTest method upgradesAggregationTests.
@Test
void upgradesAggregationTests() {
String kafkaName = "my-kafka";
String firstKafkaVersion = "2.8.0";
String kafkaVersion = "kafka_version";
String upgrade_time = "upgrade_time";
// test first aggregation
EmailAggregation aggregation = createUpgradeEmailAggregation(kafkaName, firstKafkaVersion);
aggregator.processEmailAggregation(aggregation);
assertEquals(1, upgrades.size(), "aggregator should have one disruption body");
JsonObject entry = upgrades.getJsonObject(kafkaName);
assertNotNull(entry);
assertEquals(firstKafkaVersion, entry.getString(kafkaVersion));
assertNotNull(entry.getString(upgrade_time));
// test second aggregation
String secondKafkaVersion = "3.0.0";
aggregation = createUpgradeEmailAggregation(kafkaName, secondKafkaVersion);
aggregator.processEmailAggregation(aggregation);
assertEquals(1, upgrades.size(), "aggregator should still have one disruption body");
entry = upgrades.getJsonObject(kafkaName);
assertEquals(firstKafkaVersion + ", " + secondKafkaVersion, entry.getString(kafkaVersion));
// same upgrade happening again
aggregation = createUpgradeEmailAggregation(kafkaName, "2.8.0 ");
aggregator.processEmailAggregation(aggregation);
assertEquals(1, upgrades.size(), "aggregator should still have one disruption body");
entry = upgrades.getJsonObject(kafkaName);
assertEquals(firstKafkaVersion + ", " + secondKafkaVersion, entry.getString(kafkaVersion));
// test fifth aggregation with another kafka
String kafkaName1 = "another-kafka-name";
aggregation = createUpgradeEmailAggregation(kafkaName1, firstKafkaVersion);
aggregator.processEmailAggregation(aggregation);
assertEquals(2, upgrades.size(), "aggregator should still have two disruption bodies");
entry = upgrades.getJsonObject(kafkaName1);
assertEquals(firstKafkaVersion, entry.getString(kafkaVersion));
// there has been no upgrades aggregation
assertEquals(0, disruptions.size(), "scheduled upgrades only aggregator should have empty disruption body");
}
use of com.redhat.cloud.notifications.models.EmailAggregation in project notifications-backend by RedHatInsights.
the class RhosakEmailAggregatorTest method createUpgradeEmailAggregation.
private static EmailAggregation createUpgradeEmailAggregation(String kafkaName, String kafkaVersion) {
EmailAggregation aggregation = new EmailAggregation();
aggregation.setBundleName(APPLICATION_SERVICES);
aggregation.setApplicationName(RHOSAK);
aggregation.setAccountId(ACCOUNT_ID);
Action emailActionMessage = new Action();
emailActionMessage.setBundle(APPLICATION_SERVICES);
emailActionMessage.setApplication(RHOSAK);
emailActionMessage.setTimestamp(NOW);
emailActionMessage.setEventType(SCHEDULED_UPGRADE);
emailActionMessage.setContext(new Context.ContextBuilder().withAdditionalProperty("kafka_version", kafkaVersion).withAdditionalProperty("upgrade_time", LocalDateTime.now().toString()).build());
emailActionMessage.setEvents(List.of(new Event.EventBuilder().withMetadata(new Metadata.MetadataBuilder().build()).withPayload(new Payload.PayloadBuilder().withAdditionalProperty("id", kafkaName).withAdditionalProperty("name", kafkaName).build()).build()));
emailActionMessage.setAccountId(ACCOUNT_ID);
JsonObject payload = baseTransformer.transform(emailActionMessage);
aggregation.setPayload(payload);
return aggregation;
}
Aggregations