From 5e0aafd8aa4830a4d4df0f4768e6c85245875958 Mon Sep 17 00:00:00 2001 From: Tomas Olvecky Date: Wed, 11 Dec 2013 14:00:34 +0100 Subject: [PATCH] Remove jolokia dependency from config-subsystem. Remove jolokia client from config-util and tests that were starting jolokia. Change-Id: Ibadf96c6d03d5cc325b4c9d8a01cdbb230550e4b Signed-off-by: Tomas Olvecky --- .../impl/AbstractConfigWithJolokiaTest.java | 38 --- .../ConfigTransactionManagerImplTest.java | 37 +-- .../test/AbstractParallelAPSPTest.java | 10 +- .../test/DependentWiringTest.java | 61 +--- .../test/SimpleConfigurationTest.java | 115 ++------ opendaylight/config/config-util/pom.xml | 10 - .../jolokia/ConfigRegistryJolokiaClient.java | 173 ----------- .../ConfigTransactionJolokiaClient.java | 217 -------------- .../util/jolokia/ListableJolokiaClient.java | 276 ------------------ .../util/ConfigRegistryClientsTest.java | 72 +---- .../util/ConfigTransactionClientsTest.java | 37 +-- .../controller/config/util/JolokiaHelper.java | 54 ---- .../controller/config/util/LookupTest.java | 52 ++-- .../TestingConfigTransactionController.java | 2 +- .../jolokia/ListableJolokiaClientTest.java | 58 ---- opendaylight/config/pom.xml | 17 -- 16 files changed, 91 insertions(+), 1138 deletions(-) delete mode 100644 opendaylight/config/config-manager/src/test/java/org/opendaylight/controller/config/manager/impl/AbstractConfigWithJolokiaTest.java delete mode 100644 opendaylight/config/config-util/src/main/java/org/opendaylight/controller/config/util/jolokia/ConfigRegistryJolokiaClient.java delete mode 100644 opendaylight/config/config-util/src/main/java/org/opendaylight/controller/config/util/jolokia/ConfigTransactionJolokiaClient.java delete mode 100644 opendaylight/config/config-util/src/main/java/org/opendaylight/controller/config/util/jolokia/ListableJolokiaClient.java delete mode 100644 opendaylight/config/config-util/src/test/java/org/opendaylight/controller/config/util/JolokiaHelper.java delete mode 100644 opendaylight/config/config-util/src/test/java/org/opendaylight/controller/config/util/jolokia/ListableJolokiaClientTest.java diff --git a/opendaylight/config/config-manager/src/test/java/org/opendaylight/controller/config/manager/impl/AbstractConfigWithJolokiaTest.java b/opendaylight/config/config-manager/src/test/java/org/opendaylight/controller/config/manager/impl/AbstractConfigWithJolokiaTest.java deleted file mode 100644 index de26220848..0000000000 --- a/opendaylight/config/config-manager/src/test/java/org/opendaylight/controller/config/manager/impl/AbstractConfigWithJolokiaTest.java +++ /dev/null @@ -1,38 +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.manager.impl; - -import org.junit.After; -import org.junit.Before; -import org.opendaylight.controller.config.manager.impl.factoriesresolver.ModuleFactoriesResolver; -import org.opendaylight.controller.config.util.JolokiaHelper; -import org.opendaylight.controller.config.util.jolokia.ConfigRegistryJolokiaClient; - -public class AbstractConfigWithJolokiaTest extends AbstractConfigTest { - protected String jolokiaURL; - protected ConfigRegistryJolokiaClient configRegistryJolokiaClient; - - @Before - public void initJolokia() { - jolokiaURL = JolokiaHelper.startTestingJolokia(); - } - - // this method should be called in @Before - @Override - protected void initConfigTransactionManagerImpl( - ModuleFactoriesResolver resolver) { - super.initConfigTransactionManagerImpl(resolver); - configRegistryJolokiaClient = new ConfigRegistryJolokiaClient( - jolokiaURL); - } - - @After - public void cleanUpJolokia() { - JolokiaHelper.stopJolokia(); - } -} diff --git a/opendaylight/config/config-manager/src/test/java/org/opendaylight/controller/config/manager/impl/ConfigTransactionManagerImplTest.java b/opendaylight/config/config-manager/src/test/java/org/opendaylight/controller/config/manager/impl/ConfigTransactionManagerImplTest.java index eaaee5eb5b..bbb3784b33 100644 --- a/opendaylight/config/config-manager/src/test/java/org/opendaylight/controller/config/manager/impl/ConfigTransactionManagerImplTest.java +++ b/opendaylight/config/config-manager/src/test/java/org/opendaylight/controller/config/manager/impl/ConfigTransactionManagerImplTest.java @@ -7,23 +7,19 @@ */ package org.opendaylight.controller.config.manager.impl; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; -import static org.mockito.Mockito.mock; - -import javax.management.InstanceAlreadyExistsException; - import org.junit.Before; import org.junit.Test; -import org.opendaylight.controller.config.api.jmx.ObjectNameUtil; -import org.opendaylight.controller.config.api.jmx.constants.ConfigRegistryConstants; import org.opendaylight.controller.config.manager.impl.factoriesresolver.HardcodedModuleFactoriesResolver; import org.opendaylight.controller.config.util.ConfigTransactionJMXClient; -import org.opendaylight.controller.config.util.jolokia.ConfigTransactionJolokiaClient; + +import javax.management.InstanceAlreadyExistsException; + +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; +import static org.mockito.Mockito.mock; public class ConfigTransactionManagerImplTest extends - AbstractConfigWithJolokiaTest { + AbstractConfigTest { @Before public void setUp() { @@ -55,23 +51,4 @@ public class ConfigTransactionManagerImplTest extends transaction.commit(); } - @Test - public void testRemoteCallsUsingJolokia() throws Exception { - - ConfigTransactionJolokiaClient transactionClient = configRegistryJolokiaClient - .createTransaction(); - - assertEquals("ConfigTransaction-0-1", - ObjectNameUtil.getTransactionName(transactionClient - .getTransactionON())); - - assertEquals( - ConfigRegistryConstants.ON_DOMAIN - + ":TransactionName=ConfigTransaction-0-1,type=ConfigTransaction", - transactionClient.getTransactionON().getCanonicalName()); - - // commit - transactionClient.commit(); - - } } diff --git a/opendaylight/config/config-manager/src/test/java/org/opendaylight/controller/config/manager/testingservices/parallelapsp/test/AbstractParallelAPSPTest.java b/opendaylight/config/config-manager/src/test/java/org/opendaylight/controller/config/manager/testingservices/parallelapsp/test/AbstractParallelAPSPTest.java index 7deb1efb55..3d9d5245ef 100644 --- a/opendaylight/config/config-manager/src/test/java/org/opendaylight/controller/config/manager/testingservices/parallelapsp/test/AbstractParallelAPSPTest.java +++ b/opendaylight/config/config-manager/src/test/java/org/opendaylight/controller/config/manager/testingservices/parallelapsp/test/AbstractParallelAPSPTest.java @@ -7,16 +7,16 @@ */ package org.opendaylight.controller.config.manager.testingservices.parallelapsp.test; -import javax.management.InstanceAlreadyExistsException; -import javax.management.ObjectName; - -import org.opendaylight.controller.config.manager.impl.AbstractConfigWithJolokiaTest; +import org.opendaylight.controller.config.manager.impl.AbstractConfigTest; import org.opendaylight.controller.config.manager.testingservices.parallelapsp.TestingParallelAPSPConfigMXBean; import org.opendaylight.controller.config.manager.testingservices.parallelapsp.TestingParallelAPSPModuleFactory; import org.opendaylight.controller.config.manager.testingservices.threadpool.TestingFixedThreadPoolConfigMXBean; import org.opendaylight.controller.config.util.ConfigTransactionJMXClient; -abstract class AbstractParallelAPSPTest extends AbstractConfigWithJolokiaTest { +import javax.management.InstanceAlreadyExistsException; +import javax.management.ObjectName; + +abstract class AbstractParallelAPSPTest extends AbstractConfigTest { protected final String fixed1 = "fixed1"; protected final String apsp1 = "apsp-parallel"; diff --git a/opendaylight/config/config-manager/src/test/java/org/opendaylight/controller/config/manager/testingservices/parallelapsp/test/DependentWiringTest.java b/opendaylight/config/config-manager/src/test/java/org/opendaylight/controller/config/manager/testingservices/parallelapsp/test/DependentWiringTest.java index 5b1a6f6e81..f9a11301e1 100644 --- a/opendaylight/config/config-manager/src/test/java/org/opendaylight/controller/config/manager/testingservices/parallelapsp/test/DependentWiringTest.java +++ b/opendaylight/config/config-manager/src/test/java/org/opendaylight/controller/config/manager/testingservices/parallelapsp/test/DependentWiringTest.java @@ -7,17 +7,6 @@ */ package org.opendaylight.controller.config.manager.testingservices.parallelapsp.test; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertThat; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; -import static org.junit.internal.matchers.StringContains.containsString; - -import java.util.Map; - -import javax.management.ObjectName; - -import org.json.simple.JSONObject; import org.junit.After; import org.junit.Before; import org.junit.Test; @@ -32,7 +21,15 @@ import org.opendaylight.controller.config.manager.testingservices.threadpool.Tes import org.opendaylight.controller.config.manager.testingservices.threadpool.TestingFixedThreadPoolConfigMXBean; import org.opendaylight.controller.config.manager.testingservices.threadpool.TestingFixedThreadPoolModuleFactory; import org.opendaylight.controller.config.util.ConfigTransactionJMXClient; -import org.opendaylight.controller.config.util.jolokia.ConfigTransactionJolokiaClient; + +import javax.management.ObjectName; +import java.util.Map; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertThat; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; +import static org.junit.internal.matchers.StringContains.containsString; public class DependentWiringTest extends AbstractParallelAPSPTest { private final String fixed1 = "fixed1"; @@ -135,44 +132,4 @@ public class DependentWiringTest extends AbstractParallelAPSPTest { parallelAPSPRuntimeProxy.getMaxNumberOfThreads()); } - - @Test - public void testUsingJolokia() throws Exception { - - ConfigTransactionJolokiaClient transactionClient = configRegistryJolokiaClient - .createTransaction(); - // fixed1 - ObjectName fixed1ON = transactionClient.createModule( - getThreadPoolImplementationName(), fixed1); - transactionClient.setAttribute(fixed1ON, "ThreadCount", - TestingParallelAPSPImpl.MINIMAL_NUMBER_OF_THREADS); - - // apsp-parallel with syntetic attrib - String threadPoolString = "ThreadPool"; - ObjectName apsp1ON = transactionClient.createModule( - TestingParallelAPSPModuleFactory.NAME, apsp1); - transactionClient.setAttribute(apsp1ON, threadPoolString, fixed1ON); - // check - assertEquals(ObjectNameUtil.withoutTransactionName(fixed1ON), - transactionClient.getAttributeON(apsp1ON, threadPoolString)); - transactionClient.setAttribute(apsp1ON, "SomeParam", "ahoj"); - - // commit - transactionClient.commit(); - // check thread pool - assertEquals(1, TestingFixedThreadPool.allExecutors.size()); - // check platform MBeanServer - ObjectName apspReadOnlyON = ObjectNameUtil - .withoutTransactionName(apsp1ON); - JSONObject threadPoolONJson = (JSONObject) configRegistryJolokiaClient - .getAttribute(apspReadOnlyON, threadPoolString); - ObjectName fixed1ReadOnlyON = ObjectNameUtil - .withoutTransactionName(fixed1ON); - assertEquals(fixed1ReadOnlyON, ObjectNameUtil.createON(threadPoolONJson - .get("objectName").toString())); - assertEquals(fixed1ReadOnlyON, - configRegistryJolokiaClient.getAttributeON(apspReadOnlyON, - threadPoolString)); - - } } diff --git a/opendaylight/config/config-manager/src/test/java/org/opendaylight/controller/config/manager/testingservices/threadpool/test/SimpleConfigurationTest.java b/opendaylight/config/config-manager/src/test/java/org/opendaylight/controller/config/manager/testingservices/threadpool/test/SimpleConfigurationTest.java index c2f2558a5d..13bb84040a 100644 --- a/opendaylight/config/config-manager/src/test/java/org/opendaylight/controller/config/manager/testingservices/threadpool/test/SimpleConfigurationTest.java +++ b/opendaylight/config/config-manager/src/test/java/org/opendaylight/controller/config/manager/testingservices/threadpool/test/SimpleConfigurationTest.java @@ -7,28 +7,6 @@ */ package org.opendaylight.controller.config.manager.testingservices.threadpool.test; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertThat; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; -import static org.junit.matchers.JUnitMatchers.containsString; - -import java.util.Arrays; -import java.util.Collections; -import java.util.List; -import java.util.Map; -import java.util.concurrent.ThreadPoolExecutor; - -import javax.management.DynamicMBean; -import javax.management.InstanceAlreadyExistsException; -import javax.management.InstanceNotFoundException; -import javax.management.MBeanException; -import javax.management.ObjectName; -import javax.management.ReflectionException; -import javax.management.RuntimeMBeanException; - import org.junit.After; import org.junit.Before; import org.junit.Test; @@ -37,14 +15,32 @@ import org.opendaylight.controller.config.api.ValidationException; import org.opendaylight.controller.config.api.ValidationException.ExceptionMessageWithStackTrace; import org.opendaylight.controller.config.api.jmx.CommitStatus; import org.opendaylight.controller.config.api.jmx.ObjectNameUtil; -import org.opendaylight.controller.config.manager.impl.AbstractConfigWithJolokiaTest; +import org.opendaylight.controller.config.manager.impl.AbstractConfigTest; import org.opendaylight.controller.config.manager.impl.factoriesresolver.HardcodedModuleFactoriesResolver; import org.opendaylight.controller.config.manager.testingservices.threadpool.TestingFixedThreadPool; import org.opendaylight.controller.config.manager.testingservices.threadpool.TestingFixedThreadPoolConfigMXBean; import org.opendaylight.controller.config.manager.testingservices.threadpool.TestingFixedThreadPoolModuleFactory; import org.opendaylight.controller.config.util.ConfigTransactionClient; import org.opendaylight.controller.config.util.ConfigTransactionJMXClient; -import org.opendaylight.controller.config.util.jolokia.ConfigTransactionJolokiaClient; + +import javax.management.DynamicMBean; +import javax.management.InstanceAlreadyExistsException; +import javax.management.InstanceNotFoundException; +import javax.management.MBeanException; +import javax.management.ObjectName; +import javax.management.ReflectionException; +import javax.management.RuntimeMBeanException; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; +import java.util.Map; +import java.util.concurrent.ThreadPoolExecutor; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; /** * Tests basic functionality of configuration registry: @@ -58,7 +54,7 @@ import org.opendaylight.controller.config.util.jolokia.ConfigTransactionJolokiaC * Only one bean is being configured - {@link TestingThreadPoolIfc} which has no * dependencies. */ -public class SimpleConfigurationTest extends AbstractConfigWithJolokiaTest { +public class SimpleConfigurationTest extends AbstractConfigTest { private final int numberOfThreads = 5; private final int numberOfThreads2 = 10; private static final String fixed1 = "fixed1"; @@ -134,12 +130,6 @@ public class SimpleConfigurationTest extends AbstractConfigWithJolokiaTest { testValidation(transaction); } - @Test - public void testValidationUsingJolokiaClient() throws Exception { - ConfigTransactionClient transaction = configRegistryJolokiaClient - .createTransaction(); - testValidation(transaction); - } private void testValidation(ConfigTransactionClient transaction) throws InstanceAlreadyExistsException, ReflectionException, @@ -393,68 +383,5 @@ public class SimpleConfigurationTest extends AbstractConfigWithJolokiaTest { } } - @Test - public void testOptimisticLock_ConfigTransactionJolokiaClient() - throws Exception { - ConfigTransactionJolokiaClient transaction1 = configRegistryJolokiaClient - .createTransaction(); - ConfigTransactionJolokiaClient transaction2 = configRegistryJolokiaClient - .createTransaction(); - transaction2.assertVersion(0, 2); - transaction2.commit(); - try { - transaction1.commit(); - fail(); - } catch (ConflictingVersionException e) { - assertEquals( - "Optimistic lock failed. Expected parent version 2, was 0", - e.getMessage()); - } - } - - @Test - public void testOptimisticLock_ConfigRegistryJolokiaClient() - throws Exception { - ConfigTransactionJolokiaClient transaction1 = configRegistryJolokiaClient - .createTransaction(); - ConfigTransactionJolokiaClient transaction2 = configRegistryJolokiaClient - .createTransaction(); - transaction2.assertVersion(0, 2); - transaction2.commit(); - try { - configRegistryJolokiaClient.commitConfig(transaction1 - .getObjectName()); - fail(); - } catch (ConflictingVersionException e) { - assertEquals( - "Optimistic lock failed. Expected parent version 2, was 0", - e.getMessage()); - } - } - - @Test - public void testUsingJolokia() throws Exception { - ConfigTransactionJolokiaClient transactionClient = configRegistryJolokiaClient - .createTransaction(); - - ObjectName name = transactionClient.createModule( - TestingFixedThreadPoolModuleFactory.NAME, fixed1); - - try { - transactionClient.validateConfig(); - fail(); - } catch (ValidationException e) { - assertThat( - e.getMessage(), - containsString("Parameter 'threadCount' must be greater than 0")); - } - - transactionClient.setAttribute(name, "ThreadCount", numberOfThreads); - // commit - CommitStatus commitStatus = transactionClient.commit(); - CommitStatus expected = new CommitStatus(Arrays.asList(ObjectNameUtil - .withoutTransactionName(name)), emptyONs, emptyONs); - assertEquals(expected, commitStatus); - } } diff --git a/opendaylight/config/config-util/pom.xml b/opendaylight/config/config-util/pom.xml index 206184ccce..23603ae626 100644 --- a/opendaylight/config/config-util/pom.xml +++ b/opendaylight/config/config-util/pom.xml @@ -17,16 +17,6 @@ ${project.groupId} config-api - - org.jolokia - jolokia-client-java - - - org.jolokia - jolokia-jvm - agent - - com.google.guava diff --git a/opendaylight/config/config-util/src/main/java/org/opendaylight/controller/config/util/jolokia/ConfigRegistryJolokiaClient.java b/opendaylight/config/config-util/src/main/java/org/opendaylight/controller/config/util/jolokia/ConfigRegistryJolokiaClient.java deleted file mode 100644 index 9d55f8d529..0000000000 --- a/opendaylight/config/config-util/src/main/java/org/opendaylight/controller/config/util/jolokia/ConfigRegistryJolokiaClient.java +++ /dev/null @@ -1,173 +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.util.jolokia; - -import java.util.List; -import java.util.Map; -import java.util.Set; - -import javax.management.InstanceNotFoundException; -import javax.management.ObjectName; - -import org.jolokia.client.request.J4pExecRequest; -import org.jolokia.client.request.J4pReadRequest; -import org.jolokia.client.request.J4pResponse; -import org.json.simple.JSONArray; -import org.json.simple.JSONObject; -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.api.jmx.ConfigRegistryMXBean; -import org.opendaylight.controller.config.api.jmx.ObjectNameUtil; -import org.opendaylight.controller.config.util.ConfigRegistryClient; - -@Deprecated -public class ConfigRegistryJolokiaClient extends ListableJolokiaClient - implements ConfigRegistryClient { - - public ConfigRegistryJolokiaClient(String url) { - super(url, ConfigRegistryMXBean.OBJECT_NAME); - } - - @Override - public ConfigTransactionJolokiaClient createTransaction() { - // create transaction - J4pExecRequest execReq = new J4pExecRequest(objectName, "beginConfig"); - J4pResponse resp = execute(execReq); - ObjectName transactionControllerON = extractObjectName(resp); - return getConfigTransactionClient(transactionControllerON); - } - - @Override - public ConfigTransactionJolokiaClient getConfigTransactionClient( - String transactionName) { - ObjectName objectName = ObjectNameUtil - .createTransactionControllerON(transactionName); - return getConfigTransactionClient(objectName); - } - - @Override - public ConfigTransactionJolokiaClient getConfigTransactionClient( - ObjectName objectName) { - return new ConfigTransactionJolokiaClient(url, objectName, this); - } - - @Override - public CommitStatus commitConfig(ObjectName transactionControllerON) - throws ConflictingVersionException, ValidationException { - J4pExecRequest execReq = new J4pExecRequest(objectName, "commitConfig", - transactionControllerON); - JSONObject jsonObject; - jsonObject = execute(execReq).getValue(); - JSONArray newInstancesArray = (JSONArray) jsonObject - .get("newInstances"); - List newInstances = jsonArrayToObjectNames(newInstancesArray); - JSONArray reusedInstancesArray = (JSONArray) jsonObject - .get("reusedInstances"); - List reusedInstances = jsonArrayToObjectNames(reusedInstancesArray); - JSONArray recreatedInstancesArray = (JSONArray) jsonObject - .get("recreatedInstances"); - List recreatedInstances = jsonArrayToObjectNames(recreatedInstancesArray); - return new CommitStatus(newInstances, reusedInstances, - recreatedInstances); - } - - public Object getAttribute(ObjectName configBeanTransactionON, String key) { - J4pReadRequest req = new J4pReadRequest(configBeanTransactionON, key); - return execute(req).getValue(); - } - - public ObjectName getAttributeON(ObjectName configBeanTransactionON, - String key) { - JSONObject jsonAttrib = (JSONObject) getAttribute( - configBeanTransactionON, key); - return extractObjectName(jsonAttrib); - } - - // proxy around ConfigTransactionManagerMXBean - - @Override - public ObjectName beginConfig() { - ConfigTransactionJolokiaClient result = createTransaction(); - return result.getTransactionON(); - } - - @Override - public List getOpenConfigs() { - J4pReadRequest req = new J4pReadRequest(objectName, "OpenConfigs"); - JSONArray jsonArray = execute(req).getValue(); - return jsonArrayToObjectNames(jsonArray); - } - - @Override - public long getVersion() { - J4pReadRequest req = new J4pReadRequest(objectName, "Version"); - return (Long) execute(req).getValue(); - } - - @Override - public boolean isHealthy() { - J4pReadRequest req = new J4pReadRequest(objectName, "Healthy"); - return (Boolean) execute(req).getValue(); - } - - @Override - public Set lookupRuntimeBeans() { - return lookupSomething("lookupRuntimeBeans()", new Object[0]); - } - - @Override - public Set lookupRuntimeBeans(String moduleName, - String instanceName) { - return lookupSomething( - "lookupRuntimeBeans(java.lang.String,java.lang.String)", - new Object[] { moduleName, instanceName }); - } - - @Override - public Object invokeMethod(ObjectName on, String name, Object[] params, - String[] signature) { - throw new UnsupportedOperationException(); - } - - @Override - public Object getAttributeCurrentValue(ObjectName on, String attributeName) { - throw new UnsupportedOperationException(); - } - - // TODO: implement or deprecate - @Override - public void checkConfigBeanExists(ObjectName objectName) throws InstanceNotFoundException { - throw new UnsupportedOperationException(); - } - - @Override - public ObjectName lookupConfigBeanByServiceInterfaceName(String serviceInterfaceName, String refName) { - throw new UnsupportedOperationException(); - } - - @Override - public Map> getServiceMapping() { - throw new UnsupportedOperationException(); - } - - @Override - public Map lookupServiceReferencesByServiceInterfaceName(String serviceInterfaceName) { - throw new UnsupportedOperationException(); - } - - @Override - public Set lookupServiceInterfaceNames(ObjectName objectName) throws InstanceNotFoundException { - throw new UnsupportedOperationException(); - } - - @Override - public String getServiceInterfaceName(String namespace, String localName) { - throw new UnsupportedOperationException(); - } -} diff --git a/opendaylight/config/config-util/src/main/java/org/opendaylight/controller/config/util/jolokia/ConfigTransactionJolokiaClient.java b/opendaylight/config/config-util/src/main/java/org/opendaylight/controller/config/util/jolokia/ConfigTransactionJolokiaClient.java deleted file mode 100644 index 834e9c6845..0000000000 --- a/opendaylight/config/config-util/src/main/java/org/opendaylight/controller/config/util/jolokia/ConfigTransactionJolokiaClient.java +++ /dev/null @@ -1,217 +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.util.jolokia; - -import java.util.Map; -import java.util.Set; - -import javax.management.Attribute; -import javax.management.AttributeNotFoundException; -import javax.management.InstanceAlreadyExistsException; -import javax.management.InstanceNotFoundException; -import javax.management.ObjectName; - -import org.jolokia.client.request.J4pExecRequest; -import org.jolokia.client.request.J4pReadRequest; -import org.jolokia.client.request.J4pWriteRequest; -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.api.jmx.ObjectNameUtil; -import org.opendaylight.controller.config.util.AttributeEntry; -import org.opendaylight.controller.config.util.ConfigTransactionClient; - -@Deprecated -public class ConfigTransactionJolokiaClient extends ListableJolokiaClient - implements ConfigTransactionClient { - - private final ConfigRegistryJolokiaClient configRegistryJolokiaClient; - - public ConfigTransactionJolokiaClient(String url, - ObjectName transactionControllerON, - ConfigRegistryJolokiaClient configRegistryJolokiaClient) { - super(url, transactionControllerON); - this.configRegistryJolokiaClient = configRegistryJolokiaClient; - } - - public ObjectName getTransactionON() { - return objectName; - } - - @Override - public CommitStatus commit() throws ConflictingVersionException, - ValidationException { - return configRegistryJolokiaClient.commitConfig(objectName); - } - - @Override - public ObjectName createModule(String moduleName, String instanceName) - throws InstanceAlreadyExistsException { - J4pExecRequest execReq = new J4pExecRequest(objectName, "createModule", - moduleName, instanceName); - try { - return extractObjectName(execute(execReq)); - } catch (RuntimeException e) { - if (e.getMessage() != null - && e.getMessage().startsWith( - InstanceAlreadyExistsException.class.getName())) - throw new InstanceAlreadyExistsException(); - throw e; - } - } - - @Override - public void destroyModule(ObjectName configBeanON) { - J4pExecRequest execReq = new J4pExecRequest(objectName, - "destroyModule(javax.management.ObjectName)", configBeanON); - execute(execReq); - } - - @Override - public void destroyConfigBean(String moduleName, String instanceName) - throws InstanceNotFoundException { - destroyModule(ObjectNameUtil.createTransactionModuleON( - getTransactionName(), moduleName, instanceName)); - } - - @Override - public void abortConfig() { - J4pExecRequest execReq = new J4pExecRequest(objectName, "abortConfig"); - execute(execReq); - } - - @Override - public void validateConfig() throws ValidationException { - J4pExecRequest execReq = new J4pExecRequest(objectName, - "validateConfig"); - execute(execReq); - } - - @Override - public long getParentVersion() { - J4pReadRequest req = new J4pReadRequest(objectName, "ParentVersion"); - return (Long) execute(req).getValue(); - } - - @Override - public long getVersion() { - J4pReadRequest req = new J4pReadRequest(objectName, "Version"); - return (Long) execute(req).getValue(); - } - - public void setAttribute(ObjectName configBeanTransactionON, String key, - Object value) { - J4pWriteRequest req = new J4pWriteRequest(configBeanTransactionON, key, - value); - try { - execute(req); - } catch (RuntimeException e) { - if (e.getMessage() != null - && e.getMessage().startsWith( - AttributeNotFoundException.class.getName())) { - // try to fix wrong case - Map allAttributes = getAttributes(configBeanTransactionON); - for (AttributeEntry attrib : allAttributes.values()) { - if (attrib.getKey().equalsIgnoreCase(key)) { - req = new J4pWriteRequest(configBeanTransactionON, - attrib.getKey(), value); - execute(req); - return; - } - } - } - throw e; - } - } - - public Object getAttribute(ObjectName objectName, String key) { - return configRegistryJolokiaClient.getAttribute(objectName, key); - } - - public ObjectName getAttributeON(ObjectName objectName, String key) { - return configRegistryJolokiaClient.getAttributeON(objectName, key); - } - - @Override - public String getTransactionName() { - return ObjectNameUtil.getTransactionName(objectName); - } - - @Override - public void validateBean(ObjectName rwON) throws ValidationException { - J4pExecRequest req = new J4pExecRequest(rwON, "validate", new Object[0]); - execute(req); - } - - @Override - public void assertVersion(int expectedParentVersion, - int expectedCurrentVersion) { - if (expectedParentVersion != getParentVersion()) { - throw new IllegalStateException(); - } - if (expectedCurrentVersion != getVersion()) { - throw new IllegalStateException(); - } - } - - @Override - public void setAttribute(ObjectName on, String jmxName, Attribute attribute) { - throw new UnsupportedOperationException(); - } - - // TODO: implement or deprecate - @Override - public void checkConfigBeanExists(ObjectName objectName) throws InstanceNotFoundException { - throw new UnsupportedOperationException(); - } - - @Override - public void saveServiceReference(String serviceInterfaceName, String refName, ObjectName objectName) throws InstanceNotFoundException { - throw new UnsupportedOperationException(); - } - - @Override - public boolean removeServiceReference(String serviceInterfaceName, String refName) { - throw new UnsupportedOperationException(); - } - - @Override - public void removeAllServiceReferences() { - throw new UnsupportedOperationException(); - } - - @Override - public ObjectName lookupConfigBeanByServiceInterfaceName(String serviceInterfaceName, String refName) { - throw new UnsupportedOperationException(); - } - - @Override - public Map> getServiceMapping() { - throw new UnsupportedOperationException(); - } - - @Override - public Map lookupServiceReferencesByServiceInterfaceName(String serviceInterfaceName) { - throw new UnsupportedOperationException(); - } - - @Override - public Set lookupServiceInterfaceNames(ObjectName objectName) throws InstanceNotFoundException { - throw new UnsupportedOperationException(); - } - - @Override - public String getServiceInterfaceName(String namespace, String localName) { - throw new UnsupportedOperationException(); - } - - @Override - public boolean removeServiceReferences(ObjectName objectName) throws InstanceNotFoundException { - throw new UnsupportedOperationException(); - } -} diff --git a/opendaylight/config/config-util/src/main/java/org/opendaylight/controller/config/util/jolokia/ListableJolokiaClient.java b/opendaylight/config/config-util/src/main/java/org/opendaylight/controller/config/util/jolokia/ListableJolokiaClient.java deleted file mode 100644 index 321d23ffdc..0000000000 --- a/opendaylight/config/config-util/src/main/java/org/opendaylight/controller/config/util/jolokia/ListableJolokiaClient.java +++ /dev/null @@ -1,276 +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.util.jolokia; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Map.Entry; -import java.util.Set; -import java.util.regex.Pattern; - -import javax.management.InstanceNotFoundException; -import javax.management.MalformedObjectNameException; -import javax.management.ObjectName; - -import org.jolokia.client.J4pClient; -import org.jolokia.client.exception.J4pException; -import org.jolokia.client.exception.J4pRemoteException; -import org.jolokia.client.request.J4pExecRequest; -import org.jolokia.client.request.J4pListRequest; -import org.jolokia.client.request.J4pQueryParameter; -import org.jolokia.client.request.J4pReadRequest; -import org.jolokia.client.request.J4pRequest; -import org.jolokia.client.request.J4pResponse; -import org.json.simple.JSONArray; -import org.json.simple.JSONObject; -import org.opendaylight.controller.config.api.ConflictingVersionException; -import org.opendaylight.controller.config.api.ValidationException; -import org.opendaylight.controller.config.api.ValidationException.ExceptionMessageWithStackTrace; -import org.opendaylight.controller.config.api.jmx.ObjectNameUtil; -import org.opendaylight.controller.config.util.AttributeEntry; - - -abstract class ListableJolokiaClient { - protected final J4pClient j4pClient; - protected final String url; - protected final ObjectName objectName; - - public ListableJolokiaClient(String url, ObjectName objectName) { - if (url == null) { - throw new NullPointerException("Parameter 'url' is null"); - } - if (!url.endsWith("/")) { - throw new IllegalArgumentException( - "Parameter 'url' must end with '/'"); - } - - this.url = url; - this.j4pClient = new J4pClient(url); - this.objectName = objectName; - } - - public ObjectName getObjectName() { - return objectName; - } - - protected , T extends J4pRequest> R execute( - T pRequest) { - try { - Map pProcessingOptions = new HashMap(); - pProcessingOptions - .put(J4pQueryParameter.INCLUDE_STACKTRACE, "true"); - pProcessingOptions.put(J4pQueryParameter.SERIALIZE_EXCEPTION, - "true"); - return j4pClient.execute(pRequest, "POST", pProcessingOptions); - } catch (J4pRemoteException e) { - tryToConvertException(e.getRemoteStackTrace(), e.getErrorValue()); - throw new RuntimeException(e.getRemoteStackTrace(), e); - } catch (J4pException e) { - throw new RuntimeException(e); - } - } - - protected void tryToConvertException(String remoteStackTrace, - JSONObject errorValue) { - String conflictPrefix = ConflictingVersionException.class.getName() - + ": "; - if (remoteStackTrace.startsWith(conflictPrefix)) { - remoteStackTrace = remoteStackTrace.substring(conflictPrefix - .length()); - Pattern p = Pattern.compile("\r?\n"); - remoteStackTrace = Arrays.asList(p.split(remoteStackTrace)) - .iterator().next(); - throw new ConflictingVersionException(remoteStackTrace); - } - String validationExceptionPrefix = ValidationException.class.getName(); - if (remoteStackTrace.startsWith(validationExceptionPrefix)) { - throw createValidationExceptionFromJSONObject(errorValue); - } - } - - static ValidationException createValidationExceptionFromJSONObject( - JSONObject errorValue) { - String fValsKey = "failedValidations"; - JSONObject failedVals = (JSONObject) errorValue.get(fValsKey); - - checkArgument( - !failedVals.isEmpty(), - fValsKey + " was not present in received JSON: " - + errorValue.toJSONString()); - Map> failedValsMap = new HashMap>(); - - for (Object key : failedVals.keySet()) { - checkArgument(key instanceof String, "Unexpected key " + key - + ", expected instance of String"); - Map innerMap = new HashMap(); - for (Object innerKey : ((JSONObject) failedVals.get(key)).keySet()) { - checkArgument(innerKey instanceof String, "Unexpected key " - + innerKey + ", expected instance of String"); - JSONObject exWithStackTraceVal = (JSONObject) (((JSONObject) failedVals - .get(key)).get(innerKey)); - Object mess = exWithStackTraceVal.get("message"); - Object stack = exWithStackTraceVal.get("trace"); - checkArgument(mess != null && stack != null, - "\"Message\" and \"trace\" elements expected in received json: " - + errorValue.toJSONString()); - innerMap.put(innerKey.toString(), - new ExceptionMessageWithStackTrace((String) mess, - (String) stack)); - } - failedValsMap.put((String) key, innerMap); - } - return new ValidationException(failedValsMap); - } - - private static void checkArgument(boolean b, String string) { - if (b == false) - throw new IllegalArgumentException(string); - } - - public String getUrl() { - return url; - } - - public Map getAttributes(ObjectName on) { - J4pListRequest req = new J4pListRequest(on); - J4pResponse response = execute(req); - JSONObject listJSONResponse = response.getValue(); - JSONObject attributes = (JSONObject) listJSONResponse.get("attr"); - - // Empty attributes list - if(attributes == null) - return Collections.emptyMap(); - - Map listMap = new HashMap<>(); - - for (Object entryObject : attributes.entrySet()) { - Entry entry = (Entry) entryObject; - JSONObject entryVal = (JSONObject) entry.getValue(); - - // read value - listMap.put(entry.getKey(), entryVal); - } - J4pReadRequest j4pReadRequest = new J4pReadRequest(on, listMap.keySet() - .toArray(new String[0])); - J4pResponse readResponse = execute(j4pReadRequest); - Object readResponseValue = readResponse.getValue(); - // readResponseValue can be String if there is just one attribute or - // JSONObject - Map attribsToValues = new HashMap(); - if (readResponseValue instanceof JSONObject) { - JSONObject readJSONResponse = (JSONObject) readResponseValue; - for (Object entryObject : readJSONResponse.entrySet()) { - Entry entry = (Entry) entryObject; - String key = entry.getKey(); - Object value = entry.getValue(); - attribsToValues.put(key, value); - } - } - - Map resultMap = new HashMap(); - for (Entry entry : listMap.entrySet()) { - String key = entry.getKey(); - Object value = attribsToValues.size() > 0 ? attribsToValues - .get(key) : readResponseValue; - JSONObject listJSON = entry.getValue(); - String description = (String) listJSON.get("desc"); - String type = (String) listJSON.get("type"); - boolean rw = (Boolean) listJSON.get("rw"); - AttributeEntry attributeEntry = new AttributeEntry(key, - description, value, type, rw); - resultMap.put(key, attributeEntry); - } - - return resultMap; - } - - public String getConfigBeanDescripton(ObjectName on) { - J4pListRequest req = new J4pListRequest(on); - J4pResponse response = execute(req); - JSONObject jsonDesc = response.getValue(); - Object description = jsonDesc.get("desc"); - return description == null ? null : description.toString(); - } - - protected List jsonArrayToObjectNames(JSONArray jsonArray) { - List result = new ArrayList<>(jsonArray.size()); - for (Object entry : jsonArray) { - JSONObject jsonObject = (JSONObject) entry; - String objectNameString = (String) jsonObject.get("objectName"); - try { - result.add(new ObjectName(objectNameString)); - } catch (MalformedObjectNameException e) { - throw new IllegalStateException("Cannot convert " - + objectNameString + " to ObjectName", e); - } - } - return result; - } - - protected ObjectName extractObjectName(J4pResponse resp) { - JSONObject jsonResponse = resp.getValue(); - return extractObjectName(jsonResponse); - } - - protected ObjectName extractObjectName(JSONObject jsonResponse) { - String result = jsonResponse.get("objectName").toString(); - return ObjectNameUtil.createON(result); - } - - protected Set lookupSomething(String signature, - Object[] parameters) { - J4pExecRequest req = new J4pExecRequest(objectName, signature, - parameters); - JSONArray jsonArray = execute(req).getValue(); - return new HashSet<>(jsonArrayToObjectNames(jsonArray)); - } - - public Set lookupConfigBeans() { - return lookupSomething("lookupConfigBeans()", new Object[0]); - } - - public Set lookupConfigBeans(String ifcName) { - return lookupSomething("lookupConfigBeans(java.lang.String)", - new Object[] { ifcName }); - } - - public Set lookupConfigBeans(String ifcName, String instanceName) { - return lookupSomething( - "lookupConfigBeans(java.lang.String,java.lang.String)", - new Object[] { ifcName, instanceName }); - } - - public ObjectName lookupConfigBean(String ifcName, String instanceName) - throws InstanceNotFoundException { - J4pExecRequest req = new J4pExecRequest(objectName, - "lookupConfigBean(java.lang.String,java.lang.String)", - new Object[] { ifcName, instanceName }); - try { - J4pResponse resp = execute(req); - return extractObjectName(resp); - } catch (RuntimeException e) { - if (e.getMessage() != null - && e.getMessage().startsWith( - InstanceNotFoundException.class.getName())) - throw new InstanceNotFoundException(); - throw e; - } - } - - public Set getAvailableModuleNames() { - J4pReadRequest req = new J4pReadRequest(objectName, - "AvailableModuleNames"); - List value = execute(req).getValue(); - return new HashSet<>(value); - } -} diff --git a/opendaylight/config/config-util/src/test/java/org/opendaylight/controller/config/util/ConfigRegistryClientsTest.java b/opendaylight/config/config-util/src/test/java/org/opendaylight/controller/config/util/ConfigRegistryClientsTest.java index 85397d2a20..4c99c7770a 100644 --- a/opendaylight/config/config-util/src/test/java/org/opendaylight/controller/config/util/ConfigRegistryClientsTest.java +++ b/opendaylight/config/config-util/src/test/java/org/opendaylight/controller/config/util/ConfigRegistryClientsTest.java @@ -7,49 +7,38 @@ */ package org.opendaylight.controller.config.util; -import static org.hamcrest.core.Is.is; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertThat; -import static org.junit.Assert.fail; -import static org.junit.matchers.JUnitMatchers.containsString; - -import java.lang.management.ManagementFactory; -import java.util.Set; +import com.google.common.collect.Sets; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.opendaylight.controller.config.api.ConfigRegistry; import javax.management.InstanceNotFoundException; import javax.management.MBeanServer; import javax.management.ObjectName; +import java.lang.management.ManagementFactory; +import java.util.Set; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import org.opendaylight.controller.config.api.ConfigRegistry; -import org.opendaylight.controller.config.api.ValidationException; -import org.opendaylight.controller.config.util.jolokia.ConfigRegistryJolokiaClient; +import static org.junit.Assert.assertEquals; public class ConfigRegistryClientsTest { - private String jolokiaURL; - private TestingConfigRegistry testingRegistry; private ObjectName testingRegistryON; private final MBeanServer mbs = ManagementFactory.getPlatformMBeanServer(); - private ConfigRegistryClient jmxRegistryClient, jolokiaRegistryClient; + private ConfigRegistryClient jmxRegistryClient; @Before public void setUp() throws Exception { - jolokiaURL = JolokiaHelper.startTestingJolokia(); testingRegistry = new TestingConfigRegistry(); testingRegistryON = ConfigRegistry.OBJECT_NAME; mbs.registerMBean(testingRegistry, testingRegistryON); jmxRegistryClient = new ConfigRegistryJMXClient( ManagementFactory.getPlatformMBeanServer()); - jolokiaRegistryClient = new ConfigRegistryJolokiaClient(jolokiaURL); } @After public void cleanUp() throws Exception { - JolokiaHelper.stopJolokia(); if (testingRegistryON != null) { mbs.unregisterMBean(testingRegistryON); } @@ -58,8 +47,7 @@ public class ConfigRegistryClientsTest { @Test public void testLookupRuntimeBeans() throws Exception { Set jmxLookup = lookupRuntimeBeans(jmxRegistryClient); - Set jolokiaLookup = lookupRuntimeBeans(jolokiaRegistryClient); - assertEquals(jmxLookup, jolokiaLookup); + assertEquals(Sets.newHashSet(testingRegistry.run2, testingRegistry.run1, testingRegistry.run3), jmxLookup); } private Set lookupRuntimeBeans(ConfigRegistryClient client) @@ -79,28 +67,19 @@ public class ConfigRegistryClientsTest { jmxRegistryClient, TestingConfigRegistry.moduleName1, TestingConfigRegistry.instName1); assertEquals(1, jmxLookup.size()); - Set jolokiaLookup = clientLookupRuntimeBeansWithModuleAndInstance( - jolokiaRegistryClient, TestingConfigRegistry.moduleName1, - TestingConfigRegistry.instName1); - assertEquals(jmxLookup, jolokiaLookup); + assertEquals(Sets.newHashSet(testingRegistry.run2), jmxLookup); jmxLookup = clientLookupRuntimeBeansWithModuleAndInstance( jmxRegistryClient, TestingConfigRegistry.moduleName2, TestingConfigRegistry.instName2); assertEquals(1, jmxLookup.size()); - jolokiaLookup = clientLookupRuntimeBeansWithModuleAndInstance( - jolokiaRegistryClient, TestingConfigRegistry.moduleName2, - TestingConfigRegistry.instName2); - assertEquals(jmxLookup, jolokiaLookup); + assertEquals(Sets.newHashSet(testingRegistry.run3), jmxLookup); jmxLookup = clientLookupRuntimeBeansWithModuleAndInstance( jmxRegistryClient, TestingConfigRegistry.moduleName1, TestingConfigRegistry.instName2); assertEquals(0, jmxLookup.size()); - jolokiaLookup = clientLookupRuntimeBeansWithModuleAndInstance( - jolokiaRegistryClient, TestingConfigRegistry.moduleName1, - TestingConfigRegistry.instName2); - assertEquals(jmxLookup, jolokiaLookup); + assertEquals(Sets.newHashSet(), jmxLookup); } private Set clientLookupRuntimeBeansWithModuleAndInstance( @@ -112,29 +91,4 @@ public class ConfigRegistryClientsTest { } return beans; } - - @Test - public void testValidationExceptionDeserialization() { - try { - jolokiaRegistryClient.commitConfig(null); - fail(); - } catch (ValidationException e) { - String moduleName = "moduleName", instanceName = "instanceName"; - assertThat(e.getFailedValidations().containsKey(moduleName), - is(true)); - assertThat(e.getFailedValidations().size(), is(1)); - assertThat(e.getFailedValidations().get(moduleName).size(), is(1)); - assertThat( - e.getFailedValidations().get(moduleName) - .containsKey(instanceName), is(true)); - assertThat( - e.getFailedValidations().get(moduleName).get(instanceName) - .getMessage(), is("message")); - assertThat( - e.getFailedValidations().get(moduleName).get(instanceName) - .getTrace(), - containsString("org.opendaylight.controller.config.util.TestingConfigRegistry.commitConfig")); - } - } - } diff --git a/opendaylight/config/config-util/src/test/java/org/opendaylight/controller/config/util/ConfigTransactionClientsTest.java b/opendaylight/config/config-util/src/test/java/org/opendaylight/controller/config/util/ConfigTransactionClientsTest.java index a6df1e91a5..5ce6d46799 100644 --- a/opendaylight/config/config-util/src/test/java/org/opendaylight/controller/config/util/ConfigTransactionClientsTest.java +++ b/opendaylight/config/config-util/src/test/java/org/opendaylight/controller/config/util/ConfigTransactionClientsTest.java @@ -7,47 +7,37 @@ */ package org.opendaylight.controller.config.util; -import static org.junit.Assert.assertEquals; - -import java.lang.management.ManagementFactory; -import java.util.Set; - -import javax.management.MBeanServer; -import javax.management.ObjectName; - +import com.google.common.collect.Sets; import org.junit.After; import org.junit.Before; import org.junit.Test; -import org.opendaylight.controller.config.api.jmx.ConfigTransactionControllerMXBean; import org.opendaylight.controller.config.api.jmx.ObjectNameUtil; -import org.opendaylight.controller.config.util.jolokia.ConfigTransactionJolokiaClient; -public class ConfigTransactionClientsTest { +import javax.management.MBeanServer; +import javax.management.ObjectName; +import java.lang.management.ManagementFactory; +import java.util.Set; +import static org.junit.Assert.assertEquals; + +public class ConfigTransactionClientsTest { private final MBeanServer mbs = ManagementFactory.getPlatformMBeanServer(); - private String jolokiaURL; - private ConfigTransactionControllerMXBean transactionController; + private TestingConfigTransactionController transactionController; private ObjectName transactionControllerON; - private ConfigTransactionClient jmxTransactionClient, - jolokiaTransactionClient; + private ConfigTransactionClient jmxTransactionClient; @Before public void setUp() throws Exception { - jolokiaURL = JolokiaHelper.startTestingJolokia(); transactionController = new TestingConfigTransactionController(); transactionControllerON = new ObjectName(ObjectNameUtil.ON_DOMAIN + ":" + ObjectNameUtil.TYPE_KEY + "=TransactionController"); mbs.registerMBean(transactionController, transactionControllerON); - jmxTransactionClient = new ConfigTransactionJMXClient(null, - transactionControllerON, + jmxTransactionClient = new ConfigTransactionJMXClient(null, transactionControllerON, ManagementFactory.getPlatformMBeanServer()); - jolokiaTransactionClient = new ConfigTransactionJolokiaClient( - jolokiaURL, transactionControllerON, null); } @After public void cleanUp() throws Exception { - JolokiaHelper.stopJolokia(); if (transactionControllerON != null) { mbs.unregisterMBean(transactionControllerON); } @@ -56,8 +46,8 @@ public class ConfigTransactionClientsTest { @Test public void testLookupConfigBeans() throws Exception { Set jmxLookup = testClientLookupConfigBeans(jmxTransactionClient); - Set jolokiaLookup = testClientLookupConfigBeans(jolokiaTransactionClient); - assertEquals(jmxLookup, jolokiaLookup); + assertEquals(Sets.newHashSet(transactionController.conf1, + transactionController.conf2, transactionController.conf3), jmxLookup); } private Set testClientLookupConfigBeans( @@ -69,5 +59,4 @@ public class ConfigTransactionClientsTest { assertEquals(3, beans.size()); return beans; } - } diff --git a/opendaylight/config/config-util/src/test/java/org/opendaylight/controller/config/util/JolokiaHelper.java b/opendaylight/config/config-util/src/test/java/org/opendaylight/controller/config/util/JolokiaHelper.java deleted file mode 100644 index c0a25861e9..0000000000 --- a/opendaylight/config/config-util/src/test/java/org/opendaylight/controller/config/util/JolokiaHelper.java +++ /dev/null @@ -1,54 +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.util; - -import org.jolokia.jvmagent.JolokiaServer; -import org.jolokia.jvmagent.JvmAgentConfig; - -public class JolokiaHelper { - private static JolokiaServer jolokiaServer; - - /** - * Bind to port 17777. By convention, ports above 10000 are used for testing - * and < 10000 for production - * - * @return url that can be passed to new J4pClient(url) - */ - public static String startTestingJolokia() { - return startJolokia("localhost", 17777); - } - - /** - * @return url that can be passed to new J4pClient(url) - * @throws IOException - */ - public static String startJolokia(String host, int port) { - String agentArgs = "host=" + host + ",port=" + port; - JvmAgentConfig config = new JvmAgentConfig(agentArgs); - Exception lastException = null; - for (int i = 0; i < 10; i++) { - try { - jolokiaServer = new JolokiaServer(config, false); - jolokiaServer.start(); - return "http://" + host + ":" + port + "/jolokia/"; - } catch (Exception e) { - lastException = e; - try { - Thread.sleep(100); - } catch (InterruptedException ie) { - ie.printStackTrace(); - } - } - } - throw new RuntimeException(lastException); - } - - public static void stopJolokia() { - jolokiaServer.stop(); - } -} diff --git a/opendaylight/config/config-util/src/test/java/org/opendaylight/controller/config/util/LookupTest.java b/opendaylight/config/config-util/src/test/java/org/opendaylight/controller/config/util/LookupTest.java index 52e934583e..4489762a47 100644 --- a/opendaylight/config/config-util/src/test/java/org/opendaylight/controller/config/util/LookupTest.java +++ b/opendaylight/config/config-util/src/test/java/org/opendaylight/controller/config/util/LookupTest.java @@ -7,20 +7,8 @@ */ package org.opendaylight.controller.config.util; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.fail; - -import java.lang.management.ManagementFactory; -import java.lang.reflect.Method; -import java.util.HashSet; -import java.util.Map; -import java.util.Map.Entry; -import java.util.Set; - -import javax.management.InstanceNotFoundException; -import javax.management.MBeanServer; -import javax.management.ObjectName; - +import com.google.common.collect.ImmutableMap; +import com.google.common.collect.Sets; import org.junit.After; import org.junit.Before; import org.junit.Test; @@ -28,35 +16,40 @@ import org.opendaylight.controller.config.api.ConfigRegistry; import org.opendaylight.controller.config.api.LookupRegistry; import org.opendaylight.controller.config.api.jmx.ConfigTransactionControllerMXBean; import org.opendaylight.controller.config.api.jmx.ObjectNameUtil; -import org.opendaylight.controller.config.util.jolokia.ConfigRegistryJolokiaClient; -import org.opendaylight.controller.config.util.jolokia.ConfigTransactionJolokiaClient; -import com.google.common.collect.ImmutableMap; -import com.google.common.collect.Sets; +import javax.management.InstanceNotFoundException; +import javax.management.MBeanServer; +import javax.management.ObjectName; +import java.lang.management.ManagementFactory; +import java.lang.reflect.Method; +import java.util.HashSet; +import java.util.Map; +import java.util.Map.Entry; +import java.util.Set; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.fail; public class LookupTest { - private String jolokiaURL; private TestingConfigRegistry testingRegistry; private ObjectName testingRegistryON; private final MBeanServer mbs = ManagementFactory.getPlatformMBeanServer(); - private ConfigRegistryClient jmxRegistryClient, jolokiaRegistryClient; + private ConfigRegistryClient jmxRegistryClient; private ConfigTransactionControllerMXBean testingTransactionController; private ObjectName testingTransactionControllerON; - private ConfigTransactionClient jmxTransactionClient, - jolokiaTransactionClient; + private ConfigTransactionClient jmxTransactionClient; Map> lookupProvidersToClients; @Before public void setUp() throws Exception { - jolokiaURL = JolokiaHelper.startTestingJolokia(); testingRegistry = new TestingConfigRegistry(); testingRegistryON = ConfigRegistry.OBJECT_NAME; mbs.registerMBean(testingRegistry, testingRegistryON); jmxRegistryClient = new ConfigRegistryJMXClient( ManagementFactory.getPlatformMBeanServer()); - jolokiaRegistryClient = new ConfigRegistryJolokiaClient(jolokiaURL); + testingTransactionController = new TestingConfigTransactionController(); testingTransactionControllerON = new ObjectName( @@ -68,16 +61,15 @@ public class LookupTest { jmxTransactionClient = new ConfigTransactionJMXClient(null, testingTransactionControllerON, ManagementFactory.getPlatformMBeanServer()); - jolokiaTransactionClient = new ConfigTransactionJolokiaClient( - jolokiaURL, testingTransactionControllerON, null); - HashSet registryClients = Sets.newHashSet(jmxRegistryClient, jolokiaRegistryClient); - HashSet configTransactionClients = Sets.newHashSet(jmxTransactionClient, jolokiaTransactionClient); - lookupProvidersToClients = ImmutableMap.of((LookupRegistry) testingRegistry, registryClients, testingTransactionController, configTransactionClients); + + HashSet registryClients = Sets.newHashSet(jmxRegistryClient); + HashSet configTransactionClients = Sets.newHashSet(jmxTransactionClient); + lookupProvidersToClients = ImmutableMap.of((LookupRegistry) testingRegistry, registryClients, + testingTransactionController, configTransactionClients); } @After public void cleanUp() throws Exception { - JolokiaHelper.stopJolokia(); mbs.unregisterMBean(testingRegistryON); mbs.unregisterMBean(testingTransactionControllerON); } diff --git a/opendaylight/config/config-util/src/test/java/org/opendaylight/controller/config/util/TestingConfigTransactionController.java b/opendaylight/config/config-util/src/test/java/org/opendaylight/controller/config/util/TestingConfigTransactionController.java index 0a845e1512..1c522f17b0 100644 --- a/opendaylight/config/config-util/src/test/java/org/opendaylight/controller/config/util/TestingConfigTransactionController.java +++ b/opendaylight/config/config-util/src/test/java/org/opendaylight/controller/config/util/TestingConfigTransactionController.java @@ -23,7 +23,7 @@ import com.google.common.collect.Sets; public class TestingConfigTransactionController implements ConfigTransactionControllerMXBean { - private final ObjectName conf1, conf2, conf3; + public final ObjectName conf1, conf2, conf3; public static final String moduleName1 = "moduleA"; public static final String moduleName2 = "moduleB"; diff --git a/opendaylight/config/config-util/src/test/java/org/opendaylight/controller/config/util/jolokia/ListableJolokiaClientTest.java b/opendaylight/config/config-util/src/test/java/org/opendaylight/controller/config/util/jolokia/ListableJolokiaClientTest.java deleted file mode 100644 index bff8006c51..0000000000 --- a/opendaylight/config/config-util/src/test/java/org/opendaylight/controller/config/util/jolokia/ListableJolokiaClientTest.java +++ /dev/null @@ -1,58 +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.util.jolokia; - -import static org.hamcrest.core.Is.is; -import static org.junit.Assert.assertThat; - -import java.util.HashMap; -import java.util.Map; - -import org.json.simple.JSONObject; -import org.json.simple.JSONValue; -import org.junit.Before; -import org.junit.Test; -import org.opendaylight.controller.config.api.ValidationException; -import org.opendaylight.controller.config.api.ValidationException.ExceptionMessageWithStackTrace; - -public class ListableJolokiaClientTest { - - private Map> failedValidations; - - private ValidationException val; - - private final static String ex = "{\"message\":null," - + "\"failedValidations\":" - + "{\"ifc2\":{\"impl1\":{\"message\":\"abc\",\"trace\":\"vvv\"}," - + "\"impl2\":{\"message\":\"abc2\",\"trace\":\"vvv2\"}}," - + "\"ifc1\":" - + "{\"impl1\":{\"message\":\"abc\",\"trace\":\"vvv\"}," - + "\"impl2\":{\"message\":\"abc2\",\"trace\":\"vvv2\"}}}," - + "\"localizedMessage\":null," + "\"cause\":null}"; - - @Before - public void setUp() { - failedValidations = new HashMap>(); - Map map1 = new HashMap(); - map1.put("impl1", new ExceptionMessageWithStackTrace("abc", "vvv")); - map1.put("impl2", new ExceptionMessageWithStackTrace("abc2", "vvv2")); - failedValidations.put("ifc1", map1); - failedValidations.put("ifc2", map1); - val = new ValidationException(failedValidations); - } - - @Test - public void testParsing() { - JSONObject e = (JSONObject) JSONValue.parse(ex); - ValidationException val2 = ListableJolokiaClient - .createValidationExceptionFromJSONObject(e); - assertThat(val2.getMessage(), is(val.getMessage())); - assertThat(val2.getFailedValidations(), is(val.getFailedValidations())); - } - -} diff --git a/opendaylight/config/pom.xml b/opendaylight/config/pom.xml index 99437979de..9f0145fffe 100644 --- a/opendaylight/config/pom.xml +++ b/opendaylight/config/pom.xml @@ -63,7 +63,6 @@ 5.0.0 0.6.2.201302030002 1.7.2 - 1.1.1 0.5.9-SNAPSHOT 0.6.0-SNAPSHOT 0.1.1-SNAPSHOT @@ -110,22 +109,6 @@ guava 14.0.1 - - org.jolokia - jolokia-core - ${jolokia.version} - - - org.jolokia - jolokia-jvm - ${jolokia.version} - agent - - - org.jolokia - jolokia-client-java - ${jolokia.version} - junit junit -- 2.36.6