Working on Bay-Area-Region Demo.
- added latitude / longitude parameters to regions, so the icons can be "placed" on a GEO-map
Change-Id: I5cf939f22597d4658ab603459b2b3059ba0db0c9
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 7c2a5b8..295995f 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
@@ -22,20 +22,46 @@
*/
public abstract class BasicElementConfig<S> extends AllowedEntityConfig<S> {
- protected static final String NAME = "name";
- protected static final String UI_TYPE = "uiType";
+ /**
+ * Key for friendly name.
+ */
+ public static final String NAME = "name";
- protected static final String LATITUDE = "latitude";
- protected static final String LONGITUDE = "longitude";
+ /**
+ * Key for UI type (glyph identifier).
+ */
+ public static final String UI_TYPE = "uiType";
+ /**
+ * Key for latitude.
+ */
+ public static final String LATITUDE = "latitude";
+
+ /**
+ * Key for longitude.
+ */
+ public static final String LONGITUDE = "longitude";
+
+ /**
+ * Key for rack address.
+ */
protected static final String RACK_ADDRESS = "rackAddress";
+
+ /**
+ * Key for owner.
+ */
protected static final String OWNER = "owner";
+ /**
+ * Threshold for detecting double value is zero.
+ */
protected static final double ZERO_THRESHOLD = Double.MIN_VALUE * 2.0;
+
private static final double DEFAULT_COORD = 0.0;
/**
- * Returns friendly label for the element.
+ * Returns friendly label for the element. If not set, returns the
+ * element identifier.
*
* @return friendly label or element identifier itself if not set
*/
@@ -55,7 +81,7 @@
/**
* Returns the UI type (glyph image to be used) for the element in
- * the Topology View.
+ * the Topology View. If not set, null is returned.
*
* @return the UI type
*/
@@ -65,7 +91,8 @@
/**
* Sets the UI type (glyph image to be used) for the element in
- * the Topology View.
+ * the Topology View. Setting this to null will indicate that the
+ * default glyph image should be used for the element type.
*
* @param uiType the UI type; null for default
* @return self
diff --git a/core/api/src/main/java/org/onosproject/net/config/basics/BasicRegionConfig.java b/core/api/src/main/java/org/onosproject/net/config/basics/BasicRegionConfig.java
index 2d15fa5..e27157e 100644
--- a/core/api/src/main/java/org/onosproject/net/config/basics/BasicRegionConfig.java
+++ b/core/api/src/main/java/org/onosproject/net/config/basics/BasicRegionConfig.java
@@ -18,7 +18,6 @@
import com.google.common.base.MoreObjects;
import org.onosproject.net.DeviceId;
-import org.onosproject.net.config.Config;
import org.onosproject.net.region.Region;
import org.onosproject.net.region.RegionId;
@@ -28,46 +27,30 @@
/**
* Basic configuration for network regions.
*/
-public final class BasicRegionConfig extends Config<RegionId> {
+public final class BasicRegionConfig extends BasicElementConfig<RegionId> {
- private static final String NAME = "name";
private static final String TYPE = "type";
private static final String DEVICES = "devices";
@Override
public boolean isValid() {
- return hasOnlyFields(NAME, TYPE, DEVICES);
+ return hasOnlyFields(ALLOWED, NAME, LATITUDE, LONGITUDE, UI_TYPE,
+ RACK_ADDRESS, OWNER, TYPE, DEVICES);
}
@Override
public String toString() {
return MoreObjects.toStringHelper(this)
- .add("name", name())
- .add("type", type())
- .add("devices", devices())
+ .add(NAME, name())
+ .add(TYPE, type())
+ .add(UI_TYPE, uiType())
+ .add(LATITUDE, latitude())
+ .add(LONGITUDE, longitude())
+ .add(DEVICES, devices())
.toString();
}
/**
- * Returns the region name.
- *
- * @return the region name
- */
- public String name() {
- return get(NAME, null);
- }
-
- /**
- * Sets the name of this region.
- *
- * @param name name of region, or null to unset
- * @return the config of the region
- */
- public BasicRegionConfig name(String name) {
- return (BasicRegionConfig) setOrClear(NAME, name);
- }
-
- /**
* Returns the region type.
*
* @return the region type
diff --git a/core/api/src/main/java/org/onosproject/net/region/DefaultRegion.java b/core/api/src/main/java/org/onosproject/net/region/DefaultRegion.java
index 1926a3d..d229e92 100644
--- a/core/api/src/main/java/org/onosproject/net/region/DefaultRegion.java
+++ b/core/api/src/main/java/org/onosproject/net/region/DefaultRegion.java
@@ -19,6 +19,8 @@
import com.google.common.base.MoreObjects;
import com.google.common.collect.ImmutableList;
import org.onosproject.cluster.NodeId;
+import org.onosproject.net.AbstractAnnotated;
+import org.onosproject.net.Annotations;
import java.util.List;
import java.util.Objects;
@@ -27,7 +29,7 @@
/**
* Default implementation of a region.
*/
-public final class DefaultRegion implements Region {
+public final class DefaultRegion extends AbstractAnnotated implements Region {
private final RegionId id;
private final String name;
@@ -40,9 +42,12 @@
* @param id region identifier
* @param name friendly name
* @param type region type
+ * @param annots annotations
* @param masters list of sets of cluster node identifiers; in order of mastership
*/
- public DefaultRegion(RegionId id, String name, Type type, List<Set<NodeId>> masters) {
+ public DefaultRegion(RegionId id, String name, Type type,
+ Annotations annots, List<Set<NodeId>> masters) {
+ super(annots);
this.id = id;
this.name = name;
this.type = type;
diff --git a/core/api/src/main/java/org/onosproject/net/region/Region.java b/core/api/src/main/java/org/onosproject/net/region/Region.java
index afe1805..ed8fff18 100644
--- a/core/api/src/main/java/org/onosproject/net/region/Region.java
+++ b/core/api/src/main/java/org/onosproject/net/region/Region.java
@@ -17,6 +17,7 @@
package org.onosproject.net.region;
import org.onosproject.cluster.NodeId;
+import org.onosproject.net.Annotated;
import java.util.List;
import java.util.Set;
@@ -26,7 +27,7 @@
* logical region. Optionally, devices in the region can share the same
* cluster nodes mastership affinities.
*/
-public interface Region {
+public interface Region extends Annotated {
/**
* Coarse representation of the type of the region.
@@ -58,6 +59,11 @@
BUILDING,
/**
+ * Region represents a data center.
+ */
+ DATA_CENTER,
+
+ /**
* Region represents a building floor.
*/
FLOOR,
diff --git a/core/api/src/main/java/org/onosproject/net/region/RegionStore.java b/core/api/src/main/java/org/onosproject/net/region/RegionStore.java
index 49cc378..b8527c7 100644
--- a/core/api/src/main/java/org/onosproject/net/region/RegionStore.java
+++ b/core/api/src/main/java/org/onosproject/net/region/RegionStore.java
@@ -16,6 +16,7 @@
package org.onosproject.net.region;
import org.onosproject.cluster.NodeId;
+import org.onosproject.net.Annotations;
import org.onosproject.net.DeviceId;
import org.onosproject.store.Store;
@@ -67,12 +68,13 @@
* @param regionId region identifier
* @param name friendly name
* @param type region type
+ * @param annots annotations
* @param masterNodeIds list of master nodes; null implies empty list
* @return new region descriptor
* @throws IllegalArgumentException if item already exists
*/
Region createRegion(RegionId regionId, String name, Region.Type type,
- List<Set<NodeId>> masterNodeIds);
+ Annotations annots, List<Set<NodeId>> masterNodeIds);
/**
* Updates the specified new region using the supplied data.
@@ -80,12 +82,13 @@
* @param regionId region identifier
* @param name friendly name
* @param type region type
+ * @param annots annotations
* @param masterNodeIds list of master nodes; null implies empty list
* @return new region descriptor
* @throws IllegalArgumentException if item already exists
*/
Region updateRegion(RegionId regionId, String name, Region.Type type,
- List<Set<NodeId>> masterNodeIds);
+ Annotations annots, List<Set<NodeId>> masterNodeIds);
/**
* Removes the specified region using the new set of data.
diff --git a/core/api/src/test/java/org/onosproject/net/config/basics/BasicRegionConfigTest.java b/core/api/src/test/java/org/onosproject/net/config/basics/BasicRegionConfigTest.java
index 51c5676..358c4e1 100644
--- a/core/api/src/test/java/org/onosproject/net/config/basics/BasicRegionConfigTest.java
+++ b/core/api/src/test/java/org/onosproject/net/config/basics/BasicRegionConfigTest.java
@@ -115,7 +115,7 @@
@Test
public void region3Config() {
loadRegion(R3);
- checkRegion(null, null, R3_DEVS);
+ checkRegion(R3, null, R3_DEVS);
}
@Test
@@ -128,8 +128,10 @@
@Test
public void clearName() {
loadRegion(R1);
+ checkRegion(EUROPE, Region.Type.CONTINENT, R1_DEVS);
cfg.name(null);
- checkRegion(null, Region.Type.CONTINENT, R1_DEVS);
+ // if the friendly name is cleared, name() returns the identifier
+ checkRegion(R1, Region.Type.CONTINENT, R1_DEVS);
}
@Test
@@ -150,14 +152,14 @@
public void modifyDevices() {
loadRegion(R3);
cfg.devices(ALT_DEVICES);
- checkRegion(null, null, ALT_DEVICES);
+ checkRegion(R3, null, ALT_DEVICES);
}
@Test
public void clearDevices() {
loadRegion(R3);
cfg.devices(null);
- checkRegion(null, null, null);
+ checkRegion(R3, null, null);
}
diff --git a/core/api/src/test/java/org/onosproject/net/region/DefaultRegionTest.java b/core/api/src/test/java/org/onosproject/net/region/DefaultRegionTest.java
index 392c565..9e85f3f 100644
--- a/core/api/src/test/java/org/onosproject/net/region/DefaultRegionTest.java
+++ b/core/api/src/test/java/org/onosproject/net/region/DefaultRegionTest.java
@@ -21,6 +21,8 @@
import com.google.common.testing.EqualsTester;
import org.junit.Test;
import org.onosproject.cluster.NodeId;
+import org.onosproject.net.Annotations;
+import org.onosproject.net.DefaultAnnotations;
import java.util.Set;
@@ -34,13 +36,16 @@
public class DefaultRegionTest {
private static final RegionId ID1 = RegionId.regionId("r1");
+ private static final Annotations NO_ANNOTS = DefaultAnnotations.EMPTY;
@Test
public void basics() {
- ImmutableList<Set<NodeId>> masters = ImmutableList
- .of(ImmutableSet.of(nodeId("n1"), nodeId("n2")),
- ImmutableSet.of(nodeId("n3"), nodeId("n4")));
- Region r = new DefaultRegion(ID1, "R1", METRO, masters);
+ ImmutableList<Set<NodeId>> masters =
+ ImmutableList.of(
+ ImmutableSet.of(nodeId("n1"), nodeId("n2")),
+ ImmutableSet.of(nodeId("n3"), nodeId("n4"))
+ );
+ Region r = new DefaultRegion(ID1, "R1", METRO, NO_ANNOTS, masters);
assertEquals("incorrect id", ID1, r.id());
assertEquals("incorrect name", "R1", r.name());
assertEquals("incorrect type", METRO, r.type());
@@ -49,9 +54,9 @@
@Test
public void equality() {
- Region a = new DefaultRegion(ID1, "R1", METRO, null);
- Region b = new DefaultRegion(ID1, "R1", METRO, null);
- Region c = new DefaultRegion(ID1, "R2", METRO, null);
+ Region a = new DefaultRegion(ID1, "R1", METRO, NO_ANNOTS, null);
+ Region b = new DefaultRegion(ID1, "R1", METRO, NO_ANNOTS, null);
+ Region c = new DefaultRegion(ID1, "R2", METRO, NO_ANNOTS, null);
new EqualsTester().addEqualityGroup(a, b).addEqualityGroup(c).testEquals();
}
diff --git a/core/api/src/test/java/org/onosproject/ui/model/topo/UiTopoLayoutTest.java b/core/api/src/test/java/org/onosproject/ui/model/topo/UiTopoLayoutTest.java
index b8db969..1c840fa 100644
--- a/core/api/src/test/java/org/onosproject/ui/model/topo/UiTopoLayoutTest.java
+++ b/core/api/src/test/java/org/onosproject/ui/model/topo/UiTopoLayoutTest.java
@@ -17,6 +17,8 @@
package org.onosproject.ui.model.topo;
import org.junit.Test;
+import org.onosproject.net.Annotations;
+import org.onosproject.net.DefaultAnnotations;
import org.onosproject.net.region.DefaultRegion;
import org.onosproject.net.region.Region;
import org.onosproject.net.region.RegionId;
@@ -44,10 +46,11 @@
private static final double DELTA = Double.MIN_VALUE * 2.0;
+ private static final Annotations NO_ANNOTS = DefaultAnnotations.EMPTY;
private static final UiTopoLayoutId OTHER_ID = layoutId("other-id");
private static final RegionId REGION_ID = regionId("some-region");
private static final Region REGION =
- new DefaultRegion(REGION_ID, "Region-1", CAMPUS, null);
+ new DefaultRegion(REGION_ID, "Region-1", CAMPUS, NO_ANNOTS, null);
private static final String GEOMAP = "geo1";
private static final String SPRITE = "spr1";
diff --git a/core/common/src/main/java/org/onosproject/codec/impl/RegionCodec.java b/core/common/src/main/java/org/onosproject/codec/impl/RegionCodec.java
index 5f003e0..f3aa128 100644
--- a/core/common/src/main/java/org/onosproject/codec/impl/RegionCodec.java
+++ b/core/common/src/main/java/org/onosproject/codec/impl/RegionCodec.java
@@ -23,7 +23,7 @@
import com.google.common.collect.Sets;
import org.onosproject.cluster.NodeId;
import org.onosproject.codec.CodecContext;
-import org.onosproject.codec.JsonCodec;
+import org.onosproject.net.Annotations;
import org.onosproject.net.region.DefaultRegion;
import org.onosproject.net.region.Region;
import org.onosproject.net.region.RegionId;
@@ -39,7 +39,7 @@
/**
* Codec for the Region class.
*/
-public class RegionCodec extends JsonCodec<Region> {
+public class RegionCodec extends AnnotatedCodec<Region> {
// JSON field names
private static final String REGION_ID = "id";
@@ -77,7 +77,7 @@
masters.add(setsJson);
});
result.set(MASTERS, masters);
- return result;
+ return annotate(result, region, context);
}
@Override
@@ -108,8 +108,9 @@
RegionId regionId = RegionId.regionId(extractMember(REGION_ID, json));
String name = extractMember(NAME, json);
Region.Type type = REGION_TYPE_MAP.get(extractMember(TYPE, json));
+ Annotations annots = extractAnnotations(json, context);
- return new DefaultRegion(regionId, name, type, masters);
+ return new DefaultRegion(regionId, name, type, annots, masters);
}
private String extractMember(String key, ObjectNode json) {
diff --git a/core/common/src/test/java/org/onosproject/codec/impl/RegionCodecTest.java b/core/common/src/test/java/org/onosproject/codec/impl/RegionCodecTest.java
index 05d95e1..a9e7a2f 100644
--- a/core/common/src/test/java/org/onosproject/codec/impl/RegionCodecTest.java
+++ b/core/common/src/test/java/org/onosproject/codec/impl/RegionCodecTest.java
@@ -25,6 +25,8 @@
import org.onosproject.cluster.NodeId;
import org.onosproject.codec.JsonCodec;
import org.onosproject.core.CoreService;
+import org.onosproject.net.Annotations;
+import org.onosproject.net.DefaultAnnotations;
import org.onosproject.net.region.DefaultRegion;
import org.onosproject.net.region.Region;
import org.onosproject.net.region.RegionId;
@@ -75,8 +77,9 @@
RegionId regionId = RegionId.regionId("1");
String name = "foo";
Region.Type type = Region.Type.ROOM;
+ Annotations noAnnots = DefaultAnnotations.EMPTY;
- Region region = new DefaultRegion(regionId, name, type, masters);
+ Region region = new DefaultRegion(regionId, name, type, noAnnots, masters);
ObjectNode regionJson = regionCodec.encode(region, context);
assertThat(regionJson, matchesRegion(region));
diff --git a/core/net/src/main/java/org/onosproject/net/region/impl/RegionManager.java b/core/net/src/main/java/org/onosproject/net/region/impl/RegionManager.java
index c7b8342..bf82842 100644
--- a/core/net/src/main/java/org/onosproject/net/region/impl/RegionManager.java
+++ b/core/net/src/main/java/org/onosproject/net/region/impl/RegionManager.java
@@ -25,8 +25,13 @@
import org.apache.felix.scr.annotations.Service;
import org.onosproject.cluster.NodeId;
import org.onosproject.event.AbstractListenerManager;
+import org.onosproject.net.Annotations;
+import org.onosproject.net.DefaultAnnotations;
import org.onosproject.net.DeviceId;
import org.onosproject.net.HostId;
+import org.onosproject.net.config.NetworkConfigService;
+import org.onosproject.net.config.basics.BasicElementConfig;
+import org.onosproject.net.config.basics.BasicRegionConfig;
import org.onosproject.net.region.Region;
import org.onosproject.net.region.RegionAdminService;
import org.onosproject.net.region.RegionEvent;
@@ -44,9 +49,9 @@
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.base.Preconditions.checkState;
import static com.google.common.collect.ImmutableList.of;
-import static org.slf4j.LoggerFactory.getLogger;
import static org.onosproject.security.AppGuard.checkPermission;
import static org.onosproject.security.AppPermission.Type.REGION_READ;
+import static org.slf4j.LoggerFactory.getLogger;
/**
* Provides implementation of the region service APIs.
@@ -70,6 +75,9 @@
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
protected RegionStore store;
+ @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+ protected NetworkConfigService networkConfigService;
+
@Activate
public void activate() {
store.setDelegate(delegate);
@@ -84,13 +92,41 @@
log.info("Stopped");
}
+ private String dstr(double d) {
+ return Double.toString(d);
+ }
+
+ private Annotations genAnnots(RegionId id) {
+ BasicRegionConfig cfg =
+ networkConfigService.getConfig(id, BasicRegionConfig.class);
+
+ if (cfg == null) {
+ return DefaultAnnotations.builder().build();
+ }
+
+ DefaultAnnotations.Builder builder = DefaultAnnotations.builder()
+ .set(BasicElementConfig.NAME, cfg.name())
+ .set(BasicElementConfig.LATITUDE, dstr(cfg.latitude()))
+ .set(BasicElementConfig.LONGITUDE, dstr(cfg.longitude()));
+
+ // only set the UI_TYPE annotation if it is not null in the config
+ String uiType = cfg.uiType();
+ if (uiType != null) {
+ builder.set(BasicElementConfig.UI_TYPE, uiType);
+ }
+
+ return builder.build();
+ }
+
@Override
public Region createRegion(RegionId regionId, String name, Region.Type type,
List<Set<NodeId>> masterNodeIds) {
checkNotNull(regionId, REGION_ID_NULL);
checkNotNull(name, NAME_NULL);
checkNotNull(name, REGION_TYPE_NULL);
- return store.createRegion(regionId, name, type, masterNodeIds == null ? of() : masterNodeIds);
+
+ return store.createRegion(regionId, name, type, genAnnots(regionId),
+ masterNodeIds == null ? of() : masterNodeIds);
}
@Override
@@ -99,7 +135,9 @@
checkNotNull(regionId, REGION_ID_NULL);
checkNotNull(name, NAME_NULL);
checkNotNull(name, REGION_TYPE_NULL);
- return store.updateRegion(regionId, name, type, masterNodeIds == null ? of() : masterNodeIds);
+
+ return store.updateRegion(regionId, name, type, genAnnots(regionId),
+ masterNodeIds == null ? of() : masterNodeIds);
}
@Override
diff --git a/core/net/src/test/java/org/onosproject/cluster/impl/MastershipManagerTest.java b/core/net/src/test/java/org/onosproject/cluster/impl/MastershipManagerTest.java
index ac2e558..81533fb 100644
--- a/core/net/src/test/java/org/onosproject/cluster/impl/MastershipManagerTest.java
+++ b/core/net/src/test/java/org/onosproject/cluster/impl/MastershipManagerTest.java
@@ -37,6 +37,7 @@
import org.onosproject.mastership.MastershipStore;
import org.onosproject.mastership.MastershipTermService;
import org.onosproject.net.DeviceId;
+import org.onosproject.net.config.NetworkConfigServiceAdapter;
import org.onosproject.net.region.Region;
import org.onosproject.net.region.RegionId;
import org.onosproject.net.region.RegionStore;
@@ -374,6 +375,7 @@
private class TestRegionManager extends RegionManager {
TestRegionManager() {
eventDispatcher = new TestEventDispatcher();
+ networkConfigService = new NetworkConfigServiceAdapter();
}
}
}
diff --git a/core/net/src/test/java/org/onosproject/net/region/impl/RegionManagerTest.java b/core/net/src/test/java/org/onosproject/net/region/impl/RegionManagerTest.java
index fd15104..1e29365 100644
--- a/core/net/src/test/java/org/onosproject/net/region/impl/RegionManagerTest.java
+++ b/core/net/src/test/java/org/onosproject/net/region/impl/RegionManagerTest.java
@@ -27,6 +27,7 @@
import org.onosproject.common.event.impl.TestEventDispatcher;
import org.onosproject.net.DeviceId;
import org.onosproject.net.NetTestTools;
+import org.onosproject.net.config.NetworkConfigServiceAdapter;
import org.onosproject.net.region.Region;
import org.onosproject.net.region.RegionAdminService;
import org.onosproject.net.region.RegionEvent;
@@ -175,6 +176,7 @@
private class TestManager extends RegionManager {
TestManager() {
eventDispatcher = new TestEventDispatcher();
+ networkConfigService = new NetworkConfigServiceAdapter();
}
}
diff --git a/core/store/dist/src/main/java/org/onosproject/store/region/impl/DistributedRegionStore.java b/core/store/dist/src/main/java/org/onosproject/store/region/impl/DistributedRegionStore.java
index 6d70376..e00af16 100644
--- a/core/store/dist/src/main/java/org/onosproject/store/region/impl/DistributedRegionStore.java
+++ b/core/store/dist/src/main/java/org/onosproject/store/region/impl/DistributedRegionStore.java
@@ -26,6 +26,7 @@
import org.apache.felix.scr.annotations.Service;
import org.onlab.util.Identifier;
import org.onosproject.cluster.NodeId;
+import org.onosproject.net.Annotations;
import org.onosproject.net.DeviceId;
import org.onosproject.net.region.DefaultRegion;
import org.onosproject.net.region.Region;
@@ -90,7 +91,7 @@
protected void activate() {
Serializer serializer =
Serializer.using(Arrays.asList(KryoNamespaces.API),
- Identifier.class);
+ Identifier.class);
regionsRepo = storageService.<RegionId, Region>consistentMapBuilder()
.withSerializer(serializer)
@@ -141,19 +142,19 @@
@Override
public Region createRegion(RegionId regionId, String name, Region.Type type,
- List<Set<NodeId>> masterNodeIds) {
+ Annotations annots, List<Set<NodeId>> masterNodeIds) {
return regionsRepo.compute(regionId, (id, region) -> {
checkArgument(region == null, DUPLICATE_REGION);
- return new DefaultRegion(regionId, name, type, masterNodeIds);
+ return new DefaultRegion(regionId, name, type, annots, masterNodeIds);
}).value();
}
@Override
public Region updateRegion(RegionId regionId, String name, Region.Type type,
- List<Set<NodeId>> masterNodeIds) {
+ Annotations annots, List<Set<NodeId>> masterNodeIds) {
return regionsRepo.compute(regionId, (id, region) -> {
nullIsNotFound(region, NO_REGION);
- return new DefaultRegion(regionId, name, type, masterNodeIds);
+ return new DefaultRegion(regionId, name, type, annots, masterNodeIds);
}).value();
}
@@ -165,8 +166,9 @@
@Override
public void addDevices(RegionId regionId, Collection<DeviceId> deviceIds) {
- // Devices can only be a member in one region. Remove the device if it belongs to
- // a different region than the region for which we are attempting to add it.
+ // Devices can only be a member in one region. Remove the device if it
+ // belongs to a different region than the region for which we are
+ // attempting to add it.
for (DeviceId deviceId : deviceIds) {
Region region = getRegionForDevice(deviceId);
if ((region != null) && (!regionId.id().equals(region.id().id()))) {
@@ -200,7 +202,7 @@
} else {
return ImmutableSet.<DeviceId>builder()
.addAll(Sets.difference(existingDevices,
- ImmutableSet.copyOf(deviceIds)))
+ ImmutableSet.copyOf(deviceIds)))
.build();
}
});
@@ -211,7 +213,8 @@
/**
* Listener class to map listener events to the region inventory events.
*/
- private class InternalRegionListener implements MapEventListener<RegionId, Region> {
+ private class InternalRegionListener
+ implements MapEventListener<RegionId, Region> {
@Override
public void event(MapEvent<RegionId, Region> event) {
Region region = null;
@@ -239,13 +242,14 @@
/**
* Listener class to map listener events to the region membership events.
*/
- private class InternalMembershipListener implements MapEventListener<RegionId, Set<DeviceId>> {
+ private class InternalMembershipListener
+ implements MapEventListener<RegionId, Set<DeviceId>> {
@Override
public void event(MapEvent<RegionId, Set<DeviceId>> event) {
if (event.type() != MapEvent.Type.REMOVE) {
notifyDelegate(new RegionEvent(REGION_MEMBERSHIP_CHANGED,
- regionsById.get(event.key()),
- event.newValue().value()));
+ regionsById.get(event.key()),
+ event.newValue().value()));
}
}
}
diff --git a/core/store/dist/src/test/java/org/onosproject/store/region/impl/DistributedRegionStoreTest.java b/core/store/dist/src/test/java/org/onosproject/store/region/impl/DistributedRegionStoreTest.java
index 16520f3..7ec68e0 100644
--- a/core/store/dist/src/test/java/org/onosproject/store/region/impl/DistributedRegionStoreTest.java
+++ b/core/store/dist/src/test/java/org/onosproject/store/region/impl/DistributedRegionStoreTest.java
@@ -23,6 +23,8 @@
import org.junit.Test;
import org.onlab.util.ItemNotFoundException;
import org.onosproject.cluster.NodeId;
+import org.onosproject.net.Annotations;
+import org.onosproject.net.DefaultAnnotations;
import org.onosproject.net.DeviceId;
import org.onosproject.net.region.Region;
import org.onosproject.net.region.RegionEvent;
@@ -50,6 +52,8 @@
private static final NodeId NID1 = NodeId.nodeId("n1");
+ private static final Annotations NO_ANNOTS = DefaultAnnotations.EMPTY;
+
private static final List<Set<NodeId>> MASTERS = ImmutableList.of(ImmutableSet.of(NID1));
private TestStore store;
@@ -76,16 +80,16 @@
@Test
public void basics() {
- Region r1 = store.createRegion(RID1, "R1", METRO, MASTERS);
+ Region r1 = store.createRegion(RID1, "R1", METRO, NO_ANNOTS, MASTERS);
assertEquals("incorrect id", RID1, r1.id());
assertEquals("incorrect event", REGION_ADDED, event.type());
- Region r2 = store.createRegion(RID2, "R2", CAMPUS, MASTERS);
+ Region r2 = store.createRegion(RID2, "R2", CAMPUS, NO_ANNOTS, MASTERS);
assertEquals("incorrect id", RID2, r2.id());
assertEquals("incorrect type", CAMPUS, r2.type());
assertEquals("incorrect event", REGION_ADDED, event.type());
- r2 = store.updateRegion(RID2, "R2", COUNTRY, MASTERS);
+ r2 = store.updateRegion(RID2, "R2", COUNTRY, NO_ANNOTS, MASTERS);
assertEquals("incorrect type", COUNTRY, r2.type());
assertEquals("incorrect event", REGION_UPDATED, event.type());
@@ -106,18 +110,18 @@
@Test(expected = IllegalArgumentException.class)
public void duplicateCreate() {
- store.createRegion(RID1, "R1", METRO, MASTERS);
- store.createRegion(RID1, "R2", CAMPUS, MASTERS);
+ store.createRegion(RID1, "R1", METRO, NO_ANNOTS, MASTERS);
+ store.createRegion(RID1, "R2", CAMPUS, NO_ANNOTS, MASTERS);
}
@Test(expected = ItemNotFoundException.class)
public void missingUpdate() {
- store.updateRegion(RID1, "R1", METRO, MASTERS);
+ store.updateRegion(RID1, "R1", METRO, NO_ANNOTS, MASTERS);
}
@Test
public void membership() {
- Region r = store.createRegion(RID1, "R1", METRO, MASTERS);
+ Region r = store.createRegion(RID1, "R1", METRO, NO_ANNOTS, MASTERS);
assertTrue("no devices expected", store.getRegionDevices(RID1).isEmpty());
assertNull("no region expected", store.getRegionForDevice(DID1));
@@ -139,7 +143,7 @@
// Test adding DID3 to RID2 but it is already in RID1.
// DID3 will be removed from RID1 and added to RID2.
- Region r2 = store.createRegion(RID2, "R2", CAMPUS, MASTERS);
+ Region r2 = store.createRegion(RID2, "R2", CAMPUS, NO_ANNOTS, MASTERS);
store.addDevices(RID2, ImmutableSet.of(DID3));
deviceIds = store.getRegionDevices(RID1);
assertEquals("incorrect device count", 2, deviceIds.size());