You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@brooklyn.apache.org by he...@apache.org on 2020/11/12 14:04:01 UTC
[brooklyn-server] 02/02: allow just-in-time resolution for beans,
like we do for spec types
This is an automated email from the ASF dual-hosted git repository.
heneveld pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/brooklyn-server.git
commit f11e7cecda357256b7966dba685df0def2e832fd
Author: Alex Heneveld <al...@cloudsoftcorp.com>
AuthorDate: Thu Nov 12 13:49:57 2020 +0000
allow just-in-time resolution for beans, like we do for spec types
---
.../brooklyn/CustomTypeConfigYamlOsgiTest.java | 5 ---
.../camp/brooklyn/CustomTypeConfigYamlTest.java | 42 ++++++++--------------
.../core/typereg/BasicBrooklynTypeRegistry.java | 26 ++++++++++++--
3 files changed, 38 insertions(+), 35 deletions(-)
diff --git a/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/CustomTypeConfigYamlOsgiTest.java b/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/CustomTypeConfigYamlOsgiTest.java
index b727377..c442315 100644
--- a/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/CustomTypeConfigYamlOsgiTest.java
+++ b/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/CustomTypeConfigYamlOsgiTest.java
@@ -55,9 +55,4 @@ public class CustomTypeConfigYamlOsgiTest extends CustomTypeConfigYamlTest {
Asserts.assertEquals(b1n, 1);
}
- @Override // multiple type works in OSGi
- @Test
- public void TestRegisteredType_Inherited_OneStep_FailsInPojo() {
- doTestRegisteredType_Inherited();
- }
}
diff --git a/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/CustomTypeConfigYamlTest.java b/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/CustomTypeConfigYamlTest.java
index e99ffa8..1598f0b 100644
--- a/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/CustomTypeConfigYamlTest.java
+++ b/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/CustomTypeConfigYamlTest.java
@@ -323,33 +323,21 @@ public class CustomTypeConfigYamlTest extends AbstractYamlTest {
}
@Test
- public void TestRegisteredType_Inherited_OneStep_FailsInPojo() {
- Asserts.assertFailsWith(this::doTestRegisteredType_Inherited,
- e -> {
- Asserts.expectedFailureContainsIgnoreCase(Exceptions.collapseIncludingAllCausalMessages(e), "could not resolve", "custom-type-0");
- return true;
- });
- }
-
- protected void doTestRegisteredType_Inherited() {
- try {
- addCatalogItems(
- "brooklyn.catalog:",
- " version: " + TEST_VERSION,
- " items:",
- " - id: custom-type-0",
- " item:",
- " type: " + CustomTypeConfigYamlTest.TestingCustomType.class.getName(),
- " x: foo2",
- " - id: custom-type",
- " item:",
- " type: custom-type-0",
- " y: bar");
- lastDeployedEntity = deployWithTestingCustomTypeObjectConfig(true, true, false, "custom-type", CONF1_ANONYMOUS, false);
- assertLastDeployedKeysValueIsOurCustomTypeWithFieldValues(CONF1_ANONYMOUS, "foo2", "bar");
- } catch (Exception e) {
- throw Exceptions.propagate(e);
- }
+ public void TestRegisteredType_InheritFromPeer_nowWorksInPojoAndOsgi() throws Exception {
+ addCatalogItems(
+ "brooklyn.catalog:",
+ " version: " + TEST_VERSION,
+ " items:",
+ " - id: custom-type-0",
+ " item:",
+ " type: " + CustomTypeConfigYamlTest.TestingCustomType.class.getName(),
+ " x: foo2",
+ " - id: custom-type",
+ " item:",
+ " type: custom-type-0",
+ " y: bar");
+ lastDeployedEntity = deployWithTestingCustomTypeObjectConfig(true, true, false, "custom-type", CONF1_ANONYMOUS, false);
+ assertLastDeployedKeysValueIsOurCustomTypeWithFieldValues(CONF1_ANONYMOUS, "foo2", "bar");
}
@Test
diff --git a/core/src/main/java/org/apache/brooklyn/core/typereg/BasicBrooklynTypeRegistry.java b/core/src/main/java/org/apache/brooklyn/core/typereg/BasicBrooklynTypeRegistry.java
index 7b93ff7..9160fc1 100644
--- a/core/src/main/java/org/apache/brooklyn/core/typereg/BasicBrooklynTypeRegistry.java
+++ b/core/src/main/java/org/apache/brooklyn/core/typereg/BasicBrooklynTypeRegistry.java
@@ -258,7 +258,7 @@ public class BasicBrooklynTypeRegistry implements BrooklynTypeRegistry {
} else if (type.getKind()==RegisteredTypeKind.UNRESOLVED) {
if (constraint != null && constraint.getAlreadyEncounteredTypes().contains(type.getSymbolicName())) {
- throw new UnsupportedTypePlanException("Cannot create spec from type "+type+" (kind "+type.getKind()+"), recursive reference following "+constraint.getAlreadyEncounteredTypes());
+ throw new TypePlanException("Cannot create spec from type "+type+" (kind "+type.getKind()+"), recursive reference following "+constraint.getAlreadyEncounteredTypes());
} else {
// try just-in-time validation
@@ -354,8 +354,28 @@ public class BasicBrooklynTypeRegistry implements BrooklynTypeRegistry {
public <T> T createBean(RegisteredType type, @Nullable RegisteredTypeLoadingContext constraint, @Nullable Class<T> optionalResultSuperType) {
Preconditions.checkNotNull(type, "type");
if (type.getKind()!=RegisteredTypeKind.BEAN) {
- if (type.getKind()==RegisteredTypeKind.UNRESOLVED) throw new ReferencedUnresolvedTypeException(type);
- else throw new UnsupportedTypePlanException("Cannot create bean from type "+type+" (kind "+type.getKind()+")");
+ if (type.getKind()==RegisteredTypeKind.UNRESOLVED) {
+ // attempt to resolve
+ if (constraint != null && constraint.getAlreadyEncounteredTypes().contains(type.getSymbolicName())) {
+ throw new TypePlanException("Cannot create bean from type "+type+" (kind "+type.getKind()+"), recursive reference following "+constraint.getAlreadyEncounteredTypes());
+
+ } else {
+ // try just-in-time validation
+ Collection<Throwable> validationErrors = mgmt.getCatalog().validateType(type, constraint, false);
+ if (!validationErrors.isEmpty()) {
+ throw new ReferencedUnresolvedTypeException(type, true, Exceptions.create(validationErrors));
+ }
+ type = mgmt.getTypeRegistry().get(type.getSymbolicName(), type.getVersion());
+ if (type==null || type.getKind()==RegisteredTypeKind.UNRESOLVED) {
+ // shouldn't come here
+ throw new ReferencedUnresolvedTypeException(type);
+ }
+ // continue below to do transform
+ }
+
+ } else {
+ throw new UnsupportedTypePlanException("Cannot create bean from type "+type+" (kind "+type.getKind()+")");
+ }
}
if (constraint!=null) {
if (constraint.getExpectedKind()!=null && constraint.getExpectedKind()!=RegisteredTypeKind.SPEC) {