Search in sources :

Example 11 with EmailAggregation

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);
}
Also used : EmailAggregation(com.redhat.cloud.notifications.models.EmailAggregation)

Example 12 with EmailAggregation

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();
    });
}
Also used : LocalDateTime(java.time.LocalDateTime) EmailAggregationKey(com.redhat.cloud.notifications.models.EmailAggregationKey) EmailAggregation(com.redhat.cloud.notifications.models.EmailAggregation) QuarkusTest(io.quarkus.test.junit.QuarkusTest) Test(org.junit.jupiter.api.Test)

Example 13 with EmailAggregation

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);
}
Also used : EmailAggregation(com.redhat.cloud.notifications.models.EmailAggregation)

Example 14 with EmailAggregation

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");
}
Also used : JsonObject(io.vertx.core.json.JsonObject) EmailAggregation(com.redhat.cloud.notifications.models.EmailAggregation) QuarkusTest(io.quarkus.test.junit.QuarkusTest) Test(org.junit.jupiter.api.Test)

Example 15 with EmailAggregation

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;
}
Also used : Action(com.redhat.cloud.notifications.ingress.Action) Event(com.redhat.cloud.notifications.ingress.Event) JsonObject(io.vertx.core.json.JsonObject) Payload(com.redhat.cloud.notifications.ingress.Payload) EmailAggregation(com.redhat.cloud.notifications.models.EmailAggregation)

Aggregations

EmailAggregation (com.redhat.cloud.notifications.models.EmailAggregation)19 JsonObject (io.vertx.core.json.JsonObject)13 Action (com.redhat.cloud.notifications.ingress.Action)11 Event (com.redhat.cloud.notifications.ingress.Event)9 Payload (com.redhat.cloud.notifications.ingress.Payload)8 Context (com.redhat.cloud.notifications.ingress.Context)5 QuarkusTest (io.quarkus.test.junit.QuarkusTest)5 Test (org.junit.jupiter.api.Test)5 EmailAggregationKey (com.redhat.cloud.notifications.models.EmailAggregationKey)4 LocalDateTime (java.time.LocalDateTime)4 EmailAggregationRepository (com.redhat.cloud.notifications.db.repositories.EmailAggregationRepository)2 EmailSubscriptionRepository (com.redhat.cloud.notifications.db.repositories.EmailSubscriptionRepository)2 EmailSubscriptionType (com.redhat.cloud.notifications.models.EmailSubscriptionType)2 Endpoint (com.redhat.cloud.notifications.models.Endpoint)2 RecipientResolver (com.redhat.cloud.notifications.recipients.RecipientResolver)2 User (com.redhat.cloud.notifications.recipients.User)2 ActionRecipientSettings (com.redhat.cloud.notifications.recipients.request.ActionRecipientSettings)2 EndpointRecipientSettings (com.redhat.cloud.notifications.recipients.request.EndpointRecipientSettings)2 TemplateInstance (io.quarkus.qute.TemplateInstance)2 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1