blob: bf8ae4b37cd13c56a4d10b16284c6aa962c3dafe [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;
19import org.apache.felix.scr.annotations.Activate;
20import org.apache.felix.scr.annotations.Component;
21import org.apache.felix.scr.annotations.Deactivate;
22import org.apache.felix.scr.annotations.Reference;
23import org.apache.felix.scr.annotations.ReferenceCardinality;
24import org.apache.felix.scr.annotations.Service;
25import org.onosproject.ui.UiExtension;
26import org.onosproject.ui.UiExtensionService;
27import org.onosproject.ui.UiMessageHandlerFactory;
28import org.onosproject.ui.UiView;
29import 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 */
39@Component(immediate = true, enabled = true)
40@Service(value = OpensteckTelemetryUI.class)
41public class OpensteckTelemetryUI {
42 private static final String OPENSTACKTELEMETRY_ID = "openstacktelemetry";
43 private static final String OPENSTACKTELEMETRY_TEXT = "Openstack Telemetry";
44 private static final String RESOURCE_PATH = "gui";
45 private static final ClassLoader CL = OpensteckTelemetryUI.class.getClassLoader();
46
47 private final Logger log = LoggerFactory.getLogger(getClass());
48
49 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
50 protected UiExtensionService uiExtensionService;
51
52 // Factory for UI message handlers
53 private final UiMessageHandlerFactory messageHandlerFactory =
54 () -> ImmutableList.of(new OpensteckTelemetryViewMessageHandler());
55
56 // List of application views
57 private final List<UiView> views = ImmutableList.of(
58 new UiView(NETWORK, OPENSTACKTELEMETRY_ID, OPENSTACKTELEMETRY_TEXT)
59 );
60
61 // Application UI extension
62 private final UiExtension uiExtension =
63 new UiExtension.Builder(CL, views)
64 .messageHandlerFactory(messageHandlerFactory)
65 .resourcePath(RESOURCE_PATH)
66 .build();
67
68 @Activate
69 protected void activate() {
70 uiExtensionService.register(uiExtension);
71 log.info("Started");
72 }
73
74 @Deactivate
75 protected void deactivate() {
76 uiExtensionService.unregister(uiExtension);
77 log.info("Stopped");
78 }
79}