Github user sjcorbett commented on a diff in the pull request:
https://github.com/apache/incubator-brooklyn/pull/955#discussion_r42050791
--- Diff:
usage/camp/src/main/java/org/apache/brooklyn/camp/brooklyn/spi/creation/BrooklynComponentTemplateResolver.java
---
@@ -168,156 +139,60 @@ public static String getDeclaredType(String
knownServiceType, AbstractResource o
private static String extractServiceTypeAttribute(@Nullable
ConfigBag attrs) {
return
BrooklynYamlTypeInstantiator.InstantiatorFromKey.extractTypeName("service",
attrs).orNull();
}
-
- public static boolean supportsType(BrooklynClassLoadingContext
context, String serviceType) {
- ServiceTypeResolver typeResolver =
computeResolverType(context, serviceType, null, null);
- if (typeResolver != null) return true;
- return newInstance(context, serviceType).canResolve();
- }
- }
-
- protected boolean canResolve() {
- CatalogItem<Entity, EntitySpec<?>> item =
typeResolver.getCatalogItem(this, type);
- if (item == null) {
- return loader.tryLoadClass(getJavaType(),
Entity.class).isPresent();
- }
-
- if (item.isDisabled()) {
- log.warn("Disallowed attempt to use disabled catalog item
"+item.getId());
- return false;
- } else if (item.isDeprecated()) {
- log.warn("Use of deprecated catalog item "+item.getId());
- }
- return true;
}
- /** returns the entity class, if needed in contexts which scan its
statics for example */
- protected Class<? extends Entity> loadEntityClass() {
- Maybe<Class<? extends Entity>> result = tryLoadEntityClass();
- if (result.isAbsent())
- throw new IllegalStateException("Could not find
"+typeResolver.getBrooklynType(type), ((Maybe.Absent<?>)result).getException());
- return result.get();
+ public boolean canResolve() {
+ return serviceSpecResolver.accepts(type, loader);
}
- /** tries to load the Java entity class */
- protected Maybe<Class<? extends Entity>> tryLoadEntityClass() {
- return loader.tryLoadClass(getJavaType(), Entity.class);
- }
-
- // TODO Generalise to have other prefixes (e.g. explicit "catalog:"
etc)?
- protected boolean isJavaTypePrefix() {
- return type != null && (type.toLowerCase().startsWith("java:") ||
type.toLowerCase().startsWith("brooklyn:java:"));
- }
-
- protected String getJavaType() {
- CatalogItem<Entity, EntitySpec<?>> item =
typeResolver.getCatalogItem(this, type);
- if (!isJavaTypePrefix() && item != null && item.getJavaType() !=
null) {
- return item.getJavaType();
- } else {
- return typeResolver.getBrooklynType(type);
- }
- }
-
- /** resolves the spec, updating the loader if a catalog item is loaded
*/
- @SuppressWarnings("unchecked")
- protected <T extends Entity> EntitySpec<T> resolveSpec(Set<String>
encounteredCatalogTypes, boolean canUseOtherTransformers) {
+ public <T extends Entity> EntitySpec<T> resolveSpec(Set<String>
encounteredCatalogTypes) {
if (alreadyBuilt.getAndSet(true))
throw new IllegalStateException("Spec can only be used once:
"+this);
- CatalogItem<Entity, EntitySpec<?>> item =
getServiceTypeResolver().getCatalogItem(this, getDeclaredType());
- try {
- EntitySpec<T> spec = createSpec(item, encounteredCatalogTypes);
- populateSpec(spec);
- return spec;
- } catch (Exception e) {
- Exceptions.propagateIfFatal(e);
-
- // maybe it requires a different transformer? TODO better
would be to know this from a transformer type on the catalog item type
- if (item!=null && canUseOtherTransformers) {
- log.debug("Could not resolve child "+item+" as CAMP;
trying other transformers: "+e);
- // should only be called when resolving children. and
encountered types should probably be empty.
- return (EntitySpec<T>)
EntityManagementUtils.createCatalogSpec(mgmt, (CatalogItem) item);
+ EntitySpec<?> spec = serviceSpecResolver.resolve(type, loader,
encounteredCatalogTypes);
+
+ if (spec == null) {
+ // Try to provide some troubleshooting details
+ final String msgDetails;
+ CatalogItem<?, ?> item =
CatalogUtils.getCatalogItemOptionalVersion(mgmt, Strings.removeFromStart(type,
"catalog:"));
+ String proto = Urls.getProtocol(type);
+ if (item != null &&
encounteredCatalogTypes.contains(item.getSymbolicName())) {
+ msgDetails = "Cycle between catalog items detected,
starting from " + type +
+ ". Other catalog items being resolved up the stack
are " + encounteredCatalogTypes +
+ ". Tried loading it as a Java class instead but
failed.";
+ } else if (proto != null) {
+ msgDetails = "The reference " + type + " looks like a URL
(running the CAMP Brooklyn assembly-template instantiator) but the protocol " +
+ proto + " isn't white listed (" +
BrooklynCampConstants.YAML_URL_PROTOCOL_WHITELIST + "). " +
+ "Not a catalog item or java type as well.";
--- End diff --
I'd phrase this something like "It's also neither a catalog item nor a java
type".
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---