Github user neykov commented on a diff in the pull request:
https://github.com/apache/incubator-brooklyn/pull/1017#discussion_r44704144
--- Diff:
core/src/main/java/org/apache/brooklyn/core/typereg/BasicBrooklynTypeRegistry.java
---
@@ -90,31 +96,95 @@ public RegisteredType get(String
symbolicNameWithOptionalVersion, RegisteredType
@Override
public RegisteredType get(String symbolicNameWithOptionalVersion) {
- return get(symbolicNameWithOptionalVersion,
(RegisteredTypeConstraint)null);
+ return get(symbolicNameWithOptionalVersion,
(RegisteredTypeLoadingContext)null);
}
@SuppressWarnings({ "deprecation", "unchecked", "rawtypes" })
@Override
- public <SpecT extends AbstractBrooklynObjectSpec<?,?>> SpecT
createSpec(RegisteredType type, @Nullable RegisteredTypeConstraint constraint,
Class<SpecT> specSuperType) {
- if (!(type instanceof RegisteredSpecType)) {
- throw new IllegalStateException("Cannot create spec from type
"+type);
+ public <SpecT extends AbstractBrooklynObjectSpec<?,?>> SpecT
createSpec(RegisteredType type, @Nullable RegisteredTypeLoadingContext
constraint, Class<SpecT> specSuperType) {
+ Preconditions.checkNotNull(type, "type");
+ if (type.getKind()!=RegisteredTypeKind.SPEC) {
+ throw new IllegalStateException("Cannot create spec from type
"+type+" (kind "+type.getKind()+")");
}
if (constraint!=null) {
- if (constraint.getKind()!=null &&
constraint.getKind()!=RegisteredTypeKind.SPEC) {
+ if (constraint.getExpectedKind()!=null &&
constraint.getExpectedKind()!=RegisteredTypeKind.SPEC) {
throw new IllegalStateException("Cannot create spec with
constraint "+constraint);
}
- if
(constraint.getEncounteredTypes().contains(type.getSymbolicName())) {
+ if
(constraint.getAlreadyEncounteredTypes().contains(type.getSymbolicName())) {
// avoid recursive cycle
// TODO implement using java if permitted
}
}
- constraint =
RegisteredTypeConstraints.extendedWithSpecSuperType(constraint, specSuperType);
+ constraint =
RegisteredTypeLoadingContexts.withSpecSuperType(constraint, specSuperType);
- // TODO look up in the actual registry
+ Maybe<Object> result = TypePlanTransformers.transform(mgmt, type,
constraint);
+ if (result.isPresent()) return (SpecT) result.get();
// fallback: look up in (legacy) catalog
+ // TODO remove once all transformers are available in the new style
CatalogItem item = (CatalogItem)
mgmt.getCatalog().getCatalogItem(type.getSymbolicName(), type.getVersion());
- return (SpecT)
BasicBrooklynCatalog.internalCreateSpecWithTransformers(mgmt, item,
constraint.getEncounteredTypes());
+ if (item==null) {
--- End diff --
You are mixing two types of transformations in this method:
* plan (i.e. camp) to spec transformers - `BrooklynTypePlanTransformer`
(former `PlanToSpecTransformer), the part up to this line
* type (symbolicName, java identifier) to spec transformers -
`EntitySpecResolver`, the part from this line until the end. This type of
transformation is not needed at this level, it shoud be nested in the plan
transformers. Looks like it's needed here just to get `SpecParameterInMetaTest`
from passing.
Instead of this second part, `StaticTypePlanTransformer` should be taught
how to handle the plans from the test (essentially same as pre-changes
`TestToSpecTransformer`). The commit
https://github.com/neykov/incubator-brooklyn/commit/8e9d69dbaeb6b15f8351f4bf5f2928c379a86b3d
shows what I mean. The test `testOsgiClassScanned` is moved to `brooklyn-camp`
as the camp parser is needed to create specs out of the catalog items.
With these changes the legacy transformers are used only during catalog
`addItems`. Should be easy to move to the new API, I suppose part of the next
PR.
---
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.
---