9289936acba9f4a1ed04bc3cd1e845b4e2762c3a
[transportpce.git] / tests / honeynode / 1.2.1 / netconf / src / main / java / io / fd / honeycomb / northbound / netconf / NetconfNotificationMapperProvider.java
1 /*
2  * Copyright (c) 2016 Cisco and/or its affiliates.
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
17 package io.fd.honeycomb.northbound.netconf;
18
19 import com.google.inject.Inject;
20 import com.google.inject.name.Named;
21 import io.fd.honeycomb.binding.init.ProviderTrait;
22 import io.fd.honeycomb.data.init.ShutdownHandler;
23 import org.opendaylight.controller.sal.binding.api.BindingAwareBroker;
24 import org.opendaylight.mdsal.binding.api.DataBroker;
25 import org.opendaylight.netconf.mapping.api.NetconfOperationServiceFactory;
26 import org.opendaylight.netconf.mapping.api.NetconfOperationServiceFactoryListener;
27 import org.opendaylight.netconf.mdsal.notification.impl.CapabilityChangeNotificationProducer;
28 import org.opendaylight.netconf.mdsal.notification.impl.NetconfNotificationOperationServiceFactory;
29 import org.opendaylight.netconf.mdsal.notification.impl.NotificationToMdsalWriter;
30 import org.opendaylight.netconf.notifications.NetconfNotificationCollector;
31 import org.opendaylight.netconf.notifications.NetconfNotificationRegistry;
32 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.monitoring.rev101004.NetconfState;
33 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.monitoring.rev101004.netconf.state.Capabilities;
34 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
35 import org.slf4j.Logger;
36 import org.slf4j.LoggerFactory;
37
38
39 public class NetconfNotificationMapperProvider extends ProviderTrait<NetconfOperationServiceFactory> {
40
41     private static final Logger LOG = LoggerFactory.getLogger(NetconfNotificationMapperProvider.class);
42
43     public static final InstanceIdentifier<Capabilities> capabilitiesIdentifier =
44             InstanceIdentifier.create(NetconfState.class).child(Capabilities.class).builder().build();
45     @Inject
46     private NetconfNotificationCollector notificationCollector;
47     @Inject
48     private NetconfNotificationRegistry notificationRegistry;
49     @Inject
50     @Named(NetconfModule.HONEYCOMB_NETCONF)
51     private BindingAwareBroker bindingAwareBroker;
52     @Inject
53     @Named(NetconfModule.HONEYCOMB_NETCONF)
54     private DataBroker dataBroker;
55     @Inject
56     private NetconfOperationServiceFactoryListener aggregator;
57     @Inject
58     private ShutdownHandler shutdownHandler;
59
60     @Override
61     protected NetconfNotificationOperationServiceFactory create() {
62         LOG.trace("Initializing NotificationToMdsalWriter");
63         final NotificationToMdsalWriter writer = new NotificationToMdsalWriter(notificationCollector, dataBroker);
64         writer.start();
65
66         LOG.trace("Initializing CapabilityChangeNotificationProducer");
67         final CapabilityChangeNotificationProducer capabilityChangeNotificationProducer =
68             new CapabilityChangeNotificationProducer(notificationCollector, dataBroker);
69
70         LOG.trace("Providing NetconfNotificationOperationServiceFactory");
71         final NetconfNotificationOperationServiceFactory netconfNotificationOperationServiceFactory =
72             new NetconfNotificationOperationServiceFactory(notificationRegistry, aggregator);
73
74         shutdownHandler.register("netconf-notification-service-factory", netconfNotificationOperationServiceFactory);
75         shutdownHandler.register("capability-change-notification-producer",
76             capabilityChangeNotificationProducer::close);
77         shutdownHandler.register("notification-to-mdsal-writer", writer);
78         return netconfNotificationOperationServiceFactory;
79     }
80 }