brooklyn-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From neykov <...@git.apache.org>
Subject [GitHub] incubator-brooklyn pull request: Encapsulate all CAMP calls in a s...
Date Thu, 12 Mar 2015 20:32:00 GMT
Github user neykov commented on a diff in the pull request:

    https://github.com/apache/incubator-brooklyn/pull/545#discussion_r26341363
  
    --- Diff: core/src/main/java/brooklyn/management/internal/EntityManagementUtils.java ---
    @@ -82,41 +100,90 @@
             return app;
         }
     
    -    /** convenience for accessing camp */
    -    public static Maybe<CampPlatform> getCampPlatform(ManagementContext mgmt) {
    -        return BrooklynServerConfig.getCampPlatform(mgmt);
    -    }
    -    
         /** as {@link #createApplication(ManagementContext, EntitySpec)} but for a YAML spec
*/
    -    public static <T extends Application> T createUnstarted(ManagementContext mgmt,
String yaml) {
    -        AssemblyTemplate at = getCampPlatform(mgmt).get().pdp().registerDeploymentPlan(
new StringReader(yaml) );
    -        return createUnstarted(mgmt, at);
    +    public static Application createUnstarted(ManagementContext mgmt, String yaml) {
    +        return createUnstarted(mgmt, new StringReader(yaml));
         }
    -    
    -    /** as {@link #createApplication(ManagementContext, EntitySpec)} but for an assembly
template */
    +
    +    public static Application createUnstarted(ManagementContext mgmt, Reader yaml) {
    +        EntitySpec<? extends Application> spec = createEntitySpec(mgmt, yaml);
    +        return createUnstarted(mgmt, spec);
    +    }
    +
    +    public static EntitySpec<? extends Application> createEntitySpec(ManagementContext
mgmt, String yaml) {
    +        return createEntitySpec(mgmt, new StringReader(yaml));
    +    }
    +
    +    public static EntitySpec<? extends Application> createEntitySpec(ManagementContext
mgmt, Reader yaml) {
    +        BrooklynClassLoadingContext loader = createDefaultLoader(mgmt);
    +        return createEntitySpec(mgmt, yaml, loader);
    +    }
    +
         @SuppressWarnings("unchecked")
    -    public static <T extends Application> T createUnstarted(ManagementContext mgmt,
AssemblyTemplate at) {
    -        CampPlatform camp = getCampPlatform(mgmt).get();
    -        AssemblyTemplateInstantiator instantiator;
    +    public static EntitySpec<? extends Application> createEntitySpec(ManagementContext
mgmt, Reader yaml, BrooklynClassLoadingContext loader) {
    +        return (EntitySpec<? extends Application>) createSpec(mgmt, yaml, loader);
    +    }
    +
    +    private static EntitySpec<? extends Application> createEntitySpec(String symbolicName,
CampPlatform camp,
    +                                                                      DeploymentPlan
plan, BrooklynClassLoadingContext loader) {
    +        AssemblyTemplate at = registerDeploymentPlan(camp, plan, loader);
    +        AssemblyTemplateInstantiator instantiator = newInstantiator(at);
    +        if (instantiator instanceof AssemblyTemplateSpecInstantiator) {
    +            return (EntitySpec<? extends Application>) ((AssemblyTemplateSpecInstantiator)instantiator).createNestedSpec(at,
camp, loader, MutableSet.of(symbolicName));
    +        } else {
    +            throw new IllegalStateException("Unable to instantiate YAML; incompatible
instantiator " + instantiator + " for " + at);
    +        }
    +    }
    +
    +    public static AbstractBrooklynObjectSpec<?, ?> createSpec(ManagementContext
mgmt, String yaml, BrooklynClassLoadingContext loader) {
    +        return createSpec(mgmt, new StringReader(yaml), loader);
    +    }
    +
    +    public static AbstractBrooklynObjectSpec<?, ?> createSpec(ManagementContext
mgmt, Reader yaml, BrooklynClassLoadingContext loader) {
    +        Preconditions.checkNotNull(mgmt, "mgmt");
    +        Preconditions.checkNotNull(mgmt, "yaml");
    +        Preconditions.checkNotNull(mgmt, "loader");
    +
    +        CampPlatform camp = getCampPlatform(mgmt);
    +        DeploymentPlan plan = parseDeploymentPlan(camp, yaml);
    +        return createSpec(null, mgmt, plan, loader);
    +    }
    +
    +    private static AbstractBrooklynObjectSpec<?, ?> createSpec(String symbolicName,
ManagementContext mgmt,
    +                                                               DeploymentPlan plan, BrooklynClassLoadingContext
loader) {
    +        if (isPolicyPlan(plan)) {
    +            return createPolicySpec(plan, loader);
    +        } else {
    +            return createEntitySpec(symbolicName, getCampPlatform(mgmt), plan, loader);
    --- End diff --
    
    Here is where things go sideways. The method `createEntitySpec` called here is coming
from `BasicBrooklynCatalog`, calling into `createNestedSpec`. You should instead use https://github.com/neykov/incubator-brooklyn/commit/55305ea9bf05598a8ac2c811691008818edbf321#diff-b713fc5de648db4fede03fa71cfd1c6fR315
which calls into `AssemblyTemplateSpecInstantiator.createSpec`.


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