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/io/fd/honeycomb/infra/distro/schema | |
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/io/fd/honeycomb/infra/distro/schema')
9 files changed, 268 insertions, 236 deletions
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); + } + } +} |