blob: b4a59994b7b9a336d9d65a8e10d84c8e7027743b [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;
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -080032import org.slf4j.Logger;
33import org.slf4j.LoggerFactory;
34
35import java.util.List;
36import java.util.Map;
Thomas Vachuska9ed335b2015-04-14 12:07:47 -070037import java.util.Set;
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -080038
39import static com.google.common.collect.ImmutableList.of;
40import static java.util.stream.Collectors.toSet;
Thomas Vachuska8b91f4f2015-04-23 17:55:36 -070041import static org.onosproject.ui.UiView.Category.NETWORK;
42import static org.onosproject.ui.UiView.Category.PLATFORM;
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -080043
44/**
45 * Manages the user interface extensions.
46 */
47@Component(immediate = true)
48@Service
Thomas Vachuska9ed335b2015-04-14 12:07:47 -070049public class UiExtensionManager implements UiExtensionService, SpriteService {
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -080050
51 private final Logger log = LoggerFactory.getLogger(getClass());
52
53 // List of all extensions
54 private final List<UiExtension> extensions = Lists.newArrayList();
55
56 // Map of views to extensions
57 private final Map<String, UiExtension> views = Maps.newHashMap();
58
59 // Core views & core extension
Thomas Vachuska3553b302015-03-07 14:49:43 -080060 private final UiExtension core = createCoreExtension();
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -080061
Thomas Vachuska3553b302015-03-07 14:49:43 -080062
63 // Creates core UI extension
64 private static UiExtension createCoreExtension() {
Simon Hunt20e16792015-04-24 14:29:39 -070065 List<UiView> coreViews = of(
66 new UiView(PLATFORM, "app", "Applications", "nav_apps"),
67 new UiView(PLATFORM, "cluster", "Cluster Nodes", "nav_cluster"),
68 new UiView(NETWORK, "topo", "Topology", "nav_topo"),
69 new UiView(NETWORK, "device", "Devices", "nav_devs"),
70 new UiViewHidden("flow"),
Bri Prebilic Coleac829e42015-05-05 13:42:06 -070071 new UiViewHidden("port"),
Bri Prebilic Coleff3dc672015-05-06 12:59:38 -070072 new UiViewHidden("group"),
Simon Hunt20e16792015-04-24 14:29:39 -070073 new UiView(NETWORK, "link", "Links", "nav_links"),
74 new UiView(NETWORK, "host", "Hosts", "nav_hosts"),
75 new UiView(NETWORK, "intent", "Intents", "nav_intents")
76 );
Simon Hunt1002cd82015-04-23 14:44:03 -070077
Simon Hunt4c7edd32015-03-11 10:42:53 -070078 UiMessageHandlerFactory messageHandlerFactory =
79 () -> ImmutableList.of(
Thomas Vachuskae586b792015-03-26 13:59:38 -070080 new TopologyViewMessageHandler(),
Simon Huntd7f7bcc2015-05-08 14:13:17 -070081// new AltTopoViewMessageHandler(),
Thomas Vachuskae586b792015-03-26 13:59:38 -070082 new DeviceViewMessageHandler(),
Thomas Vachuska583bc632015-04-14 10:10:57 -070083 new LinkViewMessageHandler(),
Thomas Vachuska0fa583c2015-03-30 23:07:41 -070084 new HostViewMessageHandler(),
Bri Prebilic Colecdc188d2015-04-24 16:40:11 -070085 new FlowViewMessageHandler(),
Bri Prebilic Coleac829e42015-05-05 13:42:06 -070086 new PortViewMessageHandler(),
Bri Prebilic Coleff3dc672015-05-06 12:59:38 -070087 new GroupViewMessageHandler(),
Bri Prebilic Cole384e8dc2015-04-13 15:51:14 -070088 new IntentViewMessageHandler(),
Thomas Vachuska583bc632015-04-14 10:10:57 -070089 new ApplicationViewMessageHandler(),
90 new ClusterViewMessageHandler()
Simon Hunt4c7edd32015-03-11 10:42:53 -070091 );
Simon Hunt1002cd82015-04-23 14:44:03 -070092
Thomas Vachuska3553b302015-03-07 14:49:43 -080093 return new UiExtension(coreViews, messageHandlerFactory, "core",
94 UiExtensionManager.class.getClassLoader());
95 }
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -080096
97 @Activate
98 public void activate() {
99 register(core);
100 log.info("Started");
101 }
102
103 @Deactivate
104 public void deactivate() {
105 unregister(core);
106 log.info("Stopped");
107 }
108
109 @Override
110 public synchronized void register(UiExtension extension) {
111 if (!extensions.contains(extension)) {
112 extensions.add(extension);
113 for (UiView view : extension.views()) {
114 views.put(view.id(), extension);
115 }
116 }
117 }
118
119 @Override
120 public synchronized void unregister(UiExtension extension) {
121 extensions.remove(extension);
122 extension.views().stream().map(UiView::id).collect(toSet()).forEach(views::remove);
123 }
124
125 @Override
126 public synchronized List<UiExtension> getExtensions() {
127 return ImmutableList.copyOf(extensions);
128 }
129
130 @Override
131 public synchronized UiExtension getViewExtension(String viewId) {
132 return views.get(viewId);
133 }
Thomas Vachuska9ed335b2015-04-14 12:07:47 -0700134
135
136 // Provisional tracking of sprite definitions
137 private Map<String, JsonNode> sprites = Maps.newHashMap();
138
139 @Override
140 public Set<String> getNames() {
141 return ImmutableSet.copyOf(sprites.keySet());
142 }
143
144 @Override
145 public void put(String name, JsonNode spriteData) {
Simon Huntfd8c7d72015-04-14 17:53:37 -0700146 log.info("Registered sprite definition [{}]", name);
Thomas Vachuska9ed335b2015-04-14 12:07:47 -0700147 sprites.put(name, spriteData);
148 }
149
150 @Override
151 public JsonNode get(String name) {
152 return sprites.get(name);
153 }
154
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -0800155}