blob: da987c9151406f351961f089e801581a1ef4f2d5 [file] [log] [blame]
Boyoung Jeong1cca5e82018-08-01 21:00:08 +09001/*
2 * Copyright 2018-present Open Networking Foundation
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.openstacktelemetry.gui;
17
18import com.google.common.collect.ImmutableList;
Boyoung Jeong1cca5e82018-08-01 21:00:08 +090019import org.onosproject.ui.UiExtension;
20import org.onosproject.ui.UiExtensionService;
21import org.onosproject.ui.UiMessageHandlerFactory;
boyoung2a8549d22018-11-23 20:42:37 +090022import org.onosproject.ui.UiTopoOverlayFactory;
Boyoung Jeong1cca5e82018-08-01 21:00:08 +090023import org.onosproject.ui.UiView;
Ray Milkeyd84f89b2018-08-17 14:54:17 -070024import org.osgi.service.component.annotations.Activate;
25import org.osgi.service.component.annotations.Component;
26import org.osgi.service.component.annotations.Deactivate;
27import org.osgi.service.component.annotations.Reference;
28import org.osgi.service.component.annotations.ReferenceCardinality;
Boyoung Jeong1cca5e82018-08-01 21:00:08 +090029import org.slf4j.Logger;
30import org.slf4j.LoggerFactory;
31
32import java.util.List;
33
34import static org.onosproject.ui.UiView.Category.NETWORK;
35
36/**
37 * Mechanism to stream data to the GUI.
38 */
Ray Milkeyd84f89b2018-08-17 14:54:17 -070039@Component(immediate = true, enabled = true, service = OpensteckTelemetryUI.class)
Boyoung Jeong1cca5e82018-08-01 21:00:08 +090040public class OpensteckTelemetryUI {
41 private static final String OPENSTACKTELEMETRY_ID = "openstacktelemetry";
42 private static final String OPENSTACKTELEMETRY_TEXT = "Openstack Telemetry";
43 private static final String RESOURCE_PATH = "gui";
44 private static final ClassLoader CL = OpensteckTelemetryUI.class.getClassLoader();
45
46 private final Logger log = LoggerFactory.getLogger(getClass());
47
Ray Milkeyd84f89b2018-08-17 14:54:17 -070048 @Reference(cardinality = ReferenceCardinality.MANDATORY)
Boyoung Jeong1cca5e82018-08-01 21:00:08 +090049 protected UiExtensionService uiExtensionService;
50
51 // Factory for UI message handlers
52 private final UiMessageHandlerFactory messageHandlerFactory =
53 () -> ImmutableList.of(new OpensteckTelemetryViewMessageHandler());
54
55 // List of application views
56 private final List<UiView> views = ImmutableList.of(
57 new UiView(NETWORK, OPENSTACKTELEMETRY_ID, OPENSTACKTELEMETRY_TEXT)
58 );
59
boyoung2a8549d22018-11-23 20:42:37 +090060 // Factory for UI topology overlays
61 private final UiTopoOverlayFactory topoOverlayFactory =
62 () -> ImmutableList.of(
63 new OpenstackTelemetryUiTopovOverlay()
64 );
65
Boyoung Jeong1cca5e82018-08-01 21:00:08 +090066 // Application UI extension
67 private final UiExtension uiExtension =
68 new UiExtension.Builder(CL, views)
69 .messageHandlerFactory(messageHandlerFactory)
70 .resourcePath(RESOURCE_PATH)
boyoung2a8549d22018-11-23 20:42:37 +090071 .topoOverlayFactory(topoOverlayFactory)
Boyoung Jeong1cca5e82018-08-01 21:00:08 +090072 .build();
73
74 @Activate
75 protected void activate() {
76 uiExtensionService.register(uiExtension);
77 log.info("Started");
78 }
79
80 @Deactivate
81 protected void deactivate() {
82 uiExtensionService.unregister(uiExtension);
83 log.info("Stopped");
84 }
85}