mirror of
https://github.com/opennetworkinglab/onos.git
synced 2025-10-16 09:51:38 +02:00
Adding ability to assign roles to elements as part of network config.
Change-Id: I1ecda58e35f0dd30054536024060c67e389d3d73
This commit is contained in:
parent
227943db23
commit
3516f0682b
@ -15,7 +15,11 @@
|
|||||||
*/
|
*/
|
||||||
package org.onosproject.net.config.basics;
|
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.Objects;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Basic configuration for network elements, e.g. devices, hosts. Such elements
|
* Basic configuration for network elements, e.g. devices, hosts. Such elements
|
||||||
@ -69,6 +73,11 @@ public abstract class BasicElementConfig<S> extends AllowedEntityConfig<S> {
|
|||||||
*/
|
*/
|
||||||
protected static final String OWNER = "owner";
|
protected static final String OWNER = "owner";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Key for roles.
|
||||||
|
*/
|
||||||
|
protected static final String ROLES = "roles";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Threshold for detecting double value is zero.
|
* Threshold for detecting double value is zero.
|
||||||
*/
|
*/
|
||||||
@ -288,6 +297,30 @@ public abstract class BasicElementConfig<S> extends AllowedEntityConfig<S> {
|
|||||||
return (BasicElementConfig) setOrClear(OWNER, owner);
|
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
|
@Override
|
||||||
public boolean isValid() {
|
public boolean isValid() {
|
||||||
return isValidLength(NAME, NAME_MAX_LENGTH)
|
return isValidLength(NAME, NAME_MAX_LENGTH)
|
||||||
|
@ -17,12 +17,11 @@
|
|||||||
package org.onosproject.net.config.basics;
|
package org.onosproject.net.config.basics;
|
||||||
|
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
import com.google.common.collect.ImmutableSet;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.*;
|
||||||
import static org.junit.Assert.assertFalse;
|
|
||||||
import static org.junit.Assert.assertTrue;
|
|
||||||
import static org.onosproject.net.config.basics.BasicElementConfig.ZERO_THRESHOLD;
|
import static org.onosproject.net.config.basics.BasicElementConfig.ZERO_THRESHOLD;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -35,10 +34,12 @@ public class BasicElementConfigTest {
|
|||||||
private static final String E1 = "e1";
|
private static final String E1 = "e1";
|
||||||
private static final String GEO = "geo";
|
private static final String GEO = "geo";
|
||||||
private static final String GRID = "grid";
|
private static final String GRID = "grid";
|
||||||
|
public static final ImmutableSet<String> ROLES = ImmutableSet.of("spine", "primary");
|
||||||
|
|
||||||
// concrete subclass of abstract class we are testing
|
// concrete subclass of abstract class we are testing
|
||||||
private static class ElmCfg extends BasicElementConfig<String> {
|
private static class ElmCfg extends BasicElementConfig<String> {
|
||||||
ElmCfg() {
|
ElmCfg() {
|
||||||
|
mapper = MAPPER;
|
||||||
object = MAPPER.createObjectNode();
|
object = MAPPER.createObjectNode();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -150,4 +151,11 @@ public class BasicElementConfigTest {
|
|||||||
print(cfg);
|
print(cfg);
|
||||||
assertEquals("not geo", GEO, cfg.locType());
|
assertEquals("not geo", GEO, cfg.locType());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void roles() {
|
||||||
|
cfg.roles(ROLES);
|
||||||
|
print(cfg);
|
||||||
|
assertEquals("not roles", ROLES, cfg.roles());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user