brooklyn-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aledsage <...@git.apache.org>
Subject [GitHub] incubator-brooklyn pull request: Support for adding YAML defined p...
Date Thu, 21 Aug 2014 16:24:54 GMT
Github user aledsage commented on a diff in the pull request:

    https://github.com/apache/incubator-brooklyn/pull/124#discussion_r16549863
  
    --- 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.");
    +        }
    +
    +        String policyType = (String) policyConfig.get("type");
    --- End diff --
    
    I'd use `checkNotNull(policyConfig.get("type"), "policy type")`, with an `import static
guava.Preconditions.checkNotNull`.


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

Mime
View raw message