tom

Renamed *Instance to *Node for better readability and to avoid conflict with not…

…ion of Karaf instance.
Added cluster service and trivial store implementations.
Showing 24 changed files with 369 additions and 51 deletions
package org.onlab.onos.cli;
import org.apache.karaf.shell.commands.Command;
import org.onlab.onos.cluster.ClusterService;
import org.onlab.onos.cluster.ControllerNode;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import static com.google.common.collect.Lists.newArrayList;
/**
* Lists all controller cluster nodes.
*/
@Command(scope = "onos", name = "nodes",
description = "Lists all controller cluster nodes")
public class NodesListCommand extends AbstractShellCommand {
private static final String FMT =
"id=%s, ip=%s, state=%s %s";
protected static final Comparator<ControllerNode> ID_COMPARATOR =
new Comparator<ControllerNode>() {
@Override
public int compare(ControllerNode ci1, ControllerNode ci2) {
return ci1.id().toString().compareTo(ci2.id().toString());
}
};
@Override
protected Object doExecute() throws Exception {
ClusterService service = getService(ClusterService.class);
List<ControllerNode> nodes = newArrayList(service.getNodes());
Collections.sort(nodes, ID_COMPARATOR);
ControllerNode self = service.getLocalNode();
for (ControllerNode node : nodes) {
print(FMT, node.id(), node.ip(),
service.getState(node.id()),
node.equals(self) ? "*" : "");
}
return null;
}
}
......@@ -2,6 +2,9 @@
<command-bundle xmlns="http://karaf.apache.org/xmlns/shell/v1.1.0">
<command>
<action class="org.onlab.onos.cli.NodesListCommand"/>
</command>
<command>
<action class="org.onlab.onos.cli.net.FlowsListCommand"/>
</command>
<command>
......
......@@ -5,7 +5,7 @@ import org.onlab.onos.event.AbstractEvent;
/**
* Describes cluster-related event.
*/
public class ClusterEvent extends AbstractEvent<ClusterEvent.Type, ControllerInstance> {
public class ClusterEvent extends AbstractEvent<ClusterEvent.Type, ControllerNode> {
/**
* Type of cluster-related events.
......@@ -39,7 +39,7 @@ public class ClusterEvent extends AbstractEvent<ClusterEvent.Type, ControllerIns
* @param type cluster event type
* @param instance cluster device subject
*/
public ClusterEvent(Type type, ControllerInstance instance) {
public ClusterEvent(Type type, ControllerNode instance) {
super(type, instance);
}
......@@ -50,7 +50,7 @@ public class ClusterEvent extends AbstractEvent<ClusterEvent.Type, ControllerIns
* @param instance event device subject
* @param time occurrence time
*/
public ClusterEvent(Type type, ControllerInstance instance, long time) {
public ClusterEvent(Type type, ControllerNode instance, long time) {
super(type, instance, time);
}
......
......@@ -3,24 +3,40 @@ package org.onlab.onos.cluster;
import java.util.Set;
/**
* Service for obtaining information about the individual instances within
* Service for obtaining information about the individual nodes within
* the controller cluster.
*/
public interface ClusterService {
/**
* Returns the local controller node.
*
* @return local controller node
*/
ControllerNode getLocalNode();
/**
* Returns the set of current cluster members.
*
* @return set of cluster members
*/
Set<ControllerInstance> getInstances();
Set<ControllerNode> getNodes();
/**
* Returns the specified controller node.
*
* @param nodeId controller node identifier
* @return controller node
*/
ControllerNode getNode(NodeId nodeId);
/**
* Returns the availability state of the specified controller instance.
* Returns the availability state of the specified controller node.
*
* @param nodeId controller node identifier
* @return availability state
*/
ControllerInstance.State getState(ControllerInstance instance);
ControllerNode.State getState(NodeId nodeId);
/**
* Adds the specified cluster event listener.
......
package org.onlab.onos.cluster;
import java.util.Set;
/**
* Manages inventory of controller cluster nodes; not intended for direct use.
*/
public interface ClusterStore {
/**
* Returns the local controller instance.
*
* @return local controller instance
*/
ControllerNode getLocalNode();
/**
* Returns the set of current cluster members.
*
* @return set of cluster members
*/
Set<ControllerNode> getNodes();
/**
* Returns the specified controller instance.
*
* @param nodeId controller instance identifier
* @return controller instance
*/
ControllerNode getNode(NodeId nodeId);
/**
* Returns the availability state of the specified controller instance.
*
* @param nodeId controller instance identifier
* @return availability state
*/
ControllerNode.State getState(NodeId nodeId);
}
......@@ -5,7 +5,7 @@ import org.onlab.packet.IpPrefix;
/**
* Represents a controller instance as a member in a cluster.
*/
public interface ControllerInstance {
public interface ControllerNode {
/** Represents the operational state of the instance. */
public enum State {
......@@ -26,7 +26,7 @@ public interface ControllerInstance {
*
* @return instance identifier
*/
InstanceId id();
NodeId id();
/**
* Returns the IP address of the controller instance.
......
package org.onlab.onos.cluster;
import org.onlab.packet.IpPrefix;
import java.util.Objects;
import static com.google.common.base.MoreObjects.toStringHelper;
/**
* Default implementation of a controller instance descriptor.
*/
public class DefaultControllerNode implements ControllerNode {
private final NodeId id;
private final IpPrefix ip;
/**
* Creates a new instance with the specified id and IP address.
*
* @param id instance identifier
* @param ip instance IP address
*/
public DefaultControllerNode(NodeId id, IpPrefix ip) {
this.id = id;
this.ip = ip;
}
@Override
public NodeId id() {
return id;
}
@Override
public IpPrefix ip() {
return ip;
}
@Override
public int hashCode() {
return Objects.hash(id);
}
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o instanceof DefaultControllerNode) {
DefaultControllerNode that = (DefaultControllerNode) o;
return Objects.equals(this.id, that.id);
}
return false;
}
@Override
public String toString() {
return toStringHelper(this).add("id", id).add("ip", ip).toString();
}
}
......@@ -15,6 +15,6 @@ public interface MastershipAdminService {
* @param deviceId device identifier
* @param role requested role
*/
void setRole(InstanceId instance, DeviceId deviceId, MastershipRole role);
void setRole(NodeId instance, DeviceId deviceId, MastershipRole role);
}
......
......@@ -8,7 +8,7 @@ import org.onlab.onos.net.DeviceId;
*/
public class MastershipEvent extends AbstractEvent<MastershipEvent.Type, DeviceId> {
InstanceId master;
NodeId master;
/**
* Type of mastership events.
......@@ -28,7 +28,7 @@ public class MastershipEvent extends AbstractEvent<MastershipEvent.Type, DeviceI
* @param device event device subject
* @param master master ID subject
*/
protected MastershipEvent(Type type, DeviceId device, InstanceId master) {
protected MastershipEvent(Type type, DeviceId device, NodeId master) {
super(type, device);
this.master = master;
}
......@@ -42,7 +42,7 @@ public class MastershipEvent extends AbstractEvent<MastershipEvent.Type, DeviceI
* @param master master ID subject
* @param time occurrence time
*/
protected MastershipEvent(Type type, DeviceId device, InstanceId master, long time) {
protected MastershipEvent(Type type, DeviceId device, NodeId master, long time) {
super(type, device, time);
this.master = master;
}
......@@ -52,7 +52,7 @@ public class MastershipEvent extends AbstractEvent<MastershipEvent.Type, DeviceI
*
* @return master ID subject
*/
public InstanceId master() {
public NodeId master() {
return master;
}
}
......
......@@ -19,15 +19,15 @@ public interface MastershipService {
* @param deviceId the identifier of the device
* @return the ID of the master controller for the device
*/
InstanceId getMasterFor(DeviceId deviceId);
NodeId getMasterFor(DeviceId deviceId);
/**
* Returns the devices for which a controller is master.
*
* @param instanceId the ID of the controller
* @param nodeId the ID of the controller
* @return a set of device IDs
*/
Set<DeviceId> getDevicesOf(InstanceId instanceId);
Set<DeviceId> getDevicesOf(NodeId nodeId);
/**
* Returns the mastership status of this controller for a given device.
......
......@@ -6,11 +6,12 @@ import org.onlab.onos.net.DeviceId;
import org.onlab.onos.net.MastershipRole;
/**
* Manages inventory of mastership roles for devices, across controller instances.
* Manages inventory of mastership roles for devices, across controller
* instances; not intended for direct use.
*/
public interface MastershipStore {
// three things to map: InstanceId, DeviceId, MastershipRole
// three things to map: NodeId, DeviceId, MastershipRole
/**
* Sets a device's role for a specified controller instance.
......@@ -20,7 +21,7 @@ public interface MastershipStore {
* @param role new role
* @return a mastership event
*/
MastershipEvent setRole(InstanceId instance, DeviceId deviceId,
MastershipEvent setRole(NodeId instance, DeviceId deviceId,
MastershipRole role);
/**
......@@ -31,7 +32,7 @@ public interface MastershipStore {
* @param role new role
* @return a mastership event
*/
MastershipEvent addOrUpdateDevice(InstanceId instance, DeviceId deviceId,
MastershipEvent addOrUpdateDevice(NodeId instance, DeviceId deviceId,
MastershipRole role);
/**
......@@ -40,22 +41,22 @@ public interface MastershipStore {
* @param deviceId the device identifier
* @return the instance identifier of the master
*/
InstanceId getMaster(DeviceId deviceId);
NodeId getMaster(DeviceId deviceId);
/**
* Returns the devices that a controller instance is master of.
*
* @param instanceId the instance identifier
* @param nodeId the instance identifier
* @return a set of device identifiers
*/
Set<DeviceId> getDevices(InstanceId instanceId);
Set<DeviceId> getDevices(NodeId nodeId);
/**
* Returns the role of a device for a specific controller instance.
*
* @param instanceId the instance identifier
* @param nodeId the instance identifier
* @param deviceId the device identifiers
* @return the role
*/
MastershipRole getRole(InstanceId instanceId, DeviceId deviceId);
MastershipRole getRole(NodeId nodeId, DeviceId deviceId);
}
......
......@@ -2,26 +2,24 @@ package org.onlab.onos.cluster;
import java.util.Objects;
import static com.google.common.base.MoreObjects.toStringHelper;
/**
* Controller cluster identity.
*/
public class InstanceId {
public class NodeId {
private final String id;
// Default constructor for serialization
protected InstanceId() {
protected NodeId() {
id = null;
}
/**
* Creates a new cluster instance identifier from the specified string.
* Creates a new cluster node identifier from the specified string.
*
* @param id string identifier
*/
public InstanceId(String id) {
public NodeId(String id) {
this.id = id;
}
......@@ -35,8 +33,8 @@ public class InstanceId {
if (this == obj) {
return true;
}
if (obj instanceof InstanceId) {
final InstanceId other = (InstanceId) obj;
if (obj instanceof NodeId) {
final NodeId other = (NodeId) obj;
return Objects.equals(this.id, other.id);
}
return false;
......@@ -44,7 +42,7 @@ public class InstanceId {
@Override
public String toString() {
return toStringHelper(this).add("id", id).toString();
return id;
}
}
......
......@@ -10,7 +10,7 @@ import org.onlab.onos.net.provider.ProviderId;
import java.util.List;
/**
* Manages inventory of infrastructure devices.
* Manages inventory of infrastructure devices; not intended for direct use.
*/
public interface DeviceStore {
......
......@@ -3,7 +3,7 @@ package org.onlab.onos.net.flow;
import org.onlab.onos.net.DeviceId;
/**
* Manages inventory of flow rules.
* Manages inventory of flow rules; not intended for direct use.
*/
public interface FlowRuleStore {
......
......@@ -12,8 +12,7 @@ import org.onlab.packet.VlanId;
import java.util.Set;
/**
* Manages inventory of end-station hosts. It may do so using whatever
* means are appropriate.
* Manages inventory of end-station hosts; not intended for direct use.
*/
public interface HostStore {
......
......@@ -8,8 +8,7 @@ import org.onlab.onos.net.provider.ProviderId;
import java.util.Set;
/**
* Manages inventory of infrastructure links. It may do so using whatever
* means are appropriate.
* Manages inventory of infrastructure links; not intended for direct use.
*/
public interface LinkStore {
......
......@@ -11,8 +11,7 @@ import java.util.List;
import java.util.Set;
/**
* Manages inventory of topology snapshots. It may do so using whatever
* means appropriate.
* Manages inventory of topology snapshots; not intended for direct use.
*/
public interface TopologyStore {
......
package org.onlab.onos.cluster.impl;
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.Reference;
import org.apache.felix.scr.annotations.ReferenceCardinality;
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.ClusterStore;
import org.onlab.onos.cluster.ControllerNode;
import org.onlab.onos.cluster.NodeId;
import org.onlab.onos.event.AbstractListenerRegistry;
import org.onlab.onos.event.EventDeliveryService;
import org.slf4j.Logger;
import java.util.Set;
import static com.google.common.base.Preconditions.checkNotNull;
import static org.slf4j.LoggerFactory.getLogger;
/**
* Implementation of the cluster service.
*/
@Component(immediate = true)
@Service
public class ClusterManager implements ClusterService {
public static final String INSTANCE_ID_NULL = "Instance ID cannot be null";
private final Logger log = getLogger(getClass());
protected final AbstractListenerRegistry<ClusterEvent, ClusterEventListener>
listenerRegistry = new AbstractListenerRegistry<>();
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
protected ClusterStore store;
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
protected EventDeliveryService eventDispatcher;
@Activate
public void activate() {
eventDispatcher.addSink(ClusterEvent.class, listenerRegistry);
log.info("Started");
}
@Deactivate
public void deactivate() {
eventDispatcher.removeSink(ClusterEvent.class);
log.info("Stopped");
}
@Override
public ControllerNode getLocalNode() {
return store.getLocalNode();
}
@Override
public Set<ControllerNode> getNodes() {
return store.getNodes();
}
@Override
public ControllerNode getNode(NodeId nodeId) {
checkNotNull(nodeId, INSTANCE_ID_NULL);
return store.getNode(nodeId);
}
@Override
public ControllerNode.State getState(NodeId nodeId) {
checkNotNull(nodeId, INSTANCE_ID_NULL);
return store.getState(nodeId);
}
@Override
public void addListener(ClusterEventListener listener) {
listenerRegistry.addListener(listener);
}
@Override
public void removeListener(ClusterEventListener listener) {
listenerRegistry.removeListener(listener);
}
}
......@@ -33,7 +33,7 @@ import static com.google.common.base.Preconditions.checkNotNull;
import static org.slf4j.LoggerFactory.getLogger;
/**
* Provides basic implementation of the device SB &amp; NB APIs.
* Provides implementation of the device SB &amp; NB APIs.
*/
@Component(immediate = true)
@Service
......
......@@ -33,6 +33,9 @@ import org.slf4j.Logger;
import com.google.common.collect.Lists;
/**
* Provides implementation of the flow NB &amp; SB APIs.
*/
@Component(immediate = true)
@Service
public class FlowRuleManager
......
package org.onlab.onos.net.trivial.impl;
import com.google.common.collect.ImmutableSet;
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.ClusterStore;
import org.onlab.onos.cluster.ControllerNode;
import org.onlab.onos.cluster.DefaultControllerNode;
import org.onlab.onos.cluster.NodeId;
import org.onlab.packet.IpPrefix;
import org.slf4j.Logger;
import java.util.Set;
import static org.slf4j.LoggerFactory.getLogger;
/**
* Manages inventory of infrastructure DEVICES using trivial in-memory
* structures implementation.
*/
@Component(immediate = true)
@Service
public class SimpleClusterStore implements ClusterStore {
public static final IpPrefix LOCALHOST = IpPrefix.valueOf("127.0.0.1");
private final Logger log = getLogger(getClass());
private ControllerNode instance;
@Activate
public void activate() {
instance = new DefaultControllerNode(new NodeId("local"), LOCALHOST);
log.info("Started");
}
@Deactivate
public void deactivate() {
log.info("Stopped");
}
@Override
public ControllerNode getLocalNode() {
return instance;
}
@Override
public Set<ControllerNode> getNodes() {
return ImmutableSet.of(instance);
}
@Override
public ControllerNode getNode(NodeId nodeId) {
return instance.id().equals(nodeId) ? instance : null;
}
@Override
public ControllerNode.State getState(NodeId nodeId) {
return ControllerNode.State.ACTIVE;
}
}
......@@ -35,7 +35,7 @@ import static org.onlab.onos.net.device.DeviceEvent.Type.*;
import static org.slf4j.LoggerFactory.getLogger;
/**
* Manages inventory of infrastructure DEVICES using trivial in-memory
* Manages inventory of infrastructure devices using trivial in-memory
* structures implementation.
*/
@Component(immediate = true)
......
......@@ -392,7 +392,7 @@
<group>
<title>Core Subsystems</title>
<packages>
org.onlab.onos.net.device.impl:org.onlab.onos.net.link.impl:org.onlab.onos.net.host.impl:org.onlab.onos.net.topology.impl:org.onlab.onos.net.packet.impl:org.onlab.onos.net.flow.impl:org.onlab.onos.net.trivial.*:org.onlab.onos.net.*.impl:org.onlab.onos.impl:org.onlab.onos.event.impl:org.onlab.onos.store.*
org.onlab.onos.net.device.impl:org.onlab.onos.net.link.impl:org.onlab.onos.net.host.impl:org.onlab.onos.net.topology.impl:org.onlab.onos.net.packet.impl:org.onlab.onos.net.flow.impl:org.onlab.onos.net.trivial.*:org.onlab.onos.net.*.impl:org.onlab.onos.cluster:org.onlab.onos.event.impl:org.onlab.onos.store.*
</packages>
</group>
<group>
......
......@@ -34,15 +34,15 @@ cp -r $ONOS_ROOT/tools/package/etc/* $KARAF_DIST/etc
mkdir -p $KARAF_DIST/system/org/onlab
cp -r $M2_REPO/org/onlab $KARAF_DIST/system/org/
# Wrapper & Cellar Patching ----------------------------------------------------
# Cellar Patching --------------------------------------------------------------
# Patch the Apache Karaf distribution file to add Cellar features repository
perl -pi.old -e "s|^(featuresRepositories=.*)|\1,mvn:org.apache.karaf.cellar/apache-karaf-cellar/3.0.0/xml/features|" \
$ONOS_STAGE/$KARAF_DIST/etc/org.apache.karaf.features.cfg
#perl -pi.old -e "s|^(featuresRepositories=.*)|\1,mvn:org.apache.karaf.cellar/apache-karaf-cellar/3.0.0/xml/features|" \
# $ONOS_STAGE/$KARAF_DIST/etc/org.apache.karaf.features.cfg
# Patch the Apache Karaf distribution file to load ONOS features
perl -pi.old -e 's|^(featuresBoot=.*)|\1,cellar|' \
$ONOS_STAGE/$KARAF_DIST/etc/org.apache.karaf.features.cfg
#perl -pi.old -e 's|^(featuresBoot=.*)|\1,cellar|' \
# $ONOS_STAGE/$KARAF_DIST/etc/org.apache.karaf.features.cfg
# ONOS Patching ----------------------------------------------------------------
......@@ -50,6 +50,10 @@ perl -pi.old -e 's|^(featuresBoot=.*)|\1,cellar|' \
perl -pi.old -e "s|^(featuresRepositories=.*)|\1,mvn:org.onlab.onos/onos-features/$ONOS_VERSION/xml/features|" \
$ONOS_STAGE/$KARAF_DIST/etc/org.apache.karaf.features.cfg
# Patch the Apache Karaf distribution file to load ONOS features
perl -pi.old -e 's|^(featuresBoot=.*)|\1,onos-api,onos-core,onos-cli,onos-rest,onos-gui,onos-openflow,onos-app-tvue,onos-app-fwd|' \
$ONOS_STAGE/$KARAF_DIST/etc/org.apache.karaf.features.cfg
# Patch the Apache Karaf distribution with ONOS branding bundle
cp $M2_REPO/org/onlab/onos/onos-branding/$ONOS_VERSION/onos-branding-*.jar \
$ONOS_STAGE/$KARAF_DIST/lib
......