summaryrefslogtreecommitdiffstats
path: root/config-model-api/src/main/java/com/yahoo/config/application/api/DeploymentSpec.java
diff options
context:
space:
mode:
Diffstat (limited to 'config-model-api/src/main/java/com/yahoo/config/application/api/DeploymentSpec.java')
-rw-r--r--config-model-api/src/main/java/com/yahoo/config/application/api/DeploymentSpec.java95
1 files changed, 82 insertions, 13 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 + "'.");
+ }
+ }
+
}
}