blob: 1cc923463dc9c08e3820f87f75d900afe39c0a10 [file] [log] [blame]
Simon Hunt5f6dbf82016-03-30 08:53:33 -07001/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2016-present Open Networking Laboratory
Simon Hunt5f6dbf82016-03-30 08:53:33 -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 */
16
17package org.onosproject.ui.model.topo;
18
Simon Hunt642bc452016-05-04 19:34:45 -070019import org.onlab.packet.IpAddress;
Simon Hunt338a3b42016-04-14 09:43:52 -070020import org.onosproject.cluster.ControllerNode;
21import org.onosproject.cluster.NodeId;
22
Simon Hunt642bc452016-05-04 19:34:45 -070023import static org.onosproject.cluster.ControllerNode.State.INACTIVE;
24
Simon Hunt5f6dbf82016-03-30 08:53:33 -070025/**
26 * Represents an individual member of the cluster (ONOS instance).
27 */
Simon Huntcda9c032016-04-11 10:32:54 -070028public class UiClusterMember extends UiElement {
Simon Hunt338a3b42016-04-14 09:43:52 -070029
30 private final ControllerNode cnode;
31
Simon Hunt642bc452016-05-04 19:34:45 -070032 private int deviceCount = 0;
33 private ControllerNode.State state = INACTIVE;
34
Simon Hunt338a3b42016-04-14 09:43:52 -070035 /**
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 Hunt642bc452016-05-04 19:34:45 -070045 @Override
46 public String toString() {
47 return "UiClusterMember{" + cnode +
48 ", online=" + isOnline() +
49 ", ready=" + isReady() +
50 ", #devices=" + deviceCount +
51 "}";
52 }
53
54
Simon Hunt338a3b42016-04-14 09:43:52 -070055 /**
Simon Hunt642bc452016-05-04 19:34:45 -070056 * Sets the state of this cluster member.
Simon Hunt338a3b42016-04-14 09:43:52 -070057 *
Simon Hunt642bc452016-05-04 19:34:45 -070058 * @param state the state
Simon Hunt338a3b42016-04-14 09:43:52 -070059 */
Simon Hunt642bc452016-05-04 19:34:45 -070060 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 Hunt338a3b42016-04-14 09:43:52 -070072 }
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 Hunt642bc452016-05-04 19:34:45 -070082
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 Hunt5f6dbf82016-03-30 08:53:33 -0700123}