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