Adding ability to assign roles to elements as part of network config.
Change-Id: I1ecda58e35f0dd30054536024060c67e389d3d73
diff --git a/core/api/src/main/java/org/onosproject/net/config/basics/BasicElementConfig.java b/core/api/src/main/java/org/onosproject/net/config/basics/BasicElementConfig.java
index dceed74..1cb00dc 100644
--- a/core/api/src/main/java/org/onosproject/net/config/basics/BasicElementConfig.java
+++ b/core/api/src/main/java/org/onosproject/net/config/basics/BasicElementConfig.java
@@ -15,7 +15,11 @@
*/
package org.onosproject.net.config.basics;
+import com.fasterxml.jackson.databind.node.ArrayNode;
+import com.google.common.collect.ImmutableSet;
+
import java.util.Objects;
+import java.util.Set;
/**
* Basic configuration for network elements, e.g. devices, hosts. Such elements
@@ -70,6 +74,11 @@
protected static final String OWNER = "owner";
/**
+ * Key for roles.
+ */
+ protected static final String ROLES = "roles";
+
+ /**
* Threshold for detecting double value is zero.
*/
protected static final double ZERO_THRESHOLD = Double.MIN_VALUE * 2.0;
@@ -288,6 +297,30 @@
return (BasicElementConfig) setOrClear(OWNER, owner);
}
+ /**
+ * Returns set of roles assigned to the element.
+ *
+ * @return set of roles
+ */
+ public Set<String> roles() {
+ ImmutableSet.Builder<String> roles = ImmutableSet.builder();
+ if (object.has(ROLES)) {
+ ArrayNode roleNodes = (ArrayNode) object.path(ROLES);
+ roleNodes.forEach(r -> roles.add(r.asText()));
+ }
+ return roles.build();
+ }
+
+ /**
+ * Sets the roles of the element.
+ *
+ * @param roles new roles; null to clear
+ * @return self
+ */
+ public BasicElementConfig roles(Set<String> roles) {
+ return (BasicElementConfig) setOrClear(ROLES, roles);
+ }
+
@Override
public boolean isValid() {
return isValidLength(NAME, NAME_MAX_LENGTH)