You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@brooklyn.apache.org by grkvlt <gi...@git.apache.org> on 2015/04/08 21:22:14 UTC

[GitHub] incubator-brooklyn pull request: Parse service types in YAML using...

GitHub user grkvlt opened a pull request:

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

    Parse service types in YAML using pluggable resolver impls

    Adds a `ServiceLoader` plugin capability for parsing the `serviceType: xxx:yyy` part of the YAML blueprint. Includes `brooklyn:`, `java:`, `catalog:` and `chef:` implementations.
    
    This is based on my comment on #436 and @neykov's suggestions there.

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

    $ git pull https://github.com/grkvlt/incubator-brooklyn feature/yaml-service-resolver

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

    https://github.com/apache/incubator-brooklyn/pull/587.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 #587
    
----
commit 303c3884e868b9167bd1551469507137634948fc
Author: Andrew Kennedy <gr...@apache.org>
Date:   2015-04-07T15:35:19Z

    Parse service types in YAML using pluggable resolver impls

----


---
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: Parse service types in YAML using...

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

    https://github.com/apache/incubator-brooklyn/pull/587#issuecomment-91032338
  
    This looks really good to me.  One minor comment is all.  @neykov if you have the chance to look this over too that would be useful.


---
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: Parse service types in YAML using...

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/587#discussion_r28010704
  
    --- Diff: usage/camp/src/main/java/io/brooklyn/camp/brooklyn/spi/creation/BrooklynComponentTemplateResolver.java ---
    @@ -77,59 +74,80 @@
      * This converts {@link PlatformComponentTemplate} instances whose type is prefixed {@code brooklyn:}
      * to Brooklyn {@link EntitySpec} instances.
      * <p>
    - * but TODO this should probably be done by {@link BrooklynEntityMatcher} 
    + * but TODO this should probably be done by {@link BrooklynEntityMatcher}
      * so we have a spec by the time we come to instantiate.
    - * (currently privileges "brooklyn.*" key names are checked in both places!)  
    + * (currently privileges "brooklyn.*" key names are checked in both places!)
      */
     public class BrooklynComponentTemplateResolver {
     
    -    private static final Logger log = LoggerFactory.getLogger(BrooklynDslCommon.class);
    +    private static final Logger log = LoggerFactory.getLogger(BrooklynComponentTemplateResolver.class);
     
    -    BrooklynClassLoadingContext loader;
    -    final ManagementContext mgmt;
    -    final ConfigBag attrs;
    -    final Maybe<AbstractResource> template;
    -    final BrooklynYamlTypeInstantiator.Factory yamlLoader;
    -    AtomicBoolean alreadyBuilt = new AtomicBoolean(false);
    +    private final BrooklynClassLoadingContext loader;
    +    private final ManagementContext mgmt;
    +    private final ConfigBag attrs;
    +    private final Maybe<AbstractResource> template;
    +    private final BrooklynYamlTypeInstantiator.Factory yamlLoader;
    +    private final String type;
    +    private final ServiceTypeResolver typeResolver;
    +    private final AtomicBoolean alreadyBuilt = new AtomicBoolean(false);
    +
    +    public BrooklynComponentTemplateResolver(BrooklynClassLoadingContext loader, ConfigBag attrs, AbstractResource optionalTemplate, String type, ServiceTypeResolver typeResolver) {
    +        this.loader = loader;
    +        this.mgmt = loader.getManagementContext();
    +        this.attrs = ConfigBag.newInstanceCopying(attrs);
    +        this.template = Maybe.fromNullable(optionalTemplate);
    +        this.yamlLoader = new BrooklynYamlTypeInstantiator.Factory(loader, this);
    +        this.type = type;
    +        this.typeResolver = typeResolver;
    +    }
    +
    +    public BrooklynClassLoadingContext getLoader() { return loader; }
    +    public ManagementContext getManagementContext() { return mgmt; }
    +    public ConfigBag getAttrs() { return attrs; }
    +    public Maybe<AbstractResource> getTemplate() { return template; }
    +    public BrooklynYamlTypeInstantiator.Factory getYamlLoader() { return yamlLoader; }
    +    public ServiceTypeResolver getServiceTypeResolver() { return typeResolver; }
    +    public String getDeclaredType() { return type; }
    +    public Boolean isAlreadyBuilt() { return alreadyBuilt.get(); }
     
         public static class Factory {
     
             /** returns resolver type based on the service type, inspecting the arguments in order to determine the service type */
    -        private static Class<? extends BrooklynComponentTemplateResolver> computeResolverType(String knownServiceType, AbstractResource optionalTemplate, ConfigBag attrs) {
    +        private static ServiceTypeResolver computeResolverType(BrooklynClassLoadingContext context, String knownServiceType, AbstractResource optionalTemplate, ConfigBag attrs) {
                 String type = getDeclaredType(knownServiceType, optionalTemplate, attrs);
    -            if (type!=null) {
    -                if (type.startsWith("brooklyn:") || type.startsWith("java:")) return BrooklynComponentTemplateResolver.class;
    -                if (type.equalsIgnoreCase("chef") || type.startsWith("chef:")) return ChefComponentTemplateResolver.class;
    -                // TODO other BrooklynComponentTemplateResolver subclasses detected here 
    -                // (perhaps use regexes mapping to subclass name, defined in mgmt?)
    +            return findService(context, type);
    +        }
    +
    +        protected static ServiceTypeResolver findService(BrooklynClassLoadingContext context, String type) {
    +            String prefix = Splitter.on(":").splitToList(type).get(0);
    --- End diff --
    
    first do `if (type.indexOf(':')==-1) return null;` ?  in case type matches a prefix but there is no `:`


---
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: Parse service types in YAML using...

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

    https://github.com/apache/incubator-brooklyn/pull/587#discussion_r28207771
  
    --- Diff: usage/camp/src/main/java/io/brooklyn/camp/brooklyn/spi/creation/service/ServiceTypeResolver.java ---
    @@ -0,0 +1,73 @@
    +/*
    + * Licensed to the Apache Software Foundation (ASF) under one
    + * or more contributor license agreements.  See the NOTICE file
    + * distributed with this work for additional information
    + * regarding copyright ownership.  The ASF licenses this file
    + * to you under the Apache License, Version 2.0 (the
    + * "License"); you may not use this file except in compliance
    + * with the License.  You may obtain a copy of the License at
    + *
    + *     http://www.apache.org/licenses/LICENSE-2.0
    + *
    + * Unless required by applicable law or agreed to in writing,
    + * software distributed under the License is distributed on an
    + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    + * KIND, either express or implied.  See the License for the
    + * specific language governing permissions and limitations
    + * under the License.
    + */
    +package io.brooklyn.camp.brooklyn.spi.creation.service;
    +
    +import java.util.ServiceLoader;
    +
    +import io.brooklyn.camp.brooklyn.spi.creation.BrooklynComponentTemplateResolver;
    +import brooklyn.catalog.CatalogItem;
    +import brooklyn.entity.Entity;
    +import brooklyn.entity.proxying.EntitySpec;
    +
    +/**
    + * Resolves and decorates {@link EntitySpec entity specifications} based on the {@code serviceType} in a template.
    + * <p>
    + * The {@link #getTypePrefix()} method returns a string that should match the beginning of the
    + * service type. The resolver implementation will use the rest of the service type information
    + * to create and decorate an approprate {@link EntitySpec entity}.
    + * <p>
    + * The resolvers are loaded using the {@link ServiceLoader} mechanism, allowing external libraries
    + * to add extra service type implementations that will be picked up at runtime.
    + *
    + * @see BrooklynServiceTypeResolver
    + * @see ChefServiceTypeResolver
    + */
    +public interface ServiceTypeResolver {
    +
    +    String DEFAULT_TYPE_PREFIX = "brooklyn";
    +
    +    /**
    +     * The service type prefix the resolver is responsible for.
    +     */
    +    String getTypePrefix();
    --- End diff --
    
    I wonder about also having an `accepts(String serviceType)` or an `accepts(BrooklynComponentTemplateResolver resolver, String serviceType)` - i.e. similar to `LocationResolver` - but no strong feelings.


---
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: Parse service types in YAML using...

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

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


---
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: Parse service types in YAML using...

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

    https://github.com/apache/incubator-brooklyn/pull/587#issuecomment-91028374
  
    @neykov @ahgittin I have tested this with a new `ServiceTtypeResolver` for Clocker in https://github.com/brooklyncentral/clocker/pull/100 which works nicely, using types like `docker:mysql:5.7` or docker:jboss/wildfly:8.1.0.Final` etc.


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