From: Maros Marsalek Date: Fri, 8 Nov 2013 08:26:53 +0000 (+0100) Subject: Added config wrapper for netty's NioEventLoopGroup. X-Git-Tag: jenkins-controller-bulk-release-prepare-only-2-1~454^2 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=commitdiff_plain;h=ccd4ee7d84c841e50be600db469d6b3378d3fff3 Added config wrapper for netty's NioEventLoopGroup. NioEventLoopGroup should be reused by dispatchers based on netty e.g. netconf-impl's dispatcher. Change-Id: I7a0b985fd9ce57d4a0916d1843138da4236771ca Signed-off-by: Maros Marsalek --- diff --git a/opendaylight/config/netty-threadgroup-config/pom.xml b/opendaylight/config/netty-threadgroup-config/pom.xml new file mode 100644 index 0000000000..e1b8fb34da --- /dev/null +++ b/opendaylight/config/netty-threadgroup-config/pom.xml @@ -0,0 +1,118 @@ + + + + + + org.opendaylight.controller + config-subsystem + 0.2.2-SNAPSHOT + + + 4.0.0 + netty-threadgroup-config + Configuration Wrapper around netty's event group + bundle + ${project.artifactId} + + 3.0.4 + + + + + org.opendaylight.controller + config-api + + + org.opendaylight.controller + threadpool-config-api + ${project.version} + + + + org.slf4j + slf4j-api + + + + + com.google.guava + guava + + + + + junit + junit + test + + + org.opendaylight.controller + config-manager + test + test-jar + + + org.opendaylight.controller + config-manager + test + + + org.opendaylight.controller + config-util + test + + + org.opendaylight.bgpcep + mockito-configuration + test + + + + + + + + + org.opendaylight.yangtools + yang-maven-plugin + + + + + org.apache.felix + maven-bundle-plugin + 2.3.7 + true + + + ${project.groupId}.${project.artifactId} + + + + com.google.common.base, + io.netty.channel.nio, + org.opendaylight.controller.config.yang.threadpool, + io.netty.util.concurrent, + org.opendaylight.controller.config.api, + org.opendaylight.controller.config.api.annotations, + org.opendaylight.controller.config.api.runtime, + org.opendaylight.controller.config.spi, + org.slf4j, + org.osgi.framework + + + + + + + + + + ${project.artifactId} + NETTY-THREADGROUP-CONFIG Module site + ${basedir}/target/site/${project.artifactId} + + + + diff --git a/opendaylight/config/netty-threadgroup-config/src/main/java/org/opendaylight/controller/config/yang/netty/threadgroup/NettyThreadgroupModule.java b/opendaylight/config/netty-threadgroup-config/src/main/java/org/opendaylight/controller/config/yang/netty/threadgroup/NettyThreadgroupModule.java new file mode 100644 index 0000000000..fd6b216f53 --- /dev/null +++ b/opendaylight/config/netty-threadgroup-config/src/main/java/org/opendaylight/controller/config/yang/netty/threadgroup/NettyThreadgroupModule.java @@ -0,0 +1,57 @@ +/** +* Generated file + +* Generated from: yang module name: nsos-threadpool yang module local name: netty-threadgroup-fixed +* Generated by: org.opendaylight.controller.config.yangjmxgenerator.plugin.JMXGenerator +* Generated at: Fri Nov 08 08:31:45 CET 2013 +* +* Do not modify this file unless it is present under src/main directory +*/ +package org.opendaylight.controller.config.yang.netty.threadgroup; + +import com.google.common.base.Preconditions; +import io.netty.channel.nio.NioEventLoopGroup; + +/** +* +*/ +public final class NettyThreadgroupModule extends org.opendaylight.controller.config.yang.netty.threadgroup.AbstractNettyThreadgroupModule +{ + public NettyThreadgroupModule(org.opendaylight.controller.config.api.ModuleIdentifier name, org.opendaylight.controller.config.api.DependencyResolver dependencyResolver) { + super(name, dependencyResolver); + } + + public NettyThreadgroupModule(org.opendaylight.controller.config.api.ModuleIdentifier name, org.opendaylight.controller.config.api.DependencyResolver dependencyResolver, NettyThreadgroupModule oldModule, java.lang.AutoCloseable oldInstance) { + super(name, dependencyResolver, oldModule, oldInstance); + } + + @Override + public void validate(){ + if(getThreadCount()!=null) { + Preconditions.checkArgument(getThreadCount() > 0, "Thread count cannot be < 0"); + } + } + + @Override + public java.lang.AutoCloseable createInstance() { + return getThreadCount()==null ? new NioEventLoopGroupCloseable() : new NioEventLoopGroupCloseable(getThreadCount()); + } + + + private class NioEventLoopGroupCloseable extends NioEventLoopGroup implements AutoCloseable { + + + public NioEventLoopGroupCloseable(int threadCount) { + super(threadCount); + } + + public NioEventLoopGroupCloseable() { + super(); + } + + @Override + public void close() throws Exception { + shutdownGracefully(); + } + } +} diff --git a/opendaylight/config/netty-threadgroup-config/src/main/java/org/opendaylight/controller/config/yang/netty/threadgroup/NettyThreadgroupModuleFactory.java b/opendaylight/config/netty-threadgroup-config/src/main/java/org/opendaylight/controller/config/yang/netty/threadgroup/NettyThreadgroupModuleFactory.java new file mode 100644 index 0000000000..1dca38182d --- /dev/null +++ b/opendaylight/config/netty-threadgroup-config/src/main/java/org/opendaylight/controller/config/yang/netty/threadgroup/NettyThreadgroupModuleFactory.java @@ -0,0 +1,19 @@ +/** +* Generated file + +* Generated from: yang module name: nsos-threadpool yang module local name: netty-threadgroup-fixed +* Generated by: org.opendaylight.controller.config.yangjmxgenerator.plugin.JMXGenerator +* Generated at: Fri Nov 08 08:31:45 CET 2013 +* +* Do not modify this file unless it is present under src/main directory +*/ +package org.opendaylight.controller.config.yang.netty.threadgroup; + +/** +* +*/ +public class NettyThreadgroupModuleFactory extends org.opendaylight.controller.config.yang.netty.threadgroup.AbstractNettyThreadgroupModuleFactory +{ + + +} diff --git a/opendaylight/config/netty-threadgroup-config/src/main/yang/nsos-netty-threadgroup.yang b/opendaylight/config/netty-threadgroup-config/src/main/yang/nsos-netty-threadgroup.yang new file mode 100644 index 0000000000..f13cf391bf --- /dev/null +++ b/opendaylight/config/netty-threadgroup-config/src/main/yang/nsos-netty-threadgroup.yang @@ -0,0 +1,53 @@ +// vi: set smarttab et sw=4 tabstop=4: +module nsos-threadpool { + yang-version 1; + namespace "urn:opendaylight:params:xml:ns:yang:controller:netty:threadgroup"; + prefix "netty-t"; + + import config { prefix config; revision-date 2013-04-05; } + import threadpool { prefix th; revision-date 2013-04-09; } + + organization "Cisco Systems, Inc."; + + contact "Robert Varga "; + + description + "This module contains the base YANG definitions for NS-OS + thread-related services. + + Copyright (c)2013 Cisco Systems, Inc. All rights reserved."; + + revision "2013-11-07" { + description + "Initial revision"; + } + + identity netty-threadgroup-fixed { + base config:module-type; + config:provided-service th:netty-threadgroup; + config:java-name-prefix NettyThreadgroup; + } + + augment "/config:modules/config:module/config:configuration" { + case netty-threadgroup-fixed { + when "/config:modules/config:module/config:type = 'netty-threadgroup-fixed'"; + + leaf thread-count { + type uint16; + + description "Number of threads to be used by NioEventLoopGroup. This attribute is optional and default value will be 2* Number of CPUs"; + } + + // TODO add optional thread factory dependency + + } + } + + augment "/config:modules/config:module/config:state" { + case netty-threadgroup-fixed { + when "/config:modules/config:module/config:type = 'netty-threadgroup-fixed'"; + } + } + + +} diff --git a/opendaylight/config/netty-threadgroup-config/src/test/java/org/opendaylight/controller/config/yang/netty/threadgroup/NettyThreadgroupModuleTest.java b/opendaylight/config/netty-threadgroup-config/src/test/java/org/opendaylight/controller/config/yang/netty/threadgroup/NettyThreadgroupModuleTest.java new file mode 100644 index 0000000000..590bd9185e --- /dev/null +++ b/opendaylight/config/netty-threadgroup-config/src/test/java/org/opendaylight/controller/config/yang/netty/threadgroup/NettyThreadgroupModuleTest.java @@ -0,0 +1,91 @@ +/* + * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.controller.config.yang.netty.threadgroup; + +import org.junit.Before; +import org.junit.Test; +import org.opendaylight.controller.config.api.ConflictingVersionException; +import org.opendaylight.controller.config.api.ValidationException; +import org.opendaylight.controller.config.api.jmx.CommitStatus; +import org.opendaylight.controller.config.manager.impl.AbstractConfigTest; +import org.opendaylight.controller.config.manager.impl.factoriesresolver.HardcodedModuleFactoriesResolver; +import org.opendaylight.controller.config.util.ConfigTransactionJMXClient; + +import javax.management.InstanceAlreadyExistsException; +import javax.management.InstanceNotFoundException; +import javax.management.ObjectName; + +public class NettyThreadgroupModuleTest extends AbstractConfigTest { + + private NettyThreadgroupModuleFactory factory; + private final String instanceName = "netty1"; + + @Before + public void setUp() { + factory = new NettyThreadgroupModuleFactory(); + super.initConfigTransactionManagerImpl(new HardcodedModuleFactoriesResolver(factory)); + } + + @Test + public void testCreateBean() throws InstanceAlreadyExistsException, ValidationException, ConflictingVersionException { + ConfigTransactionJMXClient transaction = configRegistryClient.createTransaction(); + + createInstance(transaction, instanceName, 2); + createInstance(transaction, instanceName + 2, null); + transaction.validateConfig(); + CommitStatus status = transaction.commit(); + + assertBeanCount(2, factory.getImplementationName()); + assertStatus(status, 2, 0, 0); + } + + @Test + public void testReusingOldInstance() throws InstanceAlreadyExistsException, ConflictingVersionException, ValidationException { + + ConfigTransactionJMXClient transaction = configRegistryClient.createTransaction(); + createInstance(transaction, instanceName, null); + + transaction.commit(); + + transaction = configRegistryClient.createTransaction(); + assertBeanCount(1, factory.getImplementationName()); + CommitStatus status = transaction.commit(); + + assertBeanCount(1, factory.getImplementationName()); + assertStatus(status, 0, 0, 1); + } + + @Test + public void testReconfigure() throws InstanceAlreadyExistsException, ConflictingVersionException, + ValidationException, InstanceNotFoundException { + + ConfigTransactionJMXClient transaction = configRegistryClient.createTransaction(); + createInstance(transaction, instanceName, null); + + transaction.commit(); + + transaction = configRegistryClient.createTransaction(); + assertBeanCount(1, factory.getImplementationName()); + NettyThreadgroupModuleMXBean mxBean = transaction.newMBeanProxy( + transaction.lookupConfigBean(AbstractNettyThreadgroupModuleFactory.NAME, instanceName), + NettyThreadgroupModuleMXBean.class); + mxBean.setThreadCount(1); + CommitStatus status = transaction.commit(); + + assertBeanCount(1, factory.getImplementationName()); + assertStatus(status, 0, 1, 0); + } + + private ObjectName createInstance(ConfigTransactionJMXClient transaction, String instanceName, Integer threads) + throws InstanceAlreadyExistsException { + ObjectName nameCreated = transaction.createModule(factory.getImplementationName(), instanceName); + NettyThreadgroupModuleMXBean mxBean = transaction.newMBeanProxy(nameCreated, NettyThreadgroupModuleMXBean.class); + mxBean.setThreadCount(threads); + return nameCreated; + } +} diff --git a/opendaylight/config/pom.xml b/opendaylight/config/pom.xml index 9db5b76988..6cf23e8868 100755 --- a/opendaylight/config/pom.xml +++ b/opendaylight/config/pom.xml @@ -31,6 +31,7 @@ logback-config threadpool-config-api threadpool-config-impl + netty-threadgroup-config diff --git a/opendaylight/config/threadpool-config-api/pom.xml b/opendaylight/config/threadpool-config-api/pom.xml index b991b69213..1f8f1ea87e 100644 --- a/opendaylight/config/threadpool-config-api/pom.xml +++ b/opendaylight/config/threadpool-config-api/pom.xml @@ -13,16 +13,20 @@ 3.0.4 - - - org.opendaylight.controller - config-api - - - com.google.guava - guava - - + + + org.opendaylight.controller + config-api + + + com.google.guava + guava + + + io.netty + netty-transport + + @@ -34,6 +38,7 @@ org.opendaylight.controller.config.api.*, com.google.common.eventbus, + io.netty.channel, org.opendaylight.controller.config.threadpool, diff --git a/opendaylight/config/threadpool-config-api/src/main/yang/threadpool.yang b/opendaylight/config/threadpool-config-api/src/main/yang/threadpool.yang index 14a20fdebc..5cc17e52ff 100644 --- a/opendaylight/config/threadpool-config-api/src/main/yang/threadpool.yang +++ b/opendaylight/config/threadpool-config-api/src/main/yang/threadpool.yang @@ -15,7 +15,7 @@ module threadpool { thread-related services. Copyright (c)2013 Cisco Systems, Inc. All rights reserved.; - + This program and the accompanying materials are made available under the terms of the Eclipse Public License v1.0 which accompanies this distribution, and is available at @@ -74,4 +74,14 @@ module threadpool { config:java-class "org.opendaylight.controller.config.threadpool.ScheduledThreadPool"; } + + identity netty-threadgroup { + description + "Configuration wrapper around netty's threadgroup"; + + base "config:service-type"; + config:java-class "io.netty.channel.EventLoopGroup"; + } + + }