Skip to content

Commit

Permalink
[RHCLOUD-28935] Add OCM Cluster updates email template (RedHatInsight…
Browse files Browse the repository at this point in the history
…s#2339)


Co-authored-by: Gwenneg Lepage <[email protected]>
  • Loading branch information
g-duval and gwenneg authored Nov 14, 2023
1 parent b3443f3 commit 1271855
Show file tree
Hide file tree
Showing 5 changed files with 169 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,11 @@ public List<String> migrate() {
"OCM/severityWarningInstantEmailTitle", "txt", "OCM Service Logs warning severity email title",
"OCM/severityWarningInstantEmailBody", "html", "OCM Service Logs warning severity email body"
);
createInstantEmailTemplate(
warnings, "openshift", "cluster-manager", List.of("cluster-update"),
"OCM/clusterUpdateInstantEmailTitle", "txt", "OCM cluster update title",
"OCM/clusterUpdateInstantEmailBody", "html", "OCM cluster update email body"
);

/*
* Former src/main/resources/templates/Patch folder.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
{@boolean renderSection1=true}
{@boolean renderSection2=true}
{#include Common/insightsEmailBody}
{#content-title}
Cluster Manager - OpenShift
{/content-title}
{#content-title-section1}
{#if action.events[0].payload.global_vars.upgrade_status == 'scheduled'}Upgrade scheduled{#else}Upgrade ended{/if}
{/content-title-section1}
{#content-body-section1}
{#let global_var=action.events[0].payload.global_vars}
<p>
This notification is for your <a href="https://cloud.redhat.com/openshift/details/s/{action.events[0].payload.subscription_id}#overview" target="_blank" title="*|CLUSTER_DISPLAY_NAME|*">{action.events[0].payload.cluster_display_name} cluster</a>.
</p>
<p>
Your {global_var.log_description}.
</p>
{#if global_var.upgrade_status == 'scheduled'}
<p>
<strong>What can you expect?</strong>
<ul>
<li>Your cluster capacity may increase briefly during the course of the upgrade but will never decrease. Your cluster will remain operational during the upgrade.</li>
<li>If your applications are not designed as highly available, they may experience brief outages as we roll through the upgrade.</li>
<li>We will send reminders as we get closer to the upgrade date. The maintenance window for the upgrade is variable and should take approximately 90 minutes for the control plane nodes and 10 minutes for each worker node.</li>
</ul>

<strong>What should you do to minimize impact?</strong>
<ul>
<li>You can minimize the impact on your applications by scaling your services to more than one pod. In general, for applications to be able to continue to service clients, they should be scaled.</li>
<li>Some pod workloads are not appropriate for scaling, such as a single-instance, non-replicated database using a persistent volume claim. In this situation, a deployment strategy of 'recreate' will ensure the pod is restarted after migration, although a brief outage will be experienced.</li>
</ul>

<strong>For more information, refer to</strong> <a href="https://www.openshift.com/blog/deploying-highly-available-applications-openshift-kubernetes" target="_blank" title="OpenShift HA guide blog">our highly available deployment guide</a>.
</p>
{/if}
{/let}
{/content-body-section1}
{#content-title-section2}
More info
{/content-title-section2}
{#content-body-section2}
If you have any questions, please <a href="https://access.redhat.com/support/contact/technicalSupport/" target="_blank" title="Red Hat Support">contact us</a>. Review the <a href="https://access.redhat.com/support/policy/support_process" target="_blank" title="Red Hat support process">support process</a> for guidance on working with Red Hat support.
<br/><br/>
Thank you for choosing Red Hat OpenShift {#switch action.events[0].payload.global_vars.subscription_plan}{#case 'OSD'}Dedicated{#case 'OSDTrial'}Dedicated Trial{#case 'MOA'}Service on AWS{/switch}.
{/content-body-section2}
{/include}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{action.events[0].payload.subject}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package com.redhat.cloud.notifications;

import com.redhat.cloud.notifications.ingress.Action;
import com.redhat.cloud.notifications.ingress.Context;
import com.redhat.cloud.notifications.ingress.Event;
import com.redhat.cloud.notifications.ingress.Metadata;
import com.redhat.cloud.notifications.ingress.Payload;
import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;

import static com.redhat.cloud.notifications.TestConstants.DEFAULT_ORG_ID;

public class OcmTestHelpers {

public static Action createOcmAction(String clusterDisplayName, String subscriptionPlan, String logDescription, String upgradeStatus, String subject) {
Action emailActionMessage = new Action();
emailActionMessage.setBundle("openshift");
emailActionMessage.setApplication("cluster-manager");
emailActionMessage.setTimestamp(LocalDateTime.now());
emailActionMessage.setEventType("testEmailSubscriptionInstant");

emailActionMessage.setContext(
new Context.ContextBuilder()
.withAdditionalProperty("system_check_in", "2021-07-13T15:22:42.199046")
.withAdditionalProperty("tags", List.of())
.build()
);
Map<String, String> globalVars = Map.of(
"cluster_display_name", clusterDisplayName,
"subscription_id", "2XqNHRdLNEAzshh7MkkOql6fx6I",
"subscription_plan", subscriptionPlan,
"log_description", logDescription,
"upgrade_status", upgradeStatus
);
emailActionMessage.setEvents(List.of(
new Event.EventBuilder()
.withMetadata(new Metadata.MetadataBuilder().build())
.withPayload(
new Payload.PayloadBuilder()
.withAdditionalProperty("global_vars", globalVars)
.withAdditionalProperty("subject", subject)
.build()
)
.build()
));

emailActionMessage.setOrgId(DEFAULT_ORG_ID);

return emailActionMessage;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package com.redhat.cloud.notifications.templates;

import com.redhat.cloud.notifications.EmailTemplatesInDbHelper;
import com.redhat.cloud.notifications.OcmTestHelpers;
import com.redhat.cloud.notifications.TestHelpers;
import com.redhat.cloud.notifications.ingress.Action;
import io.quarkus.test.junit.QuarkusTest;
import org.junit.jupiter.api.Test;
import java.util.List;
import java.util.Map;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;

@QuarkusTest
public class TestOcmTemplate extends EmailTemplatesInDbHelper {

private static final String EVENT_TYPE_NAME = "cluster-update";

@Override
protected String getBundle() {
return "openshift";
}

@Override
protected String getApp() {
return "cluster-manager";
}

@Override
protected List<String> getUsedEventTypeNames() {
return List.of(EVENT_TYPE_NAME);
}

@Test
public void testUpgradeEmailTitle() {
Action action = OcmTestHelpers.createOcmAction("Batcave", "OSDTrial", "<b>Batmobile</b> need a revision", "scheduled", "Awesome subject");

String result = generateEmailSubject(EVENT_TYPE_NAME, action);
assertEquals("Awesome subject", result);
}

@Test
public void testUpgradeScheduledInstantEmailBody() {
Action action = OcmTestHelpers.createOcmAction("Batcave", "OSDTrial", "<b>Batmobile</b> need a revision", "scheduled", "Awesome subject");
String result = generateEmailBody(EVENT_TYPE_NAME, action);
assertTrue(result.contains(TestHelpers.HCC_LOGO_TARGET));
assertTrue(result.contains("Upgrade scheduled"));
assertTrue(result.contains(((Map<String, String>) action.getEvents().get(0).getPayload().getAdditionalProperties().get("global_vars")).get("log_description")));
assertTrue(result.contains("What can you expect"));
assertTrue(result.contains("Thank you for choosing Red Hat OpenShift Dedicated Trial."));
}

@Test
public void testUpgradeEndedInstantEmailBody() {
Action action = OcmTestHelpers.createOcmAction("Batcave", "MOA", "<b>Batmobile</b> is ready to go", "ended", "Awesome subject");
String result = generateEmailBody(EVENT_TYPE_NAME, action);
assertTrue(result.contains(TestHelpers.HCC_LOGO_TARGET));
assertTrue(result.contains("Upgrade ended"));
assertTrue(result.contains(((Map<String, String>) action.getEvents().get(0).getPayload().getAdditionalProperties().get("global_vars")).get("log_description")));
assertFalse(result.contains("What can you expect"));
assertTrue(result.contains("Thank you for choosing Red Hat OpenShift Service on AWS."));
}
}

0 comments on commit 1271855

Please sign in to comment.