give better/earlier error if 'services' and 'type' supplied in same block
diff --git a/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/ApplicationsYamlTest.java b/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/ApplicationsYamlTest.java
index 656a478..561578a 100644
--- a/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/ApplicationsYamlTest.java
+++ b/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/ApplicationsYamlTest.java
@@ -446,6 +446,21 @@
e -> Asserts.expectedFailureContains(e, "not_a_real_service"));
}
+ @Test
+ public void testGoodErrorOnServicesBlockWithType() throws Exception {
+ Asserts.assertFailsWith(() -> {
+ addCatalogItems(
+ "brooklyn.catalog:",
+ " id: simple-test",
+ " version: " + TEST_VERSION,
+ "type: foo",
+ "services:",
+ "- type: "+BasicEntity.class.getName());
+ RegisteredType t = mgmt().getTypeRegistry().get("simple-test", TEST_VERSION);
+ return t+" - "+t.getSuperTypes();
+ },
+ e -> Asserts.expectedFailureContains(e, "Blueprint contains both a 'services' block and a 'type' specification"));
+ }
@Override
protected Logger getLogger() {
diff --git a/core/src/main/java/org/apache/brooklyn/core/catalog/internal/BasicBrooklynCatalog.java b/core/src/main/java/org/apache/brooklyn/core/catalog/internal/BasicBrooklynCatalog.java
index b601fad..e3a9208 100644
--- a/core/src/main/java/org/apache/brooklyn/core/catalog/internal/BasicBrooklynCatalog.java
+++ b/core/src/main/java/org/apache/brooklyn/core/catalog/internal/BasicBrooklynCatalog.java
@@ -980,8 +980,12 @@
if (!tags.contains(BrooklynTags.CATALOG_TEMPLATE)) {
if (requireValidation) {
throw Exceptions.propagate(resolutionError);
+ } else {
+ // normally if validation not requested (eg because we are adding multiple bundles and might have forward references,
+ // we add (below) as unresolved, and then do validation later; but that validation doesn't check basic problems,
+ // on those it makes sense to fail fast.
+ planInterpreter.checkResolution(true);
}
- // warn? add as "unresolved" ? just do nothing?
}
}
@@ -1364,6 +1368,11 @@
}
public void resolve() {
+ resolveWithoutChecking();
+ checkResolution(false);
+ }
+
+ public void resolveWithoutChecking() {
try {
currentlyResolvingType.set(Strings.isBlank(itemId) ? itemYaml : itemId);
@@ -1414,6 +1423,25 @@
}
}
+ public void checkResolution(boolean failOnBasicProblems) {
+ if (!failOnBasicProblems && !isResolved()) return;
+
+ if (item!=null) {
+ if (CatalogItemType.ENTITY.equals(catalogItemType)) {
+ if (item.containsKey("services")) {
+ if (item.containsKey("type")) {
+ resolved = false;
+ IllegalArgumentException error = new IllegalArgumentException("Blueprint contains both a 'services' block and a 'type' specification; not permitted");
+ if (failOnBasicProblems) throw error;
+ this.errors.add(error);
+ return;
+ }
+ }
+ }
+
+ }
+ }
+
private void attemptLegacySpecTransformersForVariousSpecTypes() {
attemptLegacySpecTransformersForType(CatalogItemType.ENTITY);