Modify config Module impls to co-exist with blueprint
authorTom Pantelis <tpanteli@brocade.com>
Mon, 28 Mar 2016 17:44:11 +0000 (13:44 -0400)
committerAnil Vishnoi <vishnoianil@gmail.com>
Fri, 22 Apr 2016 17:51:30 +0000 (17:51 +0000)
Modified various config system Module implementation classes which
have corresponding instances created and advertised via blueprint to
obtain the instance in createInstance from the OSGi registry. The
instance may not be available yet so it will wait. I added a
WaitingServiceTracker class to encapsulate this logic using a ServiceTracker.

For those modules that don't advertise services, createInstance simply
returns a noop AutoCloseable since the components are created via
blueprint.

I also added the new disable-osgi-service-registration flag to the
corresponding service yang identities to prevent the CSS from
duplicating the service registrations.

This patch also adds the blueprint bundle to the mdsal features and
"turns on" blueprint.

Change-Id: I60099c82a2a248fc233ad930c4808d6ab19ea881
Signed-off-by: Tom Pantelis <tpanteli@brocade.com>
src/test/java/org/opendaylight/controller/config/yang/protocol/framework/GlobalEventExecutorUtil.java [deleted file]
src/test/java/org/opendaylight/controller/config/yang/protocol/framework/NeverReconnectStrategyModuleTest.java [deleted file]
src/test/java/org/opendaylight/controller/config/yang/protocol/framework/ReconnectImmediatelyStrategyModuleTest.java [deleted file]
src/test/java/org/opendaylight/controller/config/yang/protocol/framework/TimedReconnectStrategyModuleTest.java [deleted file]

diff --git a/src/test/java/org/opendaylight/controller/config/yang/protocol/framework/GlobalEventExecutorUtil.java b/src/test/java/org/opendaylight/controller/config/yang/protocol/framework/GlobalEventExecutorUtil.java
deleted file mode 100644 (file)
index 695e36c..0000000
+++ /dev/null
@@ -1,37 +0,0 @@
-/*
- * 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);
-            }
-        }
-    }
-
-}
diff --git a/src/test/java/org/opendaylight/controller/config/yang/protocol/framework/NeverReconnectStrategyModuleTest.java b/src/test/java/org/opendaylight/controller/config/yang/protocol/framework/NeverReconnectStrategyModuleTest.java
deleted file mode 100644 (file)
index 77589ed..0000000
+++ /dev/null
@@ -1,108 +0,0 @@
-/*
- * 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 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;
-
-import javax.management.InstanceAlreadyExistsException;
-import javax.management.ObjectName;
-
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
-
-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(mockedContext,
-                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.newMXBeanProxy(
-                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.newMXBeanProxy(nameCreated,
-                NeverReconnectStrategyFactoryModuleMXBean.class);
-        mxBean.setTimeout(timeout);
-        mxBean.setExecutor(GlobalEventExecutorUtil.create(transaction));
-        return nameCreated;
-    }
-
-}
diff --git a/src/test/java/org/opendaylight/controller/config/yang/protocol/framework/ReconnectImmediatelyStrategyModuleTest.java b/src/test/java/org/opendaylight/controller/config/yang/protocol/framework/ReconnectImmediatelyStrategyModuleTest.java
deleted file mode 100644 (file)
index 7e3ed5b..0000000
+++ /dev/null
@@ -1,107 +0,0 @@
-/*
- * 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(mockedContext,
-                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.newMXBeanProxy(
-                transaction.lookupConfigBean(FACTORY_NAME, INSTANCE_NAME),
-                ReconnectImmediatelyStrategyFactoryModuleMXBean.class);
-        mxBean.setReconnectTimeout(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.newMXBeanProxy(nameCreated,
-                ReconnectImmediatelyStrategyFactoryModuleMXBean.class);
-        mxBean.setReconnectTimeout(timeout);
-        mxBean.setReconnectExecutor(GlobalEventExecutorUtil.create(transaction));
-        return nameCreated;
-    }
-
-}
diff --git a/src/test/java/org/opendaylight/controller/config/yang/protocol/framework/TimedReconnectStrategyModuleTest.java b/src/test/java/org/opendaylight/controller/config/yang/protocol/framework/TimedReconnectStrategyModuleTest.java
deleted file mode 100644 (file)
index ec8a9d6..0000000
+++ /dev/null
@@ -1,164 +0,0 @@
-/*
- * 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(mockedContext,
-                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.newMXBeanProxy(
-                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.newMXBeanProxy(nameCreated,
-                TimedReconnectStrategyFactoryModuleMXBean.class);
-        mxBean.setConnectTime(connectTime);
-        mxBean.setDeadline(deadline);
-        mxBean.setMaxAttempts(maxAttempts);
-        mxBean.setMaxSleep(maxSleep);
-        mxBean.setMinSleep(minSleep);
-        mxBean.setSleepFactor(sleepFactor);
-        mxBean.setTimedReconnectExecutor(GlobalEventExecutorUtil.create(transaction));
-        return nameCreated;
-    }
-
-}