Skip to content

Commit

Permalink
Make domain in notifications configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
fozboz authored Aug 25, 2021
1 parent a9d769c commit 5acd758
Show file tree
Hide file tree
Showing 9 changed files with 66 additions and 7 deletions.
6 changes: 6 additions & 0 deletions common-dup/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@

<dependencies>

<dependency>
<groupId>org.duracloud.mill</groupId>
<artifactId>common</artifactId>
<version>${project.version}</version>
</dependency>

<dependency>
<groupId>org.duracloud</groupId>
<artifactId>common</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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";

Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
6 changes: 6 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -823,6 +823,12 @@
<version>${hibernate.version}</version>
</dependency>

<dependency>
<groupId>org.javassist</groupId>
<artifactId>javassist</artifactId>
<version>3.24.0-GA</version>
</dependency>

<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<String> 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<String> cap = EasyMock.newCapture();
notificationManager.sendEmail(anyString(), capture(cap));
EasyMock.expectLastCall().once();
replayAll();
new SpaceCreatedNotifcationGeneratingProcessor(task, notificationManager).execute();

Assert.assertTrue(cap.getValue().contains(".other.domain"));
}

}

0 comments on commit 5acd758

Please sign in to comment.