4343import org .apache .brooklyn .api .catalog .CatalogItem ;
4444import org .apache .brooklyn .api .catalog .CatalogItem .CatalogBundle ;
4545import org .apache .brooklyn .api .catalog .CatalogItem .CatalogItemType ;
46+ import org .apache .brooklyn .api .entity .Application ;
4647import org .apache .brooklyn .api .internal .AbstractBrooklynObjectSpec ;
47- import org .apache .brooklyn .api .location .Location ;
48- import org .apache .brooklyn .api .location .LocationSpec ;
4948import org .apache .brooklyn .api .mgmt .ManagementContext ;
5049import org .apache .brooklyn .api .mgmt .classloading .BrooklynClassLoadingContext ;
5150import org .apache .brooklyn .api .objs .BrooklynObject ;
5655import org .apache .brooklyn .api .typereg .RegisteredType ;
5756import org .apache .brooklyn .core .catalog .CatalogPredicates ;
5857import org .apache .brooklyn .core .catalog .internal .CatalogClasspathDo .CatalogScanningModes ;
59- import org .apache .brooklyn .core .location . BasicLocationRegistry ;
58+ import org .apache .brooklyn .core .mgmt . BrooklynTags ;
6059import org .apache .brooklyn .core .mgmt .ha .OsgiBundleInstallationResult ;
6160import org .apache .brooklyn .core .mgmt .ha .OsgiManager ;
6261import org .apache .brooklyn .core .mgmt .internal .CampYamlParser ;
@@ -869,22 +868,34 @@ private void collectCatalogItemsFromItemMetadataBlock(String sourceYaml, Managed
869868 // just need TODO to make sure we delete previously-persisted things which now come through this path.)
870869 // NB: when everything is a bundle and we've removed all scanning then this can be the _only_ path
871870 // and code can be massively simpler
871+ // TODO allow these to be set in catalog.bom ?
872+ List <String > aliases = MutableList .of ();
873+ List <Object > tags = MutableList .of ();
874+ Boolean catalogDisabled = null ;
875+
876+ MutableList <Object > superTypes = MutableList .of ();
877+
878+ if (itemType ==CatalogItemType .TEMPLATE ) {
879+ tags .add (BrooklynTags .CATALOG_TEMPLATE );
880+ itemType = CatalogItemType .ENTITY ;
881+ superTypes .add (Application .class );
882+ }
872883
873884 if (resolutionError !=null ) {
874- if (requireValidation ) {
875- throw Exceptions .propagate (resolutionError );
885+ if (!tags .contains (BrooklynTags .CATALOG_TEMPLATE )) {
886+ if (requireValidation ) {
887+ throw Exceptions .propagate (resolutionError );
888+ }
889+ // warn? add as "unresolved" ? just do nothing?
876890 }
877- // warn? add as "unresolved" ? just do nothing?
878891 }
879- String format = null ; // could support specifying format
880- // TODO if kind and supertype is known, set those here
881- Class <?> javaType = null ;
882- List <Object > superTypes = MutableList .of ().appendIfNotNull (javaType );
892+ String format = null ; // could support specifying format?
883893
884- // TODO allow these to be set in catalog.bom ?
885- List <String > aliases = MutableList .of ();
886- List <Object > tags = MutableList .of ();
887- Boolean catalogDisabled = null ;
894+ if (itemType !=null ) {
895+ // if supertype is known, set it here;
896+ // we don't set kind (spec) because that is inferred from the supertype type
897+ superTypes .appendIfNotNull (BrooklynObjectType .of (itemType ).getInterfaceType ());
898+ }
888899
889900 if (version ==null ) {
890901 // use this as default version when nothing specified
@@ -1447,6 +1458,10 @@ public Map<RegisteredType,Collection<Throwable>> validateTypes(Iterable<Register
14471458 public Collection <Throwable > validateType (RegisteredType typeToValidate ) {
14481459 ReferenceWithError <RegisteredType > result = resolve (typeToValidate );
14491460 if (result .hasError ()) {
1461+ if (RegisteredTypes .isTemplate (typeToValidate )) {
1462+ // ignore for templates
1463+ return Collections .emptySet ();
1464+ }
14501465 if (result .getError () instanceof CompoundRuntimeException ) {
14511466 return ((CompoundRuntimeException )result .getError ()).getAllCauses ();
14521467 }
@@ -1456,7 +1471,7 @@ public Collection<Throwable> validateType(RegisteredType typeToValidate) {
14561471 ((BasicBrooklynTypeRegistry ) mgmt .getTypeRegistry ()).addToLocalUnpersistedTypeRegistry (result .get (), true );
14571472 return Collections .emptySet ();
14581473 }
1459-
1474+
14601475 /**
14611476 * Resolves the given object with respect to the catalog. Returns any errors found while trying to resolve.
14621477 * The argument may be changed (e.g. its kind set, supertypes set), and normal usage is to add
0 commit comments