diff options
author | Maros Marsalek <mmarsale@cisco.com> | 2016-08-25 10:46:02 +0200 |
---|---|---|
committer | Maros Marsalek <mmarsale@cisco.com> | 2016-08-25 10:35:11 +0000 |
commit | cefd2555dbf421a62269c393d0d9d28964f38e2b (patch) | |
tree | ef792decb44b97d759cbd5244be9d1e9a0780949 /infra/minimal-distribution/src/main/java | |
parent | fdc3971cfb72e5c80e0c87f2cd73fee32088718b (diff) |
Remove groovy to reduce footprint
Change-Id: I798558e52329c26aa5481d702745c4d46e290615
Signed-off-by: Maros Marsalek <mmarsale@cisco.com>
Diffstat (limited to 'infra/minimal-distribution/src/main/java')
76 files changed, 2397 insertions, 2122 deletions
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<? extends Module> 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.java index d1bce3176..a762a1618 100644 --- 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.java @@ -14,23 +14,23 @@ * limitations under the License. */ -package io.fd.honeycomb.infra.distro +package io.fd.honeycomb.infra.distro; -import com.google.inject.Provider -import groovy.util.logging.Slf4j +import com.google.inject.Provider; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; -// TODO this should be a trait, but groovy compilation/stub generation sometimes fails (only) in Intellij if using trait +public abstract class ProviderTrait<T> implements Provider<T> { -@Slf4j -abstract class ProviderTrait<T> implements Provider<T> { + private static final Logger LOG = LoggerFactory.getLogger(ProviderTrait.class); @Override - T get() { - log.info "Providing: {}", this - T create = create() as T - log.debug "Provided: {}", create - create + public T get() { + LOG.info("Providing: {}", this); + T create = create(); + LOG.debug("Provided: {}", create); + return create; } - abstract def 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.java index b20f3cd32..b22e88593 100644 --- 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.java @@ -14,21 +14,20 @@ * limitations under the License. */ -package io.fd.honeycomb.infra.distro.cfgattrs +package io.fd.honeycomb.infra.distro.cfgattrs; -import com.google.inject.AbstractModule -import groovy.util.logging.Slf4j -import net.jmob.guice.conf.core.ConfigurationModule +import com.google.inject.AbstractModule; +import net.jmob.guice.conf.core.ConfigurationModule; /** * Load the configuration from json into HoneycombConfiguration and make it available. */ -@Slf4j -class CfgAttrsModule extends AbstractModule { +public class CfgAttrsModule extends AbstractModule { protected void configure() { - install(ConfigurationModule.create()) + install(ConfigurationModule.create()); // Inject non-dependency configuration - requestInjection(HoneycombConfiguration) + 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<String> restconfBindingAddress - @InjectConfig("restconf-port") - Optional<Integer> restconfPort - // HTTPS - @InjectConfig("restconf-https-enabled") - String restconfHttps - @InjectConfig("restconf-https-binding-address") - Optional<String> restconfHttpsBindingAddress - @InjectConfig("restconf-https-port") - Optional<Integer> 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<String> restconfKeystore = Optional.of("/honeycomb-keystore") - @InjectConfig("restconf-keystore-password") - Optional<String> keystorePassword - @InjectConfig("restconf-keystore-manager-password") - Optional<String> 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<String> restconfTruststore - @InjectConfig("restconf-truststore-password") - Optional<String> truststorePassword - - // This is the way for optional attributes with default values to work - @InjectConfig("restconf-websocket-port") - Optional<Integer> restconfWebsocketPort = Optional.of(7779) - - @InjectConfig("restconf-root-path") - Optional<String> restconfRootPath = Optional.of("/restconf") - @InjectConfig("restconf-pool-max-size") - Optional<Integer> restPoolMaxSize = Optional.of(10) - @InjectConfig("restconf-pool-min-size") - Optional<Integer> restPoolMinSize = Optional.of(1) - - @InjectConfig("restconf-acceptors-size") - Optional<Integer> acceptorsSize = Optional.of(1) - @InjectConfig("restconf-selectors-size") - Optional<Integer> selectorsSize = Optional.of(1) - @InjectConfig("restconf-https-acceptors-size") - Optional<Integer> httpsAcceptorsSize = Optional.of(1) - @InjectConfig("restconf-https-selectors-size") - Optional<Integer> 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<String> netconfTcpBindingAddress - @InjectConfig("netconf-tcp-binding-port") - Optional<Integer> netconfTcpBindingPort - - // HONEYCOMB_NETCONF SSH - @InjectConfig("netconf-ssh-enabled") - String netconfSsh - @InjectConfig("netconf-ssh-binding-address") - Optional<String> netconfSshBindingAddress - @InjectConfig("netconf-ssh-binding-port") - Optional<Integer> netconfSshBindingPort - - @InjectConfig("netconf-notification-stream-name") - Optional<String> 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<String> restconfBindingAddress; + @InjectConfig("restconf-port") + public Optional<Integer> restconfPort; + @InjectConfig("restconf-https-enabled") + public String restconfHttps; + @InjectConfig("restconf-https-binding-address") + public Optional<String> restconfHttpsBindingAddress; + @InjectConfig("restconf-https-port") + public Optional<Integer> 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<String> restconfKeystore = Optional.of("/honeycomb-keystore"); + @InjectConfig("restconf-keystore-password") + public Optional<String> keystorePassword; + @InjectConfig("restconf-keystore-manager-password") + public Optional<String> 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<String> restconfTruststore; + @InjectConfig("restconf-truststore-password") + public Optional<String> truststorePassword; + @InjectConfig("restconf-websocket-port") + public Optional<Integer> restconfWebsocketPort = Optional.of(7779); + @InjectConfig("restconf-root-path") + public Optional<String> restconfRootPath = Optional.of("/restconf"); + @InjectConfig("restconf-pool-max-size") + public Optional<Integer> restPoolMaxSize = Optional.of(10); + @InjectConfig("restconf-pool-min-size") + public Optional<Integer> restPoolMinSize = Optional.of(1); + @InjectConfig("restconf-acceptors-size") + public Optional<Integer> acceptorsSize = Optional.of(1); + @InjectConfig("restconf-selectors-size") + public Optional<Integer> selectorsSize = Optional.of(1); + @InjectConfig("restconf-https-acceptors-size") + public Optional<Integer> httpsAcceptorsSize = Optional.of(1); + @InjectConfig("restconf-https-selectors-size") + public Optional<Integer> 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<String> netconfTcpBindingAddress; + @InjectConfig("netconf-tcp-binding-port") + public Optional<Integer> netconfTcpBindingPort; + @InjectConfig("netconf-ssh-enabled") + public String netconfSsh; + @InjectConfig("netconf-ssh-binding-address") + public Optional<String> netconfSshBindingAddress; + @InjectConfig("netconf-ssh-binding-port") + public Optional<Integer> netconfSshBindingPort; + @InjectConfig("netconf-notification-stream-name") + public Optional<String> 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.java index e73f14932..e17355143 100644 --- 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.java @@ -14,26 +14,24 @@ * limitations under the License. */ -package io.fd.honeycomb.infra.distro.data +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 +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; -@Slf4j -@ToString -class BindingDataBrokerProvider extends ProviderTrait<DataBroker> { +public final class BindingDataBrokerProvider extends ProviderTrait<DataBroker> { @Inject - DOMDataBroker domDataBroker + private DOMDataBroker domDataBroker; @Inject - BindingToNormalizedNodeCodec mappingService + private BindingToNormalizedNodeCodec mappingService; @Override - def create() { new BindingDOMDataBrokerAdapter(domDataBroker, mappingService) } + 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.java index f8a1859e2..424393b8d 100644 --- 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.java @@ -14,21 +14,20 @@ * limitations under the License. */ -package io.fd.honeycomb.infra.distro.data +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 +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; -@Slf4j -@ToString -class DOMNotificationServiceProvider extends ProviderTrait<DOMNotificationRouter> { +public final class DOMNotificationServiceProvider extends ProviderTrait<DOMNotificationRouter> { @Inject - HoneycombConfiguration cfg + private HoneycombConfiguration cfg; - def create() { DOMNotificationRouter.create(cfg.notificationServiceQueueDepth) } + @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.java index 6d075ccc8..5b09f21f8 100644 --- 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.java @@ -14,27 +14,30 @@ * limitations under the License. */ -package io.fd.honeycomb.infra.distro.data +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 +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; -@Slf4j -@ToString -class DataStoreProvider extends ProviderTrait<InMemoryDOMDataStore> { +public final class DataStoreProvider extends ProviderTrait<InMemoryDOMDataStore> { @Inject - SchemaService schemaService + private SchemaService schemaService; + private String name; + private LogicalDatastoreType type; - String name - LogicalDatastoreType type + public DataStoreProvider(final String name, + final LogicalDatastoreType type) { + this.name = name; + this.type = type; + } @Override - def create() { InMemoryDOMDataStoreFactory.create(name, type, schemaService, false, null) } + 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.java index bf1f562ec..c5fcc050a 100644 --- 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.java @@ -14,44 +14,43 @@ * 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<DataTree> { +package io.fd.honeycomb.infra.distro.data; + +import com.google.inject.Inject; +import io.fd.honeycomb.infra.distro.ProviderTrait; +import io.fd.honeycomb.infra.distro.cfgattrs.HoneycombConfiguration; +import org.opendaylight.controller.sal.core.api.model.SchemaService; +import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTree; +import org.opendaylight.yangtools.yang.data.api.schema.tree.TipProducingDataTree; +import org.opendaylight.yangtools.yang.data.api.schema.tree.TreeType; +import org.opendaylight.yangtools.yang.data.impl.schema.tree.InMemoryDataTreeFactory; + +public abstract class DataTreeProvider extends ProviderTrait<DataTree> { @Inject - SchemaService schemaService + private SchemaService schemaService; @Inject - HoneycombConfiguration config + private HoneycombConfiguration config; - def create() { - def delegate = InMemoryDataTreeFactory.getInstance().create(getType()) - delegate.setSchemaContext(schemaService.getGlobalContext()) - delegate + public TipProducingDataTree create() { + TipProducingDataTree delegate = InMemoryDataTreeFactory.getInstance().create(getType()); + delegate.setSchemaContext(schemaService.getGlobalContext()); + return delegate; } - abstract TreeType getType() + public abstract TreeType getType(); + + public static class ConfigDataTreeProvider extends DataTreeProvider { + public TreeType getType() { + return TreeType.CONFIGURATION; + } - @Slf4j - @ToString - static class ConfigDataTreeProvider extends DataTreeProvider { - TreeType getType() { TreeType.CONFIGURATION } } - @Slf4j - @ToString - static class ContextDataTreeProvider extends DataTreeProvider { - TreeType getType() { TreeType.OPERATIONAL } + 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.java index dc620b445..eefa1c140 100644 --- 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.java @@ -14,28 +14,27 @@ * limitations under the License. */ -package io.fd.honeycomb.infra.distro.data +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 +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; -@Slf4j -@ToString -class HoneycombDOMBrokerProvider extends ProviderTrait<Broker> { +public final class HoneycombDOMBrokerProvider extends ProviderTrait<Broker> { @Inject - DOMDataBroker domDataBroker + private DOMDataBroker domDataBroker; @Inject - SchemaService schemaService + private SchemaService schemaService; @Inject - DOMNotificationRouter domNotificationService + private DOMNotificationRouter domNotificationService; - def create() { new NorthboundFacadeHoneycombDOMBroker(domDataBroker, schemaService, 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<DOMDataBroker> { - - @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<DOMDataBroker> { + + @Inject + private ModifiableDataManager modDataManager; + @Inject(optional = true) + private ReadableDataManager readDataManager; + + protected DataBroker create() { + return readDataManager != null + ? DataBroker.create(modDataManager, readDataManager) + : DataBroker.create(modDataManager); + } +} diff --git a/infra/minimal-distribution/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.java index b81a8d784..e25cb1569 100644 --- 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.java @@ -14,47 +14,48 @@ * limitations under the License. */ -package io.fd.honeycomb.infra.distro.data +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 +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; -@Slf4j -@ToString -class HoneycombNotificationManagerProvider extends ProviderTrait<NotificationCollector> { +public final class HoneycombNotificationManagerProvider extends ProviderTrait<NotificationCollector> { @Inject - DOMNotificationRouter notificationRouter + private DOMNotificationRouter notificationRouter; @Inject(optional = true) - Set<ManagedNotificationProducer> notificationProducers = [] + private Set<ManagedNotificationProducer> notificationProducers = new HashSet<>(); @Inject - BindingToNormalizedNodeCodec codec + private BindingToNormalizedNodeCodec codec; @Override - def create() { + protected HoneycombNotificationCollector create() { // Create the registry to keep track of what'OPERATIONAL registered - def notificationProducerRegistry = new NotificationProducerRegistry(notificationProducers as List); + NotificationProducerRegistry notificationProducerRegistry = + new NotificationProducerRegistry(Lists.newArrayList(notificationProducers)); // Create BA version of notification service (implementation is free from ODL) - def bindingDOMNotificationPublishServiceAdapter = + BindingDOMNotificationPublishServiceAdapter bindingDOMNotificationPublishServiceAdapter = new BindingDOMNotificationPublishServiceAdapter(codec, notificationRouter); // Create Collector on top of BA notification service and registry - def honeycombNotificationCollector = - new HoneycombNotificationCollector(bindingDOMNotificationPublishServiceAdapter, notificationProducerRegistry); + HoneycombNotificationCollector honeycombNotificationCollector = + new HoneycombNotificationCollector(bindingDOMNotificationPublishServiceAdapter, + notificationProducerRegistry); // Create tracker, responsible for starting and stopping registered notification producers whenever necessary - def notificationProducerTracker = + NotificationProducerTracker notificationProducerTracker = new NotificationProducerTracker(notificationProducerRegistry, honeycombNotificationCollector, notificationRouter); @@ -62,6 +63,6 @@ class HoneycombNotificationManagerProvider extends ProviderTrait<NotificationCol // DOMNotificationService is already provided by DOMBroker injected into RESTCONF, however RESTCONF // only supports data-change notification, nothing else. So currently its impossible. - honeycombNotificationCollector + 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.java index a04f1a81c..7db2f7856 100644 --- 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.java @@ -14,50 +14,48 @@ * 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<DOMDataBroker> { - - public static final String CONFIG = "config" - public static final String OPERATIONAL = "operational" +package io.fd.honeycomb.infra.distro.data; + +import com.google.inject.Inject; +import com.google.inject.name.Named; +import io.fd.honeycomb.infra.distro.ProviderTrait; +import java.util.LinkedHashMap; +import java.util.Map; +import java.util.concurrent.ExecutorService; +import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType; +import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitDeadlockException; +import org.opendaylight.controller.md.sal.dom.api.DOMDataBroker; +import org.opendaylight.controller.md.sal.dom.broker.impl.SerializedDOMDataBroker; +import org.opendaylight.controller.md.sal.dom.store.impl.InMemoryDOMDataStore; +import org.opendaylight.controller.sal.core.spi.data.DOMStore; +import org.opendaylight.yangtools.util.concurrent.DeadlockDetectingListeningExecutorService; +import org.opendaylight.yangtools.util.concurrent.SpecialExecutors; + +public final class InmemoryDOMDataBrokerProvider extends ProviderTrait<DOMDataBroker> { + + public static final String CONFIG = "config"; + public static final String OPERATIONAL = "operational"; @Inject @Named(InmemoryDOMDataBrokerProvider.CONFIG) - InMemoryDOMDataStore cfgDataStore - + private InMemoryDOMDataStore cfgDataStore; @Inject @Named(InmemoryDOMDataBrokerProvider.OPERATIONAL) - InMemoryDOMDataStore operDataStore + private InMemoryDOMDataStore operDataStore; @Override - def create() { + protected SerializedDOMDataBroker 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") + 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 - def map = [:] - map.put(LogicalDatastoreType.CONFIGURATION, cfgDataStore) - map.put(LogicalDatastoreType.OPERATIONAL, operDataStore) + Map<LogicalDatastoreType, DOMStore> map = new LinkedHashMap<>(); + map.put(LogicalDatastoreType.CONFIGURATION, cfgDataStore); + map.put(LogicalDatastoreType.OPERATIONAL, operDataStore); - new SerializedDOMDataBroker(map, - new DeadlockDetectingListeningExecutorService(commitExecutor, - TransactionCommitDeadlockException.DEADLOCK_EXCEPTION_SUPPLIER, - listenableFutureExecutor)) + 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.java index cd4d9c624..edd4faadb 100644 --- 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.java @@ -14,36 +14,36 @@ * limitations under the License. */ -package io.fd.honeycomb.infra.distro.data +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 +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; -@Slf4j -@ToString -class ModifiableDTDelegProvider extends ProviderTrait<ModifiableDataManager> { +public final class ModifiableDTDelegProvider extends ProviderTrait<ModifiableDataManager> { @Inject - BindingToNormalizedNodeCodec serializer + private BindingToNormalizedNodeCodec serializer; @Inject @Named(ConfigAndOperationalPipelineModule.HONEYCOMB_CONFIG) - DataTree dataTree + private DataTree dataTree; @Inject - ModifiableWriterRegistryBuilder registry + private ModifiableWriterRegistryBuilder registry; @Inject @Named(ContextPipelineModule.HONEYCOMB_CONTEXT) - DataBroker contextBroker + private DataBroker contextBroker; @Override - def create() { new ModifiableDataTreeDelegator(serializer, dataTree, registry.build(), contextBroker) } + 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<DataTree> { - - @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<DataTree> { + + @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.java index 3c94812ef..f3e8ce200 100644 --- 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.java @@ -14,26 +14,27 @@ * limitations under the License. */ -package io.fd.honeycomb.infra.distro.data.config +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 +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; -@Slf4j -@ToString -class WriterRegistryProvider extends ProviderTrait<ModifiableWriterRegistryBuilder> { +public final class WriterRegistryProvider extends ProviderTrait<ModifiableWriterRegistryBuilder> { @Inject(optional = true) - Set<WriterFactory> writerFactories = [] + private Set<WriterFactory> writerFactories = new HashSet<>(); - def create() { - def builder = new FlatWriterRegistryBuilder() - writerFactories.forEach { it.init(builder) } - builder + @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.java index eecd87e42..8e178203d 100644 --- 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.java @@ -14,23 +14,20 @@ * limitations under the License. */ -package io.fd.honeycomb.infra.distro.data.context +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 +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; -@Slf4j -@ToString -class HoneycombContextDOMDataBrokerProvider extends ProviderTrait<DOMDataBroker> { +public final class HoneycombContextDOMDataBrokerProvider extends ProviderTrait<DOMDataBroker> { @Inject - ModifiableDataManager modDataManager - - def create() { DataBroker.create(modDataManager) } + 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.java index 01d854b28..9da97a8e4 100644 --- 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.java @@ -14,23 +14,21 @@ * limitations under the License. */ -package io.fd.honeycomb.infra.distro.data.context +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 +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; -@Slf4j -@ToString -class ModifiableDTMgrProvider extends ProviderTrait<ModifiableDataManager> { +public final class ModifiableDTMgrProvider extends ProviderTrait<ModifiableDataManager> { @Inject - DataTree dataTree + private DataTree dataTree; @Override - def create() { new ModifiableDataTreeManager(dataTree) } + 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.java index c6afd92fc..cc1a8b1b8 100644 --- 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.java @@ -14,27 +14,24 @@ * limitations under the License. */ -package io.fd.honeycomb.infra.distro.data.context +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 +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; -@Slf4j -@ToString -class RealtimeMappingContextProvider extends ProviderTrait<MappingContext> { +public final class RealtimeMappingContextProvider extends ProviderTrait<MappingContext> { @Inject @Named(ContextPipelineModule.HONEYCOMB_CONTEXT) - DataBroker contextDataBroker + private DataBroker contextDataBroker; @Override - def create() { - new RealtimeMappingContext(contextDataBroker) + 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.java index 11eaf49a4..13e82e85f 100644 --- 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.java @@ -14,36 +14,35 @@ * limitations under the License. */ -package io.fd.honeycomb.infra.distro.data.oper +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 +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; -@Slf4j -@ToString -class ReadableDTDelegProvider extends ProviderTrait<ReadableDataManager> { +public final class ReadableDTDelegProvider extends ProviderTrait<ReadableDataManager> { @Inject - BindingToNormalizedNodeCodec serializer + private BindingToNormalizedNodeCodec serializer; @Inject - SchemaService schemaService + private SchemaService schemaService; @Inject - ModifiableReaderRegistryBuilder registry + private ModifiableReaderRegistryBuilder registry; @Inject @Named(ContextPipelineModule.HONEYCOMB_CONTEXT) - DataBroker contextBroker + private DataBroker contextBroker; - def create() { - new ReadableDataTreeDelegator(serializer, schemaService.getGlobalContext(), registry.build(), 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.java index 36f74d948..ef09e0e97 100644 --- 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.java @@ -14,26 +14,27 @@ * limitations under the License. */ -package io.fd.honeycomb.infra.distro.data.oper +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 +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; -@Slf4j -@ToString -class ReaderRegistryProvider extends ProviderTrait<ModifiableReaderRegistryBuilder> { +public final class ReaderRegistryProvider extends ProviderTrait<ModifiableReaderRegistryBuilder> { @Inject(optional = true) - Set<ReaderFactory> readerFactories = [] + private Set<ReaderFactory> readerFactories = new HashSet<>(); - def create() { - def builder = new CompositeReaderRegistryBuilder() - readerFactories.forEach { it.init(builder) } - builder + @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<DataTreeInitializer> pluginInitializers; + + InitializerRegistryAdapter(final DataTreeInitializer configInitializer, final DataTreeInitializer contextInitializer, + final Set<DataTreeInitializer> 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<InitializerRegistry> { - - @Inject - @Named(ContextPipelineModule.HONEYCOMB_CONTEXT) - DataTreeInitializer contextInitializer - @Inject - @Named(ConfigAndOperationalPipelineModule.HONEYCOMB_CONFIG) - DataTreeInitializer configInitializer - @Inject(optional = true) - Set<DataTreeInitializer> 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<InitializerRegistry> { + + @Inject + @Named(ContextPipelineModule.HONEYCOMB_CONTEXT) + private DataTreeInitializer contextInitializer; + @Inject + @Named(ConfigAndOperationalPipelineModule.HONEYCOMB_CONFIG) + private DataTreeInitializer configInitializer; + @Inject(optional = true) + private Set<DataTreeInitializer> 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.java index 4c132756e..8da9d75be 100644 --- 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.java @@ -14,35 +14,33 @@ * limitations under the License. */ -package io.fd.honeycomb.infra.distro.initializer +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 +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; -@Slf4j -@ToString -class ModifiableDTDelegInitProvider extends ProviderTrait<ModifiableDataManager> { +public final class ModifiableDTDelegInitProvider extends ProviderTrait<ModifiableDataManager> { @Inject - BindingToNormalizedNodeCodec serializer + private BindingToNormalizedNodeCodec serializer; @Inject @Named(ConfigAndOperationalPipelineModule.HONEYCOMB_CONFIG_NONPERSIST) - DataTree dataTree + private DataTree dataTree; @Inject @Named(ContextPipelineModule.HONEYCOMB_CONTEXT) - DataBroker contextBroker + private DataBroker contextBroker; @Override - def create() { new ModifiableDataTreeDelegator(serializer, dataTree, new NoopWriterRegistry(), contextBroker) } + 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<RestoringInitializer> { - - @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<RestoringInitializer> { + + @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<HoneycombNotification2Netconf> { - - @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<QName> 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<HoneycombNotification2NetconfProvider.HoneycombNotification2Netconf> { + + 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<SchemaPath> 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<QName> notificationQNames = + ListenerRegistration<DOMNotificationListener> 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<DOMNotificationListener> domNotifListenerReg; + private final NotificationPublisherRegistration netconfNotifReg; + + public HoneycombNotification2Netconf(final ListenerRegistration<DOMNotificationListener> domNotifListenerReg, + final NotificationPublisherRegistration netconfNotifReg) { + this.domNotifListenerReg = domNotifListenerReg; + this.netconfNotifReg = netconfNotifReg; + } + + public ListenerRegistration<DOMNotificationListener> 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.java index f1f49700e..3d06b8d27 100644 --- 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.java @@ -14,25 +14,23 @@ * limitations under the License. */ -package io.fd.honeycomb.infra.distro.netconf +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 +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; -@Slf4j -@ToString -class NetconfBindingBrokerProvider extends ProviderTrait<BindingAwareBroker> { +public final class NetconfBindingBrokerProvider extends ProviderTrait<BindingAwareBroker> { @Inject @Named(NetconfModule.HONEYCOMB_NETCONF) - DataBroker dataBroker + private DataBroker dataBroker; @Override - def create() { new FakeBindingAwareBroker(dataBroker) } + 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.java index dff5319b4..9ede54f72 100644 --- 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.java @@ -14,36 +14,32 @@ * limitations under the License. */ -package io.fd.honeycomb.infra.distro.netconf +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 +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; -@Slf4j -@ToString -class NetconfMdsalMapperProvider extends ProviderTrait<NetconfOperationServiceFactory> { +public final class NetconfMdsalMapperProvider extends ProviderTrait<NetconfOperationServiceFactory> { @Inject - SchemaService schemaService + private SchemaService schemaService; @Inject - NetconfOperationServiceFactoryListener aggregator + private NetconfOperationServiceFactoryListener aggregator; @Inject - ModuleInfoBackedContext moduleInfoBackedContext - + private ModuleInfoBackedContext moduleInfoBackedContext; @Inject - Broker domBroker + private Broker domBroker; - def create() { - def mdsalNetconfOperationServiceFactory = - new MdsalNetconfOperationServiceFactory(schemaService, moduleInfoBackedContext) + @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<NetconfOperationServiceFactory> { - - @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<NetconfOperationServiceFactory> { + + 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.java index 54a773a80..583b15055 100644 --- 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.java @@ -14,24 +14,24 @@ * limitations under the License. */ -package io.fd.honeycomb.infra.distro.netconf +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 +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; -@Slf4j -@ToString -class NetconfMonitoringReaderFactoryProvider extends ProviderTrait<ReaderFactory> { + +public final class NetconfMonitoringReaderFactoryProvider extends ProviderTrait<ReaderFactory> { @Inject @Named(NetconfModule.HONEYCOMB_NETCONF) - DataBroker netconfDataBroker + private DataBroker netconfDataBroker; - def create() { new NetconfMonitoringReaderFactory(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.java index cac2a13cc..9858003f5 100644 --- 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.java @@ -14,27 +14,24 @@ * limitations under the License. */ -package io.fd.honeycomb.infra.distro.netconf +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 +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; -@Slf4j -@ToString -class NetconfMonitoringServiceProvider extends ProviderTrait<NetconfMonitoringService> { + +public class NetconfMonitoringServiceProvider extends ProviderTrait<NetconfMonitoringService> { @Inject @Named(NetconfModule.HONEYCOMB_NETCONF_MAPPER_AGGR) - NetconfOperationServiceFactory aggregator + private NetconfOperationServiceFactory aggregator; @Override - def create() { - new NetconfMonitoringServiceImpl(aggregator) + 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<NetconfOperationServiceFactory> { - - 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<NetconfOperationServiceFactory> { + + private static final Logger LOG = LoggerFactory.getLogger(NetconfNotificationMapperProvider.class); + + public static final InstanceIdentifier<Capabilities> 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<DataChangeListener> 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<ReaderFactory> { - - @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<ReaderFactory> { + + @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.java index 917eceeac..cb45f5d6d 100644 --- 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.java @@ -14,24 +14,21 @@ * limitations under the License. */ -package io.fd.honeycomb.infra.distro.netconf +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 +import com.google.inject.AbstractModule; +import com.google.inject.Singleton; +import com.google.inject.multibindings.Multibinder; +import io.fd.honeycomb.translate.read.ReaderFactory; -@Slf4j -class NetconfReadersModule extends AbstractModule { +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 - Multibinder.newSetBinder(binder(), ReaderFactory.class).with { - addBinding().toProvider(NetconfMonitoringReaderFactoryProvider).in(Singleton) - addBinding().toProvider(NetconfNotificationsReaderFactoryProvider).in(Singleton) - } + final Multibinder<ReaderFactory> 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<NetconfServerDispatcher> { - - // 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<NetconfServerDispatcher> { + 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<NetconfSshServer> { - - @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<ChannelFuture>() { - - @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<NetconfSshServerProvider.NetconfSshServer> { + + 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<ChannelFuture> { + 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<NetconfTcpServer> { - - @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<ChannelFuture>() { - @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<NetconfTcpServerProvider.NetconfTcpServer> { + + 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<ChannelFuture> { + 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.java index 90948647d..e14952bba 100644 --- 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.java @@ -14,26 +14,22 @@ * limitations under the License. */ -package io.fd.honeycomb.infra.distro.netconf +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 +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; -@Slf4j -@ToString -class NettyThreadGroupProvider extends ProviderTrait<NioEventLoopGroup> { +public final class NettyThreadGroupProvider extends ProviderTrait<NioEventLoopGroup> { @Inject - HoneycombConfiguration cfgAttributes + private HoneycombConfiguration cfgAttributes; @Override - def create() { - new NioEventLoopGroup(cfgAttributes.netconfNettyThreads, - new ThreadFactoryBuilder().setNameFormat("netconf-netty-%d").build()) + 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.java index e889633ed..6ae960cea 100644 --- 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.java @@ -14,26 +14,22 @@ * limitations under the License. */ -package io.fd.honeycomb.infra.distro.netconf +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 +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; -@Slf4j -@ToString -class NettyTimerProvider extends ProviderTrait<Timer> { +public final class NettyTimerProvider extends ProviderTrait<Timer> { @Inject - HoneycombConfiguration cfgAttributes + private HoneycombConfiguration cfgAttributes; @Override - def create() { + protected HashedWheelTimer create() { // TODO expose configuration, - new HashedWheelTimer() + 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<ServerConnector> { - - @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<ServerConnector> { + + @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<ServerConnector> { - - @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<ServerConnector> { + + @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<Server> { - - 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<Server> { + + 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.java index 657e16986..16a33ecbb 100644 --- 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.java @@ -1,7 +1,7 @@ /* * Copyright (c) 2016 Cisco and/or its affiliates. * - * Licensed under the Apache License, Version 2.0 (the "License") + * 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: * @@ -14,32 +14,30 @@ * limitations under the License. */ -package io.fd.honeycomb.infra.distro.restconf +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 +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; -@Slf4j -@ToString -class RestconfProvider extends ProviderTrait<RestConnector> { - @Inject - HoneycombConfiguration cfg +public class RestconfProvider extends ProviderTrait<RestConnector> { + + @Inject + private HoneycombConfiguration cfg; @Inject - Broker domBroker + private Broker domBroker; - def create() { - def instance = new RestconfProviderImpl() - instance.setWebsocketPort(new PortNumber(cfg.restconfWebsocketPort.get())) - domBroker.registerProvider(instance) - instance + @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<ModuleInfoBackedContext> { - - @Inject(optional = true) - Set<YangModelBindingProvider> 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<ModuleInfoBackedContext> { + private static final Logger LOG = LoggerFactory.getLogger(ModuleInfoBackedCtxProvider.class); + + @Inject(optional = true) + private Set<YangModelBindingProvider> 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.java index 8bb9fc65f..0799a06f3 100644 --- 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.java @@ -14,22 +14,20 @@ * limitations under the License. */ -package io.fd.honeycomb.infra.distro.schema +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 +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; -@Slf4j -class SchemaModule extends AbstractModule { +public 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) + 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<SchemaService> { - - @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<SchemaContextListener> registerSchemaContextListener(final SchemaContextListener listener) { - listener.onGlobalContextUpdated schemaContext - return new ListenerRegistration<SchemaContextListener>() { - 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<SchemaService> { + + @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<SchemaContextListener> registerSchemaContextListener( + final SchemaContextListener listener) { + listener.onGlobalContextUpdated(schemaContext); + return new ListenerRegistration<SchemaContextListener>() { + 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<BindingToNormalizedNodeCodec> { - - @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<BindingToNormalizedNodeCodec> { + + @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. - * <p/> - * 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. + * <p/> + * 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<YangModelBindingProvider> binder = + Multibinder.newSetBinder(binder(), YangModelBindingProvider.class); + final List<URL> 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<? extends YangModelBindingProvider>) 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); + } + } +} |