Simon Hunt | cda9c03 | 2016-04-11 10:32:54 -0700 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | package org.onosproject.ui.impl.topo.model; |
| 18 | |
Simon Hunt | 23fb135 | 2016-04-11 12:15:19 -0700 | [diff] [blame^] | 19 | import org.onosproject.cluster.ControllerNode; |
| 20 | import org.onosproject.cluster.RoleInfo; |
Simon Hunt | cda9c03 | 2016-04-11 10:32:54 -0700 | [diff] [blame] | 21 | import org.onosproject.event.EventDispatcher; |
| 22 | import org.onosproject.net.Device; |
Simon Hunt | 23fb135 | 2016-04-11 12:15:19 -0700 | [diff] [blame^] | 23 | import org.onosproject.net.DeviceId; |
| 24 | import org.onosproject.net.Host; |
| 25 | import org.onosproject.net.Link; |
| 26 | import org.onosproject.net.region.Region; |
Simon Hunt | cda9c03 | 2016-04-11 10:32:54 -0700 | [diff] [blame] | 27 | import org.onosproject.ui.model.topo.UiDevice; |
Simon Hunt | 23fb135 | 2016-04-11 12:15:19 -0700 | [diff] [blame^] | 28 | import org.onosproject.ui.model.topo.UiTopology; |
| 29 | |
| 30 | import static org.onosproject.ui.impl.topo.model.UiModelEvent.Type.DEVICE_ADDED; |
| 31 | import static org.onosproject.ui.impl.topo.model.UiModelEvent.Type.DEVICE_REMOVED; |
Simon Hunt | cda9c03 | 2016-04-11 10:32:54 -0700 | [diff] [blame] | 32 | |
| 33 | /** |
| 34 | * UI Topology Model cache. |
| 35 | */ |
| 36 | class ModelCache { |
| 37 | |
| 38 | private final EventDispatcher dispatcher; |
Simon Hunt | 23fb135 | 2016-04-11 12:15:19 -0700 | [diff] [blame^] | 39 | private final UiTopology uiTopology = new UiTopology(); |
Simon Hunt | cda9c03 | 2016-04-11 10:32:54 -0700 | [diff] [blame] | 40 | |
| 41 | ModelCache(EventDispatcher eventDispatcher) { |
| 42 | this.dispatcher = eventDispatcher; |
| 43 | } |
| 44 | |
| 45 | /** |
| 46 | * Clear our model. |
| 47 | */ |
| 48 | void clear() { |
Simon Hunt | 23fb135 | 2016-04-11 12:15:19 -0700 | [diff] [blame^] | 49 | uiTopology.clear(); |
Simon Hunt | cda9c03 | 2016-04-11 10:32:54 -0700 | [diff] [blame] | 50 | } |
| 51 | |
| 52 | /** |
| 53 | * Create our internal model of the global topology. |
| 54 | */ |
| 55 | void load() { |
| 56 | // loadClusterMembers(); |
| 57 | // loadRegions(); |
| 58 | // loadDevices(); |
| 59 | // loadHosts(); |
| 60 | // loadLinks(); |
| 61 | } |
| 62 | |
| 63 | |
Simon Hunt | cda9c03 | 2016-04-11 10:32:54 -0700 | [diff] [blame] | 64 | void addOrUpdateDevice(Device device) { |
Simon Hunt | 23fb135 | 2016-04-11 12:15:19 -0700 | [diff] [blame^] | 65 | // TODO: find or create device assoc. with parameter |
| 66 | // FIXME |
Simon Hunt | cda9c03 | 2016-04-11 10:32:54 -0700 | [diff] [blame] | 67 | UiDevice uiDevice = new UiDevice(); |
| 68 | |
Simon Hunt | 23fb135 | 2016-04-11 12:15:19 -0700 | [diff] [blame^] | 69 | // TODO: post the (correct) event |
| 70 | dispatcher.post(new UiModelEvent(DEVICE_ADDED, uiDevice)); |
Simon Hunt | cda9c03 | 2016-04-11 10:32:54 -0700 | [diff] [blame] | 71 | } |
| 72 | |
| 73 | void removeDevice(Device device) { |
Simon Hunt | 23fb135 | 2016-04-11 12:15:19 -0700 | [diff] [blame^] | 74 | // TODO: get UiDevice associated with the given parameter; remove from model |
| 75 | // FIXME |
Simon Hunt | cda9c03 | 2016-04-11 10:32:54 -0700 | [diff] [blame] | 76 | UiDevice uiDevice = new UiDevice(); |
| 77 | |
Simon Hunt | 23fb135 | 2016-04-11 12:15:19 -0700 | [diff] [blame^] | 78 | // TODO: post the (correct) event |
| 79 | dispatcher.post(new UiModelEvent(DEVICE_REMOVED, uiDevice)); |
Simon Hunt | cda9c03 | 2016-04-11 10:32:54 -0700 | [diff] [blame] | 80 | |
| 81 | } |
| 82 | |
Simon Hunt | 23fb135 | 2016-04-11 12:15:19 -0700 | [diff] [blame^] | 83 | void addOrUpdateClusterMember(ControllerNode cnode) { |
| 84 | // TODO: find or create cluster member assoc. with parameter |
| 85 | // TODO: post event |
| 86 | } |
Simon Hunt | cda9c03 | 2016-04-11 10:32:54 -0700 | [diff] [blame] | 87 | |
Simon Hunt | 23fb135 | 2016-04-11 12:15:19 -0700 | [diff] [blame^] | 88 | void removeClusterMember(ControllerNode cnode) { |
| 89 | // TODO: find cluster member assoc. with parameter; remove from model |
| 90 | // TODO: post event |
| 91 | } |
| 92 | |
| 93 | |
| 94 | void updateMasterships(DeviceId deviceId, RoleInfo roleInfo) { |
| 95 | // TODO: store the updated mastership information |
| 96 | // TODO: post event |
| 97 | } |
| 98 | |
| 99 | void addOrUpdateRegion(Region region) { |
| 100 | // TODO: find or create region assoc. with parameter |
| 101 | // TODO: post event |
| 102 | } |
| 103 | |
| 104 | void removeRegion(Region region) { |
| 105 | // TODO: find region assoc. with parameter; remove from model |
| 106 | // TODO: post event |
| 107 | } |
| 108 | |
| 109 | void addOrUpdateLink(Link link) { |
| 110 | // TODO: find ui-link assoc. with parameter; create or update. |
| 111 | // TODO: post event |
| 112 | } |
| 113 | |
| 114 | void removeLink(Link link) { |
| 115 | // TODO: find ui-link assoc. with parameter; update or remove. |
| 116 | // TODO: post event |
| 117 | } |
| 118 | |
| 119 | void addOrUpdateHost(Host host) { |
| 120 | // TODO: find or create host assoc. with parameter |
| 121 | // TODO: post event |
| 122 | } |
| 123 | |
| 124 | void moveHost(Host host, Host prevHost) { |
| 125 | // TODO: process host-move |
| 126 | // TODO: post event |
| 127 | } |
| 128 | |
| 129 | void removeHost(Host host) { |
| 130 | // TODO: find host assoc. with parameter; remove from model |
| 131 | } |
Simon Hunt | cda9c03 | 2016-04-11 10:32:54 -0700 | [diff] [blame] | 132 | } |