diff options
Diffstat (limited to 'infra/minimal-distribution-core/src/main/java/io/fd/honeycomb/infra/distro/data')
21 files changed, 1054 insertions, 0 deletions
diff --git a/infra/minimal-distribution-core/src/main/java/io/fd/honeycomb/infra/distro/data/BindingDataBrokerProvider.java b/infra/minimal-distribution-core/src/main/java/io/fd/honeycomb/infra/distro/data/BindingDataBrokerProvider.java new file mode 100644 index 000000000..e17355143 --- /dev/null +++ b/infra/minimal-distribution-core/src/main/java/io/fd/honeycomb/infra/distro/data/BindingDataBrokerProvider.java @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2016 Cisco and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.fd.honeycomb.infra.distro.data; + +import com.google.inject.Inject; +import io.fd.honeycomb.infra.distro.ProviderTrait; +import org.opendaylight.controller.md.sal.binding.api.DataBroker; +import org.opendaylight.controller.md.sal.binding.impl.BindingDOMDataBrokerAdapter; +import org.opendaylight.controller.md.sal.binding.impl.BindingToNormalizedNodeCodec; +import org.opendaylight.controller.md.sal.dom.api.DOMDataBroker; + +public final class BindingDataBrokerProvider extends ProviderTrait<DataBroker> { + + @Inject + private DOMDataBroker domDataBroker; + @Inject + private BindingToNormalizedNodeCodec mappingService; + + @Override + protected BindingDOMDataBrokerAdapter create() { + return new BindingDOMDataBrokerAdapter(domDataBroker, mappingService); + } +} diff --git a/infra/minimal-distribution-core/src/main/java/io/fd/honeycomb/infra/distro/data/ConfigAndOperationalPipelineModule.java b/infra/minimal-distribution-core/src/main/java/io/fd/honeycomb/infra/distro/data/ConfigAndOperationalPipelineModule.java new file mode 100644 index 000000000..55f9d989c --- /dev/null +++ b/infra/minimal-distribution-core/src/main/java/io/fd/honeycomb/infra/distro/data/ConfigAndOperationalPipelineModule.java @@ -0,0 +1,106 @@ +/* + * Copyright (c) 2016 Cisco and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.fd.honeycomb.infra.distro.data; + +import com.google.inject.PrivateModule; +import com.google.inject.Singleton; +import com.google.inject.name.Names; +import io.fd.honeycomb.data.ModifiableDataManager; +import io.fd.honeycomb.data.ReadableDataManager; +import io.fd.honeycomb.data.init.DataTreeInitializer; +import io.fd.honeycomb.infra.distro.data.config.WriterRegistryProvider; +import io.fd.honeycomb.infra.distro.data.oper.ReadableDTDelegProvider; +import io.fd.honeycomb.infra.distro.data.oper.ReaderRegistryProvider; +import io.fd.honeycomb.infra.distro.initializer.PersistedFileInitializerProvider; +import io.fd.honeycomb.rpc.RpcRegistry; +import io.fd.honeycomb.rpc.RpcRegistryBuilder; +import io.fd.honeycomb.translate.read.registry.ReaderRegistry; +import io.fd.honeycomb.translate.write.registry.WriterRegistry; +import org.opendaylight.controller.md.sal.binding.api.DataBroker; +import org.opendaylight.controller.md.sal.dom.api.DOMDataBroker; +import org.opendaylight.controller.md.sal.dom.api.DOMRpcService; +import org.opendaylight.controller.md.sal.dom.broker.impl.DOMNotificationRouter; +import org.opendaylight.controller.sal.core.api.Broker; +import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTree; + +public class ConfigAndOperationalPipelineModule extends PrivateModule { + + public static final String HONEYCOMB_CONFIG_NONPERSIST = "honeycomb-config-nopersist"; + public static final String HONEYCOMB_CONFIG = "honeycomb-config"; + + protected void configure() { + // Expose registries for plugin reader/writer factories + bind(WriterRegistry.class).toProvider(WriterRegistryProvider.class).in(Singleton.class); + expose(WriterRegistry.class); + bind(ReaderRegistry.class).toProvider(ReaderRegistryProvider.class).in(Singleton.class); + expose(ReaderRegistry.class); + + // Non persisting data tree for config + bind(DataTree.class).annotatedWith(Names.named(HONEYCOMB_CONFIG_NONPERSIST)) + .toProvider(DataTreeProvider.ConfigDataTreeProvider.class).in(Singleton.class); + expose(DataTree.class).annotatedWith(Names.named(HONEYCOMB_CONFIG_NONPERSIST)); + // Persisting data tree wrapper for config + bind(DataTree.class).annotatedWith(Names.named(HONEYCOMB_CONFIG)) + .toProvider(PersistingDataTreeProvider.ConfigPersistingDataTreeProvider.class).in(Singleton.class); + expose(DataTree.class).annotatedWith(Names.named(HONEYCOMB_CONFIG)); + + // Config Data Tree manager working on top of config data tree + writer registry + bind(ModifiableDataManager.class).toProvider(ModifiableDTDelegProvider.class).in(Singleton.class); + // Operational Data Tree manager working on top of reader registry + bind(ReadableDataManager.class).toProvider(ReadableDTDelegProvider.class).in(Singleton.class); + expose(ReadableDataManager.class); + + // DOMDataBroker wrapper on top of data tree managers + HoneycombDOMDataBrokerProvider domBrokerProvider = new HoneycombDOMDataBrokerProvider(); + bind(DOMDataBroker.class).toProvider(domBrokerProvider).in(Singleton.class); + + // BA version of data broker + bind(DataBroker.class).annotatedWith(Names.named(HONEYCOMB_CONFIG)).toProvider(BindingDataBrokerProvider.class) + .in(Singleton.class); + expose(DataBroker.class).annotatedWith(Names.named(HONEYCOMB_CONFIG)); + + // Create initializer to init persisted config data + bind(DataTreeInitializer.class).annotatedWith(Names.named(HONEYCOMB_CONFIG)) + .toProvider(PersistedFileInitializerProvider.PersistedConfigInitializerProvider.class) + .in(Singleton.class); + expose(DataTreeInitializer.class).annotatedWith(Names.named(HONEYCOMB_CONFIG)); + + configureNotifications(); + configureRpcs(); + } + + private void configureNotifications() { + // Create notification service + bind(DOMNotificationRouter.class).toProvider(DOMNotificationServiceProvider.class).in(Singleton.class); + expose(DOMNotificationRouter.class); + // Wrap notification service, data broker and schema service in a Broker MD-SAL API + bind(Broker.class).toProvider(HoneycombDOMBrokerProvider.class).in(Singleton.class); + expose(Broker.class); + } + + private void configureRpcs() { + // Create rpc service + bind(DOMRpcService.class).toProvider(HoneycombDOMRpcServiceProvider.class).in(Singleton.class); + expose(DOMRpcService.class); + + bind(RpcRegistryBuilder.class).toProvider(RpcRegistryBuilderProvider.class).in(Singleton.class); + expose(RpcRegistryBuilder.class); + + bind(RpcRegistry.class).toProvider(RpcRegistryProvider.class).in(Singleton.class); + expose(RpcRegistry.class); + } +} diff --git a/infra/minimal-distribution-core/src/main/java/io/fd/honeycomb/infra/distro/data/DOMNotificationServiceProvider.java b/infra/minimal-distribution-core/src/main/java/io/fd/honeycomb/infra/distro/data/DOMNotificationServiceProvider.java new file mode 100644 index 000000000..424393b8d --- /dev/null +++ b/infra/minimal-distribution-core/src/main/java/io/fd/honeycomb/infra/distro/data/DOMNotificationServiceProvider.java @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2016 Cisco and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.fd.honeycomb.infra.distro.data; + +import com.google.inject.Inject; +import io.fd.honeycomb.infra.distro.ProviderTrait; +import io.fd.honeycomb.infra.distro.cfgattrs.HoneycombConfiguration; +import org.opendaylight.controller.md.sal.dom.broker.impl.DOMNotificationRouter; + +public final class DOMNotificationServiceProvider extends ProviderTrait<DOMNotificationRouter> { + + @Inject + private HoneycombConfiguration cfg; + + @Override + protected DOMNotificationRouter create() { + return DOMNotificationRouter.create(cfg.notificationServiceQueueDepth); + } +} diff --git a/infra/minimal-distribution-core/src/main/java/io/fd/honeycomb/infra/distro/data/DataStoreProvider.java b/infra/minimal-distribution-core/src/main/java/io/fd/honeycomb/infra/distro/data/DataStoreProvider.java new file mode 100644 index 000000000..5b09f21f8 --- /dev/null +++ b/infra/minimal-distribution-core/src/main/java/io/fd/honeycomb/infra/distro/data/DataStoreProvider.java @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2016 Cisco and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.fd.honeycomb.infra.distro.data; + +import com.google.inject.Inject; +import io.fd.honeycomb.infra.distro.ProviderTrait; +import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType; +import org.opendaylight.controller.md.sal.dom.store.impl.InMemoryDOMDataStore; +import org.opendaylight.controller.md.sal.dom.store.impl.InMemoryDOMDataStoreFactory; +import org.opendaylight.controller.sal.core.api.model.SchemaService; + +public final class DataStoreProvider extends ProviderTrait<InMemoryDOMDataStore> { + + @Inject + private SchemaService schemaService; + private String name; + private LogicalDatastoreType type; + + public DataStoreProvider(final String name, + final LogicalDatastoreType type) { + this.name = name; + this.type = type; + } + + @Override + protected InMemoryDOMDataStore create() { + return InMemoryDOMDataStoreFactory.create(name, type, schemaService, false, null); + } +} diff --git a/infra/minimal-distribution-core/src/main/java/io/fd/honeycomb/infra/distro/data/DataTreeProvider.java b/infra/minimal-distribution-core/src/main/java/io/fd/honeycomb/infra/distro/data/DataTreeProvider.java new file mode 100644 index 000000000..c5fcc050a --- /dev/null +++ b/infra/minimal-distribution-core/src/main/java/io/fd/honeycomb/infra/distro/data/DataTreeProvider.java @@ -0,0 +1,56 @@ +/* + * Copyright (c) 2016 Cisco and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.fd.honeycomb.infra.distro.data; + +import com.google.inject.Inject; +import io.fd.honeycomb.infra.distro.ProviderTrait; +import io.fd.honeycomb.infra.distro.cfgattrs.HoneycombConfiguration; +import org.opendaylight.controller.sal.core.api.model.SchemaService; +import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTree; +import org.opendaylight.yangtools.yang.data.api.schema.tree.TipProducingDataTree; +import org.opendaylight.yangtools.yang.data.api.schema.tree.TreeType; +import org.opendaylight.yangtools.yang.data.impl.schema.tree.InMemoryDataTreeFactory; + +public abstract class DataTreeProvider extends ProviderTrait<DataTree> { + + @Inject + private SchemaService schemaService; + @Inject + private HoneycombConfiguration config; + + public TipProducingDataTree create() { + TipProducingDataTree delegate = InMemoryDataTreeFactory.getInstance().create(getType()); + delegate.setSchemaContext(schemaService.getGlobalContext()); + return delegate; + } + + public abstract TreeType getType(); + + public static class ConfigDataTreeProvider extends DataTreeProvider { + public TreeType getType() { + return TreeType.CONFIGURATION; + } + + } + + public static class ContextDataTreeProvider extends DataTreeProvider { + public TreeType getType() { + return TreeType.OPERATIONAL; + } + + } +} diff --git a/infra/minimal-distribution-core/src/main/java/io/fd/honeycomb/infra/distro/data/HoneycombDOMBrokerProvider.java b/infra/minimal-distribution-core/src/main/java/io/fd/honeycomb/infra/distro/data/HoneycombDOMBrokerProvider.java new file mode 100644 index 000000000..dd34c6c6f --- /dev/null +++ b/infra/minimal-distribution-core/src/main/java/io/fd/honeycomb/infra/distro/data/HoneycombDOMBrokerProvider.java @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2016 Cisco and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.fd.honeycomb.infra.distro.data; + +import com.google.inject.Inject; +import io.fd.honeycomb.impl.NorthboundFacadeHoneycombDOMBroker; +import io.fd.honeycomb.infra.distro.ProviderTrait; +import org.opendaylight.controller.md.sal.dom.api.DOMDataBroker; +import org.opendaylight.controller.md.sal.dom.api.DOMRpcService; +import org.opendaylight.controller.md.sal.dom.broker.impl.DOMNotificationRouter; +import org.opendaylight.controller.sal.core.api.Broker; +import org.opendaylight.controller.sal.core.api.model.SchemaService; + +public final class HoneycombDOMBrokerProvider extends ProviderTrait<Broker> { + + @Inject + private DOMDataBroker domDataBroker; + @Inject + private SchemaService schemaService; + @Inject + private DOMNotificationRouter domNotificationService; + @Inject + private DOMRpcService domRpcService; + + @Override + protected NorthboundFacadeHoneycombDOMBroker create() { + return new NorthboundFacadeHoneycombDOMBroker(domDataBroker, schemaService, domNotificationService, + domRpcService); + } +} diff --git a/infra/minimal-distribution-core/src/main/java/io/fd/honeycomb/infra/distro/data/HoneycombDOMDataBrokerProvider.java b/infra/minimal-distribution-core/src/main/java/io/fd/honeycomb/infra/distro/data/HoneycombDOMDataBrokerProvider.java new file mode 100644 index 000000000..92bbc512d --- /dev/null +++ b/infra/minimal-distribution-core/src/main/java/io/fd/honeycomb/infra/distro/data/HoneycombDOMDataBrokerProvider.java @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2016 Cisco and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.fd.honeycomb.infra.distro.data; + +import com.google.inject.Inject; +import io.fd.honeycomb.data.ModifiableDataManager; +import io.fd.honeycomb.data.ReadableDataManager; +import io.fd.honeycomb.data.impl.DataBroker; +import io.fd.honeycomb.infra.distro.ProviderTrait; +import org.opendaylight.controller.md.sal.dom.api.DOMDataBroker; + +public final class HoneycombDOMDataBrokerProvider extends ProviderTrait<DOMDataBroker> { + + @Inject + private ModifiableDataManager modDataManager; + @Inject(optional = true) + private ReadableDataManager readDataManager; + + protected DataBroker create() { + return readDataManager != null + ? DataBroker.create(modDataManager, readDataManager) + : DataBroker.create(modDataManager); + } +} diff --git a/infra/minimal-distribution-core/src/main/java/io/fd/honeycomb/infra/distro/data/HoneycombDOMRpcServiceProvider.java b/infra/minimal-distribution-core/src/main/java/io/fd/honeycomb/infra/distro/data/HoneycombDOMRpcServiceProvider.java new file mode 100644 index 000000000..0459b2fef --- /dev/null +++ b/infra/minimal-distribution-core/src/main/java/io/fd/honeycomb/infra/distro/data/HoneycombDOMRpcServiceProvider.java @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2016 Cisco and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.fd.honeycomb.infra.distro.data; + +import com.google.inject.Inject; +import io.fd.honeycomb.infra.distro.ProviderTrait; +import io.fd.honeycomb.rpc.HoneycombDOMRpcService; +import io.fd.honeycomb.rpc.RpcRegistry; +import org.opendaylight.controller.md.sal.binding.impl.BindingToNormalizedNodeCodec; +import org.opendaylight.controller.md.sal.dom.api.DOMRpcService; + +public final class HoneycombDOMRpcServiceProvider extends ProviderTrait<DOMRpcService> { + + @Inject + private BindingToNormalizedNodeCodec serializer; + + @Inject + private RpcRegistry rpcRegistry; + + @Override + protected DOMRpcService create() { + return new HoneycombDOMRpcService(serializer, rpcRegistry); + } +} diff --git a/infra/minimal-distribution-core/src/main/java/io/fd/honeycomb/infra/distro/data/HoneycombNotificationManagerProvider.java b/infra/minimal-distribution-core/src/main/java/io/fd/honeycomb/infra/distro/data/HoneycombNotificationManagerProvider.java new file mode 100644 index 000000000..f2e81a9f6 --- /dev/null +++ b/infra/minimal-distribution-core/src/main/java/io/fd/honeycomb/infra/distro/data/HoneycombNotificationManagerProvider.java @@ -0,0 +1,68 @@ +/* + * Copyright (c) 2016 Cisco and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.fd.honeycomb.infra.distro.data; + +import com.google.common.collect.Lists; +import com.google.inject.Inject; +import io.fd.honeycomb.infra.distro.ProviderTrait; +import io.fd.honeycomb.notification.ManagedNotificationProducer; +import io.fd.honeycomb.notification.NotificationCollector; +import io.fd.honeycomb.notification.impl.HoneycombNotificationCollector; +import io.fd.honeycomb.notification.impl.NotificationProducerRegistry; +import io.fd.honeycomb.notification.impl.NotificationProducerTracker; +import java.util.HashSet; +import java.util.Set; +import org.opendaylight.controller.md.sal.binding.impl.BindingDOMNotificationPublishServiceAdapter; +import org.opendaylight.controller.md.sal.binding.impl.BindingToNormalizedNodeCodec; +import org.opendaylight.controller.md.sal.dom.broker.impl.DOMNotificationRouter; + +public final class HoneycombNotificationManagerProvider extends ProviderTrait<NotificationCollector> { + + @Inject + private DOMNotificationRouter notificationRouter; + @Inject(optional = true) + private Set<ManagedNotificationProducer> notificationProducers = new HashSet<>(); + @Inject + private BindingToNormalizedNodeCodec codec; + + @Override + protected HoneycombNotificationCollector create() { + // Create the registry to keep track of what'OPERATIONAL registered + NotificationProducerRegistry notificationProducerRegistry = + new NotificationProducerRegistry(Lists.newArrayList(notificationProducers)); + + // Create BA version of notification service (implementation is free from ODL) + BindingDOMNotificationPublishServiceAdapter bindingDOMNotificationPublishServiceAdapter = + new BindingDOMNotificationPublishServiceAdapter(codec, notificationRouter); + + // Create Collector on top of BA notification service and registry + HoneycombNotificationCollector honeycombNotificationCollector = + new HoneycombNotificationCollector(bindingDOMNotificationPublishServiceAdapter, + notificationProducerRegistry); + + // Create tracker, responsible for starting and stopping registered notification producers whenever necessary + NotificationProducerTracker notificationProducerTracker = + new NotificationProducerTracker(notificationProducerRegistry, honeycombNotificationCollector, + notificationRouter); + + // DOMNotificationService is already provided by DOMBroker injected into RESTCONF, however RESTCONF + // only supports data-change notification, nothing else. So currently (Beryllium-SR2) honeycomb notifications + // won't be available over RESTCONF. + + return honeycombNotificationCollector; + } +} diff --git a/infra/minimal-distribution-core/src/main/java/io/fd/honeycomb/infra/distro/data/InmemoryDOMDataBrokerProvider.java b/infra/minimal-distribution-core/src/main/java/io/fd/honeycomb/infra/distro/data/InmemoryDOMDataBrokerProvider.java new file mode 100644 index 000000000..f5f04d2a7 --- /dev/null +++ b/infra/minimal-distribution-core/src/main/java/io/fd/honeycomb/infra/distro/data/InmemoryDOMDataBrokerProvider.java @@ -0,0 +1,61 @@ +/* + * Copyright (c) 2016 Cisco and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.fd.honeycomb.infra.distro.data; + +import com.google.inject.Inject; +import com.google.inject.name.Named; +import io.fd.honeycomb.infra.distro.ProviderTrait; +import java.util.LinkedHashMap; +import java.util.Map; +import java.util.concurrent.ExecutorService; +import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType; +import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitDeadlockException; +import org.opendaylight.controller.md.sal.dom.api.DOMDataBroker; +import org.opendaylight.controller.md.sal.dom.broker.impl.SerializedDOMDataBroker; +import org.opendaylight.controller.md.sal.dom.store.impl.InMemoryDOMDataStore; +import org.opendaylight.controller.sal.core.spi.data.DOMStore; +import org.opendaylight.yangtools.util.concurrent.DeadlockDetectingListeningExecutorService; +import org.opendaylight.yangtools.util.concurrent.SpecialExecutors; + +public final class InmemoryDOMDataBrokerProvider extends ProviderTrait<DOMDataBroker> { + + public static final String CONFIG = "config"; + public static final String OPERATIONAL = "operational"; + + @Inject + @Named(InmemoryDOMDataBrokerProvider.CONFIG) + private InMemoryDOMDataStore cfgDataStore; + @Inject + @Named(InmemoryDOMDataBrokerProvider.OPERATIONAL) + private InMemoryDOMDataStore operDataStore; + + @Override + protected SerializedDOMDataBroker create() { + // This Databroker is dedicated for netconf metadata, not expected to be under heavy load + ExecutorService listenableFutureExecutor = + SpecialExecutors.newBlockingBoundedCachedThreadPool(1, 100, "commits"); + ExecutorService commitExecutor = SpecialExecutors.newBoundedSingleThreadExecutor(100, "WriteTxCommit"); + // TODO HONEYCOMB-164 try to provide more lightweight implementation of DataBroker + + Map<LogicalDatastoreType, DOMStore> map = new LinkedHashMap<>(); + map.put(LogicalDatastoreType.CONFIGURATION, cfgDataStore); + map.put(LogicalDatastoreType.OPERATIONAL, operDataStore); + + return new SerializedDOMDataBroker(map, new DeadlockDetectingListeningExecutorService(commitExecutor, + TransactionCommitDeadlockException.DEADLOCK_EXCEPTION_SUPPLIER, listenableFutureExecutor)); + } +} diff --git a/infra/minimal-distribution-core/src/main/java/io/fd/honeycomb/infra/distro/data/ModifiableDTDelegProvider.java b/infra/minimal-distribution-core/src/main/java/io/fd/honeycomb/infra/distro/data/ModifiableDTDelegProvider.java new file mode 100644 index 000000000..b49381a27 --- /dev/null +++ b/infra/minimal-distribution-core/src/main/java/io/fd/honeycomb/infra/distro/data/ModifiableDTDelegProvider.java @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2016 Cisco and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.fd.honeycomb.infra.distro.data; + +import com.google.inject.Inject; +import com.google.inject.name.Named; +import io.fd.honeycomb.data.ModifiableDataManager; +import io.fd.honeycomb.data.impl.ModifiableDataTreeDelegator; +import io.fd.honeycomb.infra.distro.ProviderTrait; +import io.fd.honeycomb.infra.distro.data.context.ContextPipelineModule; +import io.fd.honeycomb.translate.write.registry.WriterRegistry; +import org.opendaylight.controller.md.sal.binding.api.DataBroker; +import org.opendaylight.controller.md.sal.binding.impl.BindingToNormalizedNodeCodec; +import org.opendaylight.controller.sal.core.api.model.SchemaService; +import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTree; + +public final class ModifiableDTDelegProvider extends ProviderTrait<ModifiableDataManager> { + + @Inject + private BindingToNormalizedNodeCodec serializer; + @Inject + private SchemaService schemaService; + @Inject + @Named(ConfigAndOperationalPipelineModule.HONEYCOMB_CONFIG) + private DataTree dataTree; + @Inject + private WriterRegistry registry; + @Inject + @Named(ContextPipelineModule.HONEYCOMB_CONTEXT) + private DataBroker contextBroker; + + @Override + protected ModifiableDataTreeDelegator create() { + return new ModifiableDataTreeDelegator(serializer, dataTree, schemaService.getGlobalContext(), + registry, contextBroker); + } +} diff --git a/infra/minimal-distribution-core/src/main/java/io/fd/honeycomb/infra/distro/data/PersistingDataTreeProvider.java b/infra/minimal-distribution-core/src/main/java/io/fd/honeycomb/infra/distro/data/PersistingDataTreeProvider.java new file mode 100644 index 000000000..e7a654c7d --- /dev/null +++ b/infra/minimal-distribution-core/src/main/java/io/fd/honeycomb/infra/distro/data/PersistingDataTreeProvider.java @@ -0,0 +1,99 @@ +/* + * Copyright (c) 2016 Cisco and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.fd.honeycomb.infra.distro.data; + +import com.google.inject.Inject; +import com.google.inject.name.Named; +import io.fd.honeycomb.data.impl.PersistingDataTreeAdapter; +import io.fd.honeycomb.infra.distro.ProviderTrait; +import io.fd.honeycomb.infra.distro.cfgattrs.HoneycombConfiguration; +import io.fd.honeycomb.infra.distro.data.context.ContextPipelineModule; +import java.nio.file.Paths; +import org.opendaylight.controller.sal.core.api.model.SchemaService; +import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTree; +import org.opendaylight.yangtools.yang.data.api.schema.tree.TreeType; + +public abstract class PersistingDataTreeProvider extends ProviderTrait<DataTree> { + + @Inject + private SchemaService schemaService; + @Inject + protected HoneycombConfiguration config; + + public DataTree create() { + return isEnabled() + ? new PersistingDataTreeAdapter(getDelegate(), schemaService, Paths.get(getPath())) + : getDelegate(); + } + + public abstract String getPath(); + + public abstract TreeType getType(); + + public abstract DataTree getDelegate(); + + protected abstract boolean isEnabled(); + + public static final class ConfigPersistingDataTreeProvider extends PersistingDataTreeProvider { + + @Inject + @Named(ConfigAndOperationalPipelineModule.HONEYCOMB_CONFIG_NONPERSIST) + private DataTree delegate; + + public String getPath() { + return config.peristConfigPath; + } + + public TreeType getType() { + return TreeType.CONFIGURATION; + } + + public DataTree getDelegate() { + return delegate; + } + + @Override + protected boolean isEnabled() { + return config.isConfigPersistenceEnabled(); + } + } + + public static final class ContextPersistingDataTreeProvider extends PersistingDataTreeProvider { + + @Inject + @Named(ContextPipelineModule.HONEYCOMB_CONTEXT_NOPERSIST) + private DataTree delegate; + + public String getPath() { + return config.peristContextPath; + } + + public TreeType getType() { + return TreeType.OPERATIONAL; + } + + public DataTree getDelegate() { + return delegate; + } + + @Override + protected boolean isEnabled() { + return config.isContextPersistenceEnabled(); + } + + } +} diff --git a/infra/minimal-distribution-core/src/main/java/io/fd/honeycomb/infra/distro/data/RpcRegistryBuilderProvider.java b/infra/minimal-distribution-core/src/main/java/io/fd/honeycomb/infra/distro/data/RpcRegistryBuilderProvider.java new file mode 100644 index 000000000..92d9ce951 --- /dev/null +++ b/infra/minimal-distribution-core/src/main/java/io/fd/honeycomb/infra/distro/data/RpcRegistryBuilderProvider.java @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2016 Cisco and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.fd.honeycomb.infra.distro.data; + +import com.google.inject.Inject; +import io.fd.honeycomb.infra.distro.ProviderTrait; +import io.fd.honeycomb.rpc.RpcRegistryBuilder; +import io.fd.honeycomb.rpc.RpcService; +import java.util.HashSet; +import java.util.Set; + +public final class RpcRegistryBuilderProvider extends ProviderTrait<RpcRegistryBuilder> { + + @Inject(optional = true) + private Set<RpcService> rpcServices = new HashSet<>(); + + @Override + protected RpcRegistryBuilder create() { + final RpcRegistryBuilder builder = new RpcRegistryBuilder(); + rpcServices.stream() + .forEach(service -> builder.addService(service)); + return builder; + } + +} diff --git a/infra/minimal-distribution-core/src/main/java/io/fd/honeycomb/infra/distro/data/RpcRegistryProvider.java b/infra/minimal-distribution-core/src/main/java/io/fd/honeycomb/infra/distro/data/RpcRegistryProvider.java new file mode 100644 index 000000000..4e09a9d2d --- /dev/null +++ b/infra/minimal-distribution-core/src/main/java/io/fd/honeycomb/infra/distro/data/RpcRegistryProvider.java @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2016 Cisco and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.fd.honeycomb.infra.distro.data; + +import com.google.inject.Inject; +import io.fd.honeycomb.infra.distro.ProviderTrait; +import io.fd.honeycomb.rpc.RpcRegistry; +import io.fd.honeycomb.rpc.RpcRegistryBuilder; + +public final class RpcRegistryProvider extends ProviderTrait<RpcRegistry> { + + @Inject + private RpcRegistryBuilder builder; + + @Override + protected RpcRegistry create() { + return builder.build(); + } + +} diff --git a/infra/minimal-distribution-core/src/main/java/io/fd/honeycomb/infra/distro/data/config/WriterRegistryProvider.java b/infra/minimal-distribution-core/src/main/java/io/fd/honeycomb/infra/distro/data/config/WriterRegistryProvider.java new file mode 100644 index 000000000..6546ba2d2 --- /dev/null +++ b/infra/minimal-distribution-core/src/main/java/io/fd/honeycomb/infra/distro/data/config/WriterRegistryProvider.java @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2016 Cisco and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.fd.honeycomb.infra.distro.data.config; + +import com.google.inject.Inject; +import io.fd.honeycomb.infra.distro.ProviderTrait; +import io.fd.honeycomb.translate.impl.write.registry.FlatWriterRegistryBuilder; +import io.fd.honeycomb.translate.util.YangDAG; +import io.fd.honeycomb.translate.write.WriterFactory; +import io.fd.honeycomb.translate.write.registry.WriterRegistry; +import java.util.HashSet; +import java.util.Set; + +public final class WriterRegistryProvider extends ProviderTrait<WriterRegistry> { + + @Inject(optional = true) + private Set<WriterFactory> writerFactories = new HashSet<>(); + + @Override + protected WriterRegistry create() { + final FlatWriterRegistryBuilder builder = new FlatWriterRegistryBuilder(new YangDAG()); + writerFactories + .stream() + .forEach(it -> it.init(builder)); + return builder.build(); + } +} diff --git a/infra/minimal-distribution-core/src/main/java/io/fd/honeycomb/infra/distro/data/context/ContextPipelineModule.java b/infra/minimal-distribution-core/src/main/java/io/fd/honeycomb/infra/distro/data/context/ContextPipelineModule.java new file mode 100644 index 000000000..b0ded35bd --- /dev/null +++ b/infra/minimal-distribution-core/src/main/java/io/fd/honeycomb/infra/distro/data/context/ContextPipelineModule.java @@ -0,0 +1,74 @@ +/* + * Copyright (c) 2016 Cisco and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.fd.honeycomb.infra.distro.data.context; + +import com.google.inject.PrivateModule; +import com.google.inject.Singleton; +import com.google.inject.name.Names; +import io.fd.honeycomb.data.ModifiableDataManager; +import io.fd.honeycomb.data.init.DataTreeInitializer; +import io.fd.honeycomb.infra.distro.data.BindingDataBrokerProvider; +import io.fd.honeycomb.infra.distro.data.DataTreeProvider; +import io.fd.honeycomb.infra.distro.data.PersistingDataTreeProvider; +import io.fd.honeycomb.infra.distro.initializer.PersistedFileInitializerProvider; +import io.fd.honeycomb.translate.MappingContext; +import org.opendaylight.controller.md.sal.binding.api.DataBroker; +import org.opendaylight.controller.md.sal.dom.api.DOMDataBroker; +import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTree; + +public class ContextPipelineModule extends PrivateModule { + + public static final String HONEYCOMB_CONTEXT_NOPERSIST = "honeycomb-context-nopersist"; + public static final String HONEYCOMB_CONTEXT = "honeycomb-context"; + + @Override + protected void configure() { + // Non persisting data tree for context + DataTreeProvider.ContextDataTreeProvider noPersistDataTreeProvider = + new DataTreeProvider.ContextDataTreeProvider(); + bind(DataTree.class).annotatedWith(Names.named(HONEYCOMB_CONTEXT_NOPERSIST)) + .toProvider(noPersistDataTreeProvider).in(Singleton.class); + expose(DataTree.class).annotatedWith(Names.named(HONEYCOMB_CONTEXT_NOPERSIST)); + // Persisting data tree wrapper for context + PersistingDataTreeProvider.ContextPersistingDataTreeProvider dataTreeProvider = + new PersistingDataTreeProvider.ContextPersistingDataTreeProvider(); + bind(DataTree.class).toProvider(dataTreeProvider).in(Singleton.class); + + // Data Tree manager (without any delegation) on top of context data tree + bind(ModifiableDataManager.class).toProvider(ModifiableDTMgrProvider.class).in(Singleton.class); + + // DOMDataBroker interface on top of data tree manager + HoneycombContextDOMDataBrokerProvider domBrokerProvider = new HoneycombContextDOMDataBrokerProvider(); + bind(DOMDataBroker.class).toProvider(domBrokerProvider).in(Singleton.class); + + // BA version of data broker for context + bind(DataBroker.class).annotatedWith(Names.named(HONEYCOMB_CONTEXT)).toProvider(BindingDataBrokerProvider.class) + .in(Singleton.class); + expose(DataBroker.class).annotatedWith(Names.named(HONEYCOMB_CONTEXT)); + + // Create initializer to init persisted config data + bind(DataTreeInitializer.class).annotatedWith(Names.named(HONEYCOMB_CONTEXT)) + .toProvider(PersistedFileInitializerProvider.PersistedContextInitializerProvider.class) + .in(Singleton.class); + expose(DataTreeInitializer.class).annotatedWith(Names.named(HONEYCOMB_CONTEXT)); + + // Mapping context is just a small adapter on top of BA data broker to simplify CRUD of context data + bind(MappingContext.class).annotatedWith(Names.named(HONEYCOMB_CONTEXT)) + .toProvider(RealtimeMappingContextProvider.class).in(Singleton.class); + expose(MappingContext.class).annotatedWith(Names.named(HONEYCOMB_CONTEXT)); + } +} diff --git a/infra/minimal-distribution-core/src/main/java/io/fd/honeycomb/infra/distro/data/context/HoneycombContextDOMDataBrokerProvider.java b/infra/minimal-distribution-core/src/main/java/io/fd/honeycomb/infra/distro/data/context/HoneycombContextDOMDataBrokerProvider.java new file mode 100644 index 000000000..8e178203d --- /dev/null +++ b/infra/minimal-distribution-core/src/main/java/io/fd/honeycomb/infra/distro/data/context/HoneycombContextDOMDataBrokerProvider.java @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2016 Cisco and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.fd.honeycomb.infra.distro.data.context; + +import com.google.inject.Inject; +import io.fd.honeycomb.data.ModifiableDataManager; +import io.fd.honeycomb.data.impl.DataBroker; +import io.fd.honeycomb.infra.distro.ProviderTrait; +import org.opendaylight.controller.md.sal.dom.api.DOMDataBroker; + +public final class HoneycombContextDOMDataBrokerProvider extends ProviderTrait<DOMDataBroker> { + + @Inject + private ModifiableDataManager modDataManager; + + public DataBroker create() { + return DataBroker.create(modDataManager); + } +} diff --git a/infra/minimal-distribution-core/src/main/java/io/fd/honeycomb/infra/distro/data/context/ModifiableDTMgrProvider.java b/infra/minimal-distribution-core/src/main/java/io/fd/honeycomb/infra/distro/data/context/ModifiableDTMgrProvider.java new file mode 100644 index 000000000..9da97a8e4 --- /dev/null +++ b/infra/minimal-distribution-core/src/main/java/io/fd/honeycomb/infra/distro/data/context/ModifiableDTMgrProvider.java @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2016 Cisco and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.fd.honeycomb.infra.distro.data.context; + +import com.google.inject.Inject; +import io.fd.honeycomb.data.ModifiableDataManager; +import io.fd.honeycomb.data.impl.ModifiableDataTreeManager; +import io.fd.honeycomb.infra.distro.ProviderTrait; +import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTree; + +public final class ModifiableDTMgrProvider extends ProviderTrait<ModifiableDataManager> { + + @Inject + private DataTree dataTree; + + @Override + public ModifiableDataTreeManager create() { + return new ModifiableDataTreeManager(dataTree); + } +} diff --git a/infra/minimal-distribution-core/src/main/java/io/fd/honeycomb/infra/distro/data/context/RealtimeMappingContextProvider.java b/infra/minimal-distribution-core/src/main/java/io/fd/honeycomb/infra/distro/data/context/RealtimeMappingContextProvider.java new file mode 100644 index 000000000..cc1a8b1b8 --- /dev/null +++ b/infra/minimal-distribution-core/src/main/java/io/fd/honeycomb/infra/distro/data/context/RealtimeMappingContextProvider.java @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2016 Cisco and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.fd.honeycomb.infra.distro.data.context; + +import com.google.inject.Inject; +import com.google.inject.name.Named; +import io.fd.honeycomb.infra.distro.ProviderTrait; +import io.fd.honeycomb.translate.MappingContext; +import io.fd.honeycomb.translate.util.RealtimeMappingContext; +import org.opendaylight.controller.md.sal.binding.api.DataBroker; + +public final class RealtimeMappingContextProvider extends ProviderTrait<MappingContext> { + + @Inject + @Named(ContextPipelineModule.HONEYCOMB_CONTEXT) + private DataBroker contextDataBroker; + + @Override + public RealtimeMappingContext create() { + return new RealtimeMappingContext(contextDataBroker); + } + +} diff --git a/infra/minimal-distribution-core/src/main/java/io/fd/honeycomb/infra/distro/data/oper/ReadableDTDelegProvider.java b/infra/minimal-distribution-core/src/main/java/io/fd/honeycomb/infra/distro/data/oper/ReadableDTDelegProvider.java new file mode 100644 index 000000000..caac736b5 --- /dev/null +++ b/infra/minimal-distribution-core/src/main/java/io/fd/honeycomb/infra/distro/data/oper/ReadableDTDelegProvider.java @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2016 Cisco and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.fd.honeycomb.infra.distro.data.oper; + +import com.google.inject.Inject; +import com.google.inject.name.Named; +import io.fd.honeycomb.data.ReadableDataManager; +import io.fd.honeycomb.data.impl.ReadableDataTreeDelegator; +import io.fd.honeycomb.infra.distro.ProviderTrait; +import io.fd.honeycomb.infra.distro.data.context.ContextPipelineModule; +import io.fd.honeycomb.translate.read.registry.ReaderRegistry; +import org.opendaylight.controller.md.sal.binding.api.DataBroker; +import org.opendaylight.controller.md.sal.binding.impl.BindingToNormalizedNodeCodec; +import org.opendaylight.controller.sal.core.api.model.SchemaService; + +public final class ReadableDTDelegProvider extends ProviderTrait<ReadableDataManager> { + + @Inject + private BindingToNormalizedNodeCodec serializer; + @Inject + private SchemaService schemaService; + @Inject + private ReaderRegistry registry; + @Inject + @Named(ContextPipelineModule.HONEYCOMB_CONTEXT) + private DataBroker contextBroker; + + @Override + protected ReadableDataTreeDelegator create() { + return new ReadableDataTreeDelegator(serializer, schemaService.getGlobalContext(), + registry, contextBroker); + } +} diff --git a/infra/minimal-distribution-core/src/main/java/io/fd/honeycomb/infra/distro/data/oper/ReaderRegistryProvider.java b/infra/minimal-distribution-core/src/main/java/io/fd/honeycomb/infra/distro/data/oper/ReaderRegistryProvider.java new file mode 100644 index 000000000..8f6bb0e6e --- /dev/null +++ b/infra/minimal-distribution-core/src/main/java/io/fd/honeycomb/infra/distro/data/oper/ReaderRegistryProvider.java @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2016 Cisco and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.fd.honeycomb.infra.distro.data.oper; + +import com.google.inject.Inject; +import io.fd.honeycomb.infra.distro.ProviderTrait; +import io.fd.honeycomb.translate.impl.read.registry.CompositeReaderRegistryBuilder; +import io.fd.honeycomb.translate.read.ReaderFactory; +import io.fd.honeycomb.translate.read.registry.ReaderRegistry; +import io.fd.honeycomb.translate.util.YangDAG; +import java.util.HashSet; +import java.util.Set; + +public final class ReaderRegistryProvider extends ProviderTrait<ReaderRegistry> { + + @Inject(optional = true) + private Set<ReaderFactory> readerFactories = new HashSet<>(); + + @Override + protected ReaderRegistry create() { + final CompositeReaderRegistryBuilder builder = new CompositeReaderRegistryBuilder(new YangDAG()); + readerFactories.stream() + .forEach(it -> it.init(builder)); + return builder.build(); + } + +} |