From 3f7058454cf6f479c713d6a43ed8a5fbe844a9f3 Mon Sep 17 00:00:00 2001 From: "adrian.f.cole" Date: Thu, 31 Dec 2009 18:08:30 +0000 Subject: [PATCH] Issue 29: changed userData to automatically encode data git-svn-id: http://jclouds.googlecode.com/svn/trunk@2559 3d8758e0-26b5-11de-8745-db77d3ebf521 --- .../jclouds/aws/ec2/options/RunInstancesOptions.java | 11 ++++++----- ...loudApplicationArchitecturesEC2ClientLiveTest.java | 5 +---- .../org/jclouds/aws/ec2/demos/createlamp/MainApp.java | 10 +++------- 3 files changed, 10 insertions(+), 16 deletions(-) diff --git a/aws/core/src/main/java/org/jclouds/aws/ec2/options/RunInstancesOptions.java b/aws/core/src/main/java/org/jclouds/aws/ec2/options/RunInstancesOptions.java index 9521eea722..66d5a3a199 100644 --- a/aws/core/src/main/java/org/jclouds/aws/ec2/options/RunInstancesOptions.java +++ b/aws/core/src/main/java/org/jclouds/aws/ec2/options/RunInstancesOptions.java @@ -22,6 +22,7 @@ import static com.google.common.base.Preconditions.checkNotNull; import org.jclouds.aws.ec2.domain.InstanceType; import org.jclouds.aws.ec2.options.internal.BaseEC2RequestOptions; +import org.jclouds.encryption.internal.Base64; /** * Contains options supported in the Form API for the RunInstances operation.

@@ -81,10 +82,10 @@ public class RunInstancesOptions extends BaseEC2RequestOptions { } /** - * MIME, Base64-encoded user data. + * Unencoded data */ - public RunInstancesOptions withUserData(String data) { - formParameters.put("UserData", checkNotNull(data, "data")); + public RunInstancesOptions withUserData(byte[] data) { + formParameters.put("UserData", Base64.encodeBytes(checkNotNull(data, "data"))); return this; } @@ -207,9 +208,9 @@ public class RunInstancesOptions extends BaseEC2RequestOptions { } /** - * @see RunInstancesOptions#withUserData(String) + * @see RunInstancesOptions#withUserData(byte []) */ - public static RunInstancesOptions withUserData(String userData) { + public static RunInstancesOptions withUserData(byte[] userData) { RunInstancesOptions options = new RunInstancesOptions(); return options.withUserData(userData); } diff --git a/aws/core/src/test/java/org/jclouds/aws/ec2/CloudApplicationArchitecturesEC2ClientLiveTest.java b/aws/core/src/test/java/org/jclouds/aws/ec2/CloudApplicationArchitecturesEC2ClientLiveTest.java index df27e89857..5482273b6e 100644 --- a/aws/core/src/test/java/org/jclouds/aws/ec2/CloudApplicationArchitecturesEC2ClientLiveTest.java +++ b/aws/core/src/test/java/org/jclouds/aws/ec2/CloudApplicationArchitecturesEC2ClientLiveTest.java @@ -45,7 +45,6 @@ import org.jclouds.aws.ec2.domain.RunningInstance; import org.jclouds.aws.ec2.domain.Image.EbsBlockDevice; import org.jclouds.aws.ec2.domain.Volume.InstanceInitiatedShutdownBehavior; import org.jclouds.aws.ec2.predicates.InstanceStateRunning; -import org.jclouds.encryption.internal.Base64; import org.jclouds.http.HttpResponseException; import org.jclouds.logging.log4j.config.Log4JLoggingModule; import org.jclouds.predicates.RetryablePredicate; @@ -145,8 +144,6 @@ public class CloudApplicationArchitecturesEC2ClientLiveTest { .addStatement(exec("runurl run.alestic.com/install/lamp"))// .build(OsFamily.UNIX); - // userData must be base 64 encoded - String encodedScript = Base64.encodeBytes(script.getBytes()); RunningInstance instance = null; while (instance == null) { try { @@ -160,7 +157,7 @@ public class CloudApplicationArchitecturesEC2ClientLiveTest { asType(InstanceType.M1_SMALL) // smallest instance size .withKeyName(keyPair.getKeyName()) // key I created above .withSecurityGroup(securityGroupName) // group I created above - .withUserData(encodedScript)); // script to run as root + .withUserData(script.getBytes())); // script to run as root instance = Iterables.getOnlyElement(reservation.getRunningInstances()); diff --git a/aws/demos/createlamp/src/main/java/org/jclouds/aws/ec2/demos/createlamp/MainApp.java b/aws/demos/createlamp/src/main/java/org/jclouds/aws/ec2/demos/createlamp/MainApp.java index 052e779931..c5918937c0 100755 --- a/aws/demos/createlamp/src/main/java/org/jclouds/aws/ec2/demos/createlamp/MainApp.java +++ b/aws/demos/createlamp/src/main/java/org/jclouds/aws/ec2/demos/createlamp/MainApp.java @@ -38,7 +38,6 @@ import org.jclouds.aws.ec2.domain.Region; import org.jclouds.aws.ec2.domain.Reservation; import org.jclouds.aws.ec2.domain.RunningInstance; import org.jclouds.aws.ec2.predicates.InstanceStateRunning; -import org.jclouds.encryption.internal.Base64; import org.jclouds.predicates.RetryablePredicate; import org.jclouds.predicates.SocketOpen; import org.jclouds.rest.RestContext; @@ -160,13 +159,10 @@ public class MainApp { static RunningInstance runInstance(EC2Client client, String securityGroupName, String keyPairName) { String script = new ScriptBuilder() // lamp install script - .addStatement(exec("runurl run.alestic.com/apt/upgrade")) - .addStatement(exec("runurl run.alestic.com/install/lamp")) + .addStatement(exec("runurl run.alestic.com/apt/upgrade"))// + .addStatement(exec("runurl run.alestic.com/install/lamp"))// .build(OsFamily.UNIX); - // userData must be base 64 encoded - String encodedScript = Base64.encodeBytes(script.getBytes()); - System.out.printf("%d: running instance%n", System.currentTimeMillis()); Reservation reservation = client.getInstanceServices().runInstancesInRegion(Region.DEFAULT, null, // allow ec2 to chose an availability zone @@ -176,7 +172,7 @@ public class MainApp { asType(InstanceType.M1_SMALL) // smallest instance size .withKeyName(keyPairName) // key I created above .withSecurityGroup(securityGroupName) // group I created above - .withUserData(encodedScript)); // script to run as root + .withUserData(script.getBytes())); // script to run as root return Iterables.getOnlyElement(reservation.getRunningInstances());