HONEYCOMB-19 Minimal distro ans wiring for hc infra
[honeycomb.git] / infra / minimal-distribution / src / main / java / io / fd / honeycomb / infra / distro / netconf / NetconfModule.groovy
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.infra.distro.netconf
18
19 import com.google.inject.PrivateModule
20 import com.google.inject.Singleton
21 import com.google.inject.name.Names
22 import io.fd.honeycomb.infra.distro.data.BindingDataBrokerProvider
23 import io.fd.honeycomb.infra.distro.data.DataStoreProvider
24 import io.fd.honeycomb.infra.distro.data.HoneycombNotificationManagerProvider
25 import io.fd.honeycomb.infra.distro.data.InmemoryDOMDataBrokerProvider
26 import io.fd.honeycomb.notification.NotificationCollector
27 import io.netty.channel.nio.NioEventLoopGroup
28 import io.netty.util.Timer
29 import org.opendaylight.controller.md.sal.binding.api.DataBroker
30 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType
31 import org.opendaylight.controller.md.sal.dom.api.DOMDataBroker
32 import org.opendaylight.controller.md.sal.dom.store.impl.InMemoryDOMDataStore
33 import org.opendaylight.controller.sal.binding.api.BindingAwareBroker
34 import org.opendaylight.netconf.api.NetconfServerDispatcher
35 import org.opendaylight.netconf.api.monitoring.NetconfMonitoringService
36 import org.opendaylight.netconf.impl.osgi.AggregatedNetconfOperationServiceFactory
37 import org.opendaylight.netconf.mapping.api.NetconfOperationServiceFactory
38 import org.opendaylight.netconf.mapping.api.NetconfOperationServiceFactoryListener
39 import org.opendaylight.netconf.notifications.NetconfNotificationCollector
40 import org.opendaylight.netconf.notifications.NetconfNotificationListener
41 import org.opendaylight.netconf.notifications.NetconfNotificationRegistry
42 import org.opendaylight.netconf.notifications.impl.NetconfNotificationManager
43
44 import static InmemoryDOMDataBrokerProvider.CONFIG
45 import static InmemoryDOMDataBrokerProvider.OPERATIONAL
46
47 class NetconfModule extends PrivateModule {
48
49     public static final String NETCONF = "netconf"
50     public static final String NETCONF_MAPPER_AGGREGATOR = "netconf-mapper-aggregator"
51     public static final String NETCONF_MAPPER_NOTIFICATION = "netconf-mapper-notification"
52     public static final String NETCONF_MAPPER_MONITORING = "netconf-mapper-monitoring"
53     public static final String NETCONF_MAPPER_HONEYCOMB = "netconf-mapper-honeycomb"
54
55     @Override
56     protected void configure() {
57         bind(InMemoryDOMDataStore)
58                 .annotatedWith(Names.named(CONFIG))
59                 .toProvider(new DataStoreProvider(type: LogicalDatastoreType.CONFIGURATION, name: CONFIG))
60                 .in(Singleton)
61         bind(InMemoryDOMDataStore)
62                 .annotatedWith(Names.named(OPERATIONAL))
63                 .toProvider(new DataStoreProvider(type: LogicalDatastoreType.OPERATIONAL, name: OPERATIONAL))
64                 .in(Singleton)
65         bind(DOMDataBroker).toProvider(InmemoryDOMDataBrokerProvider).in(Singleton)
66
67         bind(DataBroker)
68                 .annotatedWith(Names.named(NETCONF))
69                 .toProvider(BindingDataBrokerProvider)
70                 .in(Singleton)
71         expose(DataBroker).annotatedWith(Names.named(NETCONF))
72         bind(BindingAwareBroker)
73                 .annotatedWith(Names.named(NETCONF))
74                 .toProvider(NetconfBindingBrokerProvider)
75                 .in(Singleton)
76
77         // Mirror of org.opendaylight.controller.config.yang.config.netconf.northbound.impl.NetconfMapperAggregatorModule
78         def factory = new AggregatedNetconfOperationServiceFactory()
79         bind(NetconfOperationServiceFactory)
80                 .annotatedWith(Names.named(NETCONF_MAPPER_AGGREGATOR))
81                 .toInstance(factory)
82         bind(NetconfOperationServiceFactoryListener).toInstance(factory)
83
84         // Mirror of org.opendaylight.controller.config.yang.netconf.northbound.notification.impl.NetconfNotificationManagerModule
85         def manager = new NetconfNotificationManager()
86         bind(NetconfNotificationCollector).toInstance(manager)
87         bind(NetconfNotificationRegistry).toInstance(manager)
88         bind(NetconfNotificationListener).toInstance(manager)
89
90         // Netconf notification part
91         bind(NetconfOperationServiceFactory)
92                 .annotatedWith(Names.named(NETCONF_MAPPER_NOTIFICATION))
93                 .toProvider(NetconfNotificationMapperProvider)
94                 .in(Singleton)
95         expose(NetconfOperationServiceFactory).annotatedWith(Names.named(NETCONF_MAPPER_NOTIFICATION))
96
97         // Netconf core part - mapping between Honeycomb and Netconf
98         bind(NetconfOperationServiceFactory)
99                 .annotatedWith(Names.named(NETCONF_MAPPER_HONEYCOMB))
100                 .toProvider(NetconfMdsalMapperProvider)
101                 .in(Singleton)
102         expose(NetconfOperationServiceFactory).annotatedWith(Names.named(NETCONF_MAPPER_HONEYCOMB))
103
104         // Netconf monitoring part
105         bind(NetconfMonitoringService).toProvider(NetconfMonitoringServiceProvider).in(Singleton)
106         bind(NetconfOperationServiceFactory)
107                 .annotatedWith(Names.named(NETCONF_MAPPER_MONITORING))
108                 .toProvider(NetconfMonitoringMapperProvider)
109                 .in(Singleton)
110         expose(NetconfOperationServiceFactory).annotatedWith(Names.named(NETCONF_MAPPER_MONITORING))
111
112         bind(NotificationCollector).toProvider(HoneycombNotificationManagerProvider).in(Singleton)
113         bind(HoneycombNotification2NetconfProvider.HoneycombNotification2Netconf)
114                 .toProvider(HoneycombNotification2NetconfProvider)
115                 .in(Singleton)
116         expose(HoneycombNotification2NetconfProvider.HoneycombNotification2Netconf)
117
118         configureServer()
119     }
120
121     def configureServer() {
122         bind(NioEventLoopGroup).toProvider(NettyThreadGroupProvider).in(Singleton)
123         bind(Timer).toProvider(NettyTimerProvider).in(Singleton)
124         bind(NetconfServerDispatcher).toProvider(NetconfServerDispatcherProvider).in(Singleton)
125         bind(NetconfTcpServerProvider.NetconfTcpServer).toProvider(NetconfTcpServerProvider).in(Singleton)
126         expose(NetconfTcpServerProvider.NetconfTcpServer)
127         bind(NetconfSshServerProvider.NetconfSshServer).toProvider(NetconfSshServerProvider).in(Singleton)
128         expose(NetconfSshServerProvider.NetconfSshServer)
129     }
130 }