-changed reconnect-strategy service and modules to reconnect-strategy-factory - configuration of ReconnectStrategyFactory.
Change-Id: I863cf4f7cf559504d05e14293af9d2c5e9373ca7
Signed-off-by: Milos Fabian <milfabia@cisco.com>
<maven>3.0.4</maven>
</prerequisites>
+ <properties>
+ <jmxGeneratorPath>${project.build.directory}/generated-sources/config</jmxGeneratorPath>
+ <salGeneratorPath>${project.build.directory}/generated-sources/sal</salGeneratorPath>
+ </properties>
+
<dependencies>
<dependency>
<groupId>io.netty</groupId>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>
+ <dependency>
+ <groupId>org.opendaylight.controller</groupId>
+ <artifactId>config-api</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.opendaylight.controller</groupId>
+ <artifactId>netty-config-api</artifactId>
+ </dependency>
<!-- Testing dependencies -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</dependency>
+ <dependency>
+ <groupId>org.opendaylight.controller</groupId>
+ <artifactId>config-manager</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.opendaylight.controller</groupId>
+ <artifactId>config-manager</artifactId>
+ <version>${config.version}</version>
+ <scope>test</scope>
+ <type>test-jar</type>
+ </dependency>
+ <dependency>
+ <groupId>org.opendaylight.controller</groupId>
+ <artifactId>config-util</artifactId>
+ <version>${config.version}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.opendaylight.controller</groupId>
+ <artifactId>netty-event-executor-config</artifactId>
+ <scope>test</scope>
+ </dependency>
</dependencies>
<build>
</execution>
</executions>
</plugin>
+ <plugin>
+ <groupId>org.opendaylight.yangtools</groupId>
+ <artifactId>yang-maven-plugin</artifactId>
+ <executions>
+ <execution>
+ <goals>
+ <goal>generate-sources</goal>
+ </goals>
+ <configuration>
+ <codeGenerators>
+ <generator>
+ <codeGeneratorClass>
+ org.opendaylight.controller.config.yangjmxgenerator.plugin.JMXGenerator
+ </codeGeneratorClass>
+ <outputBaseDir>${jmxGeneratorPath}</outputBaseDir>
+ <additionalConfiguration>
+ <namespaceToPackage1>
+ urn:opendaylight:params:xml:ns:yang:controller==org.opendaylight.controller.config.yang
+ </namespaceToPackage1>
+ </additionalConfiguration>
+ </generator>
+ <generator>
+ <codeGeneratorClass>
+ org.opendaylight.yangtools.maven.sal.api.gen.plugin.CodeGeneratorImpl
+ </codeGeneratorClass>
+ <outputBaseDir>
+ ${salGeneratorPath}
+ </outputBaseDir>
+ </generator>
+ </codeGenerators>
+ <inspectDependencies>true</inspectDependencies>
+ </configuration>
+ </execution>
+ </executions>
+ <dependencies>
+ <dependency>
+ <groupId>org.opendaylight.controller</groupId>
+ <artifactId>yang-jmx-generator-plugin</artifactId>
+ <version>${config.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.opendaylight.yangtools</groupId>
+ <artifactId>maven-sal-api-gen-plugin</artifactId>
+ <version>${yangtools.version}</version>
+ </dependency>
+ </dependencies>
+ </plugin>
+ <plugin>
+ <groupId>org.codehaus.mojo</groupId>
+ <artifactId>build-helper-maven-plugin</artifactId>
+ <executions>
+ <execution>
+ <id>add-source</id>
+ <phase>generate-sources</phase>
+ <goals>
+ <goal>add-source</goal>
+ </goals>
+ <configuration>
+ <sources>
+ <source>${jmxGeneratorPath}</source>
+ <source>${salGeneratorPath}</source>
+ </sources>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
</plugins>
</build>
</project>
--- /dev/null
+/*
+ * Copyright (c) 2014 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.protocol.framework;
+
+import io.netty.util.concurrent.EventExecutor;
+
+import org.opendaylight.controller.config.api.JmxAttributeValidationException;
+import org.opendaylight.protocol.framework.NeverReconnectStrategy;
+import org.opendaylight.protocol.framework.ReconnectStrategy;
+import org.opendaylight.protocol.framework.ReconnectStrategyFactory;
+
+/**
+*
+*/
+public final class NeverReconnectStrategyFactoryModule extends org.opendaylight.controller.config.yang.protocol.framework.AbstractNeverReconnectStrategyFactoryModule
+ {
+
+ public NeverReconnectStrategyFactoryModule(org.opendaylight.controller.config.api.ModuleIdentifier identifier, org.opendaylight.controller.config.api.DependencyResolver dependencyResolver) {
+ super(identifier, dependencyResolver);
+ }
+
+ public NeverReconnectStrategyFactoryModule(org.opendaylight.controller.config.api.ModuleIdentifier identifier, org.opendaylight.controller.config.api.DependencyResolver dependencyResolver,
+ NeverReconnectStrategyFactoryModule oldModule, java.lang.AutoCloseable oldInstance) {
+
+ super(identifier, dependencyResolver, oldModule, oldInstance);
+ }
+
+ @Override
+ protected void customValidation(){
+ JmxAttributeValidationException.checkNotNull(getTimeout(), "value is not set.", timeoutJmxAttribute);
+ JmxAttributeValidationException.checkCondition(getTimeout() >= 0, "value " + getTimeout() + " is less than 0",
+ timeoutJmxAttribute);
+ }
+
+ @Override
+ public java.lang.AutoCloseable createInstance() {
+ return new NeverReconnectStrategyFactoryCloseable(getExecutorDependency(), getTimeout());
+ }
+
+ private static final class NeverReconnectStrategyFactoryCloseable implements ReconnectStrategyFactory, AutoCloseable {
+
+ private final EventExecutor executor;
+ private final int timeout;
+
+ public NeverReconnectStrategyFactoryCloseable(final EventExecutor executor, final int timeout) {
+ this.executor = executor;
+ this.timeout = timeout;
+ }
+
+ @Override
+ public void close() throws Exception {
+ // no-op
+ }
+
+ @Override
+ public ReconnectStrategy createReconnectStrategy() {
+ return new NeverReconnectStrategy(this.executor, this.timeout);
+ }
+
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2014 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.protocol.framework;
+
+/**
+*
+*/
+public class NeverReconnectStrategyFactoryModuleFactory extends org.opendaylight.controller.config.yang.protocol.framework.AbstractNeverReconnectStrategyFactoryModuleFactory
+{
+
+
+}
--- /dev/null
+/*
+ * Copyright (c) 2014 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.protocol.framework;
+
+import io.netty.util.concurrent.EventExecutor;
+
+import org.opendaylight.controller.config.api.JmxAttributeValidationException;
+import org.opendaylight.protocol.framework.ReconnectImmediatelyStrategy;
+import org.opendaylight.protocol.framework.ReconnectStrategy;
+import org.opendaylight.protocol.framework.ReconnectStrategyFactory;
+
+/**
+*
+*/
+public final class ReconnectImmediatelyStrategyFactoryModule extends org.opendaylight.controller.config.yang.protocol.framework.AbstractReconnectImmediatelyStrategyFactoryModule
+ {
+
+ public ReconnectImmediatelyStrategyFactoryModule(org.opendaylight.controller.config.api.ModuleIdentifier identifier, org.opendaylight.controller.config.api.DependencyResolver dependencyResolver) {
+ super(identifier, dependencyResolver);
+ }
+
+ public ReconnectImmediatelyStrategyFactoryModule(org.opendaylight.controller.config.api.ModuleIdentifier identifier, org.opendaylight.controller.config.api.DependencyResolver dependencyResolver,
+ ReconnectImmediatelyStrategyFactoryModule oldModule, java.lang.AutoCloseable oldInstance) {
+
+ super(identifier, dependencyResolver, oldModule, oldInstance);
+ }
+
+ @Override
+ protected void customValidation(){
+ JmxAttributeValidationException.checkNotNull(getTimeout(), "value is not set.", timeoutJmxAttribute);
+ JmxAttributeValidationException.checkCondition(getTimeout() >= 0, "value " + getTimeout() + " is less than 0",
+ timeoutJmxAttribute);
+ }
+
+ @Override
+ public java.lang.AutoCloseable createInstance() {
+ return new ReconnectImmediatelyStrategyFactoryCloseable(getExecutorDependency(), getTimeout());
+ }
+
+ private static final class ReconnectImmediatelyStrategyFactoryCloseable implements ReconnectStrategyFactory, AutoCloseable {
+
+ private final EventExecutor executor;
+ private final int timeout;
+
+ public ReconnectImmediatelyStrategyFactoryCloseable(final EventExecutor executor, final int timeout) {
+ this.executor = executor;
+ this.timeout = timeout;
+ }
+
+ @Override
+ public void close() throws Exception {
+ // no-op
+ }
+
+ @Override
+ public ReconnectStrategy createReconnectStrategy() {
+ return new ReconnectImmediatelyStrategy(this.executor, this.timeout);
+ }
+
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2014 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.protocol.framework;
+
+/**
+*
+*/
+public class ReconnectImmediatelyStrategyFactoryModuleFactory extends org.opendaylight.controller.config.yang.protocol.framework.AbstractReconnectImmediatelyStrategyFactoryModuleFactory
+{
+
+
+}
--- /dev/null
+/*
+ * Copyright (c) 2014 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.protocol.framework;
+
+import io.netty.util.concurrent.EventExecutor;
+
+import org.opendaylight.controller.config.api.JmxAttributeValidationException;
+import org.opendaylight.protocol.framework.ReconnectStrategy;
+import org.opendaylight.protocol.framework.ReconnectStrategyFactory;
+import org.opendaylight.protocol.framework.TimedReconnectStrategy;
+
+import com.google.common.base.Preconditions;
+
+/**
+*
+*/
+public final class TimedReconnectStrategyFactoryModule extends org.opendaylight.controller.config.yang.protocol.framework.AbstractTimedReconnectStrategyFactoryModule
+ {
+
+ public TimedReconnectStrategyFactoryModule(org.opendaylight.controller.config.api.ModuleIdentifier identifier, org.opendaylight.controller.config.api.DependencyResolver dependencyResolver) {
+ super(identifier, dependencyResolver);
+ }
+
+ public TimedReconnectStrategyFactoryModule(org.opendaylight.controller.config.api.ModuleIdentifier identifier, org.opendaylight.controller.config.api.DependencyResolver dependencyResolver,
+ TimedReconnectStrategyFactoryModule oldModule, java.lang.AutoCloseable oldInstance) {
+
+ super(identifier, dependencyResolver, oldModule, oldInstance);
+ }
+
+ @Override
+ protected void customValidation(){
+ JmxAttributeValidationException.checkNotNull(getSleepFactor(), "value is not set.", sleepFactorJmxAttribute);
+ JmxAttributeValidationException.checkCondition(getSleepFactor().doubleValue() >= 1, "value " + getSleepFactor()
+ + " is less than 1", sleepFactorJmxAttribute);
+
+ JmxAttributeValidationException.checkNotNull(getConnectTime(), "value is not set.", connectTimeJmxAttribute);
+ JmxAttributeValidationException.checkCondition(getConnectTime() >= 0, "value " + getConnectTime()
+ + " is less than 0", connectTimeJmxAttribute);
+
+ JmxAttributeValidationException.checkNotNull(getMinSleep(), "value is not set.", minSleepJmxAttribute);
+ JmxAttributeValidationException.checkCondition(getMaxSleep() == null || getMinSleep() <= getMaxSleep(),
+ "value " + getMinSleep() + " is greter than MaxSleep " + getMaxSleep(), minSleepJmxAttribute);
+ }
+
+ @Override
+ public java.lang.AutoCloseable createInstance() {
+ return new TimedReconnectStrategyFactoryCloseable(getExecutorDependency(),
+ getConnectTime(), getMinSleep(), getSleepFactor().doubleValue(), getMaxSleep(), getMaxAttempts(),
+ getDeadline());
+ }
+
+ private static final class TimedReconnectStrategyFactoryCloseable implements ReconnectStrategyFactory, AutoCloseable {
+
+ private final EventExecutor executor;
+ private final Long deadline, maxAttempts, maxSleep;
+ private final double sleepFactor;
+ private final int connectTime;
+ private final long minSleep;
+
+ public TimedReconnectStrategyFactoryCloseable(final EventExecutor executor, final int connectTime, final long minSleep, final double sleepFactor,
+ final Long maxSleep, final Long maxAttempts, final Long deadline) {
+ Preconditions.checkArgument(maxSleep == null || minSleep <= maxSleep);
+ Preconditions.checkArgument(sleepFactor >= 1);
+ Preconditions.checkArgument(connectTime >= 0);
+ this.executor = Preconditions.checkNotNull(executor);
+ this.deadline = deadline;
+ this.maxAttempts = maxAttempts;
+ this.minSleep = minSleep;
+ this.maxSleep = maxSleep;
+ this.sleepFactor = sleepFactor;
+ this.connectTime = connectTime;
+ }
+
+ @Override
+ public void close() throws Exception {
+ // no-op
+ }
+
+ @Override
+ public ReconnectStrategy createReconnectStrategy() {
+ return new TimedReconnectStrategy(this.executor,
+ this.connectTime, this.minSleep, this.sleepFactor, this.maxSleep, this.maxAttempts,
+ this.deadline);
+ }
+
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2014 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.protocol.framework;
+
+/**
+*
+*/
+public class TimedReconnectStrategyFactoryModuleFactory extends org.opendaylight.controller.config.yang.protocol.framework.AbstractTimedReconnectStrategyFactoryModuleFactory
+{
+
+
+}
--- /dev/null
+// vi: set smarttab et sw=4 tabstop=4:
+module protocol-framework {
+ yang-version 1;
+ namespace "urn:opendaylight:params:xml:ns:yang:controller:protocol:framework";
+ prefix "pf";
+
+ import config { prefix config; revision-date 2013-04-05; }
+ import netty { prefix netty; revision-date 2013-11-19; }
+
+ organization "Cisco Systems, Inc.";
+
+ contact "Milos Fabian <milfabia@cisco.com>";
+
+ description
+ "This module contains the base YANG definitions for
+ protocol framework.
+
+ 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
+ http://www.eclipse.org/legal/epl-v10.html";
+
+ revision "2014-03-13" {
+ description
+ "Changed reconnect-strategy to reconnect-strategy-factory - represents ReconnectStrategyFactory.
+ reconnect-strategy-factory modules provides reconnect-strategy-factory service.";
+ }
+
+ revision "2013-11-09" {
+ description
+ "Initial revision";
+ }
+
+ identity reconnect-strategy-factory {
+ description
+ "Service representing a reconnect strategy factory.";
+
+ base "config:service-type";
+ config:java-class "org.opendaylight.protocol.framework.ReconnectStrategyFactory";
+ }
+
+ identity never-reconnect-strategy-factory {
+ base config:module-type;
+ config:provided-service reconnect-strategy-factory;
+ config:java-name-prefix NeverReconnectStrategyFactory;
+ }
+
+ augment "/config:modules/config:module/config:configuration" {
+ case never-reconnect-strategy-factory {
+ when "/config:modules/config:module/config:type = 'never-reconnect-strategy-factory'";
+
+ leaf timeout {
+ mandatory true;
+ type int32;
+ }
+
+ container executor {
+ uses config:service-ref {
+ refine type {
+ mandatory true;
+ config:required-identity netty:netty-event-executor;
+ }
+ }
+ }
+ }
+ }
+
+ identity reconnect-immediately-strategy-factory {
+ base config:module-type;
+ config:provided-service reconnect-strategy-factory;
+ config:java-name-prefix ReconnectImmediatelyStrategyFactory;
+ }
+
+ augment "/config:modules/config:module/config:configuration" {
+ case reconnect-immediately-strategy-factory {
+ when "/config:modules/config:module/config:type = 'reconnect-immediately-strategy-factory'";
+
+ leaf timeout {
+ mandatory true;
+ type int32;
+ }
+
+ container executor {
+ uses config:service-ref {
+ refine type {
+ mandatory true;
+ config:required-identity netty:netty-event-executor;
+ }
+ }
+ }
+ }
+ }
+
+ identity timed-reconnect-strategy-factory {
+ base config:module-type;
+ config:provided-service reconnect-strategy-factory;
+ config:java-name-prefix TimedReconnectStrategyFactory;
+ }
+
+ augment "/config:modules/config:module/config:configuration" {
+ case timed-reconnect-strategy-factory {
+ when "/config:modules/config:module/config:type = 'timed-reconnect-strategy-factory'";
+
+ leaf deadline {
+ type int64;
+ units "epoch nanoseconds";
+ }
+
+ leaf max-attempts {
+ mandatory true;
+ type int64;
+ }
+
+ leaf max-sleep {
+ mandatory true;
+ type int64;
+ units "milliseconds";
+ }
+
+ leaf min-sleep {
+ mandatory true;
+ type int64;
+ units "milliseconds";
+ }
+
+ leaf sleep-factor {
+ mandatory true;
+ type decimal64 {
+ fraction-digits 2;
+ }
+ }
+
+ leaf connect-time {
+ mandatory true;
+ type int32;
+ units "milliseconds";
+ }
+
+ container executor {
+ uses config:service-ref {
+ refine type {
+ mandatory true;
+ config:required-identity netty:netty-event-executor;
+ }
+ }
+ }
+ }
+ }
+}
\ No newline at end of file
--- /dev/null
+/*
+ * 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.protocol.framework;
+
+import javax.management.InstanceAlreadyExistsException;
+import javax.management.InstanceNotFoundException;
+import javax.management.ObjectName;
+
+import org.opendaylight.controller.config.util.ConfigTransactionJMXClient;
+import org.opendaylight.controller.config.yang.netty.eventexecutor.GlobalEventExecutorModuleFactory;
+
+final class GlobalEventExecutorUtil {
+
+ private GlobalEventExecutorUtil() {
+ throw new UnsupportedOperationException();
+ }
+
+ public static ObjectName create(final ConfigTransactionJMXClient transaction) throws InstanceAlreadyExistsException {
+ try {
+ return transaction.lookupConfigBean(GlobalEventExecutorModuleFactory.NAME,
+ GlobalEventExecutorModuleFactory.SINGLETON_NAME);
+ } catch (InstanceNotFoundException e) {
+ try {
+ return transaction.createModule(GlobalEventExecutorModuleFactory.NAME,
+ GlobalEventExecutorModuleFactory.SINGLETON_NAME);
+ } catch (InstanceAlreadyExistsException e1) {
+ throw new IllegalStateException(e1);
+ }
+ }
+ }
+
+}
--- /dev/null
+/*
+ * 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.protocol.framework;
+
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import javax.management.InstanceAlreadyExistsException;
+import javax.management.ObjectName;
+
+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 org.opendaylight.controller.config.yang.netty.eventexecutor.GlobalEventExecutorModuleFactory;
+
+public class NeverReconnectStrategyModuleTest extends AbstractConfigTest {
+
+ private static final String INSTANCE_NAME = "never-reconect-strategy-factory-impl";
+ private static final String FACTORY_NAME = NeverReconnectStrategyFactoryModuleFactory.NAME;
+
+ @Before
+ public void setUp() throws Exception {
+ super.initConfigTransactionManagerImpl(new HardcodedModuleFactoriesResolver(
+ new NeverReconnectStrategyFactoryModuleFactory(), new GlobalEventExecutorModuleFactory()));
+ }
+
+ @Test
+ public void testValidationExceptionTimeoutNotSet() throws Exception {
+ try {
+ createInstance(null);
+ fail();
+ } catch (ValidationException e) {
+ assertTrue(e.getMessage().contains("Timeout value is not set."));
+ }
+ }
+
+ @Test
+ public void testValidationExceptionTimeoutMinValue() throws Exception {
+ try {
+ createInstance(-1);
+ fail();
+ } catch (ValidationException e) {
+ assertTrue(e.getMessage().contains("is less than 0"));
+ }
+ }
+
+ @Test
+ public void testCreateBean() throws Exception {
+ final CommitStatus status = createInstance();
+ assertBeanCount(1, FACTORY_NAME);
+ assertStatus(status, 2, 0, 0);
+ }
+
+ @Test
+ public void testReusingOldInstance() throws Exception {
+ createInstance();
+ final ConfigTransactionJMXClient transaction = configRegistryClient.createTransaction();
+ assertBeanCount(1, FACTORY_NAME);
+ final CommitStatus status = transaction.commit();
+ assertBeanCount(1, FACTORY_NAME);
+ assertStatus(status, 0, 0, 2);
+ }
+
+ @Test
+ public void testReconfigure() throws Exception {
+ createInstance();
+ final ConfigTransactionJMXClient transaction = configRegistryClient.createTransaction();
+ assertBeanCount(1, FACTORY_NAME);
+ final NeverReconnectStrategyFactoryModuleMXBean mxBean = transaction.newMBeanProxy(
+ transaction.lookupConfigBean(FACTORY_NAME, INSTANCE_NAME), NeverReconnectStrategyFactoryModuleMXBean.class);
+ mxBean.setTimeout(200);
+ final CommitStatus status = transaction.commit();
+ assertBeanCount(1, FACTORY_NAME);
+ assertStatus(status, 0, 1, 1);
+ }
+
+ private CommitStatus createInstance() throws Exception {
+ return createInstance(500);
+ }
+
+ private CommitStatus createInstance(final Integer timeout) throws InstanceAlreadyExistsException,
+ ConflictingVersionException, ValidationException {
+ final ConfigTransactionJMXClient transaction = this.configRegistryClient.createTransaction();
+ createInstance(transaction, timeout);
+ return transaction.commit();
+ }
+
+ private static ObjectName createInstance(final ConfigTransactionJMXClient transaction, final Integer timeout)
+ throws InstanceAlreadyExistsException {
+ final ObjectName nameCreated = transaction.createModule(FACTORY_NAME, INSTANCE_NAME);
+ final NeverReconnectStrategyFactoryModuleMXBean mxBean = transaction.newMBeanProxy(nameCreated,
+ NeverReconnectStrategyFactoryModuleMXBean.class);
+ mxBean.setTimeout(timeout);
+ mxBean.setExecutor(GlobalEventExecutorUtil.create(transaction));
+ return nameCreated;
+ }
+
+}
--- /dev/null
+/*
+ * 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.protocol.framework;
+
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import javax.management.InstanceAlreadyExistsException;
+import javax.management.ObjectName;
+
+import org.junit.Before;
+import org.junit.Test;
+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 org.opendaylight.controller.config.yang.netty.eventexecutor.GlobalEventExecutorModuleFactory;
+
+public class ReconnectImmediatelyStrategyModuleTest extends AbstractConfigTest {
+
+ private static final String INSTANCE_NAME = "reconnect-immediately-strategy-factory-impl";
+ private static final String FACTORY_NAME = ReconnectImmediatelyStrategyFactoryModuleFactory.NAME;
+
+ @Before
+ public void setUp() throws Exception {
+ super.initConfigTransactionManagerImpl(new HardcodedModuleFactoriesResolver(
+ new ReconnectImmediatelyStrategyFactoryModuleFactory(), new GlobalEventExecutorModuleFactory()));
+ }
+
+ @Test
+ public void testValidationExceptionTimeoutNotSet() throws Exception {
+ try {
+ createInstance(null);
+ fail();
+ } catch (ValidationException e) {
+ assertTrue(e.getMessage().contains("Timeout value is not set."));
+ }
+ }
+
+ @Test
+ public void testValidationExceptionTimeoutMinValue() throws Exception {
+ try {
+ createInstance(-1);
+ fail();
+ } catch (ValidationException e) {
+ assertTrue(e.getMessage().contains("is less than 0"));
+ }
+ }
+
+ @Test
+ public void testCreateBean() throws Exception {
+ final CommitStatus status = createInstance();
+ assertBeanCount(1, FACTORY_NAME);
+ assertStatus(status, 2, 0, 0);
+ }
+
+ @Test
+ public void testReusingOldInstance() throws Exception {
+ createInstance();
+ final ConfigTransactionJMXClient transaction = configRegistryClient.createTransaction();
+ assertBeanCount(1, FACTORY_NAME);
+ final CommitStatus status = transaction.commit();
+ assertBeanCount(1, FACTORY_NAME);
+ assertStatus(status, 0, 0, 2);
+ }
+
+ @Test
+ public void testReconfigure() throws Exception {
+ createInstance();
+ final ConfigTransactionJMXClient transaction = configRegistryClient.createTransaction();
+ assertBeanCount(1, FACTORY_NAME);
+ final ReconnectImmediatelyStrategyFactoryModuleMXBean mxBean = transaction.newMBeanProxy(
+ transaction.lookupConfigBean(FACTORY_NAME, INSTANCE_NAME),
+ ReconnectImmediatelyStrategyFactoryModuleMXBean.class);
+ mxBean.setTimeout(200);
+ final CommitStatus status = transaction.commit();
+ assertBeanCount(1, FACTORY_NAME);
+ assertStatus(status, 0, 1, 1);
+ }
+
+ private CommitStatus createInstance() throws Exception {
+ return createInstance(500);
+ }
+
+ private CommitStatus createInstance(final Integer timeout) throws Exception {
+ final ConfigTransactionJMXClient transaction = configRegistryClient.createTransaction();
+ createInstance(transaction, timeout);
+ return transaction.commit();
+ }
+
+ private static ObjectName createInstance(final ConfigTransactionJMXClient transaction, final Integer timeout)
+ throws InstanceAlreadyExistsException {
+ final ObjectName nameCreated = transaction.createModule(FACTORY_NAME, INSTANCE_NAME);
+ final ReconnectImmediatelyStrategyFactoryModuleMXBean mxBean = transaction.newMBeanProxy(nameCreated,
+ ReconnectImmediatelyStrategyFactoryModuleMXBean.class);
+ mxBean.setTimeout(timeout);
+ mxBean.setExecutor(GlobalEventExecutorUtil.create(transaction));
+ return nameCreated;
+ }
+
+}
--- /dev/null
+/*
+ * 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.protocol.framework;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import java.math.BigDecimal;
+
+import javax.management.InstanceAlreadyExistsException;
+import javax.management.ObjectName;
+
+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 org.opendaylight.controller.config.yang.netty.eventexecutor.GlobalEventExecutorModuleFactory;
+
+public class TimedReconnectStrategyModuleTest extends AbstractConfigTest {
+
+ private static final String INSTANCE_NAME = "timed-reconect-stategy-facotry-impl";
+ private static final String FACTORY_NAME = TimedReconnectStrategyFactoryModuleFactory.NAME;
+
+ @Before
+ public void setUp() throws Exception {
+ super.initConfigTransactionManagerImpl(new HardcodedModuleFactoriesResolver(
+ new TimedReconnectStrategyFactoryModuleFactory(), new GlobalEventExecutorModuleFactory()));
+ }
+
+ @Test
+ public void testValidationExceptionSleepFactorNotSet() throws Exception {
+ try {
+ createInstance(500, 100L, null, 500L, 10L, 10000L);
+ fail();
+ } catch (ValidationException e) {
+ assertTrue(e.getMessage().contains("SleepFactor value is not set."));
+ }
+ }
+
+ @Test
+ public void testValidationExceptionSleepFactorMinValue() throws Exception {
+ try {
+ createInstance(500, 100L, new BigDecimal(0.5), 500L, 10L, 10000L);
+ fail();
+ } catch (ValidationException e) {
+ assertTrue(e.getMessage().contains("is less than 1"));
+ }
+ }
+
+ @Test
+ public void testValidationExceptionConnectTimeNotSet() throws Exception {
+ try {
+ createInstance(null, 100L, new BigDecimal(1.0), 500L, 10L, 10000L);
+ fail();
+ } catch (ValidationException e) {
+ assertTrue(e.getMessage().contains("ConnectTime value is not set."));
+ }
+ }
+
+ @Test
+ public void testValidationExceptionConnectTimeMinValue() throws Exception {
+ try {
+ createInstance(-1, 100L, new BigDecimal(1.0), 500L, 10L, 10000L);
+ fail();
+ } catch (ValidationException e) {
+ assertTrue(e.getMessage().contains("is less than 0"));
+ }
+ }
+
+ @Test
+ public void testValidationExceptionMinSleepNotSet() throws Exception {
+ try {
+ createInstance(100, null, new BigDecimal(1.0), 100L, 10L, 10000L);
+ fail();
+ } catch (ValidationException e) {
+ assertTrue(e.getMessage().contains("MinSleep value is not set."));
+ }
+ }
+
+ @Test
+ public void testValidationExceptionMaxSleep() throws Exception {
+ try {
+ createInstance(100, 300L, new BigDecimal(1.0), 100L, 10L, 10000L);
+ fail();
+ } catch (ValidationException e) {
+ assertTrue(e.getMessage().contains("is greter than MaxSleep"));
+ }
+ }
+
+ @Test
+ public void testCreateBean() throws Exception {
+ final CommitStatus status = createInstance();
+ assertBeanCount(1, FACTORY_NAME);
+ assertStatus(status, 2, 0, 0);
+ }
+
+ @Test
+ public void testReusingOldInstance() throws Exception {
+ createInstance();
+ final ConfigTransactionJMXClient transaction = configRegistryClient.createTransaction();
+ assertBeanCount(1, FACTORY_NAME);
+ final CommitStatus status = transaction.commit();
+ assertBeanCount(1, FACTORY_NAME);
+ assertStatus(status, 0, 0, 2);
+ }
+
+ @Test
+ public void testReconfigure() throws Exception {
+ createInstance();
+ final ConfigTransactionJMXClient transaction = configRegistryClient.createTransaction();
+ assertBeanCount(1, FACTORY_NAME);
+ final TimedReconnectStrategyFactoryModuleMXBean mxBean = transaction.newMBeanProxy(
+ transaction.lookupConfigBean(FACTORY_NAME, INSTANCE_NAME), TimedReconnectStrategyFactoryModuleMXBean.class);
+ assertEquals(mxBean.getMinSleep(), new Long(100));
+ mxBean.setMinSleep(200L);
+ assertEquals(mxBean.getMinSleep(), new Long(200));
+ final CommitStatus status = transaction.commit();
+ assertBeanCount(1, FACTORY_NAME);
+ assertStatus(status, 0, 1, 1);
+
+ }
+
+ private CommitStatus createInstance() throws Exception {
+ return createInstance(500, 100L, new BigDecimal(1.0), 500L, 10L, 10000L);
+ }
+
+ private CommitStatus createInstance(final Integer connectTime, final Long minSleep, final BigDecimal sleepFactor,
+ final Long maxSleep, final Long maxAttempts, final Long deadline) throws ConflictingVersionException,
+ ValidationException, InstanceAlreadyExistsException {
+ ConfigTransactionJMXClient transaction = configRegistryClient.createTransaction();
+ createInstance(transaction, INSTANCE_NAME, connectTime, minSleep, sleepFactor, maxSleep, maxAttempts, deadline);
+ return transaction.commit();
+ }
+
+ public static ObjectName createInstance(final ConfigTransactionJMXClient transaction, final String InstanceName)
+ throws Exception {
+ return createInstance(transaction, InstanceName, 500, 100L, new BigDecimal(1.0), 500L, 10L, 10000L);
+ }
+
+ private static ObjectName createInstance(final ConfigTransactionJMXClient transaction, final String instanceName,
+ final Integer connectTime, final Long minSleep, final BigDecimal sleepFactor, final Long maxSleep,
+ final Long maxAttempts, final Long deadline) throws InstanceAlreadyExistsException {
+ final ObjectName nameCreated = transaction.createModule(FACTORY_NAME, instanceName);
+ final TimedReconnectStrategyFactoryModuleMXBean mxBean = transaction.newMBeanProxy(nameCreated,
+ TimedReconnectStrategyFactoryModuleMXBean.class);
+ mxBean.setConnectTime(connectTime);
+ mxBean.setDeadline(deadline);
+ mxBean.setMaxAttempts(maxAttempts);
+ mxBean.setMaxSleep(maxSleep);
+ mxBean.setMinSleep(minSleep);
+ mxBean.setSleepFactor(sleepFactor);
+ mxBean.setExecutor(GlobalEventExecutorUtil.create(transaction));
+ return nameCreated;
+ }
+
+}
mavenBundle("io.netty", "netty-codec").versionAsInProject(), //
mavenBundle("io.netty", "netty-transport").versionAsInProject(), //
- mavenBundle(CONTROLLER, "protocol-framework").versionAsInProject(), //
mavenBundle(CONTROLLER, "config-manager").versionAsInProject(), // //
mavenBundle("commons-io", "commons-io").versionAsInProject(), //
mavenBundle(CONTROLLER, "config-manager").versionAsInProject(), //
mavenBundle(CONTROLLER, "ietf-netconf-monitoring-extension").versionAsInProject(), //
mavenBundle(CONTROLLER, "netconf-monitoring").versionAsInProject(), //
+ mavenBundle(CONTROLLER, "netty-config-api"), //
+ mavenBundle(CONTROLLER, "protocol-framework").versionAsInProject(), //
+
mavenBundle(CONTROLLER, "netconf-client").versionAsInProject(), //
mavenBundle(CONTROLLER, "netconf-util").versionAsInProject(), //
mavenBundle(CONTROLLER + ".thirdparty", "ganymed").versionAsInProject(), //