blob: 6cec44284afb816d66c6a2f0c80ef45a67269db9 [file] [log] [blame]
Simon Hunt5f6dbf82016-03-30 08:53:33 -07001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2016-present Open Networking Foundation
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
Thomas Vachuskab877a6f2017-04-14 11:43:30 -070023import static com.google.common.base.Preconditions.checkNotNull;
Simon Hunt642bc452016-05-04 19:34:45 -070024
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
Thomas Vachuskab877a6f2017-04-14 11:43:30 -070030 private static final String NODE_CANNOT_BE_NULL = "Node cannot be null";
31
Simon Huntc0f20c12016-05-09 09:30:20 -070032 private final UiTopology topology;
Thomas Vachuskab877a6f2017-04-14 11:43:30 -070033 private final NodeId nodeId;
Simon Hunt338a3b42016-04-14 09:43:52 -070034
35 /**
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) {
Thomas Vachuskab877a6f2017-04-14 11:43:30 -070043 checkNotNull(cnode, NODE_CANNOT_BE_NULL);
Simon Huntc0f20c12016-05-09 09:30:20 -070044 this.topology = topology;
Thomas Vachuskab877a6f2017-04-14 11:43:30 -070045 this.nodeId = cnode.id();
Simon Hunt338a3b42016-04-14 09:43:52 -070046 }
47
Simon Hunt642bc452016-05-04 19:34:45 -070048 @Override
49 public String toString() {
Thomas Vachuskab877a6f2017-04-14 11:43:30 -070050 return "UiClusterMember{" + nodeId +
Simon Hunt642bc452016-05-04 19:34:45 -070051 "}";
52 }
53
Simon Huntc0f20c12016-05-09 09:30:20 -070054 @Override
55 public String idAsString() {
56 return id().toString();
57 }
58
59 /**
60 * Returns the controller node instance backing this UI cluster member.
61 *
62 * @return the backing controller node instance
63 */
64 public ControllerNode backingNode() {
Thomas Vachuskab877a6f2017-04-14 11:43:30 -070065 return topology.services.cluster().getNode(nodeId);
Simon Huntc0f20c12016-05-09 09:30:20 -070066 }
Simon Hunt642bc452016-05-04 19:34:45 -070067
Simon Hunt338a3b42016-04-14 09:43:52 -070068 /**
Simon Hunt338a3b42016-04-14 09:43:52 -070069 * Returns the identity of the cluster member.
70 *
71 * @return member identifier
72 */
73 public NodeId id() {
Thomas Vachuskab877a6f2017-04-14 11:43:30 -070074 return nodeId;
Simon Hunt338a3b42016-04-14 09:43:52 -070075 }
Simon Hunt642bc452016-05-04 19:34:45 -070076
77 /**
78 * Returns the IP address of the cluster member.
79 *
80 * @return the IP address
81 */
82 public IpAddress ip() {
Thomas Vachuskab877a6f2017-04-14 11:43:30 -070083 return backingNode().ip();
Simon Hunt642bc452016-05-04 19:34:45 -070084 }
85
Simon Hunt5f6dbf82016-03-30 08:53:33 -070086}