blob: 934559f31404d92ac5a59320c89187aae89e0b08 [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
Simon Huntc0f20c12016-05-09 09:30:20 -070030 private final UiTopology topology;
Simon Hunt338a3b42016-04-14 09:43:52 -070031 private final ControllerNode cnode;
32
Simon Hunt642bc452016-05-04 19:34:45 -070033 private ControllerNode.State state = INACTIVE;
34
Simon Hunt338a3b42016-04-14 09:43:52 -070035 /**
Simon Huntc0f20c12016-05-09 09:30:20 -070036 * Constructs a UI cluster member, with a reference to the parent
37 * topology instance and the specified controller node instance.
Simon Hunt338a3b42016-04-14 09:43:52 -070038 *
Simon Huntc0f20c12016-05-09 09:30:20 -070039 * @param topology parent topology containing this cluster member
Simon Huntb0582492016-09-20 18:26:38 -070040 * @param cnode underlying controller node
Simon Hunt338a3b42016-04-14 09:43:52 -070041 */
Simon Huntc0f20c12016-05-09 09:30:20 -070042 public UiClusterMember(UiTopology topology, ControllerNode cnode) {
43 this.topology = topology;
Simon Hunt338a3b42016-04-14 09:43:52 -070044 this.cnode = cnode;
45 }
46
Simon Hunt642bc452016-05-04 19:34:45 -070047 @Override
48 public String toString() {
49 return "UiClusterMember{" + cnode +
50 ", online=" + isOnline() +
51 ", ready=" + isReady() +
Simon Hunt642bc452016-05-04 19:34:45 -070052 "}";
53 }
54
Simon Huntc0f20c12016-05-09 09:30:20 -070055 @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 Hunt642bc452016-05-04 19:34:45 -070068
Simon Hunt338a3b42016-04-14 09:43:52 -070069 /**
Simon Hunt642bc452016-05-04 19:34:45 -070070 * Sets the state of this cluster member.
Simon Hunt338a3b42016-04-14 09:43:52 -070071 *
Simon Hunt642bc452016-05-04 19:34:45 -070072 * @param state the state
Simon Hunt338a3b42016-04-14 09:43:52 -070073 */
Simon Hunt642bc452016-05-04 19:34:45 -070074 public void setState(ControllerNode.State state) {
75 this.state = state;
76 }
77
Simon Hunt642bc452016-05-04 19:34:45 -070078 /**
Simon Hunt338a3b42016-04-14 09:43:52 -070079 * Returns the identity of the cluster member.
80 *
81 * @return member identifier
82 */
83 public NodeId id() {
84 return cnode.id();
85 }
Simon Hunt642bc452016-05-04 19:34:45 -070086
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 Hunt5f6dbf82016-03-30 08:53:33 -0700113}