From 83efb0ff929801a5a2ab89f6b66c07ed940a309d Mon Sep 17 00:00:00 2001 From: Maros Marsalek Date: Thu, 11 Aug 2016 13:04:56 +0200 Subject: HONEYCOMB-19 Minimal distro ans wiring for hc infra Change-Id: I8f0e577ac91106e6025f7f2f27811f850e1c5253 Signed-off-by: Maros Marsalek --- .../distro/data/BindingDataBrokerProvider.groovy | 39 ++++++++++++ .../data/ConfigAndOperationalPipelineModule.groovy | 71 +++++++++++++++++++++ .../data/DOMNotificationServiceProvider.groovy | 34 ++++++++++ .../infra/distro/data/DataStoreProvider.groovy | 40 ++++++++++++ .../infra/distro/data/DataTreeProvider.groovy | 59 ++++++++++++++++++ .../distro/data/HoneycombDOMBrokerProvider.groovy | 44 +++++++++++++ .../data/HoneycombDOMDataBrokerProvider.groovy | 43 +++++++++++++ .../HoneycombNotificationManagerProvider.groovy | 72 ++++++++++++++++++++++ .../data/InmemoryDOMDataBrokerProvider.groovy | 65 +++++++++++++++++++ .../distro/data/ModifiableDTDelegProvider.groovy | 48 +++++++++++++++ .../infra/distro/data/NotificationModule.groovy | 45 ++++++++++++++ .../data/config/WriterRegistryProvider.groovy | 39 ++++++++++++ .../data/context/ContextPipelineModule.groovy | 58 +++++++++++++++++ .../HoneycombContextDOMDataBrokerProvider.groovy | 36 +++++++++++ .../data/context/ModifiableDTMgrProvider.groovy | 36 +++++++++++ .../data/oper/ReadableDTDelegProvider.groovy | 48 +++++++++++++++ .../distro/data/oper/ReaderRegistryProvider.groovy | 39 ++++++++++++ 17 files changed, 816 insertions(+) create mode 100644 infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/data/BindingDataBrokerProvider.groovy create mode 100644 infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/data/ConfigAndOperationalPipelineModule.groovy create mode 100644 infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/data/DOMNotificationServiceProvider.groovy create mode 100644 infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/data/DataStoreProvider.groovy create mode 100644 infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/data/DataTreeProvider.groovy create mode 100644 infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/data/HoneycombDOMBrokerProvider.groovy create mode 100644 infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/data/HoneycombDOMDataBrokerProvider.groovy create mode 100644 infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/data/HoneycombNotificationManagerProvider.groovy create mode 100644 infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/data/InmemoryDOMDataBrokerProvider.groovy create mode 100644 infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/data/ModifiableDTDelegProvider.groovy create mode 100644 infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/data/NotificationModule.groovy create mode 100644 infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/data/config/WriterRegistryProvider.groovy create mode 100644 infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/data/context/ContextPipelineModule.groovy create mode 100644 infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/data/context/HoneycombContextDOMDataBrokerProvider.groovy create mode 100644 infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/data/context/ModifiableDTMgrProvider.groovy create mode 100644 infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/data/oper/ReadableDTDelegProvider.groovy create mode 100644 infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/data/oper/ReaderRegistryProvider.groovy (limited to 'infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/data') diff --git a/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/data/BindingDataBrokerProvider.groovy b/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/data/BindingDataBrokerProvider.groovy new file mode 100644 index 000000000..e73f14932 --- /dev/null +++ b/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/data/BindingDataBrokerProvider.groovy @@ -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 groovy.transform.ToString +import groovy.util.logging.Slf4j +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 + +@Slf4j +@ToString +class BindingDataBrokerProvider extends ProviderTrait { + + @Inject + DOMDataBroker domDataBroker + @Inject + BindingToNormalizedNodeCodec mappingService + + @Override + def create() { new BindingDOMDataBrokerAdapter(domDataBroker, mappingService) } +} diff --git a/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/data/ConfigAndOperationalPipelineModule.groovy b/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/data/ConfigAndOperationalPipelineModule.groovy new file mode 100644 index 000000000..01ec8c16a --- /dev/null +++ b/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/data/ConfigAndOperationalPipelineModule.groovy @@ -0,0 +1,71 @@ +/* + * 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 groovy.util.logging.Slf4j +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.translate.read.registry.ModifiableReaderRegistryBuilder +import io.fd.honeycomb.translate.write.registry.ModifiableWriterRegistryBuilder +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 + +@Slf4j +class ConfigAndOperationalPipelineModule extends PrivateModule { + + protected void configure() { + // Expose registries + bind(ModifiableWriterRegistryBuilder).toProvider(WriterRegistryProvider).in(Singleton) + expose(ModifiableWriterRegistryBuilder) + bind(ModifiableReaderRegistryBuilder).toProvider(ReaderRegistryProvider).in(Singleton) + expose(ModifiableReaderRegistryBuilder) + + def dataTreeProvider = new DataTreeProvider.ConfigDataTreeProvider() + bind(DataTree).annotatedWith(Names.named("honeycomb-config")).toProvider(dataTreeProvider).in(Singleton) + expose(DataTree).annotatedWith(Names.named("honeycomb-config")) + + bind(ModifiableDataManager).toProvider(ModifiableDTDelegProvider).in(Singleton) + bind(ReadableDataManager) + .annotatedWith(Names.named("honeycomb-operational")) + .toProvider(ReadableDTDelegProvider).in(Singleton) + // Expose reader for initializer + expose(ReadableDataManager).annotatedWith(Names.named("honeycomb-operational")) + + def domBrokerProvider = new HoneycombDOMDataBrokerProvider() + bind(DOMDataBroker).annotatedWith(Names.named("honeycomb-config")).toProvider(domBrokerProvider).in(Singleton) + // Bind also without annotation for easy private injection + bind(DOMDataBroker).toProvider(domBrokerProvider).in(Singleton) + expose(DOMDataBroker).annotatedWith(Names.named("honeycomb-config")) + bind(DataBroker).annotatedWith(Names.named("honeycomb-config")).toProvider(BindingDataBrokerProvider).in(Singleton) + expose(DataBroker).annotatedWith(Names.named("honeycomb-config")) + + bind(DataTreeInitializer) + .annotatedWith(Names.named("honeycomb-config")) + .toProvider(PersistedFileInitializerProvider.PersistedConfigInitializerProvider) + .in(Singleton) + expose(DataTreeInitializer).annotatedWith(Names.named("honeycomb-config")) + } +} diff --git a/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/data/DOMNotificationServiceProvider.groovy b/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/data/DOMNotificationServiceProvider.groovy new file mode 100644 index 000000000..f8a1859e2 --- /dev/null +++ b/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/data/DOMNotificationServiceProvider.groovy @@ -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 groovy.transform.ToString +import groovy.util.logging.Slf4j +import io.fd.honeycomb.infra.distro.cfgattrs.HoneycombConfiguration +import io.fd.honeycomb.infra.distro.ProviderTrait +import org.opendaylight.controller.md.sal.dom.broker.impl.DOMNotificationRouter + +@Slf4j +@ToString +class DOMNotificationServiceProvider extends ProviderTrait { + + @Inject + HoneycombConfiguration cfg + + def create() { DOMNotificationRouter.create(cfg.notificationServiceQueueDepth) } +} diff --git a/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/data/DataStoreProvider.groovy b/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/data/DataStoreProvider.groovy new file mode 100644 index 000000000..6d075ccc8 --- /dev/null +++ b/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/data/DataStoreProvider.groovy @@ -0,0 +1,40 @@ +/* + * 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 groovy.transform.ToString +import groovy.util.logging.Slf4j +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 + +@Slf4j +@ToString +class DataStoreProvider extends ProviderTrait { + + @Inject + SchemaService schemaService + + String name + LogicalDatastoreType type + + @Override + def create() { InMemoryDOMDataStoreFactory.create(name, type, schemaService, false, null) } +} diff --git a/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/data/DataTreeProvider.groovy b/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/data/DataTreeProvider.groovy new file mode 100644 index 000000000..6915a3cec --- /dev/null +++ b/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/data/DataTreeProvider.groovy @@ -0,0 +1,59 @@ +/* + * 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 groovy.transform.ToString +import groovy.util.logging.Slf4j +import io.fd.honeycomb.data.impl.PersistingDataTreeAdapter +import io.fd.honeycomb.infra.distro.cfgattrs.HoneycombConfiguration +import io.fd.honeycomb.infra.distro.ProviderTrait +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 +import org.opendaylight.yangtools.yang.data.impl.schema.tree.InMemoryDataTreeFactory + +import java.nio.file.Paths + +@Slf4j +@ToString +abstract class DataTreeProvider extends ProviderTrait { + + @Inject + SchemaService schemaService + @Inject + HoneycombConfiguration config + + def create() { + def delegate = InMemoryDataTreeFactory.getInstance().create(getType()) + delegate.setSchemaContext(schemaService.getGlobalContext()) + new PersistingDataTreeAdapter(delegate, schemaService, Paths.get(getPath())) + } + + abstract String getPath() + abstract TreeType getType() + + static class ConfigDataTreeProvider extends DataTreeProvider { + String getPath() { config.peristConfigPath } + TreeType getType() { TreeType.CONFIGURATION } + } + + static class ContextDataTreeProvider extends DataTreeProvider { + String getPath() { config.peristContextPath } + TreeType getType() { TreeType.OPERATIONAL } + } +} diff --git a/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/data/HoneycombDOMBrokerProvider.groovy b/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/data/HoneycombDOMBrokerProvider.groovy new file mode 100644 index 000000000..2b275f7ff --- /dev/null +++ b/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/data/HoneycombDOMBrokerProvider.groovy @@ -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 com.google.inject.name.Named +import groovy.transform.ToString +import groovy.util.logging.Slf4j +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.DOMNotificationService +import org.opendaylight.controller.sal.core.api.Broker +import org.opendaylight.controller.sal.core.api.model.SchemaService + +@Slf4j +@ToString +class HoneycombDOMBrokerProvider extends ProviderTrait { + + @Inject + @Named("honeycomb-config") + DOMDataBroker domDataBroker + @Inject + SchemaService schemaService + @Inject + @Named("honeycomb") + DOMNotificationService domNotificationService + + def create() { new NorthboundFacadeHoneycombDOMBroker(domDataBroker, schemaService, domNotificationService) } +} diff --git a/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/data/HoneycombDOMDataBrokerProvider.groovy b/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/data/HoneycombDOMDataBrokerProvider.groovy new file mode 100644 index 000000000..e91054b3b --- /dev/null +++ b/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/data/HoneycombDOMDataBrokerProvider.groovy @@ -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 com.google.inject.name.Named +import groovy.transform.ToString +import groovy.util.logging.Slf4j +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 + +@Slf4j +@ToString +class HoneycombDOMDataBrokerProvider extends ProviderTrait { + + @Inject + ModifiableDataManager modDataManager + + @Inject + @Named("honeycomb-operational") + ReadableDataManager readDataManager + + def create() { + readDataManager ? DataBroker.create(modDataManager, readDataManager) : DataBroker.create(modDataManager) + } +} diff --git a/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/data/HoneycombNotificationManagerProvider.groovy b/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/data/HoneycombNotificationManagerProvider.groovy new file mode 100644 index 000000000..f150691a8 --- /dev/null +++ b/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/data/HoneycombNotificationManagerProvider.groovy @@ -0,0 +1,72 @@ +/* + * 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 groovy.transform.ToString +import groovy.util.logging.Slf4j +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 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 + +/** + * Mirror of org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.notification.impl.rev160601.HoneycombNotificationManagerModule + */ +@Slf4j +@ToString +class HoneycombNotificationManagerProvider extends ProviderTrait { + + @Inject + @Named("honeycomb") + DOMNotificationRouter notificationRouter + @Inject(optional = true) + Set notificationProducers = [] + @Inject + BindingToNormalizedNodeCodec codec + + @Override + def create() { + // Create the registry to keep track of what'OPERATIONAL registered + def notificationProducerRegistry = new NotificationProducerRegistry(notificationProducers as List); + + // Create BA version of notification service (implementation is free from ODL) + def bindingDOMNotificationPublishServiceAdapter = + new BindingDOMNotificationPublishServiceAdapter(codec, notificationRouter); + + // Create Collector on top of BA notification service and registry + def honeycombNotificationCollector = + new HoneycombNotificationCollector(bindingDOMNotificationPublishServiceAdapter, notificationProducerRegistry); + + // Create tracker, responsible for starting and stopping registered notification producers whenever necessary + def notificationProducerTracker = + new NotificationProducerTracker(notificationProducerRegistry, honeycombNotificationCollector, + notificationRouter); + + // TODO wire with restconf + // DOMNotificationService is already provided by DOMBroker injected into RESTCONF, however RESTCONF + // only supports data-change notification, nothing else. So currently its impossible. + + honeycombNotificationCollector + } +} diff --git a/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/data/InmemoryDOMDataBrokerProvider.groovy b/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/data/InmemoryDOMDataBrokerProvider.groovy new file mode 100644 index 000000000..6462baa71 --- /dev/null +++ b/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/data/InmemoryDOMDataBrokerProvider.groovy @@ -0,0 +1,65 @@ +/* + * 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 groovy.transform.ToString +import groovy.util.logging.Slf4j +import io.fd.honeycomb.infra.distro.ProviderTrait +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.yangtools.util.concurrent.DeadlockDetectingListeningExecutorService +import org.opendaylight.yangtools.util.concurrent.SpecialExecutors +/** + * Mirror of org.opendaylight.controller.config.yang.md.sal.dom.impl.DomInmemoryDataBrokerModule + */ +@Slf4j +@ToString +class InmemoryDOMDataBrokerProvider extends ProviderTrait { + + public static final String CONFIG = "config" + public static final String OPERATIONAL = "operational" + + @Inject + @Named(InmemoryDOMDataBrokerProvider.CONFIG) + InMemoryDOMDataStore cfgDataStore + + @Inject + @Named(InmemoryDOMDataBrokerProvider.OPERATIONAL) + InMemoryDOMDataStore operDataStore + + @Override + def create() { + // This Databroker is dedicated for netconf metadata, not expected to be under heavy load + def listenableFutureExecutor = SpecialExecutors.newBlockingBoundedCachedThreadPool(1, 100, "commits") + def commitExecutor = SpecialExecutors.newBoundedSingleThreadExecutor(100, "WriteTxCommit") + // TODO try to provide more lightweight implementation of DataBroker, maybe a single executor would be enough + + def map = [:] + map.put(LogicalDatastoreType.CONFIGURATION, cfgDataStore) + map.put(LogicalDatastoreType.OPERATIONAL, operDataStore) + + new SerializedDOMDataBroker(map, + new DeadlockDetectingListeningExecutorService(commitExecutor, + TransactionCommitDeadlockException.DEADLOCK_EXCEPTION_SUPPLIER, + listenableFutureExecutor)) + } +} diff --git a/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/data/ModifiableDTDelegProvider.groovy b/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/data/ModifiableDTDelegProvider.groovy new file mode 100644 index 000000000..f7ec4cc12 --- /dev/null +++ b/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/data/ModifiableDTDelegProvider.groovy @@ -0,0 +1,48 @@ +/* + * 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 groovy.transform.ToString +import groovy.util.logging.Slf4j +import io.fd.honeycomb.data.ModifiableDataManager +import io.fd.honeycomb.data.impl.ModifiableDataTreeDelegator +import io.fd.honeycomb.infra.distro.ProviderTrait +import io.fd.honeycomb.translate.write.registry.ModifiableWriterRegistryBuilder +import org.opendaylight.controller.md.sal.binding.api.DataBroker +import org.opendaylight.controller.md.sal.binding.impl.BindingToNormalizedNodeCodec +import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTree + +@Slf4j +@ToString +class ModifiableDTDelegProvider extends ProviderTrait { + + @Inject + BindingToNormalizedNodeCodec serializer + @Inject + @Named("honeycomb-config") + DataTree dataTree + @Inject + ModifiableWriterRegistryBuilder registry + @Inject + @Named("honeycomb-context") + DataBroker contextBroker + + @Override + def create() { new ModifiableDataTreeDelegator(serializer, dataTree, registry.build(), contextBroker) } +} diff --git a/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/data/NotificationModule.groovy b/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/data/NotificationModule.groovy new file mode 100644 index 000000000..4836a0fbe --- /dev/null +++ b/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/data/NotificationModule.groovy @@ -0,0 +1,45 @@ +/* + * 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.AbstractModule +import com.google.inject.Singleton +import com.google.inject.name.Names +import groovy.util.logging.Slf4j +import org.opendaylight.controller.md.sal.dom.api.DOMNotificationService +import org.opendaylight.controller.md.sal.dom.broker.impl.DOMNotificationRouter +import org.opendaylight.controller.sal.core.api.Broker + +@Slf4j +class NotificationModule extends AbstractModule { + + protected void configure() { + def provider = new DOMNotificationServiceProvider() + bind(DOMNotificationService) + .annotatedWith(Names.named("honeycomb")) + .toProvider(provider) + .in(Singleton) + bind(DOMNotificationRouter) + .annotatedWith(Names.named("honeycomb")) + .toProvider(provider) + .in(Singleton) + bind(Broker) + .annotatedWith(Names.named("honeycomb")) + .toProvider(HoneycombDOMBrokerProvider) + .in(Singleton) + } +} diff --git a/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/data/config/WriterRegistryProvider.groovy b/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/data/config/WriterRegistryProvider.groovy new file mode 100644 index 000000000..3c94812ef --- /dev/null +++ b/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/data/config/WriterRegistryProvider.groovy @@ -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.config + +import com.google.inject.Inject +import groovy.transform.ToString +import groovy.util.logging.Slf4j +import io.fd.honeycomb.infra.distro.ProviderTrait +import io.fd.honeycomb.translate.util.write.registry.FlatWriterRegistryBuilder +import io.fd.honeycomb.translate.write.WriterFactory +import io.fd.honeycomb.translate.write.registry.ModifiableWriterRegistryBuilder + +@Slf4j +@ToString +class WriterRegistryProvider extends ProviderTrait { + + @Inject(optional = true) + Set writerFactories = [] + + def create() { + def builder = new FlatWriterRegistryBuilder() + writerFactories.forEach { it.init(builder) } + builder + } +} diff --git a/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/data/context/ContextPipelineModule.groovy b/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/data/context/ContextPipelineModule.groovy new file mode 100644 index 000000000..01124131f --- /dev/null +++ b/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/data/context/ContextPipelineModule.groovy @@ -0,0 +1,58 @@ +/* + * 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.initializer.PersistedFileInitializerProvider +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 + +class ContextPipelineModule extends PrivateModule { + + protected void configure() { + // Bind also without annotation for easy private injection + def dataTreeProvider = new DataTreeProvider.ContextDataTreeProvider() + bind(DataTree).toProvider(dataTreeProvider).in(Singleton) + bind(DataTree).annotatedWith(Names.named("honeycomb-context")).toProvider(dataTreeProvider).in(Singleton) + expose(DataTree).annotatedWith(Names.named("honeycomb-context")) + + bind(ModifiableDataManager).toProvider(ModifiableDTMgrProvider).in(Singleton) + + def domBrokerProvider = new HoneycombContextDOMDataBrokerProvider() + bind(DOMDataBroker).annotatedWith(Names.named("honeycomb-context")).toProvider(domBrokerProvider).in(Singleton) + // Bind also without annotation for easy private injection + bind(DOMDataBroker).toProvider(domBrokerProvider).in(Singleton) + expose(DOMDataBroker).annotatedWith(Names.named("honeycomb-context")) + + bind(DataBroker).annotatedWith(Names.named("honeycomb-context")).toProvider(BindingDataBrokerProvider).in(Singleton) + expose(DataBroker).annotatedWith(Names.named("honeycomb-context")) + + bind(DataTreeInitializer) + .annotatedWith(Names.named("honeycomb-context")) + .toProvider(PersistedFileInitializerProvider.PersistedContextInitializerProvider) + .in(Singleton) + expose(DataTreeInitializer).annotatedWith(Names.named("honeycomb-context")) + } + +} diff --git a/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/data/context/HoneycombContextDOMDataBrokerProvider.groovy b/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/data/context/HoneycombContextDOMDataBrokerProvider.groovy new file mode 100644 index 000000000..eecd87e42 --- /dev/null +++ b/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/data/context/HoneycombContextDOMDataBrokerProvider.groovy @@ -0,0 +1,36 @@ +/* + * 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 groovy.transform.ToString +import groovy.util.logging.Slf4j +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 + +@Slf4j +@ToString +class HoneycombContextDOMDataBrokerProvider extends ProviderTrait { + + @Inject + ModifiableDataManager modDataManager + + def create() { DataBroker.create(modDataManager) } + +} diff --git a/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/data/context/ModifiableDTMgrProvider.groovy b/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/data/context/ModifiableDTMgrProvider.groovy new file mode 100644 index 000000000..01d854b28 --- /dev/null +++ b/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/data/context/ModifiableDTMgrProvider.groovy @@ -0,0 +1,36 @@ +/* + * 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 groovy.transform.ToString +import groovy.util.logging.Slf4j +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 + +@Slf4j +@ToString +class ModifiableDTMgrProvider extends ProviderTrait { + + @Inject + DataTree dataTree + + @Override + def create() { new ModifiableDataTreeManager(dataTree) } +} diff --git a/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/data/oper/ReadableDTDelegProvider.groovy b/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/data/oper/ReadableDTDelegProvider.groovy new file mode 100644 index 000000000..384278793 --- /dev/null +++ b/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/data/oper/ReadableDTDelegProvider.groovy @@ -0,0 +1,48 @@ +/* + * 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 groovy.transform.ToString +import groovy.util.logging.Slf4j +import io.fd.honeycomb.data.ReadableDataManager +import io.fd.honeycomb.data.impl.ReadableDataTreeDelegator +import io.fd.honeycomb.infra.distro.ProviderTrait +import io.fd.honeycomb.translate.read.registry.ModifiableReaderRegistryBuilder +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 + +@Slf4j +@ToString +class ReadableDTDelegProvider extends ProviderTrait { + + @Inject + BindingToNormalizedNodeCodec serializer + @Inject + SchemaService schemaService + @Inject + ModifiableReaderRegistryBuilder registry + @Inject + @Named("honeycomb-context") + DataBroker contextBroker + + def create() { + new ReadableDataTreeDelegator(serializer, schemaService.getGlobalContext(), registry.build(), contextBroker) + } +} diff --git a/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/data/oper/ReaderRegistryProvider.groovy b/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/data/oper/ReaderRegistryProvider.groovy new file mode 100644 index 000000000..36f74d948 --- /dev/null +++ b/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/data/oper/ReaderRegistryProvider.groovy @@ -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.oper + +import com.google.inject.Inject +import groovy.transform.ToString +import groovy.util.logging.Slf4j +import io.fd.honeycomb.infra.distro.ProviderTrait +import io.fd.honeycomb.translate.read.ReaderFactory +import io.fd.honeycomb.translate.read.registry.ModifiableReaderRegistryBuilder +import io.fd.honeycomb.translate.util.read.registry.CompositeReaderRegistryBuilder + +@Slf4j +@ToString +class ReaderRegistryProvider extends ProviderTrait { + + @Inject(optional = true) + Set readerFactories = [] + + def create() { + def builder = new CompositeReaderRegistryBuilder() + readerFactories.forEach { it.init(builder) } + builder + } +} -- cgit 1.2.3-korg