Yuta HIGUCHI

Revert "Refactoring to move code to right locations. Attempt at breaking dependency cycles."

This reverts commit 58819b4d.
Showing 48 changed files with 226 additions and 233 deletions
package org.onlab.onos.cli;
import com.google.common.collect.Lists;
import org.apache.karaf.shell.commands.Command;
import org.onlab.onos.cluster.ClusterService;
import org.onlab.onos.cluster.ControllerNode;
import org.onlab.onos.cluster.MastershipService;
import org.onlab.onos.net.DeviceId;
import org.onlab.onos.net.device.DeviceMastershipService;
import java.util.Collections;
import java.util.List;
......@@ -23,7 +22,7 @@ public class MastersListCommand extends AbstractShellCommand {
@Override
protected void execute() {
ClusterService service = get(ClusterService.class);
DeviceMastershipService mastershipService = get(DeviceMastershipService.class);
MastershipService mastershipService = get(MastershipService.class);
List<ControllerNode> nodes = newArrayList(service.getNodes());
Collections.sort(nodes, Comparators.NODE_COMPARATOR);
ControllerNode self = service.getLocalNode();
......
......@@ -3,9 +3,9 @@ package org.onlab.onos.cli.net;
import org.apache.karaf.shell.commands.Argument;
import org.apache.karaf.shell.commands.Command;
import org.onlab.onos.cli.AbstractShellCommand;
import org.onlab.onos.cluster.MastershipAdminService;
import org.onlab.onos.cluster.NodeId;
import org.onlab.onos.net.MastershipRole;
import org.onlab.onos.net.device.DeviceMastershipAdminService;
import static org.onlab.onos.net.DeviceId.deviceId;
......@@ -30,7 +30,7 @@ public class DeviceRoleCommand extends AbstractShellCommand {
@Override
protected void execute() {
DeviceMastershipAdminService service = get(DeviceMastershipAdminService.class);
MastershipAdminService service = get(MastershipAdminService.class);
MastershipRole mastershipRole = MastershipRole.valueOf(role.toUpperCase());
service.setRole(new NodeId(node), deviceId(uri), mastershipRole);
}
......
package org.onlab.onos.net.device;
package org.onlab.onos.cluster;
import org.onlab.onos.cluster.NodeId;
import org.onlab.onos.net.DeviceId;
import org.onlab.onos.net.MastershipRole;
/**
* Service for administering the inventory of device masterships.
*/
public interface DeviceMastershipAdminService {
public interface MastershipAdminService {
/**
* Applies the current mastership role for the specified device.
......
package org.onlab.onos.net.device;
package org.onlab.onos.cluster;
import org.onlab.onos.cluster.NodeId;
import org.onlab.onos.event.AbstractEvent;
import org.onlab.onos.net.DeviceId;
/**
* Describes a device mastership event.
*/
public class DeviceMastershipEvent extends AbstractEvent<DeviceMastershipEvent.Type, DeviceId> {
public class MastershipEvent extends AbstractEvent<MastershipEvent.Type, DeviceId> {
//do we worry about explicitly setting slaves/equals? probably not,
//to keep it simple
......@@ -31,7 +30,7 @@ public class DeviceMastershipEvent extends AbstractEvent<DeviceMastershipEvent.T
* @param device event device subject
* @param master master ID subject
*/
public DeviceMastershipEvent(Type type, DeviceId device, NodeId master) {
public MastershipEvent(Type type, DeviceId device, NodeId master) {
super(type, device);
this.master = master;
}
......@@ -45,7 +44,7 @@ public class DeviceMastershipEvent extends AbstractEvent<DeviceMastershipEvent.T
* @param master master ID subject
* @param time occurrence time
*/
public DeviceMastershipEvent(Type type, DeviceId device, NodeId master, long time) {
public MastershipEvent(Type type, DeviceId device, NodeId master, long time) {
super(type, device, time);
this.master = master;
}
......
package org.onlab.onos.net.device;
package org.onlab.onos.cluster;
import org.onlab.onos.event.EventListener;
/**
* Entity capable of receiving device mastership-related events.
*/
public interface DeviceMastershipListener extends EventListener<DeviceMastershipEvent> {
public interface MastershipListener extends EventListener<MastershipEvent> {
}
......
package org.onlab.onos.net.device;
package org.onlab.onos.cluster;
import java.util.Set;
import org.onlab.onos.cluster.NodeId;
import org.onlab.onos.net.DeviceId;
import org.onlab.onos.net.MastershipRole;
......@@ -12,7 +11,7 @@ import org.onlab.onos.net.MastershipRole;
* determining mastership, but is not responsible for actually applying it
* to the devices; this falls on the device service.
*/
public interface DeviceMastershipService {
public interface MastershipService {
/**
* Returns the role of the local node for the specified device, without
......@@ -63,20 +62,20 @@ public interface DeviceMastershipService {
*
* @return the MastershipTermService for this mastership manager
*/
DeviceMastershipTermService requestTermService();
MastershipTermService requestTermService();
/**
* Adds the specified mastership change listener.
*
* @param listener the mastership listener
*/
void addListener(DeviceMastershipListener listener);
void addListener(MastershipListener listener);
/**
* Removes the specified mastership change listener.
*
* @param listener the mastership listener
*/
void removeListener(DeviceMastershipListener listener);
void removeListener(MastershipListener listener);
}
......
package org.onlab.onos.net.device;
package org.onlab.onos.cluster;
import java.util.Set;
import org.onlab.onos.cluster.NodeId;
import org.onlab.onos.net.DeviceId;
import org.onlab.onos.net.MastershipRole;
import org.onlab.onos.store.Store;
......@@ -11,7 +10,7 @@ import org.onlab.onos.store.Store;
* Manages inventory of mastership roles for devices, across controller
* instances; not intended for direct use.
*/
public interface DeviceMastershipStore extends Store<DeviceMastershipEvent, DeviceMastershipStoreDelegate> {
public interface MastershipStore extends Store<MastershipEvent, MastershipStoreDelegate> {
// three things to map: NodeId, DeviceId, MastershipRole
......@@ -55,7 +54,7 @@ public interface DeviceMastershipStore extends Store<DeviceMastershipEvent, Devi
* @param deviceId device identifier
* @return a mastership event
*/
DeviceMastershipEvent setMaster(NodeId nodeId, DeviceId deviceId);
MastershipEvent setMaster(NodeId nodeId, DeviceId deviceId);
/**
* Returns the current master and number of past mastership hand-offs
......@@ -64,7 +63,7 @@ public interface DeviceMastershipStore extends Store<DeviceMastershipEvent, Devi
* @param deviceId the device identifier
* @return the current master's ID and the term value for device, or null
*/
DeviceMastershipTerm getTermFor(DeviceId deviceId);
MastershipTerm getTermFor(DeviceId deviceId);
/**
* Sets a controller instance's mastership role to STANDBY for a device.
......@@ -75,7 +74,7 @@ public interface DeviceMastershipStore extends Store<DeviceMastershipEvent, Devi
* @param deviceId device to revoke mastership role for
* @return a mastership event
*/
DeviceMastershipEvent setStandby(NodeId nodeId, DeviceId deviceId);
MastershipEvent setStandby(NodeId nodeId, DeviceId deviceId);
/**
* Allows a controller instance to give up its current role for a device.
......@@ -86,6 +85,6 @@ public interface DeviceMastershipStore extends Store<DeviceMastershipEvent, Devi
* @param deviceId device to revoke mastership role for
* @return a mastership event
*/
DeviceMastershipEvent relinquishRole(NodeId nodeId, DeviceId deviceId);
MastershipEvent relinquishRole(NodeId nodeId, DeviceId deviceId);
}
......
package org.onlab.onos.net.device;
package org.onlab.onos.cluster;
import org.onlab.onos.store.StoreDelegate;
/**
* DeviceMastership store delegate abstraction.
* Mastership store delegate abstraction.
*/
public interface DeviceMastershipStoreDelegate extends StoreDelegate<DeviceMastershipEvent> {
public interface MastershipStoreDelegate extends StoreDelegate<MastershipEvent> {
}
......
package org.onlab.onos.net.device;
package org.onlab.onos.cluster;
import java.util.Objects;
import org.onlab.onos.cluster.NodeId;
public final class DeviceMastershipTerm {
public final class MastershipTerm {
private final NodeId master;
private final int termNumber;
private DeviceMastershipTerm(NodeId master, int term) {
private MastershipTerm(NodeId master, int term) {
this.master = master;
this.termNumber = term;
}
public static DeviceMastershipTerm of(NodeId master, int term) {
return new DeviceMastershipTerm(master, term);
public static MastershipTerm of(NodeId master, int term) {
return new MastershipTerm(master, term);
}
public NodeId master() {
......@@ -36,8 +34,8 @@ public final class DeviceMastershipTerm {
if (this == other) {
return true;
}
if (other instanceof DeviceMastershipTerm) {
DeviceMastershipTerm that = (DeviceMastershipTerm) other;
if (other instanceof MastershipTerm) {
MastershipTerm that = (MastershipTerm) other;
if (!this.master.equals(that.master)) {
return false;
}
......
package org.onlab.onos.net.device;
package org.onlab.onos.cluster;
import org.onlab.onos.net.DeviceId;
......@@ -6,7 +6,7 @@ import org.onlab.onos.net.DeviceId;
/**
* Service to obtain mastership term information.
*/
public interface DeviceMastershipTermService {
public interface MastershipTermService {
// TBD: manage/increment per device mastership change
// or increment on any change
......@@ -16,5 +16,5 @@ public interface DeviceMastershipTermService {
* @param deviceId the identifier of the device
* @return current master's term.
*/
DeviceMastershipTerm getMastershipTerm(DeviceId deviceId);
MastershipTerm getMastershipTerm(DeviceId deviceId);
}
......
package org.onlab.onos.store;
import org.onlab.onos.cluster.MastershipTerm;
import org.onlab.onos.net.DeviceId;
import org.onlab.onos.net.device.DeviceMastershipTerm;
//TODO: Consider renaming to DeviceClockProviderService?
/**
......@@ -16,5 +16,5 @@ public interface ClockProviderService {
* @param deviceId device identifier.
* @param term mastership term.
*/
public void setMastershipTerm(DeviceId deviceId, DeviceMastershipTerm term);
public void setMastershipTerm(DeviceId deviceId, MastershipTerm term);
}
......
......@@ -2,16 +2,13 @@ package org.onlab.onos.cluster;
import org.onlab.onos.net.DeviceId;
import org.onlab.onos.net.MastershipRole;
import org.onlab.onos.net.device.DeviceMastershipListener;
import org.onlab.onos.net.device.DeviceMastershipService;
import org.onlab.onos.net.device.DeviceMastershipTermService;
import java.util.Set;
/**
* Test adapter for mastership service.
*/
public class MastershipServiceAdapter implements DeviceMastershipService {
public class MastershipServiceAdapter implements MastershipService {
@Override
public MastershipRole getLocalRole(DeviceId deviceId) {
return null;
......@@ -37,15 +34,15 @@ public class MastershipServiceAdapter implements DeviceMastershipService {
}
@Override
public void addListener(DeviceMastershipListener listener) {
public void addListener(MastershipListener listener) {
}
@Override
public void removeListener(DeviceMastershipListener listener) {
public void removeListener(MastershipListener listener) {
}
@Override
public DeviceMastershipTermService requestTermService() {
public MastershipTermService requestTermService() {
return null;
}
}
......
......@@ -3,7 +3,6 @@ package org.onlab.onos.cluster;
import static org.junit.Assert.assertEquals;
import org.junit.Test;
import org.onlab.onos.net.device.DeviceMastershipTerm;
import com.google.common.testing.EqualsTester;
......@@ -12,10 +11,10 @@ public class MastershipTermTest {
private static final NodeId N1 = new NodeId("foo");
private static final NodeId N2 = new NodeId("bar");
private static final DeviceMastershipTerm TERM1 = DeviceMastershipTerm.of(N1, 0);
private static final DeviceMastershipTerm TERM2 = DeviceMastershipTerm.of(N2, 1);
private static final DeviceMastershipTerm TERM3 = DeviceMastershipTerm.of(N2, 1);
private static final DeviceMastershipTerm TERM4 = DeviceMastershipTerm.of(N1, 1);
private static final MastershipTerm TERM1 = MastershipTerm.of(N1, 0);
private static final MastershipTerm TERM2 = MastershipTerm.of(N2, 1);
private static final MastershipTerm TERM3 = MastershipTerm.of(N2, 1);
private static final MastershipTerm TERM4 = MastershipTerm.of(N1, 1);
@Test
public void basics() {
......@@ -25,7 +24,7 @@ public class MastershipTermTest {
@Test
public void testEquality() {
new EqualsTester().addEqualityGroup(DeviceMastershipTerm.of(N1, 0), TERM1)
new EqualsTester().addEqualityGroup(MastershipTerm.of(N1, 0), TERM1)
.addEqualityGroup(TERM2, TERM3)
.addEqualityGroup(TERM4);
}
......
......@@ -14,25 +14,25 @@ import org.apache.felix.scr.annotations.Service;
import org.onlab.onos.cluster.ClusterEvent;
import org.onlab.onos.cluster.ClusterEventListener;
import org.onlab.onos.cluster.ClusterService;
import org.onlab.onos.cluster.MastershipAdminService;
import org.onlab.onos.cluster.MastershipEvent;
import org.onlab.onos.cluster.MastershipListener;
import org.onlab.onos.cluster.MastershipService;
import org.onlab.onos.cluster.MastershipStore;
import org.onlab.onos.cluster.MastershipStoreDelegate;
import org.onlab.onos.cluster.MastershipTerm;
import org.onlab.onos.cluster.MastershipTermService;
import org.onlab.onos.cluster.NodeId;
import org.onlab.onos.event.AbstractListenerRegistry;
import org.onlab.onos.event.EventDeliveryService;
import org.onlab.onos.net.DeviceId;
import org.onlab.onos.net.MastershipRole;
import org.onlab.onos.net.device.DeviceMastershipAdminService;
import org.onlab.onos.net.device.DeviceMastershipEvent;
import org.onlab.onos.net.device.DeviceMastershipListener;
import org.onlab.onos.net.device.DeviceMastershipService;
import org.onlab.onos.net.device.DeviceMastershipStore;
import org.onlab.onos.net.device.DeviceMastershipStoreDelegate;
import org.onlab.onos.net.device.DeviceMastershipTerm;
import org.onlab.onos.net.device.DeviceMastershipTermService;
import org.slf4j.Logger;
@Component(immediate = true)
@Service
public class MastershipManager
implements DeviceMastershipService, DeviceMastershipAdminService {
implements MastershipService, MastershipAdminService {
private static final String NODE_ID_NULL = "Node ID cannot be null";
private static final String DEVICE_ID_NULL = "Device ID cannot be null";
......@@ -40,13 +40,13 @@ implements DeviceMastershipService, DeviceMastershipAdminService {
private final Logger log = getLogger(getClass());
protected final AbstractListenerRegistry<DeviceMastershipEvent, DeviceMastershipListener>
protected final AbstractListenerRegistry<MastershipEvent, MastershipListener>
listenerRegistry = new AbstractListenerRegistry<>();
private final DeviceMastershipStoreDelegate delegate = new InternalDelegate();
private final MastershipStoreDelegate delegate = new InternalDelegate();
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
protected DeviceMastershipStore store;
protected MastershipStore store;
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
protected EventDeliveryService eventDispatcher;
......@@ -58,7 +58,7 @@ implements DeviceMastershipService, DeviceMastershipAdminService {
@Activate
public void activate() {
eventDispatcher.addSink(DeviceMastershipEvent.class, listenerRegistry);
eventDispatcher.addSink(MastershipEvent.class, listenerRegistry);
clusterService.addListener(clusterListener);
store.setDelegate(delegate);
log.info("Started");
......@@ -66,7 +66,7 @@ implements DeviceMastershipService, DeviceMastershipAdminService {
@Deactivate
public void deactivate() {
eventDispatcher.removeSink(DeviceMastershipEvent.class);
eventDispatcher.removeSink(MastershipEvent.class);
clusterService.removeListener(clusterListener);
store.unsetDelegate(delegate);
log.info("Stopped");
......@@ -78,7 +78,7 @@ implements DeviceMastershipService, DeviceMastershipAdminService {
checkNotNull(deviceId, DEVICE_ID_NULL);
checkNotNull(role, ROLE_NULL);
DeviceMastershipEvent event = null;
MastershipEvent event = null;
if (role.equals(MastershipRole.MASTER)) {
event = store.setMaster(nodeId, deviceId);
} else {
......@@ -98,7 +98,7 @@ implements DeviceMastershipService, DeviceMastershipAdminService {
@Override
public void relinquishMastership(DeviceId deviceId) {
DeviceMastershipEvent event = null;
MastershipEvent event = null;
event = store.relinquishRole(
clusterService.getLocalNode().id(), deviceId);
......@@ -127,18 +127,18 @@ implements DeviceMastershipService, DeviceMastershipAdminService {
@Override
public DeviceMastershipTermService requestTermService() {
public MastershipTermService requestTermService() {
return new InternalMastershipTermService();
}
@Override
public void addListener(DeviceMastershipListener listener) {
public void addListener(MastershipListener listener) {
checkNotNull(listener);
listenerRegistry.addListener(listener);
}
@Override
public void removeListener(DeviceMastershipListener listener) {
public void removeListener(MastershipListener listener) {
checkNotNull(listener);
listenerRegistry.removeListener(listener);
}
......@@ -146,16 +146,16 @@ implements DeviceMastershipService, DeviceMastershipAdminService {
// FIXME: provide wiring to allow events to be triggered by changes within the store
// Posts the specified event to the local event dispatcher.
private void post(DeviceMastershipEvent event) {
private void post(MastershipEvent event) {
if (event != null && eventDispatcher != null) {
eventDispatcher.post(event);
}
}
private class InternalMastershipTermService implements DeviceMastershipTermService {
private class InternalMastershipTermService implements MastershipTermService {
@Override
public DeviceMastershipTerm getMastershipTerm(DeviceId deviceId) {
public MastershipTerm getMastershipTerm(DeviceId deviceId) {
return store.getTermFor(deviceId);
}
......@@ -181,10 +181,10 @@ implements DeviceMastershipService, DeviceMastershipAdminService {
}
public class InternalDelegate implements DeviceMastershipStoreDelegate {
public class InternalDelegate implements MastershipStoreDelegate {
@Override
public void notify(DeviceMastershipEvent event) {
public void notify(MastershipEvent event) {
log.info("dispatching mastership event {}", event);
eventDispatcher.post(event);
}
......
......@@ -13,6 +13,11 @@ import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.ReferenceCardinality;
import org.apache.felix.scr.annotations.Service;
import org.onlab.onos.cluster.ClusterService;
import org.onlab.onos.cluster.MastershipEvent;
import org.onlab.onos.cluster.MastershipListener;
import org.onlab.onos.cluster.MastershipService;
import org.onlab.onos.cluster.MastershipTermService;
import org.onlab.onos.cluster.MastershipTerm;
import org.onlab.onos.cluster.NodeId;
import org.onlab.onos.event.AbstractListenerRegistry;
import org.onlab.onos.event.EventDeliveryService;
......@@ -31,11 +36,6 @@ import org.onlab.onos.net.device.DeviceProviderService;
import org.onlab.onos.net.device.DeviceService;
import org.onlab.onos.net.device.DeviceStore;
import org.onlab.onos.net.device.DeviceStoreDelegate;
import org.onlab.onos.net.device.DeviceMastershipEvent;
import org.onlab.onos.net.device.DeviceMastershipListener;
import org.onlab.onos.net.device.DeviceMastershipService;
import org.onlab.onos.net.device.DeviceMastershipTerm;
import org.onlab.onos.net.device.DeviceMastershipTermService;
import org.onlab.onos.net.device.PortDescription;
import org.onlab.onos.net.provider.AbstractProviderRegistry;
import org.onlab.onos.net.provider.AbstractProviderService;
......@@ -64,7 +64,7 @@ public class DeviceManager
private final DeviceStoreDelegate delegate = new InternalStoreDelegate();
private final DeviceMastershipListener mastershipListener = new InternalMastershipListener();
private final MastershipListener mastershipListener = new InternalMastershipListener();
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
protected DeviceStore store;
......@@ -76,9 +76,9 @@ public class DeviceManager
protected ClusterService clusterService;
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
protected DeviceMastershipService mastershipService;
protected MastershipService mastershipService;
protected DeviceMastershipTermService termService;
protected MastershipTermService termService;
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
protected ClockProviderService clockProviderService;
......@@ -209,7 +209,7 @@ public class DeviceManager
return;
}
DeviceMastershipTerm term = mastershipService.requestTermService()
MastershipTerm term = mastershipService.requestTermService()
.getMastershipTerm(deviceId);
if (!term.master().equals(clusterService.getLocalNode().id())) {
// lost mastership after requestRole told this instance was MASTER.
......@@ -320,16 +320,16 @@ public class DeviceManager
}
// Intercepts mastership events
private class InternalMastershipListener implements DeviceMastershipListener {
private class InternalMastershipListener implements MastershipListener {
@Override
public void event(DeviceMastershipEvent event) {
public void event(MastershipEvent event) {
final DeviceId did = event.subject();
if (isAvailable(did)) {
final NodeId myNodeId = clusterService.getLocalNode().id();
if (myNodeId.equals(event.master())) {
DeviceMastershipTerm term = termService.getMastershipTerm(did);
MastershipTerm term = termService.getMastershipTerm(did);
if (term.master().equals(myNodeId)) {
// only set the new term if I am the master
......
......@@ -10,11 +10,11 @@ import org.onlab.onos.cluster.ClusterService;
import org.onlab.onos.cluster.ControllerNode;
import org.onlab.onos.cluster.ControllerNode.State;
import org.onlab.onos.cluster.DefaultControllerNode;
import org.onlab.onos.cluster.MastershipService;
import org.onlab.onos.cluster.MastershipTermService;
import org.onlab.onos.cluster.NodeId;
import org.onlab.onos.event.impl.TestEventDispatcher;
import org.onlab.onos.net.DeviceId;
import org.onlab.onos.net.device.DeviceMastershipService;
import org.onlab.onos.net.device.DeviceMastershipTermService;
import org.onlab.onos.store.trivial.impl.SimpleMastershipStore;
import org.onlab.packet.IpPrefix;
......@@ -34,7 +34,7 @@ public class MastershipManagerTest {
private static final DeviceId DEV_OTHER = DeviceId.deviceId("of:2");
private MastershipManager mgr;
protected DeviceMastershipService service;
protected MastershipService service;
@Before
public void setUp() {
......@@ -120,7 +120,7 @@ public class MastershipManagerTest {
@Test
public void termService() {
DeviceMastershipTermService ts = mgr.requestTermService();
MastershipTermService ts = mgr.requestTermService();
//term = 0 for both
mgr.setRole(NID_LOCAL, DEV_MASTER, MASTER);
......
......@@ -11,6 +11,8 @@ import org.onlab.onos.cluster.ClusterService;
import org.onlab.onos.cluster.ControllerNode;
import org.onlab.onos.cluster.DefaultControllerNode;
import org.onlab.onos.cluster.MastershipServiceAdapter;
import org.onlab.onos.cluster.MastershipTerm;
import org.onlab.onos.cluster.MastershipTermService;
import org.onlab.onos.cluster.NodeId;
import org.onlab.onos.cluster.ControllerNode.State;
import org.onlab.onos.event.Event;
......@@ -30,8 +32,6 @@ import org.onlab.onos.net.device.DeviceProvider;
import org.onlab.onos.net.device.DeviceProviderRegistry;
import org.onlab.onos.net.device.DeviceProviderService;
import org.onlab.onos.net.device.DeviceService;
import org.onlab.onos.net.device.DeviceMastershipTerm;
import org.onlab.onos.net.device.DeviceMastershipTermService;
import org.onlab.onos.net.device.PortDescription;
import org.onlab.onos.net.provider.AbstractProvider;
import org.onlab.onos.net.provider.ProviderId;
......@@ -290,12 +290,12 @@ public class DeviceManagerTest {
}
@Override
public DeviceMastershipTermService requestTermService() {
return new DeviceMastershipTermService() {
public MastershipTermService requestTermService() {
return new MastershipTermService() {
@Override
public DeviceMastershipTerm getMastershipTerm(DeviceId deviceId) {
public MastershipTerm getMastershipTerm(DeviceId deviceId) {
// FIXME: just returning something not null
return DeviceMastershipTerm.of(NID_LOCAL, 1);
return MastershipTerm.of(NID_LOCAL, 1);
}
};
}
......@@ -339,7 +339,7 @@ public class DeviceManagerTest {
ClockProviderService {
@Override
public void setMastershipTerm(DeviceId deviceId, DeviceMastershipTerm term) {
public void setMastershipTerm(DeviceId deviceId, MastershipTerm term) {
// TODO Auto-generated method stub
}
}
......
......@@ -6,7 +6,6 @@ import java.io.IOException;
import java.util.Set;
import java.util.Timer;
import java.util.TimerTask;
import org.apache.felix.scr.annotations.Activate;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Deactivate;
......@@ -24,8 +23,10 @@ import org.onlab.onos.store.cluster.messaging.ClusterCommunicationService;
import org.onlab.onos.store.cluster.messaging.ClusterMessage;
import org.onlab.onos.store.cluster.messaging.ClusterMessageHandler;
import org.onlab.onos.store.cluster.messaging.MessageSubject;
import org.onlab.onos.store.serializers.ClusterMessageSerializer;
import org.onlab.onos.store.serializers.KryoPoolUtil;
import org.onlab.onos.store.serializers.KryoSerializer;
import org.onlab.onos.store.serializers.MessageSubjectSerializer;
import org.onlab.util.KryoPool;
import org.onlab.netty.Endpoint;
import org.onlab.netty.Message;
......
......@@ -4,7 +4,7 @@ import java.util.Map;
import java.util.Set;
import org.onlab.onos.cluster.NodeId;
import org.onlab.onos.store.VersionedValue;
import org.onlab.onos.store.device.impl.VersionedValue;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
......
......@@ -13,7 +13,7 @@ import com.google.common.collect.ComparisonChain;
* Default implementation of Timestamp.
* TODO: Better documentation.
*/
public final class DeviceMastershipBasedTimestamp implements Timestamp {
public final class MastershipBasedTimestamp implements Timestamp {
private final int termNumber;
private final int sequenceNumber;
......@@ -24,16 +24,16 @@ public final class DeviceMastershipBasedTimestamp implements Timestamp {
* @param termNumber the mastership termNumber
* @param sequenceNumber the sequenceNumber number within the termNumber
*/
public DeviceMastershipBasedTimestamp(int termNumber, int sequenceNumber) {
public MastershipBasedTimestamp(int termNumber, int sequenceNumber) {
this.termNumber = termNumber;
this.sequenceNumber = sequenceNumber;
}
@Override
public int compareTo(Timestamp o) {
checkArgument(o instanceof DeviceMastershipBasedTimestamp,
checkArgument(o instanceof MastershipBasedTimestamp,
"Must be MastershipBasedTimestamp", o);
DeviceMastershipBasedTimestamp that = (DeviceMastershipBasedTimestamp) o;
MastershipBasedTimestamp that = (MastershipBasedTimestamp) o;
return ComparisonChain.start()
.compare(this.termNumber, that.termNumber)
......@@ -51,10 +51,10 @@ public final class DeviceMastershipBasedTimestamp implements Timestamp {
if (this == obj) {
return true;
}
if (!(obj instanceof DeviceMastershipBasedTimestamp)) {
if (!(obj instanceof MastershipBasedTimestamp)) {
return false;
}
DeviceMastershipBasedTimestamp that = (DeviceMastershipBasedTimestamp) obj;
MastershipBasedTimestamp that = (MastershipBasedTimestamp) obj;
return Objects.equals(this.termNumber, that.termNumber) &&
Objects.equals(this.sequenceNumber, that.sequenceNumber);
}
......@@ -87,7 +87,7 @@ public final class DeviceMastershipBasedTimestamp implements Timestamp {
// Default constructor for serialization
@Deprecated
protected DeviceMastershipBasedTimestamp() {
protected MastershipBasedTimestamp() {
this.termNumber = -1;
this.sequenceNumber = -1;
}
......
package org.onlab.onos.store;
package org.onlab.onos.store.common.impl;
import static com.google.common.base.Preconditions.checkNotNull;
import java.util.Objects;
import org.onlab.onos.store.Timestamp;
import com.google.common.base.MoreObjects;
/**
......
......@@ -8,7 +8,6 @@ import org.onlab.onos.cluster.NodeId;
import org.onlab.onos.net.Device;
import org.onlab.onos.net.DeviceId;
import org.onlab.onos.store.Timestamp;
import org.onlab.onos.store.VersionedValue;
import org.onlab.onos.store.common.impl.AntiEntropyAdvertisement;
// TODO DeviceID needs to be changed to something like (ProviderID, DeviceID)
......
......@@ -10,7 +10,6 @@ import org.onlab.onos.cluster.NodeId;
import org.onlab.onos.net.Device;
import org.onlab.onos.net.DeviceId;
import org.onlab.onos.store.Timestamp;
import org.onlab.onos.store.VersionedValue;
import org.onlab.onos.store.common.impl.AntiEntropyReply;
import com.google.common.collect.ImmutableMap;
......
......@@ -10,12 +10,12 @@ import org.apache.felix.scr.annotations.Activate;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Deactivate;
import org.apache.felix.scr.annotations.Service;
import org.onlab.onos.cluster.MastershipTerm;
import org.onlab.onos.net.DeviceId;
import org.onlab.onos.net.device.DeviceMastershipTerm;
import org.onlab.onos.store.ClockProviderService;
import org.onlab.onos.store.ClockService;
import org.onlab.onos.store.Timestamp;
import org.onlab.onos.store.common.impl.DeviceMastershipBasedTimestamp;
import org.onlab.onos.store.common.impl.MastershipBasedTimestamp;
import org.slf4j.Logger;
/**
......@@ -29,7 +29,7 @@ public class DeviceClockManager implements ClockService, ClockProviderService {
// TODO: Implement per device ticker that is reset to 0 at the beginning of a new term.
private final AtomicInteger ticker = new AtomicInteger(0);
private ConcurrentMap<DeviceId, DeviceMastershipTerm> deviceMastershipTerms = new ConcurrentHashMap<>();
private ConcurrentMap<DeviceId, MastershipTerm> deviceMastershipTerms = new ConcurrentHashMap<>();
@Activate
public void activate() {
......@@ -43,15 +43,15 @@ public class DeviceClockManager implements ClockService, ClockProviderService {
@Override
public Timestamp getTimestamp(DeviceId deviceId) {
DeviceMastershipTerm term = deviceMastershipTerms.get(deviceId);
MastershipTerm term = deviceMastershipTerms.get(deviceId);
if (term == null) {
throw new IllegalStateException("Requesting timestamp for a deviceId without mastership");
}
return new DeviceMastershipBasedTimestamp(term.termNumber(), ticker.incrementAndGet());
return new MastershipBasedTimestamp(term.termNumber(), ticker.incrementAndGet());
}
@Override
public void setMastershipTerm(DeviceId deviceId, DeviceMastershipTerm term) {
public void setMastershipTerm(DeviceId deviceId, MastershipTerm term) {
deviceMastershipTerms.put(deviceId, term);
}
}
......
......@@ -35,14 +35,14 @@ import org.onlab.onos.net.provider.ProviderId;
import org.onlab.onos.store.AbstractStore;
import org.onlab.onos.store.ClockService;
import org.onlab.onos.store.Timestamp;
import org.onlab.onos.store.Timestamped;
import org.onlab.onos.store.cluster.messaging.ClusterCommunicationService;
import org.onlab.onos.store.cluster.messaging.ClusterMessage;
import org.onlab.onos.store.cluster.messaging.ClusterMessageHandler;
import org.onlab.onos.store.common.impl.DeviceMastershipBasedTimestamp;
import org.onlab.onos.store.common.impl.MastershipBasedTimestampSerializer;
import org.onlab.onos.store.common.impl.MastershipBasedTimestamp;
import org.onlab.onos.store.common.impl.Timestamped;
import org.onlab.onos.store.serializers.KryoPoolUtil;
import org.onlab.onos.store.serializers.KryoSerializer;
import org.onlab.onos.store.serializers.MastershipBasedTimestampSerializer;
import org.onlab.util.KryoPool;
import org.onlab.util.NewConcurrentHashMap;
import org.slf4j.Logger;
......@@ -125,7 +125,7 @@ public class GossipDeviceStore
.register(InternalPortStatusEvent.class, new InternalPortStatusEventSerializer())
.register(Timestamp.class)
.register(Timestamped.class)
.register(DeviceMastershipBasedTimestamp.class, new MastershipBasedTimestampSerializer())
.register(MastershipBasedTimestamp.class, new MastershipBasedTimestampSerializer())
.build()
.populate(1);
}
......
......@@ -3,7 +3,7 @@ package org.onlab.onos.store.device.impl;
import org.onlab.onos.net.DeviceId;
import org.onlab.onos.net.device.DeviceDescription;
import org.onlab.onos.net.provider.ProviderId;
import org.onlab.onos.store.Timestamped;
import org.onlab.onos.store.common.impl.Timestamped;
/**
* Information published by GossipDeviceStore to notify peers of a device
......
......@@ -3,7 +3,7 @@ package org.onlab.onos.store.device.impl;
import org.onlab.onos.net.DeviceId;
import org.onlab.onos.net.device.DeviceDescription;
import org.onlab.onos.net.provider.ProviderId;
import org.onlab.onos.store.Timestamped;
import org.onlab.onos.store.common.impl.Timestamped;
import com.esotericsoftware.kryo.Kryo;
import com.esotericsoftware.kryo.Serializer;
......
......@@ -5,7 +5,7 @@ import java.util.List;
import org.onlab.onos.net.DeviceId;
import org.onlab.onos.net.device.PortDescription;
import org.onlab.onos.net.provider.ProviderId;
import org.onlab.onos.store.Timestamped;
import org.onlab.onos.store.common.impl.Timestamped;
/**
* Information published by GossipDeviceStore to notify peers of a port
......
......@@ -5,7 +5,7 @@ import java.util.List;
import org.onlab.onos.net.DeviceId;
import org.onlab.onos.net.device.PortDescription;
import org.onlab.onos.net.provider.ProviderId;
import org.onlab.onos.store.Timestamped;
import org.onlab.onos.store.common.impl.Timestamped;
import com.esotericsoftware.kryo.Kryo;
import com.esotericsoftware.kryo.Serializer;
......
......@@ -3,7 +3,7 @@ package org.onlab.onos.store.device.impl;
import org.onlab.onos.net.DeviceId;
import org.onlab.onos.net.device.PortDescription;
import org.onlab.onos.net.provider.ProviderId;
import org.onlab.onos.store.Timestamped;
import org.onlab.onos.store.common.impl.Timestamped;
/**
* Information published by GossipDeviceStore to notify peers of a port
......
......@@ -3,7 +3,7 @@ package org.onlab.onos.store.device.impl;
import org.onlab.onos.net.DeviceId;
import org.onlab.onos.net.device.PortDescription;
import org.onlab.onos.net.provider.ProviderId;
import org.onlab.onos.store.Timestamped;
import org.onlab.onos.store.common.impl.Timestamped;
import com.esotericsoftware.kryo.Kryo;
import com.esotericsoftware.kryo.Serializer;
......
package org.onlab.onos.store;
package org.onlab.onos.store.device.impl;
import java.util.Objects;
import org.onlab.onos.store.Timestamp;
/**
* Wrapper class for a entity that is versioned
* and can either be up or down.
......
......@@ -31,7 +31,7 @@ import org.onlab.onos.net.provider.ProviderId;
import org.onlab.onos.store.AbstractStore;
import org.onlab.onos.store.ClockService;
import org.onlab.onos.store.Timestamp;
import org.onlab.onos.store.VersionedValue;
import org.onlab.onos.store.device.impl.VersionedValue;
import org.slf4j.Logger;
import com.google.common.collect.HashMultimap;
......
package org.onlab.onos.store.cluster.messaging.impl;
package org.onlab.onos.store.serializers;
import org.onlab.onos.cluster.NodeId;
import org.onlab.onos.store.cluster.messaging.ClusterMessage;
......
package org.onlab.onos.store.common.impl;
package org.onlab.onos.store.serializers;
import org.onlab.onos.store.common.impl.MastershipBasedTimestamp;
import com.esotericsoftware.kryo.Kryo;
import com.esotericsoftware.kryo.Serializer;
......@@ -7,12 +9,12 @@ import com.esotericsoftware.kryo.io.Output;
// To be used if Timestamp ever needs to cross bundle boundary.
/**
* Kryo Serializer for {@link DeviceMastershipBasedTimestamp}.
* Kryo Serializer for {@link MastershipBasedTimestamp}.
*/
public class MastershipBasedTimestampSerializer extends Serializer<DeviceMastershipBasedTimestamp> {
public class MastershipBasedTimestampSerializer extends Serializer<MastershipBasedTimestamp> {
/**
* Creates a serializer for {@link DeviceMastershipBasedTimestamp}.
* Creates a serializer for {@link MastershipBasedTimestamp}.
*/
public MastershipBasedTimestampSerializer() {
// non-null, immutable
......@@ -20,15 +22,15 @@ public class MastershipBasedTimestampSerializer extends Serializer<DeviceMasters
}
@Override
public void write(Kryo kryo, Output output, DeviceMastershipBasedTimestamp object) {
public void write(Kryo kryo, Output output, MastershipBasedTimestamp object) {
output.writeInt(object.termNumber());
output.writeInt(object.sequenceNumber());
}
@Override
public DeviceMastershipBasedTimestamp read(Kryo kryo, Input input, Class<DeviceMastershipBasedTimestamp> type) {
public MastershipBasedTimestamp read(Kryo kryo, Input input, Class<MastershipBasedTimestamp> type) {
final int term = input.readInt();
final int sequence = input.readInt();
return new DeviceMastershipBasedTimestamp(term, sequence);
return new MastershipBasedTimestamp(term, sequence);
}
}
......
package org.onlab.onos.store.cluster.messaging.impl;
package org.onlab.onos.store.serializers;
import org.onlab.onos.store.cluster.messaging.MessageSubject;
......
......@@ -6,25 +6,26 @@ import java.nio.ByteBuffer;
import org.junit.Test;
import org.onlab.onos.store.Timestamp;
import org.onlab.onos.store.serializers.MastershipBasedTimestampSerializer;
import org.onlab.util.KryoPool;
import com.google.common.testing.EqualsTester;
/**
* Test of {@link DeviceMastershipBasedTimestamp}.
* Test of {@link MastershipBasedTimestamp}.
*/
public class MastershipBasedTimestampTest {
private static final Timestamp TS_1_1 = new DeviceMastershipBasedTimestamp(1, 1);
private static final Timestamp TS_1_2 = new DeviceMastershipBasedTimestamp(1, 2);
private static final Timestamp TS_2_1 = new DeviceMastershipBasedTimestamp(2, 1);
private static final Timestamp TS_2_2 = new DeviceMastershipBasedTimestamp(2, 2);
private static final Timestamp TS_1_1 = new MastershipBasedTimestamp(1, 1);
private static final Timestamp TS_1_2 = new MastershipBasedTimestamp(1, 2);
private static final Timestamp TS_2_1 = new MastershipBasedTimestamp(2, 1);
private static final Timestamp TS_2_2 = new MastershipBasedTimestamp(2, 2);
@Test
public final void testBasic() {
final int termNumber = 5;
final int sequenceNumber = 6;
DeviceMastershipBasedTimestamp ts = new DeviceMastershipBasedTimestamp(termNumber,
MastershipBasedTimestamp ts = new MastershipBasedTimestamp(termNumber,
sequenceNumber);
assertEquals(termNumber, ts.termNumber());
......@@ -34,7 +35,7 @@ public class MastershipBasedTimestampTest {
@Test
public final void testCompareTo() {
assertTrue(TS_1_1.compareTo(TS_1_1) == 0);
assertTrue(TS_1_1.compareTo(new DeviceMastershipBasedTimestamp(1, 1)) == 0);
assertTrue(TS_1_1.compareTo(new MastershipBasedTimestamp(1, 1)) == 0);
assertTrue(TS_1_1.compareTo(TS_1_2) < 0);
assertTrue(TS_1_2.compareTo(TS_1_1) > 0);
......@@ -48,14 +49,14 @@ public class MastershipBasedTimestampTest {
@Test
public final void testEqualsObject() {
new EqualsTester()
.addEqualityGroup(new DeviceMastershipBasedTimestamp(1, 1),
new DeviceMastershipBasedTimestamp(1, 1), TS_1_1)
.addEqualityGroup(new DeviceMastershipBasedTimestamp(1, 2),
new DeviceMastershipBasedTimestamp(1, 2), TS_1_2)
.addEqualityGroup(new DeviceMastershipBasedTimestamp(2, 1),
new DeviceMastershipBasedTimestamp(2, 1), TS_2_1)
.addEqualityGroup(new DeviceMastershipBasedTimestamp(2, 2),
new DeviceMastershipBasedTimestamp(2, 2), TS_2_2)
.addEqualityGroup(new MastershipBasedTimestamp(1, 1),
new MastershipBasedTimestamp(1, 1), TS_1_1)
.addEqualityGroup(new MastershipBasedTimestamp(1, 2),
new MastershipBasedTimestamp(1, 2), TS_1_2)
.addEqualityGroup(new MastershipBasedTimestamp(2, 1),
new MastershipBasedTimestamp(2, 1), TS_2_1)
.addEqualityGroup(new MastershipBasedTimestamp(2, 2),
new MastershipBasedTimestamp(2, 2), TS_2_2)
.testEquals();
}
......@@ -63,7 +64,7 @@ public class MastershipBasedTimestampTest {
public final void testKryoSerializable() {
final ByteBuffer buffer = ByteBuffer.allocate(1 * 1024 * 1024);
final KryoPool kryos = KryoPool.newBuilder()
.register(DeviceMastershipBasedTimestamp.class)
.register(MastershipBasedTimestamp.class)
.build();
kryos.serialize(TS_2_1, buffer);
......@@ -79,7 +80,7 @@ public class MastershipBasedTimestampTest {
public final void testKryoSerializableWithHandcraftedSerializer() {
final ByteBuffer buffer = ByteBuffer.allocate(1 * 1024 * 1024);
final KryoPool kryos = KryoPool.newBuilder()
.register(DeviceMastershipBasedTimestamp.class, new MastershipBasedTimestampSerializer())
.register(MastershipBasedTimestamp.class, new MastershipBasedTimestampSerializer())
.build();
kryos.serialize(TS_1_2, buffer);
......
......@@ -6,7 +6,6 @@ import java.nio.ByteBuffer;
import org.junit.Test;
import org.onlab.onos.store.Timestamp;
import org.onlab.onos.store.Timestamped;
import org.onlab.util.KryoPool;
import com.google.common.testing.EqualsTester;
......@@ -16,9 +15,9 @@ import com.google.common.testing.EqualsTester;
*/
public class TimestampedTest {
private static final Timestamp TS_1_1 = new DeviceMastershipBasedTimestamp(1, 1);
private static final Timestamp TS_1_2 = new DeviceMastershipBasedTimestamp(1, 2);
private static final Timestamp TS_2_1 = new DeviceMastershipBasedTimestamp(2, 1);
private static final Timestamp TS_1_1 = new MastershipBasedTimestamp(1, 1);
private static final Timestamp TS_1_2 = new MastershipBasedTimestamp(1, 2);
private static final Timestamp TS_2_1 = new MastershipBasedTimestamp(2, 1);
@Test
public final void testHashCode() {
......@@ -80,7 +79,7 @@ public class TimestampedTest {
final ByteBuffer buffer = ByteBuffer.allocate(1 * 1024 * 1024);
final KryoPool kryos = KryoPool.newBuilder()
.register(Timestamped.class,
DeviceMastershipBasedTimestamp.class)
MastershipBasedTimestamp.class)
.build();
Timestamped<String> original = new Timestamped<>("foobar", TS_1_1);
......
......@@ -25,6 +25,7 @@ import org.onlab.onos.cluster.ClusterService;
import org.onlab.onos.cluster.ControllerNode;
import org.onlab.onos.cluster.ControllerNode.State;
import org.onlab.onos.cluster.DefaultControllerNode;
import org.onlab.onos.cluster.MastershipTerm;
import org.onlab.onos.cluster.NodeId;
import org.onlab.onos.net.Annotations;
import org.onlab.onos.net.DefaultAnnotations;
......@@ -39,7 +40,6 @@ import org.onlab.onos.net.device.DeviceDescription;
import org.onlab.onos.net.device.DeviceEvent;
import org.onlab.onos.net.device.DeviceStore;
import org.onlab.onos.net.device.DeviceStoreDelegate;
import org.onlab.onos.net.device.DeviceMastershipTerm;
import org.onlab.onos.net.device.PortDescription;
import org.onlab.onos.net.provider.ProviderId;
import org.onlab.onos.store.ClockService;
......@@ -113,8 +113,8 @@ public class GossipDeviceStoreTest {
deviceClockManager.activate();
clockService = deviceClockManager;
deviceClockManager.setMastershipTerm(DID1, DeviceMastershipTerm.of(MYSELF, 1));
deviceClockManager.setMastershipTerm(DID2, DeviceMastershipTerm.of(MYSELF, 2));
deviceClockManager.setMastershipTerm(DID1, MastershipTerm.of(MYSELF, 1));
deviceClockManager.setMastershipTerm(DID2, MastershipTerm.of(MYSELF, 2));
ClusterCommunicationService clusterCommunicator = new TestClusterCommunicationService();
ClusterService clusterService = new TestClusterService();
......
package org.onlab.onos.store.cluster.impl;
import static org.onlab.onos.net.device.DeviceMastershipEvent.Type.MASTER_CHANGED;
import static org.onlab.onos.cluster.MastershipEvent.Type.MASTER_CHANGED;
import java.util.Map;
import java.util.Set;
......@@ -12,13 +12,13 @@ import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.ReferenceCardinality;
import org.apache.felix.scr.annotations.Service;
import org.onlab.onos.cluster.ClusterService;
import org.onlab.onos.cluster.MastershipEvent;
import org.onlab.onos.cluster.MastershipStore;
import org.onlab.onos.cluster.MastershipStoreDelegate;
import org.onlab.onos.cluster.MastershipTerm;
import org.onlab.onos.cluster.NodeId;
import org.onlab.onos.net.DeviceId;
import org.onlab.onos.net.MastershipRole;
import org.onlab.onos.net.device.DeviceMastershipEvent;
import org.onlab.onos.net.device.DeviceMastershipStore;
import org.onlab.onos.net.device.DeviceMastershipStoreDelegate;
import org.onlab.onos.net.device.DeviceMastershipTerm;
import org.onlab.onos.store.common.AbstractHazelcastStore;
import com.google.common.collect.ImmutableSet;
......@@ -33,8 +33,8 @@ import com.hazelcast.core.MultiMap;
@Component(immediate = true)
@Service
public class DistributedMastershipStore
extends AbstractHazelcastStore<DeviceMastershipEvent, DeviceMastershipStoreDelegate>
implements DeviceMastershipStore {
extends AbstractHazelcastStore<MastershipEvent, MastershipStoreDelegate>
implements MastershipStore {
//arbitrary lock name
private static final String LOCK = "lock";
......@@ -100,7 +100,7 @@ implements DeviceMastershipStore {
}
@Override
public DeviceMastershipEvent setMaster(NodeId nodeId, DeviceId deviceId) {
public MastershipEvent setMaster(NodeId nodeId, DeviceId deviceId) {
byte [] did = serialize(deviceId);
byte [] nid = serialize(nodeId);
......@@ -123,12 +123,12 @@ implements DeviceMastershipStore {
masters.put(did, nid);
evict(nid, did);
updateTerm(did);
return new DeviceMastershipEvent(MASTER_CHANGED, deviceId, nodeId);
return new MastershipEvent(MASTER_CHANGED, deviceId, nodeId);
case NONE:
masters.put(did, nid);
evict(nid, did);
updateTerm(did);
return new DeviceMastershipEvent(MASTER_CHANGED, deviceId, nodeId);
return new MastershipEvent(MASTER_CHANGED, deviceId, nodeId);
default:
log.warn("unknown Mastership Role {}", role);
return null;
......@@ -191,21 +191,21 @@ implements DeviceMastershipStore {
}
@Override
public DeviceMastershipTerm getTermFor(DeviceId deviceId) {
public MastershipTerm getTermFor(DeviceId deviceId) {
byte[] did = serialize(deviceId);
if ((masters.get(did) == null) ||
(terms.get(did) == null)) {
return null;
}
return DeviceMastershipTerm.of(
return MastershipTerm.of(
(NodeId) deserialize(masters.get(did)), terms.get(did));
}
@Override
public DeviceMastershipEvent setStandby(NodeId nodeId, DeviceId deviceId) {
public MastershipEvent setStandby(NodeId nodeId, DeviceId deviceId) {
byte [] did = serialize(deviceId);
byte [] nid = serialize(nodeId);
DeviceMastershipEvent event = null;
MastershipEvent event = null;
ILock lock = theInstance.getLock(LOCK);
lock.lock();
......@@ -231,10 +231,10 @@ implements DeviceMastershipStore {
}
@Override
public DeviceMastershipEvent relinquishRole(NodeId nodeId, DeviceId deviceId) {
public MastershipEvent relinquishRole(NodeId nodeId, DeviceId deviceId) {
byte [] did = serialize(deviceId);
byte [] nid = serialize(nodeId);
DeviceMastershipEvent event = null;
MastershipEvent event = null;
ILock lock = theInstance.getLock(LOCK);
lock.lock();
......@@ -260,7 +260,7 @@ implements DeviceMastershipStore {
}
//helper to fetch a new master candidate for a given device.
private DeviceMastershipEvent reelect(NodeId current, DeviceId deviceId) {
private MastershipEvent reelect(NodeId current, DeviceId deviceId) {
byte [] did = serialize(deviceId);
byte [] nid = serialize(current);
......@@ -281,7 +281,7 @@ implements DeviceMastershipStore {
evict(backup, did);
Integer term = terms.get(did);
terms.put(did, ++term);
return new DeviceMastershipEvent(
return new MastershipEvent(
MASTER_CHANGED, deviceId, (NodeId) deserialize(backup));
}
}
......@@ -320,7 +320,7 @@ implements DeviceMastershipStore {
@Override
protected void onAdd(DeviceId deviceId, NodeId nodeId) {
notifyDelegate(new DeviceMastershipEvent(MASTER_CHANGED, deviceId, nodeId));
notifyDelegate(new MastershipEvent(MASTER_CHANGED, deviceId, nodeId));
}
@Override
......
......@@ -21,12 +21,12 @@ import org.onlab.onos.cluster.ClusterService;
import org.onlab.onos.cluster.ControllerNode;
import org.onlab.onos.cluster.ControllerNode.State;
import org.onlab.onos.cluster.DefaultControllerNode;
import org.onlab.onos.cluster.MastershipEvent;
import org.onlab.onos.cluster.MastershipEvent.Type;
import org.onlab.onos.cluster.MastershipStoreDelegate;
import org.onlab.onos.cluster.MastershipTerm;
import org.onlab.onos.cluster.NodeId;
import org.onlab.onos.net.DeviceId;
import org.onlab.onos.net.device.DeviceMastershipEvent;
import org.onlab.onos.net.device.DeviceMastershipStoreDelegate;
import org.onlab.onos.net.device.DeviceMastershipTerm;
import org.onlab.onos.net.device.DeviceMastershipEvent.Type;
import org.onlab.onos.store.common.StoreManager;
import org.onlab.onos.store.common.StoreService;
import org.onlab.onos.store.common.TestStoreManager;
......@@ -133,7 +133,7 @@ public class DistributedMastershipStoreTest {
assertEquals("wrong role for NONE:", MASTER, dms.requestRole(DID1));
assertTrue("wrong state for store:", !dms.terms.isEmpty());
assertEquals("wrong term",
DeviceMastershipTerm.of(N1, 0), dms.getTermFor(DID1));
MastershipTerm.of(N1, 0), dms.getTermFor(DID1));
//CN2 now local. DID2 has N1 as MASTER so N2 is STANDBY
testStore.setCurrent(CN2);
......@@ -143,7 +143,7 @@ public class DistributedMastershipStoreTest {
//change term and requestRole() again; should persist
testStore.increment(DID2);
assertEquals("wrong role for STANDBY:", STANDBY, dms.requestRole(DID2));
assertEquals("wrong term", DeviceMastershipTerm.of(N1, 1), dms.getTermFor(DID2));
assertEquals("wrong term", MastershipTerm.of(N1, 1), dms.getTermFor(DID2));
}
@Test
......@@ -155,15 +155,15 @@ public class DistributedMastershipStoreTest {
//switch over to N2
assertEquals("wrong event:", Type.MASTER_CHANGED, dms.setMaster(N2, DID1).type());
assertEquals("wrong term", DeviceMastershipTerm.of(N2, 1), dms.getTermFor(DID1));
assertEquals("wrong term", MastershipTerm.of(N2, 1), dms.getTermFor(DID1));
//orphan switch - should be rare case
assertEquals("wrong event:", Type.MASTER_CHANGED, dms.setMaster(N2, DID2).type());
assertEquals("wrong term", DeviceMastershipTerm.of(N2, 0), dms.getTermFor(DID2));
assertEquals("wrong term", MastershipTerm.of(N2, 0), dms.getTermFor(DID2));
//disconnect and reconnect - sign of failing re-election or single-instance channel
testStore.reset(true, false, false);
dms.setMaster(N2, DID2);
assertEquals("wrong term", DeviceMastershipTerm.of(N2, 1), dms.getTermFor(DID2));
assertEquals("wrong term", MastershipTerm.of(N2, 1), dms.getTermFor(DID2));
}
@Test
......@@ -211,9 +211,9 @@ public class DistributedMastershipStoreTest {
//shamelessly copy other distributed store tests
final CountDownLatch addLatch = new CountDownLatch(1);
DeviceMastershipStoreDelegate checkAdd = new DeviceMastershipStoreDelegate() {
MastershipStoreDelegate checkAdd = new MastershipStoreDelegate() {
@Override
public void notify(DeviceMastershipEvent event) {
public void notify(MastershipEvent event) {
assertEquals("wrong event:", Type.MASTER_CHANGED, event.type());
assertEquals("wrong subject", DID1, event.subject());
assertEquals("wrong subject", N1, event.master());
......
......@@ -2,8 +2,8 @@ package org.onlab.onos.store.device.impl;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Service;
import org.onlab.onos.cluster.MastershipTerm;
import org.onlab.onos.net.DeviceId;
import org.onlab.onos.net.device.DeviceMastershipTerm;
import org.onlab.onos.store.ClockProviderService;
// FIXME: Code clone in onos-core-trivial, onos-core-hz-net
......@@ -15,6 +15,6 @@ import org.onlab.onos.store.ClockProviderService;
public class NoOpClockProviderService implements ClockProviderService {
@Override
public void setMastershipTerm(DeviceId deviceId, DeviceMastershipTerm term) {
public void setMastershipTerm(DeviceId deviceId, MastershipTerm term) {
}
}
......
......@@ -7,6 +7,7 @@ import java.util.HashMap;
import org.onlab.onos.cluster.ControllerNode;
import org.onlab.onos.cluster.DefaultControllerNode;
import org.onlab.onos.cluster.MastershipTerm;
import org.onlab.onos.cluster.NodeId;
import org.onlab.onos.net.ConnectPoint;
import org.onlab.onos.net.DefaultAnnotations;
......@@ -23,7 +24,6 @@ import org.onlab.onos.net.Port;
import org.onlab.onos.net.PortNumber;
import org.onlab.onos.net.device.DefaultDeviceDescription;
import org.onlab.onos.net.device.DefaultPortDescription;
import org.onlab.onos.net.device.DeviceMastershipTerm;
import org.onlab.onos.net.provider.ProviderId;
import org.onlab.packet.IpAddress;
import org.onlab.packet.IpPrefix;
......@@ -74,7 +74,7 @@ public final class KryoPoolUtil {
.register(LinkKey.class, new LinkKeySerializer())
.register(ConnectPoint.class, new ConnectPointSerializer())
.register(DefaultLink.class, new DefaultLinkSerializer())
.register(DeviceMastershipTerm.class, new MastershipTermSerializer())
.register(MastershipTerm.class, new MastershipTermSerializer())
.register(MastershipRole.class, new MastershipRoleSerializer())
.build();
......
package org.onlab.onos.store.serializers;
import org.onlab.onos.cluster.MastershipTerm;
import org.onlab.onos.cluster.NodeId;
import org.onlab.onos.net.device.DeviceMastershipTerm;
import com.esotericsoftware.kryo.Kryo;
import com.esotericsoftware.kryo.Serializer;
import com.esotericsoftware.kryo.io.Input;
import com.esotericsoftware.kryo.io.Output;
/**
* Kryo Serializer for {@link org.onlab.onos.net.device.DeviceMastershipTerm}.
* Kryo Serializer for {@link org.onlab.onos.cluster.MastershipTerm}.
*/
public class MastershipTermSerializer extends Serializer<DeviceMastershipTerm> {
public class MastershipTermSerializer extends Serializer<MastershipTerm> {
/**
* Creates {@link DeviceMastershipTerm} serializer instance.
* Creates {@link MastershipTerm} serializer instance.
*/
public MastershipTermSerializer() {
// non-null, immutable
......@@ -22,14 +21,14 @@ public class MastershipTermSerializer extends Serializer<DeviceMastershipTerm> {
}
@Override
public DeviceMastershipTerm read(Kryo kryo, Input input, Class<DeviceMastershipTerm> type) {
public MastershipTerm read(Kryo kryo, Input input, Class<MastershipTerm> type) {
final NodeId node = new NodeId(input.readString());
final int term = input.readInt();
return DeviceMastershipTerm.of(node, term);
return MastershipTerm.of(node, term);
}
@Override
public void write(Kryo kryo, Output output, DeviceMastershipTerm object) {
public void write(Kryo kryo, Output output, MastershipTerm object) {
output.writeString(object.master().toString());
output.writeInt(object.termNumber());
}
......
......@@ -10,6 +10,7 @@ import org.junit.After;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.onlab.onos.cluster.MastershipTerm;
import org.onlab.onos.cluster.NodeId;
import org.onlab.onos.net.Annotations;
import org.onlab.onos.net.ConnectPoint;
......@@ -24,7 +25,6 @@ import org.onlab.onos.net.LinkKey;
import org.onlab.onos.net.MastershipRole;
import org.onlab.onos.net.PortNumber;
import org.onlab.onos.net.SparseAnnotations;
import org.onlab.onos.net.device.DeviceMastershipTerm;
import org.onlab.onos.net.provider.ProviderId;
import org.onlab.packet.IpAddress;
import org.onlab.packet.IpPrefix;
......@@ -114,7 +114,7 @@ public class KryoSerializerTest {
testSerialized(PID);
testSerialized(PIDA);
testSerialized(new NodeId("bar"));
testSerialized(DeviceMastershipTerm.of(new NodeId("foo"), 2));
testSerialized(MastershipTerm.of(new NodeId("foo"), 2));
for (MastershipRole role : MastershipRole.values()) {
testSerialized(role);
}
......
......@@ -2,8 +2,8 @@ package org.onlab.onos.store.trivial.impl;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Service;
import org.onlab.onos.cluster.MastershipTerm;
import org.onlab.onos.net.DeviceId;
import org.onlab.onos.net.device.DeviceMastershipTerm;
import org.onlab.onos.store.ClockProviderService;
//FIXME: Code clone in onos-core-trivial, onos-core-hz-net
......@@ -15,6 +15,6 @@ import org.onlab.onos.store.ClockProviderService;
public class NoOpClockProviderService implements ClockProviderService {
@Override
public void setMastershipTerm(DeviceId deviceId, DeviceMastershipTerm term) {
public void setMastershipTerm(DeviceId deviceId, MastershipTerm term) {
}
}
......
......@@ -15,18 +15,18 @@ import org.apache.felix.scr.annotations.Deactivate;
import org.apache.felix.scr.annotations.Service;
import org.onlab.onos.cluster.ControllerNode;
import org.onlab.onos.cluster.DefaultControllerNode;
import org.onlab.onos.cluster.MastershipEvent;
import org.onlab.onos.cluster.MastershipStore;
import org.onlab.onos.cluster.MastershipStoreDelegate;
import org.onlab.onos.cluster.MastershipTerm;
import org.onlab.onos.cluster.NodeId;
import org.onlab.onos.net.DeviceId;
import org.onlab.onos.net.MastershipRole;
import org.onlab.onos.net.device.DeviceMastershipEvent;
import org.onlab.onos.net.device.DeviceMastershipStore;
import org.onlab.onos.net.device.DeviceMastershipStoreDelegate;
import org.onlab.onos.net.device.DeviceMastershipTerm;
import org.onlab.onos.store.AbstractStore;
import org.onlab.packet.IpPrefix;
import org.slf4j.Logger;
import static org.onlab.onos.net.device.DeviceMastershipEvent.Type.*;
import static org.onlab.onos.cluster.MastershipEvent.Type.*;
/**
* Manages inventory of controller mastership over devices using
......@@ -35,8 +35,8 @@ import static org.onlab.onos.net.device.DeviceMastershipEvent.Type.*;
@Component(immediate = true)
@Service
public class SimpleMastershipStore
extends AbstractStore<DeviceMastershipEvent, DeviceMastershipStoreDelegate>
implements DeviceMastershipStore {
extends AbstractStore<MastershipEvent, MastershipStoreDelegate>
implements MastershipStore {
private final Logger log = getLogger(getClass());
......@@ -63,7 +63,7 @@ public class SimpleMastershipStore
}
@Override
public DeviceMastershipEvent setMaster(NodeId nodeId, DeviceId deviceId) {
public MastershipEvent setMaster(NodeId nodeId, DeviceId deviceId) {
MastershipRole role = getRole(nodeId, deviceId);
synchronized (this) {
......@@ -86,7 +86,7 @@ public class SimpleMastershipStore
}
}
return new DeviceMastershipEvent(MASTER_CHANGED, deviceId, nodeId);
return new MastershipEvent(MASTER_CHANGED, deviceId, nodeId);
}
@Override
......@@ -164,17 +164,17 @@ public class SimpleMastershipStore
}
@Override
public DeviceMastershipTerm getTermFor(DeviceId deviceId) {
public MastershipTerm getTermFor(DeviceId deviceId) {
if ((masterMap.get(deviceId) == null) ||
(termMap.get(deviceId) == null)) {
return null;
}
return DeviceMastershipTerm.of(
return MastershipTerm.of(
masterMap.get(deviceId), termMap.get(deviceId).get());
}
@Override
public DeviceMastershipEvent setStandby(NodeId nodeId, DeviceId deviceId) {
public MastershipEvent setStandby(NodeId nodeId, DeviceId deviceId) {
MastershipRole role = getRole(nodeId, deviceId);
synchronized (this) {
switch (role) {
......@@ -185,7 +185,7 @@ public class SimpleMastershipStore
} else {
masterMap.put(deviceId, backup);
termMap.get(deviceId).incrementAndGet();
return new DeviceMastershipEvent(MASTER_CHANGED, deviceId, backup);
return new MastershipEvent(MASTER_CHANGED, deviceId, backup);
}
case STANDBY:
case NONE:
......@@ -215,7 +215,7 @@ public class SimpleMastershipStore
}
@Override
public DeviceMastershipEvent relinquishRole(NodeId nodeId, DeviceId deviceId) {
public MastershipEvent relinquishRole(NodeId nodeId, DeviceId deviceId) {
return setStandby(nodeId, deviceId);
}
......
......@@ -6,9 +6,9 @@ import java.util.concurrent.atomic.AtomicInteger;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.onlab.onos.cluster.MastershipTerm;
import org.onlab.onos.cluster.NodeId;
import org.onlab.onos.net.DeviceId;
import org.onlab.onos.net.device.DeviceMastershipTerm;
import com.google.common.collect.Sets;
......@@ -16,7 +16,7 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.onlab.onos.net.MastershipRole.*;
import static org.onlab.onos.net.device.DeviceMastershipEvent.Type.*;
import static org.onlab.onos.cluster.MastershipEvent.Type.*;
/**
* Test for the simple MastershipStore implementation.
......@@ -98,12 +98,12 @@ public class SimpleMastershipStoreTest {
@Test
public void getTermFor() {
put(DID1, N1, true, true);
assertEquals("wrong term", DeviceMastershipTerm.of(N1, 0), sms.getTermFor(DID1));
assertEquals("wrong term", MastershipTerm.of(N1, 0), sms.getTermFor(DID1));
//switch to N2 and back - 2 term switches
sms.setMaster(N2, DID1);
sms.setMaster(N1, DID1);
assertEquals("wrong term", DeviceMastershipTerm.of(N1, 2), sms.getTermFor(DID1));
assertEquals("wrong term", MastershipTerm.of(N1, 2), sms.getTermFor(DID1));
}
@Test
......