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
The following commit(s) were added to refs/heads/master by this push:
new 90ab5683aa stricter checking for entity supertype when loading an
entity reference
90ab5683aa is described below
commit 90ab5683aa251ad3af24782de863199844fa8eb9
Author: Alex Heneveld <[email protected]>
AuthorDate: Tue Dec 6 18:17:25 2022 +0000
stricter checking for entity supertype when loading an entity reference
---
.../brooklyn/camp/brooklyn/AbstractYamlTest.java | 4 +-
.../camp/brooklyn/ReferencedYamlOsgiTest.java | 6 +-
.../CatalogYamlEntityOsgiTypeRegistryTest.java | 4 +-
.../catalog/NestedRefsCatalogYamlTest.java | 95 ++++++++++++++++++++++
.../nested-refs-catalog-yaml-test.bom.yaml | 36 ++++++++
...nested-refs-catalog-yaml-workflow-test.bom.yaml | 26 ++++++
.../resolve/entity/CatalogEntitySpecResolver.java | 3 +-
.../core/typereg/BasicBrooklynTypeRegistry.java | 1 +
8 files changed, 170 insertions(+), 5 deletions(-)
diff --git
a/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/AbstractYamlTest.java
b/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/AbstractYamlTest.java
index 8141099ef9..4dc738575d 100644
---
a/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/AbstractYamlTest.java
+++
b/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/AbstractYamlTest.java
@@ -259,8 +259,8 @@ public abstract class AbstractYamlTest {
addCatalogItems(joinLines(catalogYaml));
}
- protected void addCatalogItems(String catalogYaml) {
- mgmt().getCatalog().addTypesAndValidateAllowInconsistent(catalogYaml,
null, forceUpdate);
+ protected Collection<RegisteredType> addCatalogItems(String catalogYaml) {
+ return
mgmt().getCatalog().addTypesAndValidateAllowInconsistent(catalogYaml, null,
forceUpdate);
}
/*
diff --git
a/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/ReferencedYamlOsgiTest.java
b/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/ReferencedYamlOsgiTest.java
index 0f982b8321..8c68d516be 100644
---
a/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/ReferencedYamlOsgiTest.java
+++
b/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/ReferencedYamlOsgiTest.java
@@ -18,9 +18,12 @@
*/
package org.apache.brooklyn.camp.brooklyn;
+import org.apache.brooklyn.api.typereg.RegisteredType;
import org.apache.brooklyn.util.osgi.VersionedName;
import org.testng.annotations.Test;
+import java.util.Collection;
+
/** like superclass, but with OSGi enabled, complex references now work */
public class ReferencedYamlOsgiTest extends ReferencedYamlTest {
@@ -30,8 +33,9 @@ public class ReferencedYamlOsgiTest extends
ReferencedYamlTest {
}
@Override
- protected void addCatalogItems(String catalogYaml) {
+ protected Collection<RegisteredType> addCatalogItems(String catalogYaml) {
addCatalogItemsAsOsgiWithoutStartingBundles(mgmt(), catalogYaml,
VersionedName.fromString("sample-bundle:0-SNAPSHOT"), isForceUpdate());
+ return null;
}
// these are not broken with OSGi
diff --git
a/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/catalog/CatalogYamlEntityOsgiTypeRegistryTest.java
b/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/catalog/CatalogYamlEntityOsgiTypeRegistryTest.java
index 87b3b78373..d73917f679 100644
---
a/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/catalog/CatalogYamlEntityOsgiTypeRegistryTest.java
+++
b/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/catalog/CatalogYamlEntityOsgiTypeRegistryTest.java
@@ -18,6 +18,7 @@
*/
package org.apache.brooklyn.camp.brooklyn.catalog;
+import java.util.Collection;
import java.util.List;
import java.util.Map;
import org.apache.brooklyn.api.typereg.RegisteredType;
@@ -58,7 +59,7 @@ public class CatalogYamlEntityOsgiTypeRegistryTest extends
CatalogYamlEntityTest
// use type registry approach
@Override
- protected void addCatalogItems(String catalogYaml) {
+ protected Collection<RegisteredType> addCatalogItems(String catalogYaml) {
boolean skipStart = false;
switch (itemsInstallMode!=null ? itemsInstallMode :
@@ -87,6 +88,7 @@ public class CatalogYamlEntityOsgiTypeRegistryTest extends
CatalogYamlEntityTest
addCatalogItemsAsOsgiInUsualWay(mgmt(), catalogYaml, null,
isForceUpdate());
break;
}
+ return null;
}
protected String bundleName() { return "sample-bundle"; }
diff --git
a/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/catalog/NestedRefsCatalogYamlTest.java
b/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/catalog/NestedRefsCatalogYamlTest.java
new file mode 100644
index 0000000000..7e82042241
--- /dev/null
+++
b/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/catalog/NestedRefsCatalogYamlTest.java
@@ -0,0 +1,95 @@
+/*
+ * 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 org.apache.brooklyn.camp.brooklyn.catalog;
+
+import com.google.common.base.Joiner;
+import com.google.common.base.Throwables;
+import com.google.common.collect.Iterables;
+import org.apache.brooklyn.api.catalog.BrooklynCatalog;
+import org.apache.brooklyn.api.entity.Entity;
+import org.apache.brooklyn.api.entity.EntitySpec;
+import org.apache.brooklyn.api.internal.AbstractBrooklynObjectSpec;
+import org.apache.brooklyn.api.objs.Identifiable;
+import org.apache.brooklyn.api.typereg.BrooklynTypeRegistry;
+import org.apache.brooklyn.api.typereg.BrooklynTypeRegistry.RegisteredTypeKind;
+import org.apache.brooklyn.api.typereg.RegisteredType;
+import org.apache.brooklyn.camp.brooklyn.AbstractYamlTest;
+import org.apache.brooklyn.camp.brooklyn.ConfigYamlTest;
+import org.apache.brooklyn.config.ConfigKey;
+import org.apache.brooklyn.core.catalog.internal.BasicBrooklynCatalog;
+import org.apache.brooklyn.core.catalog.internal.CatalogUtils;
+import org.apache.brooklyn.core.config.ConfigKeys;
+import org.apache.brooklyn.core.entity.Dumper;
+import org.apache.brooklyn.core.mgmt.BrooklynTags;
+import org.apache.brooklyn.core.mgmt.BrooklynTags.SpecSummary;
+import org.apache.brooklyn.core.test.entity.TestEntity;
+import org.apache.brooklyn.core.test.entity.TestEntityImpl;
+import org.apache.brooklyn.core.typereg.RegisteredTypes;
+import org.apache.brooklyn.core.workflow.WorkflowBasicTest;
+import org.apache.brooklyn.entity.stock.BasicApplication;
+import org.apache.brooklyn.entity.stock.BasicEntity;
+import org.apache.brooklyn.entity.stock.BasicEntityImpl;
+import org.apache.brooklyn.test.Asserts;
+import org.apache.brooklyn.util.collections.MutableList;
+import org.apache.brooklyn.util.collections.MutableSet;
+import org.apache.brooklyn.util.core.ResourceUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.testng.Assert;
+import org.testng.annotations.Test;
+
+import java.util.Collection;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import static com.google.common.base.Preconditions.checkNotNull;
+import static org.testng.Assert.*;
+
+
+public class NestedRefsCatalogYamlTest extends AbstractYamlTest {
+
+ private static final Logger LOG =
LoggerFactory.getLogger(NestedRefsCatalogYamlTest.class);
+
+ @Override
+ protected boolean disableOsgi() {
+ return false;
+ }
+
+ @Test
+ public void testManyAddCatalogItems() throws Exception {
+
+ /* test that invoke-effector doesn't cause confusion */
+
+// WorkflowBasicTest.addWorkflowStepTypes(mgmt());
+
+ Collection<RegisteredType> typesW =
addCatalogItems(ResourceUtils.create(this).getResourceAsString("classpath://nested-refs-catalog-yaml-workflow-test.bom.yaml"));
+ Map<RegisteredType, Collection<Throwable>> resultW =
mgmt().getCatalog().validateTypes(typesW);
+ if (!resultW.isEmpty()) {
+ Asserts.fail("Should be empty: " + resultW);
+ }
+
+ Collection<RegisteredType> types =
addCatalogItems(ResourceUtils.create(this).getResourceAsString("classpath://nested-refs-catalog-yaml-test.bom.yaml"));
+ Map<RegisteredType, Collection<Throwable>> result =
mgmt().getCatalog().validateTypes(types);
+ if (!result.isEmpty()) {
+ Asserts.fail("Should be empty: " + result);
+ }
+ }
+
+}
diff --git
a/camp/camp-brooklyn/src/test/resources/nested-refs-catalog-yaml-test.bom.yaml
b/camp/camp-brooklyn/src/test/resources/nested-refs-catalog-yaml-test.bom.yaml
new file mode 100644
index 0000000000..e867800eec
--- /dev/null
+++
b/camp/camp-brooklyn/src/test/resources/nested-refs-catalog-yaml-test.bom.yaml
@@ -0,0 +1,36 @@
+#
+# 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.
+#
+brooklyn.catalog:
+ bundle: test-bundle
+ version: "0.1.0-SNAPSHOT"
+ items:
+
+ - id: child
+ item:
+ type: parent
+ brooklyn.children:
+ - type: invoke-effector
+
+ - id: parent
+ item:
+ type: org.apache.brooklyn.entity.stock.BasicEntity
+
+ - id: invoke-effector
+ item:
+ type: org.apache.brooklyn.entity.stock.BasicEntity
diff --git
a/camp/camp-brooklyn/src/test/resources/nested-refs-catalog-yaml-workflow-test.bom.yaml
b/camp/camp-brooklyn/src/test/resources/nested-refs-catalog-yaml-workflow-test.bom.yaml
new file mode 100644
index 0000000000..4491574502
--- /dev/null
+++
b/camp/camp-brooklyn/src/test/resources/nested-refs-catalog-yaml-workflow-test.bom.yaml
@@ -0,0 +1,26 @@
+#
+# 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.
+#
+brooklyn.catalog:
+ bundle: test-bundle-workflow
+ version: "0.2-SNAPSHOT"
+ items:
+
+ - id: invoke-effector
+ item:
+ type:
org.apache.brooklyn.core.workflow.steps.appmodel.InvokeEffectorWorkflowStep
diff --git
a/core/src/main/java/org/apache/brooklyn/core/resolve/entity/CatalogEntitySpecResolver.java
b/core/src/main/java/org/apache/brooklyn/core/resolve/entity/CatalogEntitySpecResolver.java
index bc421a1518..e04be5fb4d 100644
---
a/core/src/main/java/org/apache/brooklyn/core/resolve/entity/CatalogEntitySpecResolver.java
+++
b/core/src/main/java/org/apache/brooklyn/core/resolve/entity/CatalogEntitySpecResolver.java
@@ -20,6 +20,7 @@ package org.apache.brooklyn.core.resolve.entity;
import java.util.Set;
+import org.apache.brooklyn.api.entity.Entity;
import org.apache.brooklyn.api.entity.EntitySpec;
import org.apache.brooklyn.api.mgmt.classloading.BrooklynClassLoadingContext;
import org.apache.brooklyn.api.typereg.RegisteredType;
@@ -77,7 +78,7 @@ public class CatalogEntitySpecResolver extends
AbstractEntitySpecResolver {
@Override
public EntitySpec<?> resolve(String type, BrooklynClassLoadingContext
loader, Set<String> parentEncounteredTypes) {
String localType = getLocalType(type);
- RegisteredType item = mgmt.getTypeRegistry().get(localType);
+ RegisteredType item = mgmt.getTypeRegistry().get(localType,
RegisteredTypeLoadingContexts.spec(Entity.class));
boolean upgradeRequired = item==null;
if (upgradeRequired) {
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 0e8431a87e..766841775a 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
@@ -32,6 +32,7 @@ import org.apache.brooklyn.api.catalog.CatalogItem;
import org.apache.brooklyn.api.catalog.CatalogItem.CatalogItemType;
import org.apache.brooklyn.api.internal.AbstractBrooklynObjectSpec;
import org.apache.brooklyn.api.mgmt.ManagementContext;
+import org.apache.brooklyn.api.objs.BrooklynObject;
import org.apache.brooklyn.api.typereg.BrooklynTypeRegistry;
import org.apache.brooklyn.api.typereg.RegisteredType;
import org.apache.brooklyn.api.typereg.RegisteredType.TypeImplementationPlan;