blob: 6d5de44b7841df41d6a05984356948650bdb3176 [file] [log] [blame]
Simon Huntcda9c032016-04-11 10:32:54 -07001/*
2 * Copyright 2016 Open Networking Laboratory
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
17package org.onosproject.ui.impl.topo.model;
18
Simon Hunt23fb1352016-04-11 12:15:19 -070019import org.onosproject.cluster.ControllerNode;
20import org.onosproject.cluster.RoleInfo;
Simon Huntcda9c032016-04-11 10:32:54 -070021import org.onosproject.event.EventDispatcher;
22import org.onosproject.net.Device;
Simon Hunt23fb1352016-04-11 12:15:19 -070023import org.onosproject.net.DeviceId;
24import org.onosproject.net.Host;
25import org.onosproject.net.Link;
26import org.onosproject.net.region.Region;
Simon Hunt338a3b42016-04-14 09:43:52 -070027import org.onosproject.ui.model.topo.UiClusterMember;
Simon Huntcda9c032016-04-11 10:32:54 -070028import org.onosproject.ui.model.topo.UiDevice;
Simon Hunt23fb1352016-04-11 12:15:19 -070029import org.onosproject.ui.model.topo.UiTopology;
30
31import static org.onosproject.ui.impl.topo.model.UiModelEvent.Type.DEVICE_ADDED;
32import static org.onosproject.ui.impl.topo.model.UiModelEvent.Type.DEVICE_REMOVED;
Simon Huntcda9c032016-04-11 10:32:54 -070033
34/**
35 * UI Topology Model cache.
36 */
37class ModelCache {
38
39 private final EventDispatcher dispatcher;
Simon Hunt23fb1352016-04-11 12:15:19 -070040 private final UiTopology uiTopology = new UiTopology();
Simon Huntcda9c032016-04-11 10:32:54 -070041
42 ModelCache(EventDispatcher eventDispatcher) {
43 this.dispatcher = eventDispatcher;
44 }
45
Simon Hunt338a3b42016-04-14 09:43:52 -070046 @Override
47 public String toString() {
48 return "ModelCache{" + uiTopology + "}";
49 }
50
Simon Huntcda9c032016-04-11 10:32:54 -070051 /**
52 * Clear our model.
53 */
54 void clear() {
Simon Hunt23fb1352016-04-11 12:15:19 -070055 uiTopology.clear();
Simon Huntcda9c032016-04-11 10:32:54 -070056 }
57
58 /**
59 * Create our internal model of the global topology.
60 */
61 void load() {
62// loadClusterMembers();
63// loadRegions();
64// loadDevices();
65// loadHosts();
66// loadLinks();
67 }
68
69
Simon Hunt338a3b42016-04-14 09:43:52 -070070 /**
71 * Updates the model (adds a new instance if necessary) with the given
72 * controller node information.
73 *
74 * @param cnode controller node to be added/updated
75 */
76 void addOrUpdateClusterMember(ControllerNode cnode) {
77 UiClusterMember member = uiTopology.findClusterMember(cnode.id());
78 if (member != null) {
79 member.update(cnode);
80 } else {
81 member = new UiClusterMember(cnode);
82 uiTopology.add(member);
83 }
84
85 // TODO: post event
86 }
87
88 void removeClusterMember(ControllerNode cnode) {
89 // TODO: find cluster member assoc. with parameter; remove from model
90 // TODO: post event
91 }
92
93 void updateMasterships(DeviceId deviceId, RoleInfo roleInfo) {
94 // TODO: store the updated mastership information
95 // TODO: post event
96 }
97
98 void addOrUpdateRegion(Region region) {
99 // TODO: find or create region assoc. with parameter
100 // TODO: post event
101 }
102
103 void removeRegion(Region region) {
104 // TODO: find region assoc. with parameter; remove from model
105 // TODO: post event
106 }
107
Simon Huntcda9c032016-04-11 10:32:54 -0700108 void addOrUpdateDevice(Device device) {
Simon Hunt23fb1352016-04-11 12:15:19 -0700109 // TODO: find or create device assoc. with parameter
110 // FIXME
Simon Huntcda9c032016-04-11 10:32:54 -0700111 UiDevice uiDevice = new UiDevice();
112
Simon Hunt23fb1352016-04-11 12:15:19 -0700113 // TODO: post the (correct) event
114 dispatcher.post(new UiModelEvent(DEVICE_ADDED, uiDevice));
Simon Huntcda9c032016-04-11 10:32:54 -0700115 }
116
117 void removeDevice(Device device) {
Simon Hunt23fb1352016-04-11 12:15:19 -0700118 // TODO: get UiDevice associated with the given parameter; remove from model
119 // FIXME
Simon Huntcda9c032016-04-11 10:32:54 -0700120 UiDevice uiDevice = new UiDevice();
121
Simon Hunt23fb1352016-04-11 12:15:19 -0700122 // TODO: post the (correct) event
123 dispatcher.post(new UiModelEvent(DEVICE_REMOVED, uiDevice));
Simon Huntcda9c032016-04-11 10:32:54 -0700124
125 }
126
Simon Hunt23fb1352016-04-11 12:15:19 -0700127 void addOrUpdateLink(Link link) {
128 // TODO: find ui-link assoc. with parameter; create or update.
129 // TODO: post event
130 }
131
132 void removeLink(Link link) {
133 // TODO: find ui-link assoc. with parameter; update or remove.
134 // TODO: post event
135 }
136
137 void addOrUpdateHost(Host host) {
138 // TODO: find or create host assoc. with parameter
139 // TODO: post event
140 }
141
142 void moveHost(Host host, Host prevHost) {
143 // TODO: process host-move
144 // TODO: post event
145 }
146
147 void removeHost(Host host) {
148 // TODO: find host assoc. with parameter; remove from model
149 }
Simon Hunt338a3b42016-04-14 09:43:52 -0700150
151 /**
152 * Returns the number of members in the cluster.
153 *
154 * @return number of cluster members
155 */
156 public int clusterMemberCount() {
157 return uiTopology.clusterMemberCount();
158 }
159
160 /**
161 * Returns the number of regions configured in the topology.
162 *
163 * @return number of regions
164 */
165 public int regionCount() {
166 return uiTopology.regionCount();
167 }
Simon Huntcda9c032016-04-11 10:32:54 -0700168}