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; |
tom | 0755a36 | 2014-09-24 11:54:43 -0700 | [diff] [blame] | 8 | import org.onlab.onos.cluster.ClusterEvent; |
tom | e472987 | 2014-09-23 00:37:37 -0700 | [diff] [blame] | 9 | import org.onlab.onos.cluster.ClusterStore; |
tom | 0755a36 | 2014-09-24 11:54:43 -0700 | [diff] [blame] | 10 | import org.onlab.onos.cluster.ClusterStoreDelegate; |
tom | e472987 | 2014-09-23 00:37:37 -0700 | [diff] [blame] | 11 | import org.onlab.onos.cluster.ControllerNode; |
| 12 | import org.onlab.onos.cluster.DefaultControllerNode; |
| 13 | import org.onlab.onos.cluster.NodeId; |
tom | 0755a36 | 2014-09-24 11:54:43 -0700 | [diff] [blame] | 14 | import org.onlab.onos.store.AbstractStore; |
tom | e472987 | 2014-09-23 00:37:37 -0700 | [diff] [blame] | 15 | import org.onlab.packet.IpPrefix; |
| 16 | import org.slf4j.Logger; |
| 17 | |
| 18 | import java.util.Set; |
| 19 | |
| 20 | import static org.slf4j.LoggerFactory.getLogger; |
| 21 | |
| 22 | /** |
tom | c749ae0 | 2014-09-29 13:53:51 -0700 | [diff] [blame] | 23 | * Manages inventory of infrastructure devices using trivial in-memory |
tom | e472987 | 2014-09-23 00:37:37 -0700 | [diff] [blame] | 24 | * structures implementation. |
| 25 | */ |
| 26 | @Component(immediate = true) |
| 27 | @Service |
tom | 0755a36 | 2014-09-24 11:54:43 -0700 | [diff] [blame] | 28 | public class SimpleClusterStore |
| 29 | extends AbstractStore<ClusterEvent, ClusterStoreDelegate> |
| 30 | implements ClusterStore { |
tom | e472987 | 2014-09-23 00:37:37 -0700 | [diff] [blame] | 31 | |
| 32 | public static final IpPrefix LOCALHOST = IpPrefix.valueOf("127.0.0.1"); |
| 33 | |
| 34 | private final Logger log = getLogger(getClass()); |
| 35 | |
| 36 | private ControllerNode instance; |
| 37 | |
| 38 | @Activate |
| 39 | public void activate() { |
| 40 | instance = new DefaultControllerNode(new NodeId("local"), LOCALHOST); |
| 41 | log.info("Started"); |
| 42 | } |
| 43 | |
| 44 | @Deactivate |
| 45 | public void deactivate() { |
| 46 | log.info("Stopped"); |
| 47 | } |
| 48 | |
| 49 | |
| 50 | @Override |
| 51 | public ControllerNode getLocalNode() { |
| 52 | return instance; |
| 53 | } |
| 54 | |
| 55 | @Override |
| 56 | public Set<ControllerNode> getNodes() { |
| 57 | return ImmutableSet.of(instance); |
| 58 | } |
| 59 | |
| 60 | @Override |
| 61 | public ControllerNode getNode(NodeId nodeId) { |
| 62 | return instance.id().equals(nodeId) ? instance : null; |
| 63 | } |
| 64 | |
| 65 | @Override |
| 66 | public ControllerNode.State getState(NodeId nodeId) { |
| 67 | return ControllerNode.State.ACTIVE; |
| 68 | } |
| 69 | |
tom | b41d1ac | 2014-09-24 01:51:24 -0700 | [diff] [blame] | 70 | @Override |
tom | ee49c37 | 2014-09-26 15:14:50 -0700 | [diff] [blame] | 71 | public ControllerNode addNode(NodeId nodeId, IpPrefix ip, int tcpPort) { |
| 72 | return null; |
| 73 | } |
| 74 | |
| 75 | @Override |
tom | b41d1ac | 2014-09-24 01:51:24 -0700 | [diff] [blame] | 76 | public void removeNode(NodeId nodeId) { |
| 77 | } |
| 78 | |
tom | e472987 | 2014-09-23 00:37:37 -0700 | [diff] [blame] | 79 | } |