HONEYCOMB-362: bump ODL dependencies to Carbon
[honeycomb.git] / infra / minimal-distribution-core / src / main / java / io / fd / honeycomb / infra / distro / data / ConfigAndOperationalPipelineModule.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.infra.distro.data;
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.data.ModifiableDataManager;
23 import io.fd.honeycomb.data.ReadableDataManager;
24 import io.fd.honeycomb.data.init.DataTreeInitializer;
25 import io.fd.honeycomb.infra.distro.data.config.WriterRegistryProvider;
26 import io.fd.honeycomb.infra.distro.data.oper.ReadableDTDelegProvider;
27 import io.fd.honeycomb.infra.distro.data.oper.ReaderRegistryProvider;
28 import io.fd.honeycomb.rpc.RpcRegistry;
29 import io.fd.honeycomb.rpc.RpcRegistryBuilder;
30 import io.fd.honeycomb.translate.read.registry.ReaderRegistry;
31 import io.fd.honeycomb.translate.write.registry.WriterRegistry;
32 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
33 import org.opendaylight.controller.md.sal.dom.api.DOMDataBroker;
34 import org.opendaylight.controller.md.sal.dom.api.DOMRpcService;
35 import org.opendaylight.controller.md.sal.dom.broker.impl.DOMNotificationRouter;
36 import org.opendaylight.controller.sal.core.api.Broker;
37 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTree;
38
39 public class ConfigAndOperationalPipelineModule extends PrivateModule {
40
41     public static final String HONEYCOMB_CONFIG_NONPERSIST = "honeycomb-config-nopersist";
42     public static final String HONEYCOMB_CONFIG = "honeycomb-config";
43
44     protected void configure() {
45         // Expose registries for plugin reader/writer factories
46         bind(WriterRegistry.class).toProvider(WriterRegistryProvider.class).in(Singleton.class);
47         expose(WriterRegistry.class);
48         bind(ReaderRegistry.class).toProvider(ReaderRegistryProvider.class).in(Singleton.class);
49         expose(ReaderRegistry.class);
50
51         // Non persisting data tree for config
52         bind(DataTree.class).annotatedWith(Names.named(HONEYCOMB_CONFIG_NONPERSIST))
53                 .toProvider(DataTreeProvider.ConfigDataTreeProvider.class).in(Singleton.class);
54         expose(DataTree.class).annotatedWith(Names.named(HONEYCOMB_CONFIG_NONPERSIST));
55         // Persisting data tree wrapper for config
56         bind(DataTree.class).annotatedWith(Names.named(HONEYCOMB_CONFIG))
57                 .toProvider(PersistingDataTreeProvider.ConfigPersistingDataTreeProvider.class).in(Singleton.class);
58         expose(DataTree.class).annotatedWith(Names.named(HONEYCOMB_CONFIG));
59
60         // Config Data Tree manager working on top of config data tree + writer registry
61         bind(ModifiableDataManager.class).toProvider(ModifiableDTDelegProvider.class).in(Singleton.class);
62         // Operational Data Tree manager working on top of reader registry
63         bind(ReadableDataManager.class).toProvider(ReadableDTDelegProvider.class).in(Singleton.class);
64         expose(ReadableDataManager.class);
65
66         // DOMDataBroker wrapper on top of data tree managers
67         HoneycombDOMDataBrokerProvider domBrokerProvider = new HoneycombDOMDataBrokerProvider();
68         bind(DOMDataBroker.class).annotatedWith(Names.named(HONEYCOMB_CONFIG)).toProvider(domBrokerProvider).in(Singleton.class);
69         expose(DOMDataBroker.class).annotatedWith(Names.named(HONEYCOMB_CONFIG));
70
71         // BA version of data broker
72         bind(DataBroker.class).annotatedWith(Names.named(HONEYCOMB_CONFIG)).toProvider(HoneycombBindingDataBrokerProvider.class)
73                 .in(Singleton.class);
74         expose(DataBroker.class).annotatedWith(Names.named(HONEYCOMB_CONFIG));
75
76         // Create initializer to init persisted config data
77         bind(DataTreeInitializer.class).annotatedWith(Names.named(HONEYCOMB_CONFIG))
78                 .toProvider(PersistedConfigInitializerProvider.class)
79                 .in(Singleton.class);
80         expose(DataTreeInitializer.class).annotatedWith(Names.named(HONEYCOMB_CONFIG));
81
82         configureNotifications();
83         configureRpcs();
84     }
85
86     private void configureNotifications() {
87         // Create notification service
88         bind(DOMNotificationRouter.class).toProvider(DOMNotificationServiceProvider.class).in(Singleton.class);
89         expose(DOMNotificationRouter.class);
90         // Wrap notification service, data broker and schema service in a Broker MD-SAL API
91         bind(Broker.class).toProvider(HoneycombDOMBrokerProvider.class).in(Singleton.class);
92         expose(Broker.class);
93     }
94
95     private void configureRpcs() {
96         // Create rpc service
97         bind(DOMRpcService.class).toProvider(HoneycombDOMRpcServiceProvider.class).in(Singleton.class);
98         expose(DOMRpcService.class);
99
100         bind(RpcRegistryBuilder.class).toProvider(RpcRegistryBuilderProvider.class).in(Singleton.class);
101         expose(RpcRegistryBuilder.class);
102
103         bind(RpcRegistry.class).toProvider(RpcRegistryProvider.class).in(Singleton.class);
104         expose(RpcRegistry.class);
105     }
106 }