* In some cases this may be set heuristically from context and so may not be accurate.
* Callers can set an explicit catalog item ID if inferencing is not correct.
+ *
+ * This should conform to OSGi specs for symbolic_name:version
+ * but weaker semantics are usually allowed so long as neither segment contains a : or whitespace.
*/
String getCatalogItemId();
diff --git a/camp/camp-brooklyn/src/main/java/org/apache/brooklyn/camp/brooklyn/spi/creation/BrooklynComponentTemplateResolver.java b/camp/camp-brooklyn/src/main/java/org/apache/brooklyn/camp/brooklyn/spi/creation/BrooklynComponentTemplateResolver.java
index 7e9b56279b..abc2e8ea87 100644
--- a/camp/camp-brooklyn/src/main/java/org/apache/brooklyn/camp/brooklyn/spi/creation/BrooklynComponentTemplateResolver.java
+++ b/camp/camp-brooklyn/src/main/java/org/apache/brooklyn/camp/brooklyn/spi/creation/BrooklynComponentTemplateResolver.java
@@ -30,7 +30,6 @@
import org.apache.brooklyn.api.entity.Entity;
import org.apache.brooklyn.api.entity.EntitySpec;
-import org.apache.brooklyn.api.framework.FrameworkLookup;
import org.apache.brooklyn.api.location.LocationSpec;
import org.apache.brooklyn.api.mgmt.ManagementContext;
import org.apache.brooklyn.api.mgmt.classloading.BrooklynClassLoadingContext;
@@ -39,8 +38,6 @@
import org.apache.brooklyn.camp.brooklyn.BrooklynCampConstants;
import org.apache.brooklyn.camp.brooklyn.BrooklynCampReservedKeys;
import org.apache.brooklyn.camp.brooklyn.spi.creation.service.CampServiceSpecResolver;
-import org.apache.brooklyn.camp.brooklyn.spi.creation.service.ServiceTypeResolver;
-import org.apache.brooklyn.camp.brooklyn.spi.creation.service.ServiceTypeResolverAdaptor;
import org.apache.brooklyn.camp.spi.AbstractResource;
import org.apache.brooklyn.camp.spi.ApplicationComponentTemplate;
import org.apache.brooklyn.camp.spi.AssemblyTemplate;
@@ -79,10 +76,9 @@
import com.google.common.collect.Maps;
/**
- * This generates instances of a template resolver that use a {@link ServiceTypeResolver}
+ * This generates instances of a template resolver that use a {@link EntitySpecResolver}
* to parse the {@code serviceType} line in the template.
*/
-@SuppressWarnings("deprecation") // Because of ServiceTypeResolver
public class BrooklynComponentTemplateResolver {
private static final Logger log = LoggerFactory.getLogger(BrooklynComponentTemplateResolver.class);
@@ -197,10 +193,7 @@ public EntitySpec resolveSpec(Set encounteredRegis
private List getServiceTypeResolverOverrides() {
List overrides = new ArrayList<>();
- Iterable loader = FrameworkLookup.lookupAll(ServiceTypeResolver.class, mgmt.getCatalogClassLoader());
- for (ServiceTypeResolver resolver : loader) {
- overrides.add(new ServiceTypeResolverAdaptor(this, resolver));
- }
+ // none for now -- previously supported ServiceTypeResolver service
return overrides;
}
diff --git a/camp/camp-brooklyn/src/main/java/org/apache/brooklyn/camp/brooklyn/spi/creation/service/BrooklynServiceTypeResolver.java b/camp/camp-brooklyn/src/main/java/org/apache/brooklyn/camp/brooklyn/spi/creation/service/BrooklynServiceTypeResolver.java
deleted file mode 100644
index f9c07e4e2a..0000000000
--- a/camp/camp-brooklyn/src/main/java/org/apache/brooklyn/camp/brooklyn/spi/creation/service/BrooklynServiceTypeResolver.java
+++ /dev/null
@@ -1,78 +0,0 @@
-/*
- * 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.spi.creation.service;
-
-import javax.annotation.Nullable;
-
-import org.apache.brooklyn.api.catalog.CatalogItem;
-import org.apache.brooklyn.api.entity.Entity;
-import org.apache.brooklyn.api.entity.EntitySpec;
-import org.apache.brooklyn.api.mgmt.ManagementContext;
-import org.apache.brooklyn.camp.brooklyn.spi.creation.BrooklynComponentTemplateResolver;
-import org.apache.brooklyn.camp.spi.PlatformComponentTemplate;
-import org.apache.brooklyn.core.catalog.internal.CatalogUtils;
-import org.apache.brooklyn.core.mgmt.persist.DeserializingClassRenamesProvider;
-import org.apache.brooklyn.core.resolve.entity.AbstractEntitySpecResolver;
-import org.apache.brooklyn.util.text.Strings;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * This converts {@link PlatformComponentTemplate} instances whose type is prefixed {@code brooklyn:}
- * to Brooklyn {@link EntitySpec} instances.
- *
- * @deprecated since 0.9.0, use {@link AbstractEntitySpecResolver} instead
- */
-@Deprecated
-public class BrooklynServiceTypeResolver implements ServiceTypeResolver {
-
- @SuppressWarnings("unused")
- private static final Logger LOG = LoggerFactory.getLogger(ServiceTypeResolver.class);
-
- public BrooklynServiceTypeResolver() {
- }
-
- @Override
- public String getTypePrefix() { return DEFAULT_TYPE_PREFIX; }
-
- @Override
- public String getBrooklynType(String serviceType) {
- return Strings.removeFromStart(serviceType, getTypePrefix() + ":").trim();
- }
-
- @Nullable
- @Override
- public CatalogItem> getCatalogItem(BrooklynComponentTemplateResolver resolver, String serviceType) {
- String type = getBrooklynType(serviceType);
- if (type != null) {
- return getCatalogItemImpl(resolver.getManagementContext(), type);
- } else {
- return null;
- }
- }
-
- @Override
- public void decorateSpec(BrooklynComponentTemplateResolver resolver, EntitySpec spec) {
- }
-
- protected CatalogItem> getCatalogItemImpl(ManagementContext mgmt, String brooklynType) {
- brooklynType = DeserializingClassRenamesProvider.INSTANCE.findMappedName(brooklynType);
- return CatalogUtils.getCatalogItemOptionalVersion(mgmt, Entity.class, brooklynType);
- }
-}
diff --git a/camp/camp-brooklyn/src/main/java/org/apache/brooklyn/camp/brooklyn/spi/creation/service/ServiceTypeResolver.java b/camp/camp-brooklyn/src/main/java/org/apache/brooklyn/camp/brooklyn/spi/creation/service/ServiceTypeResolver.java
deleted file mode 100644
index 14f855a605..0000000000
--- a/camp/camp-brooklyn/src/main/java/org/apache/brooklyn/camp/brooklyn/spi/creation/service/ServiceTypeResolver.java
+++ /dev/null
@@ -1,77 +0,0 @@
-/*
- * 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.spi.creation.service;
-
-import java.util.ServiceLoader;
-
-import org.apache.brooklyn.api.catalog.CatalogItem;
-import org.apache.brooklyn.api.entity.Entity;
-import org.apache.brooklyn.api.entity.EntitySpec;
-import org.apache.brooklyn.camp.brooklyn.spi.creation.BrooklynComponentTemplateResolver;
-import org.apache.brooklyn.core.resolve.entity.EntitySpecResolver;
-
-/**
- * Resolves and decorates {@link EntitySpec entity specifications} based on the {@code serviceType} in a template.
- *
- * The {@link #getTypePrefix()} method returns a string that should match the beginning of the
- * service type. The resolver implementation will use the rest of the service type information
- * to create and decorate an approprate {@link EntitySpec entity}.
- *
- * The resolvers are loaded using the {@link ServiceLoader} mechanism, allowing external libraries
- * to add extra service type implementations that will be picked up at runtime.
- *
- * @see BrooklynServiceTypeResolver
- * @see ChefServiceTypeResolver
- *
- * @deprecated since 0.9.0, {@link EntitySpecResolver} instead.
- */
-@Deprecated
-public interface ServiceTypeResolver {
-
- String DEFAULT_TYPE_PREFIX = "brooklyn";
-
- /**
- * The service type prefix the resolver is responsible for.
- */
- String getTypePrefix();
-
- /**
- * The name of the Java type that Brooklyn will instantiate to create the
- * service. This can be generated from parts of the service type information
- * or may be a fixed value.
- */
- String getBrooklynType(String serviceType);
-
- /**
- * Returns the {@link CatalogItem} if there is one for the given type.
- *
- * If no type, callers should fall back to default classloading.
- */
- CatalogItem> getCatalogItem(BrooklynComponentTemplateResolver resolver, String serviceType);
-
- /**
- * Takes the provided {@link EntitySpec} and decorates it appropriately for the service type.
- *
- * This includes setting configuration and adding policies, enrichers and initializers.
- *
- * @see BrooklynServiceTypeResolver#decorateSpec(BrooklynComponentTemplateResolver, EntitySpec)
- */
- void decorateSpec(BrooklynComponentTemplateResolver resolver, EntitySpec spec);
-
-}
diff --git a/camp/camp-brooklyn/src/main/java/org/apache/brooklyn/camp/brooklyn/spi/creation/service/ServiceTypeResolverAdaptor.java b/camp/camp-brooklyn/src/main/java/org/apache/brooklyn/camp/brooklyn/spi/creation/service/ServiceTypeResolverAdaptor.java
deleted file mode 100644
index d4cf6e955c..0000000000
--- a/camp/camp-brooklyn/src/main/java/org/apache/brooklyn/camp/brooklyn/spi/creation/service/ServiceTypeResolverAdaptor.java
+++ /dev/null
@@ -1,70 +0,0 @@
-/*
- * 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.spi.creation.service;
-
-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.camp.brooklyn.spi.creation.BrooklynComponentTemplateResolver;
-import org.apache.brooklyn.core.resolve.entity.AbstractEntitySpecResolver;
-import org.apache.brooklyn.core.resolve.entity.EntitySpecResolver;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import com.google.common.base.Splitter;
-
-@SuppressWarnings("deprecation")
-public class ServiceTypeResolverAdaptor extends AbstractEntitySpecResolver {
- private static final Logger log = LoggerFactory.getLogger(ServiceTypeResolverAdaptor.class);
- private ServiceTypeResolver serviceTypeResolver;
- private BrooklynComponentTemplateResolver resolver;
-
- public ServiceTypeResolverAdaptor(BrooklynComponentTemplateResolver resolver, ServiceTypeResolver serviceTypeResolver) {
- super(serviceTypeResolver.getTypePrefix());
- this.serviceTypeResolver = serviceTypeResolver;
- this.resolver = resolver;
- }
-
- @Override
- public boolean accepts(String type, BrooklynClassLoadingContext loader) {
- if (type.indexOf(':') != -1) {
- String prefix = Splitter.on(":").splitToList(type).get(0);
- return prefix.equals(serviceTypeResolver.getTypePrefix());
- } else {
- return false;
- }
- }
-
- @SuppressWarnings({ "unchecked", "rawtypes" })
- @Override
- public EntitySpec> resolve(String type, BrooklynClassLoadingContext loader, Set encounteredTypes) {
- // Assume this is interface! Only known implementation is DockerServiceTypeResolver.
- String brooklynType = serviceTypeResolver.getBrooklynType(type);
- Class extends Entity> javaType = loader.loadClass(brooklynType, Entity.class);
- if (!javaType.isInterface()) {
- log.warn("Using " + ServiceTypeResolver.class.getSimpleName() + " with a non-interface type - this usage is not supported. Use " + EntitySpecResolver.class.getSimpleName() + " instead.");
- }
- EntitySpec> spec = EntitySpec.create((Class)javaType);
- serviceTypeResolver.decorateSpec(resolver, spec);
- return spec;
- }
-
-}
diff --git a/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/spi/creation/service/ServiceTypeResolverTest.java b/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/spi/creation/service/ServiceTypeResolverTest.java
deleted file mode 100644
index cbaccf050e..0000000000
--- a/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/spi/creation/service/ServiceTypeResolverTest.java
+++ /dev/null
@@ -1,39 +0,0 @@
-/*
- * 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.spi.creation.service;
-
-import static org.testng.Assert.assertEquals;
-
-import org.apache.brooklyn.api.entity.EntitySpec;
-import org.apache.brooklyn.camp.brooklyn.AbstractYamlTest;
-import org.apache.brooklyn.entity.stock.BasicEntity;
-import org.testng.annotations.Test;
-
-
-public class ServiceTypeResolverTest extends AbstractYamlTest {
-
- @Test
- public void testAddCatalogItemVerySimple() throws Exception {
- EntitySpec> spec = createAppEntitySpec(
- "services:",
- "- type: \"test-resolver:" + BasicEntity.class.getName() + "\"");
- assertEquals(spec.getChildren().get(0).getFlags().get("resolver"), TestServiceTypeResolver.class);
- }
-
-}
diff --git a/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/spi/creation/service/TestServiceTypeResolver.java b/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/spi/creation/service/TestServiceTypeResolver.java
deleted file mode 100644
index 7fd6d8a91e..0000000000
--- a/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/spi/creation/service/TestServiceTypeResolver.java
+++ /dev/null
@@ -1,54 +0,0 @@
-/*
- * 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.spi.creation.service;
-
-import org.apache.brooklyn.api.catalog.CatalogItem;
-import org.apache.brooklyn.api.entity.Entity;
-import org.apache.brooklyn.api.entity.EntitySpec;
-import org.apache.brooklyn.camp.brooklyn.spi.creation.BrooklynComponentTemplateResolver;
-import org.apache.brooklyn.core.catalog.internal.CatalogUtils;
-import org.apache.brooklyn.util.text.Strings;
-
-@SuppressWarnings("deprecation")
-public class TestServiceTypeResolver implements ServiceTypeResolver {
-
- private static final String PREFIX = "test-resolver";
-
- @Override
- public String getTypePrefix() {
- return PREFIX;
- }
-
- @Override
- public String getBrooklynType(String serviceType) {
- return Strings.removeFromStart(serviceType, PREFIX + ":");
- }
-
- @SuppressWarnings("unchecked")
- @Override
- public CatalogItem> getCatalogItem(BrooklynComponentTemplateResolver resolver, String serviceType) {
- return (CatalogItem>) CatalogUtils.getCatalogItemOptionalVersion(resolver.getManagementContext(), getBrooklynType(serviceType));
- }
-
- @Override
- public void decorateSpec(BrooklynComponentTemplateResolver resolver, EntitySpec spec) {
- spec.configure("resolver", TestServiceTypeResolver.class);
- }
-
-}
diff --git a/camp/camp-brooklyn/src/test/resources/META-INF/services/org.apache.brooklyn.camp.brooklyn.spi.creation.service.ServiceTypeResolver b/camp/camp-brooklyn/src/test/resources/META-INF/services/org.apache.brooklyn.camp.brooklyn.spi.creation.service.ServiceTypeResolver
deleted file mode 100644
index 3bba7fb58b..0000000000
--- a/camp/camp-brooklyn/src/test/resources/META-INF/services/org.apache.brooklyn.camp.brooklyn.spi.creation.service.ServiceTypeResolver
+++ /dev/null
@@ -1,19 +0,0 @@
-#
-# 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.
-#
-org.apache.brooklyn.camp.brooklyn.spi.creation.service.TestServiceTypeResolver
\ No newline at end of file
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 5715b66def..3817665c44 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
@@ -46,6 +46,7 @@
import org.apache.brooklyn.core.mgmt.internal.CampYamlParser;
import org.apache.brooklyn.core.mgmt.internal.ManagementContextInternal;
import org.apache.brooklyn.core.typereg.BrooklynTypePlanTransformer;
+import org.apache.brooklyn.core.typereg.RegisteredTypeNaming;
import org.apache.brooklyn.util.collections.MutableList;
import org.apache.brooklyn.util.collections.MutableMap;
import org.apache.brooklyn.util.collections.MutableSet;
@@ -601,14 +602,34 @@ private void collectCatalogItems(String sourceYaml, Map,?> itemMetadata, List<
// if symname not set, infer from: id, then name, then item id, then item name
if (Strings.isBlank(symbolicName)) {
if (Strings.isNonBlank(id)) {
- if (CatalogUtils.looksLikeVersionedId(id)) {
+ if (RegisteredTypeNaming.isGoodTypeColonVersion(id)) {
symbolicName = CatalogUtils.getSymbolicNameFromVersionedId(id);
+ } else if (CatalogUtils.looksLikeVersionedId(id)) {
+ // use of above method is deprecated in 0.12; this block can be removed in 0.13
+ log.warn("Discouraged version syntax in id '"+id+"'; version should comply with OSGi specs (#.#.#.qualifier or portion) or specify symbolic name and version explicitly");
+ symbolicName = CatalogUtils.getSymbolicNameFromVersionedId(id);
+ } else if (RegisteredTypeNaming.isUsableTypeColonVersion(id)) {
+ log.warn("Deprecated type naming syntax in id '"+id+"'; colons not allowed in type name as it is used to indicate version");
+ // deprecated in 0.12; from 0.13 this can change to treat part after the colon as version, also see line to set version below
+ // (may optionally warn or disallow if we want to require OSGi versions)
+ // symbolicName = CatalogUtils.getSymbolicNameFromVersionedId(id);
+ symbolicName = id;
} else {
symbolicName = id;
}
} else if (Strings.isNonBlank(name)) {
- if (CatalogUtils.looksLikeVersionedId(name)) {
+ if (RegisteredTypeNaming.isGoodTypeColonVersion(name)) {
+ log.warn("Deprecated use of 'name' key to define '"+name+"'; version should be specified within 'id' key or with 'version' key, not this tag");
+ // deprecated in 0.12; remove in 0.13
+ symbolicName = CatalogUtils.getSymbolicNameFromVersionedId(name);
+ } else if (CatalogUtils.looksLikeVersionedId(name)) {
+ log.warn("Deprecated use of 'name' key to define '"+name+"'; version should be specified within 'id' key or with 'version' key, not this tag");
+ // deprecated in 0.12; remove in 0.13
symbolicName = CatalogUtils.getSymbolicNameFromVersionedId(name);
+ } else if (RegisteredTypeNaming.isUsableTypeColonVersion(name)) {
+ log.warn("Deprecated type naming syntax in id '"+id+"'; colons not allowed in type name as it is used to indicate version");
+ // deprecated in 0.12; throw error if we want in 0.13
+ symbolicName = name;
} else {
symbolicName = name;
}
@@ -624,18 +645,35 @@ private void collectCatalogItems(String sourceYaml, Map,?> itemMetadata, List<
}
}
+ String versionFromId = null;
+ if (RegisteredTypeNaming.isGoodTypeColonVersion(id)) {
+ versionFromId = CatalogUtils.getVersionFromVersionedId(id);
+ } else if (CatalogUtils.looksLikeVersionedId(id)) {
+ log.warn("Discouraged version syntax in id '"+id+"'; version should comply with OSGi specs (#.#.#.qualifier or portion) or specify symbolic name and version explicitly");
+ // remove in 0.13
+ versionFromId = CatalogUtils.getVersionFromVersionedId(id);
+ } else if (RegisteredTypeNaming.isUsableTypeColonVersion(id)) {
+ // deprecated in 0.12, with warning above; from 0.13 this can be uncommented to treat part after the colon as version
+ // (may optionally warn or disallow if we want to require OSGi versions)
+ // if comparable section above is changed, change this to:
+ // versionFromId = CatalogUtils.getVersionFromVersionedId(id);
+ }
+
// if version not set, infer from: id, then from name, then item version
- if (CatalogUtils.looksLikeVersionedId(id)) {
- String versionFromId = CatalogUtils.getVersionFromVersionedId(id);
- if (versionFromId != null && Strings.isNonBlank(version) && !versionFromId.equals(version)) {
+ if (versionFromId!=null) {
+ if (Strings.isNonBlank(version) && !versionFromId.equals(version)) {
throw new IllegalArgumentException("Discrepency between version set in id " + versionFromId + " and version property " + version);
}
version = versionFromId;
}
+
if (Strings.isBlank(version)) {
if (CatalogUtils.looksLikeVersionedId(name)) {
+ // deprecated in 0.12, remove in 0.13
+ log.warn("Deprecated use of 'name' key to define '"+name+"'; version should be specified within 'id' key or with 'version' key, not this tag");
version = CatalogUtils.getVersionFromVersionedId(name);
- } else if (Strings.isBlank(version)) {
+ }
+ if (Strings.isBlank(version)) {
version = setFromItemIfUnset(version, itemAsMap, "version");
version = setFromItemIfUnset(version, itemAsMap, "template_version");
if (version==null) {
@@ -855,24 +893,50 @@ private boolean attemptType(String key, CatalogItemType candidateCiType) {
}
// first look in collected items, if a key is given
String type = (String) item.get("type");
- String version = null;
- if (CatalogUtils.looksLikeVersionedId(type)) {
- version = CatalogUtils.getVersionFromVersionedId(type);
- type = CatalogUtils.getSymbolicNameFromVersionedId(type);
- }
+
if (type!=null && key!=null) {
for (CatalogItemDtoAbstract,?> candidate: itemsDefinedSoFar) {
if (candidateCiType == candidate.getCatalogItemType() &&
(type.equals(candidate.getSymbolicName()) || type.equals(candidate.getId()))) {
- if (version==null || version.equals(candidate.getVersion())) {
- // matched - exit
- catalogItemType = candidateCiType;
- planYaml = candidateYaml;
- resolved = true;
- return true;
+ // matched - exit
+ catalogItemType = candidateCiType;
+ planYaml = candidateYaml;
+ resolved = true;
+ return true;
+ }
+ }
+ }
+ {
+ // legacy routine; should be the same as above code added in 0.12 because:
+ // if type is symbolic_name, the type will match above, and version will be null so any version allowed to match
+ // if type is symbolic_name:version, the id will match, and the version will also have to match
+ // SHOULD NEVER NEED THIS - remove during or after 0.13
+ String typeWithId = type;
+ String version = null;
+ if (CatalogUtils.looksLikeVersionedId(type)) {
+ version = CatalogUtils.getVersionFromVersionedId(type);
+ type = CatalogUtils.getSymbolicNameFromVersionedId(type);
+ }
+ if (type!=null && key!=null) {
+ for (CatalogItemDtoAbstract,?> candidate: itemsDefinedSoFar) {
+ if (candidateCiType == candidate.getCatalogItemType() &&
+ (type.equals(candidate.getSymbolicName()) || type.equals(candidate.getId()))) {
+ if (version==null || version.equals(candidate.getVersion())) {
+ log.error("Lookup of '"+type+"' version '"+version+"' only worked using legacy routines; please advise Brooklyn community so they understand why");
+ // matched - exit
+ catalogItemType = candidateCiType;
+ planYaml = candidateYaml;
+ resolved = true;
+ return true;
+ }
}
}
}
+
+ type = typeWithId;
+ // above line is a change to behaviour; previously we proceeded below with the version dropped in code above;
+ // but that seems like a bug as the code below will have ignored version.
+ // likely this means we are now stricter about loading things that reference new versions, but correctly so.
}
// then try parsing plan - this will use loader
diff --git a/core/src/main/java/org/apache/brooklyn/core/catalog/internal/CatalogItemDtoAbstract.java b/core/src/main/java/org/apache/brooklyn/core/catalog/internal/CatalogItemDtoAbstract.java
index 4644d8d901..3f69e677ad 100644
--- a/core/src/main/java/org/apache/brooklyn/core/catalog/internal/CatalogItemDtoAbstract.java
+++ b/core/src/main/java/org/apache/brooklyn/core/catalog/internal/CatalogItemDtoAbstract.java
@@ -33,6 +33,7 @@
import org.apache.brooklyn.core.mgmt.rebind.BasicCatalogItemRebindSupport;
import org.apache.brooklyn.core.objs.AbstractBrooklynObject;
import org.apache.brooklyn.core.relations.EmptyRelationSupport;
+import org.apache.brooklyn.core.typereg.RegisteredTypeNaming;
import org.apache.brooklyn.util.collections.MutableList;
import org.apache.brooklyn.util.core.flags.FlagUtils;
import org.apache.brooklyn.util.core.flags.SetFromFlag;
@@ -386,6 +387,16 @@ protected void setTags(Set