2 * Copyright (c) 2016, 2017 Cisco and/or its affiliates.
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:
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 package io.fd.honeycomb.infra.distro.data;
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.data.init.ShutdownHandler;
26 import io.fd.honeycomb.impl.EmptyDomMountService;
27 import io.fd.honeycomb.infra.distro.data.config.WriterRegistryProvider;
28 import io.fd.honeycomb.infra.distro.data.oper.ReadableDTDelegProvider;
29 import io.fd.honeycomb.infra.distro.data.oper.ReaderRegistryProvider;
30 import io.fd.honeycomb.rpc.RpcRegistry;
31 import io.fd.honeycomb.rpc.RpcRegistryBuilder;
32 import io.fd.honeycomb.translate.read.registry.ReaderRegistry;
33 import io.fd.honeycomb.translate.write.registry.WriterRegistry;
34 import org.opendaylight.mdsal.binding.api.DataBroker;
35 import org.opendaylight.mdsal.dom.api.DOMDataBroker;
36 import org.opendaylight.mdsal.dom.api.DOMMountPointService;
37 import org.opendaylight.mdsal.dom.api.DOMRpcService;
38 import org.opendaylight.mdsal.dom.broker.DOMNotificationRouter;
39 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTree;
41 public class ConfigAndOperationalPipelineModule extends PrivateModule {
43 public static final String HONEYCOMB_CONFIG_NONPERSIST = "honeycomb-config-nopersist";
44 public static final String HONEYCOMB_CONFIG = "honeycomb-config";
47 protected void configure() {
48 bind(ShutdownHandler.class).toProvider(ShutdownHandlerProvider.class).in(Singleton.class);
49 expose(ShutdownHandler.class);
51 // Mount point service is required by notification service and restconf
52 bind(DOMMountPointService.class).to(EmptyDomMountService.class).in(Singleton.class);
53 expose(DOMMountPointService.class);
55 // Expose registries for plugin reader/writer factories
56 bind(WriterRegistry.class).toProvider(WriterRegistryProvider.class).in(Singleton.class);
57 expose(WriterRegistry.class);
58 bind(ReaderRegistry.class).toProvider(ReaderRegistryProvider.class).in(Singleton.class);
59 expose(ReaderRegistry.class);
61 // Non persisting data tree for config
62 bind(DataTree.class).annotatedWith(Names.named(HONEYCOMB_CONFIG_NONPERSIST))
63 .toProvider(DataTreeProvider.ConfigDataTreeProvider.class).in(Singleton.class);
64 expose(DataTree.class).annotatedWith(Names.named(HONEYCOMB_CONFIG_NONPERSIST));
65 // Persisting data tree wrapper for config
66 bind(DataTree.class).annotatedWith(Names.named(HONEYCOMB_CONFIG))
67 .toProvider(PersistingDataTreeProvider.ConfigPersistingDataTreeProvider.class).in(Singleton.class);
68 expose(DataTree.class).annotatedWith(Names.named(HONEYCOMB_CONFIG));
70 // Config Data Tree manager working on top of config data tree + writer registry
71 bind(ModifiableDataManager.class).toProvider(ModifiableDTDelegProvider.class).in(Singleton.class);
72 // Operational Data Tree manager working on top of reader registry
73 bind(ReadableDataManager.class).toProvider(ReadableDTDelegProvider.class).in(Singleton.class);
74 expose(ReadableDataManager.class);
76 // DOMDataBroker wrapper on top of data tree managers
77 HoneycombDOMDataBrokerProvider domBrokerProvider = new HoneycombDOMDataBrokerProvider();
78 bind(DOMDataBroker.class).annotatedWith(Names.named(HONEYCOMB_CONFIG)).toProvider(domBrokerProvider).in(Singleton.class);
79 expose(DOMDataBroker.class).annotatedWith(Names.named(HONEYCOMB_CONFIG));
81 // BA version of data broker
82 bind(DataBroker.class).annotatedWith(Names.named(HONEYCOMB_CONFIG)).toProvider(HoneycombBindingDataBrokerProvider.class)
84 expose(DataBroker.class).annotatedWith(Names.named(HONEYCOMB_CONFIG));
86 // Create initializer to init persisted config data
87 bind(DataTreeInitializer.class).annotatedWith(Names.named(HONEYCOMB_CONFIG))
88 .toProvider(PersistedConfigInitializerProvider.class)
90 expose(DataTreeInitializer.class).annotatedWith(Names.named(HONEYCOMB_CONFIG));
92 configureNotifications();
96 private void configureNotifications() {
97 // Create notification service
98 bind(DOMNotificationRouter.class).toProvider(DOMNotificationServiceProvider.class).in(Singleton.class);
99 expose(DOMNotificationRouter.class);
102 private void configureRpcs() {
103 // Create rpc service
104 bind(DOMRpcService.class).toProvider(HoneycombDOMRpcServiceProvider.class).in(Singleton.class);
105 expose(DOMRpcService.class);
107 bind(RpcRegistryBuilder.class).toProvider(RpcRegistryBuilderProvider.class).in(Singleton.class);
108 expose(RpcRegistryBuilder.class);
110 bind(RpcRegistry.class).toProvider(RpcRegistryProvider.class).in(Singleton.class);
111 expose(RpcRegistry.class);