summaryrefslogtreecommitdiffstats
path: root/config-model-api
diff options
context:
space:
mode:
authorJon Marius Venstad <venstad@gmail.com>2019-01-03 18:56:22 +0100
committerJon Marius Venstad <venstad@gmail.com>2019-01-03 18:56:22 +0100
commit1290f4f61d3d7eca42be17aa1c16805cfca62a13 (patch)
tree4746e2d2d0cc94fe6d4f6f2f43bea0a8c08d67a8 /config-model-api
parentcea4ddb1d2d8b3ae8a51b99fb92fa73cd1964807 (diff)
Move Notifications to upper level
Diffstat (limited to 'config-model-api')
-rw-r--r--config-model-api/src/main/java/com/yahoo/config/application/api/DeploymentSpec.java104
-rw-r--r--config-model-api/src/main/java/com/yahoo/config/application/api/Notifications.java112
-rw-r--r--config-model-api/src/main/java/com/yahoo/config/application/api/xml/DeploymentSpecXmlReader.java7
-rw-r--r--config-model-api/src/test/java/com/yahoo/config/application/api/DeploymentSpecTest.java11
4 files changed, 121 insertions, 113 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 bdc9e41c85d..a6cecefe940 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,7 +2,6 @@
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;
@@ -18,7 +17,6 @@ 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;
@@ -457,106 +455,4 @@ public class DeploymentSpec {
}
- /**
- * Configuration of notifications for deployment jobs.
- *
- * 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.emptyMap(), Collections.emptyMap());
- public static Notifications none() { return none; }
-
- private final Map<String, When> staticEmails;
- private final Map<Role, When> roleEmails;
-
- private Notifications(Map<String, When> staticEmails, Map<Role, When> roleEmails) {
- this.staticEmails = ImmutableMap.copyOf(staticEmails);
- this.roleEmails = ImmutableMap.copyOf(roleEmails);
- }
-
- /**
- * 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;
-
- 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 Map<String, When> staticEmails() {
- return staticEmails;
- }
-
- 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/Notifications.java b/config-model-api/src/main/java/com/yahoo/config/application/api/Notifications.java
new file mode 100644
index 00000000000..0375d99550a
--- /dev/null
+++ b/config-model-api/src/main/java/com/yahoo/config/application/api/Notifications.java
@@ -0,0 +1,112 @@
+package com.yahoo.config.application.api;
+
+import com.google.common.collect.ImmutableMap;
+
+import java.util.Collections;
+import java.util.Map;
+import java.util.Optional;
+import java.util.stream.Collectors;
+
+/**
+ * Configuration of notifications for deployment jobs.
+ *
+ * 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>
+ *
+ * @author jonmv
+ */
+public class Notifications {
+
+ private static final Notifications none = new Notifications(Collections.emptyMap(), Collections.emptyMap());
+ public static Notifications none() { return none; }
+
+ private final Map<String, When> staticEmails;
+ private final Map<Role, When> roleEmails;
+
+ private Notifications(Map<String, When> staticEmails, Map<Role, When> roleEmails) {
+ this.staticEmails = ImmutableMap.copyOf(staticEmails);
+ this.roleEmails = ImmutableMap.copyOf(roleEmails);
+ }
+
+ /**
+ * 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;
+
+ 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 Map<String, When> staticEmails() {
+ return staticEmails;
+ }
+
+ 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 8ee1d05df21..140e4dafe32 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
@@ -6,6 +6,7 @@ import com.yahoo.config.application.api.DeploymentSpec.DeclaredZone;
import com.yahoo.config.application.api.DeploymentSpec.Delay;
import com.yahoo.config.application.api.DeploymentSpec.ParallelZones;
import com.yahoo.config.application.api.DeploymentSpec.Step;
+import com.yahoo.config.application.api.Notifications;
import com.yahoo.config.application.api.TimeWindow;
import com.yahoo.config.provision.AthenzDomain;
import com.yahoo.config.provision.AthenzService;
@@ -115,10 +116,10 @@ public class DeploymentSpecXmlReader {
readNotifications(root));
}
- private DeploymentSpec.Notifications readNotifications(Element root) {
+ private Notifications readNotifications(Element root) {
Element notificationsElement = XML.getChild(root, "notifications");
if (notificationsElement == null)
- return DeploymentSpec.Notifications.none();
+ return Notifications.none();
Optional<String> when = stringAttribute("when", notificationsElement);
Map<String, Optional<String>> staticEmails = new HashMap<>();
@@ -133,7 +134,7 @@ public class DeploymentSpecXmlReader {
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);
+ return Notifications.of(when, staticEmails, roleEmails);
}
/** 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 e29ce7f6c39..b2ecf5368e9 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
@@ -9,12 +9,11 @@ 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 com.yahoo.config.application.api.DeploymentSpec.Notifications.Role.author;
-import static com.yahoo.config.application.api.DeploymentSpec.Notifications.When.failing;
-import static com.yahoo.config.application.api.DeploymentSpec.Notifications.When.failingCommit;
+import static com.yahoo.config.application.api.Notifications.Role.author;
+import static com.yahoo.config.application.api.Notifications.When.failing;
+import static com.yahoo.config.application.api.Notifications.When.failingCommit;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
@@ -442,7 +441,7 @@ public class DeploymentSpecTest {
@Test
public void noNotifications() {
- assertEquals(DeploymentSpec.Notifications.none(),
+ assertEquals(Notifications.none(),
DeploymentSpec.fromXml("<deployment />").notifications());
}
@@ -451,7 +450,7 @@ public class DeploymentSpecTest {
DeploymentSpec spec = DeploymentSpec.fromXml("<deployment>\n" +
" <notifications />" +
"</deployment>");
- assertEquals(DeploymentSpec.Notifications.none(),
+ assertEquals(Notifications.none(),
spec.notifications());
}