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 | 73d6d1e | 2014-09-17 20:08:01 -0700 | [diff] [blame] | 17 | |
Yuta HIGUCHI | 0c47d53 | 2017-08-18 23:16:35 -0700 | [diff] [blame] | 18 | import java.time.Instant; |
| 19 | import java.util.Optional; |
Jordan Halterman | 28183ee | 2017-10-17 17:29:10 -0700 | [diff] [blame] | 20 | import java.util.Set; |
| 21 | |
| 22 | import org.joda.time.DateTime; |
| 23 | import org.onosproject.core.Version; |
| 24 | import org.onosproject.event.ListenerService; |
| 25 | |
tom | 73d6d1e | 2014-09-17 20:08:01 -0700 | [diff] [blame] | 26 | /** |
Jordan Halterman | 980a8c1 | 2017-09-22 18:01:19 -0700 | [diff] [blame] | 27 | * Service for obtaining information about the individual nodes within the controller cluster. |
tom | 73d6d1e | 2014-09-17 20:08:01 -0700 | [diff] [blame] | 28 | */ |
Jordan Halterman | 28183ee | 2017-10-17 17:29:10 -0700 | [diff] [blame] | 29 | public interface ClusterService extends ListenerService<ClusterEvent, ClusterEventListener> { |
| 30 | |
| 31 | /** |
| 32 | * Returns the local controller node. |
| 33 | * |
| 34 | * @return local controller node |
| 35 | */ |
| 36 | ControllerNode getLocalNode(); |
| 37 | |
| 38 | /** |
| 39 | * Returns the set of current cluster members. |
| 40 | * |
| 41 | * @return set of cluster members |
| 42 | */ |
| 43 | Set<ControllerNode> getNodes(); |
| 44 | |
| 45 | /** |
| 46 | * Returns the specified controller node. |
| 47 | * |
| 48 | * @param nodeId controller node identifier |
| 49 | * @return controller node |
| 50 | */ |
| 51 | ControllerNode getNode(NodeId nodeId); |
| 52 | |
| 53 | /** |
| 54 | * Returns the availability state of the specified controller node. Note |
| 55 | * that this does not imply that all the core and application components |
| 56 | * have been fully activated; only that the node has joined the cluster. |
| 57 | * |
| 58 | * @param nodeId controller node identifier |
| 59 | * @return availability state |
| 60 | */ |
| 61 | ControllerNode.State getState(NodeId nodeId); |
| 62 | |
| 63 | /** |
| 64 | * Returns the version of the given controller node. |
| 65 | * |
| 66 | * @param nodeId controller node identifier |
| 67 | * @return controller version |
| 68 | */ |
| 69 | Version getVersion(NodeId nodeId); |
| 70 | |
| 71 | /** |
| 72 | * Returns the system time when the availability state was last updated. |
| 73 | * |
| 74 | * @param nodeId controller node identifier |
| 75 | * @return system time when the availability state was last updated. |
| 76 | */ |
Yuta HIGUCHI | 0c47d53 | 2017-08-18 23:16:35 -0700 | [diff] [blame] | 77 | default Instant getLastUpdatedInstant(NodeId nodeId) { |
| 78 | return Optional.ofNullable(getLastUpdated(nodeId)) |
| 79 | .map(DateTime::getMillis) |
| 80 | .map(Instant::ofEpochMilli) |
| 81 | .orElse(null); |
| 82 | } |
| 83 | |
| 84 | /** |
| 85 | * Returns the system time 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 | * |
| 90 | * @deprecated in 1.12.0 |
| 91 | */ |
| 92 | @Deprecated |
| 93 | default DateTime getLastUpdated(NodeId nodeId) { |
| 94 | return Optional.ofNullable(getLastUpdatedInstant(nodeId)) |
| 95 | .map(Instant::toEpochMilli) |
| 96 | .map(DateTime::new) |
| 97 | .orElse(null); |
| 98 | } |
Jordan Halterman | 28183ee | 2017-10-17 17:29:10 -0700 | [diff] [blame] | 99 | |
tom | 73d6d1e | 2014-09-17 20:08:01 -0700 | [diff] [blame] | 100 | } |