Simon Hunt | 5f6dbf8 | 2016-03-30 08:53:33 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | 5ab426f | 2016-04-09 01:19:45 -0700 | [diff] [blame] | 2 | * Copyright 2016-present Open Networking Laboratory |
Simon Hunt | 5f6dbf8 | 2016-03-30 08:53:33 -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 | */ |
| 16 | |
| 17 | package org.onosproject.ui.model.topo; |
| 18 | |
Simon Hunt | 642bc45 | 2016-05-04 19:34:45 -0700 | [diff] [blame] | 19 | import org.onlab.packet.IpAddress; |
Simon Hunt | 338a3b4 | 2016-04-14 09:43:52 -0700 | [diff] [blame] | 20 | import org.onosproject.cluster.ControllerNode; |
| 21 | import org.onosproject.cluster.NodeId; |
| 22 | |
Thomas Vachuska | b877a6f | 2017-04-14 11:43:30 -0700 | [diff] [blame] | 23 | import static com.google.common.base.Preconditions.checkNotNull; |
Simon Hunt | 642bc45 | 2016-05-04 19:34:45 -0700 | [diff] [blame] | 24 | import static org.onosproject.cluster.ControllerNode.State.INACTIVE; |
| 25 | |
Simon Hunt | 5f6dbf8 | 2016-03-30 08:53:33 -0700 | [diff] [blame] | 26 | /** |
| 27 | * Represents an individual member of the cluster (ONOS instance). |
| 28 | */ |
Simon Hunt | cda9c03 | 2016-04-11 10:32:54 -0700 | [diff] [blame] | 29 | public class UiClusterMember extends UiElement { |
Simon Hunt | 338a3b4 | 2016-04-14 09:43:52 -0700 | [diff] [blame] | 30 | |
Thomas Vachuska | b877a6f | 2017-04-14 11:43:30 -0700 | [diff] [blame] | 31 | private static final String NODE_CANNOT_BE_NULL = "Node cannot be null"; |
| 32 | |
Simon Hunt | c0f20c1 | 2016-05-09 09:30:20 -0700 | [diff] [blame] | 33 | private final UiTopology topology; |
Thomas Vachuska | b877a6f | 2017-04-14 11:43:30 -0700 | [diff] [blame] | 34 | private final NodeId nodeId; |
Simon Hunt | 338a3b4 | 2016-04-14 09:43:52 -0700 | [diff] [blame] | 35 | |
Simon Hunt | 642bc45 | 2016-05-04 19:34:45 -0700 | [diff] [blame] | 36 | private ControllerNode.State state = INACTIVE; |
| 37 | |
Simon Hunt | 338a3b4 | 2016-04-14 09:43:52 -0700 | [diff] [blame] | 38 | /** |
Simon Hunt | c0f20c1 | 2016-05-09 09:30:20 -0700 | [diff] [blame] | 39 | * Constructs a UI cluster member, with a reference to the parent |
| 40 | * topology instance and the specified controller node instance. |
Simon Hunt | 338a3b4 | 2016-04-14 09:43:52 -0700 | [diff] [blame] | 41 | * |
Simon Hunt | c0f20c1 | 2016-05-09 09:30:20 -0700 | [diff] [blame] | 42 | * @param topology parent topology containing this cluster member |
Simon Hunt | b058249 | 2016-09-20 18:26:38 -0700 | [diff] [blame] | 43 | * @param cnode underlying controller node |
Simon Hunt | 338a3b4 | 2016-04-14 09:43:52 -0700 | [diff] [blame] | 44 | */ |
Simon Hunt | c0f20c1 | 2016-05-09 09:30:20 -0700 | [diff] [blame] | 45 | public UiClusterMember(UiTopology topology, ControllerNode cnode) { |
Thomas Vachuska | b877a6f | 2017-04-14 11:43:30 -0700 | [diff] [blame] | 46 | checkNotNull(cnode, NODE_CANNOT_BE_NULL); |
Simon Hunt | c0f20c1 | 2016-05-09 09:30:20 -0700 | [diff] [blame] | 47 | this.topology = topology; |
Thomas Vachuska | b877a6f | 2017-04-14 11:43:30 -0700 | [diff] [blame] | 48 | this.nodeId = cnode.id(); |
Simon Hunt | 338a3b4 | 2016-04-14 09:43:52 -0700 | [diff] [blame] | 49 | } |
| 50 | |
Simon Hunt | 642bc45 | 2016-05-04 19:34:45 -0700 | [diff] [blame] | 51 | @Override |
| 52 | public String toString() { |
Thomas Vachuska | b877a6f | 2017-04-14 11:43:30 -0700 | [diff] [blame] | 53 | return "UiClusterMember{" + nodeId + |
Simon Hunt | 642bc45 | 2016-05-04 19:34:45 -0700 | [diff] [blame] | 54 | ", online=" + isOnline() + |
| 55 | ", ready=" + isReady() + |
Simon Hunt | 642bc45 | 2016-05-04 19:34:45 -0700 | [diff] [blame] | 56 | "}"; |
| 57 | } |
| 58 | |
Simon Hunt | c0f20c1 | 2016-05-09 09:30:20 -0700 | [diff] [blame] | 59 | @Override |
| 60 | public String idAsString() { |
| 61 | return id().toString(); |
| 62 | } |
| 63 | |
| 64 | /** |
| 65 | * Returns the controller node instance backing this UI cluster member. |
| 66 | * |
| 67 | * @return the backing controller node instance |
| 68 | */ |
| 69 | public ControllerNode backingNode() { |
Thomas Vachuska | b877a6f | 2017-04-14 11:43:30 -0700 | [diff] [blame] | 70 | return topology.services.cluster().getNode(nodeId); |
Simon Hunt | c0f20c1 | 2016-05-09 09:30:20 -0700 | [diff] [blame] | 71 | } |
Simon Hunt | 642bc45 | 2016-05-04 19:34:45 -0700 | [diff] [blame] | 72 | |
Simon Hunt | 338a3b4 | 2016-04-14 09:43:52 -0700 | [diff] [blame] | 73 | /** |
Simon Hunt | 642bc45 | 2016-05-04 19:34:45 -0700 | [diff] [blame] | 74 | * Sets the state of this cluster member. |
Simon Hunt | 338a3b4 | 2016-04-14 09:43:52 -0700 | [diff] [blame] | 75 | * |
Simon Hunt | 642bc45 | 2016-05-04 19:34:45 -0700 | [diff] [blame] | 76 | * @param state the state |
Simon Hunt | 338a3b4 | 2016-04-14 09:43:52 -0700 | [diff] [blame] | 77 | */ |
Simon Hunt | 642bc45 | 2016-05-04 19:34:45 -0700 | [diff] [blame] | 78 | public void setState(ControllerNode.State state) { |
| 79 | this.state = state; |
| 80 | } |
| 81 | |
Simon Hunt | 642bc45 | 2016-05-04 19:34:45 -0700 | [diff] [blame] | 82 | /** |
Simon Hunt | 338a3b4 | 2016-04-14 09:43:52 -0700 | [diff] [blame] | 83 | * Returns the identity of the cluster member. |
| 84 | * |
| 85 | * @return member identifier |
| 86 | */ |
| 87 | public NodeId id() { |
Thomas Vachuska | b877a6f | 2017-04-14 11:43:30 -0700 | [diff] [blame] | 88 | return nodeId; |
Simon Hunt | 338a3b4 | 2016-04-14 09:43:52 -0700 | [diff] [blame] | 89 | } |
Simon Hunt | 642bc45 | 2016-05-04 19:34:45 -0700 | [diff] [blame] | 90 | |
| 91 | /** |
| 92 | * Returns the IP address of the cluster member. |
| 93 | * |
| 94 | * @return the IP address |
| 95 | */ |
| 96 | public IpAddress ip() { |
Thomas Vachuska | b877a6f | 2017-04-14 11:43:30 -0700 | [diff] [blame] | 97 | return backingNode().ip(); |
Simon Hunt | 642bc45 | 2016-05-04 19:34:45 -0700 | [diff] [blame] | 98 | } |
| 99 | |
| 100 | /** |
| 101 | * Returns true if this cluster member is online (active). |
| 102 | * |
| 103 | * @return true if online, false otherwise |
| 104 | */ |
| 105 | public boolean isOnline() { |
| 106 | return state.isActive(); |
| 107 | } |
| 108 | |
| 109 | /** |
| 110 | * Returns true if this cluster member is considered ready. |
| 111 | * |
| 112 | * @return true if ready, false otherwise |
| 113 | */ |
| 114 | public boolean isReady() { |
| 115 | return state.isReady(); |
| 116 | } |
Simon Hunt | 5f6dbf8 | 2016-03-30 08:53:33 -0700 | [diff] [blame] | 117 | } |