blob: fdcd31531d2cd2f5a150d9b95d3c2c97ab6e473b [file] [log] [blame]
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2014-present Open Networking Foundation
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07003 *
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.cluster;
tome4729872014-09-23 00:37:37 -070017
Madan Jampani7d2fab22015-03-18 17:21:57 -070018import org.joda.time.DateTime;
19import org.onlab.packet.IpAddress;
Jordan Haltermanf70bf462017-07-29 13:12:00 -070020import org.onosproject.core.Version;
Madan Jampani7d2fab22015-03-18 17:21:57 -070021import org.onosproject.store.Store;
22
Yuta HIGUCHI0c47d532017-08-18 23:16:35 -070023import java.time.Instant;
24import java.util.Optional;
Thomas Vachuskade563cf2015-04-01 00:28:50 -070025import java.util.Set;
26
tome4729872014-09-23 00:37:37 -070027/**
28 * Manages inventory of controller cluster nodes; not intended for direct use.
29 */
tom0755a362014-09-24 11:54:43 -070030public interface ClusterStore extends Store<ClusterEvent, ClusterStoreDelegate> {
tome4729872014-09-23 00:37:37 -070031
32 /**
tomb41d1ac2014-09-24 01:51:24 -070033 * Returns the local controller node.
tome4729872014-09-23 00:37:37 -070034 *
35 * @return local controller instance
36 */
37 ControllerNode getLocalNode();
38
39 /**
Jordan Halterman00e92da2018-05-22 23:05:52 -070040 * Returns the set of storage nodes.
41 *
42 * @return set of storage nodes
43 */
44 Set<Node> getStorageNodes();
45
46 /**
tome4729872014-09-23 00:37:37 -070047 * Returns the set of current cluster members.
48 *
49 * @return set of cluster members
50 */
51 Set<ControllerNode> getNodes();
52
53 /**
tomb41d1ac2014-09-24 01:51:24 -070054 * Returns the specified controller node.
tome4729872014-09-23 00:37:37 -070055 *
56 * @param nodeId controller instance identifier
57 * @return controller instance
58 */
59 ControllerNode getNode(NodeId nodeId);
60
61 /**
tomb41d1ac2014-09-24 01:51:24 -070062 * Returns the availability state of the specified controller node.
tome4729872014-09-23 00:37:37 -070063 *
64 * @param nodeId controller instance identifier
65 * @return availability state
66 */
67 ControllerNode.State getState(NodeId nodeId);
68
tomb41d1ac2014-09-24 01:51:24 -070069 /**
Jordan Haltermanf70bf462017-07-29 13:12:00 -070070 * Returns the version of the specified controller node.
71 *
72 * @param nodeId controller instance identifier
73 * @return controller version
74 */
75 Version getVersion(NodeId nodeId);
76
77 /**
Thomas Vachuska7a8de842016-03-07 20:56:35 -080078 * Marks the current node as fully started.
79 *
80 * @param started true indicates all components have been started
81 */
82 void markFullyStarted(boolean started);
83
84 /**
Madan Jampani7d2fab22015-03-18 17:21:57 -070085 * Returns the system when the availability state was last updated.
86 *
87 * @param nodeId controller node identifier
88 * @return system time when the availability state was last updated.
89 */
Yuta HIGUCHI0c47d532017-08-18 23:16:35 -070090 default Instant getLastUpdatedInstant(NodeId nodeId) {
91 return Optional.ofNullable(getLastUpdated(nodeId))
92 .map(DateTime::getMillis)
93 .map(Instant::ofEpochMilli)
94 .orElse(null);
95 }
96
97 /**
98 * Returns the system when the availability state was last updated.
99 *
100 * @param nodeId controller node identifier
101 * @return system time when the availability state was last updated.
102 *
103 * @deprecated in 1.12.0
104 */
105 @Deprecated
106 default DateTime getLastUpdated(NodeId nodeId) {
107 return Optional.ofNullable(getLastUpdatedInstant(nodeId))
108 .map(Instant::toEpochMilli)
109 .map(DateTime::new)
110 .orElse(null);
111 }
Madan Jampani7d2fab22015-03-18 17:21:57 -0700112
113 /**
tomee49c372014-09-26 15:14:50 -0700114 * Adds a new controller node to the cluster.
115 *
116 * @param nodeId controller node identifier
117 * @param ip node IP listen address
118 * @param tcpPort tcp listen port
119 * @return newly added node
120 */
Pavlin Radoslavov444b5192014-10-28 10:45:19 -0700121 ControllerNode addNode(NodeId nodeId, IpAddress ip, int tcpPort);
tomee49c372014-09-26 15:14:50 -0700122
123 /**
tomb41d1ac2014-09-24 01:51:24 -0700124 * Removes the specified node from the inventory of cluster nodes.
125 *
126 * @param nodeId controller instance identifier
127 */
128 void removeNode(NodeId nodeId);
129
tome4729872014-09-23 00:37:37 -0700130}