From 5acd7583082cc1144ec5f84e6ca31fc611d1ac1e Mon Sep 17 00:00:00 2001 From: Andy Foster Date: Tue, 24 Aug 2021 20:01:07 -0400 Subject: [PATCH] Make domain in notifications configurable Resolves: https://duracloud.atlassian.net/browse/DURACLOUD-1304 --- common-dup/pom.xml | 6 ++++ .../mill/dup/util/DefaultPolicyGenerator.java | 7 +++-- .../mill/config/ConfigConstants.java | 2 ++ .../mill/config/ConfigurationManager.java | 13 +++++++++ .../util/PropertyDefinitionListBuilder.java | 1 + pom.xml | 6 ++++ ...CreatedNotifcationGeneratingProcessor.java | 5 +++- .../bit/BitIntegrityReportTaskProcessor.java | 4 ++- ...edNotificationGeneratingProcessorTest.java | 29 +++++++++++++++++-- 9 files changed, 66 insertions(+), 7 deletions(-) diff --git a/common-dup/pom.xml b/common-dup/pom.xml index 3c271226..cb5ccb44 100644 --- a/common-dup/pom.xml +++ b/common-dup/pom.xml @@ -16,6 +16,12 @@ + + org.duracloud.mill + common + ${project.version} + + org.duracloud common diff --git a/common-dup/src/main/java/org/duracloud/mill/dup/util/DefaultPolicyGenerator.java b/common-dup/src/main/java/org/duracloud/mill/dup/util/DefaultPolicyGenerator.java index 48865009..1a48f7b9 100644 --- a/common-dup/src/main/java/org/duracloud/mill/dup/util/DefaultPolicyGenerator.java +++ b/common-dup/src/main/java/org/duracloud/mill/dup/util/DefaultPolicyGenerator.java @@ -19,6 +19,7 @@ import org.duracloud.common.constant.Constants; import org.duracloud.common.model.Credential; import org.duracloud.error.ContentStoreException; +import org.duracloud.mill.config.ConfigurationManager; import org.duracloud.mill.dup.DuplicationPolicy; import org.duracloud.mill.dup.DuplicationStorePolicy; import org.duracloud.mill.dup.repo.DuplicationPolicyRepo; @@ -34,7 +35,6 @@ */ public class DefaultPolicyGenerator { - private static final String DURACLOUD_URL_SUFFIX = ".duracloud.org"; private static final String DURACLOUD_PORT = "443"; private static final String DURACLOUD_ROOT_USER = "root"; @@ -74,7 +74,10 @@ public DuplicationPolicy createDefaultDupPolicy(String account, private ContentStoreManager connectToDuraCloud(String account, String rootPass) throws ContentStoreException { - String host = account + DURACLOUD_URL_SUFFIX; + + ConfigurationManager configManager = new ConfigurationManager(); + String host = configManager.getSubdomainDotDefaultDomain(account); + ContentStoreManager storeManager = new ContentStoreManagerImpl(host, DURACLOUD_PORT); Credential credential = new Credential(DURACLOUD_ROOT_USER, rootPass); diff --git a/common/src/main/java/org/duracloud/mill/config/ConfigConstants.java b/common/src/main/java/org/duracloud/mill/config/ConfigConstants.java index 622efa17..3c98a907 100644 --- a/common/src/main/java/org/duracloud/mill/config/ConfigConstants.java +++ b/common/src/main/java/org/duracloud/mill/config/ConfigConstants.java @@ -52,6 +52,8 @@ public class ConfigConstants { public static final String NOTIFICATION_USER = "notification.user"; public static final String NOTIFICATION_PASS = "notification.pass"; + public static final String DURACLOUD_SITE_DOMAIN = "duracloud-site.domain"; + /* * AUDIT LOG GENERATOR */ diff --git a/common/src/main/java/org/duracloud/mill/config/ConfigurationManager.java b/common/src/main/java/org/duracloud/mill/config/ConfigurationManager.java index 8bad8328..6c73dd0d 100644 --- a/common/src/main/java/org/duracloud/mill/config/ConfigurationManager.java +++ b/common/src/main/java/org/duracloud/mill/config/ConfigurationManager.java @@ -8,6 +8,7 @@ package org.duracloud.mill.config; import org.apache.commons.lang3.StringUtils; +import org.duracloud.common.constant.Constants; import org.duracloud.common.model.EmailerType; import org.duracloud.common.queue.QueueType; @@ -106,4 +107,16 @@ private String[] getCommaSeparatedListToArray(String prop) { public String[] getNotificationRecipientsNonTech() { return getCommaSeparatedListToArray(ConfigConstants.NOTIFICATION_RECIPIENTS_NON_TECH); } + + public String getDefaultDomain() { + String domain = System.getProperty(ConfigConstants.DURACLOUD_SITE_DOMAIN); + if (domain == null) { + domain = Constants.DEFAULT_DOMAIN; + } + return domain; + } + + public String getSubdomainDotDefaultDomain(String subdomain) { + return subdomain + "." + getDefaultDomain(); + } } diff --git a/common/src/main/java/org/duracloud/mill/util/PropertyDefinitionListBuilder.java b/common/src/main/java/org/duracloud/mill/util/PropertyDefinitionListBuilder.java index 270b21f5..579fa758 100644 --- a/common/src/main/java/org/duracloud/mill/util/PropertyDefinitionListBuilder.java +++ b/common/src/main/java/org/duracloud/mill/util/PropertyDefinitionListBuilder.java @@ -129,6 +129,7 @@ public PropertyDefinitionListBuilder addNotificationConfig() { add(ConfigConstants.NOTIFICATION_PORT, false); add(ConfigConstants.NOTIFICATION_USER, false); add(ConfigConstants.NOTIFICATION_PASS, false, true); + add(ConfigConstants.DURACLOUD_SITE_DOMAIN, false); return this; } diff --git a/pom.xml b/pom.xml index 4fef402a..1b959cec 100644 --- a/pom.xml +++ b/pom.xml @@ -823,6 +823,12 @@ ${hibernate.version} + + org.javassist + javassist + 3.24.0-GA + + mysql mysql-connector-java diff --git a/workman/src/main/java/org/duracloud/mill/audit/SpaceCreatedNotifcationGeneratingProcessor.java b/workman/src/main/java/org/duracloud/mill/audit/SpaceCreatedNotifcationGeneratingProcessor.java index 771b5c0c..ba2ec55b 100644 --- a/workman/src/main/java/org/duracloud/mill/audit/SpaceCreatedNotifcationGeneratingProcessor.java +++ b/workman/src/main/java/org/duracloud/mill/audit/SpaceCreatedNotifcationGeneratingProcessor.java @@ -8,6 +8,7 @@ package org.duracloud.mill.audit; import org.duracloud.audit.task.AuditTask; +import org.duracloud.mill.config.ConfigurationManager; import org.duracloud.mill.notification.NotificationManager; import org.duracloud.mill.workman.TaskExecutionFailedException; import org.duracloud.mill.workman.TaskProcessor; @@ -60,7 +61,9 @@ private void newSpace(String subdomain, String datetime, String username) { - String host = subdomain + ".duracloud.org"; + ConfigurationManager configManager = new ConfigurationManager(); + String host = configManager.getSubdomainDotDefaultDomain(subdomain); + String subject = "New Space on " + host + ", provider " + storeId + ": " + spaceId; StringBuilder body = new StringBuilder(); diff --git a/workman/src/main/java/org/duracloud/mill/bit/BitIntegrityReportTaskProcessor.java b/workman/src/main/java/org/duracloud/mill/bit/BitIntegrityReportTaskProcessor.java index ac7e422a..d91ed9e0 100644 --- a/workman/src/main/java/org/duracloud/mill/bit/BitIntegrityReportTaskProcessor.java +++ b/workman/src/main/java/org/duracloud/mill/bit/BitIntegrityReportTaskProcessor.java @@ -27,6 +27,7 @@ import org.duracloud.mill.bitlog.BitLogItem; import org.duracloud.mill.bitlog.BitLogStore; import org.duracloud.mill.common.taskproducer.TaskProducerConfigurationManager; +import org.duracloud.mill.config.ConfigurationManager; import org.duracloud.mill.db.model.BitIntegrityReport; import org.duracloud.mill.notification.NotificationManager; import org.duracloud.mill.workman.TaskExecutionFailedException; @@ -184,7 +185,8 @@ private void notifyManagerOfBitIntegrityErrors(BitIntegrityReport report, String storeId = report.getStoreId(); String spaceId = report.getSpaceId(); - String host = account + ".duracloud.org"; + ConfigurationManager configManager = new ConfigurationManager(); + String host = configManager.getSubdomainDotDefaultDomain(account); String subject = "Bit Integrity Report #" + report.getId() + ": errors (count = " + errors.size() + ") detected on " + host + ", providerId=" + storeId + diff --git a/workman/src/test/java/org/duracloud/mill/audit/SpaceCreatedNotificationGeneratingProcessorTest.java b/workman/src/test/java/org/duracloud/mill/audit/SpaceCreatedNotificationGeneratingProcessorTest.java index 986a60a3..41f4742c 100644 --- a/workman/src/test/java/org/duracloud/mill/audit/SpaceCreatedNotificationGeneratingProcessorTest.java +++ b/workman/src/test/java/org/duracloud/mill/audit/SpaceCreatedNotificationGeneratingProcessorTest.java @@ -8,16 +8,20 @@ package org.duracloud.mill.audit; -import static org.easymock.EasyMock.isA; +import static org.easymock.EasyMock.anyString; +import static org.easymock.EasyMock.capture; import org.duracloud.audit.task.AuditTask; +import org.duracloud.mill.config.ConfigConstants; import org.duracloud.mill.notification.NotificationManager; import org.duracloud.mill.workman.TaskExecutionFailedException; +import org.easymock.Capture; import org.easymock.EasyMock; import org.easymock.EasyMockRunner; import org.easymock.EasyMockSupport; import org.easymock.Mock; import org.junit.After; +import org.junit.Assert; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; @@ -48,14 +52,33 @@ public void tearDown() throws Exception { } @Test - public void testSpaceCreate() throws TaskExecutionFailedException { + public void testSpaceCreateDefaultDomain() throws TaskExecutionFailedException { AuditTask task = AuditTestHelper.createTestAuditTask(); task.setAction(AuditTask.ActionType.CREATE_SPACE.name()); - notificationManager.sendEmail(isA(String.class), isA(String.class)); + Capture cap = EasyMock.newCapture(); + notificationManager.sendEmail(anyString(), capture(cap)); EasyMock.expectLastCall().once(); replayAll(); new SpaceCreatedNotifcationGeneratingProcessor(task, notificationManager).execute(); + + Assert.assertTrue(cap.getValue().contains(".duracloud.org")); + } + + @Test + public void testSpaceCreateDifferentDomain() throws TaskExecutionFailedException { + System.setProperty(ConfigConstants.DURACLOUD_SITE_DOMAIN, "other.domain"); + + AuditTask task = AuditTestHelper.createTestAuditTask(); + task.setAction(AuditTask.ActionType.CREATE_SPACE.name()); + + Capture cap = EasyMock.newCapture(); + notificationManager.sendEmail(anyString(), capture(cap)); + EasyMock.expectLastCall().once(); + replayAll(); + new SpaceCreatedNotifcationGeneratingProcessor(task, notificationManager).execute(); + + Assert.assertTrue(cap.getValue().contains(".other.domain")); } }