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