tom | e472987 | 2014-09-23 00:37:37 -0700 | [diff] [blame] | 1 | package org.onlab.onos.net.trivial.impl; |
| 2 | |
| 3 | import com.google.common.collect.ImmutableSet; |
| 4 | import org.apache.felix.scr.annotations.Activate; |
| 5 | import org.apache.felix.scr.annotations.Component; |
| 6 | import org.apache.felix.scr.annotations.Deactivate; |
| 7 | import org.apache.felix.scr.annotations.Service; |
| 8 | import org.onlab.onos.cluster.ClusterStore; |
| 9 | import org.onlab.onos.cluster.ControllerNode; |
| 10 | import org.onlab.onos.cluster.DefaultControllerNode; |
| 11 | import org.onlab.onos.cluster.NodeId; |
| 12 | import org.onlab.packet.IpPrefix; |
| 13 | import org.slf4j.Logger; |
| 14 | |
| 15 | import java.util.Set; |
| 16 | |
| 17 | import static org.slf4j.LoggerFactory.getLogger; |
| 18 | |
| 19 | /** |
| 20 | * Manages inventory of infrastructure DEVICES using trivial in-memory |
| 21 | * structures implementation. |
| 22 | */ |
| 23 | @Component(immediate = true) |
| 24 | @Service |
| 25 | public class SimpleClusterStore implements ClusterStore { |
| 26 | |
| 27 | public static final IpPrefix LOCALHOST = IpPrefix.valueOf("127.0.0.1"); |
| 28 | |
| 29 | private final Logger log = getLogger(getClass()); |
| 30 | |
| 31 | private ControllerNode instance; |
| 32 | |
| 33 | @Activate |
| 34 | public void activate() { |
| 35 | instance = new DefaultControllerNode(new NodeId("local"), LOCALHOST); |
| 36 | log.info("Started"); |
| 37 | } |
| 38 | |
| 39 | @Deactivate |
| 40 | public void deactivate() { |
| 41 | log.info("Stopped"); |
| 42 | } |
| 43 | |
| 44 | |
| 45 | @Override |
| 46 | public ControllerNode getLocalNode() { |
| 47 | return instance; |
| 48 | } |
| 49 | |
| 50 | @Override |
| 51 | public Set<ControllerNode> getNodes() { |
| 52 | return ImmutableSet.of(instance); |
| 53 | } |
| 54 | |
| 55 | @Override |
| 56 | public ControllerNode getNode(NodeId nodeId) { |
| 57 | return instance.id().equals(nodeId) ? instance : null; |
| 58 | } |
| 59 | |
| 60 | @Override |
| 61 | public ControllerNode.State getState(NodeId nodeId) { |
| 62 | return ControllerNode.State.ACTIVE; |
| 63 | } |
| 64 | |
tom | b41d1ac | 2014-09-24 01:51:24 -0700 | [diff] [blame^] | 65 | @Override |
| 66 | public void removeNode(NodeId nodeId) { |
| 67 | } |
| 68 | |
tom | e472987 | 2014-09-23 00:37:37 -0700 | [diff] [blame] | 69 | } |