brooklyn-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From neykov <...@git.apache.org>
Subject [GitHub] brooklyn-server pull request #429: BasicJcloudsLocationCustomizer is an Enti...
Date Mon, 14 Nov 2016 14:45:22 GMT
Github user neykov commented on a diff in the pull request:

    https://github.com/apache/brooklyn-server/pull/429#discussion_r87813264
  
    --- Diff: locations/jclouds/src/main/java/org/apache/brooklyn/location/jclouds/BasicJcloudsLocationCustomizer.java
---
    @@ -18,19 +18,72 @@
      */
     package org.apache.brooklyn.location.jclouds;
     
    +import java.util.Collection;
    +import java.util.List;
    +import java.util.Map;
    +
    +import org.apache.brooklyn.api.entity.Entity;
    +import org.apache.brooklyn.api.entity.EntityInitializer;
    +import org.apache.brooklyn.api.entity.EntityLocal;
    +import org.apache.brooklyn.config.ConfigKey;
    +import org.apache.brooklyn.core.entity.BrooklynConfigKeys;
    +import org.apache.brooklyn.core.location.LocationConfigKeys;
    +import org.apache.brooklyn.core.objs.BasicConfigurableObject;
    +import org.apache.brooklyn.util.core.config.ConfigBag;
     import org.jclouds.compute.ComputeService;
     import org.jclouds.compute.domain.Template;
     import org.jclouds.compute.domain.TemplateBuilder;
     import org.jclouds.compute.options.TemplateOptions;
    +import org.slf4j.Logger;
    +import org.slf4j.LoggerFactory;
     
    -import org.apache.brooklyn.api.entity.Entity;
    -import org.apache.brooklyn.core.location.LocationConfigKeys;
    -import org.apache.brooklyn.core.objs.BasicConfigurableObject;
    +import com.google.common.collect.ImmutableList;
    +import com.google.common.collect.ImmutableMap;
    +import com.google.common.collect.Iterables;
    +import com.google.common.collect.Lists;
     
     /**
    - * A default no-op implementation, which can be extended to override the appropriate
methods.
    + * A default no-op location customizer, which can be extended to override the appropriate
methods.
    + * <p>
    + * When the class is used as an {@link EntityInitializer} it inserts itself into the
entity's
    + * {@link JcloudsLocationConfig#JCLOUDS_LOCATION_CUSTOMIZERS} under the
    + * {@link BrooklynConfigKeys#PROVISIONING_PROPERTIES} key.
      */
    -public class BasicJcloudsLocationCustomizer extends BasicConfigurableObject implements
JcloudsLocationCustomizer {
    +public class BasicJcloudsLocationCustomizer extends BasicConfigurableObject implements
JcloudsLocationCustomizer, EntityInitializer {
    +
    +    private static final Logger LOG = LoggerFactory.getLogger(BasicJcloudsLocationCustomizer.class);
    +
    +    protected final ConfigBag params;
    +
    +    public BasicJcloudsLocationCustomizer() {
    +        this(ImmutableMap.<String, String>of());
    +    }
    +
    +    public BasicJcloudsLocationCustomizer(Map<String, String> params) {
    +        this(ConfigBag.newInstance(params));
    +    }
    +
    +    public BasicJcloudsLocationCustomizer(final ConfigBag params) {
    +        this.params = params;
    +    }
    +
    +    @Override
    +    public void apply(EntityLocal entity) {
    +        ConfigKey<Object> subkey = BrooklynConfigKeys.PROVISIONING_PROPERTIES.subKey(JcloudsLocationConfig.JCLOUDS_LOCATION_CUSTOMIZERS.getName());
    +        // newInstance handles the case that provisioning properties is null.
    +        ConfigBag provisioningProperties = ConfigBag.newInstance(entity.config().get(BrooklynConfigKeys.PROVISIONING_PROPERTIES));
    +        Collection<JcloudsLocationCustomizer> existingCustomizers = provisioningProperties.get(JcloudsLocationConfig.JCLOUDS_LOCATION_CUSTOMIZERS);
    +        List<? super JcloudsLocationCustomizer> merged;
    +        if (existingCustomizers == null) {
    +            merged = ImmutableList.<JcloudsLocationCustomizer>of(this);
    +        } else {
    +            merged = Lists.newArrayListWithCapacity(1 + existingCustomizers.size());
    --- End diff --
    
    Personal preference: I'd use `ImmutableList.builder()` instead (to avoid playing with
sizes).


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