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