brooklyn-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From grk...@apache.org
Subject [2/3] brooklyn-server git commit: Update BasicJcloudsLocationCustomizer to be configurable and remove deprecated methods
Date Tue, 30 Aug 2016 14:25:13 GMT
Update BasicJcloudsLocationCustomizer to be configurable and remove deprecated methods


Project: http://git-wip-us.apache.org/repos/asf/brooklyn-server/repo
Commit: http://git-wip-us.apache.org/repos/asf/brooklyn-server/commit/70bd8c3f
Tree: http://git-wip-us.apache.org/repos/asf/brooklyn-server/tree/70bd8c3f
Diff: http://git-wip-us.apache.org/repos/asf/brooklyn-server/diff/70bd8c3f

Branch: refs/heads/master
Commit: 70bd8c3f6508e3a5b93025884afe678b10df67f1
Parents: b1cafd8
Author: Andrew Donald Kennedy <andrew.kennedy@cloudsoftcorp.com>
Authored: Sat Aug 13 21:25:41 2016 +0100
Committer: Andrew Donald Kennedy <andrew.kennedy@cloudsoftcorp.com>
Committed: Tue Aug 30 15:22:27 2016 +0100

----------------------------------------------------------------------
 .../jclouds/BasicJcloudsLocationCustomizer.java | 58 ++++++-----------
 .../jclouds/JcloudsLocationCustomizer.java      | 45 +++-----------
 .../jclouds/SudoTtyFixingCustomizer.java        | 20 +++---
 .../JcloudsLocationSecurityGroupCustomizer.java | 65 ++++++++++----------
 .../SoftLayerSameVlanLocationCustomizer.java    | 20 ++----
 5 files changed, 72 insertions(+), 136 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/70bd8c3f/locations/jclouds/src/main/java/org/apache/brooklyn/location/jclouds/BasicJcloudsLocationCustomizer.java
----------------------------------------------------------------------
diff --git a/locations/jclouds/src/main/java/org/apache/brooklyn/location/jclouds/BasicJcloudsLocationCustomizer.java
b/locations/jclouds/src/main/java/org/apache/brooklyn/location/jclouds/BasicJcloudsLocationCustomizer.java
index e73d5f7..500442e 100644
--- a/locations/jclouds/src/main/java/org/apache/brooklyn/location/jclouds/BasicJcloudsLocationCustomizer.java
+++ b/locations/jclouds/src/main/java/org/apache/brooklyn/location/jclouds/BasicJcloudsLocationCustomizer.java
@@ -23,18 +23,14 @@ import org.jclouds.compute.domain.Template;
 import org.jclouds.compute.domain.TemplateBuilder;
 import org.jclouds.compute.options.TemplateOptions;
 
-import com.google.common.annotations.Beta;
-
+import org.apache.brooklyn.api.entity.Entity;
+import org.apache.brooklyn.core.location.LocationConfigKeys;
+import org.apache.brooklyn.core.objs.BasicConfigurableObject;
 
 /**
  * A default no-op implementation, which can be extended to override the appropriate methods.
- * 
- * Sub-classing will give the user some protection against future API changes - note that

- * {@link JcloudsLocationCustomizer} is marked {@link Beta}.
- * 
- * @author aled
  */
