You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@brooklyn.apache.org by neykov <gi...@git.apache.org> on 2015/11/05 11:59:39 UTC

[GitHub] incubator-brooklyn pull request: YAML config keys (parameters)

GitHub user neykov opened a pull request:

    https://github.com/apache/incubator-brooklyn/pull/1001

    YAML config keys (parameters)

    Adds parameters to specs and catalog items, which are then added as config keys to the entity's dynamic type.
    What this allows is:
      * document the possible inputs for a catalog item
      * the UI can now ask the user for input when selecting a catalog item
      * setting the correct type for inputs (coercing), validating
      * add config keys to an entity by setting them in the spec
    
    Parameters can be set at any level in the CAMP plan, including in the catalog item meta info. If not set the underlying type parameters are used (if a java class, then its config keys are used, if a catalog item, then the item's parameters). The top level service parameters become the catalog item's parameters.
    
    For referencing any passed parameters new scopes are introduced:
      * `$brooklyn:root()` returns the application entity (top-level one)
      * `$brooklyn:scopeRoot()` returns the top level entity of the current catalog item
    
    Example:
    ```
    brooklyn.catalog:
      id: parameterExample
      version: 0.0.1
      brooklyn.parameters:
      - name: maxHits
        type: integer
        constraints:
        - required
      - config2
      - config3
      item:
        type: BasicApplication
        brooklyn.children:
        - type: entity1
          # can be set at deeper levels when typing is needed
          brooklyn.parameters:
          - name: entity1Config
            type: integer
          brooklyn.config:
            entity1Config: $brooklyn:scopeRoot().config("maxHits")
        - type: entity2
          brooklyn.config:
            entity2Config: $brooklyn:config("maxHits")  # using the inherited config
    ```
    
    Which results in the following catalog item:
    
    <img width="598" alt="catalog item view" src="https://cloud.githubusercontent.com/assets/3612111/10966226/c7d7bfe4-83ba-11e5-8303-c705ce68e06c.png">
    
    When using
     the Application Wizard to create an application from the above catalog item the UI asks you to fill in the parameters:
    
    <img width="616" alt="screen shot 2015-11-05 at 12 51 35" src="https://cloud.githubusercontent.com/assets/3612111/10966396/fa52dd0e-83bb-11e5-94b2-fbe5d049541d.png">
    
    creating the following app plan:
    
    ```
    location: uLXQ8KFk
    services:
      - type: "parameterExample:0.0.1"
        brooklyn.config:
          maxHits: 55
    ```


You can merge this pull request into a Git repository by running:

    $ git pull https://github.com/neykov/incubator-brooklyn catalog-item-config

Alternatively you can review and apply these changes as the patch at:

    https://github.com/apache/incubator-brooklyn/pull/1001.patch

To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:

    This closes #1001
    
----
commit 181c5a0c5762ecc3a6eab1fec8cfb8f342f8afa3
Author: Svetoslav Neykov <sv...@cloudsoftcorp.com>
Date:   2015-10-26T15:56:47Z

    Deprecate java type based items in favor of parser dependent plans

commit 75f4ba01a0ed11c416fc783375f1c71b9ff9c6da
Author: Svetoslav Neykov <sv...@cloudsoftcorp.com>
Date:   2015-10-28T17:00:33Z

    Fix installed test osgi jar name
    
    Previously changed due to a copy&paste error

commit 35e1b43d6d653d78c0d8f23987979b753b73ce97
Author: Svetoslav Neykov <sv...@cloudsoftcorp.com>
Date:   2015-10-28T17:13:17Z

    Catalog items configuration support
    
    Functionality to let catalog items document what configuration they accept as input. Useful for YAML plans to let users know what configuration they support and for UIs to list available inputs and validate them.

commit 171a66f635650040e0308f3a60ae17f55650aa8a
Author: Svetoslav Neykov <sv...@cloudsoftcorp.com>
Date:   2015-10-29T16:44:24Z

    Parameter aware specs
    
    Let specs be aware of the parameters the underlying brooklyn object is accepting. Catalog items return the same spec parameters derived at addition time. The catalog item can override the underlying entity parameters by including the list in its meta.

commit a09c399d5505cdddf52585d435990289dac41dca
Author: Svetoslav Neykov <sv...@cloudsoftcorp.com>
Date:   2015-10-30T16:24:46Z

    Add PortRange support for the parameter types
    
    Won't be set as an attribute though.

commit 6c84eb32ff51c1a30883986aba1ea0c5dc4330a2
Author: Svetoslav Neykov <sv...@cloudsoftcorp.com>
Date:   2015-11-03T15:30:13Z

    Parameters rebind support

commit db8a815859136df92f2e9cd1da54321d7f1bd40d
Author: Svetoslav Neykov <sv...@cloudsoftcorp.com>
Date:   2015-11-03T15:31:49Z

    Parameters test coverage

commit d323cfaf6e048609716f0c22d9f188e71d552c4a
Author: Svetoslav Neykov <sv...@cloudsoftcorp.com>
Date:   2015-11-03T15:58:23Z

    Parameters docs

commit 602055531e8484d056db580781bb1f5797036c71
Author: Svetoslav Neykov <sv...@cloudsoftcorp.com>
Date:   2015-11-04T11:48:47Z

    Improve UI handling of catalog item parameters.

commit 2a1993226fbf8cd0c52981d61693de3b9903ca60
Author: Svetoslav Neykov <sv...@cloudsoftcorp.com>
Date:   2015-11-04T12:57:58Z

    Add root scope in CAMP DSL - the application

commit a525cdbe1b76ccf0addd9354cec72b7de3c72d60
Author: Svetoslav Neykov <sv...@cloudsoftcorp.com>
Date:   2015-11-04T13:59:24Z

    Add scopeRoot scope in CAMP DSL

----


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

[GitHub] incubator-brooklyn pull request: YAML config keys (parameters)

Posted by neykov <gi...@git.apache.org>.
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.
---

[GitHub] incubator-brooklyn pull request: YAML config keys (parameters)

Posted by neykov <gi...@git.apache.org>.
Github user neykov commented on the pull request:

    https://github.com/apache/incubator-brooklyn/pull/1001#issuecomment-154030665
  
    Lots of conflicts due to recent changes, working on it. Input & comments still appreciated.


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

[GitHub] incubator-brooklyn pull request: YAML config keys (parameters)

Posted by neykov <gi...@git.apache.org>.
Github user neykov commented on the pull request:

    https://github.com/apache/incubator-brooklyn/pull/1001#issuecomment-154062554
  
    Resolved conflicts (Jenkins failure is unrelated). @ahgittin Do you think registry types should have parameters as well, or it's too specific to catalog items and brooklyn objects?


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

[GitHub] incubator-brooklyn pull request: YAML config keys (parameters)

Posted by ahgittin <gi...@git.apache.org>.
Github user ahgittin commented on the pull request:

    https://github.com/apache/incubator-brooklyn/pull/1001#issuecomment-154091229
  
    @neykov I think registry types don't need parameters.  It's down to the individual `TypePlanTransformers` how to transform a plan (eg YAML, but possibly also ZIP etc) into a spec or instance.


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

[GitHub] incubator-brooklyn pull request: YAML config keys (parameters)

Posted by asfgit <gi...@git.apache.org>.
Github user asfgit closed the pull request at:

    https://github.com/apache/incubator-brooklyn/pull/1001


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

[GitHub] incubator-brooklyn pull request: YAML config keys (parameters)

Posted by ahgittin <gi...@git.apache.org>.
Github user ahgittin commented on the pull request:

    https://github.com/apache/incubator-brooklyn/pull/1001#issuecomment-154093232
  
    Oh I understand the question now -- should `RegisteredType` expose a `getDefinedConfigKeys()`.  That functionality is wanted for specs to show detail in the catalog.  However I think we can get that simply by the caller creating the spec and then asking the spec -- so still I'd say no.
    
    Have looked over the code briefly and it looks good, nay, great.
    
    The test failure looks unrelated to this PR; seems related to @geomacy's recent addition:
    
        shouldAssertContentEventuallyMatchesWithFlags(org.apache.brooklyn.util.HttpAssertsTest)
        java.lang.AssertionError: Assertion failed
    	at java.net.PlainSocketImpl.socketConnect(Native Method)


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

[GitHub] incubator-brooklyn pull request: YAML config keys (parameters)

Posted by ahgittin <gi...@git.apache.org>.
Github user ahgittin commented on a diff in the pull request:

    https://github.com/apache/incubator-brooklyn/pull/1001#discussion_r44272318
  
    --- 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 --
    
    why is this needed?


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