brooklyn-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ahgittin <...@git.apache.org>
Subject [GitHub] incubator-brooklyn pull request: Parse service types in YAML using...
Date Wed, 08 Apr 2015 20:39:51 GMT
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.
---

Mime
View raw message