diff --git a/atmos/src/main/java/org/jclouds/atmosonline/saas/domain/internal/AtmosObjectImpl.java b/atmos/src/main/java/org/jclouds/atmosonline/saas/domain/internal/AtmosObjectImpl.java index 5efa18dbf1..6ac3226f43 100644 --- a/atmos/src/main/java/org/jclouds/atmosonline/saas/domain/internal/AtmosObjectImpl.java +++ b/atmos/src/main/java/org/jclouds/atmosonline/saas/domain/internal/AtmosObjectImpl.java @@ -26,10 +26,10 @@ import org.jclouds.atmosonline.saas.domain.AtmosObject; import org.jclouds.atmosonline.saas.domain.MutableContentMetadata; import org.jclouds.atmosonline.saas.domain.SystemMetadata; import org.jclouds.atmosonline.saas.domain.UserMetadata; -import org.jclouds.http.Payload; import org.jclouds.http.PayloadEnclosing; import org.jclouds.http.internal.PayloadEnclosingImpl; -import org.jclouds.http.payloads.DelegatingPayload; +import org.jclouds.io.Payload; +import org.jclouds.io.payloads.DelegatingPayload; import com.google.common.collect.LinkedHashMultimap; import com.google.common.collect.Multimap; diff --git a/atmos/src/test/java/org/jclouds/atmosonline/saas/AtmosStorageClientLiveTest.java b/atmos/src/test/java/org/jclouds/atmosonline/saas/AtmosStorageClientLiveTest.java index 720c9f6880..d598ac4b4b 100644 --- a/atmos/src/test/java/org/jclouds/atmosonline/saas/AtmosStorageClientLiveTest.java +++ b/atmos/src/test/java/org/jclouds/atmosonline/saas/AtmosStorageClientLiveTest.java @@ -40,8 +40,8 @@ import org.jclouds.blobstore.KeyAlreadyExistsException; import org.jclouds.blobstore.KeyNotFoundException; import org.jclouds.blobstore.integration.internal.BaseBlobStoreIntegrationTest; import org.jclouds.http.HttpResponseException; -import org.jclouds.http.Payloads; -import org.jclouds.http.payloads.InputStreamPayload; +import org.jclouds.io.Payloads; +import org.jclouds.io.payloads.InputStreamPayload; import org.jclouds.logging.log4j.config.Log4JLoggingModule; import org.jclouds.rest.RestContext; import org.jclouds.util.Utils; diff --git a/atmos/src/test/java/org/jclouds/atmosonline/saas/functions/ParseSystemMetadataFromHeadersTest.java b/atmos/src/test/java/org/jclouds/atmosonline/saas/functions/ParseSystemMetadataFromHeadersTest.java index fec3ff2269..adb00e38dd 100644 --- a/atmos/src/test/java/org/jclouds/atmosonline/saas/functions/ParseSystemMetadataFromHeadersTest.java +++ b/atmos/src/test/java/org/jclouds/atmosonline/saas/functions/ParseSystemMetadataFromHeadersTest.java @@ -25,7 +25,7 @@ import org.jclouds.atmosonline.saas.domain.SystemMetadata; import org.jclouds.date.DateService; import org.jclouds.encryption.EncryptionService; import org.jclouds.http.HttpResponse; -import org.jclouds.http.Payloads; +import org.jclouds.io.Payloads; import org.testng.annotations.Test; import com.google.inject.Guice; diff --git a/aws/core/src/main/java/org/jclouds/aws/ec2/compute/options/EC2TemplateOptions.java b/aws/core/src/main/java/org/jclouds/aws/ec2/compute/options/EC2TemplateOptions.java index 759180c13d..c9d630ad1b 100644 --- a/aws/core/src/main/java/org/jclouds/aws/ec2/compute/options/EC2TemplateOptions.java +++ b/aws/core/src/main/java/org/jclouds/aws/ec2/compute/options/EC2TemplateOptions.java @@ -26,17 +26,18 @@ import java.util.Arrays; import java.util.Set; import org.jclouds.compute.options.TemplateOptions; +import org.jclouds.io.Payload; import org.jclouds.util.Utils; import com.google.common.collect.ImmutableSet; import com.google.common.collect.Iterables; /** - * Contains options supported in the {@code ComputeService#runNode} operation on the "ec2" provider. - *

- * Usage

The recommended way to instantiate a EC2TemplateOptions object is to statically import - * EC2TemplateOptions.* and invoke a static creation method followed by an instance mutator (if - * needed): + * Contains options supported in the {@code ComputeService#runNode} operation on + * the "ec2" provider.

+ * Usage

The recommended way to instantiate a EC2TemplateOptions object is + * to statically import EC2TemplateOptions.* and invoke a static creation method + * followed by an instance mutator (if needed): *

* * import static org.jclouds.aws.ec2.compute.options.EC2TemplateOptions.Builder.*; @@ -239,14 +240,6 @@ public class EC2TemplateOptions extends TemplateOptions { // methods that only facilitate returning the correct object type - /** - * @see TemplateOptions#authorizePublicKey - */ - @Override - public EC2TemplateOptions authorizePublicKey(String publicKey) { - return EC2TemplateOptions.class.cast(super.authorizePublicKey(publicKey)); - } - /** * @see TemplateOptions#blockOnPort */ @@ -257,9 +250,10 @@ public class EC2TemplateOptions extends TemplateOptions { /** * - * special thing is that we do assume if you are passing groups that you have everything you need - * already defined. for example, our option inboundPorts normally creates ingress rules - * accordingly but if we notice you've specified securityGroups, we do not mess with rules at all + * special thing is that we do assume if you are passing groups that you have + * everything you need already defined. for example, our option inboundPorts + * normally creates ingress rules accordingly but if we notice you've + * specified securityGroups, we do not mess with rules at all * * @see TemplateOptions#inboundPorts */ @@ -269,17 +263,52 @@ public class EC2TemplateOptions extends TemplateOptions { } /** - * @see TemplateOptions#installPrivateKey + * @see TemplateOptions#authorizePublicKey(String) */ @Override + @Deprecated + public EC2TemplateOptions authorizePublicKey(String publicKey) { + return EC2TemplateOptions.class.cast(super.authorizePublicKey(publicKey)); + } + + /** + * @see TemplateOptions#authorizePublicKey(Payload) + */ + @Override + public EC2TemplateOptions authorizePublicKey(Payload publicKey) { + return EC2TemplateOptions.class.cast(super.authorizePublicKey(publicKey)); + } + + /** + * @see TemplateOptions#installPrivateKey(String) + */ + @Override + @Deprecated public EC2TemplateOptions installPrivateKey(String privateKey) { return EC2TemplateOptions.class.cast(super.installPrivateKey(privateKey)); } /** - * @see TemplateOptions#runScript + * @see TemplateOptions#installPrivateKey(Payload) */ @Override + public EC2TemplateOptions installPrivateKey(Payload privateKey) { + return EC2TemplateOptions.class.cast(super.installPrivateKey(privateKey)); + } + + /** + * @see TemplateOptions#runScript(Payload) + */ + @Override + public EC2TemplateOptions runScript(Payload script) { + return EC2TemplateOptions.class.cast(super.runScript(script)); + } + + /** + * @see TemplateOptions#runScript(byte[]) + */ + @Override + @Deprecated public EC2TemplateOptions runScript(byte[] script) { return EC2TemplateOptions.class.cast(super.runScript(script)); } @@ -293,15 +322,16 @@ public class EC2TemplateOptions extends TemplateOptions { } /** - * @return groupIds the user specified to run instances with, or zero length set to create an - * implicit group + * @return groupIds the user specified to run instances with, or zero length + * set to create an implicit group */ public Set getGroupIds() { return groupIds; } /** - * @return keyPair to use when running the instance or null, to generate a keypair. + * @return keyPair to use when running the instance or null, to generate a + * keypair. */ public String getKeyPair() { return keyPair; @@ -315,7 +345,8 @@ public class EC2TemplateOptions extends TemplateOptions { } /** - * @return placementGroup to use when running the instance or null, to generate a placementGroup. + * @return placementGroup to use when running the instance or null, to + * generate a placementGroup. */ public String getPlacementGroup() { return placementGroup; @@ -387,10 +418,10 @@ public class EC2TemplateOptions extends TemplateOptions { @Override public String toString() { return "[groupIds=" + groupIds + ", keyPair=" + keyPair + ", noKeyPair=" + noKeyPair + ", placementGroup=" - + placementGroup + ", noPlacementGroup=" + noPlacementGroup + ", inboundPorts=" - + Arrays.toString(inboundPorts) + ", privateKey=" + (privateKey != null) + ", publicKey=" - + (publicKey != null) + ", runScript=" + (script != null) + ", port:seconds=" + port + ":" + seconds - + ", subnetId=" + subnetId + ", metadata/details: " + includeMetadata + "]"; + + placementGroup + ", noPlacementGroup=" + noPlacementGroup + ", inboundPorts=" + + Arrays.toString(inboundPorts) + ", privateKey=" + (privateKey != null) + ", publicKey=" + + (publicKey != null) + ", runScript=" + (script != null) + ", port:seconds=" + port + ":" + seconds + + ", subnetId=" + subnetId + ", metadata/details: " + includeMetadata + "]"; } } diff --git a/aws/core/src/main/java/org/jclouds/aws/s3/domain/internal/S3ObjectImpl.java b/aws/core/src/main/java/org/jclouds/aws/s3/domain/internal/S3ObjectImpl.java index 5acd0bf7cf..3ce5d35b14 100644 --- a/aws/core/src/main/java/org/jclouds/aws/s3/domain/internal/S3ObjectImpl.java +++ b/aws/core/src/main/java/org/jclouds/aws/s3/domain/internal/S3ObjectImpl.java @@ -25,10 +25,10 @@ import javax.inject.Inject; import org.jclouds.aws.s3.domain.AccessControlList; import org.jclouds.aws.s3.domain.MutableObjectMetadata; import org.jclouds.aws.s3.domain.S3Object; -import org.jclouds.http.Payload; import org.jclouds.http.PayloadEnclosing; import org.jclouds.http.internal.PayloadEnclosingImpl; -import org.jclouds.http.payloads.DelegatingPayload; +import org.jclouds.io.Payload; +import org.jclouds.io.payloads.DelegatingPayload; import com.google.common.collect.LinkedHashMultimap; import com.google.common.collect.Multimap; diff --git a/aws/core/src/test/java/org/jclouds/aws/ec2/EBSBootEC2ClientLiveTest.java b/aws/core/src/test/java/org/jclouds/aws/ec2/EBSBootEC2ClientLiveTest.java index 9d3070cd2e..4a5888be03 100644 --- a/aws/core/src/test/java/org/jclouds/aws/ec2/EBSBootEC2ClientLiveTest.java +++ b/aws/core/src/test/java/org/jclouds/aws/ec2/EBSBootEC2ClientLiveTest.java @@ -26,7 +26,6 @@ import static org.jclouds.aws.ec2.options.RunInstancesOptions.Builder.withKeyNam import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertNotNull; -import java.io.ByteArrayInputStream; import java.io.IOException; import java.net.UnknownHostException; import java.util.Map; @@ -58,6 +57,7 @@ import org.jclouds.aws.ec2.predicates.SnapshotCompleted; import org.jclouds.aws.ec2.predicates.VolumeAttached; import org.jclouds.aws.ec2.predicates.VolumeAvailable; import org.jclouds.http.HttpResponseException; +import org.jclouds.io.Payloads; import org.jclouds.logging.log4j.config.Log4JLoggingModule; import org.jclouds.net.IPSocket; import org.jclouds.predicates.RetryablePredicate; @@ -81,8 +81,8 @@ import com.google.inject.Module; import com.google.inject.internal.ImmutableMap; /** - * Adapted from the following sources: {@link http://gist.github.com/249915}, {@link http - * ://www.capsunlock.net/2009/12/create-ebs-boot-ami.html} + * Adapted from the following sources: {@link http://gist.github.com/249915}, + * {@link http ://www.capsunlock.net/2009/12/create-ebs-boot-ami.html} *

* * Generally disabled, as it incurs higher fees. @@ -123,7 +123,7 @@ public class EBSBootEC2ClientLiveTest { String identity = checkNotNull(System.getProperty("jclouds.test.identity"), "jclouds.test.identity"); String credential = checkNotNull(System.getProperty("jclouds.test.credential"), "jclouds.test.credential"); Injector injector = new RestContextFactory().createContextBuilder("ec2", identity, credential, - ImmutableSet. of(new Log4JLoggingModule())).buildInjector(); + ImmutableSet. of(new Log4JLoggingModule())).buildInjector(); client = injector.getInstance(EC2Client.class); sshFactory = injector.getInstance(SshClient.Factory.class); SocketOpen socketOpen = injector.getInstance(SocketOpen.class); @@ -138,24 +138,20 @@ public class EBSBootEC2ClientLiveTest { VolumeAttached volumeAttached = injector.getInstance(VolumeAttached.class); attachTester = new RetryablePredicate(volumeAttached, 60, 1, TimeUnit.SECONDS); - runningTester = new RetryablePredicate(new InstanceStateRunning(client), - 180, 5, TimeUnit.SECONDS); + runningTester = new RetryablePredicate(new InstanceStateRunning(client), 180, 5, + TimeUnit.SECONDS); InstanceStateStopped instanceStateStopped = injector.getInstance(InstanceStateStopped.class); - stoppedTester = new RetryablePredicate(instanceStateStopped, 60, 1, - TimeUnit.SECONDS); + stoppedTester = new RetryablePredicate(instanceStateStopped, 60, 1, TimeUnit.SECONDS); - InstanceStateTerminated instanceStateTerminated = injector - .getInstance(InstanceStateTerminated.class); - terminatedTester = new RetryablePredicate(instanceStateTerminated, 60, 1, - TimeUnit.SECONDS); + InstanceStateTerminated instanceStateTerminated = injector.getInstance(InstanceStateTerminated.class); + terminatedTester = new RetryablePredicate(instanceStateTerminated, 60, 1, TimeUnit.SECONDS); injector.injectMembers(socketOpen); // add logger } @Test(enabled = false) - void testCreateSecurityGroupIngressCidr() throws InterruptedException, ExecutionException, - TimeoutException { + void testCreateSecurityGroupIngressCidr() throws InterruptedException, ExecutionException, TimeoutException { securityGroupName = INSTANCE_PREFIX + "ingress"; try { @@ -163,14 +159,13 @@ public class EBSBootEC2ClientLiveTest { } catch (Exception e) { } - client.getSecurityGroupServices().createSecurityGroupInRegion(null, securityGroupName, - securityGroupName); - client.getSecurityGroupServices().authorizeSecurityGroupIngressInRegion(null, - securityGroupName, IpProtocol.TCP, 80, 80, "0.0.0.0/0"); - client.getSecurityGroupServices().authorizeSecurityGroupIngressInRegion(null, - securityGroupName, IpProtocol.TCP, 443, 443, "0.0.0.0/0"); - client.getSecurityGroupServices().authorizeSecurityGroupIngressInRegion(null, - securityGroupName, IpProtocol.TCP, 22, 22, "0.0.0.0/0"); + client.getSecurityGroupServices().createSecurityGroupInRegion(null, securityGroupName, securityGroupName); + client.getSecurityGroupServices().authorizeSecurityGroupIngressInRegion(null, securityGroupName, IpProtocol.TCP, + 80, 80, "0.0.0.0/0"); + client.getSecurityGroupServices().authorizeSecurityGroupIngressInRegion(null, securityGroupName, IpProtocol.TCP, + 443, 443, "0.0.0.0/0"); + client.getSecurityGroupServices().authorizeSecurityGroupIngressInRegion(null, securityGroupName, IpProtocol.TCP, + 22, 22, "0.0.0.0/0"); } @Test(enabled = false) @@ -189,8 +184,7 @@ public class EBSBootEC2ClientLiveTest { assertEquals(keyPair.getKeyName(), keyName); } - @Test(enabled = false, dependsOnMethods = { "testCreateKeyPair", - "testCreateSecurityGroupIngressCidr" }) + @Test(enabled = false, dependsOnMethods = { "testCreateKeyPair", "testCreateSecurityGroupIngressCidr" }) public void testCreateRunningInstance() throws Exception { instance = createInstance(IMAGE_ID); } @@ -201,18 +195,18 @@ public class EBSBootEC2ClientLiveTest { try { System.out.printf("%d: running instance%n", System.currentTimeMillis()); Reservation reservation = client.getInstanceServices().runInstancesInRegion(null, null, // allow - // ec2 - // to - // chose - // an - // availability - // zone - imageId, 1, // minimum instances - 1, // maximum instances - withKeyName(keyPair.getKeyName())// key I created above - .asType(InstanceType.M1_SMALL)// smallest instance - // size - .withSecurityGroup(securityGroupName));// group I + // ec2 + // to + // chose + // an + // availability + // zone + imageId, 1, // minimum instances + 1, // maximum instances + withKeyName(keyPair.getKeyName())// key I created above + .asType(InstanceType.M1_SMALL)// smallest instance + // size + .withSecurityGroup(securityGroupName));// group I // created // above instance = Iterables.getOnlyElement(reservation); @@ -230,22 +224,19 @@ public class EBSBootEC2ClientLiveTest { @Test(enabled = false, dependsOnMethods = "testCreateRunningInstance") void testCreateAndAttachVolume() { - volume = client.getElasticBlockStoreServices().createVolumeInAvailabilityZone( - instance.getAvailabilityZone(), VOLUME_SIZE); - System.out.printf("%d: %s awaiting volume to become available%n", System.currentTimeMillis(), - volume.getId()); + volume = client.getElasticBlockStoreServices().createVolumeInAvailabilityZone(instance.getAvailabilityZone(), + VOLUME_SIZE); + System.out.printf("%d: %s awaiting volume to become available%n", System.currentTimeMillis(), volume.getId()); assert volumeTester.apply(volume); - Attachment attachment = client.getElasticBlockStoreServices().attachVolumeInRegion( - instance.getRegion(), volume.getId(), instance.getId(), "/dev/sdh"); + Attachment attachment = client.getElasticBlockStoreServices().attachVolumeInRegion(instance.getRegion(), + volume.getId(), instance.getId(), "/dev/sdh"); - System.out.printf("%d: %s awaiting attachment to complete%n", System.currentTimeMillis(), - attachment.getId()); + System.out.printf("%d: %s awaiting attachment to complete%n", System.currentTimeMillis(), attachment.getId()); assert attachTester.apply(attachment); - System.out.printf("%d: %s attachment complete%n", System.currentTimeMillis(), attachment - .getId()); + System.out.printf("%d: %s attachment complete%n", System.currentTimeMillis(), attachment.getId()); } // TODO use userData to do this, and make initbuilder an example for @@ -254,34 +245,35 @@ public class EBSBootEC2ClientLiveTest { void makeScript() { mkEbsBoot = new InitBuilder( - "mkebsboot",// name of the script - "/tmp",// working directory - "/tmp/logs",// location of stdout.log and stderr.log - ImmutableMap.of("imageDir", "/mnt/tmp", "ebsDevice", "/dev/sdh", "ebsMountPoint", - "/mnt/ebs"),// variables used inside of the - // script - "echo creating a filesystem and mounting the ebs volume",// what to - // execute - "{md} {varl}IMAGE_DIR{varr} {varl}EBS_MOUNT_POINT{varr}", - "rm -rf {varl}IMAGE_DIR{varr}/*", - "yes| mkfs -t ext3 {varl}EBS_DEVICE{varr} 2>&-", - "mount {varl}EBS_DEVICE{varr} {varl}EBS_MOUNT_POINT{varr}", - "echo making a local working copy of the boot disk", - "rsync -ax --exclude /ubuntu/.bash_history --exclude /home/*/.bash_history --exclude /etc/ssh/ssh_host_* --exclude /etc/ssh/moduli --exclude /etc/udev/rules.d/*persistent-net.rules --exclude /var/lib/ec2/* --exclude=/mnt/* --exclude=/proc/* --exclude=/tmp/* --exclude=/dev/log / {varl}IMAGE_DIR{varr}", - "echo preparing the local working copy", - "touch {varl}IMAGE_DIR{varr}/etc/init.d/ec2-init-user-data", - "echo copying the local working copy to the ebs mount", - "{cd} {varl}IMAGE_DIR{varr}", - "tar -cSf - * | tar xf - -C {varl}EBS_MOUNT_POINT{varr}", "echo size of ebs", - "du -sk {varl}EBS_MOUNT_POINT{varr}", "echo size of source", - "du -sk {varl}IMAGE_DIR{varr}", "rm -rf {varl}IMAGE_DIR{varr}/*", - "umount {varl}EBS_MOUNT_POINT{varr}", "echo " + SCRIPT_END).build(OsFamily.UNIX); + "mkebsboot",// name of the script + "/tmp",// working directory + "/tmp/logs",// location of stdout.log and stderr.log + ImmutableMap.of("imageDir", "/mnt/tmp", "ebsDevice", "/dev/sdh", "ebsMountPoint", "/mnt/ebs"),// variables + // used + // inside + // of + // the + // script + "echo creating a filesystem and mounting the ebs volume",// what to + // execute + "{md} {varl}IMAGE_DIR{varr} {varl}EBS_MOUNT_POINT{varr}", + "rm -rf {varl}IMAGE_DIR{varr}/*", + "yes| mkfs -t ext3 {varl}EBS_DEVICE{varr} 2>&-", + "mount {varl}EBS_DEVICE{varr} {varl}EBS_MOUNT_POINT{varr}", + "echo making a local working copy of the boot disk", + "rsync -ax --exclude /ubuntu/.bash_history --exclude /home/*/.bash_history --exclude /etc/ssh/ssh_host_* --exclude /etc/ssh/moduli --exclude /etc/udev/rules.d/*persistent-net.rules --exclude /var/lib/ec2/* --exclude=/mnt/* --exclude=/proc/* --exclude=/tmp/* --exclude=/dev/log / {varl}IMAGE_DIR{varr}", + "echo preparing the local working copy", "touch {varl}IMAGE_DIR{varr}/etc/init.d/ec2-init-user-data", + "echo copying the local working copy to the ebs mount", "{cd} {varl}IMAGE_DIR{varr}", + "tar -cSf - * | tar xf - -C {varl}EBS_MOUNT_POINT{varr}", "echo size of ebs", + "du -sk {varl}EBS_MOUNT_POINT{varr}", "echo size of source", "du -sk {varl}IMAGE_DIR{varr}", + "rm -rf {varl}IMAGE_DIR{varr}/*", "umount {varl}EBS_MOUNT_POINT{varr}", "echo " + SCRIPT_END) + .build(OsFamily.UNIX); } @Test(enabled = false, dependsOnMethods = "testCreateAndAttachVolume") void testBundleInstance() { - SshClient ssh = sshFactory.create(new IPSocket(instance.getIpAddress(), 22), "ubuntu", - keyPair.getKeyMaterial().getBytes()); + SshClient ssh = sshFactory.create(new IPSocket(instance.getIpAddress(), 22), "ubuntu", keyPair.getKeyMaterial() + .getBytes()); try { ssh.connect(); } catch (SshException e) {// try twice in case there is a network timeout @@ -292,13 +284,11 @@ public class EBSBootEC2ClientLiveTest { ssh.connect(); } try { - System.out.printf("%d: %s writing ebs script%n", System.currentTimeMillis(), instance - .getId()); + System.out.printf("%d: %s writing ebs script%n", System.currentTimeMillis(), instance.getId()); String script = "/tmp/mkebsboot-init.sh"; - ssh.put(script, new ByteArrayInputStream(mkEbsBoot.getBytes())); + ssh.put(script, Payloads.newStringPayload(mkEbsBoot)); - System.out.printf("%d: %s launching ebs script%n", System.currentTimeMillis(), instance - .getId()); + System.out.printf("%d: %s launching ebs script%n", System.currentTimeMillis(), instance.getId()); ssh.exec("chmod 755 " + script); ssh.exec(script + " init"); ExecResponse output = ssh.exec("sudo " + script + " start"); @@ -307,8 +297,8 @@ public class EBSBootEC2ClientLiveTest { assert !output.getOutput().trim().equals("") : output; - RetryablePredicate scriptTester = new RetryablePredicate(new ScriptTester( - ssh, SCRIPT_END), 600, 10, TimeUnit.SECONDS); + RetryablePredicate scriptTester = new RetryablePredicate(new ScriptTester(ssh, SCRIPT_END), + 600, 10, TimeUnit.SECONDS); scriptTester.apply(script); } finally { if (ssh != null) @@ -338,8 +328,7 @@ public class EBSBootEC2ClientLiveTest { output = ssh.exec(script + " tailerr"); String stderr = output.getOutput().trim(); throw new RuntimeException(String.format( - "script %s ended without token: stdout.log: [%s]; stderr.log: [%s]; ", - script, stdout, stderr)); + "script %s ended without token: stdout.log: [%s]; stderr.log: [%s]; ", script, stdout, stderr)); } } return false; @@ -349,47 +338,43 @@ public class EBSBootEC2ClientLiveTest { @Test(enabled = false, dependsOnMethods = "testBundleInstance") void testAMIFromBundle() { - volume = Iterables.getOnlyElement(client.getElasticBlockStoreServices() - .describeVolumesInRegion(volume.getRegion(), volume.getId())); + volume = Iterables.getOnlyElement(client.getElasticBlockStoreServices().describeVolumesInRegion( + volume.getRegion(), volume.getId())); if (volume.getAttachments().size() > 0) { // should be cleanly unmounted, so force is not necessary. - client.getElasticBlockStoreServices().detachVolumeInRegion(instance.getRegion(), - volume.getId(), false); - System.out.printf("%d: %s awaiting detachment to complete%n", System.currentTimeMillis(), - volume.getId()); + client.getElasticBlockStoreServices().detachVolumeInRegion(instance.getRegion(), volume.getId(), false); + System.out.printf("%d: %s awaiting detachment to complete%n", System.currentTimeMillis(), volume.getId()); assert volumeTester.apply(volume); } else { attachment = null; // protect test closer so that it doesn't try to // detach } - snapshot = client.getElasticBlockStoreServices().createSnapshotInRegion(volume.getRegion(), - volume.getId(), withDescription("EBS Ubuntu Hardy")); + snapshot = client.getElasticBlockStoreServices().createSnapshotInRegion(volume.getRegion(), volume.getId(), + withDescription("EBS Ubuntu Hardy")); - System.out.printf("%d: %s awaiting snapshot to complete%n", System.currentTimeMillis(), - snapshot.getId()); + System.out.printf("%d: %s awaiting snapshot to complete%n", System.currentTimeMillis(), snapshot.getId()); assert snapshotTester.apply(snapshot); - Image image = Iterables.getOnlyElement(client.getAMIServices().describeImagesInRegion( - snapshot.getRegion(), imageIds(IMAGE_ID))); + Image image = Iterables.getOnlyElement(client.getAMIServices().describeImagesInRegion(snapshot.getRegion(), + imageIds(IMAGE_ID))); String description = image.getDescription() == null ? "jclouds" : image.getDescription(); - System.out.printf("%d: %s creating ami from snapshot%n", System.currentTimeMillis(), snapshot - .getId()); + System.out.printf("%d: %s creating ami from snapshot%n", System.currentTimeMillis(), snapshot.getId()); String amiId = client.getAMIServices().registerUnixImageBackedByEbsInRegion( - snapshot.getRegion(), - "ebsboot-" + image.getId(), - snapshot.getId(), - withKernelId(image.getKernelId()).withRamdisk(image.getRamdiskId()).withDescription( - description).asArchitecture(Architecture.I386)); + snapshot.getRegion(), + "ebsboot-" + image.getId(), + snapshot.getId(), + withKernelId(image.getKernelId()).withRamdisk(image.getRamdiskId()).withDescription(description) + .asArchitecture(Architecture.I386)); try { - ebsImage = Iterables.getOnlyElement(client.getAMIServices().describeImagesInRegion( - snapshot.getRegion(), imageIds(amiId))); + ebsImage = Iterables.getOnlyElement(client.getAMIServices().describeImagesInRegion(snapshot.getRegion(), + imageIds(amiId))); } catch (AWSResponseException e) { // TODO add a retry handler for this HTTP code 400 and the below error if (e.getError().getClass().equals("InvalidAMIID.NotFound")) - ebsImage = Iterables.getOnlyElement(client.getAMIServices().describeImagesInRegion( - snapshot.getRegion(), imageIds(amiId))); + ebsImage = Iterables.getOnlyElement(client.getAMIServices().describeImagesInRegion(snapshot.getRegion(), + imageIds(amiId))); else throw e; } @@ -398,22 +383,17 @@ public class EBSBootEC2ClientLiveTest { @Test(enabled = false, dependsOnMethods = { "testAMIFromBundle" }) public void testInstanceFromEBS() throws Exception { - System.out.printf("%d: %s creating instance from ebs-backed ami%n", System - .currentTimeMillis(), ebsImage.getId()); + System.out.printf("%d: %s creating instance from ebs-backed ami%n", System.currentTimeMillis(), ebsImage.getId()); ebsInstance = createInstance(ebsImage.getId()); - client.getInstanceServices().stopInstancesInRegion(ebsInstance.getRegion(), true, - ebsInstance.getId()); + client.getInstanceServices().stopInstancesInRegion(ebsInstance.getRegion(), true, ebsInstance.getId()); - System.out.printf("%d: %s awaiting instance to stop %n", System.currentTimeMillis(), - ebsInstance.getId()); + System.out.printf("%d: %s awaiting instance to stop %n", System.currentTimeMillis(), ebsInstance.getId()); stoppedTester.apply(ebsInstance); tryToChangeStuff(); - System.out.printf("%d: %s awaiting instance to start %n", System.currentTimeMillis(), - ebsInstance.getId()); - client.getInstanceServices().startInstancesInRegion(ebsInstance.getRegion(), - ebsInstance.getId()); + System.out.printf("%d: %s awaiting instance to start %n", System.currentTimeMillis(), ebsInstance.getId()); + client.getInstanceServices().startInstancesInRegion(ebsInstance.getRegion(), ebsInstance.getId()); ebsInstance = blockUntilWeCanSshIntoInstance(ebsInstance); } @@ -422,7 +402,7 @@ public class EBSBootEC2ClientLiveTest { assertEquals(ebsImage.getRootDeviceType(), RootDeviceType.EBS); assertEquals(ebsImage.getRootDeviceName(), "/dev/sda1"); assertEquals(ebsImage.getEbsBlockDevices().entrySet(), ImmutableMap.of("/dev/sda1", - new Image.EbsBlockDevice(snapshot.getId(), VOLUME_SIZE, true)).entrySet()); + new Image.EbsBlockDevice(snapshot.getId(), VOLUME_SIZE, true)).entrySet()); } private void tryToChangeStuff() { @@ -435,53 +415,43 @@ public class EBSBootEC2ClientLiveTest { } private void setUserDataForInstanceInRegion() { - client.getInstanceServices().setUserDataForInstanceInRegion(null, ebsInstance.getId(), - "test".getBytes()); - assertEquals("test", client.getInstanceServices().getUserDataForInstanceInRegion(null, - ebsInstance.getId())); + client.getInstanceServices().setUserDataForInstanceInRegion(null, ebsInstance.getId(), "test".getBytes()); + assertEquals("test", client.getInstanceServices().getUserDataForInstanceInRegion(null, ebsInstance.getId())); } private void setRamdiskForInstanceInRegion() { - String ramdisk = client.getInstanceServices().getRamdiskForInstanceInRegion(null, - ebsInstance.getId()); - client.getInstanceServices() - .setRamdiskForInstanceInRegion(null, ebsInstance.getId(), ramdisk); - assertEquals(ramdisk, client.getInstanceServices().getRamdiskForInstanceInRegion(null, - ebsInstance.getId())); + String ramdisk = client.getInstanceServices().getRamdiskForInstanceInRegion(null, ebsInstance.getId()); + client.getInstanceServices().setRamdiskForInstanceInRegion(null, ebsInstance.getId(), ramdisk); + assertEquals(ramdisk, client.getInstanceServices().getRamdiskForInstanceInRegion(null, ebsInstance.getId())); } private void setKernelForInstanceInRegion() { - String oldKernel = client.getInstanceServices().getKernelForInstanceInRegion(null, - ebsInstance.getId()); - client.getInstanceServices().setKernelForInstanceInRegion(null, ebsInstance.getId(), - oldKernel); - assertEquals(oldKernel, client.getInstanceServices().getKernelForInstanceInRegion(null, - ebsInstance.getId())); + String oldKernel = client.getInstanceServices().getKernelForInstanceInRegion(null, ebsInstance.getId()); + client.getInstanceServices().setKernelForInstanceInRegion(null, ebsInstance.getId(), oldKernel); + assertEquals(oldKernel, client.getInstanceServices().getKernelForInstanceInRegion(null, ebsInstance.getId())); } private void setInstanceTypeForInstanceInRegion() { - client.getInstanceServices().setInstanceTypeForInstanceInRegion(null, ebsInstance.getId(), - InstanceType.C1_MEDIUM); - assertEquals(InstanceType.C1_MEDIUM, client.getInstanceServices() - .getInstanceTypeForInstanceInRegion(null, ebsInstance.getId())); - client.getInstanceServices().setInstanceTypeForInstanceInRegion(null, ebsInstance.getId(), - InstanceType.M1_SMALL); - assertEquals(InstanceType.M1_SMALL, client.getInstanceServices() - .getInstanceTypeForInstanceInRegion(null, ebsInstance.getId())); + client.getInstanceServices() + .setInstanceTypeForInstanceInRegion(null, ebsInstance.getId(), InstanceType.C1_MEDIUM); + assertEquals(InstanceType.C1_MEDIUM, client.getInstanceServices().getInstanceTypeForInstanceInRegion(null, + ebsInstance.getId())); + client.getInstanceServices().setInstanceTypeForInstanceInRegion(null, ebsInstance.getId(), InstanceType.M1_SMALL); + assertEquals(InstanceType.M1_SMALL, client.getInstanceServices().getInstanceTypeForInstanceInRegion(null, + ebsInstance.getId())); } private void setBlockDeviceMappingForInstanceInRegion() { String volumeId = ebsInstance.getEbsBlockDevices().get("/dev/sda1").getVolumeId(); BlockDeviceMapping blockDeviceMapping = new BlockDeviceMapping(); - blockDeviceMapping.addEbsBlockDevice("/dev/sda1", new RunningInstance.EbsBlockDevice( - volumeId, false)); + blockDeviceMapping.addEbsBlockDevice("/dev/sda1", new RunningInstance.EbsBlockDevice(volumeId, false)); try { - client.getInstanceServices().setBlockDeviceMappingForInstanceInRegion(null, - ebsInstance.getId(), blockDeviceMapping); + client.getInstanceServices().setBlockDeviceMappingForInstanceInRegion(null, ebsInstance.getId(), + blockDeviceMapping); Map devices = client.getInstanceServices() - .getBlockDeviceMappingForInstanceInRegion(null, ebsInstance.getId()); + .getBlockDeviceMappingForInstanceInRegion(null, ebsInstance.getId()); assertEquals(devices.size(), 1); String deviceName = Iterables.getOnlyElement(devices.keySet()); RunningInstance.EbsBlockDevice device = Iterables.getOnlyElement(devices.values()); @@ -502,17 +472,15 @@ public class EBSBootEC2ClientLiveTest { try { client.getInstanceServices().setInstanceInitiatedShutdownBehaviorForInstanceInRegion(null, - ebsInstance.getId(), InstanceInitiatedShutdownBehavior.STOP); + ebsInstance.getId(), InstanceInitiatedShutdownBehavior.STOP); assertEquals(InstanceInitiatedShutdownBehavior.STOP, client.getInstanceServices() - .getInstanceInitiatedShutdownBehaviorForInstanceInRegion(null, - ebsInstance.getId())); + .getInstanceInitiatedShutdownBehaviorForInstanceInRegion(null, ebsInstance.getId())); client.getInstanceServices().setInstanceInitiatedShutdownBehaviorForInstanceInRegion(null, - ebsInstance.getId(), InstanceInitiatedShutdownBehavior.TERMINATE); + ebsInstance.getId(), InstanceInitiatedShutdownBehavior.TERMINATE); assertEquals(InstanceInitiatedShutdownBehavior.TERMINATE, client.getInstanceServices() - .getInstanceInitiatedShutdownBehaviorForInstanceInRegion(null, - ebsInstance.getId())); + .getInstanceInitiatedShutdownBehaviorForInstanceInRegion(null, ebsInstance.getId())); System.out.println("OK: setInstanceInitiatedShutdownBehaviorForInstanceInRegion"); } catch (Exception e) { System.err.println("setInstanceInitiatedShutdownBehaviorForInstanceInRegion"); @@ -521,7 +489,8 @@ public class EBSBootEC2ClientLiveTest { } /** - * this tests "personality" as the file looked up was sent during instance creation + * this tests "personality" as the file looked up was sent during instance + * creation * * @throws UnknownHostException */ @@ -542,8 +511,7 @@ public class EBSBootEC2ClientLiveTest { } private void doCheckKey(String address) { - SshClient ssh = sshFactory.create(new IPSocket(address, 22), "ubuntu", keyPair - .getKeyMaterial().getBytes()); + SshClient ssh = sshFactory.create(new IPSocket(address, 22), "ubuntu", keyPair.getKeyMaterial().getBytes()); try { ssh.connect(); ExecResponse hello = ssh.exec("echo hello"); @@ -554,15 +522,13 @@ public class EBSBootEC2ClientLiveTest { } } - private RunningInstance blockUntilWeCanSshIntoInstance(RunningInstance instance) - throws UnknownHostException { - System.out.printf("%d: %s awaiting instance to run %n", System.currentTimeMillis(), instance - .getId()); + private RunningInstance blockUntilWeCanSshIntoInstance(RunningInstance instance) throws UnknownHostException { + System.out.printf("%d: %s awaiting instance to run %n", System.currentTimeMillis(), instance.getId()); assert runningTester.apply(instance); // search my identity for the instance I just created - Set reservations = client.getInstanceServices().describeInstancesInRegion( - instance.getRegion(), instance.getId()); // last + Set reservations = client.getInstanceServices().describeInstancesInRegion(instance.getRegion(), + instance.getId()); // last // parameter // (ids) // narrows @@ -571,14 +537,11 @@ public class EBSBootEC2ClientLiveTest { instance = Iterables.getOnlyElement(Iterables.getOnlyElement(reservations)); - System.out.printf("%d: %s awaiting ssh service to start%n", System.currentTimeMillis(), - instance.getIpAddress()); + System.out.printf("%d: %s awaiting ssh service to start%n", System.currentTimeMillis(), instance.getIpAddress()); assert socketTester.apply(new IPSocket(instance.getIpAddress(), 22)); - System.out.printf("%d: %s ssh service started%n", System.currentTimeMillis(), instance - .getDnsName()); + System.out.printf("%d: %s ssh service started%n", System.currentTimeMillis(), instance.getDnsName()); sshPing(instance); - System.out.printf("%d: %s ssh connection made%n", System.currentTimeMillis(), instance - .getId()); + System.out.printf("%d: %s ssh connection made%n", System.currentTimeMillis(), instance.getId()); return instance; } @@ -586,8 +549,7 @@ public class EBSBootEC2ClientLiveTest { void cleanup() { if (ebsInstance != null) { try { - client.getInstanceServices().terminateInstancesInRegion(ebsInstance.getRegion(), - ebsInstance.getId()); + client.getInstanceServices().terminateInstancesInRegion(ebsInstance.getRegion(), ebsInstance.getId()); terminatedTester.apply(ebsInstance); } catch (Exception e) { e.printStackTrace(); @@ -603,16 +565,14 @@ public class EBSBootEC2ClientLiveTest { if (snapshot != null) { try { - client.getElasticBlockStoreServices().deleteSnapshotInRegion(snapshot.getRegion(), - snapshot.getId()); + client.getElasticBlockStoreServices().deleteSnapshotInRegion(snapshot.getRegion(), snapshot.getId()); } catch (Exception e) { e.printStackTrace(); } } if (attachment != null) { try { - client.getElasticBlockStoreServices().detachVolumeInRegion(volume.getRegion(), - volume.getId(), true); + client.getElasticBlockStoreServices().detachVolumeInRegion(volume.getRegion(), volume.getId(), true); assert volumeTester.apply(volume); } catch (Exception e) { e.printStackTrace(); @@ -620,8 +580,7 @@ public class EBSBootEC2ClientLiveTest { } if (instance != null) { try { - client.getInstanceServices().terminateInstancesInRegion(instance.getRegion(), - instance.getId()); + client.getInstanceServices().terminateInstancesInRegion(instance.getRegion(), instance.getId()); terminatedTester.apply(instance); } catch (Exception e) { e.printStackTrace(); @@ -629,16 +588,14 @@ public class EBSBootEC2ClientLiveTest { } if (volume != null) { try { - client.getElasticBlockStoreServices().deleteVolumeInRegion(volume.getRegion(), - volume.getId()); + client.getElasticBlockStoreServices().deleteVolumeInRegion(volume.getRegion(), volume.getId()); } catch (Exception e) { e.printStackTrace(); } } if (keyPair != null) { try { - client.getKeyPairServices().deleteKeyPairInRegion(keyPair.getRegion(), - keyPair.getKeyName()); + client.getKeyPairServices().deleteKeyPairInRegion(keyPair.getRegion(), keyPair.getKeyName()); } catch (Exception e) { e.printStackTrace(); } diff --git a/aws/core/src/test/java/org/jclouds/aws/ec2/compute/options/EC2TemplateOptionsTest.java b/aws/core/src/test/java/org/jclouds/aws/ec2/compute/options/EC2TemplateOptionsTest.java index 9f515e8f49..0dd3a927cb 100644 --- a/aws/core/src/test/java/org/jclouds/aws/ec2/compute/options/EC2TemplateOptionsTest.java +++ b/aws/core/src/test/java/org/jclouds/aws/ec2/compute/options/EC2TemplateOptionsTest.java @@ -28,7 +28,10 @@ import static org.jclouds.aws.ec2.compute.options.EC2TemplateOptions.Builder.noK import static org.jclouds.aws.ec2.compute.options.EC2TemplateOptions.Builder.securityGroups; import static org.testng.Assert.assertEquals; +import java.io.IOException; + import org.jclouds.compute.options.TemplateOptions; +import org.jclouds.util.Utils; import org.testng.annotations.Test; import com.google.common.collect.ImmutableSet; @@ -170,17 +173,19 @@ public class EC2TemplateOptionsTest { } // superclass tests + @SuppressWarnings("deprecation") @Test(expectedExceptions = IllegalArgumentException.class) public void testinstallPrivateKeyBadFormat() { EC2TemplateOptions options = new EC2TemplateOptions(); options.installPrivateKey("whompy"); } + @SuppressWarnings("deprecation") @Test - public void testinstallPrivateKey() { + public void testinstallPrivateKey() throws IOException { EC2TemplateOptions options = new EC2TemplateOptions(); options.installPrivateKey("-----BEGIN RSA PRIVATE KEY-----"); - assertEquals(options.getPrivateKey(), "-----BEGIN RSA PRIVATE KEY-----"); + assertEquals(Utils.toStringAndClose(options.getPrivateKey().getInput()), "-----BEGIN RSA PRIVATE KEY-----"); } @Test @@ -190,9 +195,9 @@ public class EC2TemplateOptionsTest { } @Test - public void testinstallPrivateKeyStatic() { + public void testinstallPrivateKeyStatic() throws IOException { EC2TemplateOptions options = installPrivateKey("-----BEGIN RSA PRIVATE KEY-----"); - assertEquals(options.getPrivateKey(), "-----BEGIN RSA PRIVATE KEY-----"); + assertEquals(Utils.toStringAndClose(options.getPrivateKey().getInput()), "-----BEGIN RSA PRIVATE KEY-----"); } @Test(expectedExceptions = NullPointerException.class) @@ -200,17 +205,19 @@ public class EC2TemplateOptionsTest { installPrivateKey(null); } + @SuppressWarnings("deprecation") @Test(expectedExceptions = IllegalArgumentException.class) public void testauthorizePublicKeyBadFormat() { EC2TemplateOptions options = new EC2TemplateOptions(); options.authorizePublicKey("whompy"); } + @SuppressWarnings("deprecation") @Test - public void testauthorizePublicKey() { + public void testauthorizePublicKey() throws IOException { EC2TemplateOptions options = new EC2TemplateOptions(); options.authorizePublicKey("ssh-rsa"); - assertEquals(options.getPublicKey(), "ssh-rsa"); + assertEquals(Utils.toStringAndClose(options.getPublicKey().getInput()), "ssh-rsa"); } @Test @@ -220,9 +227,9 @@ public class EC2TemplateOptionsTest { } @Test - public void testauthorizePublicKeyStatic() { + public void testauthorizePublicKeyStatic() throws IOException { EC2TemplateOptions options = authorizePublicKey("ssh-rsa"); - assertEquals(options.getPublicKey(), "ssh-rsa"); + assertEquals(Utils.toStringAndClose(options.getPublicKey().getInput()), "ssh-rsa"); } @Test(expectedExceptions = NullPointerException.class) diff --git a/aws/core/src/test/java/org/jclouds/aws/ec2/services/PlacementGroupClientLiveTest.java b/aws/core/src/test/java/org/jclouds/aws/ec2/services/PlacementGroupClientLiveTest.java index 2f0c5bacba..c740902fa7 100644 --- a/aws/core/src/test/java/org/jclouds/aws/ec2/services/PlacementGroupClientLiveTest.java +++ b/aws/core/src/test/java/org/jclouds/aws/ec2/services/PlacementGroupClientLiveTest.java @@ -19,6 +19,7 @@ package org.jclouds.aws.ec2.services; import static com.google.common.base.Preconditions.checkNotNull; +import static org.jclouds.io.Payloads.newStringPayload; import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertNotNull; @@ -82,11 +83,11 @@ public class PlacementGroupClientLiveTest { String credential = checkNotNull(System.getProperty("jclouds.test.credential"), "jclouds.test.credential"); keyPair = BaseComputeServiceLiveTest.setupKeyPair(); context = new ComputeServiceContextFactory().createContext("ec2", identity, credential, ImmutableSet. of( - new Log4JLoggingModule(), new JschSshClientModule())); + new Log4JLoggingModule(), new JschSshClientModule())); client = EC2Client.class.cast(context.getProviderSpecificContext().getApi()); availableTester = new RetryablePredicate(new PlacementGroupAvailable(client), 60, 1, - TimeUnit.SECONDS); + TimeUnit.SECONDS); deletedTester = new RetryablePredicate(new PlacementGroupDeleted(client), 60, 1, TimeUnit.SECONDS); } @@ -95,12 +96,12 @@ public class PlacementGroupClientLiveTest { void testDescribe() { for (String region : Lists.newArrayList(Region.US_EAST_1)) { SortedSet allResults = Sets.newTreeSet(client.getPlacementGroupServices() - .describePlacementGroupsInRegion(region)); + .describePlacementGroupsInRegion(region)); assertNotNull(allResults); if (allResults.size() >= 1) { PlacementGroup group = allResults.last(); SortedSet result = Sets.newTreeSet(client.getPlacementGroupServices() - .describePlacementGroupsInRegion(region, group.getName())); + .describePlacementGroupsInRegion(region, group.getName())); assertNotNull(result); PlacementGroup compare = result.last(); assertEquals(compare, group); @@ -129,7 +130,7 @@ public class PlacementGroupClientLiveTest { private void verifyPlacementGroup(String groupName) { assert availableTester.apply(new PlacementGroup(Region.US_EAST_1, groupName, "cluster", State.PENDING)) : group; Set oneResult = client.getPlacementGroupServices().describePlacementGroupsInRegion(null, - groupName); + groupName); assertNotNull(oneResult); assertEquals(oneResult.size(), 1); group = oneResult.iterator().next(); @@ -163,8 +164,9 @@ public class PlacementGroupClientLiveTest { assertEquals(template.getSize().getProviderId(), InstanceType.CC1_4XLARGE); assertEquals(template.getImage().getId(), "us-east-1/ami-7ea24a17"); - template.getOptions().installPrivateKey(keyPair.get("private")).authorizePublicKey(keyPair.get("public")) - .runScript(BaseComputeServiceLiveTest.buildScript(template.getImage().getOsFamily()).getBytes()); + template.getOptions().installPrivateKey(newStringPayload(keyPair.get("private"))).authorizePublicKey( + newStringPayload(keyPair.get("public"))).runScript( + newStringPayload(BaseComputeServiceLiveTest.buildScript(template.getImage().getOsFamily()))); String tag = PREFIX + "cccluster"; context.getComputeService().destroyNodesMatching(NodePredicates.withTag(tag)); @@ -174,7 +176,7 @@ public class PlacementGroupClientLiveTest { NodeMetadata node = Iterables.getOnlyElement(nodes); RunningInstance instance = Iterables.getOnlyElement(Iterables.getOnlyElement(client.getInstanceServices() - .describeInstancesInRegion(null, node.getProviderId()))); + .describeInstancesInRegion(null, node.getProviderId()))); assertEquals(instance.getVirtualizationType(), node.getExtra().get("virtualizationType")); assertEquals(instance.getPlacementGroup(), node.getExtra().get("placementGroup")); diff --git a/aws/core/src/test/java/org/jclouds/aws/handlers/ParseAWSErrorFromXmlContentTest.java b/aws/core/src/test/java/org/jclouds/aws/handlers/ParseAWSErrorFromXmlContentTest.java index e489c7e110..ac01201b62 100644 --- a/aws/core/src/test/java/org/jclouds/aws/handlers/ParseAWSErrorFromXmlContentTest.java +++ b/aws/core/src/test/java/org/jclouds/aws/handlers/ParseAWSErrorFromXmlContentTest.java @@ -13,8 +13,8 @@ import org.easymock.IArgumentMatcher; import org.jclouds.http.HttpCommand; import org.jclouds.http.HttpRequest; import org.jclouds.http.HttpResponse; -import org.jclouds.http.Payloads; import org.jclouds.http.functions.config.ParserModule; +import org.jclouds.io.Payloads; import org.jclouds.rest.AuthorizationException; import org.jclouds.rest.RequestSigner; import org.jclouds.rest.ResourceNotFoundException; diff --git a/aws/core/src/test/java/org/jclouds/aws/s3/binders/BindS3ObjectToPayloadTest.java b/aws/core/src/test/java/org/jclouds/aws/s3/binders/BindS3ObjectToPayloadTest.java index 80d613348c..48e9748248 100644 --- a/aws/core/src/test/java/org/jclouds/aws/s3/binders/BindS3ObjectToPayloadTest.java +++ b/aws/core/src/test/java/org/jclouds/aws/s3/binders/BindS3ObjectToPayloadTest.java @@ -29,7 +29,7 @@ import org.jclouds.aws.s3.domain.S3Object; import org.jclouds.blobstore.binders.BindUserMetadataToHeadersWithPrefix; import org.jclouds.blobstore.domain.Blob; import org.jclouds.http.HttpRequest; -import org.jclouds.http.Payload; +import org.jclouds.io.Payload; import org.testng.annotations.Test; import com.google.common.collect.Multimap; diff --git a/aws/core/src/test/java/org/jclouds/aws/s3/functions/ParseObjectMetadataFromHeadersTest.java b/aws/core/src/test/java/org/jclouds/aws/s3/functions/ParseObjectMetadataFromHeadersTest.java index 0a627a9f59..fb79594b07 100644 --- a/aws/core/src/test/java/org/jclouds/aws/s3/functions/ParseObjectMetadataFromHeadersTest.java +++ b/aws/core/src/test/java/org/jclouds/aws/s3/functions/ParseObjectMetadataFromHeadersTest.java @@ -38,7 +38,7 @@ import org.jclouds.blobstore.functions.ParseSystemAndUserMetadataFromHeaders; import org.jclouds.encryption.EncryptionService; import org.jclouds.encryption.internal.JCEEncryptionService; import org.jclouds.http.HttpResponse; -import org.jclouds.http.Payloads; +import org.jclouds.io.Payloads; import org.testng.annotations.BeforeTest; import org.testng.annotations.Test; diff --git a/aws/core/src/test/java/org/jclouds/aws/sqs/xml/ListQueuesResponseHandlerTest.java b/aws/core/src/test/java/org/jclouds/aws/sqs/xml/ListQueuesResponseHandlerTest.java index 1b757fd649..b986fb15e1 100644 --- a/aws/core/src/test/java/org/jclouds/aws/sqs/xml/ListQueuesResponseHandlerTest.java +++ b/aws/core/src/test/java/org/jclouds/aws/sqs/xml/ListQueuesResponseHandlerTest.java @@ -37,10 +37,10 @@ import org.jclouds.PerformanceTest; import org.jclouds.aws.domain.Region; import org.jclouds.aws.sqs.domain.Queue; import org.jclouds.http.HttpResponse; -import org.jclouds.http.Payloads; import org.jclouds.http.functions.ParseSax; import org.jclouds.http.functions.ParseSax.Factory; import org.jclouds.http.functions.config.ParserModule; +import org.jclouds.io.Payloads; import org.testng.annotations.BeforeTest; import org.testng.annotations.Test; diff --git a/aws/core/src/test/java/org/jclouds/aws/util/AWSUtilsTest.java b/aws/core/src/test/java/org/jclouds/aws/util/AWSUtilsTest.java index a9a48e81ca..737b371d5f 100644 --- a/aws/core/src/test/java/org/jclouds/aws/util/AWSUtilsTest.java +++ b/aws/core/src/test/java/org/jclouds/aws/util/AWSUtilsTest.java @@ -31,7 +31,7 @@ import org.jclouds.aws.domain.AWSError; import org.jclouds.http.HttpCommand; import org.jclouds.http.HttpRequest; import org.jclouds.http.HttpResponse; -import org.jclouds.http.Payloads; +import org.jclouds.io.Payloads; import org.jclouds.logging.config.NullLoggingModule; import org.jclouds.rest.RestContextFactory; import org.jclouds.rest.BaseRestClientTest.MockModule; diff --git a/azure/src/main/java/org/jclouds/azure/storage/blob/domain/internal/AzureBlobImpl.java b/azure/src/main/java/org/jclouds/azure/storage/blob/domain/internal/AzureBlobImpl.java index 08caf2f4b2..63d2ace878 100644 --- a/azure/src/main/java/org/jclouds/azure/storage/blob/domain/internal/AzureBlobImpl.java +++ b/azure/src/main/java/org/jclouds/azure/storage/blob/domain/internal/AzureBlobImpl.java @@ -24,10 +24,10 @@ import javax.inject.Inject; import org.jclouds.azure.storage.blob.domain.AzureBlob; import org.jclouds.azure.storage.blob.domain.MutableBlobProperties; -import org.jclouds.http.Payload; import org.jclouds.http.PayloadEnclosing; import org.jclouds.http.internal.PayloadEnclosingImpl; -import org.jclouds.http.payloads.DelegatingPayload; +import org.jclouds.io.Payload; +import org.jclouds.io.payloads.DelegatingPayload; import com.google.common.collect.LinkedHashMultimap; import com.google.common.collect.Multimap; diff --git a/azure/src/test/java/org/jclouds/azure/storage/blob/binders/BindAzureBlobToPayloadTest.java b/azure/src/test/java/org/jclouds/azure/storage/blob/binders/BindAzureBlobToPayloadTest.java index 37d5e2a0bf..cd38c4c68e 100644 --- a/azure/src/test/java/org/jclouds/azure/storage/blob/binders/BindAzureBlobToPayloadTest.java +++ b/azure/src/test/java/org/jclouds/azure/storage/blob/binders/BindAzureBlobToPayloadTest.java @@ -12,7 +12,7 @@ import org.jclouds.azure.storage.blob.domain.MutableBlobProperties; import org.jclouds.blobstore.binders.BindUserMetadataToHeadersWithPrefix; import org.jclouds.blobstore.domain.Blob; import org.jclouds.http.HttpRequest; -import org.jclouds.http.Payload; +import org.jclouds.io.Payload; import org.testng.annotations.Test; import com.google.common.collect.Multimap; diff --git a/blobstore/src/main/java/org/jclouds/blobstore/TransientAsyncBlobStore.java b/blobstore/src/main/java/org/jclouds/blobstore/TransientAsyncBlobStore.java index 368d804dc0..3d11e0d3dc 100755 --- a/blobstore/src/main/java/org/jclouds/blobstore/TransientAsyncBlobStore.java +++ b/blobstore/src/main/java/org/jclouds/blobstore/TransientAsyncBlobStore.java @@ -85,8 +85,8 @@ import org.jclouds.http.HttpRequest; import org.jclouds.http.HttpResponse; import org.jclouds.http.HttpResponseException; import org.jclouds.http.options.HttpRequestOptions; -import org.jclouds.http.payloads.ByteArrayPayload; -import org.jclouds.http.payloads.DelegatingPayload; +import org.jclouds.io.payloads.ByteArrayPayload; +import org.jclouds.io.payloads.DelegatingPayload; import com.google.common.base.Function; import com.google.common.base.Predicate; diff --git a/blobstore/src/main/java/org/jclouds/blobstore/binders/BindBlobToMultipartForm.java b/blobstore/src/main/java/org/jclouds/blobstore/binders/BindBlobToMultipartForm.java index c685217ab1..abc833f7af 100644 --- a/blobstore/src/main/java/org/jclouds/blobstore/binders/BindBlobToMultipartForm.java +++ b/blobstore/src/main/java/org/jclouds/blobstore/binders/BindBlobToMultipartForm.java @@ -22,9 +22,9 @@ import javax.inject.Singleton; import org.jclouds.blobstore.domain.Blob; import org.jclouds.http.HttpRequest; -import org.jclouds.http.payloads.MultipartForm; -import org.jclouds.http.payloads.Part; -import org.jclouds.http.payloads.Part.PartOptions; +import org.jclouds.io.payloads.MultipartForm; +import org.jclouds.io.payloads.Part; +import org.jclouds.io.payloads.Part.PartOptions; import org.jclouds.rest.Binder; /** diff --git a/blobstore/src/main/java/org/jclouds/blobstore/domain/internal/BlobImpl.java b/blobstore/src/main/java/org/jclouds/blobstore/domain/internal/BlobImpl.java index 925cf1fbd1..e11f53d522 100644 --- a/blobstore/src/main/java/org/jclouds/blobstore/domain/internal/BlobImpl.java +++ b/blobstore/src/main/java/org/jclouds/blobstore/domain/internal/BlobImpl.java @@ -25,10 +25,10 @@ import javax.inject.Inject; import org.jclouds.blobstore.domain.Blob; import org.jclouds.blobstore.domain.MutableBlobMetadata; import org.jclouds.blobstore.domain.StorageMetadata; -import org.jclouds.http.Payload; import org.jclouds.http.PayloadEnclosing; import org.jclouds.http.internal.PayloadEnclosingImpl; -import org.jclouds.http.payloads.DelegatingPayload; +import org.jclouds.io.Payload; +import org.jclouds.io.payloads.DelegatingPayload; import com.google.common.collect.LinkedHashMultimap; import com.google.common.collect.Multimap; diff --git a/blobstore/src/main/java/org/jclouds/blobstore/functions/ObjectMD5.java b/blobstore/src/main/java/org/jclouds/blobstore/functions/ObjectMD5.java index dbded887ac..c17e2869ec 100644 --- a/blobstore/src/main/java/org/jclouds/blobstore/functions/ObjectMD5.java +++ b/blobstore/src/main/java/org/jclouds/blobstore/functions/ObjectMD5.java @@ -22,7 +22,7 @@ import javax.inject.Inject; import org.jclouds.blobstore.domain.Blob; import org.jclouds.encryption.EncryptionService; -import org.jclouds.http.Payloads; +import org.jclouds.io.Payloads; import com.google.common.base.Function; diff --git a/blobstore/src/main/java/org/jclouds/blobstore/internal/InputStreamMapImpl.java b/blobstore/src/main/java/org/jclouds/blobstore/internal/InputStreamMapImpl.java index bdd332a8f6..d6e117606b 100755 --- a/blobstore/src/main/java/org/jclouds/blobstore/internal/InputStreamMapImpl.java +++ b/blobstore/src/main/java/org/jclouds/blobstore/internal/InputStreamMapImpl.java @@ -20,7 +20,7 @@ package org.jclouds.blobstore.internal; import static com.google.common.collect.Iterables.transform; import static com.google.common.collect.Lists.newArrayList; -import static org.jclouds.http.Payloads.newPayload; +import static org.jclouds.io.Payloads.newPayload; import java.io.File; import java.io.InputStream; @@ -39,11 +39,11 @@ import org.jclouds.blobstore.strategy.GetBlobsInListStrategy; import org.jclouds.blobstore.strategy.PutBlobsStrategy; import org.jclouds.blobstore.strategy.internal.ListContainerAndRecurseThroughFolders; import org.jclouds.encryption.EncryptionService; -import org.jclouds.http.Payload; -import org.jclouds.http.payloads.ByteArrayPayload; -import org.jclouds.http.payloads.FilePayload; -import org.jclouds.http.payloads.InputStreamPayload; -import org.jclouds.http.payloads.StringPayload; +import org.jclouds.io.Payload; +import org.jclouds.io.payloads.ByteArrayPayload; +import org.jclouds.io.payloads.FilePayload; +import org.jclouds.io.payloads.InputStreamPayload; +import org.jclouds.io.payloads.StringPayload; import com.google.common.annotations.VisibleForTesting; import com.google.common.base.Function; diff --git a/blobstore/src/main/java/org/jclouds/blobstore/strategy/internal/MarkerFileMkdirStrategy.java b/blobstore/src/main/java/org/jclouds/blobstore/strategy/internal/MarkerFileMkdirStrategy.java index d33a284294..d2e3224786 100644 --- a/blobstore/src/main/java/org/jclouds/blobstore/strategy/internal/MarkerFileMkdirStrategy.java +++ b/blobstore/src/main/java/org/jclouds/blobstore/strategy/internal/MarkerFileMkdirStrategy.java @@ -26,7 +26,7 @@ import org.jclouds.blobstore.domain.Blob; import org.jclouds.blobstore.domain.StorageType; import org.jclouds.blobstore.reference.BlobStoreConstants; import org.jclouds.blobstore.strategy.MkdirStrategy; -import org.jclouds.http.Payloads; +import org.jclouds.io.Payloads; import com.google.inject.Inject; diff --git a/blobstore/src/test/java/org/jclouds/blobstore/binders/BindBlobToMultipartFormTest.java b/blobstore/src/test/java/org/jclouds/blobstore/binders/BindBlobToMultipartFormTest.java index a3d15af3ea..90be5fdf9d 100644 --- a/blobstore/src/test/java/org/jclouds/blobstore/binders/BindBlobToMultipartFormTest.java +++ b/blobstore/src/test/java/org/jclouds/blobstore/binders/BindBlobToMultipartFormTest.java @@ -18,7 +18,7 @@ */ package org.jclouds.blobstore.binders; -import static org.jclouds.http.payloads.MultipartForm.BOUNDARY; +import static org.jclouds.io.payloads.MultipartForm.BOUNDARY; import static org.jclouds.util.Utils.toStringAndClose; import static org.testng.Assert.assertEquals; diff --git a/blobstore/src/test/java/org/jclouds/blobstore/functions/ParseBlobFromHeadersAndHttpContentTest.java b/blobstore/src/test/java/org/jclouds/blobstore/functions/ParseBlobFromHeadersAndHttpContentTest.java index 5cc859d113..4c030d2620 100755 --- a/blobstore/src/test/java/org/jclouds/blobstore/functions/ParseBlobFromHeadersAndHttpContentTest.java +++ b/blobstore/src/test/java/org/jclouds/blobstore/functions/ParseBlobFromHeadersAndHttpContentTest.java @@ -34,7 +34,7 @@ import org.jclouds.blobstore.domain.MutableBlobMetadata; import org.jclouds.blobstore.domain.internal.MutableBlobMetadataImpl; import org.jclouds.http.HttpException; import org.jclouds.http.HttpResponse; -import org.jclouds.http.Payloads; +import org.jclouds.io.Payloads; import org.testng.annotations.BeforeTest; import org.testng.annotations.Test; diff --git a/blobstore/src/test/java/org/jclouds/blobstore/functions/ParseSystemAndUserMetadataFromHeadersTest.java b/blobstore/src/test/java/org/jclouds/blobstore/functions/ParseSystemAndUserMetadataFromHeadersTest.java index c151c6e830..ee434606b0 100644 --- a/blobstore/src/test/java/org/jclouds/blobstore/functions/ParseSystemAndUserMetadataFromHeadersTest.java +++ b/blobstore/src/test/java/org/jclouds/blobstore/functions/ParseSystemAndUserMetadataFromHeadersTest.java @@ -35,7 +35,7 @@ import org.jclouds.blobstore.domain.internal.MutableBlobMetadataImpl; import org.jclouds.date.internal.SimpleDateFormatDateService; import org.jclouds.http.HttpException; import org.jclouds.http.HttpResponse; -import org.jclouds.http.Payloads; +import org.jclouds.io.Payloads; import org.jclouds.rest.internal.GeneratedHttpRequest; import org.testng.annotations.BeforeTest; import org.testng.annotations.Test; diff --git a/blobstore/src/test/java/org/jclouds/blobstore/integration/internal/BaseBlobIntegrationTest.java b/blobstore/src/test/java/org/jclouds/blobstore/integration/internal/BaseBlobIntegrationTest.java index 001259cb0c..200befd038 100755 --- a/blobstore/src/test/java/org/jclouds/blobstore/integration/internal/BaseBlobIntegrationTest.java +++ b/blobstore/src/test/java/org/jclouds/blobstore/integration/internal/BaseBlobIntegrationTest.java @@ -50,8 +50,8 @@ import org.jclouds.blobstore.domain.StorageType; import org.jclouds.encryption.internal.JCEEncryptionService; import org.jclouds.http.BaseJettyTest; import org.jclouds.http.HttpResponseException; -import org.jclouds.http.Payload; -import org.jclouds.http.Payloads; +import org.jclouds.io.Payload; +import org.jclouds.io.Payloads; import org.jclouds.logging.Logger; import org.jclouds.util.Utils; import org.testng.ITestContext; diff --git a/chef/src/main/java/org/jclouds/chef/domain/Resource.java b/chef/src/main/java/org/jclouds/chef/domain/Resource.java index 11ea989030..24bf4a410f 100644 --- a/chef/src/main/java/org/jclouds/chef/domain/Resource.java +++ b/chef/src/main/java/org/jclouds/chef/domain/Resource.java @@ -21,7 +21,7 @@ package org.jclouds.chef.domain; import java.net.URI; import java.util.Arrays; -import org.jclouds.http.payloads.FilePayload; +import org.jclouds.io.payloads.FilePayload; import com.google.common.primitives.Bytes; diff --git a/chef/src/main/java/org/jclouds/chef/filters/SignedHeaderAuth.java b/chef/src/main/java/org/jclouds/chef/filters/SignedHeaderAuth.java index 586ab6e213..26c075fdfa 100644 --- a/chef/src/main/java/org/jclouds/chef/filters/SignedHeaderAuth.java +++ b/chef/src/main/java/org/jclouds/chef/filters/SignedHeaderAuth.java @@ -43,11 +43,11 @@ import org.jclouds.http.HttpException; import org.jclouds.http.HttpRequest; import org.jclouds.http.HttpRequestFilter; import org.jclouds.http.HttpUtils; -import org.jclouds.http.Payload; -import org.jclouds.http.Payloads; import org.jclouds.http.internal.SignatureWire; -import org.jclouds.http.payloads.MultipartForm; -import org.jclouds.http.payloads.Part; +import org.jclouds.io.Payload; +import org.jclouds.io.Payloads; +import org.jclouds.io.payloads.MultipartForm; +import org.jclouds.io.payloads.Part; import org.jclouds.logging.Logger; import org.jclouds.util.Utils; diff --git a/chef/src/test/java/org/jclouds/chef/ChefClientLiveTest.java b/chef/src/test/java/org/jclouds/chef/ChefClientLiveTest.java index a710e700f7..e480080e11 100644 --- a/chef/src/test/java/org/jclouds/chef/ChefClientLiveTest.java +++ b/chef/src/test/java/org/jclouds/chef/ChefClientLiveTest.java @@ -38,8 +38,8 @@ import org.jclouds.chef.domain.ChecksumStatus; import org.jclouds.chef.domain.CookbookVersion; import org.jclouds.chef.domain.Resource; import org.jclouds.chef.domain.UploadSandbox; -import org.jclouds.http.Payloads; -import org.jclouds.http.payloads.FilePayload; +import org.jclouds.io.Payloads; +import org.jclouds.io.payloads.FilePayload; import org.jclouds.logging.log4j.config.Log4JLoggingModule; import org.jclouds.rest.RestContext; import org.jclouds.rest.RestContextFactory; diff --git a/chef/src/test/java/org/jclouds/chef/functions/ParseCookbookVersionFromJsonTest.java b/chef/src/test/java/org/jclouds/chef/functions/ParseCookbookVersionFromJsonTest.java index 786bc4c721..8bfa13c239 100644 --- a/chef/src/test/java/org/jclouds/chef/functions/ParseCookbookVersionFromJsonTest.java +++ b/chef/src/test/java/org/jclouds/chef/functions/ParseCookbookVersionFromJsonTest.java @@ -12,9 +12,9 @@ import org.jclouds.chef.domain.Metadata; import org.jclouds.chef.domain.Resource; import org.jclouds.encryption.EncryptionService; import org.jclouds.http.HttpResponse; -import org.jclouds.http.Payloads; import org.jclouds.http.functions.ParseJson; import org.jclouds.http.functions.config.ParserModule; +import org.jclouds.io.Payloads; import org.jclouds.util.Utils; import org.testng.annotations.BeforeTest; import org.testng.annotations.Test; diff --git a/chef/src/test/java/org/jclouds/chef/functions/ParseErrorFromJsonOrReturnBodyTest.java b/chef/src/test/java/org/jclouds/chef/functions/ParseErrorFromJsonOrReturnBodyTest.java index 441795889a..de5f09bdec 100644 --- a/chef/src/test/java/org/jclouds/chef/functions/ParseErrorFromJsonOrReturnBodyTest.java +++ b/chef/src/test/java/org/jclouds/chef/functions/ParseErrorFromJsonOrReturnBodyTest.java @@ -29,8 +29,8 @@ import java.io.InputStream; import java.net.UnknownHostException; import org.jclouds.http.HttpResponse; -import org.jclouds.http.Payloads; import org.jclouds.http.functions.ReturnStringIf2xx; +import org.jclouds.io.Payloads; import org.jclouds.util.Utils; import org.testng.annotations.Test; diff --git a/chef/src/test/java/org/jclouds/chef/functions/ParseKeyFromJsonTest.java b/chef/src/test/java/org/jclouds/chef/functions/ParseKeyFromJsonTest.java index 048ae9257d..0dfeeb2a1a 100644 --- a/chef/src/test/java/org/jclouds/chef/functions/ParseKeyFromJsonTest.java +++ b/chef/src/test/java/org/jclouds/chef/functions/ParseKeyFromJsonTest.java @@ -5,8 +5,8 @@ import static org.testng.Assert.assertEquals; import java.io.IOException; import org.jclouds.http.HttpResponse; -import org.jclouds.http.Payloads; import org.jclouds.http.functions.config.ParserModule; +import org.jclouds.io.Payloads; import org.jclouds.util.Utils; import org.testng.annotations.BeforeTest; import org.testng.annotations.Test; diff --git a/chef/src/test/java/org/jclouds/chef/functions/ParseKeySetFromJsonTest.java b/chef/src/test/java/org/jclouds/chef/functions/ParseKeySetFromJsonTest.java index 8b8e24f9a5..2b940a3d90 100644 --- a/chef/src/test/java/org/jclouds/chef/functions/ParseKeySetFromJsonTest.java +++ b/chef/src/test/java/org/jclouds/chef/functions/ParseKeySetFromJsonTest.java @@ -5,8 +5,8 @@ import static org.testng.Assert.assertEquals; import java.io.IOException; import org.jclouds.http.HttpResponse; -import org.jclouds.http.Payloads; import org.jclouds.http.functions.config.ParserModule; +import org.jclouds.io.Payloads; import org.jclouds.util.Utils; import org.testng.annotations.BeforeTest; import org.testng.annotations.Test; diff --git a/chef/src/test/java/org/jclouds/chef/functions/ParseOrganizationFromJsonTest.java b/chef/src/test/java/org/jclouds/chef/functions/ParseOrganizationFromJsonTest.java index c4ee4a348e..a07a604b3b 100644 --- a/chef/src/test/java/org/jclouds/chef/functions/ParseOrganizationFromJsonTest.java +++ b/chef/src/test/java/org/jclouds/chef/functions/ParseOrganizationFromJsonTest.java @@ -24,9 +24,9 @@ import java.io.IOException; import org.jclouds.chef.domain.Organization; import org.jclouds.http.HttpResponse; -import org.jclouds.http.Payloads; import org.jclouds.http.functions.ParseJson; import org.jclouds.http.functions.config.ParserModule; +import org.jclouds.io.Payloads; import org.jclouds.util.Utils; import org.testng.annotations.BeforeTest; import org.testng.annotations.Test; diff --git a/chef/src/test/java/org/jclouds/chef/functions/ParseSandboxFromJsonTest.java b/chef/src/test/java/org/jclouds/chef/functions/ParseSandboxFromJsonTest.java index 404833d867..964eaf7ed4 100644 --- a/chef/src/test/java/org/jclouds/chef/functions/ParseSandboxFromJsonTest.java +++ b/chef/src/test/java/org/jclouds/chef/functions/ParseSandboxFromJsonTest.java @@ -7,11 +7,11 @@ import java.io.IOException; import org.jclouds.chef.domain.Sandbox; import org.jclouds.date.DateService; import org.jclouds.http.HttpResponse; -import org.jclouds.http.Payloads; import org.jclouds.http.functions.ParseJson; import org.jclouds.http.functions.config.ParserModule; import org.jclouds.http.functions.config.ParserModule.DateAdapter; import org.jclouds.http.functions.config.ParserModule.Iso8601DateAdapter; +import org.jclouds.io.Payloads; import org.testng.annotations.BeforeTest; import org.testng.annotations.Test; diff --git a/chef/src/test/java/org/jclouds/chef/functions/ParseUploadSandboxFromJsonTest.java b/chef/src/test/java/org/jclouds/chef/functions/ParseUploadSandboxFromJsonTest.java index 601e576d17..046b9ebae0 100644 --- a/chef/src/test/java/org/jclouds/chef/functions/ParseUploadSandboxFromJsonTest.java +++ b/chef/src/test/java/org/jclouds/chef/functions/ParseUploadSandboxFromJsonTest.java @@ -10,9 +10,9 @@ import org.jclouds.chef.domain.ChecksumStatus; import org.jclouds.chef.domain.UploadSandbox; import org.jclouds.encryption.EncryptionService; import org.jclouds.http.HttpResponse; -import org.jclouds.http.Payloads; import org.jclouds.http.functions.ParseJson; import org.jclouds.http.functions.config.ParserModule; +import org.jclouds.io.Payloads; import org.testng.annotations.BeforeTest; import org.testng.annotations.Test; diff --git a/chef/src/test/java/org/jclouds/chef/functions/ParseUserFromJsonTest.java b/chef/src/test/java/org/jclouds/chef/functions/ParseUserFromJsonTest.java index ca4b14cc50..6d48bb1257 100644 --- a/chef/src/test/java/org/jclouds/chef/functions/ParseUserFromJsonTest.java +++ b/chef/src/test/java/org/jclouds/chef/functions/ParseUserFromJsonTest.java @@ -6,9 +6,9 @@ import java.io.IOException; import org.jclouds.chef.domain.User; import org.jclouds.http.HttpResponse; -import org.jclouds.http.Payloads; import org.jclouds.http.functions.ParseJson; import org.jclouds.http.functions.config.ParserModule; +import org.jclouds.io.Payloads; import org.jclouds.util.Utils; import org.testng.annotations.BeforeTest; import org.testng.annotations.Test; diff --git a/compute/src/main/java/org/jclouds/compute/ComputeService.java b/compute/src/main/java/org/jclouds/compute/ComputeService.java index d0724a6134..e9563f4ac2 100755 --- a/compute/src/main/java/org/jclouds/compute/ComputeService.java +++ b/compute/src/main/java/org/jclouds/compute/ComputeService.java @@ -31,6 +31,7 @@ import org.jclouds.compute.internal.BaseComputeService; import org.jclouds.compute.options.RunScriptOptions; import org.jclouds.compute.options.TemplateOptions; import org.jclouds.domain.Location; +import org.jclouds.io.Payload; import org.jclouds.ssh.ExecResponse; import com.google.common.base.Predicate; @@ -61,48 +62,52 @@ public interface ComputeService { TemplateOptions templateOptions(); /** - * The list sizes command shows you the options including virtual cpu count, memory, and disks. - * cpu count is not a portable quantity across clouds, as they are measured differently. However, - * it is a good indicator of relative speed within a cloud. memory is measured in megabytes and - * disks in gigabytes. + * The list sizes command shows you the options including virtual cpu count, + * memory, and disks. cpu count is not a portable quantity across clouds, as + * they are measured differently. However, it is a good indicator of relative + * speed within a cloud. memory is measured in megabytes and disks in + * gigabytes. * - * @return a map of sizes by ID, conceding that in some clouds the "id" is not used. + * @return a map of sizes by ID, conceding that in some clouds the "id" is + * not used. */ Set listSizes(); /** - * Images define the operating system and metadata related to a node. In some clouds, Images are - * bound to a specific region, and their identifiers are different across these regions. For this - * reason, you should consider matching image requirements like operating system family with - * TemplateBuilder as opposed to choosing an image explicitly. The getImages() command returns a - * map of images by id. + * Images define the operating system and metadata related to a node. In some + * clouds, Images are bound to a specific region, and their identifiers are + * different across these regions. For this reason, you should consider + * matching image requirements like operating system family with + * TemplateBuilder as opposed to choosing an image explicitly. The + * getImages() command returns a map of images by id. */ Set listImages(); /** - * all nodes available to the current user by id. If possible, the returned set will include - * {@link NodeMetadata} objects. + * all nodes available to the current user by id. If possible, the returned + * set will include {@link NodeMetadata} objects. */ Set listNodes(); /** - * The list locations command returns all the valid locations for nodes. A location has a scope, - * which is typically region or zone. A region is a general area, like eu-west, where a zone is - * similar to a datacenter. If a location has a parent, that implies it is within that location. - * For example a location can be a rack, whose parent is likely to be a zone. + * The list locations command returns all the valid locations for nodes. A + * location has a scope, which is typically region or zone. A region is a + * general area, like eu-west, where a zone is similar to a datacenter. If a + * location has a parent, that implies it is within that location. For + * example a location can be a rack, whose parent is likely to be a zone. */ Set listAssignableLocations(); /** * - * The compute api treats nodes as a group based on a tag you specify. Using this tag, you can - * choose to operate one or many nodes as a logical unit without regard to the implementation - * details of the cloud. + * The compute api treats nodes as a group based on a tag you specify. Using + * this tag, you can choose to operate one or many nodes as a logical unit + * without regard to the implementation details of the cloud. *

* - * The set that is returned will include credentials you can use to ssh into the nodes. The "key" - * part of the credentials is either a password or a private key. You have to inspect the value - * to determine this. + * The set that is returned will include credentials you can use to ssh into + * the nodes. The "key" part of the credentials is either a password or a + * private key. You have to inspect the value to determine this. * *

     * if (node.getCredentials().key.startsWith("-----BEGIN RSA PRIVATE KEY-----"))
@@ -110,11 +115,11 @@ public interface ComputeService {
     * 
* *

- * Note. if all you want to do is execute a script at bootup, you should consider use of the - * runscript option. + * Note. if all you want to do is execute a script at bootup, you should + * consider use of the runscript option. *

- * If resources such as security groups are needed, they will be reused or created for you. - * Inbound port 22 will always be opened up. + * If resources such as security groups are needed, they will be reused or + * created for you. Inbound port 22 will always be opened up. * * @param tag * - common identifier to group nodes by, cannot contain hyphens @@ -125,35 +130,38 @@ public interface ComputeService { * @return all of the nodes the api was able to launch in a running state. * * @throws RunNodesException - * when there's a problem applying options to nodes. Note that successful and failed - * nodes are a part of this exception, so be sure to inspect this carefully. + * when there's a problem applying options to nodes. Note that + * successful and failed nodes are a part of this exception, so be + * sure to inspect this carefully. */ - Set runNodesWithTag(String tag, int count, Template template) - throws RunNodesException; + Set runNodesWithTag(String tag, int count, Template template) throws RunNodesException; /** - * Like {@link ComputeService#runNodesWithTag(String,int,Template)}, except that the template is - * default, equivalent to {@code templateBuilder().any().options(templateOptions)}. + * Like {@link ComputeService#runNodesWithTag(String,int,Template)}, except + * that the template is default, equivalent to {@code + * templateBuilder().any().options(templateOptions)}. */ - Set runNodesWithTag(String tag, int count, - TemplateOptions templateOptions) throws RunNodesException; + Set runNodesWithTag(String tag, int count, TemplateOptions templateOptions) + throws RunNodesException; /** - * Like {@link ComputeService#runNodesWithTag(String,int,TemplateOptions)}, except that the - * options are default, as specified in {@link ComputeService#templateOptions}. + * Like {@link ComputeService#runNodesWithTag(String,int,TemplateOptions)}, + * except that the options are default, as specified in + * {@link ComputeService#templateOptions}. */ Set runNodesWithTag(String tag, int count) throws RunNodesException; /** - * destroy the node, given its id. If it is the only node in a tag set, the dependent resources - * will also be destroyed. + * destroy the node, given its id. If it is the only node in a tag set, the + * dependent resources will also be destroyed. */ void destroyNode(String id); /** - * nodes matching the filter are treated as a logical set. Using the delete command, you can save - * time by removing the nodes in parallel. When the last node in a set is destroyed, any indirect - * resources it uses, such as keypairs, are also destroyed. + * nodes matching the filter are treated as a logical set. Using the delete + * command, you can save time by removing the nodes in parallel. When the + * last node in a set is destroyed, any indirect resources it uses, such as + * keypairs, are also destroyed. * * @return list of nodes destroyed */ @@ -165,8 +173,8 @@ public interface ComputeService { void rebootNode(String id); /** - * nodes matching the filter are treated as a logical set. Using this command, you can save time - * by rebooting the nodes in parallel. + * nodes matching the filter are treated as a logical set. Using this + * command, you can save time by rebooting the nodes in parallel. */ void rebootNodesMatching(Predicate filter); @@ -176,8 +184,8 @@ public interface ComputeService { NodeMetadata getNodeMetadata(String id); /** - * get all nodes including details such as image and ip addresses even if it incurs extra - * requests to the service. + * get all nodes including details such as image and ip addresses even if it + * incurs extra requests to the service. * * @param filter * how to select the nodes you are interested in details on. @@ -187,31 +195,32 @@ public interface ComputeService { /** * Runs the script without any additional options * - * @see #runScriptOnNodesMatching(Predicate, byte[], + * @see #runScriptOnNodesMatching(Predicate, Payload, * org.jclouds.compute.options.RunScriptOptions) * @see org.jclouds.compute.predicates.NodePredicates#runningWithTag(String) */ - Map runScriptOnNodesMatching( - Predicate filter, byte[] runScript) throws RunScriptOnNodesException; + Map runScriptOnNodesMatching(Predicate filter, Payload runScript) + throws RunScriptOnNodesException; /** * Run the script on all nodes with the specific tag. * * @param filter - * Predicate-based filter to define on which nodes the script is to be executed + * Predicate-based filter to define on which nodes the script is to + * be executed * @param runScript - * script to run in byte format. If the script is a string, use - * {@link String#getBytes()} to retrieve the bytes + * payload containing the script to run * @param options - * nullable options to how to run the script, whether to override credentials + * nullable options to how to run the script, whether to override + * credentials * @return map with node identifiers and corresponding responses * @throws RunScriptOnNodesException * if anything goes wrong during script execution * * @see org.jclouds.compute.predicates.NodePredicates#runningWithTag(String) + * @see org.jclouds.io.Payloads */ - Map runScriptOnNodesMatching( - Predicate filter, byte[] runScript, RunScriptOptions options) - throws RunScriptOnNodesException; + Map runScriptOnNodesMatching(Predicate filter, + Payload runScript, RunScriptOptions options) throws RunScriptOnNodesException; } diff --git a/compute/src/main/java/org/jclouds/compute/RunScriptOnNodesException.java b/compute/src/main/java/org/jclouds/compute/RunScriptOnNodesException.java index 30cdc2c7d0..4980a393b9 100644 --- a/compute/src/main/java/org/jclouds/compute/RunScriptOnNodesException.java +++ b/compute/src/main/java/org/jclouds/compute/RunScriptOnNodesException.java @@ -27,6 +27,7 @@ import javax.annotation.Nullable; import org.jclouds.compute.domain.NodeMetadata; import org.jclouds.compute.options.RunScriptOptions; +import org.jclouds.io.Payload; import org.jclouds.ssh.ExecResponse; /** @@ -37,19 +38,17 @@ public class RunScriptOnNodesException extends Exception { /** The serialVersionUID */ private static final long serialVersionUID = -2272965726680821281L; - private final byte[] runScript; + private final Payload runScript; private final RunScriptOptions options; private final Map successfulNodes; private final Map failedNodes; private final Map executionExceptions; - public RunScriptOnNodesException(final byte[] runScript, - @Nullable final RunScriptOptions options, - Map successfulNodes, Map executionExceptions, - Map failedNodes) { + public RunScriptOnNodesException(final Payload runScript, @Nullable final RunScriptOptions options, + Map successfulNodes, Map executionExceptions, + Map failedNodes) { super(String.format("error runScript on filtered nodes options(%s)%n%s%n%s", options, - createExecutionErrorMessage(executionExceptions), - createNodeErrorMessage(failedNodes))); + createExecutionErrorMessage(executionExceptions), createNodeErrorMessage(failedNodes))); this.runScript = runScript; this.options = options; this.successfulNodes = successfulNodes; @@ -66,7 +65,8 @@ public class RunScriptOnNodesException extends Exception { /** * - * @return Nodes that performed startup without error, but incurred problems applying options + * @return Nodes that performed startup without error, but incurred problems + * applying options */ public Map getExecutionErrors() { return executionExceptions; @@ -74,13 +74,14 @@ public class RunScriptOnNodesException extends Exception { /** * - * @return Nodes that performed startup without error, but incurred problems applying options + * @return Nodes that performed startup without error, but incurred problems + * applying options */ public Map getNodeErrors() { return failedNodes; } - public byte[] getRunScript() { + public Payload getRunScript() { return runScript; } diff --git a/compute/src/main/java/org/jclouds/compute/callables/AuthorizeRSAPublicKey.java b/compute/src/main/java/org/jclouds/compute/callables/AuthorizeRSAPublicKey.java index 79798d8698..3976e87a26 100644 --- a/compute/src/main/java/org/jclouds/compute/callables/AuthorizeRSAPublicKey.java +++ b/compute/src/main/java/org/jclouds/compute/callables/AuthorizeRSAPublicKey.java @@ -20,10 +20,9 @@ package org.jclouds.compute.callables; import static com.google.common.base.Preconditions.checkNotNull; -import java.io.ByteArrayInputStream; - import org.jclouds.compute.domain.NodeMetadata; import org.jclouds.compute.util.ComputeServiceUtils.SshCallable; +import org.jclouds.io.Payload; import org.jclouds.logging.Logger; import org.jclouds.ssh.ExecResponse; import org.jclouds.ssh.SshClient; @@ -37,11 +36,11 @@ import com.google.common.collect.Iterables; public class AuthorizeRSAPublicKey implements SshCallable { private SshClient ssh; private final NodeMetadata node; - private final String publicKey; + private final Payload publicKey; private Logger logger = Logger.NULL; - public AuthorizeRSAPublicKey(NodeMetadata node, String publicKey) { + public AuthorizeRSAPublicKey(NodeMetadata node, Payload publicKey) { this.node = checkNotNull(node, "node"); this.publicKey = checkNotNull(publicKey, "publicKey"); } @@ -49,9 +48,9 @@ public class AuthorizeRSAPublicKey implements SshCallable { @Override public ExecResponse call() throws Exception { ssh.exec("mkdir .ssh"); - ssh.put(".ssh/id_rsa.pub", new ByteArrayInputStream(publicKey.getBytes())); - logger.debug(">> authorizing rsa public key for %s@%s", node.getCredentials().identity, - Iterables.get(node.getPublicAddresses(), 0)); + ssh.put(".ssh/id_rsa.pub", publicKey); + logger.debug(">> authorizing rsa public key for %s@%s", node.getCredentials().identity, Iterables.get(node + .getPublicAddresses(), 0)); ExecResponse returnVal = ssh.exec("cat .ssh/id_rsa.pub >> .ssh/authorized_keys"); returnVal = ssh.exec("chmod 600 .ssh/authorized_keys"); logger.debug("<< complete(%d)", returnVal.getExitCode()); diff --git a/compute/src/main/java/org/jclouds/compute/callables/InstallRSAPrivateKey.java b/compute/src/main/java/org/jclouds/compute/callables/InstallRSAPrivateKey.java index ead59b07d3..17882eaa80 100644 --- a/compute/src/main/java/org/jclouds/compute/callables/InstallRSAPrivateKey.java +++ b/compute/src/main/java/org/jclouds/compute/callables/InstallRSAPrivateKey.java @@ -20,10 +20,9 @@ package org.jclouds.compute.callables; import static com.google.common.base.Preconditions.checkNotNull; -import java.io.ByteArrayInputStream; - import org.jclouds.compute.domain.NodeMetadata; import org.jclouds.compute.util.ComputeServiceUtils.SshCallable; +import org.jclouds.io.Payload; import org.jclouds.logging.Logger; import org.jclouds.ssh.ExecResponse; import org.jclouds.ssh.SshClient; @@ -37,11 +36,11 @@ import com.google.common.collect.Iterables; public class InstallRSAPrivateKey implements SshCallable { private SshClient ssh; private final NodeMetadata node; - private final String privateKey; + private final Payload privateKey; private Logger logger = Logger.NULL; - public InstallRSAPrivateKey(NodeMetadata node, String privateKey) { + public InstallRSAPrivateKey(NodeMetadata node, Payload privateKey) { this.node = checkNotNull(node, "node"); this.privateKey = checkNotNull(privateKey, "privateKey"); } @@ -49,9 +48,9 @@ public class InstallRSAPrivateKey implements SshCallable { @Override public ExecResponse call() throws Exception { ssh.exec("mkdir .ssh"); - ssh.put(".ssh/id_rsa", new ByteArrayInputStream(privateKey.getBytes())); - logger.debug(">> installing rsa key for %s@%s", node.getCredentials().identity, Iterables.get( - node.getPublicAddresses(), 0)); + ssh.put(".ssh/id_rsa", privateKey); + logger.debug(">> installing rsa key for %s@%s", node.getCredentials().identity, Iterables.get(node + .getPublicAddresses(), 0)); return ssh.exec("chmod 600 .ssh/id_rsa"); } diff --git a/compute/src/main/java/org/jclouds/compute/callables/RunScriptOnNode.java b/compute/src/main/java/org/jclouds/compute/callables/RunScriptOnNode.java index 1d05ad6cce..38ed36e640 100644 --- a/compute/src/main/java/org/jclouds/compute/callables/RunScriptOnNode.java +++ b/compute/src/main/java/org/jclouds/compute/callables/RunScriptOnNode.java @@ -21,7 +21,8 @@ package org.jclouds.compute.callables; import static com.google.common.base.Preconditions.checkNotNull; -import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.util.Collections; import javax.inject.Named; @@ -29,15 +30,17 @@ import org.jclouds.compute.domain.NodeMetadata; import org.jclouds.compute.predicates.ScriptStatusReturnsZero.CommandUsingClient; import org.jclouds.compute.util.ComputeServiceUtils; import org.jclouds.compute.util.ComputeServiceUtils.SshCallable; +import org.jclouds.io.Payload; +import org.jclouds.io.Payloads; import org.jclouds.logging.Logger; import org.jclouds.scriptbuilder.InitBuilder; import org.jclouds.scriptbuilder.domain.OsFamily; import org.jclouds.ssh.ExecResponse; import org.jclouds.ssh.SshClient; +import org.jclouds.util.Utils; import com.google.common.base.Predicate; import com.google.common.base.Splitter; -import com.google.common.collect.ImmutableMap; import com.google.common.collect.Iterables; /** @@ -49,30 +52,43 @@ public class RunScriptOnNode implements SshCallable { protected final Predicate runScriptNotRunning; private final NodeMetadata node; private final String scriptName; - private final byte[] script; + private final Payload script; private final boolean runAsRoot; private Logger logger = Logger.NULL; public RunScriptOnNode(@Named("SCRIPT_COMPLETE") Predicate runScriptNotRunning, - NodeMetadata node, String scriptName, byte[] script) { + NodeMetadata node, String scriptName, Payload script) { this(runScriptNotRunning, node, scriptName, script, true); } public RunScriptOnNode(@Named("SCRIPT_COMPLETE") Predicate runScriptNotRunning, - NodeMetadata node, String scriptName, byte[] script, boolean runAsRoot) { + NodeMetadata node, String scriptName, Payload script, boolean runAsRoot) { this.runScriptNotRunning = runScriptNotRunning; this.node = checkNotNull(node, "node"); this.scriptName = checkNotNull(scriptName, "scriptName"); - this.script = new InitBuilder(scriptName, "/tmp/" + scriptName, "/tmp/" + scriptName, - ImmutableMap. of(), Iterables.toArray(Splitter.on("\n").split( - new String(checkNotNull(script, "script"))), String.class)).build( - OsFamily.UNIX).getBytes(); + this.script = createRunScript(scriptName, script); this.runAsRoot = runAsRoot; } + public static Payload createRunScript(String scriptName, Payload script) { + String path = "/tmp/" + scriptName; + InitBuilder initBuilder = new InitBuilder(scriptName, path, path, Collections. emptyMap(), + splitOnNewlines(script)); + return Payloads.newByteArrayPayload(initBuilder.build(OsFamily.UNIX).getBytes()); + } + + static String[] splitOnNewlines(Payload script) { + try { + String asString = Utils.toStringAndClose(checkNotNull(script, "script").getInput()); + return Iterables.toArray(Splitter.on("\n").split(asString), String.class); + } catch (IOException e) { + throw new RuntimeException(e); + } + } + @Override public ExecResponse call() throws Exception { - ssh.put(scriptName, new ByteArrayInputStream(script)); + ssh.put(scriptName, script); ExecResponse returnVal = ssh.exec("chmod 755 " + scriptName); returnVal = ssh.exec("./" + scriptName + " init"); @@ -83,12 +99,10 @@ public class RunScriptOnNode implements SshCallable { runScriptNotRunning.apply(new CommandUsingClient("./" + scriptName + " status", ssh)); logger.debug("<< complete(%d)", returnVal.getExitCode()); if (logger.isDebugEnabled() || returnVal.getExitCode() != 0) { - logger.debug("<< stdout from %s as %s@%s\n%s", scriptName, node.getCredentials().identity, - Iterables.get(node.getPublicAddresses(), 0), ssh - .exec("./" + scriptName + " tail").getOutput()); - logger.debug("<< stderr from %s as %s@%s\n%s", scriptName, node.getCredentials().identity, - Iterables.get(node.getPublicAddresses(), 0), ssh.exec( - "./" + scriptName + " tailerr").getOutput()); + logger.debug("<< stdout from %s as %s@%s\n%s", scriptName, node.getCredentials().identity, Iterables.get(node + .getPublicAddresses(), 0), ssh.exec("./" + scriptName + " tail").getOutput()); + logger.debug("<< stderr from %s as %s@%s\n%s", scriptName, node.getCredentials().identity, Iterables.get(node + .getPublicAddresses(), 0), ssh.exec("./" + scriptName + " tailerr").getOutput()); } return returnVal; } @@ -101,24 +115,24 @@ public class RunScriptOnNode implements SshCallable { private ExecResponse runScriptAsRoot() { if (node.getCredentials().identity.equals("root")) { - logger.debug(">> running %s as %s@%s", scriptName, node.getCredentials().identity, - Iterables.get(node.getPublicAddresses(), 0)); + logger.debug(">> running %s as %s@%s", scriptName, node.getCredentials().identity, Iterables.get(node + .getPublicAddresses(), 0)); return ssh.exec("./" + scriptName + " start"); } else if (ComputeServiceUtils.isKeyAuth(node)) { - logger.debug(">> running sudo %s as %s@%s", scriptName, node.getCredentials().identity, - Iterables.get(node.getPublicAddresses(), 0)); + logger.debug(">> running sudo %s as %s@%s", scriptName, node.getCredentials().identity, Iterables.get(node + .getPublicAddresses(), 0)); return ssh.exec("sudo ./" + scriptName + " start"); } else { - logger.debug(">> running sudo -S %s as %s@%s", scriptName, node.getCredentials().identity, - Iterables.get(node.getPublicAddresses(), 0)); - return ssh.exec(String.format("echo '%s'|sudo -S ./%s", node.getCredentials().credential, - scriptName + " start")); + logger.debug(">> running sudo -S %s as %s@%s", scriptName, node.getCredentials().identity, Iterables.get(node + .getPublicAddresses(), 0)); + return ssh.exec(String.format("echo '%s'|sudo -S ./%s", node.getCredentials().credential, scriptName + + " start")); } } private ExecResponse runScriptAsDefaultUser() { - logger.debug(">> running script %s as %s@%s", scriptName, node.getCredentials().identity, - Iterables.get(node.getPublicAddresses(), 0)); + logger.debug(">> running script %s as %s@%s", scriptName, node.getCredentials().identity, Iterables.get(node + .getPublicAddresses(), 0)); return ssh.exec(String.format("./%s", scriptName + " start")); } diff --git a/compute/src/main/java/org/jclouds/compute/internal/BaseComputeService.java b/compute/src/main/java/org/jclouds/compute/internal/BaseComputeService.java index e55c52f879..2952177acd 100755 --- a/compute/src/main/java/org/jclouds/compute/internal/BaseComputeService.java +++ b/compute/src/main/java/org/jclouds/compute/internal/BaseComputeService.java @@ -25,6 +25,7 @@ package org.jclouds.compute.internal; import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkNotNull; +import static org.jclouds.compute.util.ComputeServiceUtils.installNewCredentials; import static org.jclouds.concurrent.ConcurrentUtils.awaitCompletion; import static org.jclouds.concurrent.ConcurrentUtils.makeListenable; @@ -61,9 +62,9 @@ import org.jclouds.compute.strategy.GetNodeMetadataStrategy; import org.jclouds.compute.strategy.ListNodesStrategy; import org.jclouds.compute.strategy.RebootNodeStrategy; import org.jclouds.compute.strategy.RunNodesAndAddToSetStrategy; -import static org.jclouds.compute.util.ComputeServiceUtils.*; import org.jclouds.compute.util.ComputeUtils; import org.jclouds.domain.Location; +import org.jclouds.io.Payload; import org.jclouds.logging.Logger; import org.jclouds.ssh.ExecResponse; import org.jclouds.ssh.SshClient; @@ -104,32 +105,25 @@ public class BaseComputeService implements ComputeService { protected final ExecutorService executor; @Inject - protected BaseComputeService(ComputeServiceContext context, - Provider> images, Provider> sizes, - Provider> locations, ListNodesStrategy listNodesStrategy, - GetNodeMetadataStrategy getNodeMetadataStrategy, - RunNodesAndAddToSetStrategy runNodesAndAddToSetStrategy, - RebootNodeStrategy rebootNodeStrategy, DestroyNodeStrategy destroyNodeStrategy, - Provider templateBuilderProvider, - Provider templateOptionsProvider, - @Named("NODE_RUNNING") Predicate nodeRunning, - @Named("NODE_TERMINATED") Predicate nodeTerminated, ComputeUtils utils, - @Named(Constants.PROPERTY_USER_THREADS) ExecutorService executor) { + protected BaseComputeService(ComputeServiceContext context, Provider> images, + Provider> sizes, Provider> locations, + ListNodesStrategy listNodesStrategy, GetNodeMetadataStrategy getNodeMetadataStrategy, + RunNodesAndAddToSetStrategy runNodesAndAddToSetStrategy, RebootNodeStrategy rebootNodeStrategy, + DestroyNodeStrategy destroyNodeStrategy, Provider templateBuilderProvider, + Provider templateOptionsProvider, @Named("NODE_RUNNING") Predicate nodeRunning, + @Named("NODE_TERMINATED") Predicate nodeTerminated, ComputeUtils utils, + @Named(Constants.PROPERTY_USER_THREADS) ExecutorService executor) { this.context = checkNotNull(context, "context"); this.images = checkNotNull(images, "images"); this.sizes = checkNotNull(sizes, "sizes"); this.locations = checkNotNull(locations, "locations"); this.listNodesStrategy = checkNotNull(listNodesStrategy, "listNodesStrategy"); - this.getNodeMetadataStrategy = checkNotNull(getNodeMetadataStrategy, - "getNodeMetadataStrategy"); - this.runNodesAndAddToSetStrategy = checkNotNull(runNodesAndAddToSetStrategy, - "runNodesAndAddToSetStrategy"); + this.getNodeMetadataStrategy = checkNotNull(getNodeMetadataStrategy, "getNodeMetadataStrategy"); + this.runNodesAndAddToSetStrategy = checkNotNull(runNodesAndAddToSetStrategy, "runNodesAndAddToSetStrategy"); this.rebootNodeStrategy = checkNotNull(rebootNodeStrategy, "rebootNodeStrategy"); this.destroyNodeStrategy = checkNotNull(destroyNodeStrategy, "destroyNodeStrategy"); - this.templateBuilderProvider = checkNotNull(templateBuilderProvider, - "templateBuilderProvider"); - this.templateOptionsProvider = checkNotNull(templateOptionsProvider, - "templateOptionsProvider"); + this.templateBuilderProvider = checkNotNull(templateBuilderProvider, "templateBuilderProvider"); + this.templateOptionsProvider = checkNotNull(templateOptionsProvider, "templateOptionsProvider"); this.nodeRunning = checkNotNull(nodeRunning, "nodeRunning"); this.nodeTerminated = checkNotNull(nodeTerminated, "nodeTerminated"); this.utils = checkNotNull(utils, "utils"); @@ -149,19 +143,17 @@ public class BaseComputeService implements ComputeService { */ @Override public Set runNodesWithTag(String tag, int count, Template template) - throws RunNodesException { + throws RunNodesException { checkArgument(tag.indexOf('-') == -1, "tag cannot contain hyphens"); checkNotNull(template.getLocation(), "location"); - logger.debug(">> running %d node%s tag(%s) location(%s) image(%s) size(%s) options(%s)", - count, count > 1 ? "s" : "", tag, template.getLocation().getId(), template - .getImage().getProviderId(), template.getSize().getProviderId(), template - .getOptions()); + logger.debug(">> running %d node%s tag(%s) location(%s) image(%s) size(%s) options(%s)", count, count > 1 ? "s" + : "", tag, template.getLocation().getId(), template.getImage().getProviderId(), template.getSize() + .getProviderId(), template.getOptions()); Set nodes = Sets.newHashSet(); Map badNodes = Maps.newLinkedHashMap(); - Map> responses = runNodesAndAddToSetStrategy.execute(tag, count, - template, nodes, badNodes); - Map executionExceptions = awaitCompletion(responses, executor, null, logger, - "starting nodes"); + Map> responses = runNodesAndAddToSetStrategy.execute(tag, count, template, nodes, + badNodes); + Map executionExceptions = awaitCompletion(responses, executor, null, logger, "starting nodes"); if (executionExceptions.size() > 0 || badNodes.size() > 0) { throw new RunNodesException(tag, count, template, nodes, executionExceptions, badNodes); } @@ -172,8 +164,8 @@ public class BaseComputeService implements ComputeService { * {@inheritDoc} */ @Override - public Set runNodesWithTag(String tag, int count, - TemplateOptions templateOptions) throws RunNodesException { + public Set runNodesWithTag(String tag, int count, TemplateOptions templateOptions) + throws RunNodesException { return runNodesWithTag(tag, count, templateBuilder().any().options(templateOptions).build()); } @@ -181,8 +173,7 @@ public class BaseComputeService implements ComputeService { * {@inheritDoc} */ @Override - public Set runNodesWithTag(String tag, int count) - throws RunNodesException { + public Set runNodesWithTag(String tag, int count) throws RunNodesException { return runNodesWithTag(tag, count, templateOptions()); } @@ -221,10 +212,8 @@ public class BaseComputeService implements ComputeService { return destroyedNodes; } - private Iterable nodesMatchingFilterAndNotTerminated( - Predicate filter) { - return Iterables.filter(detailsOnAllNodes(), Predicates.and(filter, Predicates - .not(NodePredicates.TERMINATED))); + private Iterable nodesMatchingFilterAndNotTerminated(Predicate filter) { + return Iterables.filter(detailsOnAllNodes(), Predicates.and(filter, Predicates.not(NodePredicates.TERMINATED))); } /** @@ -245,8 +234,7 @@ public class BaseComputeService implements ComputeService { public Set listNodesDetailsMatching(Predicate filter) { checkNotNull(filter, "filter"); logger.debug(">> listing node details matching(%s)", filter); - Set set = Sets.newLinkedHashSet(listNodesStrategy - .listDetailsOnNodesMatching(filter)); + Set set = Sets.newLinkedHashSet(listNodesStrategy.listDetailsOnNodesMatching(filter)); logger.debug("<< list(%d)", set.size()); return set; } @@ -329,8 +317,8 @@ public class BaseComputeService implements ComputeService { * {@inheritDoc} */ @Override - public Map runScriptOnNodesMatching( - Predicate filter, byte[] runScript) throws RunScriptOnNodesException { + public Map runScriptOnNodesMatching(Predicate filter, + Payload runScript) throws RunScriptOnNodesException { return runScriptOnNodesMatching(filter, runScript, RunScriptOptions.NONE); } @@ -339,10 +327,9 @@ public class BaseComputeService implements ComputeService { */ @Override public Map runScriptOnNodesMatching(Predicate filter, - final byte[] runScript, @Nullable final RunScriptOptions options) - throws RunScriptOnNodesException { + final Payload runScript, @Nullable final RunScriptOptions options) throws RunScriptOnNodesException { Iterable nodes = verifyParametersAndListNodes(filter, runScript, - (options != null) ? options : RunScriptOptions.NONE); + (options != null) ? options : RunScriptOptions.NONE); final Map execs = Maps.newHashMap(); @@ -379,8 +366,7 @@ public class BaseComputeService implements ComputeService { }), executor)); } - Map exceptions = awaitCompletion(responses, executor, null, logger, - "starting nodes"); + Map exceptions = awaitCompletion(responses, executor, null, logger, "starting nodes"); if (exceptions.size() > 0 || badNodes.size() > 0) { throw new RunScriptOnNodesException(runScript, options, execs, exceptions, badNodes); } @@ -388,11 +374,10 @@ public class BaseComputeService implements ComputeService { } - private Iterable verifyParametersAndListNodes( - Predicate filter, byte[] runScript, final RunScriptOptions options) { + private Iterable verifyParametersAndListNodes(Predicate filter, + Payload runScript, final RunScriptOptions options) { checkNotNull(filter, "Filter must be provided"); - checkNotNull(runScript, - "The script (represented by bytes array - use \"script\".getBytes() must be provided"); + checkNotNull(runScript, "The script (represented by bytes array - use \"script\".getBytes() must be provided"); checkNotNull(options, "options"); Iterable nodes = Iterables.filter(detailsOnAllNodes(), filter); @@ -402,22 +387,18 @@ public class BaseComputeService implements ComputeService { @Override public NodeMetadata apply(NodeMetadata node) { - checkArgument(node.getPublicAddresses().size() > 0, "no public ip addresses on node: " - + node); + checkArgument(node.getPublicAddresses().size() > 0, "no public ip addresses on node: " + node); if (options.getOverrideCredentials() != null) { // override the credentials with provided to this // method node = installNewCredentials(node, options.getOverrideCredentials()); } else { // don't override - checkNotNull(node.getCredentials(), - "If the default credentials need to be used, they can't be null"); - checkNotNull(node.getCredentials().identity, - "Account name for ssh authentication must be " - + "specified. Try passing RunScriptOptions with new credentials"); - checkNotNull(node.getCredentials().credential, - "Key or password for ssh authentication must be " - + "specified. Try passing RunScriptOptions with new credentials"); + checkNotNull(node.getCredentials(), "If the default credentials need to be used, they can't be null"); + checkNotNull(node.getCredentials().identity, "Account name for ssh authentication must be " + + "specified. Try passing RunScriptOptions with new credentials"); + checkNotNull(node.getCredentials().credential, "Key or password for ssh authentication must be " + + "specified. Try passing RunScriptOptions with new credentials"); } return node; } diff --git a/compute/src/main/java/org/jclouds/compute/options/TemplateOptions.java b/compute/src/main/java/org/jclouds/compute/options/TemplateOptions.java index 14afafdb48..3e7f865483 100644 --- a/compute/src/main/java/org/jclouds/compute/options/TemplateOptions.java +++ b/compute/src/main/java/org/jclouds/compute/options/TemplateOptions.java @@ -20,9 +20,13 @@ package org.jclouds.compute.options; import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkNotNull; +import static org.jclouds.io.Payloads.newByteArrayPayload; +import static org.jclouds.io.Payloads.newStringPayload; import java.util.Arrays; +import org.jclouds.io.Payload; + /** * Contains options supported in the {@code ComputeService#runNodesWithTag} * operation.

@@ -42,303 +46,384 @@ import java.util.Arrays; */ public class TemplateOptions { - public static final TemplateOptions NONE = new ImmutableTemplateOptions( - new TemplateOptions()); + public static final TemplateOptions NONE = new ImmutableTemplateOptions(new TemplateOptions()); - public static class ImmutableTemplateOptions extends TemplateOptions { - private final TemplateOptions delegate; + public static class ImmutableTemplateOptions extends TemplateOptions { + private final TemplateOptions delegate; - public ImmutableTemplateOptions(TemplateOptions delegate) { - this.delegate = delegate; - } + public ImmutableTemplateOptions(TemplateOptions delegate) { + this.delegate = delegate; + } - @Override - public String toString() { - return delegate.toString(); - } + @Override + public String toString() { + return delegate.toString(); + } - @Override - public T as(Class clazz) { - return delegate.as(clazz); - } + @Override + public T as(Class clazz) { + return delegate.as(clazz); + } - @Override - public TemplateOptions authorizePublicKey(String publicKey) { - throw new IllegalArgumentException( - "authorizePublicKey is immutable"); - } + @Override + public TemplateOptions authorizePublicKey(String publicKey) { + throw new IllegalArgumentException("authorizePublicKey is immutable"); + } - @Override - public TemplateOptions blockUntilRunning(boolean blockUntilRunning) { - throw new IllegalArgumentException("blockUntilRunning is immutable"); - } + @Override + public TemplateOptions blockUntilRunning(boolean blockUntilRunning) { + throw new IllegalArgumentException("blockUntilRunning is immutable"); + } - @Override - public TemplateOptions blockOnPort(int port, int seconds) { - throw new IllegalArgumentException("port, seconds are immutable"); - } + @Override + public TemplateOptions blockOnPort(int port, int seconds) { + throw new IllegalArgumentException("port, seconds are immutable"); + } - @Override - public int[] getInboundPorts() { - return delegate.getInboundPorts(); - } + @Override + public int[] getInboundPorts() { + return delegate.getInboundPorts(); + } - @Override - public int getPort() { - return delegate.getPort(); - } + @Override + public int getPort() { + return delegate.getPort(); + } - @Override - public String getPrivateKey() { - return delegate.getPrivateKey(); - } + @Override + public Payload getPrivateKey() { + return delegate.getPrivateKey(); + } - @Override - public String getPublicKey() { - return delegate.getPublicKey(); - } + @Override + public Payload getPublicKey() { + return delegate.getPublicKey(); + } - @Override - public byte[] getRunScript() { - return delegate.getRunScript(); - } + @Override + public Payload getRunScript() { + return delegate.getRunScript(); + } - @Override - public int getSeconds() { - return delegate.getSeconds(); - } + @Override + public int getSeconds() { + return delegate.getSeconds(); + } - @Override - public boolean shouldBlockUntilRunning() { - return delegate.shouldBlockUntilRunning(); - } + @Override + public boolean shouldBlockUntilRunning() { + return delegate.shouldBlockUntilRunning(); + } - @Override - public TemplateOptions inboundPorts(int... ports) { - throw new IllegalArgumentException("ports is immutable"); - } + @Override + public TemplateOptions inboundPorts(int... ports) { + throw new IllegalArgumentException("ports is immutable"); + } - @Override - public TemplateOptions installPrivateKey(String privateKey) { - throw new IllegalArgumentException("privateKey is immutable"); - } + @Override + public TemplateOptions installPrivateKey(String privateKey) { + throw new IllegalArgumentException("privateKey is immutable"); + } - @Override - public boolean isIncludeMetadata() { - return delegate.isIncludeMetadata(); - } + @Override + public boolean isIncludeMetadata() { + return delegate.isIncludeMetadata(); + } - @Override - public TemplateOptions runScript(byte[] script) { - throw new IllegalArgumentException("withMetadata is immutable"); - } + @Override + public TemplateOptions runScript(byte[] script) { + throw new IllegalArgumentException("withMetadata is immutable"); + } - @Override - public TemplateOptions withMetadata() { - throw new IllegalArgumentException("withMetadata is immutable"); - } + @Override + public TemplateOptions withMetadata() { + throw new IllegalArgumentException("withMetadata is immutable"); + } - } + } - protected int[] inboundPorts = new int[] { 22 }; + protected int[] inboundPorts = new int[] { 22 }; - protected byte[] script; + protected Payload script; - protected String privateKey; + protected Payload privateKey; - protected String publicKey; + protected Payload publicKey; - protected int port = -1; + protected int port = -1; - protected int seconds = -1; + protected int seconds = -1; - protected boolean includeMetadata; + protected boolean includeMetadata; - protected boolean blockUntilRunning = true; + protected boolean blockUntilRunning = true; - public int getPort() { - return port; - } + public int getPort() { + return port; + } - public int getSeconds() { - return seconds; - } + public int getSeconds() { + return seconds; + } - public int[] getInboundPorts() { - return inboundPorts; - } + public int[] getInboundPorts() { + return inboundPorts; + } - public byte[] getRunScript() { - return script; - } + public Payload getRunScript() { + return script; + } - public String getPrivateKey() { - return privateKey; - } + public Payload getPrivateKey() { + return privateKey; + } - public String getPublicKey() { - return publicKey; - } + public Payload getPublicKey() { + return publicKey; + } - public boolean isIncludeMetadata() { - return includeMetadata; - } + public boolean isIncludeMetadata() { + return includeMetadata; + } - public boolean shouldBlockUntilRunning() { - return blockUntilRunning; - } + public boolean shouldBlockUntilRunning() { + return blockUntilRunning; + } - public T as(Class clazz) { - return clazz.cast(this); - } + public T as(Class clazz) { + return clazz.cast(this); + } - /** - * When the node is started, wait until the following port is active - */ - public TemplateOptions blockOnPort(int port, int seconds) { - checkArgument(port > 0 && port < 65536, - "port must be a positive integer < 65535"); - checkArgument(seconds > 0, "seconds must be a positive integer"); - this.port = port; - this.seconds = seconds; - return this; - } + /** + * When the node is started, wait until the following port is active + */ + public TemplateOptions blockOnPort(int port, int seconds) { + checkArgument(port > 0 && port < 65536, "port must be a positive integer < 65535"); + checkArgument(seconds > 0, "seconds must be a positive integer"); + this.port = port; + this.seconds = seconds; + return this; + } - /** - * This script will be executed as the root user upon system startup. This - * script gets a prologue, so no #!/bin/bash required, path set up, etc - */ - public TemplateOptions runScript(byte[] script) { - checkArgument(checkNotNull(script, "script").length <= 16 * 1024, - "script cannot be larger than 16kb"); - this.script = script; - return this; - } + /** + * This script will be executed as the root user upon system startup. This + * script gets a prologue, so no #!/bin/bash required, path set up, etc + *

+ * please use alternative that uses the {@link org.jclouds.io.Payload} object + * + * @see org.jclouds.io.Payloads + */ + @Deprecated + public TemplateOptions runScript(byte[] script) { + return runScript(newByteArrayPayload(checkNotNull(script, "script"))); + } - /** - * replaces the rsa ssh key used at login. - */ - public TemplateOptions installPrivateKey(String privateKey) { - checkArgument(checkNotNull(privateKey, "privateKey").startsWith( - "-----BEGIN RSA PRIVATE KEY-----"), - "key should start with -----BEGIN RSA PRIVATE KEY-----"); - this.privateKey = privateKey; - return this; - } + /** + * This script will be executed as the root user upon system startup. This + * script gets a prologue, so no #!/bin/bash required, path set up, etc + * + * @see org.jclouds.io.Payloads + */ + public TemplateOptions runScript(Payload script) { + checkArgument( + checkNotNull(checkNotNull(script, "script").getContentLength(), "script.contentLength") <= 16 * 1024, + "script cannot be larger than 16kb"); + this.script = script; + return this; + } - public TemplateOptions dontAuthorizePublicKey() { - this.publicKey = null; - return this; - } + /** + * replaces the rsa ssh key used at login. + *

+ * please use alternative that uses the {@link org.jclouds.io.Payload} object + * + * @see org.jclouds.io.Payloads + */ + @Deprecated + public TemplateOptions installPrivateKey(String privateKey) { + checkArgument(checkNotNull(privateKey, "privateKey").startsWith("-----BEGIN RSA PRIVATE KEY-----"), + "key should start with -----BEGIN RSA PRIVATE KEY-----"); + Payload payload = newStringPayload(privateKey); + payload.setContentType("text/plain"); + return installPrivateKey(payload); + } - /** - * if true, return when node(s) are NODE_RUNNING, if false, return as soon as the - * server is provisioned. - *

- * default is true - */ - public TemplateOptions blockUntilRunning(boolean blockUntilRunning) { - this.blockUntilRunning = blockUntilRunning; - if (!blockUntilRunning) - port = seconds = -1; - return this; - } + /** + * replaces the rsa ssh key used at login. + * + * @see org.jclouds.io.Payloads + */ + public TemplateOptions installPrivateKey(Payload privateKey) { + this.privateKey = checkNotNull(privateKey, "privateKey"); + return this; + } - /** - * authorized an rsa ssh key. - */ - public TemplateOptions authorizePublicKey(String publicKey) { - checkArgument(checkNotNull(publicKey, "publicKey") - .startsWith("ssh-rsa"), "key should start with ssh-rsa"); - this.publicKey = publicKey; - return this; - } + public TemplateOptions dontAuthorizePublicKey() { + this.publicKey = null; + return this; + } - /** - * Opens the set of ports to public access. - */ - public TemplateOptions inboundPorts(int... ports) { - for (int port : ports) - checkArgument(port > 0 && port < 65536, - "port must be a positive integer < 65535"); - this.inboundPorts = ports; - return this; - } + /** + * if true, return when node(s) are NODE_RUNNING, if false, return as soon as + * the server is provisioned. + *

+ * default is true + */ + public TemplateOptions blockUntilRunning(boolean blockUntilRunning) { + this.blockUntilRunning = blockUntilRunning; + if (!blockUntilRunning) + port = seconds = -1; + return this; + } - public TemplateOptions withMetadata() { - this.includeMetadata = true; - return this; - } + /** + * authorize an rsa ssh key. + *

+ * please use alternative that uses the {@link org.jclouds.io.Payload} object + * + * @see org.jclouds.io.Payloads + */ + @Deprecated + public TemplateOptions authorizePublicKey(String publicKey) { + checkArgument(checkNotNull(publicKey, "publicKey").startsWith("ssh-rsa"), "key should start with ssh-rsa"); + Payload payload = newStringPayload(publicKey); + payload.setContentType("text/plain"); + return authorizePublicKey(payload); + } - public static class Builder { + /** + * authorize an rsa ssh key. + * + * @see org.jclouds.io.Payloads + */ + public TemplateOptions authorizePublicKey(Payload publicKey) { + this.publicKey = checkNotNull(publicKey, "publicKey"); + return this; + } - /** - * @see TemplateOptions#inboundPorts - */ - public static TemplateOptions inboundPorts(int... ports) { - TemplateOptions options = new TemplateOptions(); - return options.inboundPorts(ports); - } + /** + * Opens the set of ports to public access. + */ + public TemplateOptions inboundPorts(int... ports) { + for (int port : ports) + checkArgument(port > 0 && port < 65536, "port must be a positive integer < 65535"); + this.inboundPorts = ports; + return this; + } - /** - * @see TemplateOptions#port - */ - public static TemplateOptions blockOnPort(int port, int seconds) { - TemplateOptions options = new TemplateOptions(); - return options.blockOnPort(port, seconds); - } + public TemplateOptions withMetadata() { + this.includeMetadata = true; + return this; + } - /** - * @see TemplateOptions#blockUntilRunning - */ - public static TemplateOptions blockUntilRunning( - boolean blockUntilRunning) { - TemplateOptions options = new TemplateOptions(); - return options.blockUntilRunning(blockUntilRunning); - } + public static class Builder { - /** - * @see TemplateOptions#runScript - */ - public static TemplateOptions runScript(byte[] script) { - TemplateOptions options = new TemplateOptions(); - return options.runScript(script); - } + /** + * @see TemplateOptions#inboundPorts + */ + public static TemplateOptions inboundPorts(int... ports) { + TemplateOptions options = new TemplateOptions(); + return options.inboundPorts(ports); + } - /** - * @see TemplateOptions#installPrivateKey - */ - public static TemplateOptions installPrivateKey(String rsaKey) { - TemplateOptions options = new TemplateOptions(); - return options.installPrivateKey(rsaKey); - } + /** + * @see TemplateOptions#port + */ + public static TemplateOptions blockOnPort(int port, int seconds) { + TemplateOptions options = new TemplateOptions(); + return options.blockOnPort(port, seconds); + } - /** - * @see TemplateOptions#authorizePublicKey - */ - public static TemplateOptions authorizePublicKey(String rsaKey) { - TemplateOptions options = new TemplateOptions(); - return options.authorizePublicKey(rsaKey); - } + /** + * @see TemplateOptions#blockUntilRunning + */ + public static TemplateOptions blockUntilRunning(boolean blockUntilRunning) { + TemplateOptions options = new TemplateOptions(); + return options.blockUntilRunning(blockUntilRunning); + } - public static TemplateOptions withDetails() { - TemplateOptions options = new TemplateOptions(); - return options.withMetadata(); - } + /** + * please use alternative that uses the {@link org.jclouds.io.Payload} + * object + * + * @see org.jclouds.io.Payloads + * @see #runScript(Payload) + */ + @Deprecated + public static TemplateOptions runScript(byte[] script) { + TemplateOptions options = new TemplateOptions(); + return options.runScript(script); + } - } + /** + * @see TemplateOptions#runScript + * @see org.jclouds.io.Payloads + */ + public static TemplateOptions runScript(Payload script) { + TemplateOptions options = new TemplateOptions(); + return options.runScript(script); + } - @Override - public String toString() { - return "TemplateOptions [inboundPorts=" + Arrays.toString(inboundPorts) - + ", privateKey=" + (privateKey != null) + ", publicKey=" - + (publicKey != null) + ", runScript=" + (script != null) - + ", blockUntilRunning=" + blockUntilRunning - + ", port:seconds=" + port + ":" + seconds - + ", metadata/details: " + includeMetadata + "]"; - } + /** + * please use alternative that uses the {@link org.jclouds.io.Payload} + * object + * + * @see org.jclouds.io.Payloads + * @see #installPrivateKey(Payload) + */ + @Deprecated + public static TemplateOptions installPrivateKey(String rsaKey) { + TemplateOptions options = new TemplateOptions(); + return options.installPrivateKey(rsaKey); + } - @Override + /** + * @see TemplateOptions#installPrivateKey + * @see org.jclouds.io.Payloads + */ + public static TemplateOptions installPrivateKey(Payload rsaKey) { + TemplateOptions options = new TemplateOptions(); + return options.installPrivateKey(rsaKey); + } + + /** + * please use alternative that uses the {@link org.jclouds.io.Payload} + * object + * + * @see org.jclouds.io.Payloads + * @see #authorizePublicKey(Payload) + */ + @Deprecated + public static TemplateOptions authorizePublicKey(String rsaKey) { + TemplateOptions options = new TemplateOptions(); + return options.authorizePublicKey(rsaKey); + } + + /** + * @see TemplateOptions#authorizePublicKey(Payload) + * @see org.jclouds.io.Payloads + */ + public static TemplateOptions authorizePublicKey(Payload rsaKey) { + TemplateOptions options = new TemplateOptions(); + return options.authorizePublicKey(rsaKey); + } + + public static TemplateOptions withDetails() { + TemplateOptions options = new TemplateOptions(); + return options.withMetadata(); + } + + } + + @Override + public String toString() { + return "TemplateOptions [inboundPorts=" + Arrays.toString(inboundPorts) + ", privateKey=" + (privateKey != null) + + ", publicKey=" + (publicKey != null) + ", runScript=" + (script != null) + ", blockUntilRunning=" + + blockUntilRunning + ", port:seconds=" + port + ":" + seconds + ", metadata/details: " + includeMetadata + + "]"; + } + + @Override public int hashCode() { final int prime = 31; int result = 1; @@ -346,16 +431,14 @@ public class TemplateOptions { result = prime * result + Arrays.hashCode(inboundPorts); result = prime * result + (includeMetadata ? 1231 : 1237); result = prime * result + port; - result = prime * result - + ((privateKey == null) ? 0 : privateKey.hashCode()); - result = prime * result - + ((publicKey == null) ? 0 : publicKey.hashCode()); - result = prime * result + Arrays.hashCode(script); + result = prime * result + ((privateKey == null) ? 0 : privateKey.hashCode()); + result = prime * result + ((publicKey == null) ? 0 : publicKey.hashCode()); + result = prime * result + ((script == null) ? 0 : script.hashCode()); result = prime * result + seconds; return result; } - @Override + @Override public boolean equals(Object obj) { if (this == obj) return true; @@ -382,7 +465,10 @@ public class TemplateOptions { return false; } else if (!publicKey.equals(other.publicKey)) return false; - if (!Arrays.equals(script, other.script)) + if (script == null) { + if (other.script != null) + return false; + } else if (!script.equals(other.script)) return false; if (seconds != other.seconds) return false; diff --git a/compute/src/main/java/org/jclouds/compute/util/ComputeUtils.java b/compute/src/main/java/org/jclouds/compute/util/ComputeUtils.java index 0fe904d77b..171bd78cb9 100644 --- a/compute/src/main/java/org/jclouds/compute/util/ComputeUtils.java +++ b/compute/src/main/java/org/jclouds/compute/util/ComputeUtils.java @@ -50,6 +50,7 @@ import org.jclouds.compute.reference.ComputeServiceConstants.Timeouts; import org.jclouds.compute.strategy.GetNodeMetadataStrategy; import org.jclouds.compute.util.ComputeServiceUtils.SshCallable; import org.jclouds.concurrent.ConcurrentUtils; +import org.jclouds.io.Payload; import org.jclouds.logging.Logger; import org.jclouds.net.IPSocket; import org.jclouds.predicates.RetryablePredicate; @@ -83,10 +84,9 @@ public class ComputeUtils { @Inject public ComputeUtils(Predicate socketTester, - @Named("SCRIPT_COMPLETE") Predicate runScriptNotRunning, - GetNodeMetadataStrategy getNode, Timeouts timeouts, - @Named("NODE_RUNNING") Predicate nodeRunning, - @Named(Constants.PROPERTY_USER_THREADS) ExecutorService executor) { + @Named("SCRIPT_COMPLETE") Predicate runScriptNotRunning, GetNodeMetadataStrategy getNode, + Timeouts timeouts, @Named("NODE_RUNNING") Predicate nodeRunning, + @Named(Constants.PROPERTY_USER_THREADS) ExecutorService executor) { this.nodeRunning = nodeRunning; this.timeouts = timeouts; this.getNode = getNode; @@ -96,20 +96,18 @@ public class ComputeUtils { } public Map> runOptionsOnNodesAndAddToGoodSetOrPutExceptionIntoBadMap( - final TemplateOptions options, Iterable runningNodes, - final Set goodNodes, final Map badNodes) { + final TemplateOptions options, Iterable runningNodes, final Set goodNodes, + final Map badNodes) { Map> responses = Maps.newHashMap(); for (final NodeMetadata node : runningNodes) { - responses.put(node, makeListenable(executor - .submit(runOptionsOnNodeAndAddToGoodSetOrPutExceptionIntoBadMap(node, badNodes, - goodNodes, options)), executor)); + responses.put(node, makeListenable(executor.submit(runOptionsOnNodeAndAddToGoodSetOrPutExceptionIntoBadMap( + node, badNodes, goodNodes, options)), executor)); } return responses; } - public Callable runOptionsOnNodeAndAddToGoodSetOrPutExceptionIntoBadMap( - final NodeMetadata node, final Map badNodes, - final Set goodNodes, final TemplateOptions options) { + public Callable runOptionsOnNodeAndAddToGoodSetOrPutExceptionIntoBadMap(final NodeMetadata node, + final Map badNodes, final Set goodNodes, final TemplateOptions options) { return new Callable() { @Override public Void call() throws Exception { @@ -118,8 +116,8 @@ public class ComputeUtils { logger.debug("<< options applied node(%s)", node1.getId()); goodNodes.add(node1); } catch (Exception e) { - logger.error(e, "<< problem applying options to node(%s): ", node.getId(), - Throwables.getRootCause(e).getMessage()); + logger.error(e, "<< problem applying options to node(%s): ", node.getId(), Throwables.getRootCause(e) + .getMessage()); badNodes.put(node, e); } return null; @@ -134,11 +132,9 @@ public class ComputeUtils { if (nodeRunning.apply(node)) node = installNewCredentials(getNode.execute(node.getId()), node.getCredentials()); else - throw new IllegalStateException( - String - .format( - "node didn't achieve the state running on node %s within %d seconds, final state: %s", - node.getId(), timeouts.nodeRunning / 1000, node.getState())); + throw new IllegalStateException(String.format( + "node didn't achieve the state running on node %s within %d seconds, final state: %s", node.getId(), + timeouts.nodeRunning / 1000, node.getState())); List> callables = Lists.newArrayList(); if (options.getRunScript() != null) { @@ -151,27 +147,25 @@ public class ComputeUtils { // changing the key "MUST" come last or else the other commands may // fail. if (callables.size() > 0 || options.getPrivateKey() != null) { - runCallablesOnNode(node, callables, options.getPrivateKey() != null ? installKeyOnNode( - node, options.getPrivateKey()) : null); + runCallablesOnNode(node, callables, options.getPrivateKey() != null ? installKeyOnNode(node, options + .getPrivateKey()) : null); } if (options.getPort() > 0) { checkNodeHasPublicIps(node); - blockUntilPortIsListeningOnPublicIp(options.getPort(), options.getSeconds(), Iterables - .get(node.getPublicAddresses(), 0)); + blockUntilPortIsListeningOnPublicIp(options.getPort(), options.getSeconds(), Iterables.get(node + .getPublicAddresses(), 0)); } return node; } private void checkNodeHasPublicIps(NodeMetadata node) { - checkState(node.getPublicAddresses().size() > 0, - "node does not have IP addresses configured: " + node); + checkState(node.getPublicAddresses().size() > 0, "node does not have IP addresses configured: " + node); } private void blockUntilPortIsListeningOnPublicIp(int port, int seconds, String inetAddress) { logger.debug(">> blocking on port %s:%d for %d seconds", inetAddress, port, seconds); - RetryablePredicate tester = new RetryablePredicate(socketTester, seconds, - 1, TimeUnit.SECONDS); + RetryablePredicate tester = new RetryablePredicate(socketTester, seconds, 1, TimeUnit.SECONDS); IPSocket socket = new IPSocket(inetAddress, port); boolean passed = tester.apply(socket); if (passed) @@ -180,25 +174,24 @@ public class ComputeUtils { logger.warn("<< port %s:%d didn't open after %d seconds", inetAddress, port, seconds); } - public InstallRSAPrivateKey installKeyOnNode(NodeMetadata node, String privateKey) { + public InstallRSAPrivateKey installKeyOnNode(NodeMetadata node, Payload privateKey) { return new InstallRSAPrivateKey(node, privateKey); } - public AuthorizeRSAPublicKey authorizeKeyOnNode(NodeMetadata node, String publicKey) { + public AuthorizeRSAPublicKey authorizeKeyOnNode(NodeMetadata node, Payload publicKey) { return new AuthorizeRSAPublicKey(node, publicKey); } - public RunScriptOnNode runScriptOnNode(NodeMetadata node, String scriptName, byte[] script) { + public RunScriptOnNode runScriptOnNode(NodeMetadata node, String scriptName, Payload script) { return new RunScriptOnNode(runScriptNotRunning, node, scriptName, script); } - public RunScriptOnNode runScriptOnNodeAsDefaultUser(NodeMetadata node, String scriptName, - byte[] script) { + public RunScriptOnNode runScriptOnNodeAsDefaultUser(NodeMetadata node, String scriptName, Payload script) { return new RunScriptOnNode(runScriptNotRunning, node, scriptName, script, false); } - public Map, ?> runCallablesOnNode(NodeMetadata node, - Iterable> parallel, @Nullable SshCallable last) { + public Map, ?> runCallablesOnNode(NodeMetadata node, Iterable> parallel, + @Nullable SshCallable last) { checkState(this.sshFactory != null, "runScript requested, but no SshModule configured"); checkNodeHasPublicIps(node); checkNotNull(node.getCredentials().credential, "credentials.key for node " + node.getId()); @@ -212,8 +205,8 @@ public class ComputeUtils { } } - private Map, ?> runTasksUsingSshClient( - Iterable> parallel, SshCallable last, SshClient ssh) { + private Map, ?> runTasksUsingSshClient(Iterable> parallel, + SshCallable last, SshClient ssh) { Map, Object> responses = Maps.newHashMap(); if (Iterables.size(parallel) > 0) { responses.putAll(runCallablesUsingSshClient(parallel, ssh)); @@ -233,26 +226,23 @@ public class ComputeUtils { IPSocket socket = new IPSocket(Iterables.get(node.getPublicAddresses(), 0), 22); socketTester.apply(socket); SshClient ssh = isKeyAuth(node) ? sshFactory.create(socket, node.getCredentials().identity, - node.getCredentials().credential.getBytes()) : sshFactory.create(socket, node - .getCredentials().identity, node.getCredentials().credential); + node.getCredentials().credential.getBytes()) : sshFactory.create(socket, node.getCredentials().identity, + node.getCredentials().credential); return ssh; } - private Map, Object> runCallablesUsingSshClient( - Iterable> parallel, SshClient ssh) { + private Map, Object> runCallablesUsingSshClient(Iterable> parallel, + SshClient ssh) { Map, ListenableFuture> parallelResponses = Maps.newHashMap(); for (SshCallable callable : parallel) { callable.setConnection(ssh, logger); - parallelResponses.put(callable, ConcurrentUtils.makeListenable(executor.submit(callable), - executor)); + parallelResponses.put(callable, ConcurrentUtils.makeListenable(executor.submit(callable), executor)); } - Map, Exception> exceptions = awaitCompletion(parallelResponses, executor, - null, logger, "ssh"); + Map, Exception> exceptions = awaitCompletion(parallelResponses, executor, null, logger, "ssh"); if (exceptions.size() > 0) - throw new RuntimeException(String.format("error invoking callables on nodes: %s", - exceptions)); + throw new RuntimeException(String.format("error invoking callables on nodes: %s", exceptions)); Map, Object> newresponses = transform(parallelResponses); return newresponses; } diff --git a/compute/src/main/java/org/jclouds/ssh/SshClient.java b/compute/src/main/java/org/jclouds/ssh/SshClient.java index 74af0d61d9..4c8694323b 100644 --- a/compute/src/main/java/org/jclouds/ssh/SshClient.java +++ b/compute/src/main/java/org/jclouds/ssh/SshClient.java @@ -18,12 +18,10 @@ */ package org.jclouds.ssh; -import java.io.InputStream; -import java.util.Map; - import javax.annotation.PostConstruct; import javax.annotation.PreDestroy; +import org.jclouds.io.Payload; import org.jclouds.net.IPSocket; /** @@ -35,17 +33,15 @@ public interface SshClient { SshClient create(IPSocket socket, String username, String password); SshClient create(IPSocket socket, String username, byte[] privateKey); - - Map generateRSAKeyPair(String comment, String passphrase); } String getUsername(); String getHostAddress(); - void put(String path, InputStream contents); + void put(String path, Payload contents); - InputStream get(String path); + Payload get(String path); ExecResponse exec(String command); diff --git a/compute/src/test/java/org/jclouds/compute/BaseComputeServiceLiveTest.java b/compute/src/test/java/org/jclouds/compute/BaseComputeServiceLiveTest.java index 9462bff785..f0187df79b 100755 --- a/compute/src/test/java/org/jclouds/compute/BaseComputeServiceLiveTest.java +++ b/compute/src/test/java/org/jclouds/compute/BaseComputeServiceLiveTest.java @@ -19,6 +19,21 @@ package org.jclouds.compute; import static com.google.common.base.Preconditions.checkNotNull; +import static com.google.common.base.Predicates.and; +import static com.google.common.base.Predicates.not; +import static com.google.common.base.Throwables.getRootCause; +import static com.google.common.collect.Iterables.concat; +import static com.google.common.collect.Iterables.get; +import static com.google.common.collect.Iterables.getOnlyElement; +import static com.google.common.collect.Sets.filter; +import static com.google.common.collect.Sets.newHashSet; +import static com.google.common.collect.Sets.newTreeSet; +import static org.jclouds.compute.options.RunScriptOptions.Builder.overrideCredentialsWith; +import static org.jclouds.compute.predicates.NodePredicates.TERMINATED; +import static org.jclouds.compute.predicates.NodePredicates.all; +import static org.jclouds.compute.predicates.NodePredicates.runningWithTag; +import static org.jclouds.compute.predicates.NodePredicates.withTag; +import static org.jclouds.io.Payloads.newStringPayload; import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertNotNull; @@ -43,9 +58,7 @@ import org.jclouds.compute.domain.OsFamily; import org.jclouds.compute.domain.Size; import org.jclouds.compute.domain.Template; import org.jclouds.compute.domain.TemplateBuilder; -import org.jclouds.compute.options.RunScriptOptions; import org.jclouds.compute.options.TemplateOptions; -import org.jclouds.compute.predicates.NodePredicates; import org.jclouds.domain.Credentials; import org.jclouds.domain.Location; import org.jclouds.domain.LocationScope; @@ -65,12 +78,8 @@ import org.testng.annotations.BeforeGroups; import org.testng.annotations.Test; import com.google.common.base.Charsets; -import com.google.common.base.Predicates; -import com.google.common.base.Throwables; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; -import com.google.common.collect.Iterables; -import com.google.common.collect.Sets; import com.google.common.io.Files; import com.google.inject.Guice; import com.google.inject.Injector; @@ -128,7 +137,7 @@ public abstract class BaseComputeServiceLiveTest { String secret = Files.toString(new File(secretKeyFile), Charsets.UTF_8); assert secret.startsWith("-----BEGIN RSA PRIVATE KEY-----") : "invalid key:\n" + secret; return ImmutableMap. of("private", secret, "public", Files.toString(new File(secretKeyFile - + ".pub"), Charsets.UTF_8)); + + ".pub"), Charsets.UTF_8)); } protected void setupCredentials() { @@ -144,7 +153,7 @@ public abstract class BaseComputeServiceLiveTest { if (context != null) context.close(); context = new ComputeServiceContextFactory().createContext(provider, identity, credential, ImmutableSet.of( - new Log4JLoggingModule(), getSshModule())); + new Log4JLoggingModule(), getSshModule())); client = context.getComputeService(); } @@ -161,7 +170,7 @@ public abstract class BaseComputeServiceLiveTest { @Test(enabled = true, expectedExceptions = AuthorizationException.class) public void testCorrectAuthException() throws Exception { new ComputeServiceContextFactory().createContext(provider, "MOMMA", "MIA", - ImmutableSet. of(new Log4JLoggingModule())).close(); + ImmutableSet. of(new Log4JLoggingModule())).close(); } @Test(enabled = true, dependsOnMethods = "testCorrectAuthException") @@ -179,7 +188,7 @@ public abstract class BaseComputeServiceLiveTest { public void testAScriptExecutionAfterBootWithBasicTemplate() throws Exception { String tag = this.tag + "run"; try { - client.destroyNodesMatching(NodePredicates.withTag(tag)); + client.destroyNodesMatching(withTag(tag)); } catch (Exception e) { } @@ -191,13 +200,13 @@ public abstract class BaseComputeServiceLiveTest { assert good.identity != null; assert good.credential != null; - Image image = Iterables.get(nodes, 0).getImage(); + Image image = get(nodes, 0).getImage(); try { Map responses = runScriptWithCreds(tag, image.getOsFamily(), - new Credentials(good.identity, "romeo")); + new Credentials(good.identity, "romeo")); assert false : "shouldn't pass with a bad password\n" + responses; } catch (RunScriptOnNodesException e) { - assert Throwables.getRootCause(e).getMessage().contains("Auth fail") : e; + assert getRootCause(e).getMessage().contains("Auth fail") : e; } runScriptWithCreds(tag, image.getOsFamily(), good); @@ -205,7 +214,7 @@ public abstract class BaseComputeServiceLiveTest { checkNodes(nodes, tag); } finally { - client.destroyNodesMatching(NodePredicates.withTag(tag)); + client.destroyNodesMatching(withTag(tag)); } } @@ -219,7 +228,7 @@ public abstract class BaseComputeServiceLiveTest { @Test(enabled = true, dependsOnMethods = "testTemplateMatch") public void testCreateTwoNodesWithRunScript() throws Exception { try { - client.destroyNodesMatching(NodePredicates.withTag(tag)); + client.destroyNodesMatching(withTag(tag)); } catch (HttpResponseException e) { // TODO hosting.com throws 400 when we try to delete a vApp } catch (NoSuchElementException e) { @@ -227,12 +236,13 @@ public abstract class BaseComputeServiceLiveTest { } template = buildTemplate(client.templateBuilder()); - template.getOptions().installPrivateKey(keyPair.get("private")).authorizePublicKey(keyPair.get("public")) - .runScript(buildScript(template.getImage().getOsFamily()).getBytes()); + template.getOptions().installPrivateKey(newStringPayload(keyPair.get("private"))).authorizePublicKey( + newStringPayload(keyPair.get("public"))).runScript( + newStringPayload(buildScript(template.getImage().getOsFamily()))); try { - nodes = Sets.newTreeSet(client.runNodesWithTag(tag, 2, template)); + nodes = newTreeSet(client.runNodesWithTag(tag, 2, template)); } catch (RunNodesException e) { - nodes = Sets.newTreeSet(Iterables.concat(e.getSuccessfulNodes(), e.getNodeErrors().keySet())); + nodes = newTreeSet(concat(e.getSuccessfulNodes(), e.getNodeErrors().keySet())); throw e; } assertEquals(nodes.size(), 2); @@ -261,7 +271,7 @@ public abstract class BaseComputeServiceLiveTest { @Test(enabled = true, dependsOnMethods = "testCreateTwoNodesWithRunScript") public void testCreateAnotherNodeWithANewContextToEnsureSharedMemIsntRequired() throws Exception { initializeContextAndClient(); - TreeSet nodes = Sets.newTreeSet(client.runNodesWithTag(tag, 1, template)); + TreeSet nodes = newTreeSet(client.runNodesWithTag(tag, 1, template)); checkNodes(nodes, tag); NodeMetadata node = nodes.first(); this.nodes.add(node); @@ -271,12 +281,12 @@ public abstract class BaseComputeServiceLiveTest { } protected Map runScriptWithCreds(final String tag, OsFamily osFamily, - Credentials creds) throws RunScriptOnNodesException { + Credentials creds) throws RunScriptOnNodesException { try { - return client.runScriptOnNodesMatching(NodePredicates.runningWithTag(tag), buildScript(osFamily).getBytes(), - RunScriptOptions.Builder.overrideCredentialsWith(creds)); + return client.runScriptOnNodesMatching(runningWithTag(tag), newStringPayload(buildScript(osFamily)), + overrideCredentialsWith(creds)); } catch (SshException e) { - if (Throwables.getRootCause(e).getMessage().contains("Auth fail")) { + if (getRootCause(e).getMessage().contains("Auth fail")) { // System.err.printf("bad credentials: %s:%s for %s%n", // creds.identity, creds.key, client // .listNodesDetailsMatching(tag)); @@ -307,40 +317,38 @@ public abstract class BaseComputeServiceLiveTest { public static String buildScript(OsFamily osFamily) { switch (osFamily) { - case UBUNTU: - return new StringBuilder()// - .append("echo nameserver 208.67.222.222 >> /etc/resolv.conf\n")// - .append("cp /etc/apt/sources.list /etc/apt/sources.list.old\n")// - .append( - "sed 's~us.archive.ubuntu.com~mirror.anl.gov/pub~g' /etc/apt/sources.list.old >/etc/apt/sources.list\n")// - .append("apt-get update\n")// - .append("apt-get install -f -y --force-yes openjdk-6-jdk\n")// - .append("wget -qO/usr/bin/runurl run.alestic.com/runurl\n")// - .append("chmod 755 /usr/bin/runurl\n")// - .toString(); - case CENTOS: - case RHEL: - return new StringBuilder() - .append("echo nameserver 208.67.222.222 >> /etc/resolv.conf\n") - .append("echo \"[jdkrepo]\" >> /etc/yum.repos.d/CentOS-Base.repo\n") - .append("echo \"name=jdkrepository\" >> /etc/yum.repos.d/CentOS-Base.repo\n") - .append( - "echo \"baseurl=http://ec2-us-east-mirror.rightscale.com/epel/5/i386/\" >> /etc/yum.repos.d/CentOS-Base.repo\n") - .append("echo \"enabled=1\" >> /etc/yum.repos.d/CentOS-Base.repo\n") - .append("yum --nogpgcheck -y install java-1.6.0-openjdk\n") - .append( - "echo \"export PATH=\\\"/usr/lib/jvm/jre-1.6.0-openjdk/bin/:\\$PATH\\\"\" >> /root/.bashrc\n") - .toString(); - default: - throw new IllegalArgumentException(osFamily.toString()); + case UBUNTU: + return new StringBuilder()// + .append("echo nameserver 208.67.222.222 >> /etc/resolv.conf\n")// + .append("cp /etc/apt/sources.list /etc/apt/sources.list.old\n")// + .append( + "sed 's~us.archive.ubuntu.com~mirror.anl.gov/pub~g' /etc/apt/sources.list.old >/etc/apt/sources.list\n")// + .append("apt-get update\n")// + .append("apt-get install -f -y --force-yes openjdk-6-jdk\n")// + .append("wget -qO/usr/bin/runurl run.alestic.com/runurl\n")// + .append("chmod 755 /usr/bin/runurl\n")// + .toString(); + case CENTOS: + case RHEL: + return new StringBuilder() + .append("echo nameserver 208.67.222.222 >> /etc/resolv.conf\n") + .append("echo \"[jdkrepo]\" >> /etc/yum.repos.d/CentOS-Base.repo\n") + .append("echo \"name=jdkrepository\" >> /etc/yum.repos.d/CentOS-Base.repo\n") + .append( + "echo \"baseurl=http://ec2-us-east-mirror.rightscale.com/epel/5/i386/\" >> /etc/yum.repos.d/CentOS-Base.repo\n") + .append("echo \"enabled=1\" >> /etc/yum.repos.d/CentOS-Base.repo\n").append( + "yum --nogpgcheck -y install java-1.6.0-openjdk\n").append( + "echo \"export PATH=\\\"/usr/lib/jvm/jre-1.6.0-openjdk/bin/:\\$PATH\\\"\" >> /root/.bashrc\n") + .toString(); + default: + throw new IllegalArgumentException(osFamily.toString()); } } @Test(enabled = true, dependsOnMethods = "testCreateAnotherNodeWithANewContextToEnsureSharedMemIsntRequired") public void testGet() throws Exception { - Set metadataSet = Sets.newHashSet(Iterables.filter(client - .listNodesDetailsMatching(NodePredicates.all()), Predicates.and(NodePredicates.withTag(tag), Predicates - .not(NodePredicates.TERMINATED)))); + Set metadataSet = newHashSet(filter(client.listNodesDetailsMatching(all()), and( + withTag(tag), not(TERMINATED)))); for (NodeMetadata node : nodes) { metadataSet.remove(node); NodeMetadata metadata = client.getNodeMetadata(node.getId()); @@ -357,12 +365,12 @@ public abstract class BaseComputeServiceLiveTest { protected void assertNodeZero(Set metadataSet) { assert metadataSet.size() == 0 : String.format("nodes left in set: [%s] which didn't match set: [%s]", - metadataSet, nodes); + metadataSet, nodes); } @Test(enabled = true, dependsOnMethods = "testGet") public void testReboot() throws Exception { - client.rebootNodesMatching(NodePredicates.withTag(tag));// TODO test + client.rebootNodesMatching(withTag(tag));// TODO test // validation testGet(); } @@ -383,7 +391,7 @@ public abstract class BaseComputeServiceLiveTest { } public void testGetNodesWithDetails() throws Exception { - for (NodeMetadata node : client.listNodesDetailsMatching(NodePredicates.all())) { + for (NodeMetadata node : client.listNodesDetailsMatching(all())) { assert node.getProviderId() != null : node; assert node.getLocation() != null : node; assertEquals(node.getType(), ComputeType.NODE); @@ -418,26 +426,26 @@ public abstract class BaseComputeServiceLiveTest { assert location != location.getParent() : location; assert location.getScope() != null : location; switch (location.getScope()) { - case PROVIDER: - assertProvider(location); - break; - case REGION: - assertProvider(location.getParent()); - break; - case ZONE: - Location provider = location.getParent().getParent(); - // zone can be a direct descendant of provider - if (provider == null) - provider = location.getParent(); - assertProvider(provider); - break; - case HOST: - Location provider2 = location.getParent().getParent().getParent(); - // zone can be a direct descendant of provider - if (provider2 == null) - provider2 = location.getParent().getParent(); - assertProvider(provider2); - break; + case PROVIDER: + assertProvider(location); + break; + case REGION: + assertProvider(location.getParent()); + break; + case ZONE: + Location provider = location.getParent().getParent(); + // zone can be a direct descendant of provider + if (provider == null) + provider = location.getParent(); + assertProvider(provider); + break; + case HOST: + Location provider2 = location.getParent().getParent().getParent(); + // zone can be a direct descendant of provider + if (provider2 == null) + provider2 = location.getParent().getParent(); + assertProvider(provider2); + break; } } } @@ -446,7 +454,7 @@ public abstract class BaseComputeServiceLiveTest { public void testOptionToNotBlock() throws Exception { String tag = this.tag + "block"; try { - client.destroyNodesMatching(NodePredicates.withTag(tag)); + client.destroyNodesMatching(withTag(tag)); } catch (Exception e) { } @@ -455,12 +463,12 @@ public abstract class BaseComputeServiceLiveTest { try { long time = System.currentTimeMillis(); Set nodes = client.runNodesWithTag(tag, 1, options); - NodeMetadata node = Iterables.getOnlyElement(nodes); + NodeMetadata node = getOnlyElement(nodes); assert node.getState() != NodeState.RUNNING; long duration = System.currentTimeMillis() - time; assert duration < 30 * 1000 : "duration longer than 30 seconds!: " + duration / 1000; } finally { - client.destroyNodesMatching(NodePredicates.withTag(tag)); + client.destroyNodesMatching(withTag(tag)); } } @@ -495,7 +503,7 @@ public abstract class BaseComputeServiceLiveTest { } protected void doCheckJavaIsInstalledViaSsh(NodeMetadata node) throws IOException { - IPSocket socket = new IPSocket(Iterables.get(node.getPublicAddresses(), 0), 22); + IPSocket socket = new IPSocket(get(node.getPublicAddresses(), 0), 22); socketTester.apply(socket); // TODO add transitionTo option that accepts // a socket conection // state. @@ -515,9 +523,8 @@ public abstract class BaseComputeServiceLiveTest { @AfterTest protected void cleanup() throws InterruptedException, ExecutionException, TimeoutException { if (nodes != null) { - client.destroyNodesMatching(NodePredicates.withTag(tag)); - for (NodeMetadata node : Iterables.filter(client.listNodesDetailsMatching(NodePredicates.all()), - NodePredicates.withTag(tag))) { + client.destroyNodesMatching(withTag(tag)); + for (NodeMetadata node : filter(client.listNodesDetailsMatching(all()), withTag(tag))) { assert node.getState() == NodeState.TERMINATED : node; } } diff --git a/compute/src/test/java/org/jclouds/compute/StubComputeServiceIntegrationTest.java b/compute/src/test/java/org/jclouds/compute/StubComputeServiceIntegrationTest.java index c5fa427532..1c1f7bb36b 100644 --- a/compute/src/test/java/org/jclouds/compute/StubComputeServiceIntegrationTest.java +++ b/compute/src/test/java/org/jclouds/compute/StubComputeServiceIntegrationTest.java @@ -29,7 +29,6 @@ import static org.testng.Assert.assertEquals; import java.io.FileNotFoundException; import java.io.IOException; -import java.io.InputStream; import java.io.Serializable; import java.util.Set; import java.util.concurrent.ConcurrentMap; @@ -40,6 +39,7 @@ import org.jclouds.compute.domain.NodeMetadata; import org.jclouds.compute.domain.OsFamily; import org.jclouds.compute.domain.Template; import org.jclouds.compute.stub.config.StubComputeServiceContextModule.StubNodeMetadata; +import org.jclouds.io.Payload; import org.jclouds.net.IPSocket; import org.jclouds.predicates.SocketOpen; import org.jclouds.rest.RestContext; @@ -109,17 +109,17 @@ public class StubComputeServiceIntegrationTest extends BaseComputeServiceLiveTes expect(open.apply(new IPSocket("144.175.1.4", 22))).andReturn(true); expect( - factory.create(eq(new IPSocket("144.175.1.1", 22)), eq("root"), aryEq(keyPair - .get("private").getBytes()))).andReturn(client1).atLeastOnce(); + factory.create(eq(new IPSocket("144.175.1.1", 22)), eq("root"), aryEq(keyPair.get("private") + .getBytes()))).andReturn(client1).atLeastOnce(); expect( - factory.create(eq(new IPSocket("144.175.1.2", 22)), eq("root"), aryEq(keyPair - .get("private").getBytes()))).andReturn(client2).atLeastOnce(); + factory.create(eq(new IPSocket("144.175.1.2", 22)), eq("root"), aryEq(keyPair.get("private") + .getBytes()))).andReturn(client2).atLeastOnce(); expect( - factory.create(eq(new IPSocket("144.175.1.3", 22)), eq("root"), aryEq(keyPair - .get("private").getBytes()))).andReturn(client3).atLeastOnce(); + factory.create(eq(new IPSocket("144.175.1.3", 22)), eq("root"), aryEq(keyPair.get("private") + .getBytes()))).andReturn(client3).atLeastOnce(); expect( - factory.create(eq(new IPSocket("144.175.1.4", 22)), eq("root"), aryEq(keyPair - .get("private").getBytes()))).andReturn(client4).atLeastOnce(); + factory.create(eq(new IPSocket("144.175.1.4", 22)), eq("root"), aryEq(keyPair.get("private") + .getBytes()))).andReturn(client4).atLeastOnce(); helloAndJava(client1); helloAndJava(client2); @@ -163,20 +163,20 @@ public class StubComputeServiceIntegrationTest extends BaseComputeServiceLiveTes SshClient client4 = createMock(SshClient.class); expect(factory.create(new IPSocket("144.175.1.1", 22), "root", "romeo")).andThrow( - new SshException("Auth fail")); - expect(factory.create(new IPSocket("144.175.1.1", 22), "root", "password1")).andReturn( - client1).atLeastOnce(); + new SshException("Auth fail")); + expect(factory.create(new IPSocket("144.175.1.1", 22), "root", "password1")).andReturn(client1) + .atLeastOnce(); client1.connect(); runScript(client1, "computeserv", 1); client1.disconnect(); - expect(factory.create(new IPSocket("144.175.1.2", 22), "root", "password2")).andReturn( - client2).atLeastOnce(); - expect(factory.create(new IPSocket("144.175.1.3", 22), "root", "password3")).andReturn( - client3).atLeastOnce(); - expect(factory.create(new IPSocket("144.175.1.4", 22), "root", "password4")).andReturn( - client4).atLeastOnce(); + expect(factory.create(new IPSocket("144.175.1.2", 22), "root", "password2")).andReturn(client2) + .atLeastOnce(); + expect(factory.create(new IPSocket("144.175.1.3", 22), "root", "password3")).andReturn(client3) + .atLeastOnce(); + expect(factory.create(new IPSocket("144.175.1.4", 22), "root", "password4")).andReturn(client4) + .atLeastOnce(); runScriptAndInstallSsh(client2, "runscript", 2); runScriptAndInstallSsh(client3, "runscript", 3); @@ -199,10 +199,10 @@ public class StubComputeServiceIntegrationTest extends BaseComputeServiceLiveTes expect(client.exec("mkdir .ssh")).andReturn(EXEC_GOOD); expect(client.exec("cat .ssh/id_rsa.pub >> .ssh/authorized_keys")).andReturn(EXEC_GOOD); expect(client.exec("chmod 600 .ssh/authorized_keys")).andReturn(EXEC_GOOD); - client.put(eq(".ssh/id_rsa.pub"), isEq(keyPair.get("public"))); + client.put(eq(".ssh/id_rsa.pub"), payloadEq(keyPair.get("public"))); expect(client.exec("mkdir .ssh")).andReturn(EXEC_GOOD); - client.put(eq(".ssh/id_rsa"), isEq(keyPair.get("private"))); + client.put(eq(".ssh/id_rsa"), payloadEq(keyPair.get("private"))); expect(client.exec("chmod 600 .ssh/id_rsa")).andReturn(EXEC_GOOD); client.disconnect(); @@ -211,8 +211,7 @@ public class StubComputeServiceIntegrationTest extends BaseComputeServiceLiveTes } private void runScript(SshClient client, String scriptName, int nodeId) { - client.put(eq("" + scriptName + ""), isEq(initScript(scriptName, - buildScript(OsFamily.UBUNTU)))); + client.put(eq("" + scriptName + ""), payloadEq(initScript(scriptName, buildScript(OsFamily.UBUNTU)))); expect(client.exec("chmod 755 " + scriptName + "")).andReturn(EXEC_GOOD); expect(client.getUsername()).andReturn("root").atLeastOnce(); @@ -240,30 +239,30 @@ public class StubComputeServiceIntegrationTest extends BaseComputeServiceLiveTes } public static String initScript(String scriptName, String script) { - return new InitBuilder(scriptName, "/tmp/" + scriptName, "/tmp/" + scriptName, ImmutableMap - . of(), Iterables.toArray(Splitter.on("\n").split( - new String(checkNotNull(script, "script"))), String.class)) - .build(org.jclouds.scriptbuilder.domain.OsFamily.UNIX); + return new InitBuilder(scriptName, "/tmp/" + scriptName, "/tmp/" + scriptName, + ImmutableMap. of(), Iterables.toArray(Splitter.on("\n").split( + new String(checkNotNull(script, "script"))), String.class)) + .build(org.jclouds.scriptbuilder.domain.OsFamily.UNIX); } - public static InputStream isEq(String value) { - reportMatcher(new InputStreamEquals(value)); + public static Payload payloadEq(String value) { + reportMatcher(new PayloadEquals(value)); return null; } public void testAssignability() throws Exception { @SuppressWarnings("unused") RestContext, ConcurrentMap> stubContext = new ComputeServiceContextFactory() - .createContext(provider, identity, credential).getProviderSpecificContext(); + .createContext(provider, identity, credential).getProviderSpecificContext(); } - private static class InputStreamEquals implements IArgumentMatcher, Serializable { + private static class PayloadEquals implements IArgumentMatcher, Serializable { private static final long serialVersionUID = 583055160049982067L; private final Object expected; - public InputStreamEquals(Object expected) { + public PayloadEquals(Object expected) { this.expected = expected; } @@ -272,7 +271,7 @@ public class StubComputeServiceIntegrationTest extends BaseComputeServiceLiveTes return actual == null; } try { - String real = Utils.toStringAndClose((InputStream) actual); + String real = Utils.toStringAndClose(((Payload) actual).getInput()); if (!expected.equals(real)) { System.err.println(real); return false; @@ -302,9 +301,9 @@ public class StubComputeServiceIntegrationTest extends BaseComputeServiceLiveTes public boolean equals(Object o) { if (o == null || !this.getClass().equals(o.getClass())) return false; - InputStreamEquals other = (InputStreamEquals) o; + PayloadEquals other = (PayloadEquals) o; return this.expected == null && other.expected == null || this.expected != null - && this.expected.equals(other.expected); + && this.expected.equals(other.expected); } @Override @@ -316,11 +315,11 @@ public class StubComputeServiceIntegrationTest extends BaseComputeServiceLiveTes @Override protected void setupKeyPairForTest() throws FileNotFoundException, IOException { - keyPair = ImmutableMap. of("public", "ssh-rsa", "private", - "-----BEGIN RSA PRIVATE KEY-----"); + keyPair = ImmutableMap. of("public", "ssh-rsa", "private", "-----BEGIN RSA PRIVATE KEY-----"); } - // TODO: I have absolutely no idea why I have to redeclare all this cruft. If I don't, then we + // TODO: I have absolutely no idea why I have to redeclare all this cruft. If + // I don't, then we // get all sorts of not allowed to depend on errors. @Override public void testImagesCache() throws Exception { diff --git a/compute/src/test/java/org/jclouds/compute/options/TemplateOptionsTest.java b/compute/src/test/java/org/jclouds/compute/options/TemplateOptionsTest.java index e5a0cff094..ca47887397 100755 --- a/compute/src/test/java/org/jclouds/compute/options/TemplateOptionsTest.java +++ b/compute/src/test/java/org/jclouds/compute/options/TemplateOptionsTest.java @@ -25,6 +25,9 @@ import static org.jclouds.compute.options.TemplateOptions.Builder.inboundPorts; import static org.jclouds.compute.options.TemplateOptions.Builder.installPrivateKey; import static org.testng.Assert.assertEquals; +import java.io.IOException; + +import org.jclouds.util.Utils; import org.testng.annotations.Test; /** @@ -33,150 +36,157 @@ import org.testng.annotations.Test; * @author Adrian Cole */ public class TemplateOptionsTest { + @SuppressWarnings("deprecation") + @Test(expectedExceptions = IllegalArgumentException.class) + public void testinstallPrivateKeyBadFormat() { + TemplateOptions options = new TemplateOptions(); + options.installPrivateKey("whompy"); + } - @Test(expectedExceptions = IllegalArgumentException.class) - public void testinstallPrivateKeyBadFormat() { - TemplateOptions options = new TemplateOptions(); - options.installPrivateKey("whompy"); - } + @SuppressWarnings("deprecation") + @Test + public void testinstallPrivateKey() throws IOException { + TemplateOptions options = new TemplateOptions(); + options.installPrivateKey("-----BEGIN RSA PRIVATE KEY-----"); + assertEquals(Utils.toStringAndClose(options.getPrivateKey().getInput()), "-----BEGIN RSA PRIVATE KEY-----"); + } - @Test - public void testinstallPrivateKey() { - TemplateOptions options = new TemplateOptions(); - options.installPrivateKey("-----BEGIN RSA PRIVATE KEY-----"); - assertEquals(options.getPrivateKey(), "-----BEGIN RSA PRIVATE KEY-----"); - } + @Test + public void testNullinstallPrivateKey() { + TemplateOptions options = new TemplateOptions(); + assertEquals(options.getPrivateKey(), null); + } - @Test - public void testNullinstallPrivateKey() { - TemplateOptions options = new TemplateOptions(); - assertEquals(options.getPrivateKey(), null); - } + @SuppressWarnings("deprecation") + @Test + public void testinstallPrivateKeyStatic() throws IOException { + TemplateOptions options = installPrivateKey("-----BEGIN RSA PRIVATE KEY-----"); + assertEquals(Utils.toStringAndClose(options.getPrivateKey().getInput()), "-----BEGIN RSA PRIVATE KEY-----"); + } - @Test - public void testinstallPrivateKeyStatic() { - TemplateOptions options = installPrivateKey("-----BEGIN RSA PRIVATE KEY-----"); - assertEquals(options.getPrivateKey(), "-----BEGIN RSA PRIVATE KEY-----"); - } + @SuppressWarnings("deprecation") + @Test(expectedExceptions = NullPointerException.class) + public void testinstallPrivateKeyNPE() { + installPrivateKey((String) null); + } - @Test(expectedExceptions = NullPointerException.class) - public void testinstallPrivateKeyNPE() { - installPrivateKey(null); - } + @SuppressWarnings("deprecation") + @Test(expectedExceptions = IllegalArgumentException.class) + public void testauthorizePublicKeyBadFormat() { + TemplateOptions options = new TemplateOptions(); + options.authorizePublicKey("whompy"); + } - @Test(expectedExceptions = IllegalArgumentException.class) - public void testauthorizePublicKeyBadFormat() { - TemplateOptions options = new TemplateOptions(); - options.authorizePublicKey("whompy"); - } + @Test + @SuppressWarnings("deprecation") + public void testauthorizePublicKey() throws IOException { + TemplateOptions options = new TemplateOptions(); + options.authorizePublicKey("ssh-rsa"); + assertEquals(Utils.toStringAndClose(options.getPublicKey().getInput()), "ssh-rsa"); + } - @Test - public void testauthorizePublicKey() { - TemplateOptions options = new TemplateOptions(); - options.authorizePublicKey("ssh-rsa"); - assertEquals(options.getPublicKey(), "ssh-rsa"); - } + @Test + public void testNullauthorizePublicKey() { + TemplateOptions options = new TemplateOptions(); + assertEquals(options.getPublicKey(), null); + } - @Test - public void testNullauthorizePublicKey() { - TemplateOptions options = new TemplateOptions(); - assertEquals(options.getPublicKey(), null); - } + @SuppressWarnings("deprecation") + @Test + public void testauthorizePublicKeyStatic() throws IOException { + TemplateOptions options = authorizePublicKey("ssh-rsa"); + assertEquals(Utils.toStringAndClose(options.getPublicKey().getInput()), "ssh-rsa"); + } - @Test - public void testauthorizePublicKeyStatic() { - TemplateOptions options = authorizePublicKey("ssh-rsa"); - assertEquals(options.getPublicKey(), "ssh-rsa"); - } + @SuppressWarnings("deprecation") + @Test(expectedExceptions = NullPointerException.class) + public void testauthorizePublicKeyNPE() { + authorizePublicKey((String) null); + } - @Test(expectedExceptions = NullPointerException.class) - public void testauthorizePublicKeyNPE() { - authorizePublicKey(null); - } + @Test(expectedExceptions = IllegalArgumentException.class) + public void testblockOnPortBadFormat() { + TemplateOptions options = new TemplateOptions(); + options.blockOnPort(-1, -1); + } - @Test(expectedExceptions = IllegalArgumentException.class) - public void testblockOnPortBadFormat() { - TemplateOptions options = new TemplateOptions(); - options.blockOnPort(-1, -1); - } + @Test + public void testblockOnPort() { + TemplateOptions options = new TemplateOptions(); + options.blockOnPort(22, 30); + assertEquals(options.getPort(), 22); + assertEquals(options.getSeconds(), 30); - @Test - public void testblockOnPort() { - TemplateOptions options = new TemplateOptions(); - options.blockOnPort(22, 30); - assertEquals(options.getPort(), 22); - assertEquals(options.getSeconds(), 30); + } - } + @Test + public void testNullblockOnPort() { + TemplateOptions options = new TemplateOptions(); + assertEquals(options.getPort(), -1); + assertEquals(options.getSeconds(), -1); + } - @Test - public void testNullblockOnPort() { - TemplateOptions options = new TemplateOptions(); - assertEquals(options.getPort(), -1); - assertEquals(options.getSeconds(), -1); - } + @Test + public void testblockOnPortStatic() { + TemplateOptions options = blockOnPort(22, 30); + assertEquals(options.getPort(), 22); + assertEquals(options.getSeconds(), 30); + } - @Test - public void testblockOnPortStatic() { - TemplateOptions options = blockOnPort(22, 30); - assertEquals(options.getPort(), 22); - assertEquals(options.getSeconds(), 30); - } + @Test(expectedExceptions = IllegalArgumentException.class) + public void testinboundPortsBadFormat() { + TemplateOptions options = new TemplateOptions(); + options.inboundPorts(-1, -1); + } - @Test(expectedExceptions = IllegalArgumentException.class) - public void testinboundPortsBadFormat() { - TemplateOptions options = new TemplateOptions(); - options.inboundPorts(-1, -1); - } + @Test + public void testinboundPorts() { + TemplateOptions options = new TemplateOptions(); + options.inboundPorts(22, 30); + assertEquals(options.getInboundPorts()[0], 22); + assertEquals(options.getInboundPorts()[1], 30); - @Test - public void testinboundPorts() { - TemplateOptions options = new TemplateOptions(); - options.inboundPorts(22, 30); - assertEquals(options.getInboundPorts()[0], 22); - assertEquals(options.getInboundPorts()[1], 30); + } - } + @Test + public void testDefaultOpen22() { + TemplateOptions options = new TemplateOptions(); + assertEquals(options.getInboundPorts()[0], 22); + } - @Test - public void testDefaultOpen22() { - TemplateOptions options = new TemplateOptions(); - assertEquals(options.getInboundPorts()[0], 22); - } + @Test + public void testinboundPortsStatic() { + TemplateOptions options = inboundPorts(22, 30); + assertEquals(options.getInboundPorts()[0], 22); + assertEquals(options.getInboundPorts()[1], 30); + } - @Test - public void testinboundPortsStatic() { - TemplateOptions options = inboundPorts(22, 30); - assertEquals(options.getInboundPorts()[0], 22); - assertEquals(options.getInboundPorts()[1], 30); - } + @Test + public void testblockUntilRunningDefault() { + TemplateOptions options = new TemplateOptions(); + assertEquals(options.shouldBlockUntilRunning(), true); + } - @Test - public void testblockUntilRunningDefault() { - TemplateOptions options = new TemplateOptions(); - assertEquals(options.shouldBlockUntilRunning(), true); - } + @Test + public void testblockUntilRunning() { + TemplateOptions options = new TemplateOptions(); + options.blockUntilRunning(false); + assertEquals(options.shouldBlockUntilRunning(), false); + } - @Test - public void testblockUntilRunning() { - TemplateOptions options = new TemplateOptions(); - options.blockUntilRunning(false); - assertEquals(options.shouldBlockUntilRunning(), false); - } + @Test + public void testBlockUntilRunningUnsetsBlockOnPort() { + TemplateOptions options = new TemplateOptions(); + options.blockOnPort(22, 30); + options.blockUntilRunning(false); + assertEquals(options.shouldBlockUntilRunning(), false); + assertEquals(options.getPort(), -1); + assertEquals(options.getSeconds(), -1); + } - @Test - public void testBlockUntilRunningUnsetsBlockOnPort() { - TemplateOptions options = new TemplateOptions(); - options.blockOnPort(22, 30); - options.blockUntilRunning(false); - assertEquals(options.shouldBlockUntilRunning(), false); - assertEquals(options.getPort(), -1); - assertEquals(options.getSeconds(), -1); - } - - @Test - public void testblockUntilRunningStatic() { - TemplateOptions options = blockUntilRunning(false); - assertEquals(options.shouldBlockUntilRunning(), false); - } + @Test + public void testblockUntilRunningStatic() { + TemplateOptions options = blockUntilRunning(false); + assertEquals(options.shouldBlockUntilRunning(), false); + } } diff --git a/core/src/main/java/org/jclouds/encryption/EncryptionService.java b/core/src/main/java/org/jclouds/encryption/EncryptionService.java index 350f6aeacb..2e378eeefc 100644 --- a/core/src/main/java/org/jclouds/encryption/EncryptionService.java +++ b/core/src/main/java/org/jclouds/encryption/EncryptionService.java @@ -25,9 +25,9 @@ import java.io.OutputStream; import java.security.Key; import org.jclouds.encryption.internal.JCEEncryptionService; -import org.jclouds.http.Payload; import org.jclouds.http.PayloadEnclosing; -import org.jclouds.http.payloads.ByteArrayPayload; +import org.jclouds.io.Payload; +import org.jclouds.io.payloads.ByteArrayPayload; import com.google.inject.ImplementedBy; diff --git a/core/src/main/java/org/jclouds/encryption/internal/BaseEncryptionService.java b/core/src/main/java/org/jclouds/encryption/internal/BaseEncryptionService.java index 3148ebc390..61ecc30e6f 100755 --- a/core/src/main/java/org/jclouds/encryption/internal/BaseEncryptionService.java +++ b/core/src/main/java/org/jclouds/encryption/internal/BaseEncryptionService.java @@ -26,8 +26,8 @@ import java.io.UnsupportedEncodingException; import javax.annotation.Resource; import org.jclouds.encryption.EncryptionService; -import org.jclouds.http.Payload; import org.jclouds.http.PayloadEnclosing; +import org.jclouds.io.Payload; import org.jclouds.logging.Logger; /** diff --git a/core/src/main/java/org/jclouds/encryption/internal/JCEEncryptionService.java b/core/src/main/java/org/jclouds/encryption/internal/JCEEncryptionService.java index 5d36a0cf7d..a21f450e54 100644 --- a/core/src/main/java/org/jclouds/encryption/internal/JCEEncryptionService.java +++ b/core/src/main/java/org/jclouds/encryption/internal/JCEEncryptionService.java @@ -35,7 +35,7 @@ import javax.crypto.Cipher; import javax.crypto.Mac; import javax.crypto.spec.SecretKeySpec; -import org.jclouds.http.payloads.ByteArrayPayload; +import org.jclouds.io.payloads.ByteArrayPayload; /** * diff --git a/core/src/main/java/org/jclouds/http/HttpMessage.java b/core/src/main/java/org/jclouds/http/HttpMessage.java index c581251ea9..035206d935 100644 --- a/core/src/main/java/org/jclouds/http/HttpMessage.java +++ b/core/src/main/java/org/jclouds/http/HttpMessage.java @@ -23,6 +23,7 @@ import java.util.Collection; import javax.annotation.Nullable; import org.jclouds.http.internal.PayloadEnclosingImpl; +import org.jclouds.io.Payload; import com.google.common.collect.LinkedHashMultimap; import com.google.common.collect.Multimap; diff --git a/core/src/main/java/org/jclouds/http/HttpRequest.java b/core/src/main/java/org/jclouds/http/HttpRequest.java index 5527ee84f0..b6dfe8d7a7 100644 --- a/core/src/main/java/org/jclouds/http/HttpRequest.java +++ b/core/src/main/java/org/jclouds/http/HttpRequest.java @@ -28,6 +28,8 @@ import java.util.List; import javax.annotation.Nullable; +import org.jclouds.io.Payload; + import com.google.common.collect.Multimap; /** diff --git a/core/src/main/java/org/jclouds/http/HttpResponse.java b/core/src/main/java/org/jclouds/http/HttpResponse.java index 029c1e2e49..1f623fa641 100644 --- a/core/src/main/java/org/jclouds/http/HttpResponse.java +++ b/core/src/main/java/org/jclouds/http/HttpResponse.java @@ -20,6 +20,8 @@ package org.jclouds.http; import javax.annotation.Nullable; +import org.jclouds.io.Payload; + /** * Represents a response produced from {@link HttpCommandExecutorService} * diff --git a/core/src/main/java/org/jclouds/http/HttpUtils.java b/core/src/main/java/org/jclouds/http/HttpUtils.java index 87da781ebe..cf9dc62f5c 100644 --- a/core/src/main/java/org/jclouds/http/HttpUtils.java +++ b/core/src/main/java/org/jclouds/http/HttpUtils.java @@ -30,7 +30,7 @@ import static java.util.Collections.singletonList; import static javax.ws.rs.core.HttpHeaders.CONTENT_LENGTH; import static javax.ws.rs.core.HttpHeaders.CONTENT_TYPE; import static javax.ws.rs.core.HttpHeaders.HOST; -import static org.jclouds.http.Payloads.newUrlEncodedFormPayload; +import static org.jclouds.io.Payloads.newUrlEncodedFormPayload; import static org.jclouds.util.Patterns.CHAR_TO_ENCODED_PATTERN; import static org.jclouds.util.Patterns.PATTERN_THAT_BREAKS_URI; import static org.jclouds.util.Patterns.PLUS_PATTERN; @@ -64,6 +64,8 @@ import javax.ws.rs.core.UriBuilder; import org.jclouds.Constants; import org.jclouds.encryption.EncryptionService; +import org.jclouds.io.Payload; +import org.jclouds.io.Payloads; import org.jclouds.logging.Logger; import com.google.common.base.Joiner; diff --git a/core/src/main/java/org/jclouds/http/PayloadEnclosing.java b/core/src/main/java/org/jclouds/http/PayloadEnclosing.java index 2faf579a84..3cd4edfa72 100644 --- a/core/src/main/java/org/jclouds/http/PayloadEnclosing.java +++ b/core/src/main/java/org/jclouds/http/PayloadEnclosing.java @@ -21,6 +21,8 @@ package org.jclouds.http; import java.io.File; import java.io.InputStream; +import org.jclouds.io.Payload; + /** * * @author Adrian Cole diff --git a/core/src/main/java/org/jclouds/http/internal/JavaUrlHttpCommandExecutorService.java b/core/src/main/java/org/jclouds/http/internal/JavaUrlHttpCommandExecutorService.java index 6b8a99afe7..067409fa44 100644 --- a/core/src/main/java/org/jclouds/http/internal/JavaUrlHttpCommandExecutorService.java +++ b/core/src/main/java/org/jclouds/http/internal/JavaUrlHttpCommandExecutorService.java @@ -53,10 +53,10 @@ import org.jclouds.http.HttpRequest; import org.jclouds.http.HttpResponse; import org.jclouds.http.HttpUtils; import org.jclouds.http.IOExceptionRetryHandler; -import org.jclouds.http.Payload; -import org.jclouds.http.Payloads; import org.jclouds.http.handlers.DelegatingErrorHandler; import org.jclouds.http.handlers.DelegatingRetryHandler; +import org.jclouds.io.Payload; +import org.jclouds.io.Payloads; import org.jclouds.logging.Logger; import com.google.common.collect.LinkedHashMultimap; diff --git a/core/src/main/java/org/jclouds/http/internal/PayloadEnclosingImpl.java b/core/src/main/java/org/jclouds/http/internal/PayloadEnclosingImpl.java index 5bfbe4268b..76936bbadb 100644 --- a/core/src/main/java/org/jclouds/http/internal/PayloadEnclosingImpl.java +++ b/core/src/main/java/org/jclouds/http/internal/PayloadEnclosingImpl.java @@ -19,15 +19,15 @@ package org.jclouds.http.internal; import static com.google.common.base.Preconditions.checkNotNull; -import static org.jclouds.http.Payloads.newPayload; +import static org.jclouds.io.Payloads.newPayload; import java.io.File; import java.io.InputStream; import javax.annotation.Nullable; -import org.jclouds.http.Payload; import org.jclouds.http.PayloadEnclosing; +import org.jclouds.io.Payload; /** * diff --git a/core/src/main/java/org/jclouds/http/Payload.java b/core/src/main/java/org/jclouds/io/Payload.java similarity index 98% rename from core/src/main/java/org/jclouds/http/Payload.java rename to core/src/main/java/org/jclouds/io/Payload.java index d7014109f4..401830cb12 100644 --- a/core/src/main/java/org/jclouds/http/Payload.java +++ b/core/src/main/java/org/jclouds/io/Payload.java @@ -16,7 +16,7 @@ * limitations under the License. * ==================================================================== */ -package org.jclouds.http; +package org.jclouds.io; import java.io.Closeable; import java.io.IOException; diff --git a/core/src/main/java/org/jclouds/http/Payloads.java b/core/src/main/java/org/jclouds/io/Payloads.java similarity index 90% rename from core/src/main/java/org/jclouds/http/Payloads.java rename to core/src/main/java/org/jclouds/io/Payloads.java index e3f9544a7f..3ad6721517 100644 --- a/core/src/main/java/org/jclouds/http/Payloads.java +++ b/core/src/main/java/org/jclouds/io/Payloads.java @@ -16,7 +16,7 @@ * limitations under the License. * ==================================================================== */ -package org.jclouds.http; +package org.jclouds.io; import static com.google.common.base.Preconditions.checkNotNull; @@ -27,11 +27,11 @@ import java.util.Map; import javax.annotation.Nullable; -import org.jclouds.http.payloads.ByteArrayPayload; -import org.jclouds.http.payloads.FilePayload; -import org.jclouds.http.payloads.InputStreamPayload; -import org.jclouds.http.payloads.StringPayload; -import org.jclouds.http.payloads.UrlEncodedFormPayload; +import org.jclouds.io.payloads.ByteArrayPayload; +import org.jclouds.io.payloads.FilePayload; +import org.jclouds.io.payloads.InputStreamPayload; +import org.jclouds.io.payloads.StringPayload; +import org.jclouds.io.payloads.UrlEncodedFormPayload; import com.google.common.collect.Multimap; diff --git a/core/src/main/java/org/jclouds/http/payloads/BasePayload.java b/core/src/main/java/org/jclouds/io/payloads/BasePayload.java similarity index 98% rename from core/src/main/java/org/jclouds/http/payloads/BasePayload.java rename to core/src/main/java/org/jclouds/io/payloads/BasePayload.java index ca1c07a071..25b57ce90b 100644 --- a/core/src/main/java/org/jclouds/http/payloads/BasePayload.java +++ b/core/src/main/java/org/jclouds/io/payloads/BasePayload.java @@ -16,7 +16,7 @@ * limitations under the License. * ==================================================================== */ -package org.jclouds.http.payloads; +package org.jclouds.io.payloads; import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Preconditions.checkState; @@ -29,7 +29,7 @@ import java.io.OutputStream; import javax.annotation.Nullable; -import org.jclouds.http.Payload; +import org.jclouds.io.Payload; /** * @author Adrian Cole diff --git a/core/src/main/java/org/jclouds/http/payloads/ByteArrayPayload.java b/core/src/main/java/org/jclouds/io/payloads/ByteArrayPayload.java similarity index 97% rename from core/src/main/java/org/jclouds/http/payloads/ByteArrayPayload.java rename to core/src/main/java/org/jclouds/io/payloads/ByteArrayPayload.java index fd32602f18..b5375b2f9c 100644 --- a/core/src/main/java/org/jclouds/http/payloads/ByteArrayPayload.java +++ b/core/src/main/java/org/jclouds/io/payloads/ByteArrayPayload.java @@ -16,7 +16,7 @@ * limitations under the License. * ==================================================================== */ -package org.jclouds.http.payloads; +package org.jclouds.io.payloads; import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkNotNull; diff --git a/core/src/main/java/org/jclouds/http/payloads/DelegatingPayload.java b/core/src/main/java/org/jclouds/io/payloads/DelegatingPayload.java similarity index 97% rename from core/src/main/java/org/jclouds/http/payloads/DelegatingPayload.java rename to core/src/main/java/org/jclouds/io/payloads/DelegatingPayload.java index 4d1c9e698e..6933b7075f 100644 --- a/core/src/main/java/org/jclouds/http/payloads/DelegatingPayload.java +++ b/core/src/main/java/org/jclouds/io/payloads/DelegatingPayload.java @@ -16,7 +16,7 @@ * limitations under the License. * ==================================================================== */ -package org.jclouds.http.payloads; +package org.jclouds.io.payloads; import static com.google.common.base.Preconditions.checkNotNull; @@ -24,7 +24,7 @@ import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; -import org.jclouds.http.Payload; +import org.jclouds.io.Payload; /** * diff --git a/core/src/main/java/org/jclouds/http/payloads/FilePayload.java b/core/src/main/java/org/jclouds/io/payloads/FilePayload.java similarity index 97% rename from core/src/main/java/org/jclouds/http/payloads/FilePayload.java rename to core/src/main/java/org/jclouds/io/payloads/FilePayload.java index a8c42792dc..ff506b919f 100644 --- a/core/src/main/java/org/jclouds/http/payloads/FilePayload.java +++ b/core/src/main/java/org/jclouds/io/payloads/FilePayload.java @@ -16,7 +16,7 @@ * limitations under the License. * ==================================================================== */ -package org.jclouds.http.payloads; +package org.jclouds.io.payloads; import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkNotNull; diff --git a/core/src/main/java/org/jclouds/http/payloads/InputStreamPayload.java b/core/src/main/java/org/jclouds/io/payloads/InputStreamPayload.java similarity index 97% rename from core/src/main/java/org/jclouds/http/payloads/InputStreamPayload.java rename to core/src/main/java/org/jclouds/io/payloads/InputStreamPayload.java index cd4940f0ba..6b73d69971 100644 --- a/core/src/main/java/org/jclouds/http/payloads/InputStreamPayload.java +++ b/core/src/main/java/org/jclouds/io/payloads/InputStreamPayload.java @@ -16,7 +16,7 @@ * limitations under the License. * ==================================================================== */ -package org.jclouds.http.payloads; +package org.jclouds.io.payloads; import static com.google.common.io.Closeables.closeQuietly; diff --git a/core/src/main/java/org/jclouds/http/payloads/MultipartForm.java b/core/src/main/java/org/jclouds/io/payloads/MultipartForm.java similarity index 99% rename from core/src/main/java/org/jclouds/http/payloads/MultipartForm.java rename to core/src/main/java/org/jclouds/io/payloads/MultipartForm.java index 03fd7a955b..08097f4645 100644 --- a/core/src/main/java/org/jclouds/http/payloads/MultipartForm.java +++ b/core/src/main/java/org/jclouds/io/payloads/MultipartForm.java @@ -16,7 +16,7 @@ * limitations under the License. * ==================================================================== */ -package org.jclouds.http.payloads; +package org.jclouds.io.payloads; import static com.google.common.base.Throwables.propagate; import static com.google.common.collect.Lists.newArrayList; diff --git a/core/src/main/java/org/jclouds/http/payloads/Part.java b/core/src/main/java/org/jclouds/io/payloads/Part.java similarity index 97% rename from core/src/main/java/org/jclouds/http/payloads/Part.java rename to core/src/main/java/org/jclouds/io/payloads/Part.java index da3aefb91f..002d6b8f2a 100644 --- a/core/src/main/java/org/jclouds/http/payloads/Part.java +++ b/core/src/main/java/org/jclouds/io/payloads/Part.java @@ -16,7 +16,7 @@ * limitations under the License. * ==================================================================== */ -package org.jclouds.http.payloads; +package org.jclouds.io.payloads; import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.collect.Multimaps.forMap; @@ -26,8 +26,8 @@ import java.util.LinkedHashMap; import javax.annotation.Nullable; import javax.ws.rs.core.HttpHeaders; -import org.jclouds.http.Payload; -import org.jclouds.http.Payloads; +import org.jclouds.io.Payload; +import org.jclouds.io.Payloads; import com.google.common.collect.ImmutableMultimap; import com.google.common.collect.Multimap; diff --git a/core/src/main/java/org/jclouds/http/payloads/StringPayload.java b/core/src/main/java/org/jclouds/io/payloads/StringPayload.java similarity index 97% rename from core/src/main/java/org/jclouds/http/payloads/StringPayload.java rename to core/src/main/java/org/jclouds/io/payloads/StringPayload.java index ac114a693c..139e7eed5f 100644 --- a/core/src/main/java/org/jclouds/http/payloads/StringPayload.java +++ b/core/src/main/java/org/jclouds/io/payloads/StringPayload.java @@ -16,7 +16,7 @@ * limitations under the License. * ==================================================================== */ -package org.jclouds.http.payloads; +package org.jclouds.io.payloads; import java.io.InputStream; diff --git a/core/src/main/java/org/jclouds/http/payloads/UrlEncodedFormPayload.java b/core/src/main/java/org/jclouds/io/payloads/UrlEncodedFormPayload.java similarity index 98% rename from core/src/main/java/org/jclouds/http/payloads/UrlEncodedFormPayload.java rename to core/src/main/java/org/jclouds/io/payloads/UrlEncodedFormPayload.java index 78b3ba9d47..ac7e16f02f 100644 --- a/core/src/main/java/org/jclouds/http/payloads/UrlEncodedFormPayload.java +++ b/core/src/main/java/org/jclouds/io/payloads/UrlEncodedFormPayload.java @@ -16,7 +16,7 @@ * limitations under the License. * ==================================================================== */ -package org.jclouds.http.payloads; +package org.jclouds.io.payloads; import static org.jclouds.http.HttpUtils.makeQueryLine; diff --git a/core/src/main/java/org/jclouds/logging/internal/Wire.java b/core/src/main/java/org/jclouds/logging/internal/Wire.java index a39444717e..3cf622f0a3 100644 --- a/core/src/main/java/org/jclouds/logging/internal/Wire.java +++ b/core/src/main/java/org/jclouds/logging/internal/Wire.java @@ -29,9 +29,9 @@ import java.io.InputStream; import javax.annotation.Resource; -import org.jclouds.http.Payload; import org.jclouds.http.PayloadEnclosing; -import org.jclouds.http.Payloads; +import org.jclouds.io.Payload; +import org.jclouds.io.Payloads; import org.jclouds.logging.Logger; import com.google.common.io.ByteStreams; diff --git a/core/src/main/java/org/jclouds/rest/HttpAsyncClient.java b/core/src/main/java/org/jclouds/rest/HttpAsyncClient.java index ee18e9c09d..1b352d245a 100644 --- a/core/src/main/java/org/jclouds/rest/HttpAsyncClient.java +++ b/core/src/main/java/org/jclouds/rest/HttpAsyncClient.java @@ -9,9 +9,9 @@ import javax.ws.rs.HEAD; import javax.ws.rs.POST; import javax.ws.rs.PUT; -import org.jclouds.http.Payload; import org.jclouds.http.functions.ParseETagHeader; import org.jclouds.http.options.HttpRequestOptions; +import org.jclouds.io.Payload; import org.jclouds.rest.annotations.EndpointParam; import org.jclouds.rest.annotations.ExceptionParser; import org.jclouds.rest.annotations.ResponseParser; diff --git a/core/src/main/java/org/jclouds/rest/HttpClient.java b/core/src/main/java/org/jclouds/rest/HttpClient.java index e26cbe22a6..075306ae49 100644 --- a/core/src/main/java/org/jclouds/rest/HttpClient.java +++ b/core/src/main/java/org/jclouds/rest/HttpClient.java @@ -23,8 +23,8 @@ import java.net.URI; import java.util.concurrent.TimeUnit; import org.jclouds.concurrent.Timeout; -import org.jclouds.http.Payload; import org.jclouds.http.options.HttpRequestOptions; +import org.jclouds.io.Payload; /** * Simple client diff --git a/core/src/main/java/org/jclouds/rest/internal/RestAnnotationProcessor.java b/core/src/main/java/org/jclouds/rest/internal/RestAnnotationProcessor.java index c64aec1792..472d5def51 100755 --- a/core/src/main/java/org/jclouds/rest/internal/RestAnnotationProcessor.java +++ b/core/src/main/java/org/jclouds/rest/internal/RestAnnotationProcessor.java @@ -34,7 +34,7 @@ import static javax.ws.rs.core.HttpHeaders.HOST; import static org.jclouds.http.HttpUtils.makeQueryLine; import static org.jclouds.http.HttpUtils.parseQueryToMap; import static org.jclouds.http.HttpUtils.urlEncode; -import static org.jclouds.http.Payloads.newPayload; +import static org.jclouds.io.Payloads.newPayload; import static org.jclouds.util.Utils.replaceTokens; import java.io.InputStream; @@ -75,9 +75,7 @@ import org.jclouds.http.HttpRequest; import org.jclouds.http.HttpRequestFilter; import org.jclouds.http.HttpResponse; import org.jclouds.http.HttpUtils; -import org.jclouds.http.Payload; import org.jclouds.http.PayloadEnclosing; -import org.jclouds.http.Payloads; import org.jclouds.http.functions.ParseJson; import org.jclouds.http.functions.ParseSax; import org.jclouds.http.functions.ParseURIFromListOrLocationHeaderIf20x; @@ -88,10 +86,12 @@ import org.jclouds.http.functions.ReturnTrueIf2xx; import org.jclouds.http.functions.UnwrapOnlyJsonValue; import org.jclouds.http.functions.ParseSax.HandlerWithResult; import org.jclouds.http.options.HttpRequestOptions; -import org.jclouds.http.payloads.MultipartForm; -import org.jclouds.http.payloads.Part; -import org.jclouds.http.payloads.Part.PartOptions; import org.jclouds.internal.ClassMethodArgs; +import org.jclouds.io.Payload; +import org.jclouds.io.Payloads; +import org.jclouds.io.payloads.MultipartForm; +import org.jclouds.io.payloads.Part; +import org.jclouds.io.payloads.Part.PartOptions; import org.jclouds.logging.Logger; import org.jclouds.rest.Binder; import org.jclouds.rest.InputParamValidator; diff --git a/core/src/test/java/org/jclouds/http/BaseHttpErrorHandlerTest.java b/core/src/test/java/org/jclouds/http/BaseHttpErrorHandlerTest.java index c635daf3e0..c8539fa65f 100644 --- a/core/src/test/java/org/jclouds/http/BaseHttpErrorHandlerTest.java +++ b/core/src/test/java/org/jclouds/http/BaseHttpErrorHandlerTest.java @@ -28,6 +28,7 @@ import java.net.URI; import org.easymock.IArgumentMatcher; import org.jclouds.http.functions.config.ParserModule; +import org.jclouds.io.Payloads; import com.google.inject.Guice; diff --git a/core/src/test/java/org/jclouds/http/functions/ParseURIFromListOrLocationHeaderIf20xTest.java b/core/src/test/java/org/jclouds/http/functions/ParseURIFromListOrLocationHeaderIf20xTest.java index 42691ddfb5..5d595d2a7c 100644 --- a/core/src/test/java/org/jclouds/http/functions/ParseURIFromListOrLocationHeaderIf20xTest.java +++ b/core/src/test/java/org/jclouds/http/functions/ParseURIFromListOrLocationHeaderIf20xTest.java @@ -34,7 +34,7 @@ import javax.ws.rs.core.UriBuilder; import org.jboss.resteasy.specimpl.UriBuilderImpl; import org.jclouds.http.HttpResponse; -import org.jclouds.http.Payload; +import org.jclouds.io.Payload; import org.jclouds.rest.internal.GeneratedHttpRequest; import org.jclouds.util.Utils; import org.mortbay.jetty.HttpHeaders; diff --git a/core/src/test/java/org/jclouds/http/functions/ReturnStringIf200Test.java b/core/src/test/java/org/jclouds/http/functions/ReturnStringIf200Test.java index 4ba749b083..0f2c479857 100644 --- a/core/src/test/java/org/jclouds/http/functions/ReturnStringIf200Test.java +++ b/core/src/test/java/org/jclouds/http/functions/ReturnStringIf200Test.java @@ -29,7 +29,7 @@ import java.util.concurrent.ExecutionException; import java.util.concurrent.TimeoutException; import org.jclouds.http.HttpResponse; -import org.jclouds.http.Payload; +import org.jclouds.io.Payload; import org.jclouds.util.Utils; import org.testng.annotations.Test; diff --git a/core/src/test/java/org/jclouds/http/handlers/BackoffLimitedRetryHandlerTest.java b/core/src/test/java/org/jclouds/http/handlers/BackoffLimitedRetryHandlerTest.java index d95715b2ae..dcd49456fc 100644 --- a/core/src/test/java/org/jclouds/http/handlers/BackoffLimitedRetryHandlerTest.java +++ b/core/src/test/java/org/jclouds/http/handlers/BackoffLimitedRetryHandlerTest.java @@ -39,12 +39,12 @@ import org.jclouds.http.HttpCommand; import org.jclouds.http.HttpResponse; import org.jclouds.http.HttpUtils; import org.jclouds.http.IntegrationTestAsyncClient; -import org.jclouds.http.Payloads; import org.jclouds.http.TransformingHttpCommandExecutorServiceImpl; import org.jclouds.http.TransformingHttpCommandImpl; import org.jclouds.http.functions.ReturnStringIf2xx; import org.jclouds.http.internal.HttpWire; import org.jclouds.http.internal.JavaUrlHttpCommandExecutorService; +import org.jclouds.io.Payloads; import org.jclouds.rest.internal.RestAnnotationProcessor; import org.testng.annotations.BeforeTest; import org.testng.annotations.Test; diff --git a/core/src/test/java/org/jclouds/http/MultipartFormTest.java b/core/src/test/java/org/jclouds/io/payloads/MultipartFormTest.java similarity index 93% rename from core/src/test/java/org/jclouds/http/MultipartFormTest.java rename to core/src/test/java/org/jclouds/io/payloads/MultipartFormTest.java index 8dafbce000..fa6fea81c8 100644 --- a/core/src/test/java/org/jclouds/http/MultipartFormTest.java +++ b/core/src/test/java/org/jclouds/io/payloads/MultipartFormTest.java @@ -16,7 +16,7 @@ * limitations under the License. * ==================================================================== */ -package org.jclouds.http; +package org.jclouds.io.payloads; import static org.easymock.EasyMock.expect; import static org.easymock.classextension.EasyMock.createMock; @@ -30,11 +30,12 @@ import java.io.OutputStream; import javax.ws.rs.core.MediaType; -import org.jclouds.http.payloads.FilePayload; -import org.jclouds.http.payloads.MultipartForm; -import org.jclouds.http.payloads.Part; -import org.jclouds.http.payloads.StringPayload; -import org.jclouds.http.payloads.Part.PartOptions; +import org.jclouds.io.Payloads; +import org.jclouds.io.payloads.FilePayload; +import org.jclouds.io.payloads.MultipartForm; +import org.jclouds.io.payloads.Part; +import org.jclouds.io.payloads.StringPayload; +import org.jclouds.io.payloads.Part.PartOptions; import org.jclouds.util.Utils; import org.testng.annotations.Test; diff --git a/core/src/test/java/org/jclouds/rest/internal/RestAnnotationProcessorTest.java b/core/src/test/java/org/jclouds/rest/internal/RestAnnotationProcessorTest.java index fd93611b7a..9304fe060b 100755 --- a/core/src/test/java/org/jclouds/rest/internal/RestAnnotationProcessorTest.java +++ b/core/src/test/java/org/jclouds/rest/internal/RestAnnotationProcessorTest.java @@ -26,8 +26,8 @@ import static org.easymock.EasyMock.expect; import static org.easymock.EasyMock.reportMatcher; import static org.easymock.classextension.EasyMock.replay; import static org.easymock.classextension.EasyMock.verify; -import static org.jclouds.http.Payloads.newInputStreamPayload; -import static org.jclouds.http.Payloads.newStringPayload; +import static org.jclouds.io.Payloads.newInputStreamPayload; +import static org.jclouds.io.Payloads.newStringPayload; import static org.jclouds.rest.RestContextFactory.contextSpec; import static org.jclouds.rest.RestContextFactory.createContextBuilder; import static org.jclouds.util.Utils.toInputStream; @@ -84,9 +84,7 @@ import org.jclouds.http.HttpRequest; import org.jclouds.http.HttpRequestFilter; import org.jclouds.http.HttpResponse; import org.jclouds.http.IOExceptionRetryHandler; -import org.jclouds.http.Payload; import org.jclouds.http.PayloadEnclosing; -import org.jclouds.http.Payloads; import org.jclouds.http.RequiresHttp; import org.jclouds.http.TransformingHttpCommandExecutorService; import org.jclouds.http.functions.ParseJson; @@ -101,6 +99,8 @@ import org.jclouds.http.internal.PayloadEnclosingImpl; import org.jclouds.http.options.BaseHttpRequestOptions; import org.jclouds.http.options.GetOptions; import org.jclouds.http.options.HttpRequestOptions; +import org.jclouds.io.Payload; +import org.jclouds.io.Payloads; import org.jclouds.logging.config.NullLoggingModule; import org.jclouds.rest.AsyncClientFactory; import org.jclouds.rest.BaseRestClientTest; diff --git a/extensions/apachehc/src/main/java/org/jclouds/http/apachehc/ApacheHCHttpCommandExecutorService.java b/extensions/apachehc/src/main/java/org/jclouds/http/apachehc/ApacheHCHttpCommandExecutorService.java index a2031560be..ae8aea3a7f 100644 --- a/extensions/apachehc/src/main/java/org/jclouds/http/apachehc/ApacheHCHttpCommandExecutorService.java +++ b/extensions/apachehc/src/main/java/org/jclouds/http/apachehc/ApacheHCHttpCommandExecutorService.java @@ -36,12 +36,12 @@ import org.jclouds.http.HttpRequest; import org.jclouds.http.HttpResponse; import org.jclouds.http.HttpUtils; import org.jclouds.http.IOExceptionRetryHandler; -import org.jclouds.http.Payload; -import org.jclouds.http.Payloads; import org.jclouds.http.handlers.DelegatingErrorHandler; import org.jclouds.http.handlers.DelegatingRetryHandler; import org.jclouds.http.internal.BaseHttpCommandExecutorService; import org.jclouds.http.internal.HttpWire; +import org.jclouds.io.Payload; +import org.jclouds.io.Payloads; import com.google.common.collect.LinkedHashMultimap; import com.google.common.collect.Multimap; diff --git a/extensions/apachehc/src/main/java/org/jclouds/http/apachehc/ApacheHCUtils.java b/extensions/apachehc/src/main/java/org/jclouds/http/apachehc/ApacheHCUtils.java index c29ea1589e..44b35f4a04 100644 --- a/extensions/apachehc/src/main/java/org/jclouds/http/apachehc/ApacheHCUtils.java +++ b/extensions/apachehc/src/main/java/org/jclouds/http/apachehc/ApacheHCUtils.java @@ -41,12 +41,12 @@ import org.apache.http.entity.FileEntity; import org.apache.http.entity.InputStreamEntity; import org.apache.http.entity.StringEntity; import org.jclouds.http.HttpRequest; -import org.jclouds.http.Payload; -import org.jclouds.http.payloads.BasePayload; -import org.jclouds.http.payloads.ByteArrayPayload; -import org.jclouds.http.payloads.DelegatingPayload; -import org.jclouds.http.payloads.FilePayload; -import org.jclouds.http.payloads.StringPayload; +import org.jclouds.io.Payload; +import org.jclouds.io.payloads.BasePayload; +import org.jclouds.io.payloads.ByteArrayPayload; +import org.jclouds.io.payloads.DelegatingPayload; +import org.jclouds.io.payloads.FilePayload; +import org.jclouds.io.payloads.StringPayload; import com.google.common.base.Throwables; diff --git a/extensions/bouncycastle/src/main/java/org/jclouds/encryption/bouncycastle/BouncyCastleEncryptionService.java b/extensions/bouncycastle/src/main/java/org/jclouds/encryption/bouncycastle/BouncyCastleEncryptionService.java index 18000a1c06..c683ff808c 100644 --- a/extensions/bouncycastle/src/main/java/org/jclouds/encryption/bouncycastle/BouncyCastleEncryptionService.java +++ b/extensions/bouncycastle/src/main/java/org/jclouds/encryption/bouncycastle/BouncyCastleEncryptionService.java @@ -40,7 +40,7 @@ import org.bouncycastle.crypto.macs.HMac; import org.bouncycastle.crypto.params.KeyParameter; import org.bouncycastle.util.encoders.Base64; import org.jclouds.encryption.internal.BaseEncryptionService; -import org.jclouds.http.payloads.ByteArrayPayload; +import org.jclouds.io.payloads.ByteArrayPayload; /** * diff --git a/extensions/gae/src/main/java/org/jclouds/gae/ConvertToJcloudsResponse.java b/extensions/gae/src/main/java/org/jclouds/gae/ConvertToJcloudsResponse.java index dbe1ad4ad4..e4859f9674 100644 --- a/extensions/gae/src/main/java/org/jclouds/gae/ConvertToJcloudsResponse.java +++ b/extensions/gae/src/main/java/org/jclouds/gae/ConvertToJcloudsResponse.java @@ -23,8 +23,8 @@ import javax.inject.Singleton; import org.jclouds.http.HttpResponse; import org.jclouds.http.HttpUtils; -import org.jclouds.http.Payload; -import org.jclouds.http.Payloads; +import org.jclouds.io.Payload; +import org.jclouds.io.Payloads; import com.google.appengine.api.urlfetch.HTTPHeader; import com.google.appengine.api.urlfetch.HTTPResponse; diff --git a/extensions/gae/src/test/java/org/jclouds/gae/ConvertToGaeRequestTest.java b/extensions/gae/src/test/java/org/jclouds/gae/ConvertToGaeRequestTest.java index b52caca499..a2aae241ad 100644 --- a/extensions/gae/src/test/java/org/jclouds/gae/ConvertToGaeRequestTest.java +++ b/extensions/gae/src/test/java/org/jclouds/gae/ConvertToGaeRequestTest.java @@ -31,7 +31,7 @@ import javax.ws.rs.core.HttpHeaders; import org.jclouds.encryption.internal.JCEEncryptionService; import org.jclouds.http.HttpRequest; -import org.jclouds.http.Payloads; +import org.jclouds.io.Payloads; import org.jclouds.util.Utils; import org.testng.annotations.BeforeTest; import org.testng.annotations.Parameters; diff --git a/extensions/ssh/jsch/src/main/java/org/jclouds/ssh/jsch/JschSshClient.java b/extensions/ssh/jsch/src/main/java/org/jclouds/ssh/jsch/JschSshClient.java index 9122d26f80..8eee5285c1 100644 --- a/extensions/ssh/jsch/src/main/java/org/jclouds/ssh/jsch/JschSshClient.java +++ b/extensions/ssh/jsch/src/main/java/org/jclouds/ssh/jsch/JschSshClient.java @@ -40,6 +40,8 @@ import javax.inject.Named; import org.apache.commons.io.input.ProxyInputStream; import org.apache.commons.io.output.ByteArrayOutputStream; import org.jclouds.http.handlers.BackoffLimitedRetryHandler; +import org.jclouds.io.Payload; +import org.jclouds.io.Payloads; import org.jclouds.logging.Logger; import org.jclouds.net.IPSocket; import org.jclouds.ssh.ExecResponse; @@ -101,8 +103,7 @@ public class JschSshClient implements SshClient { @Inject(optional = true) @Named("jclouds.ssh.retry_predicate") - private Predicate retryPredicate = or(instanceOf(ConnectException.class), - instanceOf(IOException.class)); + private Predicate retryPredicate = or(instanceOf(ConnectException.class), instanceOf(IOException.class)); @Resource protected Logger logger = Logger.NULL; private Session session; @@ -111,21 +112,20 @@ public class JschSshClient implements SshClient { private final int timeout; private final BackoffLimitedRetryHandler backoffLimitedRetryHandler; - public JschSshClient(BackoffLimitedRetryHandler backoffLimitedRetryHandler, IPSocket socket, - int timeout, String username, String password, byte[] privateKey) { + public JschSshClient(BackoffLimitedRetryHandler backoffLimitedRetryHandler, IPSocket socket, int timeout, + String username, String password, byte[] privateKey) { this.host = checkNotNull(socket, "socket").getAddress(); checkArgument(socket.getPort() > 0, "ssh port must be greater then zero" + socket.getPort()); checkArgument(password != null || privateKey != null, "you must specify a password or a key"); this.port = socket.getPort(); this.username = checkNotNull(username, "username"); - this.backoffLimitedRetryHandler = checkNotNull(backoffLimitedRetryHandler, - "backoffLimitedRetryHandler"); + this.backoffLimitedRetryHandler = checkNotNull(backoffLimitedRetryHandler, "backoffLimitedRetryHandler"); this.timeout = timeout; this.password = password; this.privateKey = privateKey; } - public InputStream get(String path) { + public Payload get(String path) { checkNotNull(path, "path"); checkConnected(); @@ -135,18 +135,16 @@ public class JschSshClient implements SshClient { sftp = (ChannelSftp) session.openChannel("sftp"); sftp.connect(); } catch (JSchException e) { - throw new SshException(String.format("%s@%s:%d: Error connecting to sftp.", username, - host, port), e); + throw new SshException(String.format("%s@%s:%d: Error connecting to sftp.", username, host, port), e); } try { - return new CloseFtpChannelOnCloseInputStream(sftp.get(path), sftp); + return Payloads.newInputStreamPayload(new CloseFtpChannelOnCloseInputStream(sftp.get(path), sftp)); } catch (SftpException e) { - throw new SshException(String.format("%s@%s:%d: Error getting path: %s", username, host, - port, path), e); + throw new SshException(String.format("%s@%s:%d: Error getting path: %s", username, host, port, path), e); } } - public void put(String path, InputStream contents) { + public void put(String path, Payload contents) { checkNotNull(path, "path"); checkNotNull(contents, "contents"); @@ -157,22 +155,20 @@ public class JschSshClient implements SshClient { sftp = (ChannelSftp) session.openChannel("sftp"); sftp.connect(); } catch (JSchException e) { - throw new SshException(String.format("%s@%s:%d: Error connecting to sftp.", username, - host, port), e); + throw new SshException(String.format("%s@%s:%d: Error connecting to sftp.", username, host, port), e); } try { - sftp.put(contents, path); + sftp.put(contents.getInput(), path); } catch (SftpException e) { - throw new SshException(String.format("%s@%s:%d: Error putting path: %s", username, host, - port, path), e); + throw new SshException(String.format("%s@%s:%d: Error putting path: %s", username, host, port, path), e); } finally { Closeables.closeQuietly(contents); } } private void checkConnected() { - checkState(session != null && session.isConnected(), String.format( - "%s@%s:%d: SFTP not connected!", username, host, port)); + checkState(session != null && session.isConnected(), String.format("%s@%s:%d: SFTP not connected!", username, + host, port)); } @PostConstruct @@ -207,19 +203,19 @@ public class JschSshClient implements SshClient { boolean shouldRetry(Exception from) { final String rootMessage = getRootCause(from).getMessage(); return any(getCausalChain(from), retryPredicate) - || Iterables.any(Splitter.on(",").split(retryableMessages), new Predicate() { + || Iterables.any(Splitter.on(",").split(retryableMessages), new Predicate() { - @Override - public boolean apply(String input) { - return rootMessage.indexOf(input) != -1; - } + @Override + public boolean apply(String input) { + return rootMessage.indexOf(input) != -1; + } - }); + }); } private void backoffForAttempt(int retryAttempt, String rootMessage) { - backoffLimitedRetryHandler.imposeBackoffExponentialDelay(200L, 2, retryAttempt, sshRetries, - String.format("%s@%s:%d: connection error: %s", username, host, port, rootMessage)); + backoffLimitedRetryHandler.imposeBackoffExponentialDelay(200L, 2, retryAttempt, sshRetries, String.format( + "%s@%s:%d: connection error: %s", username, host, port, rootMessage)); } private void newSession() throws JSchException { @@ -234,12 +230,10 @@ public class JschSshClient implements SshClient { session.setPassword(password); } else { // jsch wipes out your private key - jsch.addIdentity(username, Arrays.copyOf(privateKey, privateKey.length), null, - emptyPassPhrase); + jsch.addIdentity(username, Arrays.copyOf(privateKey, privateKey.length), null, emptyPassPhrase); } } catch (JSchException e) { - throw new SshException(String.format("%s@%s:%d: Error creating session.", username, host, - port), e); + throw new SshException(String.format("%s@%s:%d: Error creating session.", username, host, port), e); } java.util.Properties config = new java.util.Properties(); config.put("StrictHostKeyChecking", "no"); @@ -249,8 +243,7 @@ public class JschSshClient implements SshClient { } private SshException propagate(Exception e) { - throw new SshException(String.format("%s@%s:%d: Error connecting to session.", username, - host, port), e); + throw new SshException(String.format("%s@%s:%d: Error connecting to session.", username, host, port), e); } @PreDestroy @@ -268,19 +261,18 @@ public class JschSshClient implements SshClient { try { executor = (ChannelExec) session.openChannel("exec"); } catch (JSchException e) { - throw new SshException(String.format("%s@%s:%d: Error connecting to exec.", username, - host, port), e); + throw new SshException(String.format("%s@%s:%d: Error connecting to exec.", username, host, port), e); } executor.setCommand(command); ByteArrayOutputStream error = new ByteArrayOutputStream(); executor.setErrStream(error); try { executor.connect(); - return new ExecResponse(Utils.toStringAndClose(executor.getInputStream()), error - .toString(), executor.getExitStatus()); + return new ExecResponse(Utils.toStringAndClose(executor.getInputStream()), error.toString(), executor + .getExitStatus()); } catch (Exception e) { - throw new SshException(String.format("%s@%s:%d: Error executing command: %s", username, - host, port, command), e); + throw new SshException(String + .format("%s@%s:%d: Error executing command: %s", username, host, port, command), e); } } finally { if (executor != null) diff --git a/extensions/ssh/jsch/src/main/java/org/jclouds/ssh/jsch/config/JschSshClientModule.java b/extensions/ssh/jsch/src/main/java/org/jclouds/ssh/jsch/config/JschSshClientModule.java index 6d8b6507f4..f4bd0a3f44 100755 --- a/extensions/ssh/jsch/src/main/java/org/jclouds/ssh/jsch/config/JschSshClientModule.java +++ b/extensions/ssh/jsch/src/main/java/org/jclouds/ssh/jsch/config/JschSshClientModule.java @@ -18,9 +18,6 @@ */ package org.jclouds.ssh.jsch.config; -import java.io.ByteArrayOutputStream; -import java.util.Map; - import javax.inject.Named; import org.jclouds.Constants; @@ -32,15 +29,10 @@ import org.jclouds.ssh.SshClient; import org.jclouds.ssh.jsch.JschSshClient; import org.jclouds.ssh.jsch.predicates.InetSocketAddressConnect; -import com.google.common.base.Throwables; -import com.google.common.collect.ImmutableMap; import com.google.inject.AbstractModule; import com.google.inject.Inject; import com.google.inject.Injector; import com.google.inject.Scopes; -import com.jcraft.jsch.JSch; -import com.jcraft.jsch.JSchException; -import com.jcraft.jsch.KeyPair; /** * @@ -81,22 +73,5 @@ public class JschSshClientModule extends AbstractModule { return client; } - @Override - public Map generateRSAKeyPair(String comment, String passphrase) { - KeyPair pair = null; - try { - pair = KeyPair.genKeyPair(new JSch(), KeyPair.RSA); - } catch (JSchException e) { - Throwables.propagate(e); - } - if (passphrase != null) - pair.setPassphrase(passphrase); - ByteArrayOutputStream privateKey = new ByteArrayOutputStream(); - pair.writePrivateKey(privateKey); - ByteArrayOutputStream publicKey = new ByteArrayOutputStream(); - pair.writePublicKey(publicKey, comment); - return ImmutableMap.of("comment", comment, "passphrase", passphrase, "private", new String(privateKey - .toByteArray()), "public", new String(publicKey.toByteArray())); - } } } \ No newline at end of file diff --git a/extensions/ssh/jsch/src/test/java/org/jclouds/ssh/jsch/JschSshClientLiveTest.java b/extensions/ssh/jsch/src/test/java/org/jclouds/ssh/jsch/JschSshClientLiveTest.java index f843664177..051e4263a6 100644 --- a/extensions/ssh/jsch/src/test/java/org/jclouds/ssh/jsch/JschSshClientLiveTest.java +++ b/extensions/ssh/jsch/src/test/java/org/jclouds/ssh/jsch/JschSshClientLiveTest.java @@ -24,8 +24,9 @@ import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException; -import java.io.InputStream; +import org.jclouds.io.Payload; +import org.jclouds.io.Payloads; import org.jclouds.net.IPSocket; import org.jclouds.ssh.ExecResponse; import org.jclouds.ssh.SshClient; @@ -55,8 +56,8 @@ public class JschSshClientLiveTest { public SshClient setupClient() throws NumberFormatException, FileNotFoundException, IOException { int port = (sshPort != null) ? Integer.parseInt(sshPort) : 22; if (sshUser == null - || ((sshPass == null || sshPass.trim().equals("")) && (sshKeyFile == null || sshKeyFile - .trim().equals(""))) || sshUser.trim().equals("")) { + || ((sshPass == null || sshPass.trim().equals("")) && (sshKeyFile == null || sshKeyFile.trim().equals(""))) + || sshUser.trim().equals("")) { System.err.println("ssh credentials not present. Tests will be lame"); return new SshClient() { @@ -66,11 +67,11 @@ public class JschSshClientLiveTest { public void disconnect() { } - public InputStream get(String path) { + public Payload get(String path) { if (path.equals("/etc/passwd")) { - return Utils.toInputStream("root"); + return Payloads.newStringPayload("root"); } else if (path.equals(temp.getAbsolutePath())) { - return Utils.toInputStream("rabbit"); + return Payloads.newStringPayload("rabbit"); } throw new RuntimeException("path " + path + " not stubbed"); } @@ -83,7 +84,7 @@ public class JschSshClientLiveTest { } @Override - public void put(String path, InputStream contents) { + public void put(String path, Payload contents) { } @@ -103,8 +104,8 @@ public class JschSshClientLiveTest { SshClient.Factory factory = i.getInstance(SshClient.Factory.class); SshClient connection; if (sshKeyFile != null && !sshKeyFile.trim().equals("")) { - connection = factory.create(new IPSocket(sshHost, port), sshUser, Utils - .toStringAndClose(new FileInputStream(sshKeyFile)).getBytes()); + connection = factory.create(new IPSocket(sshHost, port), sshUser, Utils.toStringAndClose( + new FileInputStream(sshKeyFile)).getBytes()); } else { connection = factory.create(new IPSocket(sshHost, port), sshUser, sshPass); } @@ -117,15 +118,15 @@ public class JschSshClientLiveTest { temp = File.createTempFile("foo", "bar"); temp.deleteOnExit(); SshClient client = setupClient(); - client.put(temp.getAbsolutePath(), Utils.toInputStream("rabbit")); - InputStream input = setupClient().get(temp.getAbsolutePath()); - String contents = Utils.toStringAndClose(input); + client.put(temp.getAbsolutePath(), Payloads.newStringPayload("rabbit")); + Payload input = setupClient().get(temp.getAbsolutePath()); + String contents = Utils.toStringAndClose(input.getInput()); assertEquals(contents, "rabbit"); } public void testGetEtcPassword() throws IOException { - InputStream input = setupClient().get("/etc/passwd"); - String contents = Utils.toStringAndClose(input); + Payload input = setupClient().get("/etc/passwd"); + String contents = Utils.toStringAndClose(input.getInput()); assert contents.indexOf("root") >= 0 : "no root in " + contents; } diff --git a/extensions/ssh/jsch/src/test/java/org/jclouds/ssh/jsch/config/JschSshClientModuleTest.java b/extensions/ssh/jsch/src/test/java/org/jclouds/ssh/jsch/config/JschSshClientModuleTest.java index 52c1ed596d..56c197e918 100644 --- a/extensions/ssh/jsch/src/test/java/org/jclouds/ssh/jsch/config/JschSshClientModuleTest.java +++ b/extensions/ssh/jsch/src/test/java/org/jclouds/ssh/jsch/config/JschSshClientModuleTest.java @@ -18,10 +18,7 @@ */ package org.jclouds.ssh.jsch.config; -import static org.testng.Assert.assertEquals; - import java.net.UnknownHostException; -import java.util.Map; import org.jclouds.net.IPSocket; import org.jclouds.ssh.SshClient; @@ -45,10 +42,5 @@ public class JschSshClientModuleTest { SshClient.Factory factory = i.getInstance(SshClient.Factory.class); SshClient connection = factory.create(new IPSocket("localhost", 22), "username", "password"); assert connection instanceof JschSshClient; - Map keyPair = factory.generateRSAKeyPair("comment", "hola"); - assertEquals(keyPair.get("comment"), "comment"); - assertEquals(keyPair.get("passphrase"), "hola"); - assert keyPair.get("private").indexOf("-----BEGIN RSA PRIVATE KEY-----") == 0 : keyPair; - assert keyPair.get("public").indexOf("ssh-rsa ") == 0 : keyPair; } } \ No newline at end of file diff --git a/gogrid/src/test/java/org/jclouds/gogrid/functions/ParseCredentialsFromJsonResponseTest.java b/gogrid/src/test/java/org/jclouds/gogrid/functions/ParseCredentialsFromJsonResponseTest.java index 7f3cf2f075..c3323c309c 100644 --- a/gogrid/src/test/java/org/jclouds/gogrid/functions/ParseCredentialsFromJsonResponseTest.java +++ b/gogrid/src/test/java/org/jclouds/gogrid/functions/ParseCredentialsFromJsonResponseTest.java @@ -35,8 +35,8 @@ import org.jclouds.gogrid.domain.ServerImageState; import org.jclouds.gogrid.domain.ServerImageType; import org.jclouds.gogrid.functions.internal.CustomDeserializers; import org.jclouds.http.HttpResponse; -import org.jclouds.http.Payloads; import org.jclouds.http.functions.config.ParserModule; +import org.jclouds.io.Payloads; import org.testng.annotations.Test; import com.google.common.collect.Maps; diff --git a/gogrid/src/test/java/org/jclouds/gogrid/functions/ParseErrorFromJsonResponseTest.java b/gogrid/src/test/java/org/jclouds/gogrid/functions/ParseErrorFromJsonResponseTest.java index c58b476bf4..b56abb666c 100644 --- a/gogrid/src/test/java/org/jclouds/gogrid/functions/ParseErrorFromJsonResponseTest.java +++ b/gogrid/src/test/java/org/jclouds/gogrid/functions/ParseErrorFromJsonResponseTest.java @@ -29,8 +29,8 @@ import java.net.UnknownHostException; import org.jclouds.gogrid.config.DateSecondsAdapter; import org.jclouds.gogrid.domain.internal.ErrorResponse; import org.jclouds.http.HttpResponse; -import org.jclouds.http.Payloads; import org.jclouds.http.functions.config.ParserModule; +import org.jclouds.io.Payloads; import org.testng.annotations.Test; import com.google.common.collect.Iterables; diff --git a/gogrid/src/test/java/org/jclouds/gogrid/functions/ParseJobsFromJsonResponseTest.java b/gogrid/src/test/java/org/jclouds/gogrid/functions/ParseJobsFromJsonResponseTest.java index 7d3ff92f72..2148636d42 100644 --- a/gogrid/src/test/java/org/jclouds/gogrid/functions/ParseJobsFromJsonResponseTest.java +++ b/gogrid/src/test/java/org/jclouds/gogrid/functions/ParseJobsFromJsonResponseTest.java @@ -38,8 +38,8 @@ import org.jclouds.gogrid.domain.ObjectType; import org.jclouds.gogrid.domain.Option; import org.jclouds.gogrid.functions.internal.CustomDeserializers; import org.jclouds.http.HttpResponse; -import org.jclouds.http.Payloads; import org.jclouds.http.functions.config.ParserModule; +import org.jclouds.io.Payloads; import org.testng.annotations.Test; import com.google.common.collect.ImmutableSortedSet; diff --git a/gogrid/src/test/java/org/jclouds/gogrid/functions/ParseLoadBalancersFromJsonResponseTest.java b/gogrid/src/test/java/org/jclouds/gogrid/functions/ParseLoadBalancersFromJsonResponseTest.java index de4c88a19d..7a418b4de4 100644 --- a/gogrid/src/test/java/org/jclouds/gogrid/functions/ParseLoadBalancersFromJsonResponseTest.java +++ b/gogrid/src/test/java/org/jclouds/gogrid/functions/ParseLoadBalancersFromJsonResponseTest.java @@ -41,8 +41,8 @@ import org.jclouds.gogrid.domain.LoadBalancerType; import org.jclouds.gogrid.domain.Option; import org.jclouds.gogrid.functions.internal.CustomDeserializers; import org.jclouds.http.HttpResponse; -import org.jclouds.http.Payloads; import org.jclouds.http.functions.config.ParserModule; +import org.jclouds.io.Payloads; import org.testng.annotations.Test; import com.google.common.collect.ImmutableSortedSet; diff --git a/gogrid/src/test/java/org/jclouds/gogrid/functions/ParseServerNameToCredentialsMapFromJsonResponseTest.java b/gogrid/src/test/java/org/jclouds/gogrid/functions/ParseServerNameToCredentialsMapFromJsonResponseTest.java index 4c49fb4a90..f4ca1314cc 100644 --- a/gogrid/src/test/java/org/jclouds/gogrid/functions/ParseServerNameToCredentialsMapFromJsonResponseTest.java +++ b/gogrid/src/test/java/org/jclouds/gogrid/functions/ParseServerNameToCredentialsMapFromJsonResponseTest.java @@ -35,8 +35,8 @@ import org.jclouds.gogrid.domain.ServerImageState; import org.jclouds.gogrid.domain.ServerImageType; import org.jclouds.gogrid.functions.internal.CustomDeserializers; import org.jclouds.http.HttpResponse; -import org.jclouds.http.Payloads; import org.jclouds.http.functions.config.ParserModule; +import org.jclouds.io.Payloads; import org.testng.annotations.Test; import com.google.common.collect.Maps; diff --git a/gogrid/src/test/java/org/jclouds/gogrid/functions/ParseServersFromJsonResponseTest.java b/gogrid/src/test/java/org/jclouds/gogrid/functions/ParseServersFromJsonResponseTest.java index 533d737ac3..349469f3b5 100644 --- a/gogrid/src/test/java/org/jclouds/gogrid/functions/ParseServersFromJsonResponseTest.java +++ b/gogrid/src/test/java/org/jclouds/gogrid/functions/ParseServersFromJsonResponseTest.java @@ -46,8 +46,8 @@ import org.jclouds.gogrid.domain.ServerImageState; import org.jclouds.gogrid.domain.ServerImageType; import org.jclouds.gogrid.functions.internal.CustomDeserializers; import org.jclouds.http.HttpResponse; -import org.jclouds.http.Payloads; import org.jclouds.http.functions.config.ParserModule; +import org.jclouds.io.Payloads; import org.testng.annotations.Test; import com.google.common.collect.ImmutableSortedSet; diff --git a/gogrid/src/test/java/org/jclouds/gogrid/handlers/GoGridErrorHandlerTest.java b/gogrid/src/test/java/org/jclouds/gogrid/handlers/GoGridErrorHandlerTest.java index 3782a7259d..3f6d4b662f 100644 --- a/gogrid/src/test/java/org/jclouds/gogrid/handlers/GoGridErrorHandlerTest.java +++ b/gogrid/src/test/java/org/jclouds/gogrid/handlers/GoGridErrorHandlerTest.java @@ -33,8 +33,8 @@ import java.io.InputStream; import org.jclouds.gogrid.mock.HttpCommandMock; import org.jclouds.http.HttpCommand; import org.jclouds.http.HttpResponse; -import org.jclouds.http.Payloads; import org.jclouds.http.functions.config.ParserModule; +import org.jclouds.io.Payloads; import org.testng.TestException; import org.testng.annotations.Test; diff --git a/ibmdev/src/main/java/org/jclouds/ibmdev/compute/config/IBMDeveloperCloudComputeServiceContextModule.java b/ibmdev/src/main/java/org/jclouds/ibmdev/compute/config/IBMDeveloperCloudComputeServiceContextModule.java index 3ef69a8646..fdedc5e713 100644 --- a/ibmdev/src/main/java/org/jclouds/ibmdev/compute/config/IBMDeveloperCloudComputeServiceContextModule.java +++ b/ibmdev/src/main/java/org/jclouds/ibmdev/compute/config/IBMDeveloperCloudComputeServiceContextModule.java @@ -23,6 +23,7 @@ import static org.jclouds.compute.domain.OsFamily.RHEL; import static org.jclouds.ibmdev.options.CreateInstanceOptions.Builder.authorizePublicKey; import static org.jclouds.ibmdev.reference.IBMDeveloperCloudConstants.PROPERTY_IBMDEVELOPERCLOUD_LOCATION; +import java.io.IOException; import java.util.Map; import java.util.Set; import java.util.concurrent.ConcurrentHashMap; @@ -67,9 +68,11 @@ import org.jclouds.ibmdev.IBMDeveloperCloudClient; import org.jclouds.ibmdev.compute.functions.InstanceToNodeMetadata; import org.jclouds.ibmdev.domain.Instance; import org.jclouds.ibmdev.reference.IBMDeveloperCloudConstants; +import org.jclouds.io.Payload; import org.jclouds.logging.Logger; import org.jclouds.rest.RestContext; import org.jclouds.rest.internal.RestContextImpl; +import org.jclouds.util.Utils; import com.google.common.base.Function; import com.google.common.base.Predicate; @@ -95,15 +98,11 @@ public class IBMDeveloperCloudComputeServiceContextModule extends AbstractModule bind(new TypeLiteral>() { }).to(InstanceToNodeMetadata.class); bind(new TypeLiteral() { - }) - .to( - new TypeLiteral>() { - }).in(Scopes.SINGLETON); + }).to(new TypeLiteral>() { + }).in(Scopes.SINGLETON); bind(new TypeLiteral>() { - }) - .to( - new TypeLiteral>() { - }).in(Scopes.SINGLETON); + }).to(new TypeLiteral>() { + }).in(Scopes.SINGLETON); bind(AddNodeWithTagStrategy.class).to(IBMDeveloperCloudAddNodeWithTagStrategy.class); bind(ListNodesStrategy.class).to(IBMDeveloperCloudListNodesStrategy.class); bind(GetNodeMetadataStrategy.class).to(IBMDeveloperCloudGetNodeMetadataStrategy.class); @@ -137,33 +136,37 @@ public class IBMDeveloperCloudComputeServiceContextModule extends AbstractModule @Singleton public static class CreateKeyPairEncodeTagIntoNameRunNodesAndAddToSet extends - EncodeTagIntoNameRunNodesAndAddToSetStrategy { + EncodeTagIntoNameRunNodesAndAddToSetStrategy { private final IBMDeveloperCloudClient client; private final Map credentialsMap; @Inject - protected CreateKeyPairEncodeTagIntoNameRunNodesAndAddToSet( - AddNodeWithTagStrategy addNodeWithTagStrategy, ListNodesStrategy listNodesStrategy, - @Named("NAMING_CONVENTION") String nodeNamingConvention, ComputeUtils utils, - @Named(Constants.PROPERTY_USER_THREADS) ExecutorService executor, - IBMDeveloperCloudClient client, - @Named("CREDENTIALS") Map credentialsMap) { + protected CreateKeyPairEncodeTagIntoNameRunNodesAndAddToSet(AddNodeWithTagStrategy addNodeWithTagStrategy, + ListNodesStrategy listNodesStrategy, @Named("NAMING_CONVENTION") String nodeNamingConvention, + ComputeUtils utils, @Named(Constants.PROPERTY_USER_THREADS) ExecutorService executor, + IBMDeveloperCloudClient client, @Named("CREDENTIALS") Map credentialsMap) { super(addNodeWithTagStrategy, listNodesStrategy, nodeNamingConvention, utils, executor); this.client = checkNotNull(client, "client"); this.credentialsMap = checkNotNull(credentialsMap, "credentialsMap"); } @Override - public Map> execute(String tag, int count, Template template, - Set nodes, Map badNodes) { - String key = template.getOptions().getPublicKey(); + public Map> execute(String tag, int count, Template template, Set nodes, + Map badNodes) { + Payload key = template.getOptions().getPublicKey(); if (key != null) { + String keyAsText; + try { + keyAsText = Utils.toStringAndClose(key.getInput()); + } catch (IOException e1) { + throw new RuntimeException(e1); + } template.getOptions().dontAuthorizePublicKey(); try { - client.addPublicKey(tag, key); + client.addPublicKey(tag, keyAsText); } catch (IllegalStateException e) { // must not have been found - client.updatePublicKey(tag, key); + client.updatePublicKey(tag, keyAsText); } } else { credentialsMap.put(tag, client.generateKeyPair(tag).getKeyMaterial()); @@ -181,17 +184,15 @@ public class IBMDeveloperCloudComputeServiceContextModule extends AbstractModule @Inject protected IBMDeveloperCloudAddNodeWithTagStrategy(IBMDeveloperCloudClient client, - Function instanceToNodeMetadata) { + Function instanceToNodeMetadata) { this.client = checkNotNull(client, "client"); - this.instanceToNodeMetadata = checkNotNull(instanceToNodeMetadata, - "instanceToNodeMetadata"); + this.instanceToNodeMetadata = checkNotNull(instanceToNodeMetadata, "instanceToNodeMetadata"); } @Override public NodeMetadata execute(String tag, String name, Template template) { - Instance instance = client.createInstanceInLocation(template.getLocation().getId(), name, - template.getImage().getProviderId(), template.getSize().getProviderId(), - authorizePublicKey(tag)); + Instance instance = client.createInstanceInLocation(template.getLocation().getId(), name, template.getImage() + .getProviderId(), template.getSize().getProviderId(), authorizePublicKey(tag)); return instanceToNodeMetadata.apply(client.getInstance(instance.getId())); } } @@ -203,8 +204,7 @@ public class IBMDeveloperCloudComputeServiceContextModule extends AbstractModule private final GetNodeMetadataStrategy getNode; @Inject - protected IBMDeveloperCloudRebootNodeStrategy(IBMDeveloperCloudClient client, - GetNodeMetadataStrategy getNode) { + protected IBMDeveloperCloudRebootNodeStrategy(IBMDeveloperCloudClient client, GetNodeMetadataStrategy getNode) { this.client = checkNotNull(client, "client"); this.getNode = checkNotNull(getNode, "getNode"); } @@ -219,19 +219,18 @@ public class IBMDeveloperCloudComputeServiceContextModule extends AbstractModule @Singleton @Provides Map provideServerToNodeState() { - return ImmutableMap. builder().put(Instance.Status.ACTIVE, - NodeState.RUNNING)// - .put(Instance.Status.STOPPED, NodeState.SUSPENDED)// - .put(Instance.Status.REMOVED, NodeState.TERMINATED)// - .put(Instance.Status.DEPROVISIONING, NodeState.PENDING)// - .put(Instance.Status.FAILED, NodeState.ERROR)// - .put(Instance.Status.NEW, NodeState.PENDING)// - .put(Instance.Status.PROVISIONING, NodeState.PENDING)// - .put(Instance.Status.REJECTED, NodeState.ERROR)// - .put(Instance.Status.RESTARTING, NodeState.PENDING)// - .put(Instance.Status.STARTING, NodeState.PENDING)// - .put(Instance.Status.STOPPING, NodeState.PENDING)// - .put(Instance.Status.UNKNOWN, NodeState.UNKNOWN).build(); + return ImmutableMap. builder().put(Instance.Status.ACTIVE, NodeState.RUNNING)// + .put(Instance.Status.STOPPED, NodeState.SUSPENDED)// + .put(Instance.Status.REMOVED, NodeState.TERMINATED)// + .put(Instance.Status.DEPROVISIONING, NodeState.PENDING)// + .put(Instance.Status.FAILED, NodeState.ERROR)// + .put(Instance.Status.NEW, NodeState.PENDING)// + .put(Instance.Status.PROVISIONING, NodeState.PENDING)// + .put(Instance.Status.REJECTED, NodeState.ERROR)// + .put(Instance.Status.RESTARTING, NodeState.PENDING)// + .put(Instance.Status.STARTING, NodeState.PENDING)// + .put(Instance.Status.STOPPING, NodeState.PENDING)// + .put(Instance.Status.UNKNOWN, NodeState.UNKNOWN).build(); } @Singleton @@ -241,7 +240,7 @@ public class IBMDeveloperCloudComputeServiceContextModule extends AbstractModule @Inject protected IBMDeveloperCloudListNodesStrategy(IBMDeveloperCloudClient client, - Function instanceToNodeMetadata) { + Function instanceToNodeMetadata) { this.client = client; this.instanceToNodeMetadata = instanceToNodeMetadata; } @@ -252,10 +251,8 @@ public class IBMDeveloperCloudComputeServiceContextModule extends AbstractModule } @Override - public Iterable listDetailsOnNodesMatching( - Predicate filter) { - return Iterables.filter(Iterables - .transform(client.listInstances(), instanceToNodeMetadata), filter); + public Iterable listDetailsOnNodesMatching(Predicate filter) { + return Iterables.filter(Iterables.transform(client.listInstances(), instanceToNodeMetadata), filter); } } @@ -266,7 +263,7 @@ public class IBMDeveloperCloudComputeServiceContextModule extends AbstractModule @Inject protected IBMDeveloperCloudGetNodeMetadataStrategy(IBMDeveloperCloudClient client, - Function instanceToNodeMetadata) { + Function instanceToNodeMetadata) { this.client = client; this.instanceToNodeMetadata = instanceToNodeMetadata; } @@ -284,8 +281,7 @@ public class IBMDeveloperCloudComputeServiceContextModule extends AbstractModule private final GetNodeMetadataStrategy getNode; @Inject - protected IBMDeveloperCloudDestroyNodeStrategy(IBMDeveloperCloudClient client, - GetNodeMetadataStrategy getNode) { + protected IBMDeveloperCloudDestroyNodeStrategy(IBMDeveloperCloudClient client, GetNodeMetadataStrategy getNode) { this.client = checkNotNull(client, "client"); this.getNode = checkNotNull(getNode, "getNode"); } @@ -299,9 +295,8 @@ public class IBMDeveloperCloudComputeServiceContextModule extends AbstractModule @Provides @Singleton - Location getDefaultLocation( - @Named(PROPERTY_IBMDEVELOPERCLOUD_LOCATION) final String defaultLocation, - Set locations) { + Location getDefaultLocation(@Named(PROPERTY_IBMDEVELOPERCLOUD_LOCATION) final String defaultLocation, + Set locations) { return Iterables.find(locations, new Predicate() { @Override @@ -315,14 +310,13 @@ public class IBMDeveloperCloudComputeServiceContextModule extends AbstractModule @Provides @Singleton Set getAssignableLocations(IBMDeveloperCloudClient sync, LogHolder holder, - @org.jclouds.rest.annotations.Provider String providerName) { + @org.jclouds.rest.annotations.Provider String providerName) { final Set assignableLocations = Sets.newHashSet(); holder.logger.debug(">> providing locations"); Location parent = new LocationImpl(LocationScope.PROVIDER, providerName, providerName, null); for (org.jclouds.ibmdev.domain.Location location : sync.listLocations()) - assignableLocations.add(new LocationImpl(LocationScope.ZONE, location.getId(), location - .getName(), parent)); + assignableLocations.add(new LocationImpl(LocationScope.ZONE, location.getId(), location.getName(), parent)); holder.logger.debug("<< locations(%d)", assignableLocations.size()); return assignableLocations; @@ -331,7 +325,7 @@ public class IBMDeveloperCloudComputeServiceContextModule extends AbstractModule @Provides @Singleton protected Set provideSizes(IBMDeveloperCloudClient sync, LogHolder holder, - Map locations) { + Map locations) { final Set sizes = Sets.newHashSet(); holder.logger.debug(">> providing sizes"); @@ -340,31 +334,27 @@ public class IBMDeveloperCloudComputeServiceContextModule extends AbstractModule // TODO we cannot query actual size, yet, so lets make the // multipliers work out int sizeMultiplier = 1; - for (String i386 : location.getCapabilities().get( - IBMDeveloperCloudConstants.CAPABILITY_I386).keySet()) + for (String i386 : location.getCapabilities().get(IBMDeveloperCloudConstants.CAPABILITY_I386).keySet()) sizes.add(buildSize(location, i386, assignedLocation, sizeMultiplier++)); - for (String x86_64 : location.getCapabilities().get( - IBMDeveloperCloudConstants.CAPABILITY_x86_64).keySet()) + for (String x86_64 : location.getCapabilities().get(IBMDeveloperCloudConstants.CAPABILITY_x86_64).keySet()) sizes.add(buildSize(location, x86_64, assignedLocation, sizeMultiplier++)); } holder.logger.debug("<< sizes(%d)", sizes.size()); return sizes; } - private SizeImpl buildSize(org.jclouds.ibmdev.domain.Location location, final String id, - Location assignedLocation, int multiplier) { + private SizeImpl buildSize(org.jclouds.ibmdev.domain.Location location, final String id, Location assignedLocation, + int multiplier) { return new SizeImpl(id, id, location.getId() + "/" + id, assignedLocation, null, ImmutableMap - . of(), multiplier, multiplier * 1024, multiplier * 10, - new Predicate() { - @Override - public boolean apply(Image input) { - if (input instanceof IBMImage) - return IBMImage.class.cast(input).rawImage.getSupportedInstanceTypes() - .contains(id); - return false; - } + . of(), multiplier, multiplier * 1024, multiplier * 10, new Predicate() { + @Override + public boolean apply(Image input) { + if (input instanceof IBMImage) + return IBMImage.class.cast(input).rawImage.getSupportedInstanceTypes().contains(id); + return false; + } - }); + }); } @Provides @@ -395,8 +385,8 @@ public class IBMDeveloperCloudComputeServiceContextModule extends AbstractModule @Provides @Singleton - protected Set provideImages(final IBMDeveloperCloudClient sync, - LogHolder holder, Map locations) { + protected Set provideImages(final IBMDeveloperCloudClient sync, LogHolder holder, + Map locations) { final Set images = Sets.newHashSet(); holder.logger.debug(">> providing images"); @@ -419,12 +409,11 @@ public class IBMDeveloperCloudComputeServiceContextModule extends AbstractModule // TODO manifest fails to parse due to encoding issues in the path // TODO get correct default credentials // http://www-180.ibm.com/cloud/enterprise/beta/ram/community/_rlvid.jsp.faces?_rap=pc_DiscussionForum.doDiscussionTopic&_rvip=/community/discussionForum.jsp&guid={DA689AEE-783C-6FE7-6F9F-DFEE9763F806}&v=1&submission=false&fid=1068&tid=1527 - super(in.getId(), in.getName(), in.getId(), location, null, ImmutableMap - . of(), in.getDescription(), in.getCreatedTime().getTime() + "", - (in.getPlatform().indexOf("Redhat") != -1) ? OsFamily.RHEL : OsFamily.SUSE, in - .getPlatform(), - (in.getPlatform().indexOf("32") != -1) ? Architecture.X86_32 - : Architecture.X86_64, new Credentials("idcuser", null)); + super(in.getId(), in.getName(), in.getId(), location, null, ImmutableMap. of(), in + .getDescription(), in.getCreatedTime().getTime() + "", + (in.getPlatform().indexOf("Redhat") != -1) ? OsFamily.RHEL : OsFamily.SUSE, in.getPlatform(), (in + .getPlatform().indexOf("32") != -1) ? Architecture.X86_32 : Architecture.X86_64, new Credentials( + "idcuser", null)); this.rawImage = in; } diff --git a/ibmdev/src/test/java/org/jclouds/ibmdev/functions/ParseAddressFromJsonTest.java b/ibmdev/src/test/java/org/jclouds/ibmdev/functions/ParseAddressFromJsonTest.java index 5f9b245dcb..bd16a359b4 100644 --- a/ibmdev/src/test/java/org/jclouds/ibmdev/functions/ParseAddressFromJsonTest.java +++ b/ibmdev/src/test/java/org/jclouds/ibmdev/functions/ParseAddressFromJsonTest.java @@ -24,9 +24,9 @@ import static org.testng.Assert.assertEquals; import java.io.IOException; import org.jclouds.http.HttpResponse; -import org.jclouds.http.Payloads; import org.jclouds.http.functions.config.ParserModule; import org.jclouds.ibmdev.domain.Address; +import org.jclouds.io.Payloads; import org.testng.annotations.BeforeTest; import org.testng.annotations.Test; diff --git a/ibmdev/src/test/java/org/jclouds/ibmdev/functions/ParseAddressesFromJsonTest.java b/ibmdev/src/test/java/org/jclouds/ibmdev/functions/ParseAddressesFromJsonTest.java index 46c3d4c87b..45d6afda49 100644 --- a/ibmdev/src/test/java/org/jclouds/ibmdev/functions/ParseAddressesFromJsonTest.java +++ b/ibmdev/src/test/java/org/jclouds/ibmdev/functions/ParseAddressesFromJsonTest.java @@ -23,9 +23,9 @@ import java.io.IOException; import java.util.Set; import org.jclouds.http.HttpResponse; -import org.jclouds.http.Payloads; import org.jclouds.http.functions.config.ParserModule; import org.jclouds.ibmdev.domain.Address; +import org.jclouds.io.Payloads; import org.testng.annotations.BeforeTest; import org.testng.annotations.Test; diff --git a/ibmdev/src/test/java/org/jclouds/ibmdev/functions/ParseExpirationTimeFromJsonTest.java b/ibmdev/src/test/java/org/jclouds/ibmdev/functions/ParseExpirationTimeFromJsonTest.java index f5e9a4b463..a20f95c3c3 100644 --- a/ibmdev/src/test/java/org/jclouds/ibmdev/functions/ParseExpirationTimeFromJsonTest.java +++ b/ibmdev/src/test/java/org/jclouds/ibmdev/functions/ParseExpirationTimeFromJsonTest.java @@ -25,8 +25,8 @@ import java.io.IOException; import java.util.Date; import org.jclouds.http.HttpResponse; -import org.jclouds.http.Payloads; import org.jclouds.http.functions.config.ParserModule; +import org.jclouds.io.Payloads; import org.testng.annotations.BeforeTest; import org.testng.annotations.Test; diff --git a/ibmdev/src/test/java/org/jclouds/ibmdev/functions/ParseImageFromJsonTest.java b/ibmdev/src/test/java/org/jclouds/ibmdev/functions/ParseImageFromJsonTest.java index ab996dcccd..8ae0dd5775 100644 --- a/ibmdev/src/test/java/org/jclouds/ibmdev/functions/ParseImageFromJsonTest.java +++ b/ibmdev/src/test/java/org/jclouds/ibmdev/functions/ParseImageFromJsonTest.java @@ -26,11 +26,11 @@ import java.util.Date; import org.jclouds.http.HttpResponse; import org.jclouds.http.HttpUtils; -import org.jclouds.http.Payloads; import org.jclouds.http.functions.config.ParserModule; import org.jclouds.ibmdev.config.IBMDeveloperCloudParserModule; import org.jclouds.ibmdev.domain.Image; import org.jclouds.ibmdev.domain.Image.Visibility; +import org.jclouds.io.Payloads; import org.testng.annotations.BeforeTest; import org.testng.annotations.Test; diff --git a/ibmdev/src/test/java/org/jclouds/ibmdev/functions/ParseImagesFromJsonTest.java b/ibmdev/src/test/java/org/jclouds/ibmdev/functions/ParseImagesFromJsonTest.java index 6fdabb0cc8..1e79a4cff5 100644 --- a/ibmdev/src/test/java/org/jclouds/ibmdev/functions/ParseImagesFromJsonTest.java +++ b/ibmdev/src/test/java/org/jclouds/ibmdev/functions/ParseImagesFromJsonTest.java @@ -25,10 +25,10 @@ import java.util.Set; import org.jclouds.http.HttpResponse; import org.jclouds.http.HttpUtils; -import org.jclouds.http.Payloads; import org.jclouds.http.functions.config.ParserModule; import org.jclouds.ibmdev.config.IBMDeveloperCloudParserModule; import org.jclouds.ibmdev.domain.Image; +import org.jclouds.io.Payloads; import org.testng.annotations.BeforeTest; import org.testng.annotations.Test; diff --git a/ibmdev/src/test/java/org/jclouds/ibmdev/functions/ParseInstanceFromJsonTest.java b/ibmdev/src/test/java/org/jclouds/ibmdev/functions/ParseInstanceFromJsonTest.java index 5976f2000a..de70446bc0 100644 --- a/ibmdev/src/test/java/org/jclouds/ibmdev/functions/ParseInstanceFromJsonTest.java +++ b/ibmdev/src/test/java/org/jclouds/ibmdev/functions/ParseInstanceFromJsonTest.java @@ -25,10 +25,10 @@ import java.io.IOException; import java.util.Date; import org.jclouds.http.HttpResponse; -import org.jclouds.http.Payloads; import org.jclouds.http.functions.config.ParserModule; import org.jclouds.ibmdev.domain.Instance; import org.jclouds.ibmdev.domain.Instance.Software; +import org.jclouds.io.Payloads; import org.testng.annotations.BeforeTest; import org.testng.annotations.Test; diff --git a/ibmdev/src/test/java/org/jclouds/ibmdev/functions/ParseInstancesFromJsonTest.java b/ibmdev/src/test/java/org/jclouds/ibmdev/functions/ParseInstancesFromJsonTest.java index 5074af9125..e79d5af92a 100644 --- a/ibmdev/src/test/java/org/jclouds/ibmdev/functions/ParseInstancesFromJsonTest.java +++ b/ibmdev/src/test/java/org/jclouds/ibmdev/functions/ParseInstancesFromJsonTest.java @@ -24,10 +24,10 @@ import java.util.Date; import java.util.Set; import org.jclouds.http.HttpResponse; -import org.jclouds.http.Payloads; import org.jclouds.http.functions.config.ParserModule; import org.jclouds.ibmdev.domain.Instance; import org.jclouds.ibmdev.domain.Instance.Software; +import org.jclouds.io.Payloads; import org.testng.annotations.BeforeTest; import org.testng.annotations.Test; diff --git a/ibmdev/src/test/java/org/jclouds/ibmdev/functions/ParseKeyFromJsonTest.java b/ibmdev/src/test/java/org/jclouds/ibmdev/functions/ParseKeyFromJsonTest.java index 089cce950f..0c0e83625e 100644 --- a/ibmdev/src/test/java/org/jclouds/ibmdev/functions/ParseKeyFromJsonTest.java +++ b/ibmdev/src/test/java/org/jclouds/ibmdev/functions/ParseKeyFromJsonTest.java @@ -25,10 +25,10 @@ import java.io.IOException; import java.util.Date; import org.jclouds.http.HttpResponse; -import org.jclouds.http.Payloads; import org.jclouds.http.functions.ParseJson; import org.jclouds.http.functions.config.ParserModule; import org.jclouds.ibmdev.domain.Key; +import org.jclouds.io.Payloads; import org.testng.annotations.BeforeTest; import org.testng.annotations.Test; diff --git a/ibmdev/src/test/java/org/jclouds/ibmdev/functions/ParseKeysFromJsonTest.java b/ibmdev/src/test/java/org/jclouds/ibmdev/functions/ParseKeysFromJsonTest.java index d03d3598de..ea223a919c 100644 --- a/ibmdev/src/test/java/org/jclouds/ibmdev/functions/ParseKeysFromJsonTest.java +++ b/ibmdev/src/test/java/org/jclouds/ibmdev/functions/ParseKeysFromJsonTest.java @@ -24,9 +24,9 @@ import java.util.Date; import java.util.Set; import org.jclouds.http.HttpResponse; -import org.jclouds.http.Payloads; import org.jclouds.http.functions.config.ParserModule; import org.jclouds.ibmdev.domain.Key; +import org.jclouds.io.Payloads; import org.testng.annotations.BeforeTest; import org.testng.annotations.Test; diff --git a/ibmdev/src/test/java/org/jclouds/ibmdev/functions/ParseVolumeFromJsonTest.java b/ibmdev/src/test/java/org/jclouds/ibmdev/functions/ParseVolumeFromJsonTest.java index cf307bdc8b..977a91c751 100644 --- a/ibmdev/src/test/java/org/jclouds/ibmdev/functions/ParseVolumeFromJsonTest.java +++ b/ibmdev/src/test/java/org/jclouds/ibmdev/functions/ParseVolumeFromJsonTest.java @@ -25,9 +25,9 @@ import java.io.IOException; import java.util.Date; import org.jclouds.http.HttpResponse; -import org.jclouds.http.Payloads; import org.jclouds.http.functions.config.ParserModule; import org.jclouds.ibmdev.domain.Volume; +import org.jclouds.io.Payloads; import org.testng.annotations.BeforeTest; import org.testng.annotations.Test; diff --git a/ibmdev/src/test/java/org/jclouds/ibmdev/functions/ParseVolumesFromJsonTest.java b/ibmdev/src/test/java/org/jclouds/ibmdev/functions/ParseVolumesFromJsonTest.java index a2355becc6..b5d2f08e92 100644 --- a/ibmdev/src/test/java/org/jclouds/ibmdev/functions/ParseVolumesFromJsonTest.java +++ b/ibmdev/src/test/java/org/jclouds/ibmdev/functions/ParseVolumesFromJsonTest.java @@ -24,9 +24,9 @@ import java.util.Date; import java.util.Set; import org.jclouds.http.HttpResponse; -import org.jclouds.http.Payloads; import org.jclouds.http.functions.config.ParserModule; import org.jclouds.ibmdev.domain.Volume; +import org.jclouds.io.Payloads; import org.testng.annotations.BeforeTest; import org.testng.annotations.Test; diff --git a/nirvanix/sdn/core/src/test/java/org/jclouds/nirvanix/sdn/functions/ParseMetadataFromJsonResponseTest.java b/nirvanix/sdn/core/src/test/java/org/jclouds/nirvanix/sdn/functions/ParseMetadataFromJsonResponseTest.java index c3c38a57f0..05611ac0ed 100644 --- a/nirvanix/sdn/core/src/test/java/org/jclouds/nirvanix/sdn/functions/ParseMetadataFromJsonResponseTest.java +++ b/nirvanix/sdn/core/src/test/java/org/jclouds/nirvanix/sdn/functions/ParseMetadataFromJsonResponseTest.java @@ -25,8 +25,8 @@ import java.net.UnknownHostException; import java.util.Map; import org.jclouds.http.HttpResponse; -import org.jclouds.http.Payloads; import org.jclouds.http.functions.config.ParserModule; +import org.jclouds.io.Payloads; import org.testng.annotations.Test; import com.google.common.collect.ImmutableMap; diff --git a/nirvanix/sdn/core/src/test/java/org/jclouds/nirvanix/sdn/functions/ParseSessionTokenFromJsonResponseTest.java b/nirvanix/sdn/core/src/test/java/org/jclouds/nirvanix/sdn/functions/ParseSessionTokenFromJsonResponseTest.java index c05186ee62..89b7bb88b7 100644 --- a/nirvanix/sdn/core/src/test/java/org/jclouds/nirvanix/sdn/functions/ParseSessionTokenFromJsonResponseTest.java +++ b/nirvanix/sdn/core/src/test/java/org/jclouds/nirvanix/sdn/functions/ParseSessionTokenFromJsonResponseTest.java @@ -24,8 +24,8 @@ import java.io.InputStream; import java.net.UnknownHostException; import org.jclouds.http.HttpResponse; -import org.jclouds.http.Payloads; import org.jclouds.http.functions.config.ParserModule; +import org.jclouds.io.Payloads; import org.testng.annotations.Test; import com.google.inject.Guice; diff --git a/nirvanix/sdn/core/src/test/java/org/jclouds/nirvanix/sdn/functions/ParseUploadInfoFromJsonResponseTest.java b/nirvanix/sdn/core/src/test/java/org/jclouds/nirvanix/sdn/functions/ParseUploadInfoFromJsonResponseTest.java index 8d635238cb..9e5840927e 100644 --- a/nirvanix/sdn/core/src/test/java/org/jclouds/nirvanix/sdn/functions/ParseUploadInfoFromJsonResponseTest.java +++ b/nirvanix/sdn/core/src/test/java/org/jclouds/nirvanix/sdn/functions/ParseUploadInfoFromJsonResponseTest.java @@ -25,8 +25,8 @@ import java.net.URI; import java.net.UnknownHostException; import org.jclouds.http.HttpResponse; -import org.jclouds.http.Payloads; import org.jclouds.http.functions.config.ParserModule; +import org.jclouds.io.Payloads; import org.jclouds.nirvanix.sdn.domain.UploadInfo; import org.testng.annotations.Test; diff --git a/rackspace/src/main/java/org/jclouds/rackspace/cloudfiles/domain/internal/CFObjectImpl.java b/rackspace/src/main/java/org/jclouds/rackspace/cloudfiles/domain/internal/CFObjectImpl.java index 47f5b4bd93..7704fe0e15 100644 --- a/rackspace/src/main/java/org/jclouds/rackspace/cloudfiles/domain/internal/CFObjectImpl.java +++ b/rackspace/src/main/java/org/jclouds/rackspace/cloudfiles/domain/internal/CFObjectImpl.java @@ -22,10 +22,10 @@ import static com.google.common.base.Preconditions.checkNotNull; import javax.inject.Inject; -import org.jclouds.http.Payload; import org.jclouds.http.PayloadEnclosing; import org.jclouds.http.internal.PayloadEnclosingImpl; -import org.jclouds.http.payloads.DelegatingPayload; +import org.jclouds.io.Payload; +import org.jclouds.io.payloads.DelegatingPayload; import org.jclouds.rackspace.cloudfiles.domain.CFObject; import org.jclouds.rackspace.cloudfiles.domain.MutableObjectInfoWithMetadata; diff --git a/rackspace/src/test/java/org/jclouds/rackspace/cloudfiles/binders/BindCFObjectToPayloadTest.java b/rackspace/src/test/java/org/jclouds/rackspace/cloudfiles/binders/BindCFObjectToPayloadTest.java index d2676178cd..b15a2dcf91 100644 --- a/rackspace/src/test/java/org/jclouds/rackspace/cloudfiles/binders/BindCFObjectToPayloadTest.java +++ b/rackspace/src/test/java/org/jclouds/rackspace/cloudfiles/binders/BindCFObjectToPayloadTest.java @@ -28,7 +28,7 @@ import javax.ws.rs.core.MediaType; import org.jclouds.blobstore.binders.BindUserMetadataToHeadersWithPrefix; import org.jclouds.blobstore.domain.Blob; import org.jclouds.http.HttpRequest; -import org.jclouds.http.Payload; +import org.jclouds.io.Payload; import org.jclouds.rackspace.cloudfiles.blobstore.functions.ObjectToBlob; import org.jclouds.rackspace.cloudfiles.domain.CFObject; import org.jclouds.rackspace.cloudfiles.domain.MutableObjectInfoWithMetadata; diff --git a/rackspace/src/test/java/org/jclouds/rackspace/cloudfiles/functions/ParseContainerCDNMetadataListFromJsonResponseTest.java b/rackspace/src/test/java/org/jclouds/rackspace/cloudfiles/functions/ParseContainerCDNMetadataListFromJsonResponseTest.java index d55d517ea7..97ae9f5bcf 100644 --- a/rackspace/src/test/java/org/jclouds/rackspace/cloudfiles/functions/ParseContainerCDNMetadataListFromJsonResponseTest.java +++ b/rackspace/src/test/java/org/jclouds/rackspace/cloudfiles/functions/ParseContainerCDNMetadataListFromJsonResponseTest.java @@ -26,9 +26,9 @@ import java.util.Set; import java.util.SortedSet; import org.jclouds.http.HttpResponse; -import org.jclouds.http.Payloads; import org.jclouds.http.functions.ParseJson; import org.jclouds.http.functions.config.ParserModule; +import org.jclouds.io.Payloads; import org.jclouds.rackspace.cloudfiles.domain.ContainerCDNMetadata; import org.testng.annotations.Test; diff --git a/rackspace/src/test/java/org/jclouds/rackspace/cloudfiles/functions/ParseContainerListFromJsonResponseTest.java b/rackspace/src/test/java/org/jclouds/rackspace/cloudfiles/functions/ParseContainerListFromJsonResponseTest.java index 2fea1ff1d2..850a109a52 100755 --- a/rackspace/src/test/java/org/jclouds/rackspace/cloudfiles/functions/ParseContainerListFromJsonResponseTest.java +++ b/rackspace/src/test/java/org/jclouds/rackspace/cloudfiles/functions/ParseContainerListFromJsonResponseTest.java @@ -24,9 +24,9 @@ import java.io.InputStream; import java.util.List; import org.jclouds.http.HttpResponse; -import org.jclouds.http.Payloads; import org.jclouds.http.functions.ParseJson; import org.jclouds.http.functions.config.ParserModule; +import org.jclouds.io.Payloads; import org.jclouds.rackspace.cloudfiles.domain.ContainerMetadata; import org.jclouds.util.Utils; import org.testng.annotations.Test; diff --git a/rackspace/src/test/java/org/jclouds/rackspace/cloudfiles/functions/ParseObjectInfoFromHeadersTest.java b/rackspace/src/test/java/org/jclouds/rackspace/cloudfiles/functions/ParseObjectInfoFromHeadersTest.java index 88d0a38c45..0f3818b03c 100644 --- a/rackspace/src/test/java/org/jclouds/rackspace/cloudfiles/functions/ParseObjectInfoFromHeadersTest.java +++ b/rackspace/src/test/java/org/jclouds/rackspace/cloudfiles/functions/ParseObjectInfoFromHeadersTest.java @@ -28,8 +28,8 @@ import java.net.URI; import org.jclouds.Constants; import org.jclouds.blobstore.reference.BlobStoreConstants; import org.jclouds.http.HttpResponse; -import org.jclouds.http.Payloads; import org.jclouds.http.functions.config.ParserModule; +import org.jclouds.io.Payloads; import org.jclouds.rackspace.cloudfiles.domain.MutableObjectInfoWithMetadata; import org.jclouds.rest.internal.GeneratedHttpRequest; import org.testng.annotations.Test; diff --git a/rackspace/src/test/java/org/jclouds/rackspace/cloudservers/CloudServersClientLiveTest.java b/rackspace/src/test/java/org/jclouds/rackspace/cloudservers/CloudServersClientLiveTest.java index 17233a3b85..ee271a8861 100755 --- a/rackspace/src/test/java/org/jclouds/rackspace/cloudservers/CloudServersClientLiveTest.java +++ b/rackspace/src/test/java/org/jclouds/rackspace/cloudservers/CloudServersClientLiveTest.java @@ -27,7 +27,6 @@ import static org.testng.Assert.assertNotNull; import static org.testng.Assert.assertTrue; import java.io.IOException; -import java.io.InputStream; import java.lang.reflect.UndeclaredThrowableException; import java.security.SecureRandom; import java.util.Map; @@ -36,6 +35,7 @@ import java.util.Set; import java.util.concurrent.TimeUnit; import org.jclouds.http.HttpResponseException; +import org.jclouds.io.Payload; import org.jclouds.logging.log4j.config.Log4JLoggingModule; import org.jclouds.net.IPSocket; import org.jclouds.predicates.RetryablePredicate; @@ -383,8 +383,8 @@ public class CloudServersClientLiveTest { SshClient client = sshFactory.create(socket, "root", pass); try { client.connect(); - InputStream etcPasswd = client.get("/etc/jclouds.txt"); - String etcPasswdContents = Utils.toStringAndClose(etcPasswd); + Payload etcPasswd = client.get("/etc/jclouds.txt"); + String etcPasswdContents = Utils.toStringAndClose(etcPasswd.getInput()); assertEquals("rackspace", etcPasswdContents.trim()); } finally { if (client != null) diff --git a/rackspace/src/test/java/org/jclouds/rackspace/cloudservers/functions/ParseAddressesFromJsonResponseTest.java b/rackspace/src/test/java/org/jclouds/rackspace/cloudservers/functions/ParseAddressesFromJsonResponseTest.java index 6e550ba6a6..a655996629 100644 --- a/rackspace/src/test/java/org/jclouds/rackspace/cloudservers/functions/ParseAddressesFromJsonResponseTest.java +++ b/rackspace/src/test/java/org/jclouds/rackspace/cloudservers/functions/ParseAddressesFromJsonResponseTest.java @@ -25,9 +25,9 @@ import java.net.UnknownHostException; import java.util.List; import org.jclouds.http.HttpResponse; -import org.jclouds.http.Payloads; import org.jclouds.http.functions.UnwrapOnlyJsonValue; import org.jclouds.http.functions.config.ParserModule; +import org.jclouds.io.Payloads; import org.jclouds.rackspace.cloudservers.domain.Addresses; import org.testng.annotations.Test; diff --git a/rackspace/src/test/java/org/jclouds/rackspace/cloudservers/functions/ParseBackupScheduleFromJsonResponseTest.java b/rackspace/src/test/java/org/jclouds/rackspace/cloudservers/functions/ParseBackupScheduleFromJsonResponseTest.java index 631b1c5927..81b74413c6 100644 --- a/rackspace/src/test/java/org/jclouds/rackspace/cloudservers/functions/ParseBackupScheduleFromJsonResponseTest.java +++ b/rackspace/src/test/java/org/jclouds/rackspace/cloudservers/functions/ParseBackupScheduleFromJsonResponseTest.java @@ -24,9 +24,9 @@ import java.io.InputStream; import java.net.UnknownHostException; import org.jclouds.http.HttpResponse; -import org.jclouds.http.Payloads; import org.jclouds.http.functions.UnwrapOnlyJsonValue; import org.jclouds.http.functions.config.ParserModule; +import org.jclouds.io.Payloads; import org.jclouds.rackspace.cloudservers.domain.BackupSchedule; import org.jclouds.rackspace.cloudservers.domain.DailyBackup; import org.jclouds.rackspace.cloudservers.domain.WeeklyBackup; diff --git a/rackspace/src/test/java/org/jclouds/rackspace/cloudservers/functions/ParseFlavorFromJsonResponseTest.java b/rackspace/src/test/java/org/jclouds/rackspace/cloudservers/functions/ParseFlavorFromJsonResponseTest.java index 6ca5e38f22..acc6be768b 100644 --- a/rackspace/src/test/java/org/jclouds/rackspace/cloudservers/functions/ParseFlavorFromJsonResponseTest.java +++ b/rackspace/src/test/java/org/jclouds/rackspace/cloudservers/functions/ParseFlavorFromJsonResponseTest.java @@ -24,9 +24,9 @@ import java.io.InputStream; import java.net.UnknownHostException; import org.jclouds.http.HttpResponse; -import org.jclouds.http.Payloads; import org.jclouds.http.functions.UnwrapOnlyJsonValue; import org.jclouds.http.functions.config.ParserModule; +import org.jclouds.io.Payloads; import org.jclouds.rackspace.cloudservers.domain.Flavor; import org.testng.annotations.Test; diff --git a/rackspace/src/test/java/org/jclouds/rackspace/cloudservers/functions/ParseFlavorListFromJsonResponseTest.java b/rackspace/src/test/java/org/jclouds/rackspace/cloudservers/functions/ParseFlavorListFromJsonResponseTest.java index 628caf249b..452ae7ab67 100644 --- a/rackspace/src/test/java/org/jclouds/rackspace/cloudservers/functions/ParseFlavorListFromJsonResponseTest.java +++ b/rackspace/src/test/java/org/jclouds/rackspace/cloudservers/functions/ParseFlavorListFromJsonResponseTest.java @@ -25,9 +25,9 @@ import java.net.UnknownHostException; import java.util.List; import org.jclouds.http.HttpResponse; -import org.jclouds.http.Payloads; import org.jclouds.http.functions.UnwrapOnlyJsonValue; import org.jclouds.http.functions.config.ParserModule; +import org.jclouds.io.Payloads; import org.jclouds.rackspace.cloudservers.domain.Flavor; import org.testng.annotations.Test; diff --git a/rackspace/src/test/java/org/jclouds/rackspace/cloudservers/functions/ParseImageFromJsonResponseTest.java b/rackspace/src/test/java/org/jclouds/rackspace/cloudservers/functions/ParseImageFromJsonResponseTest.java index e8249e5184..a576d04e76 100644 --- a/rackspace/src/test/java/org/jclouds/rackspace/cloudservers/functions/ParseImageFromJsonResponseTest.java +++ b/rackspace/src/test/java/org/jclouds/rackspace/cloudservers/functions/ParseImageFromJsonResponseTest.java @@ -25,9 +25,9 @@ import java.net.UnknownHostException; import org.jclouds.date.DateService; import org.jclouds.http.HttpResponse; -import org.jclouds.http.Payloads; import org.jclouds.http.functions.UnwrapOnlyJsonValue; import org.jclouds.http.functions.config.ParserModule; +import org.jclouds.io.Payloads; import org.jclouds.rackspace.cloudservers.domain.Image; import org.jclouds.rackspace.cloudservers.domain.ImageStatus; import org.testng.annotations.Test; diff --git a/rackspace/src/test/java/org/jclouds/rackspace/cloudservers/functions/ParseImageListFromJsonResponseTest.java b/rackspace/src/test/java/org/jclouds/rackspace/cloudservers/functions/ParseImageListFromJsonResponseTest.java index 1d8ae919c9..f167dd00b6 100644 --- a/rackspace/src/test/java/org/jclouds/rackspace/cloudservers/functions/ParseImageListFromJsonResponseTest.java +++ b/rackspace/src/test/java/org/jclouds/rackspace/cloudservers/functions/ParseImageListFromJsonResponseTest.java @@ -26,9 +26,9 @@ import java.util.List; import org.jclouds.date.DateService; import org.jclouds.http.HttpResponse; -import org.jclouds.http.Payloads; import org.jclouds.http.functions.UnwrapOnlyJsonValue; import org.jclouds.http.functions.config.ParserModule; +import org.jclouds.io.Payloads; import org.jclouds.rackspace.cloudservers.domain.Image; import org.jclouds.rackspace.cloudservers.domain.ImageStatus; import org.testng.annotations.Test; diff --git a/rackspace/src/test/java/org/jclouds/rackspace/cloudservers/functions/ParseInetAddressListFromJsonResponseTest.java b/rackspace/src/test/java/org/jclouds/rackspace/cloudservers/functions/ParseInetAddressListFromJsonResponseTest.java index 4a7df56fb7..8e8a333f0c 100644 --- a/rackspace/src/test/java/org/jclouds/rackspace/cloudservers/functions/ParseInetAddressListFromJsonResponseTest.java +++ b/rackspace/src/test/java/org/jclouds/rackspace/cloudservers/functions/ParseInetAddressListFromJsonResponseTest.java @@ -25,9 +25,9 @@ import java.net.UnknownHostException; import java.util.List; import org.jclouds.http.HttpResponse; -import org.jclouds.http.Payloads; import org.jclouds.http.functions.UnwrapOnlyJsonValue; import org.jclouds.http.functions.config.ParserModule; +import org.jclouds.io.Payloads; import org.testng.annotations.Test; import com.google.inject.Guice; diff --git a/rackspace/src/test/java/org/jclouds/rackspace/cloudservers/functions/ParseServerFromJsonResponseTest.java b/rackspace/src/test/java/org/jclouds/rackspace/cloudservers/functions/ParseServerFromJsonResponseTest.java index 4ed4ebb66d..d3a5d501c1 100644 --- a/rackspace/src/test/java/org/jclouds/rackspace/cloudservers/functions/ParseServerFromJsonResponseTest.java +++ b/rackspace/src/test/java/org/jclouds/rackspace/cloudservers/functions/ParseServerFromJsonResponseTest.java @@ -25,9 +25,9 @@ import java.net.UnknownHostException; import java.util.List; import org.jclouds.http.HttpResponse; -import org.jclouds.http.Payloads; import org.jclouds.http.functions.UnwrapOnlyJsonValue; import org.jclouds.http.functions.config.ParserModule; +import org.jclouds.io.Payloads; import org.jclouds.rackspace.cloudservers.domain.Addresses; import org.jclouds.rackspace.cloudservers.domain.Server; import org.jclouds.rackspace.cloudservers.domain.ServerStatus; diff --git a/rackspace/src/test/java/org/jclouds/rackspace/cloudservers/functions/ParseServerListFromJsonResponseTest.java b/rackspace/src/test/java/org/jclouds/rackspace/cloudservers/functions/ParseServerListFromJsonResponseTest.java index 07279f1d61..39114de032 100644 --- a/rackspace/src/test/java/org/jclouds/rackspace/cloudservers/functions/ParseServerListFromJsonResponseTest.java +++ b/rackspace/src/test/java/org/jclouds/rackspace/cloudservers/functions/ParseServerListFromJsonResponseTest.java @@ -25,9 +25,9 @@ import java.net.UnknownHostException; import java.util.List; import org.jclouds.http.HttpResponse; -import org.jclouds.http.Payloads; import org.jclouds.http.functions.UnwrapOnlyJsonValue; import org.jclouds.http.functions.config.ParserModule; +import org.jclouds.io.Payloads; import org.jclouds.rackspace.cloudservers.domain.Addresses; import org.jclouds.rackspace.cloudservers.domain.Server; import org.jclouds.rackspace.cloudservers.domain.ServerStatus; diff --git a/rackspace/src/test/java/org/jclouds/rackspace/cloudservers/functions/ParseSharedIpGroupFromJsonResponseTest.java b/rackspace/src/test/java/org/jclouds/rackspace/cloudservers/functions/ParseSharedIpGroupFromJsonResponseTest.java index a105038045..287e41eaa5 100644 --- a/rackspace/src/test/java/org/jclouds/rackspace/cloudservers/functions/ParseSharedIpGroupFromJsonResponseTest.java +++ b/rackspace/src/test/java/org/jclouds/rackspace/cloudservers/functions/ParseSharedIpGroupFromJsonResponseTest.java @@ -24,9 +24,9 @@ import java.io.InputStream; import java.net.UnknownHostException; import org.jclouds.http.HttpResponse; -import org.jclouds.http.Payloads; import org.jclouds.http.functions.UnwrapOnlyJsonValue; import org.jclouds.http.functions.config.ParserModule; +import org.jclouds.io.Payloads; import org.jclouds.rackspace.cloudservers.domain.SharedIpGroup; import org.testng.annotations.Test; diff --git a/rackspace/src/test/java/org/jclouds/rackspace/cloudservers/functions/ParseSharedIpGroupListFromJsonResponseTest.java b/rackspace/src/test/java/org/jclouds/rackspace/cloudservers/functions/ParseSharedIpGroupListFromJsonResponseTest.java index 225e135442..1072dfc77a 100644 --- a/rackspace/src/test/java/org/jclouds/rackspace/cloudservers/functions/ParseSharedIpGroupListFromJsonResponseTest.java +++ b/rackspace/src/test/java/org/jclouds/rackspace/cloudservers/functions/ParseSharedIpGroupListFromJsonResponseTest.java @@ -25,9 +25,9 @@ import java.net.UnknownHostException; import java.util.List; import org.jclouds.http.HttpResponse; -import org.jclouds.http.Payloads; import org.jclouds.http.functions.UnwrapOnlyJsonValue; import org.jclouds.http.functions.config.ParserModule; +import org.jclouds.io.Payloads; import org.jclouds.rackspace.cloudservers.domain.SharedIpGroup; import org.testng.annotations.Test; diff --git a/tools/antcontrib/src/main/java/org/jclouds/tools/ant/taskdefs/compute/ComputeTaskUtils.java b/tools/antcontrib/src/main/java/org/jclouds/tools/ant/taskdefs/compute/ComputeTaskUtils.java index a36d302795..d064d15fda 100644 --- a/tools/antcontrib/src/main/java/org/jclouds/tools/ant/taskdefs/compute/ComputeTaskUtils.java +++ b/tools/antcontrib/src/main/java/org/jclouds/tools/ant/taskdefs/compute/ComputeTaskUtils.java @@ -25,7 +25,6 @@ package org.jclouds.tools.ant.taskdefs.compute; import static org.jclouds.rest.RestContextFactory.getPropertiesFromResource; -import java.io.IOException; import java.net.URI; import java.util.Map; import java.util.NoSuchElementException; @@ -43,16 +42,15 @@ import org.jclouds.compute.domain.TemplateBuilder; import org.jclouds.compute.options.TemplateOptions; import org.jclouds.compute.reference.ComputeServiceConstants; import org.jclouds.domain.Credentials; +import org.jclouds.io.Payloads; import org.jclouds.ssh.jsch.config.JschSshClientModule; import org.jclouds.tools.ant.logging.config.AntLoggingModule; -import com.google.common.base.Charsets; import com.google.common.base.Function; import com.google.common.base.Splitter; import com.google.common.collect.ImmutableSet; import com.google.common.collect.Iterables; import com.google.common.collect.MapMaker; -import com.google.common.io.Files; import com.google.inject.Module; import com.google.inject.Provider; @@ -64,12 +62,12 @@ public class ComputeTaskUtils { /** * - * Creates a Map that associates a uri with a live connection to the compute provider. This is - * done on-demand. + * Creates a Map that associates a uri with a live connection to the compute + * provider. This is done on-demand. * * @param projectProvider - * allows access to the ant project to retrieve default properties needed for compute - * providers. + * allows access to the ant project to retrieve default properties + * needed for compute providers. */ static Map buildComputeMap(final Provider projectProvider) { return new MapMaker().makeComputingMap(new Function() { @@ -79,13 +77,13 @@ public class ComputeTaskUtils { public ComputeServiceContext apply(URI from) { Properties props = getPropertiesFromResource("/rest.properties"); props.putAll(projectProvider.get().getProperties()); - // adding the properties to the factory will allow us to pass alternate endpoints + // adding the properties to the factory will allow us to pass + // alternate endpoints String provider = from.getHost(); Credentials creds = Credentials.parse(from); - return new ComputeServiceContextFactory(props).createContext(provider, - creds.identity, creds.credential, ImmutableSet.of((Module) new AntLoggingModule( - projectProvider.get(), ComputeServiceConstants.COMPUTE_LOGGER), - new JschSshClientModule()), props); + return new ComputeServiceContextFactory(props).createContext(provider, creds.identity, creds.credential, + ImmutableSet.of((Module) new AntLoggingModule(projectProvider.get(), + ComputeServiceConstants.COMPUTE_LOGGER), new JschSshClientModule()), props); } @@ -122,49 +120,31 @@ public class ComputeTaskUtils { template.biggest(); } else { throw new BuildException("size: " + nodeElement.getSize() - + " not supported. valid sizes are smallest, fastest, biggest"); + + " not supported. valid sizes are smallest, fastest, biggest"); } } static TemplateOptions getNodeOptionsFromElement(NodeElement nodeElement) { - TemplateOptions options = new TemplateOptions() - .inboundPorts(getPortsToOpenFromElement(nodeElement)); + TemplateOptions options = new TemplateOptions().inboundPorts(getPortsToOpenFromElement(nodeElement)); addRunScriptToOptionsIfPresentInNodeElement(nodeElement, options); addPrivateKeyToOptionsIfPresentInNodeElement(nodeElement, options); addPublicKeyToOptionsIfPresentInNodeElement(nodeElement, options); return options; } - static void addRunScriptToOptionsIfPresentInNodeElement(NodeElement nodeElement, - TemplateOptions options) { + static void addRunScriptToOptionsIfPresentInNodeElement(NodeElement nodeElement, TemplateOptions options) { if (nodeElement.getRunscript() != null) - try { - options.runScript(Files.toByteArray(nodeElement.getRunscript())); - } catch (IOException e) { - throw new BuildException(e); - } + options.runScript(Payloads.newFilePayload(nodeElement.getRunscript())); } - static void addPrivateKeyToOptionsIfPresentInNodeElement(NodeElement nodeElement, - TemplateOptions options) { + static void addPrivateKeyToOptionsIfPresentInNodeElement(NodeElement nodeElement, TemplateOptions options) { if (nodeElement.getPrivatekeyfile() != null) - try { - options.installPrivateKey(Files.toString(nodeElement.getPrivatekeyfile(), - Charsets.UTF_8)); - } catch (IOException e) { - throw new BuildException(e); - } + options.installPrivateKey(Payloads.newFilePayload(nodeElement.getPrivatekeyfile())); } - static void addPublicKeyToOptionsIfPresentInNodeElement(NodeElement nodeElement, - TemplateOptions options) { + static void addPublicKeyToOptionsIfPresentInNodeElement(NodeElement nodeElement, TemplateOptions options) { if (nodeElement.getPrivatekeyfile() != null) - try { - options.authorizePublicKey(Files.toString(nodeElement.getPublickeyfile(), - Charsets.UTF_8)); - } catch (IOException e) { - throw new BuildException(e); - } + options.authorizePublicKey(Payloads.newFilePayload(nodeElement.getPublickeyfile())); } static String ipOrEmptyString(Set set) { diff --git a/vcloud/core/src/test/java/org/jclouds/vcloud/functions/ParseLoginResponseFromHeadersTest.java b/vcloud/core/src/test/java/org/jclouds/vcloud/functions/ParseLoginResponseFromHeadersTest.java index 9995b0fcb9..7bd6165a62 100644 --- a/vcloud/core/src/test/java/org/jclouds/vcloud/functions/ParseLoginResponseFromHeadersTest.java +++ b/vcloud/core/src/test/java/org/jclouds/vcloud/functions/ParseLoginResponseFromHeadersTest.java @@ -25,8 +25,8 @@ import java.net.URI; import javax.ws.rs.core.HttpHeaders; import org.jclouds.http.HttpResponse; -import org.jclouds.http.Payloads; import org.jclouds.http.functions.BaseHandlerTest; +import org.jclouds.io.Payloads; import org.jclouds.vcloud.VCloudMediaType; import org.jclouds.vcloud.domain.internal.NamedResourceImpl; import org.jclouds.vcloud.internal.VCloudLoginAsyncClient.VCloudSession; diff --git a/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/compute/options/TerremarkVCloudTemplateOptions.java b/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/compute/options/TerremarkVCloudTemplateOptions.java index d2cdd07df5..aa4eb87920 100644 --- a/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/compute/options/TerremarkVCloudTemplateOptions.java +++ b/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/compute/options/TerremarkVCloudTemplateOptions.java @@ -24,6 +24,7 @@ import static com.google.common.base.Preconditions.checkState; import java.util.Arrays; import org.jclouds.compute.options.TemplateOptions; +import org.jclouds.io.Payload; import org.jclouds.util.Utils; /** @@ -55,10 +56,8 @@ public class TerremarkVCloudTemplateOptions extends TemplateOptions { * Specifies the keypair used to run instances with */ public TerremarkVCloudTemplateOptions sshKeyFingerprint(String keyPair) { - checkNotNull(keyPair, - "use noKeyPair option to request boot without a keypair"); - checkState(!noKeyPair, - "you cannot specify both options keyPair and noKeyPair"); + checkNotNull(keyPair, "use noKeyPair option to request boot without a keypair"); + checkState(!noKeyPair, "you cannot specify both options keyPair and noKeyPair"); Utils.checkNotEmpty(keyPair, "keypair must be non-empty"); this.keyPair = keyPair; return this; @@ -68,8 +67,7 @@ public class TerremarkVCloudTemplateOptions extends TemplateOptions { * Do not use a keypair on instances */ public TerremarkVCloudTemplateOptions noKeyPair() { - checkState(keyPair == null, - "you cannot specify both options keyPair and noKeyPair"); + checkState(keyPair == null, "you cannot specify both options keyPair and noKeyPair"); this.noKeyPair = true; return this; } @@ -79,11 +77,9 @@ public class TerremarkVCloudTemplateOptions extends TemplateOptions { /** * @see TerremarkVCloudTemplateOptions#sshKeyFingerprint */ - public static TerremarkVCloudTemplateOptions sshKeyFingerprint( - String keyPair) { + public static TerremarkVCloudTemplateOptions sshKeyFingerprint(String keyPair) { TerremarkVCloudTemplateOptions options = new TerremarkVCloudTemplateOptions(); - return TerremarkVCloudTemplateOptions.class.cast(options - .sshKeyFingerprint(keyPair)); + return TerremarkVCloudTemplateOptions.class.cast(options.sshKeyFingerprint(keyPair)); } /** @@ -100,28 +96,23 @@ public class TerremarkVCloudTemplateOptions extends TemplateOptions { */ public static TerremarkVCloudTemplateOptions inboundPorts(int... ports) { TerremarkVCloudTemplateOptions options = new TerremarkVCloudTemplateOptions(); - return TerremarkVCloudTemplateOptions.class.cast(options - .inboundPorts(ports)); + return TerremarkVCloudTemplateOptions.class.cast(options.inboundPorts(ports)); } /** * @see TemplateOptions#port */ - public static TerremarkVCloudTemplateOptions blockOnPort(int port, - int seconds) { + public static TerremarkVCloudTemplateOptions blockOnPort(int port, int seconds) { TerremarkVCloudTemplateOptions options = new TerremarkVCloudTemplateOptions(); - return TerremarkVCloudTemplateOptions.class.cast(options.blockOnPort( - port, seconds)); + return TerremarkVCloudTemplateOptions.class.cast(options.blockOnPort(port, seconds)); } /** * @see TemplateOptions#blockUntilRunning */ - public static TerremarkVCloudTemplateOptions blockUntilRunning( - boolean blockUntilRunning) { + public static TerremarkVCloudTemplateOptions blockUntilRunning(boolean blockUntilRunning) { TerremarkVCloudTemplateOptions options = new TerremarkVCloudTemplateOptions(); - return TerremarkVCloudTemplateOptions.class.cast(options - .blockUntilRunning(blockUntilRunning)); + return TerremarkVCloudTemplateOptions.class.cast(options.blockUntilRunning(blockUntilRunning)); } /** @@ -129,28 +120,23 @@ public class TerremarkVCloudTemplateOptions extends TemplateOptions { */ public static TerremarkVCloudTemplateOptions runScript(byte[] script) { TerremarkVCloudTemplateOptions options = new TerremarkVCloudTemplateOptions(); - return TerremarkVCloudTemplateOptions.class.cast(options - .runScript(script)); + return TerremarkVCloudTemplateOptions.class.cast(options.runScript(script)); } /** * @see TemplateOptions#installPrivateKey */ - public static TerremarkVCloudTemplateOptions installPrivateKey( - String rsaKey) { + public static TerremarkVCloudTemplateOptions installPrivateKey(String rsaKey) { TerremarkVCloudTemplateOptions options = new TerremarkVCloudTemplateOptions(); - return TerremarkVCloudTemplateOptions.class.cast(options - .installPrivateKey(rsaKey)); + return TerremarkVCloudTemplateOptions.class.cast(options.installPrivateKey(rsaKey)); } /** * @see TemplateOptions#authorizePublicKey */ - public static TerremarkVCloudTemplateOptions authorizePublicKey( - String rsaKey) { + public static TerremarkVCloudTemplateOptions authorizePublicKey(String rsaKey) { TerremarkVCloudTemplateOptions options = new TerremarkVCloudTemplateOptions(); - return TerremarkVCloudTemplateOptions.class.cast(options - .authorizePublicKey(rsaKey)); + return TerremarkVCloudTemplateOptions.class.cast(options.authorizePublicKey(rsaKey)); } /** @@ -158,30 +144,19 @@ public class TerremarkVCloudTemplateOptions extends TemplateOptions { */ public static TerremarkVCloudTemplateOptions withDetails() { TerremarkVCloudTemplateOptions options = new TerremarkVCloudTemplateOptions(); - return TerremarkVCloudTemplateOptions.class.cast(options - .withMetadata()); + return TerremarkVCloudTemplateOptions.class.cast(options.withMetadata()); } } // methods that only facilitate returning the correct object type - /** - * @see TemplateOptions#authorizePublicKey - */ - @Override - public TerremarkVCloudTemplateOptions authorizePublicKey(String publicKey) { - return TerremarkVCloudTemplateOptions.class.cast(super - .authorizePublicKey(publicKey)); - } - /** * @see TemplateOptions#blockOnPort */ @Override public TerremarkVCloudTemplateOptions blockOnPort(int port, int seconds) { - return TerremarkVCloudTemplateOptions.class.cast(super.blockOnPort(port, - seconds)); + return TerremarkVCloudTemplateOptions.class.cast(super.blockOnPort(port, seconds)); } /** @@ -195,23 +170,56 @@ public class TerremarkVCloudTemplateOptions extends TemplateOptions { */ @Override public TerremarkVCloudTemplateOptions inboundPorts(int... ports) { - return TerremarkVCloudTemplateOptions.class.cast(super - .inboundPorts(ports)); + return TerremarkVCloudTemplateOptions.class.cast(super.inboundPorts(ports)); } /** - * @see TemplateOptions#installPrivateKey + * @see TemplateOptions#authorizePublicKey(String) */ @Override + @Deprecated + public TerremarkVCloudTemplateOptions authorizePublicKey(String publicKey) { + return TerremarkVCloudTemplateOptions.class.cast(super.authorizePublicKey(publicKey)); + } + + /** + * @see TemplateOptions#authorizePublicKey(Payload) + */ + @Override + public TerremarkVCloudTemplateOptions authorizePublicKey(Payload publicKey) { + return TerremarkVCloudTemplateOptions.class.cast(super.authorizePublicKey(publicKey)); + } + + /** + * @see TemplateOptions#installPrivateKey(String) + */ + @Override + @Deprecated public TerremarkVCloudTemplateOptions installPrivateKey(String privateKey) { - return TerremarkVCloudTemplateOptions.class.cast(super - .installPrivateKey(privateKey)); + return TerremarkVCloudTemplateOptions.class.cast(super.installPrivateKey(privateKey)); } /** - * @see TemplateOptions#runScript + * @see TemplateOptions#installPrivateKey(Payload) */ @Override + public TerremarkVCloudTemplateOptions installPrivateKey(Payload privateKey) { + return TerremarkVCloudTemplateOptions.class.cast(super.installPrivateKey(privateKey)); + } + + /** + * @see TemplateOptions#runScript(Payload) + */ + @Override + public TerremarkVCloudTemplateOptions runScript(Payload script) { + return TerremarkVCloudTemplateOptions.class.cast(super.runScript(script)); + } + + /** + * @see TemplateOptions#runScript(byte[]) + */ + @Override + @Deprecated public TerremarkVCloudTemplateOptions runScript(byte[] script) { return TerremarkVCloudTemplateOptions.class.cast(super.runScript(script)); } @@ -269,12 +277,10 @@ public class TerremarkVCloudTemplateOptions extends TemplateOptions { @Override public String toString() { - return "TerremarkVCloudTemplateOptions [keyPair=" + keyPair - + ", noKeyPair=" + noKeyPair + ", inboundPorts=" - + Arrays.toString(inboundPorts) + ", privateKey=" - + (privateKey != null) + ", publicKey=" + (publicKey != null) - + ", runScript=" + (script != null) + ", port:seconds=" + port - + ":" + seconds + ", metadata/details: " + includeMetadata + "]"; + return "TerremarkVCloudTemplateOptions [keyPair=" + keyPair + ", noKeyPair=" + noKeyPair + ", inboundPorts=" + + Arrays.toString(inboundPorts) + ", privateKey=" + (privateKey != null) + ", publicKey=" + + (publicKey != null) + ", runScript=" + (script != null) + ", port:seconds=" + port + ":" + seconds + + ", metadata/details: " + includeMetadata + "]"; } } diff --git a/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/compute/TerremarkVCloudTemplateOptionsTest.java b/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/compute/TerremarkVCloudTemplateOptionsTest.java index 60e99f1b83..e8880001a2 100644 --- a/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/compute/TerremarkVCloudTemplateOptionsTest.java +++ b/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/compute/TerremarkVCloudTemplateOptionsTest.java @@ -8,7 +8,10 @@ import static org.jclouds.vcloud.terremark.compute.options.TerremarkVCloudTempla import static org.jclouds.vcloud.terremark.compute.options.TerremarkVCloudTemplateOptions.Builder.sshKeyFingerprint; import static org.testng.Assert.assertEquals; +import java.io.IOException; + import org.jclouds.compute.options.TemplateOptions; +import org.jclouds.util.Utils; import org.jclouds.vcloud.terremark.compute.options.TerremarkVCloudTemplateOptions; import org.testng.annotations.Test; @@ -92,17 +95,19 @@ public class TerremarkVCloudTemplateOptionsTest { } // superclass tests + @SuppressWarnings("deprecation") @Test(expectedExceptions = IllegalArgumentException.class) public void testinstallPrivateKeyBadFormat() { TerremarkVCloudTemplateOptions options = new TerremarkVCloudTemplateOptions(); options.installPrivateKey("whompy"); } + @SuppressWarnings("deprecation") @Test - public void testinstallPrivateKey() { + public void testinstallPrivateKey() throws IOException { TerremarkVCloudTemplateOptions options = new TerremarkVCloudTemplateOptions(); options.installPrivateKey("-----BEGIN RSA PRIVATE KEY-----"); - assertEquals(options.getPrivateKey(), "-----BEGIN RSA PRIVATE KEY-----"); + assertEquals(Utils.toStringAndClose(options.getPrivateKey().getInput()), "-----BEGIN RSA PRIVATE KEY-----"); } @Test @@ -112,9 +117,9 @@ public class TerremarkVCloudTemplateOptionsTest { } @Test - public void testinstallPrivateKeyStatic() { + public void testinstallPrivateKeyStatic() throws IOException { TerremarkVCloudTemplateOptions options = installPrivateKey("-----BEGIN RSA PRIVATE KEY-----"); - assertEquals(options.getPrivateKey(), "-----BEGIN RSA PRIVATE KEY-----"); + assertEquals(Utils.toStringAndClose(options.getPrivateKey().getInput()), "-----BEGIN RSA PRIVATE KEY-----"); } @Test(expectedExceptions = NullPointerException.class) @@ -122,17 +127,19 @@ public class TerremarkVCloudTemplateOptionsTest { installPrivateKey(null); } + @SuppressWarnings("deprecation") @Test(expectedExceptions = IllegalArgumentException.class) public void testauthorizePublicKeyBadFormat() { TerremarkVCloudTemplateOptions options = new TerremarkVCloudTemplateOptions(); options.authorizePublicKey("whompy"); } + @SuppressWarnings("deprecation") @Test - public void testauthorizePublicKey() { + public void testauthorizePublicKey() throws IOException { TerremarkVCloudTemplateOptions options = new TerremarkVCloudTemplateOptions(); options.authorizePublicKey("ssh-rsa"); - assertEquals(options.getPublicKey(), "ssh-rsa"); + assertEquals(Utils.toStringAndClose(options.getPublicKey().getInput()), "ssh-rsa"); } @Test @@ -142,9 +149,9 @@ public class TerremarkVCloudTemplateOptionsTest { } @Test - public void testauthorizePublicKeyStatic() { + public void testauthorizePublicKeyStatic() throws IOException { TerremarkVCloudTemplateOptions options = authorizePublicKey("ssh-rsa"); - assertEquals(options.getPublicKey(), "ssh-rsa"); + assertEquals(Utils.toStringAndClose(options.getPublicKey().getInput()), "ssh-rsa"); } @Test(expectedExceptions = NullPointerException.class)