Sho SHIMIZU

Remove dependency on LinkResourceService from ObjectiveTracker

This resolves ONOS-3262.

Change-Id: I57b51b9d8ef1ed2d847ecddeca279b8afdb8725e
......@@ -48,9 +48,9 @@ import org.onosproject.net.intent.PartitionEvent;
import org.onosproject.net.intent.PartitionEventListener;
import org.onosproject.net.intent.PartitionService;
import org.onosproject.net.link.LinkEvent;
import org.onosproject.net.resource.link.LinkResourceEvent;
import org.onosproject.net.resource.link.LinkResourceListener;
import org.onosproject.net.resource.link.LinkResourceService;
import org.onosproject.net.newresource.ResourceEvent;
import org.onosproject.net.newresource.ResourceListener;
import org.onosproject.net.newresource.ResourceService;
import org.onosproject.net.topology.TopologyEvent;
import org.onosproject.net.topology.TopologyListener;
import org.onosproject.net.topology.TopologyService;
......@@ -60,6 +60,7 @@ import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Optional;
import java.util.Set;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
......@@ -101,7 +102,7 @@ public class ObjectiveTracker implements ObjectiveTrackerService {
protected TopologyService topologyService;
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
protected LinkResourceService resourceManager;
protected ResourceService resourceService;
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
protected DeviceService deviceService;
......@@ -122,8 +123,7 @@ public class ObjectiveTracker implements ObjectiveTrackerService {
.newScheduledThreadPool(1);
private TopologyListener listener = new InternalTopologyListener();
private LinkResourceListener linkResourceListener =
new InternalLinkResourceListener();
private ResourceListener resourceListener = new InternalResourceListener();
private DeviceListener deviceListener = new InternalDeviceListener();
private HostListener hostListener = new InternalHostListener();
private PartitionEventListener partitionListener = new InternalPartitionListener();
......@@ -134,7 +134,7 @@ public class ObjectiveTracker implements ObjectiveTrackerService {
@Activate
public void activate() {
topologyService.addListener(listener);
resourceManager.addListener(linkResourceListener);
resourceService.addListener(resourceListener);
deviceService.addListener(deviceListener);
hostService.addListener(hostListener);
partitionService.addListener(partitionListener);
......@@ -144,7 +144,7 @@ public class ObjectiveTracker implements ObjectiveTrackerService {
@Deactivate
public void deactivate() {
topologyService.removeListener(listener);
resourceManager.removeListener(linkResourceListener);
resourceService.removeListener(resourceListener);
deviceService.removeListener(deviceListener);
hostService.removeListener(hostListener);
partitionService.removeListener(partitionListener);
......@@ -299,35 +299,22 @@ public class ObjectiveTracker implements ObjectiveTrackerService {
}
}
/**
* Internal re-actor to resource available events.
*/
private class InternalLinkResourceListener implements LinkResourceListener {
private class InternalResourceListener implements ResourceListener {
@Override
public void event(LinkResourceEvent event) {
executorService.execute(new ResourceAvailableHandler(event));
}
}
/*
* Re-dispatcher of resource available events.
*/
private class ResourceAvailableHandler implements Runnable {
private final LinkResourceEvent event;
ResourceAvailableHandler(LinkResourceEvent event) {
this.event = event;
}
public void event(ResourceEvent event) {
Optional<Class<?>> linkEvent = event.subject().components().stream()
.map(Object::getClass)
.filter(x -> x == LinkKey.class)
.findFirst();
if (linkEvent.isPresent()) {
executorService.execute(() -> {
if (delegate == null) {
return;
}
@Override
public void run() {
// If there is no delegate, why bother? Just bail.
if (delegate == null) {
return;
delegate.triggerCompile(Collections.emptySet(), true);
});
}
delegate.triggerCompile(Collections.emptySet(), true);
}
}
......
......@@ -16,7 +16,6 @@
package org.onosproject.net.intent.impl;
import java.util.Collection;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.concurrent.CountDownLatch;
......@@ -38,8 +37,9 @@ import org.onosproject.net.intent.Intent;
import org.onosproject.net.intent.Key;
import org.onosproject.net.intent.MockIdGenerator;
import org.onosproject.net.link.LinkEvent;
import org.onosproject.net.resource.link.LinkResourceEvent;
import org.onosproject.net.resource.link.LinkResourceListener;
import org.onosproject.net.newresource.ResourceEvent;
import org.onosproject.net.newresource.ResourceListener;
import org.onosproject.net.newresource.ResourcePath;
import org.onosproject.net.topology.Topology;
import org.onosproject.net.topology.TopologyEvent;
import org.onosproject.net.topology.TopologyListener;
......@@ -52,6 +52,8 @@ import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.hasSize;
import static org.hamcrest.Matchers.is;
import static org.onosproject.net.LinkKey.linkKey;
import static org.onosproject.net.newresource.ResourceEvent.Type.*;
import static org.onosproject.net.NetTestTools.APP_ID;
import static org.onosproject.net.NetTestTools.device;
import static org.onosproject.net.NetTestTools.link;
......@@ -67,7 +69,7 @@ public class ObjectiveTrackerTest {
private List<Event> reasons;
private TopologyListener listener;
private DeviceListener deviceListener;
private LinkResourceListener linkResourceListener;
private ResourceListener resourceListener;
private IdGenerator mockGenerator;
/**
......@@ -84,7 +86,7 @@ public class ObjectiveTrackerTest {
reasons = new LinkedList<>();
listener = TestUtils.getField(tracker, "listener");
deviceListener = TestUtils.getField(tracker, "deviceListener");
linkResourceListener = TestUtils.getField(tracker, "linkResourceListener");
resourceListener = TestUtils.getField(tracker, "resourceListener");
mockGenerator = new MockIdGenerator();
Intent.bindIdGenerator(mockGenerator);
}
......@@ -228,10 +230,9 @@ public class ObjectiveTrackerTest {
*/
@Test
public void testResourceEvent() throws Exception {
LinkResourceEvent event = new LinkResourceEvent(
LinkResourceEvent.Type.ADDITIONAL_RESOURCES_AVAILABLE,
new HashSet<>());
linkResourceListener.event(event);
ResourceEvent event = new ResourceEvent(RESOURCE_ADDED,
new ResourcePath(linkKey(link("a", 1, "b", 1))));
resourceListener.event(event);
assertThat(
delegate.latch.await(WAIT_TIMEOUT_SECONDS, TimeUnit.SECONDS),
......