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 | 338a3b4 | 2016-04-14 09:43:52 -0700 | [diff] [blame] | 19 | import org.onosproject.cluster.NodeId; |
Simon Hunt | 23fb135 | 2016-04-11 12:15:19 -0700 | [diff] [blame] | 20 | import org.slf4j.Logger; |
| 21 | import org.slf4j.LoggerFactory; |
| 22 | |
| 23 | import java.util.Set; |
| 24 | import java.util.TreeSet; |
| 25 | |
Simon Hunt | 5f6dbf8 | 2016-03-30 08:53:33 -0700 | [diff] [blame] | 26 | /** |
| 27 | * Represents the overall network topology. |
| 28 | */ |
Simon Hunt | cda9c03 | 2016-04-11 10:32:54 -0700 | [diff] [blame] | 29 | public class UiTopology extends UiElement { |
Simon Hunt | 23fb135 | 2016-04-11 12:15:19 -0700 | [diff] [blame] | 30 | |
Simon Hunt | 642bc45 | 2016-05-04 19:34:45 -0700 | [diff] [blame] | 31 | private static final String DEFAULT_TOPOLOGY_ID = "TOPOLOGY-0"; |
| 32 | |
Simon Hunt | 23fb135 | 2016-04-11 12:15:19 -0700 | [diff] [blame] | 33 | private static final Logger log = LoggerFactory.getLogger(UiTopology.class); |
| 34 | |
| 35 | private final UiCluster uiCluster = new UiCluster(); |
| 36 | private final Set<UiRegion> uiRegions = new TreeSet<>(); |
| 37 | |
Simon Hunt | 338a3b4 | 2016-04-14 09:43:52 -0700 | [diff] [blame] | 38 | @Override |
| 39 | public String toString() { |
| 40 | return "Topology: " + uiCluster + ", " + uiRegions.size() + " regions"; |
| 41 | } |
| 42 | |
Simon Hunt | 23fb135 | 2016-04-11 12:15:19 -0700 | [diff] [blame] | 43 | /** |
| 44 | * Clears the topology state; that is, drops all regions, devices, hosts, |
| 45 | * links, and cluster members. |
| 46 | */ |
| 47 | public void clear() { |
| 48 | log.debug("clearing topology model"); |
| 49 | uiRegions.clear(); |
| 50 | uiCluster.clear(); |
| 51 | } |
Simon Hunt | 338a3b4 | 2016-04-14 09:43:52 -0700 | [diff] [blame] | 52 | |
| 53 | /** |
| 54 | * Returns the cluster member with the given identifier, or null if no |
| 55 | * such member. |
| 56 | * |
| 57 | * @param id cluster node identifier |
| 58 | * @return the cluster member with that identifier |
| 59 | */ |
| 60 | public UiClusterMember findClusterMember(NodeId id) { |
| 61 | return uiCluster.find(id); |
| 62 | } |
| 63 | |
| 64 | /** |
| 65 | * Adds the given cluster member to the topology model. |
| 66 | * |
| 67 | * @param member cluster member to add |
| 68 | */ |
| 69 | public void add(UiClusterMember member) { |
| 70 | uiCluster.add(member); |
| 71 | } |
| 72 | |
| 73 | /** |
Simon Hunt | 642bc45 | 2016-05-04 19:34:45 -0700 | [diff] [blame] | 74 | * Removes the given cluster member from the topology model. |
| 75 | * |
| 76 | * @param member cluster member to remove |
| 77 | */ |
| 78 | public void remove(UiClusterMember member) { |
| 79 | uiCluster.remove(member); |
| 80 | } |
| 81 | |
| 82 | /** |
Simon Hunt | 338a3b4 | 2016-04-14 09:43:52 -0700 | [diff] [blame] | 83 | * Returns the number of members in the cluster. |
| 84 | * |
| 85 | * @return number of cluster members |
| 86 | */ |
| 87 | public int clusterMemberCount() { |
| 88 | return uiCluster.size(); |
| 89 | } |
| 90 | |
| 91 | /** |
| 92 | * Returns the number of regions configured in the topology. |
| 93 | * |
| 94 | * @return number of regions |
| 95 | */ |
| 96 | public int regionCount() { |
| 97 | return uiRegions.size(); |
| 98 | } |
Simon Hunt | 642bc45 | 2016-05-04 19:34:45 -0700 | [diff] [blame] | 99 | |
| 100 | @Override |
| 101 | public String idAsString() { |
| 102 | return DEFAULT_TOPOLOGY_ID; |
| 103 | } |
Simon Hunt | 5f6dbf8 | 2016-03-30 08:53:33 -0700 | [diff] [blame] | 104 | } |