blob: 3f09f6a60e8792d1f1e58481132e322bca3071c2 [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;
22import org.onosproject.ui.UiView;
Ray Milkeyd84f89b2018-08-17 14:54:17 -070023import org.osgi.service.component.annotations.Activate;
24import org.osgi.service.component.annotations.Component;
25import org.osgi.service.component.annotations.Deactivate;
26import org.osgi.service.component.annotations.Reference;
27import org.osgi.service.component.annotations.ReferenceCardinality;
Boyoung Jeong1cca5e82018-08-01 21:00:08 +090028import org.slf4j.Logger;
29import org.slf4j.LoggerFactory;
30
31import java.util.List;
32
33import static org.onosproject.ui.UiView.Category.NETWORK;
34
35/**
36 * Mechanism to stream data to the GUI.
37 */
Ray Milkeyd84f89b2018-08-17 14:54:17 -070038@Component(immediate = true, enabled = true, service = OpensteckTelemetryUI.class)
Boyoung Jeong1cca5e82018-08-01 21:00:08 +090039public class OpensteckTelemetryUI {
40 private static final String OPENSTACKTELEMETRY_ID = "openstacktelemetry";
41 private static final String OPENSTACKTELEMETRY_TEXT = "Openstack Telemetry";
42 private static final String RESOURCE_PATH = "gui";
43 private static final ClassLoader CL = OpensteckTelemetryUI.class.getClassLoader();
44
45 private final Logger log = LoggerFactory.getLogger(getClass());
46
Ray Milkeyd84f89b2018-08-17 14:54:17 -070047 @Reference(cardinality = ReferenceCardinality.MANDATORY)
Boyoung Jeong1cca5e82018-08-01 21:00:08 +090048 protected UiExtensionService uiExtensionService;
49
50 // Factory for UI message handlers
51 private final UiMessageHandlerFactory messageHandlerFactory =
52 () -> ImmutableList.of(new OpensteckTelemetryViewMessageHandler());
53
54 // List of application views
55 private final List<UiView> views = ImmutableList.of(
56 new UiView(NETWORK, OPENSTACKTELEMETRY_ID, OPENSTACKTELEMETRY_TEXT)
57 );
58
59 // Application UI extension
60 private final UiExtension uiExtension =
61 new UiExtension.Builder(CL, views)
62 .messageHandlerFactory(messageHandlerFactory)
63 .resourcePath(RESOURCE_PATH)
64 .build();
65
66 @Activate
67 protected void activate() {
68 uiExtensionService.register(uiExtension);
69 log.info("Started");
70 }
71
72 @Deactivate
73 protected void deactivate() {
74 uiExtensionService.unregister(uiExtension);
75 log.info("Stopped");
76 }
77}