aboutsummaryrefslogtreecommitdiffstats
path: root/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/tenant
diff options
context:
space:
mode:
authorØyvind Grønnesby <oyving@verizonmedia.com>2022-03-04 12:52:05 +0100
committerLeandro Alves <leandroalves@yahooinc.com>2022-03-14 11:01:55 +0100
commitb2b0d390c21fd588909e38473fc260be97c8b8ef (patch)
tree6ff62100a8491d047697543804dfb049df0f6b8a /controller-api/src/main/java/com/yahoo/vespa/hosted/controller/tenant
parent3d71f172aca4d97acbe089384882f168dbc2db3e (diff)
Persist notification contacts
Diffstat (limited to 'controller-api/src/main/java/com/yahoo/vespa/hosted/controller/tenant')
-rw-r--r--controller-api/src/main/java/com/yahoo/vespa/hosted/controller/tenant/TenantContacts.java136
-rw-r--r--controller-api/src/main/java/com/yahoo/vespa/hosted/controller/tenant/TenantInfo.java28
-rw-r--r--controller-api/src/main/java/com/yahoo/vespa/hosted/controller/tenant/TenantInfoContacts.java28
3 files changed, 154 insertions, 38 deletions
diff --git a/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/tenant/TenantContacts.java b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/tenant/TenantContacts.java
new file mode 100644
index 00000000000..bb8ce709444
--- /dev/null
+++ b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/tenant/TenantContacts.java
@@ -0,0 +1,136 @@
+// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+package com.yahoo.vespa.hosted.controller.tenant;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+
+/**
+ * Tenant contacts are targets of the notification system. Sometimes they
+ * are a person with an email address, other times they are a Slack channel,
+ * IRC plugin, etc.
+ *
+ * @author ogronnesby
+ */
+public class TenantContacts {
+ private final Map<String, Contact<?>> contacts;
+
+ public TenantContacts() {
+ this.contacts = new LinkedHashMap<>();
+ }
+
+ public static TenantContacts empty() {
+ return new TenantContacts();
+ }
+
+ public static TenantContacts from(List<Contact<?>> contacts) {
+ var tc = new TenantContacts();
+ contacts.forEach(tc::add);
+ return tc;
+ }
+
+ public <T> void add(Contact<T> contact) {
+ contacts.put(contact.name(), contact);
+ }
+
+ public Optional<Contact<?>> get(String name) {
+ return Optional.ofNullable(contacts.get(name));
+ }
+
+ public List<Contact<?>> all() {
+ return new ArrayList<>(contacts.values());
+ }
+
+ public boolean isEmpty() {
+ return contacts.isEmpty();
+ }
+
+ public static class Contact<T> {
+ private final String name;
+ private final Type type;
+ private final Audience audience;
+ protected final T data;
+
+ public Contact(String name, Type type, Audience audience, T data) {
+ this.name = name;
+ this.type = type;
+ this.audience = audience;
+ this.data = data;
+ }
+
+ public String name() { return name; }
+ public Type type() { return type; }
+ public Audience audience() { return audience; }
+ public T data() { return data; }
+
+ @Override
+ public String toString() {
+ return "Contact{" +
+ "name='" + name + '\'' +
+ ", type=" + type +
+ ", audience=" + audience +
+ ", data=" + data +
+ '}';
+ }
+ }
+
+ public static class EmailContact {
+ private final String email;
+
+ public EmailContact(String email) {
+ this.email = email;
+ }
+
+ public String email() { return email; }
+
+ @Override
+ public String toString() {
+ return "EmailContact{" +
+ "email='" + email + '\'' +
+ '}';
+ }
+ }
+
+ public enum Type {
+ EMAIL("email");
+
+ private final String value;
+
+ Type(String value) {
+ this.value = value;
+ }
+
+ public String value() {
+ return this.value;
+ }
+
+ public static Optional<Type> from(String value) {
+ return Arrays.stream(Type.values()).filter(x -> x.value().equals(value)).findAny();
+ }
+ }
+
+ public enum Audience {
+ // tenant admin type updates about billing etc.
+ TENANT("tenant"),
+
+ // system notifications like deployment failures etc.
+ NOTIFICATIONS("notifications");
+
+ private final String value;
+
+ Audience(String value) {
+ this.value = value;
+ }
+
+ public String value() {
+ return value;
+ }
+
+ public static Optional<Audience> from(String value) {
+ return Arrays.stream(Audience.values()).filter((x -> x.value().equals(value))).findAny();
+ }
+ }
+}
diff --git a/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/tenant/TenantInfo.java b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/tenant/TenantInfo.java
index f658ec4ece9..484035fa759 100644
--- a/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/tenant/TenantInfo.java
+++ b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/tenant/TenantInfo.java
@@ -21,23 +21,25 @@ public class TenantInfo {
private final TenantContact contact;
private final TenantAddress address;
private final TenantBilling billingContact;
+ private final TenantContacts contacts;
TenantInfo(String name, String email, String website, String contactName, String contactEmail,
- TenantAddress address, TenantBilling billingContact) {
- this(name, email, website, TenantContact.from(contactName, contactEmail), address, billingContact);
+ TenantAddress address, TenantBilling billingContact, TenantContacts contacts) {
+ this(name, email, website, TenantContact.from(contactName, contactEmail), address, billingContact, contacts);
}
- TenantInfo(String name, String email, String website, TenantContact contact, TenantAddress address, TenantBilling billing) {
+ TenantInfo(String name, String email, String website, TenantContact contact, TenantAddress address, TenantBilling billing, TenantContacts contacts) {
this.name = Objects.requireNonNull(name);
this.email = Objects.requireNonNull(email);
this.website = Objects.requireNonNull(website);
this.contact = Objects.requireNonNull(contact);
this.address = Objects.requireNonNull(address);
this.billingContact = Objects.requireNonNull(billing);
+ this.contacts = Objects.requireNonNull(contacts);
}
public static TenantInfo empty() {
- return new TenantInfo("", "", "", "", "", TenantAddress.empty(), TenantBilling.empty());
+ return new TenantInfo("", "", "", "", "", TenantAddress.empty(), TenantBilling.empty(), TenantContacts.empty());
}
public String name() {
@@ -60,32 +62,38 @@ public class TenantInfo {
return billingContact;
}
+ public TenantContacts contacts() { return contacts; }
+
public boolean isEmpty() {
return this.equals(empty());
}
public TenantInfo withName(String name) {
- return new TenantInfo(name, email, website, contact, address, billingContact);
+ return new TenantInfo(name, email, website, contact, address, billingContact, contacts);
}
public TenantInfo withEmail(String email) {
- return new TenantInfo(name, email, website, contact, address, billingContact);
+ return new TenantInfo(name, email, website, contact, address, billingContact, contacts);
}
public TenantInfo withWebsite(String website) {
- return new TenantInfo(name, email, website, contact, address, billingContact);
+ return new TenantInfo(name, email, website, contact, address, billingContact, contacts);
}
public TenantInfo withContact(TenantContact contact) {
- return new TenantInfo(name, email, website, contact, address, billingContact);
+ return new TenantInfo(name, email, website, contact, address, billingContact, contacts);
}
public TenantInfo withAddress(TenantAddress address) {
- return new TenantInfo(name, email, website, contact, address, billingContact);
+ return new TenantInfo(name, email, website, contact, address, billingContact, contacts);
}
public TenantInfo withBilling(TenantBilling billingContact) {
- return new TenantInfo(name, email, website, contact, address, billingContact);
+ return new TenantInfo(name, email, website, contact, address, billingContact, contacts);
+ }
+
+ public TenantInfo withContacts(TenantContacts contacts) {
+ return new TenantInfo(name, email, website, contact, address, billingContact, contacts);
}
@Override
diff --git a/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/tenant/TenantInfoContacts.java b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/tenant/TenantInfoContacts.java
deleted file mode 100644
index dddbcdd1d91..00000000000
--- a/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/tenant/TenantInfoContacts.java
+++ /dev/null
@@ -1,28 +0,0 @@
-// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
-package com.yahoo.vespa.hosted.controller.tenant;
-
-import java.util.EnumMap;
-
-/**
- * @author ogronnesby
- */
-public class TenantInfoContacts {
- private final EnumMap<ContactType, TenantContact> contacts;
-
- TenantInfoContacts() {
- this.contacts = new EnumMap<>(ContactType.class);
- }
-
- public enum ContactType {
- DEFAULT("default"),
- PRODUCT("product");
-
- private final String value;
-
- ContactType(String value) {
- this.value = value;
- }
-
- public String value() { return value; }
- }
-}