blob: e0a4b9d71d2c06ce643ba06015ecd469d79ed66e [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 */
Brian O'Connorabafb502014-12-02 22:26:20 -080016package org.onosproject.store.trivial.impl;
tome4729872014-09-23 00:37:37 -070017
Thomas Vachuskade563cf2015-04-01 00:28:50 -070018import com.google.common.collect.ImmutableSet;
tome4729872014-09-23 00:37:37 -070019import 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;
Madan Jampani7d2fab22015-03-18 17:21:57 -070023import org.joda.time.DateTime;
24import org.onlab.packet.IpAddress;
Brian O'Connorabafb502014-12-02 22:26:20 -080025import org.onosproject.cluster.ClusterEvent;
26import org.onosproject.cluster.ClusterStore;
27import org.onosproject.cluster.ClusterStoreDelegate;
28import org.onosproject.cluster.ControllerNode;
29import org.onosproject.cluster.DefaultControllerNode;
30import org.onosproject.cluster.NodeId;
Thomas Vachuska7648d662015-03-16 11:58:30 -070031import org.onosproject.net.intent.Key;
32import org.onosproject.net.intent.PartitionService;
Brian O'Connorabafb502014-12-02 22:26:20 -080033import org.onosproject.store.AbstractStore;
tome4729872014-09-23 00:37:37 -070034import org.slf4j.Logger;
35
Thomas Vachuskade563cf2015-04-01 00:28:50 -070036import java.util.Set;
37
38import static org.slf4j.LoggerFactory.getLogger;
tome4729872014-09-23 00:37:37 -070039
40/**
tomc749ae02014-09-29 13:53:51 -070041 * Manages inventory of infrastructure devices using trivial in-memory
tome4729872014-09-23 00:37:37 -070042 * structures implementation.
43 */
44@Component(immediate = true)
45@Service
tom0755a362014-09-24 11:54:43 -070046public class SimpleClusterStore
47 extends AbstractStore<ClusterEvent, ClusterStoreDelegate>
Thomas Vachuska7648d662015-03-16 11:58:30 -070048 implements ClusterStore, PartitionService {
tome4729872014-09-23 00:37:37 -070049
Pavlin Radoslavov444b5192014-10-28 10:45:19 -070050 public static final IpAddress LOCALHOST = IpAddress.valueOf("127.0.0.1");
tome4729872014-09-23 00:37:37 -070051
52 private final Logger log = getLogger(getClass());
53
54 private ControllerNode instance;
55
Madan Jampani7d2fab22015-03-18 17:21:57 -070056 private final DateTime creationTime = DateTime.now();
57
tome4729872014-09-23 00:37:37 -070058 @Activate
59 public void activate() {
60 instance = new DefaultControllerNode(new NodeId("local"), LOCALHOST);
61 log.info("Started");
62 }
63
64 @Deactivate
65 public void deactivate() {
66 log.info("Stopped");
67 }
68
69
70 @Override
71 public ControllerNode getLocalNode() {
72 return instance;
73 }
74
75 @Override
76 public Set<ControllerNode> getNodes() {
77 return ImmutableSet.of(instance);
78 }
79
80 @Override
81 public ControllerNode getNode(NodeId nodeId) {
82 return instance.id().equals(nodeId) ? instance : null;
83 }
84
85 @Override
86 public ControllerNode.State getState(NodeId nodeId) {
87 return ControllerNode.State.ACTIVE;
88 }
89
tomb41d1ac2014-09-24 01:51:24 -070090 @Override
Madan Jampani7d2fab22015-03-18 17:21:57 -070091 public DateTime getLastUpdated(NodeId nodeId) {
92 return creationTime;
93 }
94
95 @Override
Thomas Vachuskade563cf2015-04-01 00:28:50 -070096 public void formCluster(Set<ControllerNode> nodes, String ipPrefix) {
97
98 }
99
100 @Override
Pavlin Radoslavov444b5192014-10-28 10:45:19 -0700101 public ControllerNode addNode(NodeId nodeId, IpAddress ip, int tcpPort) {
tomee49c372014-09-26 15:14:50 -0700102 return null;
103 }
104
105 @Override
tomb41d1ac2014-09-24 01:51:24 -0700106 public void removeNode(NodeId nodeId) {
107 }
108
Thomas Vachuska7648d662015-03-16 11:58:30 -0700109 @Override
110 public boolean isMine(Key intentKey) {
111 return true;
112 }
113
114 @Override
115 public NodeId getLeader(Key intentKey) {
116 return instance.id();
117 }
tome4729872014-09-23 00:37:37 -0700118}