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/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());