Ray Milkey
Committed by Brian O'Connor

Removed deprecated classes/interfaces

IntentBatchLeaderEvent
IntentBatchListener
IntentBatchService

Change-Id: I712f0eb0b26d9bfaa820a14022c1dd30943fab27
......@@ -56,7 +56,6 @@ import org.onosproject.net.host.HostService;
import org.onosproject.net.intent.Constraint;
import org.onosproject.net.intent.HostToHostIntent;
import org.onosproject.net.intent.Intent;
import org.onosproject.net.intent.IntentBatchService;
import org.onosproject.net.intent.IntentService;
import org.slf4j.Logger;
......@@ -103,9 +102,6 @@ public class DemoInstaller implements DemoAPI {
protected MastershipService mastershipService;
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
protected IntentBatchService intentBatchService;
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
protected ClusterService clusterService;
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
......
/*
* Copyright 2014 Open Networking Laboratory
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.net.intent;
import org.onosproject.core.ApplicationId;
import org.onosproject.event.AbstractEvent;
/**
* A class to represent an intent related event.
*/
@Deprecated
public class IntentBatchLeaderEvent extends AbstractEvent<IntentBatchLeaderEvent.Type, ApplicationId> {
public enum Type {
/**
* Signifies that this instance has become the leader for the given application id.
*/
ELECTED,
/**
* Signifies that instance is no longer the leader for a given application id.
*/
BOOTED
}
/**
* Creates an event of a given type and for the specified appId and the
* current time.
*
* @param type event type
* @param appId subject appId
* @param time time the event created in milliseconds since start of epoch
*/
public IntentBatchLeaderEvent(Type type, ApplicationId appId, long time) {
super(type, appId, time);
}
/**
* Creates an event of a given type and for the specified appId and the
* current time.
*
* @param type event type
* @param appId subject appId
*/
public IntentBatchLeaderEvent(Type type, ApplicationId appId) {
super(type, appId);
}
}
/*
* Copyright 2014 Open Networking Laboratory
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.net.intent;
import org.onosproject.event.EventListener;
/**
* Listener for {@link org.onosproject.net.intent.IntentEvent intent events}.
*/
@Deprecated
public interface IntentBatchListener extends EventListener<IntentBatchLeaderEvent> {
}
/*
* Copyright 2014 Open Networking Laboratory
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.net.intent;
import org.onosproject.core.ApplicationId;
/**
* Service for tracking and delegating batches of intent operations.
*/
@Deprecated
public interface IntentBatchService {
/**
* Return true if this instance is the local leader for batch
* processing a given application id.
*
* @param applicationId an application id
* @return true if this instance is the local leader for batch
*/
boolean isLocalLeader(ApplicationId applicationId);
/**
* Sets the batch service delegate.
*
* @param delegate delegate to apply
*/
void setDelegate(IntentBatchDelegate delegate);
/**
* Unsets the batch service delegate.
*
* @param delegate delegate to unset
*/
void unsetDelegate(IntentBatchDelegate delegate);
/**
* Adds the specified listener for intent batch leadership events.
*
* @param listener listener to be added
*/
void addListener(IntentBatchListener listener);
/**
* Removes the specified listener for intent batch leadership events.
*
* @param listener listener to be removed
*/
void removeListener(IntentBatchListener listener);
}
......@@ -29,9 +29,6 @@ import org.onosproject.event.Event;
import org.onosproject.net.Link;
import org.onosproject.net.LinkKey;
import org.onosproject.net.NetworkResource;
import org.onosproject.net.intent.IntentBatchLeaderEvent;
import org.onosproject.net.intent.IntentBatchListener;
import org.onosproject.net.intent.IntentBatchService;
import org.onosproject.net.intent.IntentId;
import org.onosproject.net.intent.IntentService;
import org.onosproject.net.link.LinkEvent;
......@@ -80,23 +77,18 @@ public class ObjectiveTracker implements ObjectiveTrackerService {
@Reference(cardinality = ReferenceCardinality.OPTIONAL_UNARY)
protected IntentService intentService;
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
protected IntentBatchService batchService;
private ExecutorService executorService =
newSingleThreadExecutor(namedThreads("onos-flowtracker"));
private TopologyListener listener = new InternalTopologyListener();
private LinkResourceListener linkResourceListener =
new InternalLinkResourceListener();
private final LeadershipListener leaderListener = new LeadershipListener();
private TopologyChangeDelegate delegate;
@Activate
public void activate() {
topologyService.addListener(listener);
resourceManager.addListener(linkResourceListener);
batchService.addListener(leaderListener);
log.info("Started");
}
......@@ -104,7 +96,6 @@ public class ObjectiveTracker implements ObjectiveTrackerService {
public void deactivate() {
topologyService.removeListener(listener);
resourceManager.removeListener(linkResourceListener);
batchService.removeListener(leaderListener);
log.info("Stopped");
}
......@@ -265,22 +256,4 @@ public class ObjectiveTracker implements ObjectiveTrackerService {
}
});
}
private class LeadershipListener implements IntentBatchListener {
@Override
public void event(IntentBatchLeaderEvent event) {
log.debug("leadership event: {}", event);
ApplicationId appId = event.subject();
switch (event.type()) {
case ELECTED:
updateTrackedResources(appId, true);
break;
case BOOTED:
updateTrackedResources(appId, false);
break;
default:
break;
}
}
}
}
......
......@@ -26,17 +26,13 @@ import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.onlab.junit.TestUtils;
import org.onlab.junit.TestUtils.TestUtilsException;
import org.onosproject.core.IdGenerator;
import org.onosproject.event.Event;
import org.onosproject.net.Link;
import org.onosproject.net.LinkKey;
import org.onosproject.net.NetTestTools;
import org.onosproject.net.NetworkResource;
import org.onosproject.net.intent.Intent;
import org.onosproject.net.intent.IntentBatchLeaderEvent;
import org.onosproject.net.intent.IntentBatchListener;
import org.onosproject.net.intent.IntentId;
import org.onosproject.net.intent.IntentService;
import org.onosproject.net.intent.MockIdGenerator;
import org.onosproject.net.link.LinkEvent;
import org.onosproject.net.resource.LinkResourceEvent;
......@@ -45,20 +41,15 @@ import org.onosproject.net.topology.Topology;
import org.onosproject.net.topology.TopologyEvent;
import org.onosproject.net.topology.TopologyListener;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Lists;
import com.google.common.collect.SetMultimap;
import static org.easymock.EasyMock.createMock;
import static org.easymock.EasyMock.expect;
import static org.easymock.EasyMock.replay;
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.NetTestTools.link;
import org.onlab.junit.TestUtils.TestUtilsException;
/**
* Tests for the objective tracker.
......@@ -71,7 +62,6 @@ public class ObjectiveTrackerTest {
private List<Event> reasons;
private TopologyListener listener;
private LinkResourceListener linkResourceListener;
private IntentBatchListener leaderListener;
private IdGenerator mockGenerator;
/**
......@@ -88,7 +78,6 @@ public class ObjectiveTrackerTest {
reasons = new LinkedList<>();
listener = TestUtils.getField(tracker, "listener");
linkResourceListener = TestUtils.getField(tracker, "linkResourceListener");
leaderListener = TestUtils.getField(tracker, "leaderListener");
mockGenerator = new MockIdGenerator();
Intent.bindIdGenerator(mockGenerator);
}
......@@ -123,32 +112,6 @@ public class ObjectiveTrackerTest {
}
/**
* Mock compilable intent class.
*/
private static class MockIntent extends Intent {
public MockIntent(Collection<NetworkResource> resources) {
super(NetTestTools.APP_ID, resources);
}
}
/**
* Mock installable intent class.
*/
private static class MockInstallableIntent extends Intent {
public MockInstallableIntent(Collection<NetworkResource> resources) {
super(NetTestTools.APP_ID, resources);
}
@Override
public boolean isInstallable() {
return true;
}
}
/**
* Tests an event with no associated reasons.
*
* @throws InterruptedException if the latch wait fails.
......@@ -271,52 +234,4 @@ public class ObjectiveTrackerTest {
assertThat(delegate.compileAllFailedFromEvent, is(true));
}
/**
* Tests leadership events.
*
* @throws InterruptedException if the latch wait fails.
*/
@Test
public void testLeaderEvents() throws Exception {
final Link link = link("src", 1, "dst", 2);
final List<NetworkResource> resources = ImmutableList.of(link);
final List<Intent> intents = new LinkedList<>();
final List<Intent> installableIntents = new LinkedList<>();
installableIntents.add(new MockInstallableIntent(resources));
intents.add(new MockIntent(resources));
final SetMultimap<LinkKey, IntentId> intentsByLink =
TestUtils.getField(tracker, "intentsByLink");
assertThat(intentsByLink.size(), is(0));
final IntentService mockIntentManager = createMock(IntentService.class);
expect(mockIntentManager
.getIntents())
.andReturn(intents)
.anyTimes();
expect(mockIntentManager
.getIntent(IntentId.valueOf(0x0)))
.andReturn(intents.get(0))
.anyTimes();
expect(mockIntentManager
.getInstallableIntents(IntentId.valueOf(0x1)))
.andReturn(installableIntents)
.anyTimes();
replay(mockIntentManager);
tracker.bindIntentService(mockIntentManager);
final IntentBatchLeaderEvent electedEvent = new IntentBatchLeaderEvent(
IntentBatchLeaderEvent.Type.ELECTED, NetTestTools.APP_ID);
leaderListener.event(electedEvent);
assertThat(intentsByLink.size(), is(1));
final IntentBatchLeaderEvent bootedEvent = new IntentBatchLeaderEvent(
IntentBatchLeaderEvent.Type.BOOTED, NetTestTools.APP_ID);
leaderListener.event(bootedEvent);
assertThat(intentsByLink.size(), is(0));
tracker.unbindIntentService(mockIntentManager);
}
}
......