blob: 6ef6826d7707b8a139a4b56f6f81ff6b89ee4a7d [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"),
74 new UiView(PLATFORM, "cluster", "Cluster Nodes", "nav_cluster"),
75 new UiView(NETWORK, "topo", "Topology", "nav_topo"),
76 new UiView(NETWORK, "device", "Devices", "nav_devs"),
77 new UiViewHidden("flow"),
Bri Prebilic Coleac829e42015-05-05 13:42:06 -070078 new UiViewHidden("port"),
Bri Prebilic Coleff3dc672015-05-06 12:59:38 -070079 new UiViewHidden("group"),
Simon Hunt20e16792015-04-24 14:29:39 -070080 new UiView(NETWORK, "link", "Links", "nav_links"),
81 new UiView(NETWORK, "host", "Hosts", "nav_hosts"),
82 new UiView(NETWORK, "intent", "Intents", "nav_intents")
83 );
Simon Hunt1002cd82015-04-23 14:44:03 -070084
Simon Hunt4c7edd32015-03-11 10:42:53 -070085 UiMessageHandlerFactory messageHandlerFactory =
86 () -> ImmutableList.of(
Thomas Vachuskae586b792015-03-26 13:59:38 -070087 new TopologyViewMessageHandler(),
Simon Huntc54cd1b2015-05-11 13:43:44 -070088// topoHandler,
Thomas Vachuskae586b792015-03-26 13:59:38 -070089 new DeviceViewMessageHandler(),
Thomas Vachuska583bc632015-04-14 10:10:57 -070090 new LinkViewMessageHandler(),
Thomas Vachuska0fa583c2015-03-30 23:07:41 -070091 new HostViewMessageHandler(),
Bri Prebilic Colecdc188d2015-04-24 16:40:11 -070092 new FlowViewMessageHandler(),
Bri Prebilic Coleac829e42015-05-05 13:42:06 -070093 new PortViewMessageHandler(),
Bri Prebilic Coleff3dc672015-05-06 12:59:38 -070094 new GroupViewMessageHandler(),
Bri Prebilic Cole384e8dc2015-04-13 15:51:14 -070095 new IntentViewMessageHandler(),
Thomas Vachuska583bc632015-04-14 10:10:57 -070096 new ApplicationViewMessageHandler(),
97 new ClusterViewMessageHandler()
Simon Hunt4c7edd32015-03-11 10:42:53 -070098 );
Simon Hunt1002cd82015-04-23 14:44:03 -070099
Thomas Vachuska3553b302015-03-07 14:49:43 -0800100 return new UiExtension(coreViews, messageHandlerFactory, "core",
101 UiExtensionManager.class.getClassLoader());
102 }
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -0800103
104 @Activate
105 public void activate() {
106 register(core);
107 log.info("Started");
108 }
109
110 @Deactivate
111 public void deactivate() {
112 unregister(core);
113 log.info("Stopped");
114 }
115
116 @Override
117 public synchronized void register(UiExtension extension) {
118 if (!extensions.contains(extension)) {
119 extensions.add(extension);
120 for (UiView view : extension.views()) {
121 views.put(view.id(), extension);
122 }
123 }
124 }
125
126 @Override
127 public synchronized void unregister(UiExtension extension) {
128 extensions.remove(extension);
Simon Huntc54cd1b2015-05-11 13:43:44 -0700129 extension.views().stream()
130 .map(UiView::id).collect(toSet()).forEach(views::remove);
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -0800131 }
132
133 @Override
134 public synchronized List<UiExtension> getExtensions() {
135 return ImmutableList.copyOf(extensions);
136 }
137
138 @Override
139 public synchronized UiExtension getViewExtension(String viewId) {
140 return views.get(viewId);
141 }
Thomas Vachuska9ed335b2015-04-14 12:07:47 -0700142
Simon Huntc54cd1b2015-05-11 13:43:44 -0700143 // =====================================================================
Thomas Vachuska9ed335b2015-04-14 12:07:47 -0700144 // Provisional tracking of sprite definitions
Simon Huntc54cd1b2015-05-11 13:43:44 -0700145
146 private final Map<String, JsonNode> sprites = Maps.newHashMap();
Thomas Vachuska9ed335b2015-04-14 12:07:47 -0700147
148 @Override
149 public Set<String> getNames() {
150 return ImmutableSet.copyOf(sprites.keySet());
151 }
152
153 @Override
154 public void put(String name, JsonNode spriteData) {
Simon Huntfd8c7d72015-04-14 17:53:37 -0700155 log.info("Registered sprite definition [{}]", name);
Thomas Vachuska9ed335b2015-04-14 12:07:47 -0700156 sprites.put(name, spriteData);
157 }
158
159 @Override
160 public JsonNode get(String name) {
161 return sprites.get(name);
162 }
163
Simon Huntc54cd1b2015-05-11 13:43:44 -0700164
165 // =====================================================================
166 // Topology Overlay API -- pass through to topology message handler
167
168 // NOTE: while WIP, comment out calls to topoHandler (for checked in code)
169 @Override
170 public void addSummaryGenerator(String overlayId, SummaryGenerator generator) {
171 topoHandler.addSummaryGenerator(overlayId, generator);
172 }
173
174 @Override
175 public void removeSummaryGenerator(String overlayId) {
176 topoHandler.removeSummaryGenerator(overlayId);
177 }
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -0800178}