import io.lighty.core.controller.api.AbstractLightyModule;
import io.lighty.core.controller.api.LightyServices;
-
-import java.util.Arrays;
-import java.util.List;
-
import org.opendaylight.transportpce.common.crossconnect.CrossConnect;
import org.opendaylight.transportpce.common.crossconnect.CrossConnectImpl;
import org.opendaylight.transportpce.common.crossconnect.CrossConnectImpl121;
private TapiProvider tapiProvider;
// nbi-notifications beans
private NbiNotificationsProvider nbiNotificationsProvider;
- /**
- * List of publisher topics.
- */
- private final List<String> publisherServiceList = Arrays.asList("PceListener", "ServiceHandlerOperations",
- "ServiceHandler", "RendererListener");
- private final List<String> publisherAlarmList = Arrays.asList("ServiceListener");
public TransportPCEImpl(LightyServices lightyServices, boolean activateNbiNotification, boolean activateTapi,
String olmtimer1, String olmtimer2) {
if (activateNbiNotification) {
LOG.info("Creating nbi-notifications beans ...");
nbiNotificationsProvider = new NbiNotificationsProvider(
- publisherServiceList, publisherAlarmList, null, null, lightyServices.getRpcProviderService(),
+ null, null, lightyServices.getRpcProviderService(),
lightyServices.getNotificationService(), lightyServices.getAdapterContext().currentSerializer(),
networkTransaction);
}
}
if (nbiNotificationsProvider != null) {
LOG.info("Initializing nbi-notifications provider ...");
- nbiNotificationsProvider.init();
}
LOG.info("Init done.");
return true;
*/
package org.opendaylight.transportpce.nbinotifications.impl;
+import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.notification.rev181210.TapiNotificationService;
import org.opendaylight.yangtools.concepts.ListenerRegistration;
import org.opendaylight.yangtools.concepts.ObjectRegistration;
+import org.osgi.service.component.annotations.Activate;
+import org.osgi.service.component.annotations.Component;
+import org.osgi.service.component.annotations.Deactivate;
+import org.osgi.service.component.annotations.Reference;
+import org.osgi.service.metatype.annotations.AttributeDefinition;
+import org.osgi.service.metatype.annotations.ObjectClassDefinition;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+@Component(configurationPid = "org.opendaylight.transportpce.nbinotifications")
public class NbiNotificationsProvider {
+ @ObjectClassDefinition
+ public @interface Configuration {
+ @AttributeDefinition
+ String suscriberServer() default "";
+ @AttributeDefinition
+ String publisherServer() default "";
+ }
+
private static final Logger LOG = LoggerFactory.getLogger(NbiNotificationsProvider.class);
private static Map<String, Publisher<NotificationProcessService>> publishersServiceMap = new HashMap<>();
private static Map<String, Publisher<NotificationAlarmService>> publishersAlarmMap = new HashMap<>();
- private final RpcProviderService rpcService;
- private final NotificationService notificationService;
- private final JsonStringConverter<NotificationProcessService> converterService;
- private final JsonStringConverter<NotificationAlarmService> converterAlarmService;
- private final JsonStringConverter<NotificationTapiService> converterTapiService;
- private final String subscriberServer;
- private ObjectRegistration<NbiNotificationsService> rpcRegistration;
private ListenerRegistration<NbiNotificationsListener> listenerRegistration;
- private TopicManager topicManager = TopicManager.getInstance();
- private final NetworkTransactionService networkTransactionService;
+ private List<ObjectRegistration<NbiNotificationsImpl>> rpcRegistrations = new ArrayList<>();
+ @Activate
+ public NbiNotificationsProvider(@Reference RpcProviderService rpcProviderService,
+ @Reference NotificationService notificationService,
+ @Reference BindingDOMCodecServices bindingDOMCodecServices,
+ @Reference NetworkTransactionService networkTransactionService,
+ final Configuration configuration) {
+ this(configuration.suscriberServer(), configuration.publisherServer(), rpcProviderService, notificationService,
+ bindingDOMCodecServices, networkTransactionService);
+ }
- public NbiNotificationsProvider(List<String> publishersService, List<String> publishersAlarm,
- String subscriberServer, String publisherServer,
- RpcProviderService rpcProviderService, NotificationService notificationService,
- BindingDOMCodecServices bindingDOMCodecServices,
- NetworkTransactionService networkTransactionService) {
- this.rpcService = rpcProviderService;
- this.notificationService = notificationService;
- this.topicManager.setPublisherServer(publisherServer);
- converterService = new JsonStringConverter<>(bindingDOMCodecServices);
- this.topicManager.setProcessConverter(converterService);
- for (String publisherService: publishersService) {
+ public NbiNotificationsProvider(String subscriberServer, String publisherServer,
+ RpcProviderService rpcProviderService, NotificationService notificationService,
+ BindingDOMCodecServices bindingDOMCodecServices, NetworkTransactionService networkTransactionService) {
+ List<String> publishersServiceList = List.of("PceListener", "ServiceHandlerOperations", "ServiceHandler",
+ "RendererListener");
+ TopicManager topicManager = TopicManager.getInstance();
+ topicManager.setPublisherServer(publisherServer);
+ JsonStringConverter<NotificationProcessService> converterService =
+ new JsonStringConverter<>(bindingDOMCodecServices);
+ topicManager.setProcessConverter(converterService);
+ for (String publisherService: publishersServiceList) {
LOG.info("Creating publisher for the following class {}", publisherService);
- this.topicManager.addProcessTopic(publisherService);
+ topicManager.addProcessTopic(publisherService);
}
- converterAlarmService = new JsonStringConverter<>(bindingDOMCodecServices);
- this.topicManager.setAlarmConverter(converterAlarmService);
- for (String publisherAlarm: publishersAlarm) {
+ JsonStringConverter<NotificationAlarmService> converterAlarmService =
+ new JsonStringConverter<>(bindingDOMCodecServices);
+ topicManager.setAlarmConverter(converterAlarmService);
+ List<String> publishersAlarmList = List.of("ServiceListener");
+ for (String publisherAlarm: publishersAlarmList) {
LOG.info("Creating publisher for the following class {}", publisherAlarm);
- this.topicManager.addAlarmTopic(publisherAlarm);
+ topicManager.addAlarmTopic(publisherAlarm);
}
- this.subscriberServer = subscriberServer;
- converterTapiService = new JsonStringConverter<>(bindingDOMCodecServices);
+ JsonStringConverter<NotificationTapiService> converterTapiService =
+ new JsonStringConverter<>(bindingDOMCodecServices);
LOG.info("baozhi tapi converter: {}", converterTapiService);
- this.topicManager.setTapiConverter(converterTapiService);
- this.networkTransactionService = networkTransactionService;
- }
+ topicManager.setTapiConverter(converterTapiService);
- /**
- * Method called when the blueprint container is created.
- */
- public void init() {
- LOG.info("NbiNotificationsProvider Session Initiated");
NbiNotificationsImpl nbiImpl = new NbiNotificationsImpl(converterService, converterAlarmService,
- converterTapiService, subscriberServer, this.networkTransactionService, this.topicManager);
- rpcRegistration = rpcService.registerRpcImplementation(NbiNotificationsService.class, nbiImpl);
- rpcService.registerRpcImplementation(TapiNotificationService.class, nbiImpl);
- NbiNotificationsListenerImpl nbiNotificationsListener =
- new NbiNotificationsListenerImpl(this.topicManager.getProcessTopicMap(),
- this.topicManager.getAlarmTopicMap(), this.topicManager.getTapiTopicMap());
+ converterTapiService, subscriberServer, networkTransactionService, topicManager);
+ rpcRegistrations.add(rpcProviderService.registerRpcImplementation(NbiNotificationsService.class, nbiImpl));
+ rpcRegistrations.add(rpcProviderService.registerRpcImplementation(TapiNotificationService.class, nbiImpl));
+ NbiNotificationsListenerImpl nbiNotificationsListener = new NbiNotificationsListenerImpl(
+ topicManager.getProcessTopicMap(), topicManager.getAlarmTopicMap(), topicManager.getTapiTopicMap());
listenerRegistration = notificationService.registerNotificationListener(nbiNotificationsListener);
- this.topicManager.setNbiNotificationsListener(nbiNotificationsListener);
+ topicManager.setNbiNotificationsListener(nbiNotificationsListener);
+ LOG.info("NbiNotificationsProvider Session Initiated");
}
/**
* Method called when the blueprint container is destroyed.
*/
+ @Deactivate
public void close() {
for (Publisher<NotificationProcessService> publisher : publishersServiceMap.values()) {
publisher.close();
for (Publisher<NotificationAlarmService> publisherAlarm : publishersAlarmMap.values()) {
publisherAlarm.close();
}
- rpcRegistration.close();
+ rpcRegistrations.forEach(reg -> reg.close());
listenerRegistration.close();
LOG.info("NbiNotificationsProvider Closed");
}
-
}
+++ /dev/null
-<?xml version="1.0" encoding="UTF-8"?>
-<!-- vi: set et smarttab sw=4 tabstop=4: -->
-<!-- Copyright © 2020 Orange and others. All rights reserved. This program and the accompanying materials
- are made available under the terms of the Eclipse Public License v1.0 which accompanies this distribution,
- and is available at http://www.eclipse.org/legal/epl-v10.html -->
-<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
- xmlns:cm="http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.1.0">
- <cm:property-placeholder persistent-id="org.opendaylight.transportpce.nbinotifications" update-strategy="reload">
- <cm:default-properties>
- <cm:property name="suscriber.server" value="" />
- <cm:property name="publisher.server" value="" />
- </cm:default-properties>
- </cm:property-placeholder>
- <reference id="rpcService" interface="org.opendaylight.mdsal.binding.api.RpcProviderService"/>
- <reference id="notificationService" interface="org.opendaylight.mdsal.binding.api.NotificationService"/>
- <reference id="bindingDOMCodecServices" interface="org.opendaylight.mdsal.binding.dom.codec.spi.BindingDOMCodecServices" />
- <reference id="networkTransactionImpl"
- interface="org.opendaylight.transportpce.common.network.NetworkTransactionService" />
- <bean id="provider"
- class="org.opendaylight.transportpce.nbinotifications.impl.NbiNotificationsProvider"
- init-method="init" destroy-method="close">
- <argument>
- <list value-type="java.lang.String">
- <value>PceListener</value>
- <value>ServiceHandlerOperations</value>
- <value>ServiceHandler</value>
- <value>RendererListener</value>
- </list>
- </argument>
- <argument>
- <list value-type="java.lang.String">
- <value>ServiceListener</value>
- </list>
- </argument>
- <argument value="${suscriber.server}"/>
- <argument value="${publisher.server}"/>
- <argument ref="rpcService" />
- <argument ref="notificationService" />
- <argument ref="bindingDOMCodecServices" />
- <argument ref="networkTransactionImpl" />
- </bean>
-</blueprint>