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: YAML config keys (parameters)
Date Mon, 09 Nov 2015 13:26:03 GMT
Github user neykov commented on a diff in the pull request:

    https://github.com/apache/incubator-brooklyn/pull/1001#discussion_r44273804
  
    --- Diff: usage/camp/src/main/java/org/apache/brooklyn/camp/brooklyn/spi/creation/CampUtils.java
---
    @@ -23,48 +23,94 @@
     import java.io.StringReader;
     import java.util.List;
     import java.util.Map;
    +import java.util.Map.Entry;
     import java.util.Set;
     
    +import org.apache.brooklyn.api.entity.Application;
     import org.apache.brooklyn.api.entity.EntitySpec;
    +import org.apache.brooklyn.api.internal.AbstractBrooklynObjectSpec;
     import org.apache.brooklyn.api.location.Location;
     import org.apache.brooklyn.api.location.LocationSpec;
     import org.apache.brooklyn.api.mgmt.ManagementContext;
    +import org.apache.brooklyn.api.objs.SpecParameter;
     import org.apache.brooklyn.api.policy.Policy;
     import org.apache.brooklyn.api.policy.PolicySpec;
     import org.apache.brooklyn.api.typereg.RegisteredType;
     import org.apache.brooklyn.camp.CampPlatform;
     import org.apache.brooklyn.camp.brooklyn.BrooklynCampConstants;
    +import org.apache.brooklyn.camp.brooklyn.BrooklynCampReservedKeys;
     import org.apache.brooklyn.camp.brooklyn.api.AssemblyTemplateSpecInstantiator;
     import org.apache.brooklyn.camp.spi.AssemblyTemplate;
    +import org.apache.brooklyn.camp.spi.AssemblyTemplate.Builder;
     import org.apache.brooklyn.camp.spi.instantiate.AssemblyTemplateInstantiator;
     import org.apache.brooklyn.camp.spi.pdp.DeploymentPlan;
     import org.apache.brooklyn.core.catalog.internal.BasicBrooklynCatalog;
     import org.apache.brooklyn.core.catalog.internal.BasicBrooklynCatalog.BrooklynLoaderTracker;
    +import org.apache.brooklyn.core.mgmt.EntityManagementUtils;
     import org.apache.brooklyn.core.mgmt.classloading.BrooklynClassLoadingContext;
    +import org.apache.brooklyn.core.objs.BasicSpecParameter;
     import org.apache.brooklyn.core.objs.BrooklynObjectInternal.ConfigurationSupportInternal;
    +import org.apache.brooklyn.entity.stock.BasicApplicationImpl;
     import org.apache.brooklyn.util.exceptions.Exceptions;
     import org.apache.brooklyn.util.guava.Maybe;
     import org.apache.brooklyn.util.stream.Streams;
     import org.apache.brooklyn.util.yaml.Yamls;
     
    +import com.google.common.collect.ImmutableList;
     import com.google.common.collect.ImmutableMap;
    +import com.google.common.collect.ImmutableSet;
     import com.google.common.collect.Iterables;
     
     //TODO-type-registry
     public class CampUtils {
     
    -    public static List<EntitySpec<?>> createServiceSpecs(String plan, BrooklynClassLoadingContext
loader, Set<String> encounteredTypes) {
    +    public static EntitySpec<?> createRootServiceSpec(String plan, BrooklynClassLoadingContext
loader, Set<String> encounteredTypes) {
             CampPlatform camp = getCampPlatform(loader.getManagementContext());
     
             AssemblyTemplate at = registerDeploymentPlan(plan, loader, camp);
             AssemblyTemplateInstantiator instantiator = getInstantiator(at);
             if (instantiator instanceof AssemblyTemplateSpecInstantiator) {
    -            return ((AssemblyTemplateSpecInstantiator)instantiator).createServiceSpecs(at,
camp, loader, encounteredTypes);
    +            List<EntitySpec<?>> serviceSpecs = ((AssemblyTemplateSpecInstantiator)instantiator).createServiceSpecs(at,
camp, loader, encounteredTypes);
    +            if (serviceSpecs.size() > 1) {
    +                throw new UnsupportedOperationException("Single service expected, but
got "+serviceSpecs);
    +            }
    +            EntitySpec<?> rootSpec = serviceSpecs.get(0);
    +            EntitySpec<? extends Application> wrapperApp = createWrapperApp(at,
loader);
    +            EntityManagementUtils.mergeWrapperParentSpecToChildEntity(wrapperApp, rootSpec);
    +            return rootSpec;
             } else {
                 throw new IllegalStateException("Unable to instantiate YAML; incompatible
instantiator "+instantiator+" for "+at);
             }
         }
     
    +    public static EntitySpec<? extends Application> createWrapperApp(AssemblyTemplate
template, BrooklynClassLoadingContext loader) {
    +        BrooklynComponentTemplateResolver resolver = BrooklynComponentTemplateResolver.Factory.newInstance(
    +            loader, buildWrapperAppTemplate(template));
    +        EntitySpec<Application> wrapperSpec = resolver.resolveSpec(ImmutableSet.<String>of());
    +        if (!hasExplicitParams(template)) {
    --- End diff --
    
    The spec will always be populated with parameters - either from the template or from the
apps's java class (BasicApplication has defaultDisplayName). Clear out the parameters if coming
from the class (i.e. the defaults) so they don't overwrite the entity spec when unwrapping.


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