Github user aledsage commented on a diff in the pull request:

    https://github.com/apache/incubator-brooklyn/pull/124#discussion_r16549801
  
    --- Diff: 
core/src/main/java/brooklyn/catalog/internal/BasicBrooklynCatalog.java ---
    @@ -215,7 +203,56 @@ public void load() {
     
             return spec;
         }
    -    
    +
    +    @SuppressWarnings("unchecked")
    +    private <T, SpecT> SpecT createEntitySpec(
    +            CatalogItemDo<T, SpecT> loadedItem, DeploymentPlan plan) {
    +        CampPlatform camp = 
BrooklynServerConfig.getCampPlatform(mgmt).get();
    +
    +        // TODO should not register new AT each time we instantiate from 
the same plan; use some kind of cache
    +        AssemblyTemplate at;
    +        BrooklynClassLoadingContext loader = 
loadedItem.newClassLoadingContext(mgmt);
    +        BrooklynLoaderTracker.setLoader(loader);
    +        try {
    +            at = camp.pdp().registerDeploymentPlan(plan);
    +        } finally {
    +            BrooklynLoaderTracker.unsetLoader(loader);
    +        }
    +
    +        try {
    +            AssemblyTemplateInstantiator instantiator = 
at.getInstantiator().newInstance();
    +            if (instantiator instanceof AssemblyTemplateSpecInstantiator) {
    +                return (SpecT) 
((AssemblyTemplateSpecInstantiator)instantiator).createSpec(at, camp);
    +            }
    +            throw new IllegalStateException("Unable to instantiate YAML; 
incompatible instantiator "+instantiator+" for "+at);
    +        } catch (Exception e) {
    +            throw Exceptions.propagate(e);
    +        }
    +    }
    +
    +
    +    @SuppressWarnings("unchecked")
    +    private <T, SpecT> SpecT createPolicySpec(CatalogItemDo<T, SpecT> 
loadedItem, DeploymentPlan plan) {
    +        Object policy = plan.getCustomAttributes().get("policy");
    +        Map<String, Object> policyConfig;
    +        if (policy instanceof String) {
    +            policyConfig = ImmutableMap.<String, Object>of("type", policy);
    +        } else if (policy instanceof Map) {
    +            policyConfig = (Map<String, Object>) policy;
    +        } else {
    +            throw new IllegalStateException("Policy exepcted to be string 
or map.");
    --- End diff --
    
    Again, good to say what type was passed in as part of the exception message.


---
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.
---

Reply via email to