You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@brooklyn.apache.org by sv...@apache.org on 2017/04/11 13:11:49 UTC
[1/2] brooklyn-server git commit: Updates
BasicExternalConfigSupplierRegistry to use ClassLoaderUtils
Repository: brooklyn-server
Updated Branches:
refs/heads/master 486246510 -> a23d42ffb
Updates BasicExternalConfigSupplierRegistry to use ClassLoaderUtils
Project: http://git-wip-us.apache.org/repos/asf/brooklyn-server/repo
Commit: http://git-wip-us.apache.org/repos/asf/brooklyn-server/commit/736db3ee
Tree: http://git-wip-us.apache.org/repos/asf/brooklyn-server/tree/736db3ee
Diff: http://git-wip-us.apache.org/repos/asf/brooklyn-server/diff/736db3ee
Branch: refs/heads/master
Commit: 736db3ee40e6d5fbaca91e3514ecf6e484e7a9cd
Parents: ee367e2
Author: Martin Harris <gi...@nakomis.com>
Authored: Mon Apr 10 15:01:01 2017 +0100
Committer: Martin Harris <gi...@nakomis.com>
Committed: Tue Apr 11 13:46:52 2017 +0100
----------------------------------------------------------------------
.../BasicExternalConfigSupplierRegistry.java | 9 +++--
.../PrefixedDummyExternalConfigSupplier.java | 39 +++++++++++++++++++
.../UnprefixedDummyExternalConfigSupplier.java | 39 +++++++++++++++++++
.../brooklyn/util/javalang/Reflections.java | 11 +++++-
.../brooklyn/util/osgi/OsgiTestResources.java | 4 +-
.../brooklyn-test-osgi-com-example-entities.jar | Bin 21436 -> 22144 bytes
.../osgi/brooklyn-test-osgi-entities.jar | Bin 20814 -> 22075 bytes
7 files changed, 96 insertions(+), 6 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/736db3ee/core/src/main/java/org/apache/brooklyn/core/mgmt/internal/BasicExternalConfigSupplierRegistry.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/core/mgmt/internal/BasicExternalConfigSupplierRegistry.java b/core/src/main/java/org/apache/brooklyn/core/mgmt/internal/BasicExternalConfigSupplierRegistry.java
index c5dc551..7d303a3 100644
--- a/core/src/main/java/org/apache/brooklyn/core/mgmt/internal/BasicExternalConfigSupplierRegistry.java
+++ b/core/src/main/java/org/apache/brooklyn/core/mgmt/internal/BasicExternalConfigSupplierRegistry.java
@@ -27,6 +27,7 @@ import org.apache.brooklyn.core.config.ConfigPredicates;
import org.apache.brooklyn.core.config.ConfigUtils;
import org.apache.brooklyn.core.config.external.ExternalConfigSupplier;
import org.apache.brooklyn.core.internal.BrooklynProperties;
+import org.apache.brooklyn.util.core.ClassLoaderUtils;
import org.apache.brooklyn.util.exceptions.Exceptions;
import org.apache.brooklyn.util.guava.Maybe;
import org.apache.brooklyn.util.javalang.Reflections;
@@ -90,7 +91,6 @@ public class BasicExternalConfigSupplierRegistry implements ExternalConfigSuppli
String EXTERNAL_PROVIDER_PREFIX = "brooklyn.external.";
Map<String, Object> externalProviderProperties = mgmt.getConfig().submap(ConfigPredicates.nameStartsWith(EXTERNAL_PROVIDER_PREFIX)).asMapWithStringKeys();
- ClassLoader classloader = mgmt.getCatalogClassLoader();
List<Exception> exceptions = new LinkedList<Exception>();
for (String key : externalProviderProperties.keySet()) {
@@ -103,12 +103,13 @@ public class BasicExternalConfigSupplierRegistry implements ExternalConfigSuppli
BrooklynProperties config = ConfigUtils.filterForPrefixAndStrip(externalProviderProperties, key + ".");
try {
- Maybe<ExternalConfigSupplier> configSupplier = Reflections.invokeConstructorFromArgs(classloader, ExternalConfigSupplier.class, providerClassname, mgmt, name, config);
+ Class<ExternalConfigSupplier> supplierClass = (Class<ExternalConfigSupplier>)new ClassLoaderUtils(this, mgmt).loadClass(providerClassname);
+ Maybe<ExternalConfigSupplier> configSupplier = Reflections.invokeConstructorFromArgs(supplierClass, mgmt, name, config);
if (!configSupplier.isPresent()) {
- configSupplier = Reflections.invokeConstructorFromArgs(classloader, ExternalConfigSupplier.class, providerClassname, mgmt, name, config.asMapWithStringKeys());
+ configSupplier = Reflections.invokeConstructorFromArgs(supplierClass, mgmt, name, config.asMapWithStringKeys());
}
if (!configSupplier.isPresent()) {
- configSupplier = Reflections.invokeConstructorFromArgs(classloader, ExternalConfigSupplier.class, providerClassname, mgmt, name);
+ configSupplier = Reflections.invokeConstructorFromArgs(supplierClass, mgmt, name);
}
if (!configSupplier.isPresent()) {
throw new IllegalStateException("No matching constructor found in "+providerClassname);
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/736db3ee/utils/common/dependencies/osgi/com-example-entities/src/main/java/com/example/brooklyn/test/osgi/PrefixedDummyExternalConfigSupplier.java
----------------------------------------------------------------------
diff --git a/utils/common/dependencies/osgi/com-example-entities/src/main/java/com/example/brooklyn/test/osgi/PrefixedDummyExternalConfigSupplier.java b/utils/common/dependencies/osgi/com-example-entities/src/main/java/com/example/brooklyn/test/osgi/PrefixedDummyExternalConfigSupplier.java
new file mode 100644
index 0000000..a260913
--- /dev/null
+++ b/utils/common/dependencies/osgi/com-example-entities/src/main/java/com/example/brooklyn/test/osgi/PrefixedDummyExternalConfigSupplier.java
@@ -0,0 +1,39 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package com.example.brooklyn.test.osgi;
+
+import org.apache.brooklyn.core.config.external.ExternalConfigSupplier;
+import org.apache.brooklyn.api.mgmt.ManagementContext;
+
+public class PrefixedDummyExternalConfigSupplier implements ExternalConfigSupplier {
+
+ public PrefixedDummyExternalConfigSupplier(ManagementContext mgmt, String name) {
+
+ }
+
+ @Override
+ public String getName() {
+ return "DummyExternalConfigSupplier";
+ }
+
+ @Override
+ public String get(String key) {
+ return key;
+ }
+}
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/736db3ee/utils/common/dependencies/osgi/entities/src/main/java/org/apache/brooklyn/test/osgi/UnprefixedDummyExternalConfigSupplier.java
----------------------------------------------------------------------
diff --git a/utils/common/dependencies/osgi/entities/src/main/java/org/apache/brooklyn/test/osgi/UnprefixedDummyExternalConfigSupplier.java b/utils/common/dependencies/osgi/entities/src/main/java/org/apache/brooklyn/test/osgi/UnprefixedDummyExternalConfigSupplier.java
new file mode 100644
index 0000000..4a2003f
--- /dev/null
+++ b/utils/common/dependencies/osgi/entities/src/main/java/org/apache/brooklyn/test/osgi/UnprefixedDummyExternalConfigSupplier.java
@@ -0,0 +1,39 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package com.example.brooklyn.test.osgi;
+
+import org.apache.brooklyn.core.config.external.ExternalConfigSupplier;
+import org.apache.brooklyn.api.mgmt.ManagementContext;
+
+public class UnprefixedDummyExternalConfigSupplier implements ExternalConfigSupplier {
+
+ public UnprefixedDummyExternalConfigSupplier(ManagementContext mgmt, String name) {
+
+ }
+
+ @Override
+ public String getName() {
+ return "DummyExternalConfigSupplier";
+ }
+
+ @Override
+ public String get(String key) {
+ return key;
+ }
+}
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/736db3ee/utils/common/src/main/java/org/apache/brooklyn/util/javalang/Reflections.java
----------------------------------------------------------------------
diff --git a/utils/common/src/main/java/org/apache/brooklyn/util/javalang/Reflections.java b/utils/common/src/main/java/org/apache/brooklyn/util/javalang/Reflections.java
index abcaf47..beedc7f 100644
--- a/utils/common/src/main/java/org/apache/brooklyn/util/javalang/Reflections.java
+++ b/utils/common/src/main/java/org/apache/brooklyn/util/javalang/Reflections.java
@@ -101,6 +101,7 @@ public class Reflections {
return this;
}
+ /** @deprecated since 0.11.0, use {@link org.apache.brooklyn.util.core.ClassLoaderUtils} in a combination with {@link #invokeConstructorFromArgs(Class, Object...)} instead */
public Object loadInstance(String classname, Object...argValues) throws ReflectionNotFoundException, ReflectionAccessException {
Class<?> clazz = loadClass(classname);
Maybe<?> v = null;
@@ -112,12 +113,14 @@ public class Reflections {
}
throw new IllegalStateException("No suitable constructor for "+clazz+Arrays.toString(argValues));
}
+ /** @deprecated since 0.11.0, use {@link org.apache.brooklyn.util.core.ClassLoaderUtils} in a combination with {@link #invokeConstructorFromArgs(Class, Object...)} instead */
public Object loadInstance(String classname, Class<?>[] argTypes, Object[] argValues) throws ReflectionNotFoundException, ReflectionAccessException {
Class<?> clazz = loadClass(classname);
Constructor<?> constructor = loadConstructor(clazz, argTypes);
return loadInstance(constructor, argValues);
}
+ /** @deprecated since 0.11.0, use {@link org.apache.brooklyn.util.core.ClassLoaderUtils} in a combination with {@link #invokeConstructorFromArgs(Class, Object...)} instead */
public Object loadInstance(String classname) throws ReflectionNotFoundException, ReflectionAccessException {
Class<?> clazz = loadClass(classname);
try {
@@ -130,6 +133,7 @@ public class Reflections {
}
/** instantiates the given class from its binary name */
+ /** @deprecated since 0.11.0, use {@link org.apache.brooklyn.util.core.ClassLoaderUtils} in a combination with {@link #invokeConstructorFromArgs(Class, Object...)} instead */
public Class<?> loadClass(String classname) throws ReflectionNotFoundException {
try {
classname = findMappedNameAndLog(classRenameMap, classname);
@@ -142,7 +146,8 @@ public class Reflections {
throw new ReflectionNotFoundException("Failed to load class '" + classname + "' using class loader " + classLoader + ": " + Exceptions.collapseText(e), e);
}
}
-
+
+ /** @deprecated since 0.11.0, use {@link org.apache.brooklyn.util.core.ClassLoaderUtils} in a combination with {@link #invokeConstructorFromArgs(Class, Object...)} instead */
@SuppressWarnings("unchecked")
public <T> Class<? extends T> loadClass(String classname, Class<T> superType) throws ReflectionNotFoundException {
return (Class<? extends T>) loadClass(classname);
@@ -204,6 +209,7 @@ public class Reflections {
}
/** does not look through ancestors of outer class */
+ /** @deprecated since 0.11.0, use {@link org.apache.brooklyn.util.core.ClassLoaderUtils} in a combination with {@link #invokeConstructorFromArgs(Class, Object...)} instead */
public Class<?> loadInnerClassNotInheritted(String outerClassname, String innerClassname) throws ReflectionNotFoundException {
return loadClass(outerClassname + "$" + innerClassname);
}
@@ -253,11 +259,13 @@ public class Reflections {
}
/** As {@link #invokeConstructorFromArgs(Class, Object...)} but allowing more configurable input */
+ /** @deprecated since 0.11.0, use {@link org.apache.brooklyn.util.core.ClassLoaderUtils} in a combination with {@link #invokeConstructorFromArgs(Class, Object...)} instead */
public static Maybe<Object> invokeConstructorFromArgs(ClassLoader classLoader, String className, Object...argsArray) {
return invokeConstructorFromArgs(classLoader, null, className, argsArray);
}
/** As {@link #invokeConstructorFromArgs(Class, Object...)} but allowing more configurable input */
+ /** @deprecated since 0.11.0, use {@link org.apache.brooklyn.util.core.ClassLoaderUtils} in a combination with {@link #invokeConstructorFromArgs(Class, Object...)} instead */
@SuppressWarnings("unchecked")
public static <T> Maybe<T> invokeConstructorFromArgs(ClassLoader classLoader, Class<T> optionalSupertype, String className, Object...argsArray) {
Reflections reflections = new Reflections(classLoader);
@@ -269,6 +277,7 @@ public class Reflections {
}
/** As {@link #invokeConstructorFromArgs(Class, Object...)} but allowing more configurable input */
+ /** @deprecated since 0.11.0, use {@link org.apache.brooklyn.util.core.ClassLoaderUtils} in a combination with {@link #invokeConstructorFromArgs(Class, Object...)} instead */
public static <T> Maybe<T> invokeConstructorFromArgsUntyped(ClassLoader classLoader, String className, Object...argsArray) {
Reflections reflections = new Reflections(classLoader);
@SuppressWarnings("unchecked")
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/736db3ee/utils/common/src/test/java/org/apache/brooklyn/util/osgi/OsgiTestResources.java
----------------------------------------------------------------------
diff --git a/utils/common/src/test/java/org/apache/brooklyn/util/osgi/OsgiTestResources.java b/utils/common/src/test/java/org/apache/brooklyn/util/osgi/OsgiTestResources.java
index 7e19843..39ae99c 100644
--- a/utils/common/src/test/java/org/apache/brooklyn/util/osgi/OsgiTestResources.java
+++ b/utils/common/src/test/java/org/apache/brooklyn/util/osgi/OsgiTestResources.java
@@ -28,7 +28,6 @@ package org.apache.brooklyn.util.osgi;
*/
public class OsgiTestResources {
-
/**
* brooklyn-osgi-test-a_0.1.0 -
* defines TestA which has a "times" method and a static multiplier field;
@@ -41,6 +40,7 @@ public class OsgiTestResources {
* defines an entity and an application, to confirm it can be read and used by brooklyn
*/
public static final String BROOKLYN_TEST_OSGI_ENTITIES_SYMBOLIC_NAME_FINAL_PART = "brooklyn-test-osgi-entities";
+ public static final String BROOKLYN_TEST_OSGI_ENTITIES_VERSION = "0.1.0";
public static final String BROOKLYN_TEST_OSGI_ENTITIES_SYMBOLIC_NAME_FULL =
"org.apache.brooklyn.test.resources.osgi."+BROOKLYN_TEST_OSGI_ENTITIES_SYMBOLIC_NAME_FINAL_PART;
public static final String BROOKLYN_TEST_OSGI_ENTITIES_PATH = "/brooklyn/osgi/brooklyn-test-osgi-entities.jar";
@@ -51,6 +51,7 @@ public class OsgiTestResources {
public static final String BROOKLYN_TEST_OSGI_ENTITIES_SIMPLE_OBJECT = "org.apache.brooklyn.test.osgi.entities.SimpleObject";
public static final String BROOKLYN_TEST_OSGI_ENTITIES_SIMPLE_ENTITY_CONFIG_NAME = "simple.config";
public static final String BROOKLYN_TEST_OSGI_ENTITIES_SIMPLE_ENTITY_SENSOR_NAME = "simple.sensor";
+ public static final String BROOKLYN_TEST_OSGI_ENTITIES_UNPREFIXED_DUMMY_EXTERNAL_CONFIG_SUPPLIER = "com.example.brooklyn.test.osgi.UnprefixedDummyExternalConfigSupplier";
/**
* brooklyn-test-com-example-osgi-entities (v 0.1.0) -
@@ -73,6 +74,7 @@ public class OsgiTestResources {
public static final String BROOKLYN_TEST_OSGI_ENTITIES_COM_EXAMPLE_OBJECT = "com.example.brooklyn.test.osgi.entities.SimpleObject";
public static final String BROOKLYN_TEST_OSGI_ENTITIES_COM_EXAMPLE_ENTITY_CONFIG_NAME = "simple.config";
public static final String BROOKLYN_TEST_OSGI_ENTITIES_COM_EXAMPLE_ENTITY_SENSOR_NAME = "simple.sensor";
+ public static final String BROOKLYN_TEST_OSGI_ENTITIES_PREFIXED_DUMMY_EXTERNAL_CONFIG_SUPPLIER = "com.example.brooklyn.test.osgi.PrefixedDummyExternalConfigSupplier";
/**
* brooklyn-test-osgi-more-entities_0.1.0 -
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/736db3ee/utils/common/src/test/resources/brooklyn/osgi/brooklyn-test-osgi-com-example-entities.jar
----------------------------------------------------------------------
diff --git a/utils/common/src/test/resources/brooklyn/osgi/brooklyn-test-osgi-com-example-entities.jar b/utils/common/src/test/resources/brooklyn/osgi/brooklyn-test-osgi-com-example-entities.jar
index d92ab9f..c476d9d 100644
Binary files a/utils/common/src/test/resources/brooklyn/osgi/brooklyn-test-osgi-com-example-entities.jar and b/utils/common/src/test/resources/brooklyn/osgi/brooklyn-test-osgi-com-example-entities.jar differ
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/736db3ee/utils/common/src/test/resources/brooklyn/osgi/brooklyn-test-osgi-entities.jar
----------------------------------------------------------------------
diff --git a/utils/common/src/test/resources/brooklyn/osgi/brooklyn-test-osgi-entities.jar b/utils/common/src/test/resources/brooklyn/osgi/brooklyn-test-osgi-entities.jar
index 51d57bb..a9a2ecc 100644
Binary files a/utils/common/src/test/resources/brooklyn/osgi/brooklyn-test-osgi-entities.jar and b/utils/common/src/test/resources/brooklyn/osgi/brooklyn-test-osgi-entities.jar differ
[2/2] brooklyn-server git commit: Closes #625
Posted by sv...@apache.org.
Closes #625
Updates BasicExternalConfigSupplierRegistry to use ClassLoaderUtils
Project: http://git-wip-us.apache.org/repos/asf/brooklyn-server/repo
Commit: http://git-wip-us.apache.org/repos/asf/brooklyn-server/commit/a23d42ff
Tree: http://git-wip-us.apache.org/repos/asf/brooklyn-server/tree/a23d42ff
Diff: http://git-wip-us.apache.org/repos/asf/brooklyn-server/diff/a23d42ff
Branch: refs/heads/master
Commit: a23d42ffb7b86d81ded2382d039f13bcfb5cf417
Parents: 4862465 736db3e
Author: Svetoslav Neykov <sv...@cloudsoftcorp.com>
Authored: Tue Apr 11 16:11:30 2017 +0300
Committer: Svetoslav Neykov <sv...@cloudsoftcorp.com>
Committed: Tue Apr 11 16:11:30 2017 +0300
----------------------------------------------------------------------
.../BasicExternalConfigSupplierRegistry.java | 9 +++--
.../PrefixedDummyExternalConfigSupplier.java | 39 +++++++++++++++++++
.../UnprefixedDummyExternalConfigSupplier.java | 39 +++++++++++++++++++
.../brooklyn/util/javalang/Reflections.java | 11 +++++-
.../brooklyn/util/osgi/OsgiTestResources.java | 4 +-
.../brooklyn-test-osgi-com-example-entities.jar | Bin 21436 -> 22144 bytes
.../osgi/brooklyn-test-osgi-entities.jar | Bin 20814 -> 22075 bytes
7 files changed, 96 insertions(+), 6 deletions(-)
----------------------------------------------------------------------