blob: 20ede866d462c210e3aa6e632227e031635028ff [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
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;
Brian O'Connorabafb502014-12-02 22:26:20 -080023import org.onosproject.cluster.ClusterEvent;
24import org.onosproject.cluster.ClusterStore;
25import org.onosproject.cluster.ClusterStoreDelegate;
26import org.onosproject.cluster.ControllerNode;
27import org.onosproject.cluster.DefaultControllerNode;
28import org.onosproject.cluster.NodeId;
Thomas Vachuska7648d662015-03-16 11:58:30 -070029import org.onosproject.net.intent.Key;
30import org.onosproject.net.intent.PartitionService;
Brian O'Connorabafb502014-12-02 22:26:20 -080031import org.onosproject.store.AbstractStore;
Pavlin Radoslavov444b5192014-10-28 10:45:19 -070032import org.onlab.packet.IpAddress;
tome4729872014-09-23 00:37:37 -070033import org.slf4j.Logger;
34
35import java.util.Set;
36
37import static org.slf4j.LoggerFactory.getLogger;
38
39/**
tomc749ae02014-09-29 13:53:51 -070040 * Manages inventory of infrastructure devices using trivial in-memory
tome4729872014-09-23 00:37:37 -070041 * structures implementation.
42 */
43@Component(immediate = true)
44@Service
tom0755a362014-09-24 11:54:43 -070045public class SimpleClusterStore
46 extends AbstractStore<ClusterEvent, ClusterStoreDelegate>
Thomas Vachuska7648d662015-03-16 11:58:30 -070047 implements ClusterStore, PartitionService {
tome4729872014-09-23 00:37:37 -070048
Pavlin Radoslavov444b5192014-10-28 10:45:19 -070049 public static final IpAddress LOCALHOST = IpAddress.valueOf("127.0.0.1");
tome4729872014-09-23 00:37:37 -070050
51 private final Logger log = getLogger(getClass());
52
53 private ControllerNode instance;
54
55 @Activate
56 public void activate() {
57 instance = new DefaultControllerNode(new NodeId("local"), LOCALHOST);
58 log.info("Started");
59 }
60
61 @Deactivate
62 public void deactivate() {
63 log.info("Stopped");
64 }
65
66
67 @Override
68 public ControllerNode getLocalNode() {
69 return instance;
70 }
71
72 @Override
73 public Set<ControllerNode> getNodes() {
74 return ImmutableSet.of(instance);
75 }
76
77 @Override
78 public ControllerNode getNode(NodeId nodeId) {
79 return instance.id().equals(nodeId) ? instance : null;
80 }
81
82 @Override
83 public ControllerNode.State getState(NodeId nodeId) {
84 return ControllerNode.State.ACTIVE;
85 }
86
tomb41d1ac2014-09-24 01:51:24 -070087 @Override
Pavlin Radoslavov444b5192014-10-28 10:45:19 -070088 public ControllerNode addNode(NodeId nodeId, IpAddress ip, int tcpPort) {
tomee49c372014-09-26 15:14:50 -070089 return null;
90 }
91
92 @Override
tomb41d1ac2014-09-24 01:51:24 -070093 public void removeNode(NodeId nodeId) {
94 }
95
Thomas Vachuska7648d662015-03-16 11:58:30 -070096 @Override
97 public boolean isMine(Key intentKey) {
98 return true;
99 }
100
101 @Override
102 public NodeId getLeader(Key intentKey) {
103 return instance.id();
104 }
tome4729872014-09-23 00:37:37 -0700105}