summaryrefslogtreecommitdiffstats
path: root/config-model-api
diff options
context:
space:
mode:
authorJon Marius Venstad <jvenstad@yahoo-inc.com>2019-01-02 15:10:38 +0100
committerJon Marius Venstad <jvenstad@yahoo-inc.com>2019-01-02 15:10:38 +0100
commitf55a08234122589f7ef0ea959c0c2411d74532c3 (patch)
tree90e94023112c2351a121bcd39e12bee279b3b6f9 /config-model-api
parent8b09e94ba9d7c1563f9f5d44f42e3b8a124f0af4 (diff)
Read notifications from deployment spec XML
Diffstat (limited to 'config-model-api')
-rw-r--r--config-model-api/src/main/java/com/yahoo/config/application/api/DeploymentSpec.java46
-rw-r--r--config-model-api/src/main/java/com/yahoo/config/application/api/xml/DeploymentSpecXmlReader.java15
-rw-r--r--config-model-api/src/test/java/com/yahoo/config/application/api/DeploymentSpecTest.java31
3 files changed, 89 insertions, 3 deletions
diff --git a/config-model-api/src/main/java/com/yahoo/config/application/api/DeploymentSpec.java b/config-model-api/src/main/java/com/yahoo/config/application/api/DeploymentSpec.java
index 349faf90cb0..8d0a68b47f5 100644
--- a/config-model-api/src/main/java/com/yahoo/config/application/api/DeploymentSpec.java
+++ b/config-model-api/src/main/java/com/yahoo/config/application/api/DeploymentSpec.java
@@ -44,7 +44,8 @@ public class DeploymentSpec {
Collections.emptyList(),
"<deployment version='1.0'/>",
Optional.empty(),
- Optional.empty());
+ Optional.empty(),
+ Notifications.none());
private final Optional<String> globalServiceId;
private final UpgradePolicy upgradePolicy;
@@ -54,10 +55,11 @@ public class DeploymentSpec {
private final String xmlForm;
private final Optional<AthenzDomain> athenzDomain;
private final Optional<AthenzService> athenzService;
+ private final Notifications notifications;
public DeploymentSpec(Optional<String> globalServiceId, UpgradePolicy upgradePolicy, Optional<Integer> majorVersion,
List<ChangeBlocker> changeBlockers, List<Step> steps, String xmlForm,
- Optional<AthenzDomain> athenzDomain, Optional<AthenzService> athenzService) {
+ Optional<AthenzDomain> athenzDomain, Optional<AthenzService> athenzService, Notifications notifications) {
validateTotalDelay(steps);
this.globalServiceId = globalServiceId;
this.upgradePolicy = upgradePolicy;
@@ -67,6 +69,7 @@ public class DeploymentSpec {
this.xmlForm = xmlForm;
this.athenzDomain = athenzDomain;
this.athenzService = athenzService;
+ this.notifications = notifications;
validateZones(this.steps);
validateAthenz();
}
@@ -192,6 +195,9 @@ public class DeploymentSpec {
.collect(Collectors.toList());
}
+ /** Returns the notification configuration */
+ public Notifications notifications() { return notifications; }
+
/** Returns the XML form of this spec, or null if it was not created by fromXml, nor is empty */
public String xmlForm() { return xmlForm; }
@@ -448,4 +454,40 @@ public class DeploymentSpec {
}
+
+ /**
+ * Configuration of notifications for deployment jobs.
+ *
+ * Supports a list of email recipients, and a flag for whether to send to the commit author.
+ */
+ public static class Notifications {
+
+ private static final Notifications none = of(Collections.emptyList(), false);
+ public static Notifications none() { return none; }
+
+ private final List<String> staticEmails;
+ private final boolean includeAuthor;
+
+ private Notifications(List<String> staticEmails, boolean includeAuthor) {
+ this.staticEmails = ImmutableList.copyOf(staticEmails);
+ this.includeAuthor = includeAuthor;
+ }
+
+ public static Notifications of(List<String> staticEmails, boolean includeAuthor) {
+ if (staticEmails.isEmpty() && ! includeAuthor)
+ return none;
+
+ return new Notifications(staticEmails, includeAuthor);
+ }
+
+ public List<String> staticEmails() {
+ return staticEmails;
+ }
+
+ public boolean includeAuthor() {
+ return includeAuthor;
+ }
+
+ }
+
}
diff --git a/config-model-api/src/main/java/com/yahoo/config/application/api/xml/DeploymentSpecXmlReader.java b/config-model-api/src/main/java/com/yahoo/config/application/api/xml/DeploymentSpecXmlReader.java
index 1900e2139cd..04f8594d18e 100644
--- a/config-model-api/src/main/java/com/yahoo/config/application/api/xml/DeploymentSpecXmlReader.java
+++ b/config-model-api/src/main/java/com/yahoo/config/application/api/xml/DeploymentSpecXmlReader.java
@@ -109,7 +109,20 @@ public class DeploymentSpecXmlReader {
steps,
xmlForm,
athenzDomain,
- athenzService);
+ athenzService,
+ readNotifications(root));
+ }
+
+ private DeploymentSpec.Notifications readNotifications(Element root) {
+ Element notificationsElement = XML.getChild(root, "notifications");
+ if (notificationsElement == null)
+ return DeploymentSpec.Notifications.none();
+
+ List<String> staticEmails = XML.getChildren(notificationsElement, "email").stream()
+ .map(XML::getValue)
+ .collect(Collectors.toList());
+ boolean includeAuthor = XML.getChild(notificationsElement, "author") != null;
+ return DeploymentSpec.Notifications.of(staticEmails, includeAuthor);
}
/** Imposes some constraints on tag order which are not expressible in the schema */
diff --git a/config-model-api/src/test/java/com/yahoo/config/application/api/DeploymentSpecTest.java b/config-model-api/src/test/java/com/yahoo/config/application/api/DeploymentSpecTest.java
index a0423293d1d..ae1d8bd6d9b 100644
--- a/config-model-api/src/test/java/com/yahoo/config/application/api/DeploymentSpecTest.java
+++ b/config-model-api/src/test/java/com/yahoo/config/application/api/DeploymentSpecTest.java
@@ -8,6 +8,7 @@ import org.junit.Test;
import java.io.StringReader;
import java.time.Instant;
import java.time.ZoneId;
+import java.util.Arrays;
import java.util.Optional;
import static org.junit.Assert.assertEquals;
@@ -434,4 +435,34 @@ public class DeploymentSpecTest {
);
DeploymentSpec spec = DeploymentSpec.fromXml(r);
}
+
+ @Test
+ public void noNotifications() {
+ assertEquals(DeploymentSpec.Notifications.none(),
+ DeploymentSpec.fromXml("<deployment />").notifications());
+ }
+
+ @Test
+ public void emptyNotifications() {
+ DeploymentSpec spec = DeploymentSpec.fromXml("<deployment>\n" +
+ " <notifications />" +
+ "</deployment>");
+ assertEquals(DeploymentSpec.Notifications.none(),
+ spec.notifications());
+ }
+
+ @Test
+ public void someNotifications() {
+ DeploymentSpec spec = DeploymentSpec.fromXml("<deployment>\n" +
+ " <notifications>\n" +
+ " <author />\n" +
+ " <email>john@dev</email>\n" +
+ " <email>jane@dev</email>\n" +
+ " </notifications>\n" +
+ "</deployment>");
+ assertTrue(spec.notifications().includeAuthor());
+ assertEquals(Arrays.asList("john@dev", "jane@dev"),
+ spec.notifications().staticEmails());
+ }
+
}