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 | c0f20c1 | 2016-05-09 09:30:20 -0700 | [diff] [blame] | 19 | import com.google.common.base.MoreObjects; |
Simon Hunt | d5b9673 | 2016-07-08 13:22:27 -0700 | [diff] [blame] | 20 | import org.onosproject.cluster.NodeId; |
Simon Hunt | 23fb135 | 2016-04-11 12:15:19 -0700 | [diff] [blame] | 21 | import org.onosproject.net.Device; |
Simon Hunt | 642bc45 | 2016-05-04 19:34:45 -0700 | [diff] [blame] | 22 | import org.onosproject.net.DeviceId; |
Simon Hunt | c0f20c1 | 2016-05-09 09:30:20 -0700 | [diff] [blame] | 23 | import org.onosproject.net.region.RegionId; |
Simon Hunt | 23fb135 | 2016-04-11 12:15:19 -0700 | [diff] [blame] | 24 | |
Simon Hunt | 5f6dbf8 | 2016-03-30 08:53:33 -0700 | [diff] [blame] | 25 | /** |
| 26 | * Represents a device. |
| 27 | */ |
| 28 | public class UiDevice extends UiNode { |
Simon Hunt | 23fb135 | 2016-04-11 12:15:19 -0700 | [diff] [blame] | 29 | |
Simon Hunt | c0f20c1 | 2016-05-09 09:30:20 -0700 | [diff] [blame] | 30 | private final UiTopology topology; |
| 31 | private final Device device; |
| 32 | |
| 33 | private RegionId regionId; |
Simon Hunt | d5b9673 | 2016-07-08 13:22:27 -0700 | [diff] [blame] | 34 | private NodeId masterId; |
Simon Hunt | c0f20c1 | 2016-05-09 09:30:20 -0700 | [diff] [blame] | 35 | |
| 36 | /** |
| 37 | * Creates a new UI device. |
| 38 | * |
| 39 | * @param topology parent topology |
| 40 | * @param device backing device |
| 41 | */ |
| 42 | public UiDevice(UiTopology topology, Device device) { |
| 43 | this.topology = topology; |
| 44 | this.device = device; |
| 45 | } |
| 46 | |
| 47 | /** |
| 48 | * Sets the ID of the region to which this device belongs. |
| 49 | * |
| 50 | * @param regionId region identifier |
| 51 | */ |
| 52 | public void setRegionId(RegionId regionId) { |
| 53 | this.regionId = regionId; |
| 54 | } |
Simon Hunt | 23fb135 | 2016-04-11 12:15:19 -0700 | [diff] [blame] | 55 | |
Simon Hunt | d5b9673 | 2016-07-08 13:22:27 -0700 | [diff] [blame] | 56 | /** |
| 57 | * Sets the ID of the controller node that holds mastership for this device. |
| 58 | * |
| 59 | * @param masterId master identifier |
| 60 | */ |
| 61 | public void setMasterId(NodeId masterId) { |
| 62 | this.masterId = masterId; |
| 63 | } |
| 64 | |
Simon Hunt | 23fb135 | 2016-04-11 12:15:19 -0700 | [diff] [blame] | 65 | @Override |
Simon Hunt | c0f20c1 | 2016-05-09 09:30:20 -0700 | [diff] [blame] | 66 | public String toString() { |
| 67 | return MoreObjects.toStringHelper(this) |
| 68 | .add("id", id()) |
| 69 | .add("region", regionId) |
| 70 | .toString(); |
Simon Hunt | 23fb135 | 2016-04-11 12:15:19 -0700 | [diff] [blame] | 71 | } |
Simon Hunt | 642bc45 | 2016-05-04 19:34:45 -0700 | [diff] [blame] | 72 | |
Simon Hunt | c0f20c1 | 2016-05-09 09:30:20 -0700 | [diff] [blame] | 73 | // @Override |
| 74 | // protected void destroy() { |
| 75 | // } |
| 76 | |
Simon Hunt | 642bc45 | 2016-05-04 19:34:45 -0700 | [diff] [blame] | 77 | /** |
| 78 | * Returns the identity of the device. |
| 79 | * |
| 80 | * @return device ID |
| 81 | */ |
| 82 | public DeviceId id() { |
| 83 | return device.id(); |
| 84 | } |
| 85 | |
| 86 | @Override |
| 87 | public String idAsString() { |
| 88 | return id().toString(); |
| 89 | } |
Simon Hunt | c0f20c1 | 2016-05-09 09:30:20 -0700 | [diff] [blame] | 90 | |
| 91 | /** |
| 92 | * Returns the device instance backing this UI device. |
| 93 | * |
| 94 | * @return the backing device instance |
| 95 | */ |
| 96 | public Device backingDevice() { |
| 97 | return device; |
| 98 | } |
| 99 | |
| 100 | /** |
Simon Hunt | 58a0dd0 | 2016-05-17 11:54:23 -0700 | [diff] [blame] | 101 | * Returns the identifier of the region to which this device belongs. |
| 102 | * This will be null if the device does not belong to any region. |
| 103 | * |
| 104 | * @return region identity |
| 105 | */ |
| 106 | public RegionId regionId() { |
| 107 | return regionId; |
| 108 | } |
| 109 | |
| 110 | /** |
Simon Hunt | c0f20c1 | 2016-05-09 09:30:20 -0700 | [diff] [blame] | 111 | * Returns the UI region to which this device belongs. |
| 112 | * |
| 113 | * @return the UI region |
| 114 | */ |
| 115 | public UiRegion uiRegion() { |
| 116 | return topology.findRegion(regionId); |
| 117 | } |
Simon Hunt | d5b9673 | 2016-07-08 13:22:27 -0700 | [diff] [blame] | 118 | |
| 119 | /** |
| 120 | * Returns a string representation of the type of the backing device. |
| 121 | * |
| 122 | * @return the device type |
| 123 | */ |
| 124 | public String type() { |
| 125 | return device.type().toString().toLowerCase(); |
| 126 | } |
| 127 | |
| 128 | /** |
Simon Hunt | d5b9673 | 2016-07-08 13:22:27 -0700 | [diff] [blame] | 129 | * Returns the identifier for the cluster member that has |
| 130 | * mastership over this device. |
| 131 | * |
| 132 | * @return master cluster member identifier |
| 133 | */ |
| 134 | public NodeId master() { |
| 135 | return masterId; |
| 136 | } |
Simon Hunt | 5f6dbf8 | 2016-03-30 08:53:33 -0700 | [diff] [blame] | 137 | } |