aboutsummaryrefslogtreecommitdiffstats
path: root/config-model-api/src/main/java
diff options
context:
space:
mode:
Diffstat (limited to 'config-model-api/src/main/java')
-rw-r--r--config-model-api/src/main/java/com/yahoo/config/application/api/DeploymentSpec.java95
-rw-r--r--config-model-api/src/main/java/com/yahoo/config/application/api/xml/DeploymentSpecXmlReader.java21
2 files changed, 98 insertions, 18 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 7f63abe72c3..bdc9e41c85d 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
@@ -2,6 +2,7 @@
package com.yahoo.config.application.api;
import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableMap;
import com.yahoo.config.application.api.xml.DeploymentSpecXmlReader;
import com.yahoo.config.provision.AthenzDomain;
import com.yahoo.config.provision.AthenzService;
@@ -17,6 +18,7 @@ import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
+import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.Set;
@@ -458,34 +460,101 @@ 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.
+ * Supports a list of email addresses, and a list of roles for which email addresses are known.
+ * The currently supported roles are:
+ * <ul>
+ * <li><strong>author</strong>: the author of the git commit of a given application package. </li>
+ * </ul>
*/
public static class Notifications {
- private static final Notifications none = new Notifications(Collections.emptyList(), false);
+ private static final Notifications none = new Notifications(Collections.emptyMap(), Collections.emptyMap());
public static Notifications none() { return none; }
- private final List<String> staticEmails;
- private final boolean includeAuthor;
+ private final Map<String, When> staticEmails;
+ private final Map<Role, When> roleEmails;
- private Notifications(List<String> staticEmails, boolean includeAuthor) {
- this.staticEmails = ImmutableList.copyOf(staticEmails);
- this.includeAuthor = includeAuthor;
+ private Notifications(Map<String, When> staticEmails, Map<Role, When> roleEmails) {
+ this.staticEmails = ImmutableMap.copyOf(staticEmails);
+ this.roleEmails = ImmutableMap.copyOf(roleEmails);
}
- public static Notifications of(List<String> staticEmails, boolean includeAuthor) {
- if (staticEmails.isEmpty() && ! includeAuthor)
+ /**
+ * Returns a new Notifications as specified by the given String input.
+ *
+ * @param when Optional string name of the default condition for sending notifications; defaults to failingCommit.
+ * @param staticEmails Map from email addresses to optional overrides for when to send to these.
+ * @param roleEmails Map from email roles to optional overrides for when to send to these.
+ * @return The Notifications as specified.
+ */
+ public static Notifications of(Optional<String> when, Map<String, Optional<String>> staticEmails, Map<String, Optional<String>> roleEmails) {
+ if (staticEmails.isEmpty() && roleEmails.isEmpty())
return none;
- return new Notifications(staticEmails, includeAuthor);
+ When defaultWhen = when.map(When::fromValue).orElse(When.failingCommit);
+ return new Notifications(staticEmails.entrySet().stream()
+ .collect(Collectors.toMap(entry -> entry.getKey(),
+ entry -> entry.getValue().map(When::fromValue).orElse(defaultWhen))),
+ roleEmails.entrySet().stream()
+ .collect(Collectors.toMap(entry -> Role.fromValue(entry.getKey()),
+ entry -> entry.getValue().map(When::fromValue).orElse(defaultWhen))));
}
- public List<String> staticEmails() {
+ public Map<String, When> staticEmails() {
return staticEmails;
}
- public boolean includeAuthor() {
- return includeAuthor;
+ public Map<Role, When> roleEmails() {
+ return roleEmails;
+ }
+
+
+ public enum Role {
+
+ /** Author of the last commit of an application package. */
+ author;
+
+ public static String toValue(Role role) {
+ switch (role) {
+ case author: return "author";
+ default: throw new IllegalArgumentException("Unexpected constant '" + role.name() + "'.");
+ }
+ }
+
+ public static Role fromValue(String value) {
+ switch (value) {
+ case "author": return author;
+ default: throw new IllegalArgumentException("Unknown value '" + value + "'.");
+ }
+ }
+
+ }
+
+
+ public enum When {
+
+ /** Send notifications whenever a job fails. */
+ failing,
+
+ /** Send notifications whenever a job fails while deploying a new commit. */
+ failingCommit;
+
+ public static String toValue(When when) {
+ switch (when) {
+ case failing: return "failing";
+ case failingCommit: return "failing-commit";
+ default: throw new IllegalArgumentException("Unexpected constant '" + when.name() + "'.");
+ }
+ }
+
+ public static When fromValue(String value) {
+ switch (value) {
+ case "failing": return failing;
+ case "failing-commit": return failingCommit;
+ default: throw new IllegalArgumentException("Unknown value '" + value + "'.");
+ }
+ }
+
}
}
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 04f8594d18e..8ee1d05df21 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
@@ -21,7 +21,9 @@ import java.time.Duration;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
+import java.util.HashMap;
import java.util.List;
+import java.util.Map;
import java.util.Optional;
import java.util.stream.Collectors;
@@ -118,11 +120,20 @@ public class DeploymentSpecXmlReader {
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);
+ Optional<String> when = stringAttribute("when", notificationsElement);
+ Map<String, Optional<String>> staticEmails = new HashMap<>();
+ Map<String, Optional<String>> roleEmails = new HashMap<>();
+
+ for (Element emailElement : XML.getChildren(notificationsElement, "email")) {
+ Optional<String> addressAttribute = stringAttribute("address", emailElement);
+ Optional<String> roleAttribute = stringAttribute("role", emailElement);
+ if (addressAttribute.isPresent() == roleAttribute.isPresent())
+ throw new IllegalArgumentException("Exactly one of 'role' and 'address' must be present in 'email' elements.");
+
+ addressAttribute.ifPresent(address -> staticEmails.put(address, stringAttribute("when", emailElement)));
+ roleAttribute.ifPresent(role -> roleEmails.put(role, stringAttribute("when", emailElement)));
+ }
+ return DeploymentSpec.Notifications.of(when, staticEmails, roleEmails);
}
/** Imposes some constraints on tag order which are not expressible in the schema */