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 | |
| 30 | private final ControllerNode cnode; |
| 31 | |
Simon Hunt | 642bc45 | 2016-05-04 19:34:45 -0700 | [diff] [blame^] | 32 | private int deviceCount = 0; |
| 33 | private ControllerNode.State state = INACTIVE; |
| 34 | |
Simon Hunt | 338a3b4 | 2016-04-14 09:43:52 -0700 | [diff] [blame] | 35 | /** |
| 36 | * Constructs a cluster member, with a reference to the specified |
| 37 | * controller node instance. |
| 38 | * |
| 39 | * @param cnode underlying controller node. |
| 40 | */ |
| 41 | public UiClusterMember(ControllerNode cnode) { |
| 42 | this.cnode = cnode; |
| 43 | } |
| 44 | |
Simon Hunt | 642bc45 | 2016-05-04 19:34:45 -0700 | [diff] [blame^] | 45 | @Override |
| 46 | public String toString() { |
| 47 | return "UiClusterMember{" + cnode + |
| 48 | ", online=" + isOnline() + |
| 49 | ", ready=" + isReady() + |
| 50 | ", #devices=" + deviceCount + |
| 51 | "}"; |
| 52 | } |
| 53 | |
| 54 | |
Simon Hunt | 338a3b4 | 2016-04-14 09:43:52 -0700 | [diff] [blame] | 55 | /** |
Simon Hunt | 642bc45 | 2016-05-04 19:34:45 -0700 | [diff] [blame^] | 56 | * Sets the state of this cluster member. |
Simon Hunt | 338a3b4 | 2016-04-14 09:43:52 -0700 | [diff] [blame] | 57 | * |
Simon Hunt | 642bc45 | 2016-05-04 19:34:45 -0700 | [diff] [blame^] | 58 | * @param state the state |
Simon Hunt | 338a3b4 | 2016-04-14 09:43:52 -0700 | [diff] [blame] | 59 | */ |
Simon Hunt | 642bc45 | 2016-05-04 19:34:45 -0700 | [diff] [blame^] | 60 | public void setState(ControllerNode.State state) { |
| 61 | this.state = state; |
| 62 | } |
| 63 | |
| 64 | |
| 65 | /** |
| 66 | * Sets the number of devices for which this cluster member is master. |
| 67 | * |
| 68 | * @param deviceCount number of devices |
| 69 | */ |
| 70 | public void setDeviceCount(int deviceCount) { |
| 71 | this.deviceCount = deviceCount; |
Simon Hunt | 338a3b4 | 2016-04-14 09:43:52 -0700 | [diff] [blame] | 72 | } |
| 73 | |
| 74 | /** |
| 75 | * Returns the identity of the cluster member. |
| 76 | * |
| 77 | * @return member identifier |
| 78 | */ |
| 79 | public NodeId id() { |
| 80 | return cnode.id(); |
| 81 | } |
Simon Hunt | 642bc45 | 2016-05-04 19:34:45 -0700 | [diff] [blame^] | 82 | |
| 83 | /** |
| 84 | * Returns the IP address of the cluster member. |
| 85 | * |
| 86 | * @return the IP address |
| 87 | */ |
| 88 | public IpAddress ip() { |
| 89 | return cnode.ip(); |
| 90 | } |
| 91 | |
| 92 | /** |
| 93 | * Returns true if this cluster member is online (active). |
| 94 | * |
| 95 | * @return true if online, false otherwise |
| 96 | */ |
| 97 | public boolean isOnline() { |
| 98 | return state.isActive(); |
| 99 | } |
| 100 | |
| 101 | /** |
| 102 | * Returns true if this cluster member is considered ready. |
| 103 | * |
| 104 | * @return true if ready, false otherwise |
| 105 | */ |
| 106 | public boolean isReady() { |
| 107 | return state.isReady(); |
| 108 | } |
| 109 | |
| 110 | /** |
| 111 | * Returns the number of devices for which this cluster member is master. |
| 112 | * |
| 113 | * @return number of devices for which this member is master |
| 114 | */ |
| 115 | public int deviceCount() { |
| 116 | return deviceCount; |
| 117 | } |
| 118 | |
| 119 | @Override |
| 120 | public String idAsString() { |
| 121 | return id().toString(); |
| 122 | } |
Simon Hunt | 5f6dbf8 | 2016-03-30 08:53:33 -0700 | [diff] [blame] | 123 | } |