From cefd2555dbf421a62269c393d0d9d28964f38e2b Mon Sep 17 00:00:00 2001 From: Maros Marsalek Date: Thu, 25 Aug 2016 10:46:02 +0200 Subject: Remove groovy to reduce footprint Change-Id: I798558e52329c26aa5481d702745c4d46e290615 Signed-off-by: Maros Marsalek --- .../java/io/fd/honeycomb/infra/distro/Main.java | 8 +- .../fd/honeycomb/infra/distro/ProviderTrait.groovy | 36 ----- .../fd/honeycomb/infra/distro/ProviderTrait.java | 36 +++++ .../infra/distro/cfgattrs/CfgAttrsModule.groovy | 34 ---- .../infra/distro/cfgattrs/CfgAttrsModule.java | 33 ++++ .../distro/cfgattrs/HoneycombConfiguration.groovy | 140 ----------------- .../distro/cfgattrs/HoneycombConfiguration.java | 174 +++++++++++++++++++++ .../distro/data/BindingDataBrokerProvider.groovy | 39 ----- .../distro/data/BindingDataBrokerProvider.java | 37 +++++ .../data/ConfigAndOperationalPipelineModule.groovy | 96 ------------ .../data/ConfigAndOperationalPipelineModule.java | 90 +++++++++++ .../data/DOMNotificationServiceProvider.groovy | 34 ---- .../data/DOMNotificationServiceProvider.java | 33 ++++ .../infra/distro/data/DataStoreProvider.groovy | 40 ----- .../infra/distro/data/DataStoreProvider.java | 43 +++++ .../infra/distro/data/DataTreeProvider.groovy | 57 ------- .../infra/distro/data/DataTreeProvider.java | 56 +++++++ .../distro/data/HoneycombDOMBrokerProvider.groovy | 41 ----- .../distro/data/HoneycombDOMBrokerProvider.java | 40 +++++ .../data/HoneycombDOMDataBrokerProvider.groovy | 41 ----- .../data/HoneycombDOMDataBrokerProvider.java | 38 +++++ .../HoneycombNotificationManagerProvider.groovy | 67 -------- .../data/HoneycombNotificationManagerProvider.java | 68 ++++++++ .../data/InmemoryDOMDataBrokerProvider.groovy | 63 -------- .../distro/data/InmemoryDOMDataBrokerProvider.java | 61 ++++++++ .../distro/data/ModifiableDTDelegProvider.groovy | 49 ------ .../distro/data/ModifiableDTDelegProvider.java | 49 ++++++ .../distro/data/PersistingDataTreeProvider.groovy | 71 --------- .../distro/data/PersistingDataTreeProvider.java | 84 ++++++++++ .../data/config/WriterRegistryProvider.groovy | 39 ----- .../distro/data/config/WriterRegistryProvider.java | 40 +++++ .../data/context/ContextPipelineModule.groovy | 76 --------- .../distro/data/context/ContextPipelineModule.java | 74 +++++++++ .../HoneycombContextDOMDataBrokerProvider.groovy | 36 ----- .../HoneycombContextDOMDataBrokerProvider.java | 33 ++++ .../data/context/ModifiableDTMgrProvider.groovy | 36 ----- .../data/context/ModifiableDTMgrProvider.java | 34 ++++ .../context/RealtimeMappingContextProvider.groovy | 40 ----- .../context/RealtimeMappingContextProvider.java | 37 +++++ .../data/oper/ReadableDTDelegProvider.groovy | 49 ------ .../distro/data/oper/ReadableDTDelegProvider.java | 48 ++++++ .../distro/data/oper/ReaderRegistryProvider.groovy | 39 ----- .../distro/data/oper/ReaderRegistryProvider.java | 40 +++++ .../initializer/InitializerPipelineModule.groovy | 53 ------- .../initializer/InitializerPipelineModule.java | 48 ++++++ .../initializer/InitializerRegistryAdapter.java | 69 ++++++++ .../initializer/InitializerRegistryProvider.groovy | 75 --------- .../initializer/InitializerRegistryProvider.java | 44 ++++++ .../ModifiableDTDelegInitProvider.groovy | 48 ------ .../initializer/ModifiableDTDelegInitProvider.java | 46 ++++++ .../PersistedFileInitializerProvider.groovy | 65 -------- .../PersistedFileInitializerProvider.java | 78 +++++++++ .../HoneycombNotification2NetconfProvider.groovy | 88 ----------- .../HoneycombNotification2NetconfProvider.java | 130 +++++++++++++++ .../netconf/NetconfBindingBrokerProvider.groovy | 38 ----- .../netconf/NetconfBindingBrokerProvider.java | 36 +++++ .../netconf/NetconfMdsalMapperProvider.groovy | 51 ------ .../distro/netconf/NetconfMdsalMapperProvider.java | 47 ++++++ .../infra/distro/netconf/NetconfModule.groovy | 141 ----------------- .../infra/distro/netconf/NetconfModule.java | 130 +++++++++++++++ .../netconf/NetconfMonitoringMapperProvider.groovy | 53 ------- .../netconf/NetconfMonitoringMapperProvider.java | 79 ++++++++++ .../NetconfMonitoringReaderFactoryProvider.groovy | 37 ----- .../NetconfMonitoringReaderFactoryProvider.java | 37 +++++ .../NetconfMonitoringServiceProvider.groovy | 40 ----- .../netconf/NetconfMonitoringServiceProvider.java | 37 +++++ .../NetconfNotificationMapperProvider.groovy | 70 --------- .../netconf/NetconfNotificationMapperProvider.java | 96 ++++++++++++ ...etconfNotificationsReaderFactoryProvider.groovy | 52 ------ .../NetconfNotificationsReaderFactoryProvider.java | 57 +++++++ .../distro/netconf/NetconfReadersModule.groovy | 37 ----- .../infra/distro/netconf/NetconfReadersModule.java | 34 ++++ .../netconf/NetconfServerDispatcherProvider.groovy | 66 -------- .../netconf/NetconfServerDispatcherProvider.java | 60 +++++++ .../distro/netconf/NetconfSshServerProvider.groovy | 97 ------------ .../distro/netconf/NetconfSshServerProvider.java | 151 ++++++++++++++++++ .../distro/netconf/NetconfTcpServerProvider.groovy | 63 -------- .../distro/netconf/NetconfTcpServerProvider.java | 85 ++++++++++ .../distro/netconf/NettyThreadGroupProvider.groovy | 39 ----- .../distro/netconf/NettyThreadGroupProvider.java | 35 +++++ .../infra/distro/netconf/NettyTimerProvider.groovy | 39 ----- .../infra/distro/netconf/NettyTimerProvider.java | 35 +++++ .../distro/restconf/HttpConnectorProvider.groovy | 24 --- .../distro/restconf/HttpConnectorProvider.java | 41 +++++ .../distro/restconf/HttpsConnectorProvider.groovy | 57 ------- .../distro/restconf/HttpsConnectorProvider.java | 75 +++++++++ .../distro/restconf/JettyServerProvider.groovy | 80 ---------- .../infra/distro/restconf/JettyServerProvider.java | 80 ++++++++++ .../infra/distro/restconf/RestconfModule.groovy | 39 ----- .../infra/distro/restconf/RestconfModule.java | 40 +++++ .../infra/distro/restconf/RestconfProvider.groovy | 45 ------ .../infra/distro/restconf/RestconfProvider.java | 43 +++++ .../schema/ModuleInfoBackedCtxProvider.groovy | 47 ------ .../distro/schema/ModuleInfoBackedCtxProvider.java | 50 ++++++ .../infra/distro/schema/SchemaModule.groovy | 35 ----- .../infra/distro/schema/SchemaModule.java | 33 ++++ .../distro/schema/SchemaServiceProvider.groovy | 79 ---------- .../infra/distro/schema/SchemaServiceProvider.java | 81 ++++++++++ .../infra/distro/schema/SerializerProvider.groovy | 47 ------ .../infra/distro/schema/SerializerProvider.java | 45 ++++++ .../distro/schema/YangBindingProviderModule.groovy | 51 ------ .../distro/schema/YangBindingProviderModule.java | 82 ++++++++++ 102 files changed, 3057 insertions(+), 2782 deletions(-) delete mode 100644 infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/ProviderTrait.groovy create mode 100644 infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/ProviderTrait.java delete mode 100644 infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/cfgattrs/CfgAttrsModule.groovy create mode 100644 infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/cfgattrs/CfgAttrsModule.java delete mode 100644 infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/cfgattrs/HoneycombConfiguration.groovy create mode 100644 infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/cfgattrs/HoneycombConfiguration.java delete 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/BindingDataBrokerProvider.java delete 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/ConfigAndOperationalPipelineModule.java delete 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/DOMNotificationServiceProvider.java delete 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/DataStoreProvider.java delete 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/DataTreeProvider.java delete 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/HoneycombDOMBrokerProvider.java delete 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/HoneycombDOMDataBrokerProvider.java delete 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/HoneycombNotificationManagerProvider.java delete 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/InmemoryDOMDataBrokerProvider.java delete 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/ModifiableDTDelegProvider.java delete mode 100644 infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/data/PersistingDataTreeProvider.groovy create mode 100644 infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/data/PersistingDataTreeProvider.java delete 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/config/WriterRegistryProvider.java delete 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/ContextPipelineModule.java delete 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/HoneycombContextDOMDataBrokerProvider.java delete 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/context/ModifiableDTMgrProvider.java delete mode 100644 infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/data/context/RealtimeMappingContextProvider.groovy create mode 100644 infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/data/context/RealtimeMappingContextProvider.java delete 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/ReadableDTDelegProvider.java delete mode 100644 infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/data/oper/ReaderRegistryProvider.groovy create mode 100644 infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/data/oper/ReaderRegistryProvider.java delete mode 100644 infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/initializer/InitializerPipelineModule.groovy create mode 100644 infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/initializer/InitializerPipelineModule.java create mode 100644 infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/initializer/InitializerRegistryAdapter.java delete mode 100644 infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/initializer/InitializerRegistryProvider.groovy create mode 100644 infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/initializer/InitializerRegistryProvider.java delete mode 100644 infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/initializer/ModifiableDTDelegInitProvider.groovy create mode 100644 infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/initializer/ModifiableDTDelegInitProvider.java delete mode 100644 infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/initializer/PersistedFileInitializerProvider.groovy create mode 100644 infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/initializer/PersistedFileInitializerProvider.java delete mode 100644 infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/netconf/HoneycombNotification2NetconfProvider.groovy create mode 100644 infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/netconf/HoneycombNotification2NetconfProvider.java delete mode 100644 infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/netconf/NetconfBindingBrokerProvider.groovy create mode 100644 infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/netconf/NetconfBindingBrokerProvider.java delete mode 100644 infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/netconf/NetconfMdsalMapperProvider.groovy create mode 100644 infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/netconf/NetconfMdsalMapperProvider.java delete mode 100644 infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/netconf/NetconfModule.groovy create mode 100644 infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/netconf/NetconfModule.java delete mode 100644 infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/netconf/NetconfMonitoringMapperProvider.groovy create mode 100644 infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/netconf/NetconfMonitoringMapperProvider.java delete mode 100644 infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/netconf/NetconfMonitoringReaderFactoryProvider.groovy create mode 100644 infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/netconf/NetconfMonitoringReaderFactoryProvider.java delete mode 100644 infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/netconf/NetconfMonitoringServiceProvider.groovy create mode 100644 infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/netconf/NetconfMonitoringServiceProvider.java delete mode 100644 infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/netconf/NetconfNotificationMapperProvider.groovy create mode 100644 infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/netconf/NetconfNotificationMapperProvider.java delete mode 100644 infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/netconf/NetconfNotificationsReaderFactoryProvider.groovy create mode 100644 infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/netconf/NetconfNotificationsReaderFactoryProvider.java delete mode 100644 infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/netconf/NetconfReadersModule.groovy create mode 100644 infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/netconf/NetconfReadersModule.java delete mode 100644 infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/netconf/NetconfServerDispatcherProvider.groovy create mode 100644 infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/netconf/NetconfServerDispatcherProvider.java delete mode 100644 infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/netconf/NetconfSshServerProvider.groovy create mode 100644 infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/netconf/NetconfSshServerProvider.java delete mode 100644 infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/netconf/NetconfTcpServerProvider.groovy create mode 100644 infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/netconf/NetconfTcpServerProvider.java delete mode 100644 infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/netconf/NettyThreadGroupProvider.groovy create mode 100644 infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/netconf/NettyThreadGroupProvider.java delete mode 100644 infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/netconf/NettyTimerProvider.groovy create mode 100644 infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/netconf/NettyTimerProvider.java delete mode 100644 infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/restconf/HttpConnectorProvider.groovy create mode 100644 infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/restconf/HttpConnectorProvider.java delete mode 100644 infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/restconf/HttpsConnectorProvider.groovy create mode 100644 infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/restconf/HttpsConnectorProvider.java delete mode 100644 infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/restconf/JettyServerProvider.groovy create mode 100644 infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/restconf/JettyServerProvider.java delete mode 100644 infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/restconf/RestconfModule.groovy create mode 100644 infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/restconf/RestconfModule.java delete mode 100644 infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/restconf/RestconfProvider.groovy create mode 100644 infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/restconf/RestconfProvider.java delete mode 100644 infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/schema/ModuleInfoBackedCtxProvider.groovy create mode 100644 infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/schema/ModuleInfoBackedCtxProvider.java delete mode 100644 infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/schema/SchemaModule.groovy create mode 100644 infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/schema/SchemaModule.java delete mode 100644 infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/schema/SchemaServiceProvider.groovy create mode 100644 infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/schema/SchemaServiceProvider.java delete mode 100644 infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/schema/SerializerProvider.groovy create mode 100644 infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/schema/SerializerProvider.java delete mode 100644 infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/schema/YangBindingProviderModule.groovy create mode 100644 infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/schema/YangBindingProviderModule.java (limited to 'infra/minimal-distribution/src/main/java/io') diff --git a/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/Main.java b/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/Main.java index d74906244..44b6cd35b 100644 --- a/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/Main.java +++ b/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/Main.java @@ -26,7 +26,6 @@ import com.google.inject.Key; import com.google.inject.Module; import com.google.inject.ProvisionException; import com.google.inject.name.Names; -import groovy.util.logging.Slf4j; import io.fd.honeycomb.data.init.DataTreeInitializer; import io.fd.honeycomb.data.init.InitializerRegistry; import io.fd.honeycomb.infra.distro.cfgattrs.CfgAttrsModule; @@ -50,7 +49,6 @@ import org.opendaylight.netconf.sal.rest.api.RestConnector; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -@Slf4j public final class Main { private static final Logger LOG = LoggerFactory.getLogger(Main.class); @@ -79,7 +77,6 @@ public final class Main { public static Injector init(final List modules) { try { LOG.info("Starting honeycomb"); - Injector injector = Guice.createInjector(modules); LOG.info("Honeycomb configuration: " + injector.getInstance(HoneycombConfiguration.class)); @@ -98,9 +95,11 @@ public final class Main { final RestConnector instance = injector.getInstance(RestConnector.class); if (cfgAttributes.isRestconfHttpEnabled()) { + LOG.info("Starting Restconf on http"); injector.getInstance(Key.get(ServerConnector.class, Names.named(RestconfModule.RESTCONF_HTTP))); } if (cfgAttributes.isRestconfHttpsEnabled()) { + LOG.info("Starting Restconf on https"); injector.getInstance(Key.get(ServerConnector.class, Names.named(RestconfModule.RESTCONF_HTTPS))); } @@ -153,6 +152,9 @@ public final class Main { } catch (RuntimeException e) { LOG.error("Unexpected initialization failure", e); throw e; + } finally { + // Trigger gc to force collect initial garbage + dedicated classloader + System.gc(); } } } diff --git a/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/ProviderTrait.groovy b/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/ProviderTrait.groovy deleted file mode 100644 index d1bce3176..000000000 --- a/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/ProviderTrait.groovy +++ /dev/null @@ -1,36 +0,0 @@ -/* - * 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 - -import com.google.inject.Provider -import groovy.util.logging.Slf4j - -// TODO this should be a trait, but groovy compilation/stub generation sometimes fails (only) in Intellij if using trait - -@Slf4j -abstract class ProviderTrait implements Provider { - - @Override - T get() { - log.info "Providing: {}", this - T create = create() as T - log.debug "Provided: {}", create - create - } - - abstract def create() -} diff --git a/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/ProviderTrait.java b/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/ProviderTrait.java new file mode 100644 index 000000000..a762a1618 --- /dev/null +++ b/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/ProviderTrait.java @@ -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; + +import com.google.inject.Provider; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public abstract class ProviderTrait implements Provider { + + private static final Logger LOG = LoggerFactory.getLogger(ProviderTrait.class); + + @Override + public T get() { + LOG.info("Providing: {}", this); + T create = create(); + LOG.debug("Provided: {}", create); + return create; + } + + protected abstract T create(); +} diff --git a/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/cfgattrs/CfgAttrsModule.groovy b/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/cfgattrs/CfgAttrsModule.groovy deleted file mode 100644 index b20f3cd32..000000000 --- a/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/cfgattrs/CfgAttrsModule.groovy +++ /dev/null @@ -1,34 +0,0 @@ -/* - * 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.cfgattrs - -import com.google.inject.AbstractModule -import groovy.util.logging.Slf4j -import net.jmob.guice.conf.core.ConfigurationModule - -/** - * Load the configuration from json into HoneycombConfiguration and make it available. - */ -@Slf4j -class CfgAttrsModule extends AbstractModule { - - protected void configure() { - install(ConfigurationModule.create()) - // Inject non-dependency configuration - requestInjection(HoneycombConfiguration) - } -} diff --git a/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/cfgattrs/CfgAttrsModule.java b/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/cfgattrs/CfgAttrsModule.java new file mode 100644 index 000000000..b22e88593 --- /dev/null +++ b/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/cfgattrs/CfgAttrsModule.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.cfgattrs; + +import com.google.inject.AbstractModule; +import net.jmob.guice.conf.core.ConfigurationModule; + +/** + * Load the configuration from json into HoneycombConfiguration and make it available. + */ +public class CfgAttrsModule extends AbstractModule { + + protected void configure() { + install(ConfigurationModule.create()); + // Inject non-dependency configuration + requestInjection(HoneycombConfiguration.class); + } + +} diff --git a/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/cfgattrs/HoneycombConfiguration.groovy b/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/cfgattrs/HoneycombConfiguration.groovy deleted file mode 100644 index 15f907f4b..000000000 --- a/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/cfgattrs/HoneycombConfiguration.groovy +++ /dev/null @@ -1,140 +0,0 @@ -/* - * 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.cfgattrs - -import groovy.transform.ToString -import net.jmob.guice.conf.core.BindConfig -import net.jmob.guice.conf.core.InjectConfig -import net.jmob.guice.conf.core.Syntax - -/** - * This is the Java equivalent for honeyconb.json file. - * We use guice-config library to load all the config attributes into this class instance. - * - * The BindConfig annotation tells that honeycomb.json file should be looked up on classpath root. - */ -@ToString(includeNames = true) -@BindConfig(value = "honeycomb", syntax = Syntax.JSON) -class HoneycombConfiguration { - - // TODO break into smaller pieces, config, context, rest, netconf etc. - - @InjectConfig("persisted-context-path") - String peristContextPath - @InjectConfig("persisted-context-restoration-type") - String persistedContextRestorationType - - @InjectConfig("persisted-config-path") - String peristConfigPath - @InjectConfig("persisted-config-restoration-type") - String persistedConfigRestorationType - - @InjectConfig("notification-service-queue-depth") - int notificationServiceQueueDepth - - // RESTCONF - // HTTP - @InjectConfig("restconf-http-enabled") - String restconfHttp - - @InjectConfig("restconf-binding-address") - Optional restconfBindingAddress - @InjectConfig("restconf-port") - Optional restconfPort - // HTTPS - @InjectConfig("restconf-https-enabled") - String restconfHttps - @InjectConfig("restconf-https-binding-address") - Optional restconfHttpsBindingAddress - @InjectConfig("restconf-https-port") - Optional restconfHttpsPort - /** - * Restconf keystore file name. - * It will be loaded from the classpath so must be present in one of the folders packaged with the distribution e.g. cert/ - */ - @InjectConfig("restconf-keystore") - Optional restconfKeystore = Optional.of("/honeycomb-keystore") - @InjectConfig("restconf-keystore-password") - Optional keystorePassword - @InjectConfig("restconf-keystore-manager-password") - Optional keystoreManagerPassword - /** - * Restconf truststore file name. - * It will be loaded from the classpath so must be present in one of the folders packaged with the distribution e.g. cert/ - */ - @InjectConfig("restconf-truststore") - Optional restconfTruststore - @InjectConfig("restconf-truststore-password") - Optional truststorePassword - - // This is the way for optional attributes with default values to work - @InjectConfig("restconf-websocket-port") - Optional restconfWebsocketPort = Optional.of(7779) - - @InjectConfig("restconf-root-path") - Optional restconfRootPath = Optional.of("/restconf") - @InjectConfig("restconf-pool-max-size") - Optional restPoolMaxSize = Optional.of(10) - @InjectConfig("restconf-pool-min-size") - Optional restPoolMinSize = Optional.of(1) - - @InjectConfig("restconf-acceptors-size") - Optional acceptorsSize = Optional.of(1) - @InjectConfig("restconf-selectors-size") - Optional selectorsSize = Optional.of(1) - @InjectConfig("restconf-https-acceptors-size") - Optional httpsAcceptorsSize = Optional.of(1) - @InjectConfig("restconf-https-selectors-size") - Optional httpsSelectorsSize = Optional.of(1) - - // Booleans not supported - boolean isRestconfHttpEnabled() { Boolean.valueOf(restconfHttp) } - boolean isRestconfHttpsEnabled() { Boolean.valueOf(restconfHttps) } - boolean isRestconfEnabled() { isRestconfHttpEnabled() || isRestconfHttpsEnabled() } - - // HONEYCOMB_NETCONF - @InjectConfig("netconf-netty-threads") - Integer netconfNettyThreads - - // HONEYCOMB_NETCONF TCP - @InjectConfig("netconf-tcp-enabled") - String netconfTcp - @InjectConfig("netconf-tcp-binding-address") - Optional netconfTcpBindingAddress - @InjectConfig("netconf-tcp-binding-port") - Optional netconfTcpBindingPort - - // HONEYCOMB_NETCONF SSH - @InjectConfig("netconf-ssh-enabled") - String netconfSsh - @InjectConfig("netconf-ssh-binding-address") - Optional netconfSshBindingAddress - @InjectConfig("netconf-ssh-binding-port") - Optional netconfSshBindingPort - - @InjectConfig("netconf-notification-stream-name") - Optional netconfNotificationStreamName = Optional.of("honeycomb") - - boolean isNetconfTcpEnabled() { Boolean.valueOf(netconfTcp) } - boolean isNetconfSshEnabled() { Boolean.valueOf(netconfSsh) } - boolean isNetconfEnabled() { isNetconfTcpEnabled() || isNetconfSshEnabled() } - - @InjectConfig("username") - String username - @InjectConfig("password") - String password -} diff --git a/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/cfgattrs/HoneycombConfiguration.java b/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/cfgattrs/HoneycombConfiguration.java new file mode 100644 index 000000000..8c09c7b71 --- /dev/null +++ b/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/cfgattrs/HoneycombConfiguration.java @@ -0,0 +1,174 @@ +/* + * 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.cfgattrs; + +import com.google.common.base.MoreObjects; +import java.util.Optional; +import net.jmob.guice.conf.core.BindConfig; +import net.jmob.guice.conf.core.InjectConfig; +import net.jmob.guice.conf.core.Syntax; + +/** + * This is the Java equivalent for honeyconb.json file. We use guice-config library to load all the config attributes + * into this class instance. + * + * The BindConfig annotation tells that honeycomb.json file should be looked up on classpath root. + */ +@BindConfig(value = "honeycomb", syntax = Syntax.JSON) +public class HoneycombConfiguration { + + public boolean isRestconfHttpEnabled() { + return Boolean.valueOf(restconfHttp); + } + + public boolean isRestconfHttpsEnabled() { + return Boolean.valueOf(restconfHttps); + } + + public boolean isRestconfEnabled() { + return isRestconfHttpEnabled() || isRestconfHttpsEnabled(); + } + + public boolean isNetconfTcpEnabled() { + return Boolean.valueOf(netconfTcp); + } + + public boolean isNetconfSshEnabled() { + return Boolean.valueOf(netconfSsh); + } + + public boolean isNetconfEnabled() { + return isNetconfTcpEnabled() || isNetconfSshEnabled(); + } + + @InjectConfig("persisted-context-path") + public String peristContextPath; + @InjectConfig("persisted-context-restoration-type") + public String persistedContextRestorationType; + @InjectConfig("persisted-config-path") + public String peristConfigPath; + @InjectConfig("persisted-config-restoration-type") + public String persistedConfigRestorationType; + @InjectConfig("notification-service-queue-depth") + public int notificationServiceQueueDepth; + @InjectConfig("restconf-http-enabled") + public String restconfHttp; + @InjectConfig("restconf-binding-address") + public Optional restconfBindingAddress; + @InjectConfig("restconf-port") + public Optional restconfPort; + @InjectConfig("restconf-https-enabled") + public String restconfHttps; + @InjectConfig("restconf-https-binding-address") + public Optional restconfHttpsBindingAddress; + @InjectConfig("restconf-https-port") + public Optional restconfHttpsPort; + /** + * Restconf keystore file name. It will be loaded from the classpath so must be present in one of the folders + * packaged with the distribution e.g. cert/ + */ + @InjectConfig("restconf-keystore") + public Optional restconfKeystore = Optional.of("/honeycomb-keystore"); + @InjectConfig("restconf-keystore-password") + public Optional keystorePassword; + @InjectConfig("restconf-keystore-manager-password") + public Optional keystoreManagerPassword; + /** + * Restconf truststore file name. It will be loaded from the classpath so must be present in one of the folders + * packaged with the distribution e.g. cert/ + */ + @InjectConfig("restconf-truststore") + public Optional restconfTruststore; + @InjectConfig("restconf-truststore-password") + public Optional truststorePassword; + @InjectConfig("restconf-websocket-port") + public Optional restconfWebsocketPort = Optional.of(7779); + @InjectConfig("restconf-root-path") + public Optional restconfRootPath = Optional.of("/restconf"); + @InjectConfig("restconf-pool-max-size") + public Optional restPoolMaxSize = Optional.of(10); + @InjectConfig("restconf-pool-min-size") + public Optional restPoolMinSize = Optional.of(1); + @InjectConfig("restconf-acceptors-size") + public Optional acceptorsSize = Optional.of(1); + @InjectConfig("restconf-selectors-size") + public Optional selectorsSize = Optional.of(1); + @InjectConfig("restconf-https-acceptors-size") + public Optional httpsAcceptorsSize = Optional.of(1); + @InjectConfig("restconf-https-selectors-size") + public Optional httpsSelectorsSize = Optional.of(1); + @InjectConfig("netconf-netty-threads") + public Integer netconfNettyThreads; + @InjectConfig("netconf-tcp-enabled") + public String netconfTcp; + @InjectConfig("netconf-tcp-binding-address") + public Optional netconfTcpBindingAddress; + @InjectConfig("netconf-tcp-binding-port") + public Optional netconfTcpBindingPort; + @InjectConfig("netconf-ssh-enabled") + public String netconfSsh; + @InjectConfig("netconf-ssh-binding-address") + public Optional netconfSshBindingAddress; + @InjectConfig("netconf-ssh-binding-port") + public Optional netconfSshBindingPort; + @InjectConfig("netconf-notification-stream-name") + public Optional netconfNotificationStreamName = Optional.of("honeycomb"); + @InjectConfig("username") + public String username; + @InjectConfig("password") + public String password; + + @Override + public String toString() { + return MoreObjects.toStringHelper(this) + .add("peristContextPath", peristContextPath) + .add("persistedContextRestorationType", persistedContextRestorationType) + .add("peristConfigPath", peristConfigPath) + .add("persistedConfigRestorationType", persistedConfigRestorationType) + .add("notificationServiceQueueDepth", notificationServiceQueueDepth) + .add("restconfHttp", restconfHttp) + .add("restconfBindingAddress", restconfBindingAddress) + .add("restconfPort", restconfPort) + .add("restconfHttps", restconfHttps) + .add("restconfHttpsBindingAddress", restconfHttpsBindingAddress) + .add("restconfHttpsPort", restconfHttpsPort) + .add("restconfKeystore", restconfKeystore) + .add("keystorePassword", keystorePassword) + .add("keystoreManagerPassword", keystoreManagerPassword) + .add("restconfTruststore", restconfTruststore) + .add("truststorePassword", truststorePassword) + .add("restconfWebsocketPort", restconfWebsocketPort) + .add("restconfRootPath", restconfRootPath) + .add("restPoolMaxSize", restPoolMaxSize) + .add("restPoolMinSize", restPoolMinSize) + .add("acceptorsSize", acceptorsSize) + .add("selectorsSize", selectorsSize) + .add("httpsAcceptorsSize", httpsAcceptorsSize) + .add("httpsSelectorsSize", httpsSelectorsSize) + .add("netconfNettyThreads", netconfNettyThreads) + .add("netconfTcp", netconfTcp) + .add("netconfTcpBindingAddress", netconfTcpBindingAddress) + .add("netconfTcpBindingPort", netconfTcpBindingPort) + .add("netconfSsh", netconfSsh) + .add("netconfSshBindingAddress", netconfSshBindingAddress) + .add("netconfSshBindingPort", netconfSshBindingPort) + .add("netconfNotificationStreamName", netconfNotificationStreamName) + .add("username", username) + .add("password", password) + .toString(); + } +} 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 deleted file mode 100644 index e73f14932..000000000 --- a/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/data/BindingDataBrokerProvider.groovy +++ /dev/null @@ -1,39 +0,0 @@ -/* - * 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/BindingDataBrokerProvider.java b/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/data/BindingDataBrokerProvider.java new file mode 100644 index 000000000..e17355143 --- /dev/null +++ b/infra/minimal-distribution/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 { + + @Inject + private DOMDataBroker domDataBroker; + @Inject + private BindingToNormalizedNodeCodec mappingService; + + @Override + protected BindingDOMDataBrokerAdapter create() { + return 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 deleted file mode 100644 index eb17cf36a..000000000 --- a/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/data/ConfigAndOperationalPipelineModule.groovy +++ /dev/null @@ -1,96 +0,0 @@ -/* - * 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.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 - -@Slf4j -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(ModifiableWriterRegistryBuilder).toProvider(WriterRegistryProvider).in(Singleton) - expose(ModifiableWriterRegistryBuilder) - bind(ModifiableReaderRegistryBuilder).toProvider(ReaderRegistryProvider).in(Singleton) - expose(ModifiableReaderRegistryBuilder) - - // Non persisting data tree for config - bind(DataTree) - .annotatedWith(Names.named(HONEYCOMB_CONFIG_NONPERSIST)) - .toProvider(DataTreeProvider.ConfigDataTreeProvider) - .in(Singleton) - expose(DataTree).annotatedWith(Names.named(HONEYCOMB_CONFIG_NONPERSIST)) - // Persisting data tree wrapper for config - bind(DataTree) - .annotatedWith(Names.named(HONEYCOMB_CONFIG)) - .toProvider(PersistingDataTreeProvider.ConfigPersistingDataTreeProvider) - .in(Singleton) - expose(DataTree).annotatedWith(Names.named(HONEYCOMB_CONFIG)) - - // Config Data Tree manager working on top of config data tree + writer registry - bind(ModifiableDataManager).toProvider(ModifiableDTDelegProvider).in(Singleton) - // Operational Data Tree manager working on top of reader registry - bind(ReadableDataManager).toProvider(ReadableDTDelegProvider).in(Singleton) - expose(ReadableDataManager) - - // DOMDataBroker wrapper on top of data tree managers - def domBrokerProvider = new HoneycombDOMDataBrokerProvider() - bind(DOMDataBroker).toProvider(domBrokerProvider).in(Singleton) - - // BA version of data broker - bind(DataBroker).annotatedWith(Names.named(HONEYCOMB_CONFIG)).toProvider(BindingDataBrokerProvider).in(Singleton) - expose(DataBroker).annotatedWith(Names.named(HONEYCOMB_CONFIG)) - - // Create initializer to init persisted config data - bind(DataTreeInitializer) - .annotatedWith(Names.named(HONEYCOMB_CONFIG)) - .toProvider(PersistedFileInitializerProvider.PersistedConfigInitializerProvider) - .in(Singleton) - expose(DataTreeInitializer).annotatedWith(Names.named(HONEYCOMB_CONFIG)) - - configureNotifications() - } - - protected void configureNotifications() { - // Create notification service - bind(DOMNotificationRouter).toProvider(DOMNotificationServiceProvider).in(Singleton) - expose(DOMNotificationRouter) - // Wrap notification service, data broker and schema service in a Broker MD-SAL API - bind(Broker).toProvider(HoneycombDOMBrokerProvider).in(Singleton) - expose(Broker) - } -} diff --git a/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/data/ConfigAndOperationalPipelineModule.java b/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/data/ConfigAndOperationalPipelineModule.java new file mode 100644 index 000000000..bac1b3ce0 --- /dev/null +++ b/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/data/ConfigAndOperationalPipelineModule.java @@ -0,0 +1,90 @@ +/* + * 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.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.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(ModifiableWriterRegistryBuilder.class).toProvider(WriterRegistryProvider.class).in(Singleton.class); + expose(ModifiableWriterRegistryBuilder.class); + bind(ModifiableReaderRegistryBuilder.class).toProvider(ReaderRegistryProvider.class).in(Singleton.class); + expose(ModifiableReaderRegistryBuilder.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(); + } + + 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); + } +} 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 deleted file mode 100644 index f8a1859e2..000000000 --- a/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/data/DOMNotificationServiceProvider.groovy +++ /dev/null @@ -1,34 +0,0 @@ -/* - * 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/DOMNotificationServiceProvider.java b/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/data/DOMNotificationServiceProvider.java new file mode 100644 index 000000000..424393b8d --- /dev/null +++ b/infra/minimal-distribution/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 { + + @Inject + private HoneycombConfiguration cfg; + + @Override + protected DOMNotificationRouter create() { + return 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 deleted file mode 100644 index 6d075ccc8..000000000 --- a/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/data/DataStoreProvider.groovy +++ /dev/null @@ -1,40 +0,0 @@ -/* - * 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/DataStoreProvider.java b/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/data/DataStoreProvider.java new file mode 100644 index 000000000..5b09f21f8 --- /dev/null +++ b/infra/minimal-distribution/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 { + + @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/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 deleted file mode 100644 index bf1f562ec..000000000 --- a/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/data/DataTreeProvider.groovy +++ /dev/null @@ -1,57 +0,0 @@ -/* - * 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 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.TreeType -import org.opendaylight.yangtools.yang.data.impl.schema.tree.InMemoryDataTreeFactory - -@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()) - delegate - } - - abstract TreeType getType() - - @Slf4j - @ToString - static class ConfigDataTreeProvider extends DataTreeProvider { - TreeType getType() { TreeType.CONFIGURATION } - } - - @Slf4j - @ToString - static class ContextDataTreeProvider extends DataTreeProvider { - TreeType getType() { TreeType.OPERATIONAL } - } -} diff --git a/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/data/DataTreeProvider.java b/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/data/DataTreeProvider.java new file mode 100644 index 000000000..c5fcc050a --- /dev/null +++ b/infra/minimal-distribution/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 { + + @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/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 deleted file mode 100644 index dc620b445..000000000 --- a/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/data/HoneycombDOMBrokerProvider.groovy +++ /dev/null @@ -1,41 +0,0 @@ -/* - * 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.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.broker.impl.DOMNotificationRouter -import org.opendaylight.controller.sal.core.api.Broker -import org.opendaylight.controller.sal.core.api.model.SchemaService - -@Slf4j -@ToString -class HoneycombDOMBrokerProvider extends ProviderTrait { - - @Inject - DOMDataBroker domDataBroker - @Inject - SchemaService schemaService - @Inject - DOMNotificationRouter domNotificationService - - def create() { new NorthboundFacadeHoneycombDOMBroker(domDataBroker, schemaService, domNotificationService) } -} diff --git a/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/data/HoneycombDOMBrokerProvider.java b/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/data/HoneycombDOMBrokerProvider.java new file mode 100644 index 000000000..eefa1c140 --- /dev/null +++ b/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/data/HoneycombDOMBrokerProvider.java @@ -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 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.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 { + + @Inject + private DOMDataBroker domDataBroker; + @Inject + private SchemaService schemaService; + @Inject + private DOMNotificationRouter domNotificationService; + + @Override + protected NorthboundFacadeHoneycombDOMBroker create() { + return 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 deleted file mode 100644 index a2fec2a60..000000000 --- a/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/data/HoneycombDOMDataBrokerProvider.groovy +++ /dev/null @@ -1,41 +0,0 @@ -/* - * 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.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 - 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/HoneycombDOMDataBrokerProvider.java b/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/data/HoneycombDOMDataBrokerProvider.java new file mode 100644 index 000000000..92bbc512d --- /dev/null +++ b/infra/minimal-distribution/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 { + + @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/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 deleted file mode 100644 index b81a8d784..000000000 --- a/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/data/HoneycombNotificationManagerProvider.groovy +++ /dev/null @@ -1,67 +0,0 @@ -/* - * 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 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 - -@Slf4j -@ToString -class HoneycombNotificationManagerProvider extends ProviderTrait { - - @Inject - 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/HoneycombNotificationManagerProvider.java b/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/data/HoneycombNotificationManagerProvider.java new file mode 100644 index 000000000..e25cb1569 --- /dev/null +++ b/infra/minimal-distribution/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 { + + @Inject + private DOMNotificationRouter notificationRouter; + @Inject(optional = true) + private Set 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); + + // 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. + + return 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 deleted file mode 100644 index a04f1a81c..000000000 --- a/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/data/InmemoryDOMDataBrokerProvider.groovy +++ /dev/null @@ -1,63 +0,0 @@ -/* - * 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 - -@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/InmemoryDOMDataBrokerProvider.java b/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/data/InmemoryDOMDataBrokerProvider.java new file mode 100644 index 000000000..7db2f7856 --- /dev/null +++ b/infra/minimal-distribution/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 { + + 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 try to provide more lightweight implementation of DataBroker, maybe a single executor would be enough + + Map 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/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 deleted file mode 100644 index cd4d9c624..000000000 --- a/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/data/ModifiableDTDelegProvider.groovy +++ /dev/null @@ -1,49 +0,0 @@ -/* - * 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.infra.distro.data.context.ContextPipelineModule -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(ConfigAndOperationalPipelineModule.HONEYCOMB_CONFIG) - DataTree dataTree - @Inject - ModifiableWriterRegistryBuilder registry - @Inject - @Named(ContextPipelineModule.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/ModifiableDTDelegProvider.java b/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/data/ModifiableDTDelegProvider.java new file mode 100644 index 000000000..edd4faadb --- /dev/null +++ b/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/data/ModifiableDTDelegProvider.java @@ -0,0 +1,49 @@ +/* + * 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.ModifiableWriterRegistryBuilder; +import io.fd.honeycomb.translate.write.registry.WriterRegistryBuilder; +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; + +public final class ModifiableDTDelegProvider extends ProviderTrait { + + @Inject + private BindingToNormalizedNodeCodec serializer; + @Inject + @Named(ConfigAndOperationalPipelineModule.HONEYCOMB_CONFIG) + private DataTree dataTree; + @Inject + private ModifiableWriterRegistryBuilder registry; + @Inject + @Named(ContextPipelineModule.HONEYCOMB_CONTEXT) + private DataBroker contextBroker; + + @Override + protected ModifiableDataTreeDelegator create() { + return new ModifiableDataTreeDelegator(serializer, dataTree, + ((WriterRegistryBuilder) registry).build(), contextBroker); + } +} diff --git a/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/data/PersistingDataTreeProvider.groovy b/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/data/PersistingDataTreeProvider.groovy deleted file mode 100644 index 6c41ad69f..000000000 --- a/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/data/PersistingDataTreeProvider.groovy +++ /dev/null @@ -1,71 +0,0 @@ -/* - * 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.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 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 java.nio.file.Paths - -@Slf4j -@ToString -abstract class PersistingDataTreeProvider extends ProviderTrait { - - @Inject - SchemaService schemaService - @Inject - HoneycombConfiguration config - - def create() { - new PersistingDataTreeAdapter(delegate, schemaService, Paths.get(path)) - } - - abstract String getPath() - abstract TreeType getType() - abstract DataTree getDelegate() - - static class ConfigPersistingDataTreeProvider extends PersistingDataTreeProvider { - - @Inject - @Named(ConfigAndOperationalPipelineModule.HONEYCOMB_CONFIG_NONPERSIST) - DataTree delegate - - String getPath() { config.peristConfigPath } - TreeType getType() { TreeType.CONFIGURATION } - DataTree getDelegate() { return delegate } - } - - static class ContextPersistingDataTreeProvider extends PersistingDataTreeProvider { - - @Inject - @Named(ContextPipelineModule.HONEYCOMB_CONTEXT_NOPERSIST) - DataTree delegate - - String getPath() { config.peristContextPath } - TreeType getType() { TreeType.OPERATIONAL } - DataTree getDelegate() { return delegate } - } -} diff --git a/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/data/PersistingDataTreeProvider.java b/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/data/PersistingDataTreeProvider.java new file mode 100644 index 000000000..fb4ebc69d --- /dev/null +++ b/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/data/PersistingDataTreeProvider.java @@ -0,0 +1,84 @@ +/* + * 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 { + + @Inject + private SchemaService schemaService; + @Inject + protected HoneycombConfiguration config; + + public PersistingDataTreeAdapter create() { + return new PersistingDataTreeAdapter(getDelegate(), schemaService, Paths.get(getPath())); + } + + public abstract String getPath(); + + public abstract TreeType getType(); + + public abstract DataTree getDelegate(); + + 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; + } + } + + 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; + } + } +} 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 deleted file mode 100644 index 3c94812ef..000000000 --- a/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/data/config/WriterRegistryProvider.groovy +++ /dev/null @@ -1,39 +0,0 @@ -/* - * 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/config/WriterRegistryProvider.java b/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/data/config/WriterRegistryProvider.java new file mode 100644 index 000000000..f3e8ce200 --- /dev/null +++ b/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/data/config/WriterRegistryProvider.java @@ -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.config; + +import com.google.inject.Inject; +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; +import java.util.HashSet; +import java.util.Set; + +public final class WriterRegistryProvider extends ProviderTrait { + + @Inject(optional = true) + private Set writerFactories = new HashSet<>(); + + @Override + protected FlatWriterRegistryBuilder create() { + final FlatWriterRegistryBuilder builder = new FlatWriterRegistryBuilder(); + writerFactories + .stream() + .forEach(it -> it.init(builder)); + return 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 deleted file mode 100644 index a4cf73162..000000000 --- a/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/data/context/ContextPipelineModule.groovy +++ /dev/null @@ -1,76 +0,0 @@ -/* - * 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 - -class ContextPipelineModule extends PrivateModule { - - public static final String HONEYCOMB_CONTEXT_NOPERSIST = "honeycomb-context-nopersist" - public static final String HONEYCOMB_CONTEXT = "honeycomb-context" - - protected void configure() { - // Non persisting data tree for context - def noPersistDataTreeProvider = new DataTreeProvider.ContextDataTreeProvider() - bind(DataTree) - .annotatedWith(Names.named(HONEYCOMB_CONTEXT_NOPERSIST)) - .toProvider(noPersistDataTreeProvider) - .in(Singleton) - expose(DataTree).annotatedWith(Names.named(HONEYCOMB_CONTEXT_NOPERSIST)) - // Persisting data tree wrapper for context - def dataTreeProvider = new PersistingDataTreeProvider.ContextPersistingDataTreeProvider() - bind(DataTree).toProvider(dataTreeProvider).in(Singleton) - - // Data Tree manager (without any delegation) on top of context data tree - bind(ModifiableDataManager).toProvider(ModifiableDTMgrProvider).in(Singleton) - - // DOMDataBroker interface on top of data tree manager - def domBrokerProvider = new HoneycombContextDOMDataBrokerProvider() - bind(DOMDataBroker).toProvider(domBrokerProvider).in(Singleton) - - // BA version of data broker for context - bind(DataBroker).annotatedWith(Names.named(HONEYCOMB_CONTEXT)).toProvider(BindingDataBrokerProvider).in(Singleton) - expose(DataBroker).annotatedWith(Names.named(HONEYCOMB_CONTEXT)) - - // Create initializer to init persisted config data - bind(DataTreeInitializer) - .annotatedWith(Names.named(HONEYCOMB_CONTEXT)) - .toProvider(PersistedFileInitializerProvider.PersistedContextInitializerProvider) - .in(Singleton) - expose(DataTreeInitializer).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) - .annotatedWith(Names.named(HONEYCOMB_CONTEXT)) - .toProvider(RealtimeMappingContextProvider) - .in(Singleton.class) - expose(MappingContext).annotatedWith(Names.named(HONEYCOMB_CONTEXT)) - } - -} diff --git a/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/data/context/ContextPipelineModule.java b/infra/minimal-distribution/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/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/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 deleted file mode 100644 index eecd87e42..000000000 --- a/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/data/context/HoneycombContextDOMDataBrokerProvider.groovy +++ /dev/null @@ -1,36 +0,0 @@ -/* - * 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/HoneycombContextDOMDataBrokerProvider.java b/infra/minimal-distribution/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/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 { + + @Inject + private ModifiableDataManager modDataManager; + + public DataBroker create() { + return 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 deleted file mode 100644 index 01d854b28..000000000 --- a/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/data/context/ModifiableDTMgrProvider.groovy +++ /dev/null @@ -1,36 +0,0 @@ -/* - * 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/context/ModifiableDTMgrProvider.java b/infra/minimal-distribution/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/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 { + + @Inject + private DataTree dataTree; + + @Override + public ModifiableDataTreeManager create() { + return new ModifiableDataTreeManager(dataTree); + } +} diff --git a/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/data/context/RealtimeMappingContextProvider.groovy b/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/data/context/RealtimeMappingContextProvider.groovy deleted file mode 100644 index c6afd92fc..000000000 --- a/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/data/context/RealtimeMappingContextProvider.groovy +++ /dev/null @@ -1,40 +0,0 @@ -/* - * 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 groovy.transform.ToString -import groovy.util.logging.Slf4j -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 - -@Slf4j -@ToString -class RealtimeMappingContextProvider extends ProviderTrait { - - @Inject - @Named(ContextPipelineModule.HONEYCOMB_CONTEXT) - DataBroker contextDataBroker - - @Override - def create() { - new RealtimeMappingContext(contextDataBroker) - } -} diff --git a/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/data/context/RealtimeMappingContextProvider.java b/infra/minimal-distribution/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/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 { + + @Inject + @Named(ContextPipelineModule.HONEYCOMB_CONTEXT) + private DataBroker contextDataBroker; + + @Override + public RealtimeMappingContext create() { + return new RealtimeMappingContext(contextDataBroker); + } + +} 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 deleted file mode 100644 index 11eaf49a4..000000000 --- a/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/data/oper/ReadableDTDelegProvider.groovy +++ /dev/null @@ -1,49 +0,0 @@ -/* - * 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.infra.distro.data.context.ContextPipelineModule -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(ContextPipelineModule.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/ReadableDTDelegProvider.java b/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/data/oper/ReadableDTDelegProvider.java new file mode 100644 index 000000000..13e82e85f --- /dev/null +++ b/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/data/oper/ReadableDTDelegProvider.java @@ -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 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.ModifiableReaderRegistryBuilder; +import io.fd.honeycomb.translate.read.registry.ReaderRegistryBuilder; +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 { + + @Inject + private BindingToNormalizedNodeCodec serializer; + @Inject + private SchemaService schemaService; + @Inject + private ModifiableReaderRegistryBuilder registry; + @Inject + @Named(ContextPipelineModule.HONEYCOMB_CONTEXT) + private DataBroker contextBroker; + + @Override + protected ReadableDataTreeDelegator create() { + return new ReadableDataTreeDelegator(serializer, schemaService.getGlobalContext(), + ((ReaderRegistryBuilder) 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 deleted file mode 100644 index 36f74d948..000000000 --- a/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/data/oper/ReaderRegistryProvider.groovy +++ /dev/null @@ -1,39 +0,0 @@ -/* - * 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 - } -} diff --git a/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/data/oper/ReaderRegistryProvider.java b/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/data/oper/ReaderRegistryProvider.java new file mode 100644 index 000000000..ef09e0e97 --- /dev/null +++ b/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/data/oper/ReaderRegistryProvider.java @@ -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.oper; + +import com.google.inject.Inject; +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; +import java.util.HashSet; +import java.util.Set; + +public final class ReaderRegistryProvider extends ProviderTrait { + + @Inject(optional = true) + private Set readerFactories = new HashSet<>(); + + @Override + protected CompositeReaderRegistryBuilder create() { + final CompositeReaderRegistryBuilder builder = new CompositeReaderRegistryBuilder(); + readerFactories.stream() + .forEach(it -> it.init(builder)); + return builder; + } + +} diff --git a/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/initializer/InitializerPipelineModule.groovy b/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/initializer/InitializerPipelineModule.groovy deleted file mode 100644 index 4bd197385..000000000 --- a/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/initializer/InitializerPipelineModule.groovy +++ /dev/null @@ -1,53 +0,0 @@ -/* - * 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.initializer - -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.init.InitializerRegistry -import io.fd.honeycomb.infra.distro.data.BindingDataBrokerProvider -import io.fd.honeycomb.infra.distro.data.HoneycombDOMDataBrokerProvider -import org.opendaylight.controller.md.sal.binding.api.DataBroker -import org.opendaylight.controller.md.sal.dom.api.DOMDataBroker - -@Slf4j -class InitializerPipelineModule extends PrivateModule { - - - public static final String HONEYCOMB_INITIALIZER = "honeycomb-initializer" - - protected void configure() { - // Create data tree manager on top of non-persisting config data tree - bind(ModifiableDataManager).toProvider(ModifiableDTDelegInitProvider).in(Singleton) - // Wrap as DOMDataBroker - bind(DOMDataBroker).toProvider(HoneycombDOMDataBrokerProvider).in(Singleton) - // Wrap as BA data broker - bind(DataBroker).annotatedWith(Names.named(HONEYCOMB_INITIALIZER)).toProvider(BindingDataBrokerProvider).in(Singleton) - expose(DataBroker).annotatedWith(Names.named(HONEYCOMB_INITIALIZER)) - - // Create initializer registry so that plugins can provide their initializers - bind(InitializerRegistry) - .annotatedWith(Names.named(HONEYCOMB_INITIALIZER)) - .toProvider(InitializerRegistryProvider) - .in(Singleton) - expose(InitializerRegistry) - .annotatedWith(Names.named(HONEYCOMB_INITIALIZER)) - } -} diff --git a/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/initializer/InitializerPipelineModule.java b/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/initializer/InitializerPipelineModule.java new file mode 100644 index 000000000..f5240093e --- /dev/null +++ b/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/initializer/InitializerPipelineModule.java @@ -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.initializer; + +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.InitializerRegistry; +import io.fd.honeycomb.infra.distro.data.BindingDataBrokerProvider; +import io.fd.honeycomb.infra.distro.data.HoneycombDOMDataBrokerProvider; +import org.opendaylight.controller.md.sal.binding.api.DataBroker; +import org.opendaylight.controller.md.sal.dom.api.DOMDataBroker; + +public final class InitializerPipelineModule extends PrivateModule { + + public static final String HONEYCOMB_INITIALIZER = "honeycomb-initializer"; + + protected void configure() { + // Create data tree manager on top of non-persisting config data tree + bind(ModifiableDataManager.class).toProvider(ModifiableDTDelegInitProvider.class).in(Singleton.class); + // Wrap as DOMDataBroker + bind(DOMDataBroker.class).toProvider(HoneycombDOMDataBrokerProvider.class).in(Singleton.class); + // Wrap as BA data broker + bind(DataBroker.class).annotatedWith(Names.named(HONEYCOMB_INITIALIZER)) + .toProvider(BindingDataBrokerProvider.class).in(Singleton.class); + expose(DataBroker.class).annotatedWith(Names.named(HONEYCOMB_INITIALIZER)); + + // Create initializer registry so that plugins can provide their initializers + bind(InitializerRegistry.class).annotatedWith(Names.named(HONEYCOMB_INITIALIZER)) + .toProvider(InitializerRegistryProvider.class).in(Singleton.class); + expose(InitializerRegistry.class).annotatedWith(Names.named(HONEYCOMB_INITIALIZER)); + } +} diff --git a/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/initializer/InitializerRegistryAdapter.java b/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/initializer/InitializerRegistryAdapter.java new file mode 100644 index 000000000..4d488cfdb --- /dev/null +++ b/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/initializer/InitializerRegistryAdapter.java @@ -0,0 +1,69 @@ +/* + * 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.initializer; + +import com.google.common.collect.Lists; +import io.fd.honeycomb.data.init.DataTreeInitializer; +import io.fd.honeycomb.data.init.InitializerRegistry; +import io.fd.honeycomb.data.init.InitializerRegistryImpl; +import java.util.List; +import java.util.Set; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +final class InitializerRegistryAdapter implements InitializerRegistry { + + private static final Logger LOG = LoggerFactory.getLogger(InitializerRegistryAdapter.class); + + private final DataTreeInitializer configInitializer; + private final DataTreeInitializer contextInitializer; + private final List pluginInitializers; + + InitializerRegistryAdapter(final DataTreeInitializer configInitializer, final DataTreeInitializer contextInitializer, + final Set pluginInitializers) { + this.configInitializer = configInitializer; + this.contextInitializer = contextInitializer; + this.pluginInitializers = Lists.newArrayList(pluginInitializers); + } + + @Override + public void initialize() throws DataTreeInitializer.InitializeException { + LOG.info("Config initialization started"); + + final InitializerRegistry initializer = new InitializerRegistryImpl(pluginInitializers); + + try { + // Initialize contexts first so that other initializers can find any relevant mapping before initializing + // configuration to what is already in VPP + contextInitializer.initialize(); + LOG.info("Persisted context restored successfully"); + // Initialize all registered initializers + initializer.initialize(); + LOG.info("Configuration initialized successfully"); + // Initialize stored configuration on top + configInitializer.initialize(); + LOG.info("Persisted configuration restored successfully"); + } catch (Exception e) { + LOG.warn("Failed to initialize config", e); + } + + LOG.info("Honeycomb initialized"); + } + + @Override + public void close() throws Exception {} +} diff --git a/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/initializer/InitializerRegistryProvider.groovy b/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/initializer/InitializerRegistryProvider.groovy deleted file mode 100644 index 6c90291b9..000000000 --- a/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/initializer/InitializerRegistryProvider.groovy +++ /dev/null @@ -1,75 +0,0 @@ -/* - * 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.initializer - -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.init.DataTreeInitializer -import io.fd.honeycomb.data.init.InitializerRegistry -import io.fd.honeycomb.data.init.InitializerRegistryImpl -import io.fd.honeycomb.infra.distro.ProviderTrait -import io.fd.honeycomb.infra.distro.data.ConfigAndOperationalPipelineModule -import io.fd.honeycomb.infra.distro.data.context.ContextPipelineModule - -@Slf4j -@ToString -class InitializerRegistryProvider extends ProviderTrait { - - @Inject - @Named(ContextPipelineModule.HONEYCOMB_CONTEXT) - DataTreeInitializer contextInitializer - @Inject - @Named(ConfigAndOperationalPipelineModule.HONEYCOMB_CONFIG) - DataTreeInitializer configInitializer - @Inject(optional = true) - Set pluginInitializers = [] - - @Override - def create() { - return new InitializerRegistry() { - - @Override - void initialize() throws DataTreeInitializer.InitializeException { - log.info("Config initialization started"); - - final InitializerRegistry initializer = new InitializerRegistryImpl(new ArrayList<>(pluginInitializers)) - - try { - // Initialize contexts first so that other initializers can find any relevant mapping before initializing - // configuration to what is already in VPP - contextInitializer.initialize(); - log.info("Persisted context restored successfully"); - // Initialize all registered initializers - initializer.initialize(); - log.info("Configuration initialized successfully"); - // Initialize stored configuration on top - configInitializer.initialize(); - log.info("Persisted configuration restored successfully"); - } catch (Exception e) { - log.warn("Failed to initialize config", e); - } - - log.info("Honeycomb initialized"); - } - - @Override - void close() throws Exception {} - } - } -} diff --git a/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/initializer/InitializerRegistryProvider.java b/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/initializer/InitializerRegistryProvider.java new file mode 100644 index 000000000..e984b0154 --- /dev/null +++ b/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/initializer/InitializerRegistryProvider.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.initializer; + +import com.google.inject.Inject; +import com.google.inject.name.Named; +import io.fd.honeycomb.data.init.DataTreeInitializer; +import io.fd.honeycomb.data.init.InitializerRegistry; +import io.fd.honeycomb.infra.distro.ProviderTrait; +import io.fd.honeycomb.infra.distro.data.ConfigAndOperationalPipelineModule; +import io.fd.honeycomb.infra.distro.data.context.ContextPipelineModule; +import java.util.HashSet; +import java.util.Set; + +public final class InitializerRegistryProvider extends ProviderTrait { + + @Inject + @Named(ContextPipelineModule.HONEYCOMB_CONTEXT) + private DataTreeInitializer contextInitializer; + @Inject + @Named(ConfigAndOperationalPipelineModule.HONEYCOMB_CONFIG) + private DataTreeInitializer configInitializer; + @Inject(optional = true) + private Set pluginInitializers = new HashSet<>(); + + @Override + protected InitializerRegistryAdapter create() { + return new InitializerRegistryAdapter(contextInitializer, configInitializer, pluginInitializers); + } +} diff --git a/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/initializer/ModifiableDTDelegInitProvider.groovy b/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/initializer/ModifiableDTDelegInitProvider.groovy deleted file mode 100644 index 4c132756e..000000000 --- a/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/initializer/ModifiableDTDelegInitProvider.groovy +++ /dev/null @@ -1,48 +0,0 @@ -/* - * 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.initializer - -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.infra.distro.data.ConfigAndOperationalPipelineModule -import io.fd.honeycomb.infra.distro.data.context.ContextPipelineModule -import io.fd.honeycomb.translate.util.write.NoopWriterRegistry -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 ModifiableDTDelegInitProvider extends ProviderTrait { - - @Inject - BindingToNormalizedNodeCodec serializer - @Inject - @Named(ConfigAndOperationalPipelineModule.HONEYCOMB_CONFIG_NONPERSIST) - DataTree dataTree - @Inject - @Named(ContextPipelineModule.HONEYCOMB_CONTEXT) - DataBroker contextBroker - - @Override - def create() { new ModifiableDataTreeDelegator(serializer, dataTree, new NoopWriterRegistry(), contextBroker) } -} diff --git a/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/initializer/ModifiableDTDelegInitProvider.java b/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/initializer/ModifiableDTDelegInitProvider.java new file mode 100644 index 000000000..8da9d75be --- /dev/null +++ b/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/initializer/ModifiableDTDelegInitProvider.java @@ -0,0 +1,46 @@ +/* + * 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.initializer; + +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.ConfigAndOperationalPipelineModule; +import io.fd.honeycomb.infra.distro.data.context.ContextPipelineModule; +import io.fd.honeycomb.translate.util.write.NoopWriterRegistry; +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; + +public final class ModifiableDTDelegInitProvider extends ProviderTrait { + + @Inject + private BindingToNormalizedNodeCodec serializer; + @Inject + @Named(ConfigAndOperationalPipelineModule.HONEYCOMB_CONFIG_NONPERSIST) + private DataTree dataTree; + @Inject + @Named(ContextPipelineModule.HONEYCOMB_CONTEXT) + private DataBroker contextBroker; + + @Override + public ModifiableDataTreeDelegator create() { + return new ModifiableDataTreeDelegator(serializer, dataTree, new NoopWriterRegistry(), contextBroker); + } +} diff --git a/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/initializer/PersistedFileInitializerProvider.groovy b/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/initializer/PersistedFileInitializerProvider.groovy deleted file mode 100644 index bb7015e01..000000000 --- a/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/initializer/PersistedFileInitializerProvider.groovy +++ /dev/null @@ -1,65 +0,0 @@ -/* - * 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.initializer - -import com.google.inject.Inject -import groovy.transform.ToString -import groovy.util.logging.Slf4j - -import io.fd.honeycomb.data.init.RestoringInitializer -import io.fd.honeycomb.infra.distro.ProviderTrait -import io.fd.honeycomb.infra.distro.cfgattrs.HoneycombConfiguration -import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType -import org.opendaylight.controller.md.sal.dom.api.DOMDataBroker -import org.opendaylight.controller.sal.core.api.model.SchemaService - -import java.nio.file.Paths - -@Slf4j -@ToString -abstract class PersistedFileInitializerProvider extends ProviderTrait { - - @Inject - SchemaService schemaService - @Inject - HoneycombConfiguration cfgAttributes - - @Inject - DOMDataBroker domDataBroker - - @Override - def create() { - new RestoringInitializer(schemaService, Paths.get(getPersistPath()), - domDataBroker, RestoringInitializer.RestorationType.valueOf(restorationType), getDataStoreType()) - } - - abstract String getPersistPath() - abstract LogicalDatastoreType getDataStoreType() - abstract String getRestorationType() - - static class PersistedContextInitializerProvider extends PersistedFileInitializerProvider { - String getPersistPath() { cfgAttributes.peristContextPath } - LogicalDatastoreType getDataStoreType() { LogicalDatastoreType.OPERATIONAL } - String getRestorationType() { cfgAttributes.persistedContextRestorationType } - } - - static class PersistedConfigInitializerProvider extends PersistedFileInitializerProvider { - String getPersistPath() { cfgAttributes.peristConfigPath } - LogicalDatastoreType getDataStoreType() { LogicalDatastoreType.CONFIGURATION } - String getRestorationType() { cfgAttributes.persistedConfigRestorationType } - } -} diff --git a/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/initializer/PersistedFileInitializerProvider.java b/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/initializer/PersistedFileInitializerProvider.java new file mode 100644 index 000000000..58d63cfb3 --- /dev/null +++ b/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/initializer/PersistedFileInitializerProvider.java @@ -0,0 +1,78 @@ +/* + * 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.initializer; + +import com.google.inject.Inject; +import io.fd.honeycomb.data.init.RestoringInitializer; +import io.fd.honeycomb.infra.distro.ProviderTrait; +import io.fd.honeycomb.infra.distro.cfgattrs.HoneycombConfiguration; +import java.nio.file.Paths; +import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType; +import org.opendaylight.controller.md.sal.dom.api.DOMDataBroker; +import org.opendaylight.controller.sal.core.api.model.SchemaService; + +public abstract class PersistedFileInitializerProvider extends ProviderTrait { + + @Inject + private SchemaService schemaService; + @Inject + protected HoneycombConfiguration cfgAttributes; + @Inject + private DOMDataBroker domDataBroker; + + @Override + public RestoringInitializer create() { + return new RestoringInitializer(schemaService, Paths.get(getPersistPath()), domDataBroker, + RestoringInitializer.RestorationType.valueOf(getRestorationType()), getDataStoreType()); + } + + public abstract String getPersistPath(); + + public abstract LogicalDatastoreType getDataStoreType(); + + public abstract String getRestorationType(); + + public static class PersistedContextInitializerProvider extends PersistedFileInitializerProvider { + public String getPersistPath() { + return cfgAttributes.peristContextPath; + } + + public LogicalDatastoreType getDataStoreType() { + return LogicalDatastoreType.OPERATIONAL; + } + + public String getRestorationType() { + return cfgAttributes.persistedContextRestorationType; + } + + } + + public static class PersistedConfigInitializerProvider extends PersistedFileInitializerProvider { + public String getPersistPath() { + return cfgAttributes.peristConfigPath; + } + + public LogicalDatastoreType getDataStoreType() { + return LogicalDatastoreType.CONFIGURATION; + } + + public String getRestorationType() { + return cfgAttributes.persistedConfigRestorationType; + } + + } +} diff --git a/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/netconf/HoneycombNotification2NetconfProvider.groovy b/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/netconf/HoneycombNotification2NetconfProvider.groovy deleted file mode 100644 index f3ced2e3f..000000000 --- a/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/netconf/HoneycombNotification2NetconfProvider.groovy +++ /dev/null @@ -1,88 +0,0 @@ -/* - * 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.netconf - -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.infra.distro.cfgattrs.HoneycombConfiguration -import io.fd.honeycomb.notification.NotificationCollector -import io.fd.honeycomb.notification.impl.NotificationProducerRegistry -import org.opendaylight.controller.md.sal.dom.broker.impl.DOMNotificationRouter -import org.opendaylight.controller.sal.core.api.model.SchemaService -import org.opendaylight.netconf.notifications.NetconfNotificationCollector -import io.fd.honeycomb.notification.impl.TranslationUtil -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.netconf.notification._1._0.rev080714.StreamNameType -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.netmod.notification.rev080714.netconf.streams.StreamBuilder -import org.opendaylight.yangtools.yang.model.api.SchemaPath - -@Slf4j -@ToString -class HoneycombNotification2NetconfProvider extends ProviderTrait { - - @Inject - DOMNotificationRouter notificationRouter - @Inject - SchemaService schemaService - @Inject - HoneycombConfiguration cfgAttributes - @Inject - NotificationCollector hcNotificationCollector - @Inject - NetconfNotificationCollector netconfNotificationCollector - - @Override - def create() { - def streamType = new StreamNameType(cfgAttributes.netconfNotificationStreamName.get()); - - // Register as HONEYCOMB_NETCONF notification publisher under configured name - def netconfNotifReg = netconfNotificationCollector.registerNotificationPublisher(new StreamBuilder() - .setName(streamType) - .setReplaySupport(false) - .setDescription(cfgAttributes.netconfNotificationStreamName.get()).build()); - - // Notification Translator, get notification from HC producers and put into HONEYCOMB_NETCONF notification collector - def domNotificationListener = { notif -> - log.debug "Propagating notification: {} into HONEYCOMB_NETCONF", notif.type - netconfNotifReg.onNotification(streamType, TranslationUtil.notificationToXml(notif, schemaService.globalContext)) - } - - // NotificationManager is used to provide list of available notifications (which are all of the notifications registered) - // TODO make available notifications configurable here so that any number of notification streams for HONEYCOMB_NETCONF - // can be configured on top of a single notification manager - log.debug "Current notifications to be exposed over HONEYCOMB_NETCONF: {}", hcNotificationCollector.notificationTypes - def currentNotificationSchemaPaths = hcNotificationCollector.notificationTypes - .collect {SchemaPath.create(true, NotificationProducerRegistry.getQName(it))} - - // Register as listener to HC'OPERATIONAL DOM notification service - // TODO This should only be triggered when HONEYCOMB_NETCONF notifications are activated - // Because this way we actually start all notification producers - // final Collection notificationQNames = - def domNotifListenerReg = notificationRouter - .registerNotificationListener(domNotificationListener, currentNotificationSchemaPaths); - - log.info "Exposing HONEYCOMB_NETCONF notification stream: {}", streamType.value - - new HoneycombNotification2Netconf(domNotifListenerReg: domNotifListenerReg, netconfNotifReg: netconfNotifReg) - } - - static class HoneycombNotification2Netconf { - def domNotifListenerReg - def netconfNotifReg - } -} diff --git a/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/netconf/HoneycombNotification2NetconfProvider.java b/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/netconf/HoneycombNotification2NetconfProvider.java new file mode 100644 index 000000000..3954af896 --- /dev/null +++ b/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/netconf/HoneycombNotification2NetconfProvider.java @@ -0,0 +1,130 @@ +/* + * 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.netconf; + +import com.google.inject.Inject; +import io.fd.honeycomb.infra.distro.ProviderTrait; +import io.fd.honeycomb.infra.distro.cfgattrs.HoneycombConfiguration; +import io.fd.honeycomb.notification.NotificationCollector; +import io.fd.honeycomb.notification.impl.NotificationProducerRegistry; +import io.fd.honeycomb.notification.impl.TranslationUtil; +import java.util.List; +import java.util.stream.Collectors; +import javax.annotation.Nonnull; +import org.opendaylight.controller.md.sal.dom.api.DOMNotification; +import org.opendaylight.controller.md.sal.dom.api.DOMNotificationListener; +import org.opendaylight.controller.md.sal.dom.broker.impl.DOMNotificationRouter; +import org.opendaylight.controller.sal.core.api.model.SchemaService; +import org.opendaylight.netconf.notifications.NetconfNotificationCollector; +import org.opendaylight.netconf.notifications.NotificationPublisherRegistration; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.netconf.notification._1._0.rev080714.StreamNameType; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.netmod.notification.rev080714.netconf.streams.StreamBuilder; +import org.opendaylight.yangtools.concepts.ListenerRegistration; +import org.opendaylight.yangtools.yang.model.api.SchemaPath; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public final class HoneycombNotification2NetconfProvider + extends ProviderTrait { + + private static final Logger LOG = LoggerFactory.getLogger(HoneycombNotification2NetconfProvider.class); + + @Inject + private DOMNotificationRouter notificationRouter; + @Inject + private SchemaService schemaService; + @Inject + private HoneycombConfiguration cfgAttributes; + @Inject + private NotificationCollector hcNotificationCollector; + @Inject + private NetconfNotificationCollector netconfNotificationCollector; + + @Override + protected HoneycombNotification2Netconf create() { + final StreamNameType streamType = new StreamNameType(cfgAttributes.netconfNotificationStreamName.get()); + + // Register as HONEYCOMB_NETCONF notification publisher under configured name + final NotificationPublisherRegistration netconfNotifReg = netconfNotificationCollector + .registerNotificationPublisher(new StreamBuilder().setName(streamType).setReplaySupport(false) + .setDescription(cfgAttributes.netconfNotificationStreamName.get()).build()); + + // Notification Translator, get notification from HC producers and put into HONEYCOMB_NETCONF notification collector + final DOMNotificationListener domNotificationListener = + new TranslatingNotificationListener(netconfNotifReg, streamType, schemaService); + + // NotificationManager is used to provide list of available notifications (which are all of the notifications registered) + // TODO make available notifications configurable here so that any number of notification streams for HONEYCOMB_NETCONF + // can be configured on top of a single notification manager + LOG.debug("Current notifications to be exposed over HONEYCOMB_NETCONF: {}", + hcNotificationCollector.getNotificationTypes()); + List currentNotificationSchemaPaths = hcNotificationCollector.getNotificationTypes().stream() + .map(notifType -> SchemaPath.create(true, NotificationProducerRegistry.getQName(notifType))) + .collect(Collectors.toList()); + + // Register as listener to HC'OPERATIONAL DOM notification service + // TODO This should only be triggered when HONEYCOMB_NETCONF notifications are activated + // Because this way we actually start all notification producers + // final Collection notificationQNames = + ListenerRegistration domNotifListenerReg = notificationRouter + .registerNotificationListener(domNotificationListener, currentNotificationSchemaPaths); + + LOG.info("Exposing HONEYCOMB_NETCONF notification stream: {}", streamType.getValue()); + return new HoneycombNotification2Netconf(domNotifListenerReg, netconfNotifReg); + } + + public static final class HoneycombNotification2Netconf { + private final ListenerRegistration domNotifListenerReg; + private final NotificationPublisherRegistration netconfNotifReg; + + public HoneycombNotification2Netconf(final ListenerRegistration domNotifListenerReg, + final NotificationPublisherRegistration netconfNotifReg) { + this.domNotifListenerReg = domNotifListenerReg; + this.netconfNotifReg = netconfNotifReg; + } + + public ListenerRegistration getDomNotifListenerReg() { + return domNotifListenerReg; + } + + public NotificationPublisherRegistration getNetconfNotifReg() { + return netconfNotifReg; + } + } + + private static final class TranslatingNotificationListener implements DOMNotificationListener { + + private static final Logger LOG = LoggerFactory.getLogger(TranslatingNotificationListener.class); + + private final NotificationPublisherRegistration netconfNotifReg; + private final StreamNameType streamType; + private final SchemaService schemaService; + + TranslatingNotificationListener(final NotificationPublisherRegistration netconfNotifReg, + final StreamNameType streamType, final SchemaService schemaService) { + this.netconfNotifReg = netconfNotifReg; + this.streamType = streamType; + this.schemaService = schemaService; + } + + @Override + public void onNotification(@Nonnull final DOMNotification notif) { + LOG.debug("Propagating notification: {} into HONEYCOMB_NETCONF", notif.getType()); + netconfNotifReg.onNotification(streamType, TranslationUtil.notificationToXml(notif, schemaService.getGlobalContext())); + } + } +} diff --git a/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/netconf/NetconfBindingBrokerProvider.groovy b/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/netconf/NetconfBindingBrokerProvider.groovy deleted file mode 100644 index f1f49700e..000000000 --- a/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/netconf/NetconfBindingBrokerProvider.groovy +++ /dev/null @@ -1,38 +0,0 @@ -/* - * 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.netconf - -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.binding.api.DataBroker -import org.opendaylight.controller.sal.binding.api.BindingAwareBroker -import io.fd.honeycomb.impl.FakeBindingAwareBroker - -@Slf4j -@ToString -class NetconfBindingBrokerProvider extends ProviderTrait { - - @Inject - @Named(NetconfModule.HONEYCOMB_NETCONF) - DataBroker dataBroker - - @Override - def create() { new FakeBindingAwareBroker(dataBroker) } -} diff --git a/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/netconf/NetconfBindingBrokerProvider.java b/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/netconf/NetconfBindingBrokerProvider.java new file mode 100644 index 000000000..3d06b8d27 --- /dev/null +++ b/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/netconf/NetconfBindingBrokerProvider.java @@ -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.netconf; + +import com.google.inject.Inject; +import com.google.inject.name.Named; +import io.fd.honeycomb.impl.FakeBindingAwareBroker; +import io.fd.honeycomb.infra.distro.ProviderTrait; +import org.opendaylight.controller.md.sal.binding.api.DataBroker; +import org.opendaylight.controller.sal.binding.api.BindingAwareBroker; + +public final class NetconfBindingBrokerProvider extends ProviderTrait { + + @Inject + @Named(NetconfModule.HONEYCOMB_NETCONF) + private DataBroker dataBroker; + + @Override + protected FakeBindingAwareBroker create() { + return new FakeBindingAwareBroker(dataBroker); + } +} diff --git a/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/netconf/NetconfMdsalMapperProvider.groovy b/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/netconf/NetconfMdsalMapperProvider.groovy deleted file mode 100644 index dff5319b4..000000000 --- a/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/netconf/NetconfMdsalMapperProvider.groovy +++ /dev/null @@ -1,51 +0,0 @@ -/* - * 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.netconf - -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.sal.core.api.Broker -import org.opendaylight.controller.sal.core.api.model.SchemaService -import org.opendaylight.netconf.mapping.api.NetconfOperationServiceFactory -import org.opendaylight.netconf.mapping.api.NetconfOperationServiceFactoryListener -import org.opendaylight.netconf.mdsal.connector.MdsalNetconfOperationServiceFactory -import org.opendaylight.yangtools.sal.binding.generator.impl.ModuleInfoBackedContext - -@Slf4j -@ToString -class NetconfMdsalMapperProvider extends ProviderTrait { - - @Inject - SchemaService schemaService - @Inject - NetconfOperationServiceFactoryListener aggregator - @Inject - ModuleInfoBackedContext moduleInfoBackedContext - - @Inject - Broker domBroker - - def create() { - def mdsalNetconfOperationServiceFactory = - new MdsalNetconfOperationServiceFactory(schemaService, moduleInfoBackedContext) - domBroker.registerConsumer(mdsalNetconfOperationServiceFactory); - aggregator.onAddNetconfOperationServiceFactory(mdsalNetconfOperationServiceFactory); - return mdsalNetconfOperationServiceFactory; - } -} diff --git a/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/netconf/NetconfMdsalMapperProvider.java b/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/netconf/NetconfMdsalMapperProvider.java new file mode 100644 index 000000000..9ede54f72 --- /dev/null +++ b/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/netconf/NetconfMdsalMapperProvider.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.netconf; + +import com.google.inject.Inject; +import io.fd.honeycomb.infra.distro.ProviderTrait; +import org.opendaylight.controller.sal.core.api.Broker; +import org.opendaylight.controller.sal.core.api.model.SchemaService; +import org.opendaylight.netconf.mapping.api.NetconfOperationServiceFactory; +import org.opendaylight.netconf.mapping.api.NetconfOperationServiceFactoryListener; +import org.opendaylight.netconf.mdsal.connector.MdsalNetconfOperationServiceFactory; +import org.opendaylight.yangtools.sal.binding.generator.impl.ModuleInfoBackedContext; + +public final class NetconfMdsalMapperProvider extends ProviderTrait { + + @Inject + private SchemaService schemaService; + @Inject + private NetconfOperationServiceFactoryListener aggregator; + @Inject + private ModuleInfoBackedContext moduleInfoBackedContext; + @Inject + private Broker domBroker; + + @Override + protected MdsalNetconfOperationServiceFactory create() { + MdsalNetconfOperationServiceFactory mdsalNetconfOperationServiceFactory = + new MdsalNetconfOperationServiceFactory(schemaService, moduleInfoBackedContext); + domBroker.registerConsumer(mdsalNetconfOperationServiceFactory); + aggregator.onAddNetconfOperationServiceFactory(mdsalNetconfOperationServiceFactory); + return mdsalNetconfOperationServiceFactory; + } +} diff --git a/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/netconf/NetconfModule.groovy b/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/netconf/NetconfModule.groovy deleted file mode 100644 index 29eeae301..000000000 --- a/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/netconf/NetconfModule.groovy +++ /dev/null @@ -1,141 +0,0 @@ -/* - * 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.netconf - -import com.google.inject.PrivateModule -import com.google.inject.Singleton -import com.google.inject.name.Names -import io.fd.honeycomb.infra.distro.data.BindingDataBrokerProvider -import io.fd.honeycomb.infra.distro.data.DataStoreProvider -import io.fd.honeycomb.infra.distro.data.HoneycombNotificationManagerProvider -import io.fd.honeycomb.infra.distro.data.InmemoryDOMDataBrokerProvider -import io.fd.honeycomb.notification.NotificationCollector -import io.netty.channel.nio.NioEventLoopGroup -import io.netty.util.Timer -import org.opendaylight.controller.md.sal.binding.api.DataBroker -import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType -import org.opendaylight.controller.md.sal.dom.api.DOMDataBroker -import org.opendaylight.controller.md.sal.dom.store.impl.InMemoryDOMDataStore -import org.opendaylight.controller.sal.binding.api.BindingAwareBroker -import org.opendaylight.netconf.api.NetconfServerDispatcher -import org.opendaylight.netconf.api.monitoring.NetconfMonitoringService -import org.opendaylight.netconf.impl.osgi.AggregatedNetconfOperationServiceFactory -import org.opendaylight.netconf.mapping.api.NetconfOperationServiceFactory -import org.opendaylight.netconf.mapping.api.NetconfOperationServiceFactoryListener -import org.opendaylight.netconf.notifications.NetconfNotificationCollector -import org.opendaylight.netconf.notifications.NetconfNotificationListener -import org.opendaylight.netconf.notifications.NetconfNotificationRegistry -import org.opendaylight.netconf.notifications.impl.NetconfNotificationManager - -import static InmemoryDOMDataBrokerProvider.CONFIG -import static InmemoryDOMDataBrokerProvider.OPERATIONAL - -class NetconfModule extends PrivateModule { - - - public static final String HONEYCOMB_NETCONF = "honeycomb-netconf" - public static final String HONEYCOMB_NETCONF_MAPPER_AGGR = "netconf-mapper-aggregator" - public static final String HONEYCOMB_NETCONF_MAPPER_NOTIF = "netconf-mapper-notification" - public static final String HONEYCOMB_NETCONF_MAPPER_CORE = "netconf-mapper-honeycomb" - public static final String HONEYCOMB_NETCONF_MAPPER_OPER = "netconf-mapper-monitoring" - - @Override - protected void configure() { - // Create inmemory data store for HONEYCOMB_NETCONF config metadata - bind(InMemoryDOMDataStore) - .annotatedWith(Names.named(CONFIG)) - .toProvider(new DataStoreProvider(type: LogicalDatastoreType.CONFIGURATION, name: CONFIG)) - .in(Singleton) - // Create inmemory data store for HONEYCOMB_NETCONF operational metadata - bind(InMemoryDOMDataStore) - .annotatedWith(Names.named(OPERATIONAL)) - .toProvider(new DataStoreProvider(type: LogicalDatastoreType.OPERATIONAL, name: OPERATIONAL)) - .in(Singleton) - // Wrap datastores as DOMDataBroker - bind(DOMDataBroker).toProvider(InmemoryDOMDataBrokerProvider).in(Singleton) - - // Wrap DOMDataBroker as BA data broker - bind(DataBroker) - .annotatedWith(Names.named(HONEYCOMB_NETCONF)) - .toProvider(BindingDataBrokerProvider) - .in(Singleton) - expose(DataBroker).annotatedWith(Names.named(HONEYCOMB_NETCONF)) - - // Wrap BA data broker as BindingAwareBroker (requied by HONEYCOMB_NETCONF) - bind(BindingAwareBroker) - .annotatedWith(Names.named(HONEYCOMB_NETCONF)) - .toProvider(NetconfBindingBrokerProvider) - .in(Singleton) - - // Create netconf operation service factory aggregator to aggregate different services - def factory = new AggregatedNetconfOperationServiceFactory() - bind(NetconfOperationServiceFactory) - .annotatedWith(Names.named(HONEYCOMB_NETCONF_MAPPER_AGGR)) - .toInstance(factory) - bind(NetconfOperationServiceFactoryListener).toInstance(factory) - - // Create netconf notification manager - def manager = new NetconfNotificationManager() - bind(NetconfNotificationCollector).toInstance(manager) - bind(NetconfNotificationRegistry).toInstance(manager) - bind(NetconfNotificationListener).toInstance(manager) - - // Netconf notification service factory - bind(NetconfOperationServiceFactory) - .annotatedWith(Names.named(HONEYCOMB_NETCONF_MAPPER_NOTIF)) - .toProvider(NetconfNotificationMapperProvider) - .in(Singleton) - expose(NetconfOperationServiceFactory).annotatedWith(Names.named(HONEYCOMB_NETCONF_MAPPER_NOTIF)) - - // Netconf core part - mapping between Honeycomb and Netconf - bind(NetconfOperationServiceFactory) - .annotatedWith(Names.named(HONEYCOMB_NETCONF_MAPPER_CORE)) - .toProvider(NetconfMdsalMapperProvider) - .in(Singleton) - expose(NetconfOperationServiceFactory).annotatedWith(Names.named(HONEYCOMB_NETCONF_MAPPER_CORE)) - - // Netconf monitoring service factory - bind(NetconfMonitoringService).toProvider(NetconfMonitoringServiceProvider).in(Singleton) - bind(NetconfOperationServiceFactory) - .annotatedWith(Names.named(HONEYCOMB_NETCONF_MAPPER_OPER)) - .toProvider(NetconfMonitoringMapperProvider) - .in(Singleton) - expose(NetconfOperationServiceFactory).annotatedWith(Names.named(HONEYCOMB_NETCONF_MAPPER_OPER)) - - // Create HC notification manager + HC2Netconf translator - bind(NotificationCollector).toProvider(HoneycombNotificationManagerProvider).in(Singleton) - bind(HoneycombNotification2NetconfProvider.HoneycombNotification2Netconf) - .toProvider(HoneycombNotification2NetconfProvider) - .in(Singleton) - expose(HoneycombNotification2NetconfProvider.HoneycombNotification2Netconf) - - configureServer() - } - - /** - * Provide HONEYCOMB_NETCONF TCP and SSH servers - */ - def configureServer() { - bind(NioEventLoopGroup).toProvider(NettyThreadGroupProvider).in(Singleton) - bind(Timer).toProvider(NettyTimerProvider).in(Singleton) - bind(NetconfServerDispatcher).toProvider(NetconfServerDispatcherProvider).in(Singleton) - bind(NetconfTcpServerProvider.NetconfTcpServer).toProvider(NetconfTcpServerProvider).in(Singleton) - expose(NetconfTcpServerProvider.NetconfTcpServer) - bind(NetconfSshServerProvider.NetconfSshServer).toProvider(NetconfSshServerProvider).in(Singleton) - expose(NetconfSshServerProvider.NetconfSshServer) - } -} diff --git a/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/netconf/NetconfModule.java b/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/netconf/NetconfModule.java new file mode 100644 index 000000000..9beb10dbc --- /dev/null +++ b/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/netconf/NetconfModule.java @@ -0,0 +1,130 @@ +/* + * 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.netconf; + +import static io.fd.honeycomb.infra.distro.data.InmemoryDOMDataBrokerProvider.CONFIG; +import static io.fd.honeycomb.infra.distro.data.InmemoryDOMDataBrokerProvider.OPERATIONAL; + +import com.google.inject.PrivateModule; +import com.google.inject.Singleton; +import com.google.inject.binder.AnnotatedElementBuilder; +import com.google.inject.name.Names; +import io.fd.honeycomb.infra.distro.data.BindingDataBrokerProvider; +import io.fd.honeycomb.infra.distro.data.DataStoreProvider; +import io.fd.honeycomb.infra.distro.data.HoneycombNotificationManagerProvider; +import io.fd.honeycomb.infra.distro.data.InmemoryDOMDataBrokerProvider; +import io.fd.honeycomb.notification.NotificationCollector; +import io.netty.channel.nio.NioEventLoopGroup; +import io.netty.util.Timer; +import org.opendaylight.controller.md.sal.binding.api.DataBroker; +import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType; +import org.opendaylight.controller.md.sal.dom.api.DOMDataBroker; +import org.opendaylight.controller.md.sal.dom.store.impl.InMemoryDOMDataStore; +import org.opendaylight.controller.sal.binding.api.BindingAwareBroker; +import org.opendaylight.netconf.api.NetconfServerDispatcher; +import org.opendaylight.netconf.api.monitoring.NetconfMonitoringService; +import org.opendaylight.netconf.impl.osgi.AggregatedNetconfOperationServiceFactory; +import org.opendaylight.netconf.mapping.api.NetconfOperationServiceFactory; +import org.opendaylight.netconf.mapping.api.NetconfOperationServiceFactoryListener; +import org.opendaylight.netconf.notifications.NetconfNotificationCollector; +import org.opendaylight.netconf.notifications.NetconfNotificationListener; +import org.opendaylight.netconf.notifications.NetconfNotificationRegistry; +import org.opendaylight.netconf.notifications.impl.NetconfNotificationManager; + +public class NetconfModule extends PrivateModule { + + public static final String HONEYCOMB_NETCONF = "honeycomb-netconf"; + public static final String HONEYCOMB_NETCONF_MAPPER_AGGR = "netconf-mapper-aggregator"; + public static final String HONEYCOMB_NETCONF_MAPPER_NOTIF = "netconf-mapper-notification"; + public static final String HONEYCOMB_NETCONF_MAPPER_CORE = "netconf-mapper-honeycomb"; + public static final String HONEYCOMB_NETCONF_MAPPER_OPER = "netconf-mapper-monitoring"; + + @Override + protected void configure() { + // Create inmemory data store for HONEYCOMB_NETCONF config metadata + bind(InMemoryDOMDataStore.class).annotatedWith(Names.named(CONFIG)) + .toProvider(new DataStoreProvider(CONFIG, LogicalDatastoreType.CONFIGURATION)) + .in(Singleton.class); + + // Create inmemory data store for HONEYCOMB_NETCONF operational metadata + bind(InMemoryDOMDataStore.class).annotatedWith(Names.named(OPERATIONAL)) + .toProvider(new DataStoreProvider(OPERATIONAL, LogicalDatastoreType.OPERATIONAL)) + .in(Singleton.class); + // Wrap datastores as DOMDataBroker + bind(DOMDataBroker.class).toProvider(InmemoryDOMDataBrokerProvider.class).in(Singleton.class); + + // Wrap DOMDataBroker as BA data broker + bind(DataBroker.class).annotatedWith(Names.named(HONEYCOMB_NETCONF)).toProvider(BindingDataBrokerProvider.class) + .in(Singleton.class); + expose(DataBroker.class).annotatedWith(Names.named(HONEYCOMB_NETCONF)); + + // Wrap BA data broker as BindingAwareBroker (requied by HONEYCOMB_NETCONF) + bind(BindingAwareBroker.class).annotatedWith(Names.named(HONEYCOMB_NETCONF)) + .toProvider(NetconfBindingBrokerProvider.class).in(Singleton.class); + + // Create netconf operation service factory aggregator to aggregate different services + AggregatedNetconfOperationServiceFactory factory = new AggregatedNetconfOperationServiceFactory(); + bind(NetconfOperationServiceFactory.class).annotatedWith(Names.named(HONEYCOMB_NETCONF_MAPPER_AGGR)) + .toInstance(factory); + bind(NetconfOperationServiceFactoryListener.class).toInstance(factory); + + // Create netconf notification manager + NetconfNotificationManager manager = new NetconfNotificationManager(); + bind(NetconfNotificationCollector.class).toInstance(manager); + bind(NetconfNotificationRegistry.class).toInstance(manager); + bind(NetconfNotificationListener.class).toInstance(manager); + + // Netconf notification service factory + bind(NetconfOperationServiceFactory.class).annotatedWith(Names.named(HONEYCOMB_NETCONF_MAPPER_NOTIF)) + .toProvider(NetconfNotificationMapperProvider.class).in(Singleton.class); + expose(NetconfOperationServiceFactory.class).annotatedWith(Names.named(HONEYCOMB_NETCONF_MAPPER_NOTIF)); + + // Netconf core part - mapping between Honeycomb and Netconf + bind(NetconfOperationServiceFactory.class).annotatedWith(Names.named(HONEYCOMB_NETCONF_MAPPER_CORE)) + .toProvider(NetconfMdsalMapperProvider.class).in(Singleton.class); + expose(NetconfOperationServiceFactory.class).annotatedWith(Names.named(HONEYCOMB_NETCONF_MAPPER_CORE)); + + // Netconf monitoring service factory + bind(NetconfMonitoringService.class).toProvider(NetconfMonitoringServiceProvider.class).in(Singleton.class); + bind(NetconfOperationServiceFactory.class).annotatedWith(Names.named(HONEYCOMB_NETCONF_MAPPER_OPER)) + .toProvider(NetconfMonitoringMapperProvider.class).in(Singleton.class); + expose(NetconfOperationServiceFactory.class).annotatedWith(Names.named(HONEYCOMB_NETCONF_MAPPER_OPER)); + + // Create HC notification manager + HC2Netconf translator + bind(NotificationCollector.class).toProvider(HoneycombNotificationManagerProvider.class).in(Singleton.class); + bind(HoneycombNotification2NetconfProvider.HoneycombNotification2Netconf.class) + .toProvider(HoneycombNotification2NetconfProvider.class).in(Singleton.class); + expose(HoneycombNotification2NetconfProvider.HoneycombNotification2Netconf.class); + + configureServer(); + } + + /** + * Provide HONEYCOMB_NETCONF TCP and SSH servers. + */ + private AnnotatedElementBuilder configureServer() { + bind(NioEventLoopGroup.class).toProvider(NettyThreadGroupProvider.class).in(Singleton.class); + bind(Timer.class).toProvider(NettyTimerProvider.class).in(Singleton.class); + bind(NetconfServerDispatcher.class).toProvider(NetconfServerDispatcherProvider.class).in(Singleton.class); + bind(NetconfTcpServerProvider.NetconfTcpServer.class).toProvider(NetconfTcpServerProvider.class) + .in(Singleton.class); + expose(NetconfTcpServerProvider.NetconfTcpServer.class); + bind(NetconfSshServerProvider.NetconfSshServer.class).toProvider(NetconfSshServerProvider.class) + .in(Singleton.class); + return expose(NetconfSshServerProvider.NetconfSshServer.class); + } +} diff --git a/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/netconf/NetconfMonitoringMapperProvider.groovy b/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/netconf/NetconfMonitoringMapperProvider.groovy deleted file mode 100644 index c35a97352..000000000 --- a/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/netconf/NetconfMonitoringMapperProvider.groovy +++ /dev/null @@ -1,53 +0,0 @@ -/* - * 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.netconf - -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.config.yang.netconf.mdsal.monitoring.MonitoringToMdsalWriter -import org.opendaylight.controller.config.yang.netconf.mdsal.monitoring.NetconfMdsalMonitoringMapperModule -import org.opendaylight.controller.sal.binding.api.BindingAwareBroker -import org.opendaylight.netconf.api.monitoring.NetconfMonitoringService -import org.opendaylight.netconf.mapping.api.NetconfOperationServiceFactory -import org.opendaylight.netconf.mapping.api.NetconfOperationServiceFactoryListener - -@Slf4j -@ToString -class NetconfMonitoringMapperProvider extends ProviderTrait { - - @Inject - @Named(NetconfModule.HONEYCOMB_NETCONF) - BindingAwareBroker bindingAwareBroker - @Inject - NetconfOperationServiceFactoryListener aggregator - @Inject - NetconfMonitoringService monitoringService - - def create() { - def monitoringToMdsalWriter = new MonitoringToMdsalWriter(monitoringService) - bindingAwareBroker.registerProvider(monitoringToMdsalWriter) - - def mdSalMonitoringMapperFactory = new NetconfMdsalMonitoringMapperModule.MdSalMonitoringMapperFactory( - new NetconfMdsalMonitoringMapperModule.MdsalMonitoringMapper(monitoringService)) - - aggregator.onAddNetconfOperationServiceFactory(mdSalMonitoringMapperFactory) - return mdSalMonitoringMapperFactory - } -} diff --git a/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/netconf/NetconfMonitoringMapperProvider.java b/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/netconf/NetconfMonitoringMapperProvider.java new file mode 100644 index 000000000..46a46ba47 --- /dev/null +++ b/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/netconf/NetconfMonitoringMapperProvider.java @@ -0,0 +1,79 @@ +/* + * 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.netconf; + +import com.google.inject.Inject; +import com.google.inject.name.Named; +import io.fd.honeycomb.infra.distro.ProviderTrait; +import java.lang.reflect.Constructor; +import org.opendaylight.controller.sal.binding.api.BindingAwareBroker; +import org.opendaylight.controller.sal.binding.api.BindingAwareProvider; +import org.opendaylight.netconf.api.monitoring.NetconfMonitoringService; +import org.opendaylight.netconf.mapping.api.NetconfOperationService; +import org.opendaylight.netconf.mapping.api.NetconfOperationServiceFactory; +import org.opendaylight.netconf.mapping.api.NetconfOperationServiceFactoryListener; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + + +public final class NetconfMonitoringMapperProvider extends ProviderTrait { + + private static final Logger LOG = LoggerFactory.getLogger(NetconfMonitoringMapperProvider.class); + + @Inject + @Named(NetconfModule.HONEYCOMB_NETCONF) + private BindingAwareBroker bindingAwareBroker; + @Inject + private NetconfOperationServiceFactoryListener aggregator; + @Inject + private NetconfMonitoringService monitoringService; + + @Override + protected NetconfOperationServiceFactory create() { + try { + final Class monitoringWriterCls = Class.forName( + "org.opendaylight.controller.config.yang.netconf.mdsal.monitoring.MonitoringToMdsalWriter"); + Constructor declaredConstructor = + monitoringWriterCls.getDeclaredConstructor(NetconfMonitoringService.class); + declaredConstructor.setAccessible(true); + final BindingAwareProvider o = (BindingAwareProvider) declaredConstructor.newInstance(monitoringService); + bindingAwareBroker.registerProvider(o); + + final Class monitoringMapperCls = Class.forName( + "org.opendaylight.controller.config.yang.netconf.mdsal.monitoring.NetconfMdsalMonitoringMapperModule$MdsalMonitoringMapper"); + declaredConstructor = + monitoringMapperCls.getDeclaredConstructor(NetconfMonitoringService.class); + declaredConstructor.setAccessible(true); + final NetconfOperationService mdSalMonitoringMapper = + (NetconfOperationService) declaredConstructor.newInstance(monitoringService); + + final Class monitoringMpperFactory = Class.forName( + "org.opendaylight.controller.config.yang.netconf.mdsal.monitoring.NetconfMdsalMonitoringMapperModule$MdSalMonitoringMapperFactory"); + declaredConstructor = + monitoringMpperFactory.getDeclaredConstructor(NetconfOperationService.class); + declaredConstructor.setAccessible(true); + final NetconfOperationServiceFactory mdSalMonitoringMapperFactory = + (NetconfOperationServiceFactory) declaredConstructor.newInstance(mdSalMonitoringMapper); + aggregator.onAddNetconfOperationServiceFactory(mdSalMonitoringMapperFactory); + return mdSalMonitoringMapperFactory; + } catch (final ReflectiveOperationException e) { + final String msg = "Unable to instantiate operation service factory using reflection"; + LOG.error(msg, e); + throw new IllegalStateException(msg, e); + } + } +} diff --git a/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/netconf/NetconfMonitoringReaderFactoryProvider.groovy b/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/netconf/NetconfMonitoringReaderFactoryProvider.groovy deleted file mode 100644 index 54a773a80..000000000 --- a/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/netconf/NetconfMonitoringReaderFactoryProvider.groovy +++ /dev/null @@ -1,37 +0,0 @@ -/* - * 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.netconf - -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.translate.read.ReaderFactory -import org.opendaylight.controller.md.sal.binding.api.DataBroker -import io.fd.honeycomb.impl.NetconfMonitoringReaderFactory - -@Slf4j -@ToString -class NetconfMonitoringReaderFactoryProvider extends ProviderTrait { - - @Inject - @Named(NetconfModule.HONEYCOMB_NETCONF) - DataBroker netconfDataBroker - - def create() { new NetconfMonitoringReaderFactory(netconfDataBroker) } -} diff --git a/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/netconf/NetconfMonitoringReaderFactoryProvider.java b/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/netconf/NetconfMonitoringReaderFactoryProvider.java new file mode 100644 index 000000000..583b15055 --- /dev/null +++ b/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/netconf/NetconfMonitoringReaderFactoryProvider.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.netconf; + +import com.google.inject.Inject; +import com.google.inject.name.Named; +import io.fd.honeycomb.impl.NetconfMonitoringReaderFactory; +import io.fd.honeycomb.infra.distro.ProviderTrait; +import io.fd.honeycomb.translate.read.ReaderFactory; +import org.opendaylight.controller.md.sal.binding.api.DataBroker; + + +public final class NetconfMonitoringReaderFactoryProvider extends ProviderTrait { + + @Inject + @Named(NetconfModule.HONEYCOMB_NETCONF) + private DataBroker netconfDataBroker; + + @Override + protected NetconfMonitoringReaderFactory create() { + return new NetconfMonitoringReaderFactory(netconfDataBroker); + } +} diff --git a/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/netconf/NetconfMonitoringServiceProvider.groovy b/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/netconf/NetconfMonitoringServiceProvider.groovy deleted file mode 100644 index cac2a13cc..000000000 --- a/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/netconf/NetconfMonitoringServiceProvider.groovy +++ /dev/null @@ -1,40 +0,0 @@ -/* - * 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.netconf - -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.netconf.api.monitoring.NetconfMonitoringService -import org.opendaylight.netconf.impl.osgi.NetconfMonitoringServiceImpl -import org.opendaylight.netconf.mapping.api.NetconfOperationServiceFactory - -@Slf4j -@ToString -class NetconfMonitoringServiceProvider extends ProviderTrait { - - @Inject - @Named(NetconfModule.HONEYCOMB_NETCONF_MAPPER_AGGR) - NetconfOperationServiceFactory aggregator - - @Override - def create() { - new NetconfMonitoringServiceImpl(aggregator) - } -} diff --git a/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/netconf/NetconfMonitoringServiceProvider.java b/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/netconf/NetconfMonitoringServiceProvider.java new file mode 100644 index 000000000..9858003f5 --- /dev/null +++ b/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/netconf/NetconfMonitoringServiceProvider.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.netconf; + +import com.google.inject.Inject; +import com.google.inject.name.Named; +import io.fd.honeycomb.infra.distro.ProviderTrait; +import org.opendaylight.netconf.api.monitoring.NetconfMonitoringService; +import org.opendaylight.netconf.impl.osgi.NetconfMonitoringServiceImpl; +import org.opendaylight.netconf.mapping.api.NetconfOperationServiceFactory; + + +public class NetconfMonitoringServiceProvider extends ProviderTrait { + + @Inject + @Named(NetconfModule.HONEYCOMB_NETCONF_MAPPER_AGGR) + private NetconfOperationServiceFactory aggregator; + + @Override + protected NetconfMonitoringServiceImpl create() { + return new NetconfMonitoringServiceImpl(aggregator); + } +} diff --git a/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/netconf/NetconfNotificationMapperProvider.groovy b/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/netconf/NetconfNotificationMapperProvider.groovy deleted file mode 100644 index 74b384317..000000000 --- a/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/netconf/NetconfNotificationMapperProvider.groovy +++ /dev/null @@ -1,70 +0,0 @@ -/* - * 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.netconf - -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.config.yang.netconf.mdsal.notification.BaseCapabilityChangeNotificationPublisher -import org.opendaylight.controller.config.yang.netconf.mdsal.notification.NotificationToMdsalWriter -import org.opendaylight.controller.md.sal.binding.api.DataBroker -import org.opendaylight.controller.md.sal.common.api.data.AsyncDataBroker -import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType -import org.opendaylight.controller.sal.binding.api.BindingAwareBroker -import org.opendaylight.netconf.mapping.api.NetconfOperationServiceFactory -import org.opendaylight.netconf.mapping.api.NetconfOperationServiceFactoryListener -import org.opendaylight.netconf.mdsal.notification.NetconfNotificationOperationServiceFactory -import org.opendaylight.netconf.notifications.NetconfNotificationCollector -import org.opendaylight.netconf.notifications.NetconfNotificationRegistry -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.monitoring.rev101004.NetconfState -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.monitoring.rev101004.netconf.state.Capabilities -import org.opendaylight.yangtools.yang.binding.InstanceIdentifier - -@Slf4j -@ToString -class NetconfNotificationMapperProvider extends ProviderTrait { - - public static final capabilitiesIdentifier = - InstanceIdentifier.create(NetconfState.class).child(Capabilities.class).builder().build() - - @Inject - NetconfNotificationCollector notificationCollector - @Inject - NetconfNotificationRegistry notificationRegistry - @Inject - @Named(NetconfModule.HONEYCOMB_NETCONF) - BindingAwareBroker bindingAwareBroker - @Inject - @Named(NetconfModule.HONEYCOMB_NETCONF) - DataBroker dataBroker - @Inject - NetconfOperationServiceFactoryListener aggregator - - def create() { - def notificationToMdsalWriter = new NotificationToMdsalWriter(notificationCollector) - bindingAwareBroker.registerProvider(notificationToMdsalWriter) - - def capabilityChangeListenerRegistration = dataBroker.registerDataChangeListener(LogicalDatastoreType.OPERATIONAL, capabilitiesIdentifier, - new BaseCapabilityChangeNotificationPublisher(notificationCollector.registerBaseNotificationPublisher()), AsyncDataBroker.DataChangeScope.SUBTREE) - - def netconfNotificationOperationServiceFactory = new NetconfNotificationOperationServiceFactory(notificationRegistry) - aggregator.onAddNetconfOperationServiceFactory(netconfNotificationOperationServiceFactory) - netconfNotificationOperationServiceFactory - } -} diff --git a/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/netconf/NetconfNotificationMapperProvider.java b/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/netconf/NetconfNotificationMapperProvider.java new file mode 100644 index 000000000..2c2631b0b --- /dev/null +++ b/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/netconf/NetconfNotificationMapperProvider.java @@ -0,0 +1,96 @@ +/* + * 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.netconf; + +import com.google.inject.Inject; +import com.google.inject.name.Named; +import io.fd.honeycomb.infra.distro.ProviderTrait; +import java.lang.reflect.Constructor; +import org.opendaylight.controller.md.sal.binding.api.DataBroker; +import org.opendaylight.controller.md.sal.binding.api.DataChangeListener; +import org.opendaylight.controller.md.sal.common.api.data.AsyncDataBroker; +import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType; +import org.opendaylight.controller.sal.binding.api.BindingAwareBroker; +import org.opendaylight.controller.sal.binding.api.BindingAwareProvider; +import org.opendaylight.netconf.mapping.api.NetconfOperationServiceFactory; +import org.opendaylight.netconf.mapping.api.NetconfOperationServiceFactoryListener; +import org.opendaylight.netconf.mdsal.notification.NetconfNotificationOperationServiceFactory; +import org.opendaylight.netconf.notifications.BaseNotificationPublisherRegistration; +import org.opendaylight.netconf.notifications.NetconfNotificationCollector; +import org.opendaylight.netconf.notifications.NetconfNotificationRegistry; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.monitoring.rev101004.NetconfState; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.monitoring.rev101004.netconf.state.Capabilities; +import org.opendaylight.yangtools.concepts.ListenerRegistration; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + + +public class NetconfNotificationMapperProvider extends ProviderTrait { + + private static final Logger LOG = LoggerFactory.getLogger(NetconfNotificationMapperProvider.class); + + public static final InstanceIdentifier capabilitiesIdentifier = + InstanceIdentifier.create(NetconfState.class).child(Capabilities.class).builder().build(); + @Inject + private NetconfNotificationCollector notificationCollector; + @Inject + private NetconfNotificationRegistry notificationRegistry; + @Inject + @Named(NetconfModule.HONEYCOMB_NETCONF) + private BindingAwareBroker bindingAwareBroker; + @Inject + @Named(NetconfModule.HONEYCOMB_NETCONF) + private DataBroker dataBroker; + @Inject + private NetconfOperationServiceFactoryListener aggregator; + + @Override + protected NetconfNotificationOperationServiceFactory create() { + try { + final Class notificationWriter = Class.forName( + "org.opendaylight.controller.config.yang.netconf.mdsal.notification.NotificationToMdsalWriter"); + Constructor declaredConstructor = + notificationWriter.getDeclaredConstructor(NetconfNotificationCollector.class); + declaredConstructor.setAccessible(true); + final BindingAwareProvider writer = + (BindingAwareProvider) declaredConstructor.newInstance(notificationCollector); + bindingAwareBroker.registerProvider(writer); + + final Class notifPublisherCls = Class.forName( + "org.opendaylight.controller.config.yang.netconf.mdsal.notification.BaseCapabilityChangeNotificationPublisher"); + declaredConstructor = + notifPublisherCls.getDeclaredConstructor(BaseNotificationPublisherRegistration.class); + declaredConstructor.setAccessible(true); + final DataChangeListener publisher = (DataChangeListener) declaredConstructor.newInstance( + notificationCollector.registerBaseNotificationPublisher()); + + ListenerRegistration capabilityChangeListenerRegistration = dataBroker + .registerDataChangeListener(LogicalDatastoreType.OPERATIONAL, capabilitiesIdentifier, + publisher, AsyncDataBroker.DataChangeScope.SUBTREE); + NetconfNotificationOperationServiceFactory netconfNotificationOperationServiceFactory = + new NetconfNotificationOperationServiceFactory(notificationRegistry); + aggregator.onAddNetconfOperationServiceFactory(netconfNotificationOperationServiceFactory); + + return netconfNotificationOperationServiceFactory; + } catch (final ReflectiveOperationException e) { + final String msg = "Unable to instantiate notification mapper using reflection"; + LOG.error(msg, e); + throw new IllegalStateException(msg, e); + } + } +} diff --git a/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/netconf/NetconfNotificationsReaderFactoryProvider.groovy b/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/netconf/NetconfNotificationsReaderFactoryProvider.groovy deleted file mode 100644 index c714cdd14..000000000 --- a/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/netconf/NetconfNotificationsReaderFactoryProvider.groovy +++ /dev/null @@ -1,52 +0,0 @@ -/* - * 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.netconf - -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.translate.read.ReaderFactory -import io.fd.honeycomb.translate.read.registry.ModifiableReaderRegistryBuilder -import io.fd.honeycomb.translate.util.read.BindingBrokerReader -import org.opendaylight.controller.md.sal.binding.api.DataBroker -import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.netmod.notification.rev080714.Netconf -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.netmod.notification.rev080714.NetconfBuilder -import org.opendaylight.yangtools.yang.binding.InstanceIdentifier - -import javax.annotation.Nonnull - -@Slf4j -@ToString -class NetconfNotificationsReaderFactoryProvider extends ProviderTrait { - - @Inject - @Named(NetconfModule.HONEYCOMB_NETCONF) - DataBroker netconfDataBroker - - def create() { - new ReaderFactory() { - @Override - void init(@Nonnull final ModifiableReaderRegistryBuilder registry) { - registry.add(new BindingBrokerReader<>(InstanceIdentifier.create(Netconf.class), - netconfDataBroker, LogicalDatastoreType.OPERATIONAL, NetconfBuilder.class)); - } - } - } -} diff --git a/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/netconf/NetconfNotificationsReaderFactoryProvider.java b/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/netconf/NetconfNotificationsReaderFactoryProvider.java new file mode 100644 index 000000000..b699439b4 --- /dev/null +++ b/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/netconf/NetconfNotificationsReaderFactoryProvider.java @@ -0,0 +1,57 @@ +/* + * 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.netconf; + +import com.google.inject.Inject; +import com.google.inject.name.Named; +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.BindingBrokerReader; +import javax.annotation.Nonnull; +import org.opendaylight.controller.md.sal.binding.api.DataBroker; +import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.netmod.notification.rev080714.Netconf; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.netmod.notification.rev080714.NetconfBuilder; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; + +public final class NetconfNotificationsReaderFactoryProvider extends ProviderTrait { + + @Inject + @Named(NetconfModule.HONEYCOMB_NETCONF) + private DataBroker netconfDataBroker; + + @Override + protected ReaderFactory create() { + return new NotificationReaderFactory(netconfDataBroker); + } + + private static final class NotificationReaderFactory implements ReaderFactory { + private final DataBroker netconfDataBroker; + + NotificationReaderFactory(final DataBroker netconfDataBroker) { + this.netconfDataBroker = netconfDataBroker; + } + + @Override + public void init(@Nonnull final ModifiableReaderRegistryBuilder registry) { + registry.add(new BindingBrokerReader<>(InstanceIdentifier.create(Netconf.class), netconfDataBroker, + LogicalDatastoreType.OPERATIONAL, NetconfBuilder.class)); + } + + } +} diff --git a/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/netconf/NetconfReadersModule.groovy b/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/netconf/NetconfReadersModule.groovy deleted file mode 100644 index 917eceeac..000000000 --- a/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/netconf/NetconfReadersModule.groovy +++ /dev/null @@ -1,37 +0,0 @@ -/* - * 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.netconf - -import com.google.inject.AbstractModule -import com.google.inject.Singleton -import com.google.inject.multibindings.Multibinder -import groovy.util.logging.Slf4j -import io.fd.honeycomb.translate.read.ReaderFactory - -@Slf4j -class NetconfReadersModule extends AbstractModule { - - protected void configure() { - // This should be part of NetconfModule, but that one is Private and Multibinders + private BASE_MODULES - // do not work together, that's why there's a dedicated module here - // https://github.com/google/guice/issues/906 - Multibinder.newSetBinder(binder(), ReaderFactory.class).with { - addBinding().toProvider(NetconfMonitoringReaderFactoryProvider).in(Singleton) - addBinding().toProvider(NetconfNotificationsReaderFactoryProvider).in(Singleton) - } - } -} diff --git a/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/netconf/NetconfReadersModule.java b/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/netconf/NetconfReadersModule.java new file mode 100644 index 000000000..cb45f5d6d --- /dev/null +++ b/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/netconf/NetconfReadersModule.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.netconf; + +import com.google.inject.AbstractModule; +import com.google.inject.Singleton; +import com.google.inject.multibindings.Multibinder; +import io.fd.honeycomb.translate.read.ReaderFactory; + +public class NetconfReadersModule extends AbstractModule { + + protected void configure() { + // This should be part of NetconfModule, but that one is Private and Multibinders + private BASE_MODULES + // do not work together, that's why there's a dedicated module here + // https://github.com/google/guice/issues/906 + final Multibinder binder = Multibinder.newSetBinder(binder(), ReaderFactory.class); + binder.addBinding().toProvider(NetconfMonitoringReaderFactoryProvider.class).in(Singleton.class); + binder.addBinding().toProvider(NetconfNotificationsReaderFactoryProvider.class).in(Singleton.class); + } +} diff --git a/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/netconf/NetconfServerDispatcherProvider.groovy b/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/netconf/NetconfServerDispatcherProvider.groovy deleted file mode 100644 index 10388f9c4..000000000 --- a/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/netconf/NetconfServerDispatcherProvider.groovy +++ /dev/null @@ -1,66 +0,0 @@ -/* - * 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.netconf - -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.netty.channel.nio.NioEventLoopGroup -import io.netty.util.Timer -import org.opendaylight.netconf.api.NetconfServerDispatcher -import org.opendaylight.netconf.api.monitoring.NetconfMonitoringService -import org.opendaylight.netconf.impl.NetconfServerDispatcherImpl -import org.opendaylight.netconf.impl.NetconfServerSessionNegotiatorFactory -import org.opendaylight.netconf.impl.SessionIdProvider -import org.opendaylight.netconf.impl.osgi.AggregatedNetconfOperationServiceFactory -import org.opendaylight.netconf.mapping.api.NetconfOperationServiceFactory - -import java.util.concurrent.TimeUnit - -@Slf4j -@ToString -class NetconfServerDispatcherProvider extends ProviderTrait { - - // TODO make configurable - private static final long CONNECTION_TIMEOUT_MILLIS = TimeUnit.SECONDS.toMillis(20) - - @Inject - @Named(NetconfModule.HONEYCOMB_NETCONF_MAPPER_AGGR) - NetconfOperationServiceFactory aggregator - @Inject - NetconfMonitoringService monitoringService - @Inject - Timer timer - @Inject - NioEventLoopGroup nettyThreadgroup - - - def create() { - def netconfOperationProvider = new AggregatedNetconfOperationServiceFactory() - netconfOperationProvider.onAddNetconfOperationServiceFactory(aggregator) - - def serverNegotiatorFactory = new NetconfServerSessionNegotiatorFactory( - timer, netconfOperationProvider, new SessionIdProvider(), CONNECTION_TIMEOUT_MILLIS, monitoringService); - def serverChannelInitializer = new NetconfServerDispatcherImpl.ServerChannelInitializer( - serverNegotiatorFactory); - - new NetconfServerDispatcherImpl(serverChannelInitializer, nettyThreadgroup, nettyThreadgroup) - } - -} diff --git a/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/netconf/NetconfServerDispatcherProvider.java b/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/netconf/NetconfServerDispatcherProvider.java new file mode 100644 index 000000000..1f3caafa1 --- /dev/null +++ b/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/netconf/NetconfServerDispatcherProvider.java @@ -0,0 +1,60 @@ +/* + * 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.netconf; + +import com.google.inject.Inject; +import com.google.inject.name.Named; +import io.fd.honeycomb.infra.distro.ProviderTrait; +import io.netty.channel.nio.NioEventLoopGroup; +import io.netty.util.Timer; +import java.util.concurrent.TimeUnit; +import org.opendaylight.netconf.api.NetconfServerDispatcher; +import org.opendaylight.netconf.api.monitoring.NetconfMonitoringService; +import org.opendaylight.netconf.impl.NetconfServerDispatcherImpl; +import org.opendaylight.netconf.impl.NetconfServerSessionNegotiatorFactory; +import org.opendaylight.netconf.impl.SessionIdProvider; +import org.opendaylight.netconf.impl.osgi.AggregatedNetconfOperationServiceFactory; +import org.opendaylight.netconf.mapping.api.NetconfOperationServiceFactory; + +public final class NetconfServerDispatcherProvider extends ProviderTrait { + private static final long CONNECTION_TIMEOUT_MILLIS = TimeUnit.SECONDS.toMillis(20); + + @Inject + @Named(NetconfModule.HONEYCOMB_NETCONF_MAPPER_AGGR) + private NetconfOperationServiceFactory aggregator; + @Inject + private NetconfMonitoringService monitoringService; + @Inject + private Timer timer; + @Inject + private NioEventLoopGroup nettyThreadgroup; + + @Override + protected NetconfServerDispatcherImpl create() { + AggregatedNetconfOperationServiceFactory netconfOperationProvider = + new AggregatedNetconfOperationServiceFactory(); + netconfOperationProvider.onAddNetconfOperationServiceFactory(aggregator); + + NetconfServerSessionNegotiatorFactory serverNegotiatorFactory = + new NetconfServerSessionNegotiatorFactory(timer, netconfOperationProvider, new SessionIdProvider(), + CONNECTION_TIMEOUT_MILLIS, monitoringService); + NetconfServerDispatcherImpl.ServerChannelInitializer serverChannelInitializer = + new NetconfServerDispatcherImpl.ServerChannelInitializer(serverNegotiatorFactory); + + return new NetconfServerDispatcherImpl(serverChannelInitializer, nettyThreadgroup, nettyThreadgroup); + } +} diff --git a/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/netconf/NetconfSshServerProvider.groovy b/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/netconf/NetconfSshServerProvider.groovy deleted file mode 100644 index 55daca23d..000000000 --- a/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/netconf/NetconfSshServerProvider.groovy +++ /dev/null @@ -1,97 +0,0 @@ -/* - * 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.netconf - -import com.google.common.util.concurrent.ThreadFactoryBuilder -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 io.netty.channel.ChannelFuture -import io.netty.channel.local.LocalAddress -import io.netty.channel.nio.NioEventLoopGroup -import io.netty.util.concurrent.GenericFutureListener -import io.netty.util.concurrent.GlobalEventExecutor -import org.apache.sshd.server.keyprovider.PEMGeneratorHostKeyProvider -import org.opendaylight.netconf.api.NetconfServerDispatcher -import org.opendaylight.netconf.ssh.SshProxyServer -import org.opendaylight.netconf.ssh.SshProxyServerConfigurationBuilder - -import java.util.concurrent.Executors -import java.util.concurrent.ScheduledExecutorService - -@Slf4j -@ToString -class NetconfSshServerProvider extends ProviderTrait { - - @Inject - NetconfServerDispatcher dispatcher - @Inject - HoneycombConfiguration cfgAttributes - @Inject - NioEventLoopGroup nettyThreadgroup - - private ScheduledExecutorService pool = - Executors.newScheduledThreadPool(1, new ThreadFactoryBuilder().setNameFormat("netconf-ssh-%d").build()) - - @Override - def create() { - def name = InetAddress.getByName(cfgAttributes.netconfSshBindingAddress.get()) - def bindingAddress = new InetSocketAddress(name, cfgAttributes.netconfSshBindingPort.get()) - - def localAddress = new LocalAddress(cfgAttributes.netconfSshBindingPort.toString()) - def localServer = dispatcher.createLocalServer(localAddress) - - def sshProxyServer = new SshProxyServer(pool, nettyThreadgroup, GlobalEventExecutor.INSTANCE) - - def sshConfigBuilder = new SshProxyServerConfigurationBuilder() - sshConfigBuilder.bindingAddress = bindingAddress - sshConfigBuilder.localAddress = localAddress - // TODO only simple authProvider checking ConfigAttributes - sshConfigBuilder.authenticator = { String uname, String passwd -> - cfgAttributes.username == uname && cfgAttributes.password == passwd - } - sshConfigBuilder.idleTimeout = Integer.MAX_VALUE - sshConfigBuilder.keyPairProvider = new PEMGeneratorHostKeyProvider() - - localServer.addListener(new GenericFutureListener() { - - @Override - public void operationComplete(final ChannelFuture future) { - if(future.isDone() && !future.isCancelled()) { - try { - sshProxyServer.bind(sshConfigBuilder.createSshProxyServerConfiguration()) - log.info "Netconf SSH endpoint started successfully at {}", bindingAddress - } catch (final IOException e) { - throw new RuntimeException("Unable to start SSH netconf server", e) - } - } else { - log.warn "Unable to start SSH netconf server at {}", bindingAddress, future.cause() - throw new RuntimeException("Unable to start SSH netconf server", future.cause()) - } - } - }) - - return new NetconfSshServer(localServer: localServer, sshProxyServer: sshProxyServer) - } - - static class NetconfSshServer { - def localServer - def sshProxyServer - } -} diff --git a/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/netconf/NetconfSshServerProvider.java b/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/netconf/NetconfSshServerProvider.java new file mode 100644 index 000000000..53be6b5d9 --- /dev/null +++ b/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/netconf/NetconfSshServerProvider.java @@ -0,0 +1,151 @@ +/* + * 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.netconf; + +import com.google.common.util.concurrent.ThreadFactoryBuilder; +import com.google.inject.Inject; +import io.fd.honeycomb.infra.distro.ProviderTrait; +import io.fd.honeycomb.infra.distro.cfgattrs.HoneycombConfiguration; +import io.netty.channel.ChannelFuture; +import io.netty.channel.local.LocalAddress; +import io.netty.channel.nio.NioEventLoopGroup; +import io.netty.util.concurrent.GenericFutureListener; +import io.netty.util.concurrent.GlobalEventExecutor; +import java.io.IOException; +import java.net.InetAddress; +import java.net.InetSocketAddress; +import java.net.UnknownHostException; +import java.util.concurrent.Executors; +import java.util.concurrent.ScheduledExecutorService; +import org.apache.sshd.server.keyprovider.PEMGeneratorHostKeyProvider; +import org.opendaylight.netconf.api.NetconfServerDispatcher; +import org.opendaylight.netconf.auth.AuthProvider; +import org.opendaylight.netconf.ssh.SshProxyServer; +import org.opendaylight.netconf.ssh.SshProxyServerConfigurationBuilder; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + + +public final class NetconfSshServerProvider extends ProviderTrait { + + private static final Logger LOG = LoggerFactory.getLogger(NetconfSshServerProvider.class); + + @Inject + private NetconfServerDispatcher dispatcher; + @Inject + private HoneycombConfiguration cfgAttributes; + @Inject + private NioEventLoopGroup nettyThreadgroup; + + private ScheduledExecutorService pool = + Executors.newScheduledThreadPool(1, new ThreadFactoryBuilder().setNameFormat("netconf-ssh-%d").build()); + + @Override + protected NetconfSshServer create() { + InetAddress sshBindingAddress = null; + try { + sshBindingAddress = InetAddress.getByName(cfgAttributes.netconfSshBindingAddress.get()); + } catch (UnknownHostException e) { + throw new IllegalArgumentException("Illegal binding address", e); + } + + final InetSocketAddress bindingAddress = + new InetSocketAddress(sshBindingAddress, cfgAttributes.netconfSshBindingPort.get()); + + LocalAddress localAddress = new LocalAddress(cfgAttributes.netconfSshBindingPort.toString()); + ChannelFuture localServer = dispatcher.createLocalServer(localAddress); + + final SshProxyServer sshProxyServer = new SshProxyServer(pool, nettyThreadgroup, GlobalEventExecutor.INSTANCE); + + final SshProxyServerConfigurationBuilder sshConfigBuilder = new SshProxyServerConfigurationBuilder(); + sshConfigBuilder.setBindingAddress(bindingAddress); + sshConfigBuilder.setLocalAddress(localAddress); + // TODO only simple authProvider checking ConfigAttributes + sshConfigBuilder.setAuthenticator(new SimplelAuthProvider(cfgAttributes)); + sshConfigBuilder.setIdleTimeout(Integer.MAX_VALUE); + sshConfigBuilder.setKeyPairProvider(new PEMGeneratorHostKeyProvider()); + + localServer.addListener(new SshServerBinder(sshProxyServer, sshConfigBuilder, bindingAddress)); + + return new NetconfSshServer(localServer, sshProxyServer); + } + + public static final class NetconfSshServer { + private ChannelFuture localServer; + private SshProxyServer sshProxyServer; + + NetconfSshServer(final ChannelFuture localServer, + final SshProxyServer sshProxyServer) { + this.localServer = localServer; + this.sshProxyServer = sshProxyServer; + } + + public Object getLocalServer() { + return localServer; + } + + public Object getSshProxyServer() { + return sshProxyServer; + } + } + + private static final class SimplelAuthProvider implements AuthProvider { + + private final HoneycombConfiguration cfgAttributes; + + SimplelAuthProvider(final HoneycombConfiguration cfgAttributes) { + this.cfgAttributes = cfgAttributes; + } + + @Override + public boolean authenticated(final String uname, final String passwd) { + return cfgAttributes.username.equals(uname) && cfgAttributes.password.equals(passwd); + } + } + + private static final class SshServerBinder implements GenericFutureListener { + private final SshProxyServer sshProxyServer; + private final SshProxyServerConfigurationBuilder sshConfigBuilder; + private final InetSocketAddress bindingAddress; + + SshServerBinder(final SshProxyServer sshProxyServer, + final SshProxyServerConfigurationBuilder sshConfigBuilder, + final InetSocketAddress bindingAddress) { + this.sshProxyServer = sshProxyServer; + this.sshConfigBuilder = sshConfigBuilder; + this.bindingAddress = bindingAddress; + } + + @Override + public void operationComplete(final ChannelFuture future) { + if (future.isDone() && !future.isCancelled()) { + try { + sshProxyServer.bind(sshConfigBuilder.createSshProxyServerConfiguration()); + LOG.info("Netconf SSH endpoint started successfully at {}", bindingAddress); + } catch (final IOException e) { + throw new RuntimeException("Unable to start SSH netconf server", e); + } + + } else { + LOG.warn("Unable to start SSH netconf server at {}", bindingAddress, future.cause()); + throw new RuntimeException("Unable to start SSH netconf server", future.cause()); + } + + } + + } +} diff --git a/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/netconf/NetconfTcpServerProvider.groovy b/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/netconf/NetconfTcpServerProvider.groovy deleted file mode 100644 index 1b0800207..000000000 --- a/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/netconf/NetconfTcpServerProvider.groovy +++ /dev/null @@ -1,63 +0,0 @@ -/* - * 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.netconf - -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 io.netty.channel.ChannelFuture -import io.netty.util.concurrent.GenericFutureListener -import org.opendaylight.netconf.api.NetconfServerDispatcher - -@Slf4j -@ToString -class NetconfTcpServerProvider extends ProviderTrait { - - @Inject - NetconfServerDispatcher dispatcher - @Inject - HoneycombConfiguration cfgAttributes - - @Override - def create() { - - def name = InetAddress.getByName(cfgAttributes.netconfTcpBindingAddress.get()) - def unresolved = new InetSocketAddress(name, cfgAttributes.netconfTcpBindingPort.get()) - - def tcpServer = dispatcher.createServer(unresolved) - - tcpServer.addListener(new GenericFutureListener() { - @Override - public void operationComplete(ChannelFuture future) throws Exception { - if (future.isDone() && future.isSuccess()) { - log.info("Netconf TCP endpoint started successfully at {}", unresolved) - } else { - log.warn("Unable to start TCP netconf server at {}", unresolved, future.cause()) - throw new RuntimeException("Unable to start TCP netconf server", future.cause()) - } - } - }) - - new NetconfTcpServer(tcpServer: tcpServer) - } - - static class NetconfTcpServer { - def tcpServer - } -} diff --git a/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/netconf/NetconfTcpServerProvider.java b/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/netconf/NetconfTcpServerProvider.java new file mode 100644 index 000000000..d6ab47446 --- /dev/null +++ b/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/netconf/NetconfTcpServerProvider.java @@ -0,0 +1,85 @@ +/* + * 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.netconf; + +import com.google.inject.Inject; +import io.fd.honeycomb.infra.distro.ProviderTrait; +import io.fd.honeycomb.infra.distro.cfgattrs.HoneycombConfiguration; +import io.netty.channel.ChannelFuture; +import io.netty.util.concurrent.GenericFutureListener; +import java.net.InetAddress; +import java.net.InetSocketAddress; +import java.net.UnknownHostException; +import org.opendaylight.netconf.api.NetconfServerDispatcher; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public final class NetconfTcpServerProvider extends ProviderTrait { + + private static final Logger LOG = LoggerFactory.getLogger(NetconfTcpServerProvider.class); + + @Inject + private NetconfServerDispatcher dispatcher; + @Inject + private HoneycombConfiguration cfgAttributes; + + @Override + protected NetconfTcpServer create() { + InetAddress name = null; + try { + name = InetAddress.getByName(cfgAttributes.netconfTcpBindingAddress.get()); + } catch (UnknownHostException e) { + throw new IllegalArgumentException("Illegal binding address", e); + } + + final InetSocketAddress unresolved = new InetSocketAddress(name, cfgAttributes.netconfTcpBindingPort.get()); + + ChannelFuture tcpServer = dispatcher.createServer(unresolved); + tcpServer.addListener(new TcpLoggingListener(unresolved)); + return new NetconfTcpServer(tcpServer); + } + + public static final class NetconfTcpServer { + private Object tcpServer; + + NetconfTcpServer(final ChannelFuture tcpServer) { + this.tcpServer = tcpServer; + } + + public Object getTcpServer() { + return tcpServer; + } + } + + private static final class TcpLoggingListener implements GenericFutureListener { + private final InetSocketAddress unresolved; + + TcpLoggingListener(final InetSocketAddress unresolved) { + this.unresolved = unresolved; + } + + @Override + public void operationComplete(ChannelFuture future) throws Exception { + if (future.isDone() && future.isSuccess()) { + LOG.info("Netconf TCP endpoint started successfully at {}", unresolved); + } else { + LOG.warn("Unable to start TCP netconf server at {}", unresolved, future.cause()); + throw new RuntimeException("Unable to start TCP netconf server", future.cause()); + } + } + } +} diff --git a/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/netconf/NettyThreadGroupProvider.groovy b/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/netconf/NettyThreadGroupProvider.groovy deleted file mode 100644 index 90948647d..000000000 --- a/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/netconf/NettyThreadGroupProvider.groovy +++ /dev/null @@ -1,39 +0,0 @@ -/* - * 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.netconf - -import com.google.common.util.concurrent.ThreadFactoryBuilder -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.infra.distro.cfgattrs.HoneycombConfiguration -import io.netty.channel.nio.NioEventLoopGroup - -@Slf4j -@ToString -class NettyThreadGroupProvider extends ProviderTrait { - - @Inject - HoneycombConfiguration cfgAttributes - - @Override - def create() { - new NioEventLoopGroup(cfgAttributes.netconfNettyThreads, - new ThreadFactoryBuilder().setNameFormat("netconf-netty-%d").build()) - } -} diff --git a/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/netconf/NettyThreadGroupProvider.java b/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/netconf/NettyThreadGroupProvider.java new file mode 100644 index 000000000..e14952bba --- /dev/null +++ b/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/netconf/NettyThreadGroupProvider.java @@ -0,0 +1,35 @@ +/* + * 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.netconf; + +import com.google.common.util.concurrent.ThreadFactoryBuilder; +import com.google.inject.Inject; +import io.fd.honeycomb.infra.distro.ProviderTrait; +import io.fd.honeycomb.infra.distro.cfgattrs.HoneycombConfiguration; +import io.netty.channel.nio.NioEventLoopGroup; + +public final class NettyThreadGroupProvider extends ProviderTrait { + + @Inject + private HoneycombConfiguration cfgAttributes; + + @Override + protected NioEventLoopGroup create() { + return new NioEventLoopGroup(cfgAttributes.netconfNettyThreads, + new ThreadFactoryBuilder().setNameFormat("netconf-netty-%d").build()); + } +} diff --git a/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/netconf/NettyTimerProvider.groovy b/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/netconf/NettyTimerProvider.groovy deleted file mode 100644 index e889633ed..000000000 --- a/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/netconf/NettyTimerProvider.groovy +++ /dev/null @@ -1,39 +0,0 @@ -/* - * 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.netconf - -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 io.netty.util.HashedWheelTimer -import io.netty.util.Timer - -@Slf4j -@ToString -class NettyTimerProvider extends ProviderTrait { - - @Inject - HoneycombConfiguration cfgAttributes - - @Override - def create() { - // TODO expose configuration, - new HashedWheelTimer() - } -} diff --git a/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/netconf/NettyTimerProvider.java b/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/netconf/NettyTimerProvider.java new file mode 100644 index 000000000..6ae960cea --- /dev/null +++ b/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/netconf/NettyTimerProvider.java @@ -0,0 +1,35 @@ +/* + * 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.netconf; + +import com.google.inject.Inject; +import io.fd.honeycomb.infra.distro.ProviderTrait; +import io.fd.honeycomb.infra.distro.cfgattrs.HoneycombConfiguration; +import io.netty.util.HashedWheelTimer; +import io.netty.util.Timer; + +public final class NettyTimerProvider extends ProviderTrait { + + @Inject + private HoneycombConfiguration cfgAttributes; + + @Override + protected HashedWheelTimer create() { + // TODO expose configuration, + return new HashedWheelTimer(); + } +} diff --git a/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/restconf/HttpConnectorProvider.groovy b/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/restconf/HttpConnectorProvider.groovy deleted file mode 100644 index 0be4a3264..000000000 --- a/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/restconf/HttpConnectorProvider.groovy +++ /dev/null @@ -1,24 +0,0 @@ -package io.fd.honeycomb.infra.distro.restconf - -import com.google.inject.Inject -import io.fd.honeycomb.infra.distro.ProviderTrait -import io.fd.honeycomb.infra.distro.cfgattrs.HoneycombConfiguration -import org.eclipse.jetty.server.Server -import org.eclipse.jetty.server.ServerConnector - -class HttpConnectorProvider extends ProviderTrait { - - @Inject - HoneycombConfiguration cfg - @Inject - Server server - - @Override - def create() { - def httpConnector = new ServerConnector(server, cfg.acceptorsSize.get(), cfg.selectorsSize.get()) - httpConnector.setHost(cfg.restconfBindingAddress.get()) - httpConnector.setPort(cfg.restconfPort.get()) - server.addConnector(httpConnector) - httpConnector - } -} diff --git a/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/restconf/HttpConnectorProvider.java b/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/restconf/HttpConnectorProvider.java new file mode 100644 index 000000000..e3c9577e7 --- /dev/null +++ b/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/restconf/HttpConnectorProvider.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.restconf; + +import com.google.inject.Inject; +import io.fd.honeycomb.infra.distro.ProviderTrait; +import io.fd.honeycomb.infra.distro.cfgattrs.HoneycombConfiguration; +import org.eclipse.jetty.server.Server; +import org.eclipse.jetty.server.ServerConnector; + +public final class HttpConnectorProvider extends ProviderTrait { + + @Inject + private HoneycombConfiguration cfg; + @Inject + private Server server; + + @Override + protected ServerConnector create() { + ServerConnector httpConnector = + new ServerConnector(server, cfg.acceptorsSize.get(), cfg.selectorsSize.get()); + httpConnector.setHost(cfg.restconfBindingAddress.get()); + httpConnector.setPort(cfg.restconfPort.get()); + server.addConnector(httpConnector); + return httpConnector; + } +} diff --git a/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/restconf/HttpsConnectorProvider.groovy b/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/restconf/HttpsConnectorProvider.groovy deleted file mode 100644 index 388aa2bbe..000000000 --- a/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/restconf/HttpsConnectorProvider.groovy +++ /dev/null @@ -1,57 +0,0 @@ -package io.fd.honeycomb.infra.distro.restconf - -import com.google.inject.Inject -import io.fd.honeycomb.infra.distro.ProviderTrait -import io.fd.honeycomb.infra.distro.cfgattrs.HoneycombConfiguration -import org.eclipse.jetty.http.HttpVersion -import org.eclipse.jetty.server.Server -import org.eclipse.jetty.server.ServerConnector -import org.eclipse.jetty.server.SslConnectionFactory -import org.eclipse.jetty.util.ssl.SslContextFactory - -class HttpsConnectorProvider extends ProviderTrait { - - @Inject - HoneycombConfiguration cfg - @Inject - Server server - - @Override - def create() { - - // SSL Context Factory - // Based on: - // https://github.com/eclipse/jetty.project/blob/jetty-9.3.x/examples/embedded/src/main/java/org/eclipse/jetty/embedded/LikeJettyXml.java - // https://wiki.eclipse.org/Jetty/Howto/Configure_SSL#Loading_Keys_and_Certificates_via_PKCS12 - // Keystore created with: - // openssl genrsa -des3 -out honeycomb.key - // openssl req -new -x509 -key honeycomb.key -out honeycomb.crt - // openssl pkcs12 -inkey honeycomb.key -in honeycomb.crt -export -out honeycomb.pkcs12 - // keytool -importkeystore -srckeystore honeycomb.pkcs12 -srcstoretype PKCS12 -destkeystore honeycomb-keystore - def sslContextFactory = new SslContextFactory() - def keystoreURL = getClass().getResource(cfg.restconfKeystore.get()) - sslContextFactory.setKeyStorePath(keystoreURL.path) - sslContextFactory.setKeyStorePassword(cfg.keystorePassword.get()) - sslContextFactory.setKeyManagerPassword((cfg.keystoreManagerPassword.get())) - def truststoreURL = getClass().getResource(cfg.restconfTruststore.get()) - sslContextFactory.setTrustStorePath(truststoreURL.path) - sslContextFactory.setTrustStorePassword((cfg.truststorePassword.get())) - // TODO make this more configurable - sslContextFactory.setExcludeCipherSuites( - "SSL_RSA_WITH_DES_CBC_SHA", - "SSL_DHE_RSA_WITH_DES_CBC_SHA", - "SSL_DHE_DSS_WITH_DES_CBC_SHA", - "SSL_RSA_EXPORT_WITH_RC4_40_MD5", - "SSL_RSA_EXPORT_WITH_DES40_CBC_SHA", - "SSL_DHE_RSA_EXPORT_WITH_DES40_CBC_SHA", - "SSL_DHE_DSS_EXPORT_WITH_DES40_CBC_SHA") - - // SSL Connector - def sslConnector = new ServerConnector(server, cfg.httpsAcceptorsSize.get(), cfg.httpsSelectorsSize.get(), - new SslConnectionFactory(sslContextFactory, HttpVersion.HTTP_1_1.asString())) - sslConnector.setHost(cfg.restconfHttpsBindingAddress.get()) - sslConnector.setPort(cfg.restconfHttpsPort.get()) - server.addConnector(sslConnector) - return sslConnector - } -} diff --git a/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/restconf/HttpsConnectorProvider.java b/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/restconf/HttpsConnectorProvider.java new file mode 100644 index 000000000..76fc72f3f --- /dev/null +++ b/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/restconf/HttpsConnectorProvider.java @@ -0,0 +1,75 @@ +/* + * 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.restconf; + +import com.google.inject.Inject; +import io.fd.honeycomb.infra.distro.ProviderTrait; +import io.fd.honeycomb.infra.distro.cfgattrs.HoneycombConfiguration; +import java.net.URL; +import org.eclipse.jetty.http.HttpVersion; +import org.eclipse.jetty.server.HttpConnectionFactory; +import org.eclipse.jetty.server.Server; +import org.eclipse.jetty.server.ServerConnector; +import org.eclipse.jetty.server.SslConnectionFactory; +import org.eclipse.jetty.util.ssl.SslContextFactory; + +public final class HttpsConnectorProvider extends ProviderTrait { + + @Inject + private HoneycombConfiguration cfg; + @Inject + private Server server; + + @Override + protected ServerConnector create() { + // SSL Context Factory + // Based on: + // https://github.com/eclipse/jetty.project/blob/jetty-9.3.x/examples/embedded/src/main/java/org/eclipse/jetty/embedded/LikeJettyXml.java + // https://wiki.eclipse.org/Jetty/Howto/Configure_SSL#Loading_Keys_and_Certificates_via_PKCS12 + // Keystore created with: + // openssl genrsa -des3 -out honeycomb.key + // openssl req -new -x509 -key honeycomb.key -out honeycomb.crt + // openssl pkcs12 -inkey honeycomb.key -in honeycomb.crt -export -out honeycomb.pkcs12 + // keytool -importkeystore -srckeystore honeycomb.pkcs12 -srcstoretype PKCS12 -destkeystore honeycomb-keystore + SslContextFactory sslContextFactory = new SslContextFactory(); + URL keystoreURL = getClass().getResource(cfg.restconfKeystore.get()); + sslContextFactory.setKeyStorePath(keystoreURL.getPath()); + sslContextFactory.setKeyStorePassword(cfg.keystorePassword.get()); + sslContextFactory.setKeyManagerPassword((cfg.keystoreManagerPassword.get())); + URL truststoreURL = getClass().getResource(cfg.restconfTruststore.get()); + sslContextFactory.setTrustStorePath(truststoreURL.getPath()); + sslContextFactory.setTrustStorePassword((cfg.truststorePassword.get())); + // TODO make this more configurable + sslContextFactory.setExcludeCipherSuites("SSL_RSA_WITH_DES_CBC_SHA", "SSL_DHE_RSA_WITH_DES_CBC_SHA", + "SSL_DHE_DSS_WITH_DES_CBC_SHA", "SSL_RSA_EXPORT_WITH_RC4_40_MD5", "SSL_RSA_EXPORT_WITH_DES40_CBC_SHA", + "SSL_DHE_RSA_EXPORT_WITH_DES40_CBC_SHA", "SSL_DHE_DSS_EXPORT_WITH_DES40_CBC_SHA"); + + // SSL Connector + ServerConnector sslConnector = + new ServerConnector(server, cfg.httpsAcceptorsSize.get(), cfg.httpsSelectorsSize.get(), + // The ssl connection factory delegates the real processing to http connection factory + new SslConnectionFactory(sslContextFactory, HttpVersion.HTTP_1_1.asString()), + // That's why http connection factory is also required here + // Order is IMPORTANT here + new HttpConnectionFactory() + ); + sslConnector.setHost(cfg.restconfHttpsBindingAddress.get()); + sslConnector.setPort(cfg.restconfHttpsPort.get()); + server.addConnector(sslConnector); + return sslConnector; + } +} diff --git a/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/restconf/JettyServerProvider.groovy b/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/restconf/JettyServerProvider.groovy deleted file mode 100644 index 14e6ae6f2..000000000 --- a/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/restconf/JettyServerProvider.groovy +++ /dev/null @@ -1,80 +0,0 @@ -/* - * 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.restconf - -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.infra.distro.cfgattrs.HoneycombConfiguration -import org.eclipse.jetty.security.ConstraintMapping -import org.eclipse.jetty.security.ConstraintSecurityHandler -import org.eclipse.jetty.security.HashLoginService -import org.eclipse.jetty.security.authentication.BasicAuthenticator -import org.eclipse.jetty.server.Server -import org.eclipse.jetty.util.security.Constraint -import org.eclipse.jetty.util.security.Password -import org.eclipse.jetty.util.thread.QueuedThreadPool -import org.eclipse.jetty.webapp.WebAppContext - -@Slf4j -@ToString -class JettyServerProvider extends ProviderTrait { - - public static final String REALM = "HCRealm" - - @Inject - HoneycombConfiguration cfg - - def create() { - def server = new Server(new QueuedThreadPool(cfg.restPoolMaxSize.get(), cfg.restPoolMinSize.get())) - - // Load Realm for basic auth - def service = new HashLoginService(REALM) - // Reusing the name as role - service.putUser(cfg.username, new Password(cfg.password), cfg.username) - server.addBean(service) - - final URL resource = getClass().getResource("/") - WebAppContext webapp = new WebAppContext(resource.getPath(), cfg.restconfRootPath.get()) - - ConstraintSecurityHandler security = getBaseAuth(service, webapp) - server.setHandler(security) - - return server - } - - private ConstraintSecurityHandler getBaseAuth(HashLoginService service, WebAppContext webapp) { - ConstraintSecurityHandler security = new ConstraintSecurityHandler() - - Constraint constraint = new Constraint() - constraint.setName("auth") - constraint.setAuthenticate(true) - constraint.setRoles(cfg.username) - - ConstraintMapping mapping = new ConstraintMapping() - mapping.setPathSpec("/*") - mapping.setConstraint(constraint) - - security.setConstraintMappings(Collections.singletonList(mapping)) - security.setAuthenticator(new BasicAuthenticator()) - security.setLoginService(service) - - security.setHandler(webapp) - security - } -} diff --git a/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/restconf/JettyServerProvider.java b/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/restconf/JettyServerProvider.java new file mode 100644 index 000000000..6d055bf81 --- /dev/null +++ b/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/restconf/JettyServerProvider.java @@ -0,0 +1,80 @@ +/* + * 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.restconf; + +import com.google.inject.Inject; +import io.fd.honeycomb.infra.distro.ProviderTrait; +import io.fd.honeycomb.infra.distro.cfgattrs.HoneycombConfiguration; +import java.net.URL; +import java.util.Collections; +import org.eclipse.jetty.security.ConstraintMapping; +import org.eclipse.jetty.security.ConstraintSecurityHandler; +import org.eclipse.jetty.security.HashLoginService; +import org.eclipse.jetty.security.authentication.BasicAuthenticator; +import org.eclipse.jetty.server.Server; +import org.eclipse.jetty.util.security.Constraint; +import org.eclipse.jetty.util.security.Password; +import org.eclipse.jetty.util.thread.QueuedThreadPool; +import org.eclipse.jetty.webapp.WebAppContext; + +public final class JettyServerProvider extends ProviderTrait { + + public static final String REALM = "HCRealm"; + + @Inject + private HoneycombConfiguration cfg; + + @Override + protected Server create() { + Server server = new Server(new QueuedThreadPool(cfg.restPoolMaxSize.get(), cfg.restPoolMinSize.get())); + + + // Load Realm for basic auth + HashLoginService service = new HashLoginService(REALM); + // Reusing the name as role + service.putUser(cfg.username, new Password(cfg.password), new String[]{cfg.username}); + server.addBean(service); + + final URL resource = getClass().getResource("/"); + WebAppContext webapp = new WebAppContext(resource.getPath(), cfg.restconfRootPath.get()); + + ConstraintSecurityHandler security = getBaseAuth(service, webapp); + server.setHandler(security); + + return server; + } + + private ConstraintSecurityHandler getBaseAuth(HashLoginService service, WebAppContext webapp) { + ConstraintSecurityHandler security = new ConstraintSecurityHandler(); + + Constraint constraint = new Constraint(); + constraint.setName("auth"); + constraint.setAuthenticate(true); + constraint.setRoles(new String[]{cfg.username}); + + ConstraintMapping mapping = new ConstraintMapping(); + mapping.setPathSpec("/*"); + mapping.setConstraint(constraint); + + security.setConstraintMappings(Collections.singletonList(mapping)); + security.setAuthenticator(new BasicAuthenticator()); + security.setLoginService(service); + + security.setHandler(webapp); + return security; + } +} diff --git a/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/restconf/RestconfModule.groovy b/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/restconf/RestconfModule.groovy deleted file mode 100644 index e8594a8c3..000000000 --- a/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/restconf/RestconfModule.groovy +++ /dev/null @@ -1,39 +0,0 @@ -/* - * 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.restconf - -import com.google.inject.AbstractModule -import com.google.inject.Singleton -import com.google.inject.name.Names -import groovy.util.logging.Slf4j -import org.eclipse.jetty.server.Server -import org.eclipse.jetty.server.ServerConnector -import org.opendaylight.netconf.sal.rest.api.RestConnector - -@Slf4j -class RestconfModule extends AbstractModule { - - public static final String RESTCONF_HTTP = "restconf-http" - public static final String RESTCONF_HTTPS = "restconf-https" - - protected void configure() { - bind(Server).toProvider(JettyServerProvider).in(Singleton) - bind(ServerConnector).annotatedWith(Names.named(RESTCONF_HTTP)).toProvider(HttpConnectorProvider).in(Singleton) - bind(ServerConnector).annotatedWith(Names.named(RESTCONF_HTTPS)).toProvider(HttpsConnectorProvider).in(Singleton) - bind(RestConnector).toProvider(RestconfProvider).in(Singleton) - } -} diff --git a/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/restconf/RestconfModule.java b/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/restconf/RestconfModule.java new file mode 100644 index 000000000..846ed1b03 --- /dev/null +++ b/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/restconf/RestconfModule.java @@ -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.restconf; + +import com.google.inject.AbstractModule; +import com.google.inject.Singleton; +import com.google.inject.name.Names; +import org.eclipse.jetty.server.Server; +import org.eclipse.jetty.server.ServerConnector; +import org.opendaylight.netconf.sal.rest.api.RestConnector; + + +public class RestconfModule extends AbstractModule { + + public static final String RESTCONF_HTTP = "restconf-http"; + public static final String RESTCONF_HTTPS = "restconf-https"; + + protected void configure() { + bind(Server.class).toProvider(JettyServerProvider.class).in(Singleton.class); + bind(ServerConnector.class).annotatedWith(Names.named(RESTCONF_HTTP)).toProvider(HttpConnectorProvider.class) + .in(Singleton.class); + bind(ServerConnector.class).annotatedWith(Names.named(RESTCONF_HTTPS)).toProvider(HttpsConnectorProvider.class) + .in(Singleton.class); + bind(RestConnector.class).toProvider(RestconfProvider.class).in(Singleton.class); + } +} diff --git a/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/restconf/RestconfProvider.groovy b/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/restconf/RestconfProvider.groovy deleted file mode 100644 index 657e16986..000000000 --- a/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/restconf/RestconfProvider.groovy +++ /dev/null @@ -1,45 +0,0 @@ -/* - * 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.restconf - -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.infra.distro.cfgattrs.HoneycombConfiguration -import org.opendaylight.controller.sal.core.api.Broker -import org.opendaylight.netconf.sal.rest.api.RestConnector -import org.opendaylight.netconf.sal.restconf.impl.RestconfProviderImpl -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.PortNumber - -@Slf4j -@ToString -class RestconfProvider extends ProviderTrait { - - @Inject - HoneycombConfiguration cfg - - @Inject - Broker domBroker - - def create() { - def instance = new RestconfProviderImpl() - instance.setWebsocketPort(new PortNumber(cfg.restconfWebsocketPort.get())) - domBroker.registerProvider(instance) - instance - } -} diff --git a/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/restconf/RestconfProvider.java b/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/restconf/RestconfProvider.java new file mode 100644 index 000000000..16a33ecbb --- /dev/null +++ b/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/restconf/RestconfProvider.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.restconf; + +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.Broker; +import org.opendaylight.netconf.sal.rest.api.RestConnector; +import org.opendaylight.netconf.sal.restconf.impl.RestconfProviderImpl; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.PortNumber; + + + +public class RestconfProvider extends ProviderTrait { + + @Inject + private HoneycombConfiguration cfg; + @Inject + private Broker domBroker; + + @Override + protected RestconfProviderImpl create() { + RestconfProviderImpl instance = new RestconfProviderImpl(); + instance.setWebsocketPort(new PortNumber(cfg.restconfWebsocketPort.get())); + domBroker.registerProvider(instance); + return instance; + } +} diff --git a/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/schema/ModuleInfoBackedCtxProvider.groovy b/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/schema/ModuleInfoBackedCtxProvider.groovy deleted file mode 100644 index a319bb8af..000000000 --- a/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/schema/ModuleInfoBackedCtxProvider.groovy +++ /dev/null @@ -1,47 +0,0 @@ -/* - * 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.schema - -import com.google.common.base.MoreObjects -import com.google.inject.Inject -import groovy.transform.ToString -import groovy.util.logging.Slf4j -import io.fd.honeycomb.infra.distro.ProviderTrait -import org.opendaylight.yangtools.sal.binding.generator.impl.ModuleInfoBackedContext -import org.opendaylight.yangtools.yang.binding.YangModelBindingProvider - -@Slf4j -@ToString -class ModuleInfoBackedCtxProvider extends ProviderTrait { - - @Inject(optional = true) - Set moduleInfos = [] - - def create() { - def create = ModuleInfoBackedContext.create() - create.addModuleInfos(moduleInfos.collect {it.getModuleInfo()}) - log.debug "ModuleInfoBackedContext created from {}", moduleInfos - create - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("writerFactories", moduleInfos) - .toString(); - } -} diff --git a/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/schema/ModuleInfoBackedCtxProvider.java b/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/schema/ModuleInfoBackedCtxProvider.java new file mode 100644 index 000000000..f82cdd0b1 --- /dev/null +++ b/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/schema/ModuleInfoBackedCtxProvider.java @@ -0,0 +1,50 @@ +/* + * 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.schema; + +import com.google.common.base.MoreObjects; +import com.google.inject.Inject; +import io.fd.honeycomb.infra.distro.ProviderTrait; +import java.util.HashSet; +import java.util.Set; +import java.util.stream.Collectors; +import org.opendaylight.yangtools.sal.binding.generator.impl.ModuleInfoBackedContext; +import org.opendaylight.yangtools.yang.binding.YangModelBindingProvider; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public final class ModuleInfoBackedCtxProvider extends ProviderTrait { + private static final Logger LOG = LoggerFactory.getLogger(ModuleInfoBackedCtxProvider.class); + + @Inject(optional = true) + private Set moduleInfos = new HashSet<>(); + + @Override + protected ModuleInfoBackedContext create() { + ModuleInfoBackedContext create = ModuleInfoBackedContext.create(); + create.addModuleInfos(moduleInfos.stream() + .map(YangModelBindingProvider::getModuleInfo) + .collect(Collectors.toList())); + LOG.debug("ModuleInfoBackedContext created from {}", moduleInfos); + return create; + } + + @Override + public String toString() { + return MoreObjects.toStringHelper(this).add("writerFactories", moduleInfos).toString(); + } +} diff --git a/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/schema/SchemaModule.groovy b/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/schema/SchemaModule.groovy deleted file mode 100644 index 8bb9fc65f..000000000 --- a/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/schema/SchemaModule.groovy +++ /dev/null @@ -1,35 +0,0 @@ -/* - * 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.schema - -import com.google.inject.AbstractModule -import com.google.inject.Singleton -import groovy.util.logging.Slf4j -import org.opendaylight.controller.md.sal.binding.impl.BindingToNormalizedNodeCodec -import org.opendaylight.controller.sal.core.api.model.SchemaService -import org.opendaylight.yangtools.sal.binding.generator.impl.ModuleInfoBackedContext - -@Slf4j -class SchemaModule extends AbstractModule { - - protected void configure() { - bind(ModuleInfoBackedContext).toProvider(ModuleInfoBackedCtxProvider).in(Singleton) - bind(SchemaService).toProvider(SchemaServiceProvider).in(Singleton) - bind(BindingToNormalizedNodeCodec).toProvider(SerializerProvider).in(Singleton) - } - -} diff --git a/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/schema/SchemaModule.java b/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/schema/SchemaModule.java new file mode 100644 index 000000000..0799a06f3 --- /dev/null +++ b/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/schema/SchemaModule.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.schema; + +import com.google.inject.AbstractModule; +import com.google.inject.Singleton; +import org.opendaylight.controller.md.sal.binding.impl.BindingToNormalizedNodeCodec; +import org.opendaylight.controller.sal.core.api.model.SchemaService; +import org.opendaylight.yangtools.sal.binding.generator.impl.ModuleInfoBackedContext; + +public class SchemaModule extends AbstractModule { + + protected void configure() { + bind(ModuleInfoBackedContext.class).toProvider(ModuleInfoBackedCtxProvider.class).in(Singleton.class); + bind(SchemaService.class).toProvider(SchemaServiceProvider.class).in(Singleton.class); + bind(BindingToNormalizedNodeCodec.class).toProvider(SerializerProvider.class).in(Singleton.class); + } + +} diff --git a/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/schema/SchemaServiceProvider.groovy b/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/schema/SchemaServiceProvider.groovy deleted file mode 100644 index c020d399b..000000000 --- a/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/schema/SchemaServiceProvider.groovy +++ /dev/null @@ -1,79 +0,0 @@ -/* - * 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.schema - -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.sal.core.api.model.SchemaService -import org.opendaylight.yangtools.concepts.ListenerRegistration -import org.opendaylight.yangtools.sal.binding.generator.impl.ModuleInfoBackedContext -import org.opendaylight.yangtools.yang.model.api.Module -import org.opendaylight.yangtools.yang.model.api.SchemaContext -import org.opendaylight.yangtools.yang.model.api.SchemaContextListener - -@Slf4j -@ToString -class SchemaServiceProvider extends ProviderTrait { - - @Inject - ModuleInfoBackedContext mibCtx; - - def create() { new StaticSchemaService(mibCtx.getSchemaContext()) } - - /** - * Static schema context provider service. - */ - static class StaticSchemaService implements SchemaService { - - private final SchemaContext schemaContext - - StaticSchemaService(SchemaContext schemaContext) { - this.schemaContext = schemaContext - } - - @Override - void addModule(final Module module) { - throw new UnsupportedOperationException("Static service") - } - - @Override - void removeModule(final Module module) { - throw new UnsupportedOperationException("Static service") - } - - @Override - SchemaContext getSessionContext() { - schemaContext - } - - @Override - SchemaContext getGlobalContext() { - schemaContext - } - - @Override - ListenerRegistration registerSchemaContextListener(final SchemaContextListener listener) { - listener.onGlobalContextUpdated schemaContext - return new ListenerRegistration() { - void close() {} - SchemaContextListener getInstance() { listener } - } - } - } -} diff --git a/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/schema/SchemaServiceProvider.java b/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/schema/SchemaServiceProvider.java new file mode 100644 index 000000000..eb3552c12 --- /dev/null +++ b/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/schema/SchemaServiceProvider.java @@ -0,0 +1,81 @@ +/* + * 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.schema; + +import com.google.inject.Inject; +import io.fd.honeycomb.infra.distro.ProviderTrait; +import org.opendaylight.controller.sal.core.api.model.SchemaService; +import org.opendaylight.yangtools.concepts.ListenerRegistration; +import org.opendaylight.yangtools.sal.binding.generator.impl.ModuleInfoBackedContext; +import org.opendaylight.yangtools.yang.model.api.Module; +import org.opendaylight.yangtools.yang.model.api.SchemaContext; +import org.opendaylight.yangtools.yang.model.api.SchemaContextListener; + +public final class SchemaServiceProvider extends ProviderTrait { + + @Inject + private ModuleInfoBackedContext mibCtx; + + public StaticSchemaService create() { + return new StaticSchemaService(mibCtx.getSchemaContext()); + } + + /** + * Static schema context provider service. + */ + private static final class StaticSchemaService implements SchemaService { + private final SchemaContext schemaContext; + + StaticSchemaService(SchemaContext schemaContext) { + this.schemaContext = schemaContext; + } + + @Override + public void addModule(final Module module) { + throw new UnsupportedOperationException("Static service"); + } + + @Override + public void removeModule(final Module module) { + throw new UnsupportedOperationException("Static service"); + } + + @Override + public SchemaContext getSessionContext() { + return schemaContext; + } + + @Override + public SchemaContext getGlobalContext() { + return schemaContext; + } + + @Override + public ListenerRegistration registerSchemaContextListener( + final SchemaContextListener listener) { + listener.onGlobalContextUpdated(schemaContext); + return new ListenerRegistration() { + public void close() {} + + public SchemaContextListener getInstance() { + return listener; + } + + }; + } + } +} diff --git a/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/schema/SerializerProvider.groovy b/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/schema/SerializerProvider.groovy deleted file mode 100644 index 01ea006ec..000000000 --- a/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/schema/SerializerProvider.groovy +++ /dev/null @@ -1,47 +0,0 @@ -/* - * 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.schema - -import com.google.inject.Inject -import groovy.transform.ToString -import groovy.util.logging.Slf4j -import io.fd.honeycomb.infra.distro.ProviderTrait -import javassist.ClassPool -import org.opendaylight.controller.md.sal.binding.impl.BindingToNormalizedNodeCodec -import org.opendaylight.yangtools.binding.data.codec.gen.impl.StreamWriterGenerator -import org.opendaylight.yangtools.binding.data.codec.impl.BindingNormalizedNodeCodecRegistry -import org.opendaylight.yangtools.sal.binding.generator.impl.ModuleInfoBackedContext -import org.opendaylight.yangtools.sal.binding.generator.util.BindingRuntimeContext -import org.opendaylight.yangtools.sal.binding.generator.util.JavassistUtils - -@Slf4j -@ToString -class SerializerProvider extends ProviderTrait { - - @Inject - ModuleInfoBackedContext mibCtx; - - def create() { - def serializerGenerator = new StreamWriterGenerator(JavassistUtils.forClassPool(ClassPool.getDefault())) - def codecRegistry = new BindingNormalizedNodeCodecRegistry(serializerGenerator) - def ctx = BindingRuntimeContext.create(mibCtx, mibCtx.getSchemaContext()) - codecRegistry.onBindingRuntimeContextUpdated(ctx) - def codec = new BindingToNormalizedNodeCodec(mibCtx, codecRegistry) - codec.onGlobalContextUpdated(mibCtx.getSchemaContext()) - codec - } -} \ No newline at end of file diff --git a/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/schema/SerializerProvider.java b/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/schema/SerializerProvider.java new file mode 100644 index 000000000..e61b88432 --- /dev/null +++ b/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/schema/SerializerProvider.java @@ -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.schema; + +import com.google.inject.Inject; +import io.fd.honeycomb.infra.distro.ProviderTrait; +import javassist.ClassPool; +import org.opendaylight.controller.md.sal.binding.impl.BindingToNormalizedNodeCodec; +import org.opendaylight.yangtools.binding.data.codec.gen.impl.StreamWriterGenerator; +import org.opendaylight.yangtools.binding.data.codec.impl.BindingNormalizedNodeCodecRegistry; +import org.opendaylight.yangtools.sal.binding.generator.impl.ModuleInfoBackedContext; +import org.opendaylight.yangtools.sal.binding.generator.util.BindingRuntimeContext; +import org.opendaylight.yangtools.sal.binding.generator.util.JavassistUtils; + +public class SerializerProvider extends ProviderTrait { + + @Inject + private ModuleInfoBackedContext mibCtx; + + @Override + protected BindingToNormalizedNodeCodec create() { + StreamWriterGenerator serializerGenerator = + new StreamWriterGenerator(JavassistUtils.forClassPool(ClassPool.getDefault())); + BindingNormalizedNodeCodecRegistry codecRegistry = new BindingNormalizedNodeCodecRegistry(serializerGenerator); + BindingRuntimeContext ctx = BindingRuntimeContext.create(mibCtx, mibCtx.getSchemaContext()); + codecRegistry.onBindingRuntimeContextUpdated(ctx); + BindingToNormalizedNodeCodec codec = new BindingToNormalizedNodeCodec(mibCtx, codecRegistry); + codec.onGlobalContextUpdated(mibCtx.getSchemaContext()); + return codec; + } +} diff --git a/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/schema/YangBindingProviderModule.groovy b/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/schema/YangBindingProviderModule.groovy deleted file mode 100644 index d8c4e3927..000000000 --- a/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/schema/YangBindingProviderModule.groovy +++ /dev/null @@ -1,51 +0,0 @@ -/* - * 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.schema - -import com.google.common.base.Charsets -import com.google.inject.AbstractModule -import com.google.inject.Singleton -import com.google.inject.multibindings.Multibinder -import groovy.util.logging.Slf4j -import org.opendaylight.yangtools.yang.binding.YangModelBindingProvider - -/** - * Load all YangModelBindingProvider classes from classpath. - *

- * Relying on /META-INF/services/ metadata. - */ -@Slf4j -class YangBindingProviderModule extends AbstractModule { - - static final String YANG_BA_PROVIDER_PATH = "META-INF/services/" + YangModelBindingProvider.class.getName(); - - void configure() { - Multibinder.newSetBinder(binder(), YangModelBindingProvider.class).with { - def resources = Collections.list(getClass().getClassLoader().getResources(YANG_BA_PROVIDER_PATH)) - log.debug "ModuleProviders found at {}", resources - resources.forEach { - it.getText(Charsets.UTF_8.displayName()).split("\n") - .findAll { it != null && !it.isEmpty() && !it.isAllWhitespace()} - .collect { this.getClass().forName(it) } - .forEach { - log.debug "ModuleProvider found for {}", it - addBinding().to(it).in(Singleton) - } - } - } - } -} diff --git a/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/schema/YangBindingProviderModule.java b/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/schema/YangBindingProviderModule.java new file mode 100644 index 000000000..4348333a9 --- /dev/null +++ b/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/schema/YangBindingProviderModule.java @@ -0,0 +1,82 @@ +/* + * 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.schema; + +import com.google.common.base.Charsets; +import com.google.common.base.Strings; +import com.google.common.collect.Lists; +import com.google.common.io.Resources; +import com.google.inject.AbstractModule; +import com.google.inject.Singleton; +import com.google.inject.multibindings.Multibinder; +import java.io.IOException; +import java.net.URL; +import java.util.Collections; +import java.util.List; +import javax.annotation.Nonnull; +import org.opendaylight.yangtools.yang.binding.YangModelBindingProvider; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * Load all YangModelBindingProvider classes from classpath. + *

+ * Relying on /META-INF/services/ metadata. + */ +public class YangBindingProviderModule extends AbstractModule { + private static final Logger LOG = LoggerFactory.getLogger(YangBindingProviderModule.class); + + private static final String YANG_BA_PROVIDER_PATH = "META-INF/services/" + YangModelBindingProvider.class.getName(); + + protected void configure() { + final Multibinder binder = + Multibinder.newSetBinder(binder(), YangModelBindingProvider.class); + final List resources; + try { + resources = Collections.list(getClass().getClassLoader().getResources(YANG_BA_PROVIDER_PATH)); + } catch (IOException e) { + throw new IllegalStateException("Unable to load binding providers from path: " + YANG_BA_PROVIDER_PATH, e); + } + LOG.debug("ModuleProviders found at {}", resources); + resources.stream() + .map(YangBindingProviderModule::urlToString) + .flatMap(content -> Lists.newArrayList(content.split("\n")).stream()) + .filter(line -> !Strings.isNullOrEmpty(line.trim())) + .map(YangBindingProviderModule::loadClass) + .forEach(providerClass -> { + LOG.debug("ModuleProvider found for {}", providerClass); + binder.addBinding().to((Class) providerClass) + .in(Singleton.class); + }); + } + + private static Class loadClass(@Nonnull final String className) { + try { + return Class.forName(className); + } catch (ClassNotFoundException e) { + throw new IllegalArgumentException("Unable to load class: " + className, e); + } + } + + private static String urlToString(@Nonnull final URL url) { + try { + return Resources.toString(url, Charsets.UTF_8); + } catch (IOException e) { + throw new IllegalArgumentException("Unable to read resource from: " + url, e); + } + } +} -- cgit 1.2.3-korg