blob: b28b557f010bb8522879eaae3e37897354c93aae [file] [log] [blame]
lishuai10de6db2016-03-22 16:45:44 +08001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2016-present Open Networking Foundation
lishuai10de6db2016-03-22 16:45:44 +08003 *
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.vtnweb.gui;
17
18import static com.google.common.collect.ImmutableList.of;
19import static org.onosproject.ui.UiView.Category.NETWORK;
20import static org.slf4j.LoggerFactory.getLogger;
21
22import java.util.List;
23
24import org.apache.felix.scr.annotations.Activate;
25import org.apache.felix.scr.annotations.Component;
26import org.apache.felix.scr.annotations.Deactivate;
27import org.apache.felix.scr.annotations.Reference;
28import org.apache.felix.scr.annotations.ReferenceCardinality;
29import org.apache.felix.scr.annotations.Service;
30import org.onosproject.ui.UiExtension;
31import org.onosproject.ui.UiExtensionService;
32import org.onosproject.ui.UiMessageHandlerFactory;
33import org.onosproject.ui.UiView;
34import org.slf4j.Logger;
35
36import com.google.common.collect.ImmutableList;
37
38/**
39 * service function chain gui.
40 */
41@Component(immediate = true, enabled = true)
42@Service(value = SfcUiExtensionManager.class)
43public class SfcUiExtensionManager {
44 private final Logger log = getLogger(getClass());
45
46 private static final ClassLoader CL =
47 SfcUiExtensionManager.class.getClassLoader();
48 private static final String GUI = "gui";
49
50 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
51 protected UiExtensionService uiExtensionService;
52
53 // service function chain extension
54 private final UiExtension sfc = createSfcExtension();
55
56 // Creates service function chain UI extension
57 private UiExtension createSfcExtension() {
58 List<UiView> coreViews = of(
59 //TODO add a new type of icon for sfc
60 new UiView(NETWORK, "sfc", "SFC", "nav_sfcs")
61 );
62
63 UiMessageHandlerFactory messageHandlerFactory =
64 () -> ImmutableList.of(
65 new SfcViewMessageHandler()
66 );
67
68 return new UiExtension.Builder(CL, coreViews)
69 .messageHandlerFactory(messageHandlerFactory)
70 .resourcePath(GUI)
71 .build();
72 }
73
74 @Activate
75 public void activate() {
76 uiExtensionService.register(sfc);
77 log.info("Started");
78 }
79
80 @Deactivate
81 public void deactivate() {
82 uiExtensionService.unregister(sfc);
83 log.info("Stopped");
84 }
85}