blob: 0eeda52cd788103cbe8a1af17b85c60e04a36635 [file] [log] [blame]
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -08001/*
2 * Copyright 2015 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 */
16package org.onosproject.ui.impl;
17
Thomas Vachuska9ed335b2015-04-14 12:07:47 -070018import com.fasterxml.jackson.databind.JsonNode;
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -080019import com.google.common.collect.ImmutableList;
Thomas Vachuska9ed335b2015-04-14 12:07:47 -070020import com.google.common.collect.ImmutableSet;
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -080021import com.google.common.collect.Lists;
22import com.google.common.collect.Maps;
23import org.apache.felix.scr.annotations.Activate;
24import org.apache.felix.scr.annotations.Component;
25import org.apache.felix.scr.annotations.Deactivate;
26import org.apache.felix.scr.annotations.Service;
27import org.onosproject.ui.UiExtension;
28import org.onosproject.ui.UiExtensionService;
Thomas Vachuska3553b302015-03-07 14:49:43 -080029import org.onosproject.ui.UiMessageHandlerFactory;
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -080030import org.onosproject.ui.UiView;
Simon Hunt1002cd82015-04-23 14:44:03 -070031import org.onosproject.ui.UiViewHidden;
Simon Huntc54cd1b2015-05-11 13:43:44 -070032import org.onosproject.ui.impl.topo.OverlayService;
33import org.onosproject.ui.impl.topo.overlay.SummaryGenerator;
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -080034import org.slf4j.Logger;
35import org.slf4j.LoggerFactory;
36
37import java.util.List;
38import java.util.Map;
Thomas Vachuska9ed335b2015-04-14 12:07:47 -070039import java.util.Set;
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -080040
41import static com.google.common.collect.ImmutableList.of;
42import static java.util.stream.Collectors.toSet;
Thomas Vachuska8b91f4f2015-04-23 17:55:36 -070043import static org.onosproject.ui.UiView.Category.NETWORK;
44import static org.onosproject.ui.UiView.Category.PLATFORM;
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -080045
46/**
47 * Manages the user interface extensions.
48 */
49@Component(immediate = true)
50@Service
Simon Huntc54cd1b2015-05-11 13:43:44 -070051public class UiExtensionManager
52 implements UiExtensionService, SpriteService, OverlayService {
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -080053
54 private final Logger log = LoggerFactory.getLogger(getClass());
55
56 // List of all extensions
57 private final List<UiExtension> extensions = Lists.newArrayList();
58
59 // Map of views to extensions
60 private final Map<String, UiExtension> views = Maps.newHashMap();
61
62 // Core views & core extension
Thomas Vachuska3553b302015-03-07 14:49:43 -080063 private final UiExtension core = createCoreExtension();
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -080064
Simon Huntc54cd1b2015-05-11 13:43:44 -070065 // Topology Message Handler
66 private final AltTopoViewMessageHandler topoHandler =
67 new AltTopoViewMessageHandler();
68
Thomas Vachuska3553b302015-03-07 14:49:43 -080069
70 // Creates core UI extension
Simon Huntc54cd1b2015-05-11 13:43:44 -070071 private UiExtension createCoreExtension() {
Simon Hunt20e16792015-04-24 14:29:39 -070072 List<UiView> coreViews = of(
73 new UiView(PLATFORM, "app", "Applications", "nav_apps"),
Thomas Vachuskaaa8b0eb2015-05-22 09:54:15 -070074 new UiView(PLATFORM, "settings", "Settings", "nav_settings"),
Simon Hunt20e16792015-04-24 14:29:39 -070075 new UiView(PLATFORM, "cluster", "Cluster Nodes", "nav_cluster"),
76 new UiView(NETWORK, "topo", "Topology", "nav_topo"),
77 new UiView(NETWORK, "device", "Devices", "nav_devs"),
78 new UiViewHidden("flow"),
Bri Prebilic Coleac829e42015-05-05 13:42:06 -070079 new UiViewHidden("port"),
Bri Prebilic Coleff3dc672015-05-06 12:59:38 -070080 new UiViewHidden("group"),
Simon Hunt20e16792015-04-24 14:29:39 -070081 new UiView(NETWORK, "link", "Links", "nav_links"),
82 new UiView(NETWORK, "host", "Hosts", "nav_hosts"),
83 new UiView(NETWORK, "intent", "Intents", "nav_intents")
84 );
Simon Hunt1002cd82015-04-23 14:44:03 -070085
Simon Hunt4c7edd32015-03-11 10:42:53 -070086 UiMessageHandlerFactory messageHandlerFactory =
87 () -> ImmutableList.of(
Thomas Vachuskae586b792015-03-26 13:59:38 -070088 new TopologyViewMessageHandler(),
Simon Huntc54cd1b2015-05-11 13:43:44 -070089// topoHandler,
Thomas Vachuskae586b792015-03-26 13:59:38 -070090 new DeviceViewMessageHandler(),
Thomas Vachuska583bc632015-04-14 10:10:57 -070091 new LinkViewMessageHandler(),
Thomas Vachuska0fa583c2015-03-30 23:07:41 -070092 new HostViewMessageHandler(),
Bri Prebilic Colecdc188d2015-04-24 16:40:11 -070093 new FlowViewMessageHandler(),
Bri Prebilic Coleac829e42015-05-05 13:42:06 -070094 new PortViewMessageHandler(),
Bri Prebilic Coleff3dc672015-05-06 12:59:38 -070095 new GroupViewMessageHandler(),
Bri Prebilic Cole384e8dc2015-04-13 15:51:14 -070096 new IntentViewMessageHandler(),
Thomas Vachuska583bc632015-04-14 10:10:57 -070097 new ApplicationViewMessageHandler(),
Thomas Vachuskaaa8b0eb2015-05-22 09:54:15 -070098 new SettingsViewMessageHandler(),
Thomas Vachuska583bc632015-04-14 10:10:57 -070099 new ClusterViewMessageHandler()
Simon Hunt4c7edd32015-03-11 10:42:53 -0700100 );
Simon Hunt1002cd82015-04-23 14:44:03 -0700101
Thomas Vachuska3553b302015-03-07 14:49:43 -0800102 return new UiExtension(coreViews, messageHandlerFactory, "core",
103 UiExtensionManager.class.getClassLoader());
104 }
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -0800105
106 @Activate
107 public void activate() {
108 register(core);
109 log.info("Started");
110 }
111
112 @Deactivate
113 public void deactivate() {
114 unregister(core);
115 log.info("Stopped");
116 }
117
118 @Override
119 public synchronized void register(UiExtension extension) {
120 if (!extensions.contains(extension)) {
121 extensions.add(extension);
122 for (UiView view : extension.views()) {
123 views.put(view.id(), extension);
124 }
125 }
126 }
127
128 @Override
129 public synchronized void unregister(UiExtension extension) {
130 extensions.remove(extension);
Simon Huntc54cd1b2015-05-11 13:43:44 -0700131 extension.views().stream()
132 .map(UiView::id).collect(toSet()).forEach(views::remove);
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -0800133 }
134
135 @Override
136 public synchronized List<UiExtension> getExtensions() {
137 return ImmutableList.copyOf(extensions);
138 }
139
140 @Override
141 public synchronized UiExtension getViewExtension(String viewId) {
142 return views.get(viewId);
143 }
Thomas Vachuska9ed335b2015-04-14 12:07:47 -0700144
Simon Huntc54cd1b2015-05-11 13:43:44 -0700145 // =====================================================================
Thomas Vachuska9ed335b2015-04-14 12:07:47 -0700146 // Provisional tracking of sprite definitions
Simon Huntc54cd1b2015-05-11 13:43:44 -0700147
148 private final Map<String, JsonNode> sprites = Maps.newHashMap();
Thomas Vachuska9ed335b2015-04-14 12:07:47 -0700149
150 @Override
151 public Set<String> getNames() {
152 return ImmutableSet.copyOf(sprites.keySet());
153 }
154
155 @Override
156 public void put(String name, JsonNode spriteData) {
Simon Huntfd8c7d72015-04-14 17:53:37 -0700157 log.info("Registered sprite definition [{}]", name);
Thomas Vachuska9ed335b2015-04-14 12:07:47 -0700158 sprites.put(name, spriteData);
159 }
160
161 @Override
162 public JsonNode get(String name) {
163 return sprites.get(name);
164 }
165
Simon Huntc54cd1b2015-05-11 13:43:44 -0700166
167 // =====================================================================
168 // Topology Overlay API -- pass through to topology message handler
169
170 // NOTE: while WIP, comment out calls to topoHandler (for checked in code)
171 @Override
172 public void addSummaryGenerator(String overlayId, SummaryGenerator generator) {
173 topoHandler.addSummaryGenerator(overlayId, generator);
174 }
175
176 @Override
177 public void removeSummaryGenerator(String overlayId) {
178 topoHandler.removeSummaryGenerator(overlayId);
179 }
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -0800180}