Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 1 | /* |
| 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'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 16 | package org.onosproject.store.trivial.impl; |
tom | e472987 | 2014-09-23 00:37:37 -0700 | [diff] [blame] | 17 | |
| 18 | import com.google.common.collect.ImmutableSet; |
| 19 | import org.apache.felix.scr.annotations.Activate; |
| 20 | import org.apache.felix.scr.annotations.Component; |
| 21 | import org.apache.felix.scr.annotations.Deactivate; |
| 22 | import org.apache.felix.scr.annotations.Service; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 23 | import org.onosproject.cluster.ClusterEvent; |
| 24 | import org.onosproject.cluster.ClusterStore; |
| 25 | import org.onosproject.cluster.ClusterStoreDelegate; |
| 26 | import org.onosproject.cluster.ControllerNode; |
| 27 | import org.onosproject.cluster.DefaultControllerNode; |
| 28 | import org.onosproject.cluster.NodeId; |
Thomas Vachuska | 7648d66 | 2015-03-16 11:58:30 -0700 | [diff] [blame^] | 29 | import org.onosproject.net.intent.Key; |
| 30 | import org.onosproject.net.intent.PartitionService; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 31 | import org.onosproject.store.AbstractStore; |
Pavlin Radoslavov | 444b519 | 2014-10-28 10:45:19 -0700 | [diff] [blame] | 32 | import org.onlab.packet.IpAddress; |
tom | e472987 | 2014-09-23 00:37:37 -0700 | [diff] [blame] | 33 | import org.slf4j.Logger; |
| 34 | |
| 35 | import java.util.Set; |
| 36 | |
| 37 | import static org.slf4j.LoggerFactory.getLogger; |
| 38 | |
| 39 | /** |
tom | c749ae0 | 2014-09-29 13:53:51 -0700 | [diff] [blame] | 40 | * Manages inventory of infrastructure devices using trivial in-memory |
tom | e472987 | 2014-09-23 00:37:37 -0700 | [diff] [blame] | 41 | * structures implementation. |
| 42 | */ |
| 43 | @Component(immediate = true) |
| 44 | @Service |
tom | 0755a36 | 2014-09-24 11:54:43 -0700 | [diff] [blame] | 45 | public class SimpleClusterStore |
| 46 | extends AbstractStore<ClusterEvent, ClusterStoreDelegate> |
Thomas Vachuska | 7648d66 | 2015-03-16 11:58:30 -0700 | [diff] [blame^] | 47 | implements ClusterStore, PartitionService { |
tom | e472987 | 2014-09-23 00:37:37 -0700 | [diff] [blame] | 48 | |
Pavlin Radoslavov | 444b519 | 2014-10-28 10:45:19 -0700 | [diff] [blame] | 49 | public static final IpAddress LOCALHOST = IpAddress.valueOf("127.0.0.1"); |
tom | e472987 | 2014-09-23 00:37:37 -0700 | [diff] [blame] | 50 | |
| 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 | |
tom | b41d1ac | 2014-09-24 01:51:24 -0700 | [diff] [blame] | 87 | @Override |
Pavlin Radoslavov | 444b519 | 2014-10-28 10:45:19 -0700 | [diff] [blame] | 88 | public ControllerNode addNode(NodeId nodeId, IpAddress ip, int tcpPort) { |
tom | ee49c37 | 2014-09-26 15:14:50 -0700 | [diff] [blame] | 89 | return null; |
| 90 | } |
| 91 | |
| 92 | @Override |
tom | b41d1ac | 2014-09-24 01:51:24 -0700 | [diff] [blame] | 93 | public void removeNode(NodeId nodeId) { |
| 94 | } |
| 95 | |
Thomas Vachuska | 7648d66 | 2015-03-16 11:58:30 -0700 | [diff] [blame^] | 96 | @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 | } |
tom | e472987 | 2014-09-23 00:37:37 -0700 | [diff] [blame] | 105 | } |