Fix the issue of ONOS-3423
Change-Id: I60c3105149f6ef46e2effb7de6d8f40152027ec7
diff --git a/core/api/src/main/java/org/onosproject/net/newresource/ResourcePath.java b/core/api/src/main/java/org/onosproject/net/newresource/ResourcePath.java
index 0a4d385..d87682a 100644
--- a/core/api/src/main/java/org/onosproject/net/newresource/ResourcePath.java
+++ b/core/api/src/main/java/org/onosproject/net/newresource/ResourcePath.java
@@ -121,10 +121,10 @@
public List<Object> components() {
LinkedList<Object> components = new LinkedList<>();
- Optional<Discrete> parentPath = Optional.ofNullable(parent);
- while (parentPath.isPresent()) {
- components.addFirst(last);
- parentPath = parent.parent();
+ ResourcePath current = this;
+ while (current.parent().isPresent()) {
+ components.addFirst(current.last);
+ current = current.parent;
}
return components;
diff --git a/core/api/src/test/java/org/onosproject/net/newresource/ResourcePathTest.java b/core/api/src/test/java/org/onosproject/net/newresource/ResourcePathTest.java
index 8e44536..35dcf1e 100644
--- a/core/api/src/test/java/org/onosproject/net/newresource/ResourcePathTest.java
+++ b/core/api/src/test/java/org/onosproject/net/newresource/ResourcePathTest.java
@@ -26,6 +26,7 @@
import java.util.Optional;
+import static org.hamcrest.Matchers.contains;
import static org.hamcrest.Matchers.is;
import static org.junit.Assert.assertThat;
@@ -63,6 +64,13 @@
}
@Test
+ public void testComponents() {
+ ResourcePath port = ResourcePath.discrete(D1, P1);
+
+ assertThat(port.components(), contains(D1, P1));
+ }
+
+ @Test
public void testThereIsParent() {
ResourcePath path = ResourcePath.discrete(LinkKey.linkKey(CP1_1, CP2_1), VLAN1);
ResourcePath parent = ResourcePath.discrete(LinkKey.linkKey(CP1_1, CP2_1));
diff --git a/core/net/src/main/java/org/onosproject/net/newresource/impl/ResourceRegistrar.java b/core/net/src/main/java/org/onosproject/net/newresource/impl/ResourceRegistrar.java
index 8a320b8..143f8c2 100644
--- a/core/net/src/main/java/org/onosproject/net/newresource/impl/ResourceRegistrar.java
+++ b/core/net/src/main/java/org/onosproject/net/newresource/impl/ResourceRegistrar.java
@@ -59,17 +59,15 @@
@Activate
public void activate() {
- // FIXME there is a loop causing high resource utilization on device registration
-// deviceListener = new ResourceDeviceListener(adminService, executor);
-// deviceService.addListener(deviceListener);
-// linkListener = new ResourceLinkListener(adminService, driverService, executor);
-// linkService.addListener(linkListener);
+ deviceListener = new ResourceDeviceListener(adminService, executor);
+ deviceService.addListener(deviceListener);
+ linkListener = new ResourceLinkListener(adminService, driverService, executor);
+ linkService.addListener(linkListener);
}
@Deactivate
public void deactivate() {
- // FIXME there is a loop causing high resource utilization on device registration
-// deviceService.removeListener(deviceListener);
-// linkService.removeListener(linkListener);
+ deviceService.removeListener(deviceListener);
+ linkService.removeListener(linkListener);
}
}