-public class BasicJcloudsLocationCustomizer implements JcloudsLocationCustomizer {
+public class BasicJcloudsLocationCustomizer extends BasicConfigurableObject implements JcloudsLocationCustomizer
{
 
     @Override
     public void customize(JcloudsLocation location, ComputeService computeService, TemplateBuilder
templateBuilder) {
@@ -53,47 +49,31 @@ public class BasicJcloudsLocationCustomizer implements JcloudsLocationCustomizer
 
     @Override
     public void customize(JcloudsLocation location, ComputeService computeService, JcloudsMachineLocation
machine) {
-        if (machine instanceof JcloudsSshMachineLocation) {
-            customize(location, computeService, (JcloudsSshMachineLocation)machine);
-        } else {
-            // no-op
-        }
+        // no-op
     }
-    
+
     @Override
     public void preRelease(JcloudsMachineLocation machine) {
-        if (machine instanceof JcloudsSshMachineLocation) {
-            preRelease((JcloudsSshMachineLocation)machine);
-        } else {
-            // no-op
-        }
+        // no-op
     }
 
     @Override
     public void postRelease(JcloudsMachineLocation machine) {
-        if (machine instanceof JcloudsSshMachineLocation) {
-            postRelease((JcloudsSshMachineLocation)machine);
-        } else {
-            // no-op
-        }
-    }
-    
-    @Override
-    @Deprecated
-    public void customize(JcloudsLocation location, ComputeService computeService, JcloudsSshMachineLocation
machine) {
         // no-op
     }
 
-    @Override
-    @Deprecated
-    public void preRelease(JcloudsSshMachineLocation machine) {
-        // no-op
-    }
+    /** @return the calling entity */
+    protected Entity getCallerContext(JcloudsMachineLocation machine) {
+        SudoTtyFixingCustomizer s;
 
-    @Override
-    @Deprecated
-    public void postRelease(JcloudsSshMachineLocation machine) {
-        // no-op
+        Object context = config().get(LocationConfigKeys.CALLER_CONTEXT);
+        if (context == null) {
+            context = machine.config().get(LocationConfigKeys.CALLER_CONTEXT);
+        }
+        if (!(context instanceof Entity)) {
+            throw new IllegalStateException("Invalid location context: " + context);
+        }
+        Entity entity = (Entity) context;
+        return entity;
     }
-    
 }

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/70bd8c3f/locations/jclouds/src/main/java/org/apache/brooklyn/location/jclouds/JcloudsLocationCustomizer.java
----------------------------------------------------------------------
diff --git a/locations/jclouds/src/main/java/org/apache/brooklyn/location/jclouds/JcloudsLocationCustomizer.java
b/locations/jclouds/src/main/java/org/apache/brooklyn/location/jclouds/JcloudsLocationCustomizer.java
index 696a462..d768cb4 100644
--- a/locations/jclouds/src/main/java/org/apache/brooklyn/location/jclouds/JcloudsLocationCustomizer.java
+++ b/locations/jclouds/src/main/java/org/apache/brooklyn/location/jclouds/JcloudsLocationCustomizer.java
@@ -18,23 +18,21 @@
  */
 package org.apache.brooklyn.location.jclouds;
 
-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 com.google.common.annotations.Beta;
+import org.apache.brooklyn.util.core.config.ConfigBag;
 
 /**
  * Customization hooks to allow apps to perform specific customisation at each stage of jclouds
machine provisioning.
  * For example, an app could attach an EBS volume to an EC2 node, or configure a desired
availability zone.
- * <p/>
+ * <p>
  * Instances will be invoked with the {@link ConfigBag} being used to obtain a machine by
the
- * {@link JcloudsLocation }if such a constructor exists. If not, the default no argument
constructor
+ * {@link JcloudsLocation} if such a constructor exists. If not, the default no argument
constructor
  * will be invoked.
  */
-@Beta
 public interface JcloudsLocationCustomizer {
 
     /**
@@ -46,7 +44,7 @@ public interface JcloudsLocationCustomizer {
     /**
      * Override to configure a subclass of this with the built template, or to configure
the built
      * template's {@link org.jclouds.compute.options.TemplateOptions}.
-     * <p/>
+     * <p>
      * This method will be called before {@link #customize(JcloudsLocation, ComputeService,
TemplateOptions)}.
      */
     void customize(JcloudsLocation location, ComputeService computeService, Template template);
@@ -59,39 +57,12 @@ public interface JcloudsLocationCustomizer {
 
     /**
      * Override to configure the given machine once it has been created and started by Jclouds.
-     * <p/>
-     * If {@link JcloudsLocationConfig#WAIT_FOR_SSHABLE} is true the
-     * machine is guaranteed to be SSHable when this method is called.
-     * 
-     * @since 0.7.0; use {@link #customize(JcloudsLocation, ComputeService, JcloudsMachineLocation)}
-     */
-    @Deprecated
-    void customize(JcloudsLocation location, ComputeService computeService, JcloudsSshMachineLocation
machine);
-    
-    /**
-     * Override to handle machine-related cleanup before Jclouds is called to release (destroy)
the machine.
-     * 
-     * @since 0.7.0; use {@link #preRelease(JcloudsMachineLocation)}
-     */
-    @Deprecated
-    void preRelease(JcloudsSshMachineLocation machine);
-
-    /**
-     * Override to handle machine-related cleanup after Jclouds is called to release (destroy)
the machine.
-     * 
-     * @since 0.7.0; use {@link #postRelesae(JcloudsMachineLocation)}
-     */
-    @Deprecated
-    void postRelease(JcloudsSshMachineLocation machine);
-
-    /**
-     * Override to configure the given machine once it has been created and started by Jclouds.
-     * <p/>
-     * If {@link JcloudsLocationConfig#WAIT_FOR_SSHABLE} is true the
-     * machine is guaranteed to be SSHable when this method is called.
+     * <p>
+     * If {@link JcloudsLocationConfig#WAIT_FOR_SSHABLE} is true the machine is guaranteed
to be
+     * SSHable when this method is called.
      */
     void customize(JcloudsLocation location, ComputeService computeService, JcloudsMachineLocation
machine);
-    
+
     /**
      * Override to handle machine-related cleanup before Jclouds is called to release (destroy)
the machine.
      */

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/70bd8c3f/locations/jclouds/src/main/java/org/apache/brooklyn/location/jclouds/SudoTtyFixingCustomizer.java
----------------------------------------------------------------------
diff --git a/locations/jclouds/src/main/java/org/apache/brooklyn/location/jclouds/SudoTtyFixingCustomizer.java
b/locations/jclouds/src/main/java/org/apache/brooklyn/location/jclouds/SudoTtyFixingCustomizer.java
index 2552874..f2b8d4f 100644
--- a/locations/jclouds/src/main/java/org/apache/brooklyn/location/jclouds/SudoTtyFixingCustomizer.java
+++ b/locations/jclouds/src/main/java/org/apache/brooklyn/location/jclouds/SudoTtyFixingCustomizer.java
@@ -30,19 +30,15 @@ import com.google.common.base.Preconditions;
 /**
  * Wraps Brooklyn's sudo-tty mitigations in a {@link JcloudsLocationCustomizer} for easy(-ish)
consumption
  * in YAML blueprints:
+ * <pre>{@code
+ * name: My App
+ * brooklyn.config:
+ *   provisioning.properties:
+ *     customizerType: SudoTtyFixingCustomizer
+ * }</pre>
+ * This class should be seen as a temporary workaround and might disappear completely if/when
Brooklyn takes care of this automatically.
  *
- * <pre>
- *   name: My App
- *   brooklyn.config:
- *     provisioning.properties:
- *       customizerType: SudoTtyFixingCustomizer
- *   services: ...
- * </pre>
- *
- * <p>This class should be seen as a temporary workaround and might disappear completely
if/when Brooklyn takes care of this automatically.
- *
- * <p>See
- * <a href='http://unix.stackexchange.com/questions/122616/why-do-i-need-a-tty-to-run-sudo-if-i-can-sudo-without-a-password'>http://unix.stackexchange.com/questions/122616/why-do-i-need-a-tty-to-run-sudo-if-i-can-sudo-without-a-password</a>
+ * @see <a href='http://unix.stackexchange.com/questions/122616/why-do-i-need-a-tty-to-run-sudo-if-i-can-sudo-without-a-password'>http://unix.stackexchange.com/questions/122616/why-do-i-need-a-tty-to-run-sudo-if-i-can-sudo-without-a-password</a>
  * for background.
  */
 @Beta

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/70bd8c3f/locations/jclouds/src/main/java/org/apache/brooklyn/location/jclouds/networking/JcloudsLocationSecurityGroupCustomizer.java
----------------------------------------------------------------------
diff --git a/locations/jclouds/src/main/java/org/apache/brooklyn/location/jclouds/networking/JcloudsLocationSecurityGroupCustomizer.java
b/locations/jclouds/src/main/java/org/apache/brooklyn/location/jclouds/networking/JcloudsLocationSecurityGroupCustomizer.java
index 3d6bc22..4dcce1a 100644
--- a/locations/jclouds/src/main/java/org/apache/brooklyn/location/jclouds/networking/JcloudsLocationSecurityGroupCustomizer.java
+++ b/locations/jclouds/src/main/java/org/apache/brooklyn/location/jclouds/networking/JcloudsLocationSecurityGroupCustomizer.java
@@ -27,35 +27,9 @@ import java.util.concurrent.ExecutionException;
 
 import javax.annotation.Nullable;
 
-import org.apache.brooklyn.api.entity.Entity;
-import org.apache.brooklyn.core.location.geo.LocalhostExternalIpLoader;
-import org.apache.brooklyn.location.jclouds.JcloudsLocation;
-import org.apache.brooklyn.location.jclouds.JcloudsLocationCustomizer;
-import org.apache.brooklyn.location.jclouds.JcloudsMachineLocation;
-import org.apache.brooklyn.location.jclouds.JcloudsSshMachineLocation;
-
-import org.jclouds.aws.AWSResponseException;
-import org.jclouds.compute.ComputeService;
-import org.jclouds.compute.domain.SecurityGroup;
-import org.jclouds.compute.domain.Template;
-import org.jclouds.compute.extensions.SecurityGroupExtension;
-import org.jclouds.domain.Location;
-import org.jclouds.net.domain.IpPermission;
-import org.jclouds.net.domain.IpProtocol;
-import org.jclouds.providers.ProviderMetadata;
-import org.jclouds.providers.Providers;
-
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import org.apache.brooklyn.location.jclouds.BasicJcloudsLocationCustomizer;
-import org.apache.brooklyn.util.collections.MutableList;
-import org.apache.brooklyn.util.core.task.Tasks;
-import org.apache.brooklyn.util.exceptions.Exceptions;
-import org.apache.brooklyn.util.net.Cidr;
-import org.apache.brooklyn.util.time.Duration;
-
-import com.google.common.annotations.Beta;
 import com.google.common.annotations.VisibleForTesting;
 import com.google.common.base.Function;
 import com.google.common.base.Optional;
@@ -74,19 +48,44 @@ import com.google.common.collect.ImmutableSet;
 import com.google.common.collect.Iterables;
 import com.google.common.util.concurrent.UncheckedExecutionException;
 
+import org.jclouds.aws.AWSResponseException;
+import org.jclouds.compute.ComputeService;
+import org.jclouds.compute.domain.SecurityGroup;
+import org.jclouds.compute.domain.Template;
+import org.jclouds.compute.extensions.SecurityGroupExtension;
+import org.jclouds.domain.Location;
+import org.jclouds.net.domain.IpPermission;
+import org.jclouds.net.domain.IpProtocol;
+import org.jclouds.providers.ProviderMetadata;
+import org.jclouds.providers.Providers;
+
+import org.apache.brooklyn.api.entity.Entity;
+import org.apache.brooklyn.core.location.geo.LocalhostExternalIpLoader;
+import org.apache.brooklyn.location.jclouds.BasicJcloudsLocationCustomizer;
+import org.apache.brooklyn.location.jclouds.JcloudsLocation;
+import org.apache.brooklyn.location.jclouds.JcloudsLocationConfig;
+import org.apache.brooklyn.location.jclouds.JcloudsLocationCustomizer;
+import org.apache.brooklyn.location.jclouds.JcloudsMachineLocation;
+import org.apache.brooklyn.location.jclouds.JcloudsSshMachineLocation;
+import org.apache.brooklyn.util.collections.MutableList;
+import org.apache.brooklyn.util.core.task.Tasks;
+import org.apache.brooklyn.util.exceptions.Exceptions;
+import org.apache.brooklyn.util.net.Cidr;
+import org.apache.brooklyn.util.time.Duration;
+
 /**
  * Configures custom security groups on Jclouds locations.
- *
- * @see SecurityGroupExtension is an optional extension to jclouds compute service. It allows
the manipulation of
- * {@link SecurityGroup}s.
- *
+ * <p>
  * This customizer can be injected into {@link JcloudsLocation#obtainOnce} using
- * It will be executed after the provisiioning of the {@link JcloudsMachineLocation} to apply
app-specific
- * customization related to the security groups.
+ * the {@link JcloudsLocationConfig#JCLOUDS_LOCATION_CUSTOMIZERS} configuration key.
+ * It will be executed after the provisiioning of the {@link JcloudsMachineLocation}
+ * to apply app-specific customization related to the security groups.
+ * <p>
+ * {@link SecurityGroupExtension} is an optional extension to the jclouds compute
+ * service. It allows the manipulation of {@link SecurityGroup security groups}.
  *
  * @since 0.7.0
  */
-@Beta
 public class JcloudsLocationSecurityGroupCustomizer extends BasicJcloudsLocationCustomizer
{
 
     private static final Logger LOG = LoggerFactory.getLogger(JcloudsLocationSecurityGroupCustomizer.class);

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/70bd8c3f/locations/jclouds/src/main/java/org/apache/brooklyn/location/jclouds/softlayer/SoftLayerSameVlanLocationCustomizer.java
----------------------------------------------------------------------
diff --git a/locations/jclouds/src/main/java/org/apache/brooklyn/location/jclouds/softlayer/SoftLayerSameVlanLocationCustomizer.java
b/locations/jclouds/src/main/java/org/apache/brooklyn/location/jclouds/softlayer/SoftLayerSameVlanLocationCustomizer.java
index 5158a0c..8ada2aa 100644
--- a/locations/jclouds/src/main/java/org/apache/brooklyn/location/jclouds/softlayer/SoftLayerSameVlanLocationCustomizer.java
+++ b/locations/jclouds/src/main/java/org/apache/brooklyn/location/jclouds/softlayer/SoftLayerSameVlanLocationCustomizer.java
@@ -105,26 +105,16 @@ public class SoftLayerSameVlanLocationCustomizer extends BasicJcloudsLocationCus
     public static final AttributeSensor<Integer> PRIVATE_VLAN_ID = Sensors.newIntegerSensor(
             "softLayer.vlan.privateId", "The private VLAN ID for this entity");
 
-    /* Flags passed in on object creation. */
-    private final Map<String, ?> flags;
-
     /* Lock object for global critical sections accessing shared state maps. */
     private static final transient Object lock = new Object[0];
 
     /** Convenience creation method. */
     public static SoftLayerSameVlanLocationCustomizer forScope(String scopeUid) {
-        SoftLayerSameVlanLocationCustomizer customizer = new SoftLayerSameVlanLocationCustomizer(ImmutableMap.of(SCOPE_UID.getName(),
scopeUid));
+        SoftLayerSameVlanLocationCustomizer customizer = new SoftLayerSameVlanLocationCustomizer();
+        customizer.config().set(SCOPE_UID, scopeUid);
         return customizer;
     }
 
-    public SoftLayerSameVlanLocationCustomizer() {
-        this(ImmutableMap.<String, Object>of());
-    }
-
-    public SoftLayerSameVlanLocationCustomizer(Map<String, ?> flags) {
-        this.flags = ImmutableMap.copyOf(flags);
-    }
-
     /**
      * Update the {@link org.jclouds.compute.options.TemplateOptions} that will
      * be used by {@link JcloudsLocation} to obtain machines. Uses the VLAN
@@ -287,7 +277,7 @@ public class SoftLayerSameVlanLocationCustomizer extends BasicJcloudsLocationCus
 
     /* Save the VLAN IDs as sensor data on the entity and set tag. */
     private void saveVlanDetails(JcloudsMachineLocation machine, String scopeUid, Integer
privateVlanId, Integer publicVlanId) {
-        Object context = flags.get(LocationConfigKeys.CALLER_CONTEXT.getName());
+        Object context = config().get(LocationConfigKeys.CALLER_CONTEXT);
         if (context == null) {
             context = machine.config().get(LocationConfigKeys.CALLER_CONTEXT);
         }
@@ -306,7 +296,7 @@ public class SoftLayerSameVlanLocationCustomizer extends BasicJcloudsLocationCus
      * location flags, or the location itself.
      */
     private Duration getTimeout(JcloudsLocation location) {
-        Duration timeout = (Duration) flags.get(SCOPE_TIMEOUT.getName());
+        Duration timeout = config().get(SCOPE_TIMEOUT);
         if (timeout == null) {
             timeout = location.config().get(SCOPE_TIMEOUT);
         }
@@ -318,7 +308,7 @@ public class SoftLayerSameVlanLocationCustomizer extends BasicJcloudsLocationCus
      * location itself.
      */
     private String getScopeUid(JcloudsLocation location) {
-        String scopeUid = (String) flags.get(SCOPE_UID.getName());
+        String scopeUid = config().get(SCOPE_UID);
         if (Strings.isEmpty(scopeUid)) {
             scopeUid = location.config().get(SCOPE_UID);
         }


Mime
View raw message