blob: 447defb3b519d1a562038a38e5dbbbed64f86f69 [file] [log] [blame]
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07001/*
2 * Copyright 2014 Open Networking Laboratory
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
tomea961ff2014-10-01 12:45:15 -070016package org.onlab.onos.store.trivial.impl;
tome4729872014-09-23 00:37:37 -070017
18import com.google.common.collect.ImmutableSet;
19import org.apache.felix.scr.annotations.Activate;
20import org.apache.felix.scr.annotations.Component;
21import org.apache.felix.scr.annotations.Deactivate;
22import org.apache.felix.scr.annotations.Service;
tom0755a362014-09-24 11:54:43 -070023import org.onlab.onos.cluster.ClusterEvent;
tome4729872014-09-23 00:37:37 -070024import org.onlab.onos.cluster.ClusterStore;
tom0755a362014-09-24 11:54:43 -070025import org.onlab.onos.cluster.ClusterStoreDelegate;
tome4729872014-09-23 00:37:37 -070026import org.onlab.onos.cluster.ControllerNode;
27import org.onlab.onos.cluster.DefaultControllerNode;
28import org.onlab.onos.cluster.NodeId;
tom0755a362014-09-24 11:54:43 -070029import org.onlab.onos.store.AbstractStore;
Pavlin Radoslavov444b5192014-10-28 10:45:19 -070030import org.onlab.packet.IpAddress;
tome4729872014-09-23 00:37:37 -070031import org.slf4j.Logger;
32
33import java.util.Set;
34
35import static org.slf4j.LoggerFactory.getLogger;
36
37/**
tomc749ae02014-09-29 13:53:51 -070038 * Manages inventory of infrastructure devices using trivial in-memory
tome4729872014-09-23 00:37:37 -070039 * structures implementation.
40 */
41@Component(immediate = true)
42@Service
tom0755a362014-09-24 11:54:43 -070043public class SimpleClusterStore
44 extends AbstractStore<ClusterEvent, ClusterStoreDelegate>
45 implements ClusterStore {
tome4729872014-09-23 00:37:37 -070046
Pavlin Radoslavov444b5192014-10-28 10:45:19 -070047 public static final IpAddress LOCALHOST = IpAddress.valueOf("127.0.0.1");
tome4729872014-09-23 00:37:37 -070048
49 private final Logger log = getLogger(getClass());
50
51 private ControllerNode instance;
52
53 @Activate
54 public void activate() {
55 instance = new DefaultControllerNode(new NodeId("local"), LOCALHOST);
56 log.info("Started");
57 }
58
59 @Deactivate
60 public void deactivate() {
61 log.info("Stopped");
62 }
63
64
65 @Override
66 public ControllerNode getLocalNode() {
67 return instance;
68 }
69
70 @Override
71 public Set<ControllerNode> getNodes() {
72 return ImmutableSet.of(instance);
73 }
74
75 @Override
76 public ControllerNode getNode(NodeId nodeId) {
77 return instance.id().equals(nodeId) ? instance : null;
78 }
79
80 @Override
81 public ControllerNode.State getState(NodeId nodeId) {
82 return ControllerNode.State.ACTIVE;
83 }
84
tomb41d1ac2014-09-24 01:51:24 -070085 @Override
Pavlin Radoslavov444b5192014-10-28 10:45:19 -070086 public ControllerNode addNode(NodeId nodeId, IpAddress ip, int tcpPort) {
tomee49c372014-09-26 15:14:50 -070087 return null;
88 }
89
90 @Override
tomb41d1ac2014-09-24 01:51:24 -070091 public void removeNode(NodeId nodeId) {
92 }
93
tome4729872014-09-23 00:37:37 -070094}