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; |
| 29 | import org.onosproject.store.AbstractStore; |
Pavlin Radoslavov | 444b519 | 2014-10-28 10:45:19 -0700 | [diff] [blame] | 30 | import org.onlab.packet.IpAddress; |
tom | e472987 | 2014-09-23 00:37:37 -0700 | [diff] [blame] | 31 | import org.slf4j.Logger; |
| 32 | |
| 33 | import java.util.Set; |
| 34 | |
| 35 | import static org.slf4j.LoggerFactory.getLogger; |
| 36 | |
| 37 | /** |
tom | c749ae0 | 2014-09-29 13:53:51 -0700 | [diff] [blame] | 38 | * Manages inventory of infrastructure devices using trivial in-memory |
tom | e472987 | 2014-09-23 00:37:37 -0700 | [diff] [blame] | 39 | * structures implementation. |
| 40 | */ |
| 41 | @Component(immediate = true) |
| 42 | @Service |
tom | 0755a36 | 2014-09-24 11:54:43 -0700 | [diff] [blame] | 43 | public class SimpleClusterStore |
| 44 | extends AbstractStore<ClusterEvent, ClusterStoreDelegate> |
| 45 | implements ClusterStore { |
tom | e472987 | 2014-09-23 00:37:37 -0700 | [diff] [blame] | 46 | |
Pavlin Radoslavov | 444b519 | 2014-10-28 10:45:19 -0700 | [diff] [blame] | 47 | public static final IpAddress LOCALHOST = IpAddress.valueOf("127.0.0.1"); |
tom | e472987 | 2014-09-23 00:37:37 -0700 | [diff] [blame] | 48 | |
| 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 | |
tom | b41d1ac | 2014-09-24 01:51:24 -0700 | [diff] [blame] | 85 | @Override |
Pavlin Radoslavov | 444b519 | 2014-10-28 10:45:19 -0700 | [diff] [blame] | 86 | public ControllerNode addNode(NodeId nodeId, IpAddress ip, int tcpPort) { |
tom | ee49c37 | 2014-09-26 15:14:50 -0700 | [diff] [blame] | 87 | return null; |
| 88 | } |
| 89 | |
| 90 | @Override |
tom | b41d1ac | 2014-09-24 01:51:24 -0700 | [diff] [blame] | 91 | public void removeNode(NodeId nodeId) { |
| 92 | } |
| 93 | |
tom | e472987 | 2014-09-23 00:37:37 -0700 | [diff] [blame] | 94 | } |