Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2014-present Open Networking Foundation |
Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 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.cluster; |
tom | e472987 | 2014-09-23 00:37:37 -0700 | [diff] [blame] | 17 | |
Madan Jampani | 7d2fab2 | 2015-03-18 17:21:57 -0700 | [diff] [blame] | 18 | import org.joda.time.DateTime; |
| 19 | import org.onlab.packet.IpAddress; |
Jordan Halterman | f70bf46 | 2017-07-29 13:12:00 -0700 | [diff] [blame] | 20 | import org.onosproject.core.Version; |
Madan Jampani | 7d2fab2 | 2015-03-18 17:21:57 -0700 | [diff] [blame] | 21 | import org.onosproject.store.Store; |
| 22 | |
Yuta HIGUCHI | 0c47d53 | 2017-08-18 23:16:35 -0700 | [diff] [blame] | 23 | import java.time.Instant; |
| 24 | import java.util.Optional; |
Thomas Vachuska | de563cf | 2015-04-01 00:28:50 -0700 | [diff] [blame] | 25 | import java.util.Set; |
| 26 | |
tom | e472987 | 2014-09-23 00:37:37 -0700 | [diff] [blame] | 27 | /** |
| 28 | * Manages inventory of controller cluster nodes; not intended for direct use. |
| 29 | */ |
tom | 0755a36 | 2014-09-24 11:54:43 -0700 | [diff] [blame] | 30 | public interface ClusterStore extends Store<ClusterEvent, ClusterStoreDelegate> { |
tom | e472987 | 2014-09-23 00:37:37 -0700 | [diff] [blame] | 31 | |
| 32 | /** |
tom | b41d1ac | 2014-09-24 01:51:24 -0700 | [diff] [blame] | 33 | * Returns the local controller node. |
tom | e472987 | 2014-09-23 00:37:37 -0700 | [diff] [blame] | 34 | * |
| 35 | * @return local controller instance |
| 36 | */ |
| 37 | ControllerNode getLocalNode(); |
| 38 | |
| 39 | /** |
| 40 | * Returns the set of current cluster members. |
| 41 | * |
| 42 | * @return set of cluster members |
| 43 | */ |
| 44 | Set<ControllerNode> getNodes(); |
| 45 | |
| 46 | /** |
tom | b41d1ac | 2014-09-24 01:51:24 -0700 | [diff] [blame] | 47 | * Returns the specified controller node. |
tom | e472987 | 2014-09-23 00:37:37 -0700 | [diff] [blame] | 48 | * |
| 49 | * @param nodeId controller instance identifier |
| 50 | * @return controller instance |
| 51 | */ |
| 52 | ControllerNode getNode(NodeId nodeId); |
| 53 | |
| 54 | /** |
tom | b41d1ac | 2014-09-24 01:51:24 -0700 | [diff] [blame] | 55 | * Returns the availability state of the specified controller node. |
tom | e472987 | 2014-09-23 00:37:37 -0700 | [diff] [blame] | 56 | * |
| 57 | * @param nodeId controller instance identifier |
| 58 | * @return availability state |
| 59 | */ |
| 60 | ControllerNode.State getState(NodeId nodeId); |
| 61 | |
tom | b41d1ac | 2014-09-24 01:51:24 -0700 | [diff] [blame] | 62 | /** |
Jordan Halterman | f70bf46 | 2017-07-29 13:12:00 -0700 | [diff] [blame] | 63 | * Returns the version of the specified controller node. |
| 64 | * |
| 65 | * @param nodeId controller instance identifier |
| 66 | * @return controller version |
| 67 | */ |
| 68 | Version getVersion(NodeId nodeId); |
| 69 | |
| 70 | /** |
Thomas Vachuska | 7a8de84 | 2016-03-07 20:56:35 -0800 | [diff] [blame] | 71 | * Marks the current node as fully started. |
| 72 | * |
| 73 | * @param started true indicates all components have been started |
| 74 | */ |
| 75 | void markFullyStarted(boolean started); |
| 76 | |
| 77 | /** |
Madan Jampani | 7d2fab2 | 2015-03-18 17:21:57 -0700 | [diff] [blame] | 78 | * Returns the system when the availability state was last updated. |
| 79 | * |
| 80 | * @param nodeId controller node identifier |
| 81 | * @return system time when the availability state was last updated. |
| 82 | */ |
Yuta HIGUCHI | 0c47d53 | 2017-08-18 23:16:35 -0700 | [diff] [blame] | 83 | default Instant getLastUpdatedInstant(NodeId nodeId) { |
| 84 | return Optional.ofNullable(getLastUpdated(nodeId)) |
| 85 | .map(DateTime::getMillis) |
| 86 | .map(Instant::ofEpochMilli) |
| 87 | .orElse(null); |
| 88 | } |
| 89 | |
| 90 | /** |
| 91 | * Returns the system when the availability state was last updated. |
| 92 | * |
| 93 | * @param nodeId controller node identifier |
| 94 | * @return system time when the availability state was last updated. |
| 95 | * |
| 96 | * @deprecated in 1.12.0 |
| 97 | */ |
| 98 | @Deprecated |
| 99 | default DateTime getLastUpdated(NodeId nodeId) { |
| 100 | return Optional.ofNullable(getLastUpdatedInstant(nodeId)) |
| 101 | .map(Instant::toEpochMilli) |
| 102 | .map(DateTime::new) |
| 103 | .orElse(null); |
| 104 | } |
Madan Jampani | 7d2fab2 | 2015-03-18 17:21:57 -0700 | [diff] [blame] | 105 | |
| 106 | /** |
tom | ee49c37 | 2014-09-26 15:14:50 -0700 | [diff] [blame] | 107 | * Adds a new controller node to the cluster. |
| 108 | * |
| 109 | * @param nodeId controller node identifier |
| 110 | * @param ip node IP listen address |
| 111 | * @param tcpPort tcp listen port |
| 112 | * @return newly added node |
| 113 | */ |
Pavlin Radoslavov | 444b519 | 2014-10-28 10:45:19 -0700 | [diff] [blame] | 114 | ControllerNode addNode(NodeId nodeId, IpAddress ip, int tcpPort); |
tom | ee49c37 | 2014-09-26 15:14:50 -0700 | [diff] [blame] | 115 | |
| 116 | /** |
tom | b41d1ac | 2014-09-24 01:51:24 -0700 | [diff] [blame] | 117 | * Removes the specified node from the inventory of cluster nodes. |
| 118 | * |
| 119 | * @param nodeId controller instance identifier |
| 120 | */ |
| 121 | void removeNode(NodeId nodeId); |
| 122 | |
tom | e472987 | 2014-09-23 00:37:37 -0700 | [diff] [blame] | 123 | } |