Issue 316: refactored ssh to use Payload object; deprecated non-payload methods

This commit is contained in:
Adrian Cole 2010-07-19 13:08:12 -07:00
parent 45450e1b8f
commit 887bb7adfe
131 changed files with 1391 additions and 1350 deletions

View File

@ -26,10 +26,10 @@ import org.jclouds.atmosonline.saas.domain.AtmosObject;
import org.jclouds.atmosonline.saas.domain.MutableContentMetadata; import org.jclouds.atmosonline.saas.domain.MutableContentMetadata;
import org.jclouds.atmosonline.saas.domain.SystemMetadata; import org.jclouds.atmosonline.saas.domain.SystemMetadata;
import org.jclouds.atmosonline.saas.domain.UserMetadata; import org.jclouds.atmosonline.saas.domain.UserMetadata;
import org.jclouds.http.Payload;
import org.jclouds.http.PayloadEnclosing; import org.jclouds.http.PayloadEnclosing;
import org.jclouds.http.internal.PayloadEnclosingImpl; 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.LinkedHashMultimap;
import com.google.common.collect.Multimap; import com.google.common.collect.Multimap;

View File

@ -40,8 +40,8 @@ import org.jclouds.blobstore.KeyAlreadyExistsException;
import org.jclouds.blobstore.KeyNotFoundException; import org.jclouds.blobstore.KeyNotFoundException;
import org.jclouds.blobstore.integration.internal.BaseBlobStoreIntegrationTest; import org.jclouds.blobstore.integration.internal.BaseBlobStoreIntegrationTest;
import org.jclouds.http.HttpResponseException; import org.jclouds.http.HttpResponseException;
import org.jclouds.http.Payloads; import org.jclouds.io.Payloads;
import org.jclouds.http.payloads.InputStreamPayload; import org.jclouds.io.payloads.InputStreamPayload;
import org.jclouds.logging.log4j.config.Log4JLoggingModule; import org.jclouds.logging.log4j.config.Log4JLoggingModule;
import org.jclouds.rest.RestContext; import org.jclouds.rest.RestContext;
import org.jclouds.util.Utils; import org.jclouds.util.Utils;

View File

@ -25,7 +25,7 @@ import org.jclouds.atmosonline.saas.domain.SystemMetadata;
import org.jclouds.date.DateService; import org.jclouds.date.DateService;
import org.jclouds.encryption.EncryptionService; import org.jclouds.encryption.EncryptionService;
import org.jclouds.http.HttpResponse; import org.jclouds.http.HttpResponse;
import org.jclouds.http.Payloads; import org.jclouds.io.Payloads;
import org.testng.annotations.Test; import org.testng.annotations.Test;
import com.google.inject.Guice; import com.google.inject.Guice;

View File

@ -26,17 +26,18 @@ import java.util.Arrays;
import java.util.Set; import java.util.Set;
import org.jclouds.compute.options.TemplateOptions; import org.jclouds.compute.options.TemplateOptions;
import org.jclouds.io.Payload;
import org.jclouds.util.Utils; import org.jclouds.util.Utils;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Iterables; import com.google.common.collect.Iterables;
/** /**
* Contains options supported in the {@code ComputeService#runNode} operation on the "ec2" provider. * Contains options supported in the {@code ComputeService#runNode} operation on
* <h2> * the "ec2" provider. <h2>
* Usage</h2> The recommended way to instantiate a EC2TemplateOptions object is to statically import * Usage</h2> The recommended way to instantiate a EC2TemplateOptions object is
* EC2TemplateOptions.* and invoke a static creation method followed by an instance mutator (if * to statically import EC2TemplateOptions.* and invoke a static creation method
* needed): * followed by an instance mutator (if needed):
* <p/> * <p/>
* <code> * <code>
* import static org.jclouds.aws.ec2.compute.options.EC2TemplateOptions.Builder.*; * 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 // 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 * @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 * special thing is that we do assume if you are passing groups that you have
* already defined. for example, our option inboundPorts normally creates ingress rules * everything you need already defined. for example, our option inboundPorts
* accordingly but if we notice you've specified securityGroups, we do not mess with rules at all * normally creates ingress rules accordingly but if we notice you've
* specified securityGroups, we do not mess with rules at all
* *
* @see TemplateOptions#inboundPorts * @see TemplateOptions#inboundPorts
*/ */
@ -269,17 +263,52 @@ public class EC2TemplateOptions extends TemplateOptions {
} }
/** /**
* @see TemplateOptions#installPrivateKey * @see TemplateOptions#authorizePublicKey(String)
*/ */
@Override @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) { public EC2TemplateOptions installPrivateKey(String privateKey) {
return EC2TemplateOptions.class.cast(super.installPrivateKey(privateKey)); return EC2TemplateOptions.class.cast(super.installPrivateKey(privateKey));
} }
/** /**
* @see TemplateOptions#runScript * @see TemplateOptions#installPrivateKey(Payload)
*/ */
@Override @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) { public EC2TemplateOptions runScript(byte[] script) {
return EC2TemplateOptions.class.cast(super.runScript(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 * @return groupIds the user specified to run instances with, or zero length
* implicit group * set to create an implicit group
*/ */
public Set<String> getGroupIds() { public Set<String> getGroupIds() {
return groupIds; 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() { public String getKeyPair() {
return keyPair; 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() { public String getPlacementGroup() {
return placementGroup; return placementGroup;
@ -387,10 +418,10 @@ public class EC2TemplateOptions extends TemplateOptions {
@Override @Override
public String toString() { public String toString() {
return "[groupIds=" + groupIds + ", keyPair=" + keyPair + ", noKeyPair=" + noKeyPair + ", placementGroup=" return "[groupIds=" + groupIds + ", keyPair=" + keyPair + ", noKeyPair=" + noKeyPair + ", placementGroup="
+ placementGroup + ", noPlacementGroup=" + noPlacementGroup + ", inboundPorts=" + placementGroup + ", noPlacementGroup=" + noPlacementGroup + ", inboundPorts="
+ Arrays.toString(inboundPorts) + ", privateKey=" + (privateKey != null) + ", publicKey=" + Arrays.toString(inboundPorts) + ", privateKey=" + (privateKey != null) + ", publicKey="
+ (publicKey != null) + ", runScript=" + (script != null) + ", port:seconds=" + port + ":" + seconds + (publicKey != null) + ", runScript=" + (script != null) + ", port:seconds=" + port + ":" + seconds
+ ", subnetId=" + subnetId + ", metadata/details: " + includeMetadata + "]"; + ", subnetId=" + subnetId + ", metadata/details: " + includeMetadata + "]";
} }
} }

View File

@ -25,10 +25,10 @@ import javax.inject.Inject;
import org.jclouds.aws.s3.domain.AccessControlList; import org.jclouds.aws.s3.domain.AccessControlList;
import org.jclouds.aws.s3.domain.MutableObjectMetadata; import org.jclouds.aws.s3.domain.MutableObjectMetadata;
import org.jclouds.aws.s3.domain.S3Object; import org.jclouds.aws.s3.domain.S3Object;
import org.jclouds.http.Payload;
import org.jclouds.http.PayloadEnclosing; import org.jclouds.http.PayloadEnclosing;
import org.jclouds.http.internal.PayloadEnclosingImpl; 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.LinkedHashMultimap;
import com.google.common.collect.Multimap; import com.google.common.collect.Multimap;

View File

@ -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.assertEquals;
import static org.testng.Assert.assertNotNull; import static org.testng.Assert.assertNotNull;
import java.io.ByteArrayInputStream;
import java.io.IOException; import java.io.IOException;
import java.net.UnknownHostException; import java.net.UnknownHostException;
import java.util.Map; 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.VolumeAttached;
import org.jclouds.aws.ec2.predicates.VolumeAvailable; import org.jclouds.aws.ec2.predicates.VolumeAvailable;
import org.jclouds.http.HttpResponseException; import org.jclouds.http.HttpResponseException;
import org.jclouds.io.Payloads;
import org.jclouds.logging.log4j.config.Log4JLoggingModule; import org.jclouds.logging.log4j.config.Log4JLoggingModule;
import org.jclouds.net.IPSocket; import org.jclouds.net.IPSocket;
import org.jclouds.predicates.RetryablePredicate; import org.jclouds.predicates.RetryablePredicate;
@ -81,8 +81,8 @@ import com.google.inject.Module;
import com.google.inject.internal.ImmutableMap; import com.google.inject.internal.ImmutableMap;
/** /**
* Adapted from the following sources: {@link http://gist.github.com/249915}, {@link http * Adapted from the following sources: {@link http://gist.github.com/249915},
* ://www.capsunlock.net/2009/12/create-ebs-boot-ami.html} * {@link http ://www.capsunlock.net/2009/12/create-ebs-boot-ami.html}
* <p/> * <p/>
* *
* Generally disabled, as it incurs higher fees. * 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 identity = checkNotNull(System.getProperty("jclouds.test.identity"), "jclouds.test.identity");
String credential = checkNotNull(System.getProperty("jclouds.test.credential"), "jclouds.test.credential"); String credential = checkNotNull(System.getProperty("jclouds.test.credential"), "jclouds.test.credential");
Injector injector = new RestContextFactory().createContextBuilder("ec2", identity, credential, Injector injector = new RestContextFactory().createContextBuilder("ec2", identity, credential,
ImmutableSet.<Module> of(new Log4JLoggingModule())).buildInjector(); ImmutableSet.<Module> of(new Log4JLoggingModule())).buildInjector();
client = injector.getInstance(EC2Client.class); client = injector.getInstance(EC2Client.class);
sshFactory = injector.getInstance(SshClient.Factory.class); sshFactory = injector.getInstance(SshClient.Factory.class);
SocketOpen socketOpen = injector.getInstance(SocketOpen.class); SocketOpen socketOpen = injector.getInstance(SocketOpen.class);
@ -138,24 +138,20 @@ public class EBSBootEC2ClientLiveTest {
VolumeAttached volumeAttached = injector.getInstance(VolumeAttached.class); VolumeAttached volumeAttached = injector.getInstance(VolumeAttached.class);
attachTester = new RetryablePredicate<Attachment>(volumeAttached, 60, 1, TimeUnit.SECONDS); attachTester = new RetryablePredicate<Attachment>(volumeAttached, 60, 1, TimeUnit.SECONDS);
runningTester = new RetryablePredicate<RunningInstance>(new InstanceStateRunning(client), runningTester = new RetryablePredicate<RunningInstance>(new InstanceStateRunning(client), 180, 5,
180, 5, TimeUnit.SECONDS); TimeUnit.SECONDS);
InstanceStateStopped instanceStateStopped = injector.getInstance(InstanceStateStopped.class); InstanceStateStopped instanceStateStopped = injector.getInstance(InstanceStateStopped.class);
stoppedTester = new RetryablePredicate<RunningInstance>(instanceStateStopped, 60, 1, stoppedTester = new RetryablePredicate<RunningInstance>(instanceStateStopped, 60, 1, TimeUnit.SECONDS);
TimeUnit.SECONDS);
InstanceStateTerminated instanceStateTerminated = injector InstanceStateTerminated instanceStateTerminated = injector.getInstance(InstanceStateTerminated.class);
.getInstance(InstanceStateTerminated.class); terminatedTester = new RetryablePredicate<RunningInstance>(instanceStateTerminated, 60, 1, TimeUnit.SECONDS);
terminatedTester = new RetryablePredicate<RunningInstance>(instanceStateTerminated, 60, 1,
TimeUnit.SECONDS);
injector.injectMembers(socketOpen); // add logger injector.injectMembers(socketOpen); // add logger
} }
@Test(enabled = false) @Test(enabled = false)
void testCreateSecurityGroupIngressCidr() throws InterruptedException, ExecutionException, void testCreateSecurityGroupIngressCidr() throws InterruptedException, ExecutionException, TimeoutException {
TimeoutException {
securityGroupName = INSTANCE_PREFIX + "ingress"; securityGroupName = INSTANCE_PREFIX + "ingress";
try { try {
@ -163,14 +159,13 @@ public class EBSBootEC2ClientLiveTest {
} catch (Exception e) { } catch (Exception e) {
} }
client.getSecurityGroupServices().createSecurityGroupInRegion(null, securityGroupName, client.getSecurityGroupServices().createSecurityGroupInRegion(null, securityGroupName, securityGroupName);
securityGroupName); client.getSecurityGroupServices().authorizeSecurityGroupIngressInRegion(null, securityGroupName, IpProtocol.TCP,
client.getSecurityGroupServices().authorizeSecurityGroupIngressInRegion(null, 80, 80, "0.0.0.0/0");
securityGroupName, IpProtocol.TCP, 80, 80, "0.0.0.0/0"); client.getSecurityGroupServices().authorizeSecurityGroupIngressInRegion(null, securityGroupName, IpProtocol.TCP,
client.getSecurityGroupServices().authorizeSecurityGroupIngressInRegion(null, 443, 443, "0.0.0.0/0");
securityGroupName, IpProtocol.TCP, 443, 443, "0.0.0.0/0"); client.getSecurityGroupServices().authorizeSecurityGroupIngressInRegion(null, securityGroupName, IpProtocol.TCP,
client.getSecurityGroupServices().authorizeSecurityGroupIngressInRegion(null, 22, 22, "0.0.0.0/0");
securityGroupName, IpProtocol.TCP, 22, 22, "0.0.0.0/0");
} }
@Test(enabled = false) @Test(enabled = false)
@ -189,8 +184,7 @@ public class EBSBootEC2ClientLiveTest {
assertEquals(keyPair.getKeyName(), keyName); assertEquals(keyPair.getKeyName(), keyName);
} }
@Test(enabled = false, dependsOnMethods = { "testCreateKeyPair", @Test(enabled = false, dependsOnMethods = { "testCreateKeyPair", "testCreateSecurityGroupIngressCidr" })
"testCreateSecurityGroupIngressCidr" })
public void testCreateRunningInstance() throws Exception { public void testCreateRunningInstance() throws Exception {
instance = createInstance(IMAGE_ID); instance = createInstance(IMAGE_ID);
} }
@ -201,18 +195,18 @@ public class EBSBootEC2ClientLiveTest {
try { try {
System.out.printf("%d: running instance%n", System.currentTimeMillis()); System.out.printf("%d: running instance%n", System.currentTimeMillis());
Reservation reservation = client.getInstanceServices().runInstancesInRegion(null, null, // allow Reservation reservation = client.getInstanceServices().runInstancesInRegion(null, null, // allow
// ec2 // ec2
// to // to
// chose // chose
// an // an
// availability // availability
// zone // zone
imageId, 1, // minimum instances imageId, 1, // minimum instances
1, // maximum instances 1, // maximum instances
withKeyName(keyPair.getKeyName())// key I created above withKeyName(keyPair.getKeyName())// key I created above
.asType(InstanceType.M1_SMALL)// smallest instance .asType(InstanceType.M1_SMALL)// smallest instance
// size // size
.withSecurityGroup(securityGroupName));// group I .withSecurityGroup(securityGroupName));// group I
// created // created
// above // above
instance = Iterables.getOnlyElement(reservation); instance = Iterables.getOnlyElement(reservation);
@ -230,22 +224,19 @@ public class EBSBootEC2ClientLiveTest {
@Test(enabled = false, dependsOnMethods = "testCreateRunningInstance") @Test(enabled = false, dependsOnMethods = "testCreateRunningInstance")
void testCreateAndAttachVolume() { void testCreateAndAttachVolume() {
volume = client.getElasticBlockStoreServices().createVolumeInAvailabilityZone( volume = client.getElasticBlockStoreServices().createVolumeInAvailabilityZone(instance.getAvailabilityZone(),
instance.getAvailabilityZone(), VOLUME_SIZE); VOLUME_SIZE);
System.out.printf("%d: %s awaiting volume to become available%n", System.currentTimeMillis(), System.out.printf("%d: %s awaiting volume to become available%n", System.currentTimeMillis(), volume.getId());
volume.getId());
assert volumeTester.apply(volume); assert volumeTester.apply(volume);
Attachment attachment = client.getElasticBlockStoreServices().attachVolumeInRegion( Attachment attachment = client.getElasticBlockStoreServices().attachVolumeInRegion(instance.getRegion(),
instance.getRegion(), volume.getId(), instance.getId(), "/dev/sdh"); volume.getId(), instance.getId(), "/dev/sdh");
System.out.printf("%d: %s awaiting attachment to complete%n", System.currentTimeMillis(), System.out.printf("%d: %s awaiting attachment to complete%n", System.currentTimeMillis(), attachment.getId());
attachment.getId());
assert attachTester.apply(attachment); assert attachTester.apply(attachment);
System.out.printf("%d: %s attachment complete%n", System.currentTimeMillis(), attachment System.out.printf("%d: %s attachment complete%n", System.currentTimeMillis(), attachment.getId());
.getId());
} }
// TODO use userData to do this, and make initbuilder an example for // TODO use userData to do this, and make initbuilder an example for
@ -254,34 +245,35 @@ public class EBSBootEC2ClientLiveTest {
void makeScript() { void makeScript() {
mkEbsBoot = new InitBuilder( mkEbsBoot = new InitBuilder(
"mkebsboot",// name of the script "mkebsboot",// name of the script
"/tmp",// working directory "/tmp",// working directory
"/tmp/logs",// location of stdout.log and stderr.log "/tmp/logs",// location of stdout.log and stderr.log
ImmutableMap.of("imageDir", "/mnt/tmp", "ebsDevice", "/dev/sdh", "ebsMountPoint", ImmutableMap.of("imageDir", "/mnt/tmp", "ebsDevice", "/dev/sdh", "ebsMountPoint", "/mnt/ebs"),// variables
"/mnt/ebs"),// variables used inside of the // used
// script // inside
"echo creating a filesystem and mounting the ebs volume",// what to // of
// execute // the
"{md} {varl}IMAGE_DIR{varr} {varl}EBS_MOUNT_POINT{varr}", // script
"rm -rf {varl}IMAGE_DIR{varr}/*", "echo creating a filesystem and mounting the ebs volume",// what to
"yes| mkfs -t ext3 {varl}EBS_DEVICE{varr} 2>&-", // execute
"mount {varl}EBS_DEVICE{varr} {varl}EBS_MOUNT_POINT{varr}", "{md} {varl}IMAGE_DIR{varr} {varl}EBS_MOUNT_POINT{varr}",
"echo making a local working copy of the boot disk", "rm -rf {varl}IMAGE_DIR{varr}/*",
"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}", "yes| mkfs -t ext3 {varl}EBS_DEVICE{varr} 2>&-",
"echo preparing the local working copy", "mount {varl}EBS_DEVICE{varr} {varl}EBS_MOUNT_POINT{varr}",
"touch {varl}IMAGE_DIR{varr}/etc/init.d/ec2-init-user-data", "echo making a local working copy of the boot disk",
"echo copying the local working copy to the ebs mount", "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}",
"{cd} {varl}IMAGE_DIR{varr}", "echo preparing the local working copy", "touch {varl}IMAGE_DIR{varr}/etc/init.d/ec2-init-user-data",
"tar -cSf - * | tar xf - -C {varl}EBS_MOUNT_POINT{varr}", "echo size of ebs", "echo copying the local working copy to the ebs mount", "{cd} {varl}IMAGE_DIR{varr}",
"du -sk {varl}EBS_MOUNT_POINT{varr}", "echo size of source", "tar -cSf - * | tar xf - -C {varl}EBS_MOUNT_POINT{varr}", "echo size of ebs",
"du -sk {varl}IMAGE_DIR{varr}", "rm -rf {varl}IMAGE_DIR{varr}/*", "du -sk {varl}EBS_MOUNT_POINT{varr}", "echo size of source", "du -sk {varl}IMAGE_DIR{varr}",
"umount {varl}EBS_MOUNT_POINT{varr}", "echo " + SCRIPT_END).build(OsFamily.UNIX); "rm -rf {varl}IMAGE_DIR{varr}/*", "umount {varl}EBS_MOUNT_POINT{varr}", "echo " + SCRIPT_END)
.build(OsFamily.UNIX);
} }
@Test(enabled = false, dependsOnMethods = "testCreateAndAttachVolume") @Test(enabled = false, dependsOnMethods = "testCreateAndAttachVolume")
void testBundleInstance() { void testBundleInstance() {
SshClient ssh = sshFactory.create(new IPSocket(instance.getIpAddress(), 22), "ubuntu", SshClient ssh = sshFactory.create(new IPSocket(instance.getIpAddress(), 22), "ubuntu", keyPair.getKeyMaterial()
keyPair.getKeyMaterial().getBytes()); .getBytes());
try { try {
ssh.connect(); ssh.connect();
} catch (SshException e) {// try twice in case there is a network timeout } catch (SshException e) {// try twice in case there is a network timeout
@ -292,13 +284,11 @@ public class EBSBootEC2ClientLiveTest {
ssh.connect(); ssh.connect();
} }
try { try {
System.out.printf("%d: %s writing ebs script%n", System.currentTimeMillis(), instance System.out.printf("%d: %s writing ebs script%n", System.currentTimeMillis(), instance.getId());
.getId());
String script = "/tmp/mkebsboot-init.sh"; 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 System.out.printf("%d: %s launching ebs script%n", System.currentTimeMillis(), instance.getId());
.getId());
ssh.exec("chmod 755 " + script); ssh.exec("chmod 755 " + script);
ssh.exec(script + " init"); ssh.exec(script + " init");
ExecResponse output = ssh.exec("sudo " + script + " start"); ExecResponse output = ssh.exec("sudo " + script + " start");
@ -307,8 +297,8 @@ public class EBSBootEC2ClientLiveTest {
assert !output.getOutput().trim().equals("") : output; assert !output.getOutput().trim().equals("") : output;
RetryablePredicate<String> scriptTester = new RetryablePredicate<String>(new ScriptTester( RetryablePredicate<String> scriptTester = new RetryablePredicate<String>(new ScriptTester(ssh, SCRIPT_END),
ssh, SCRIPT_END), 600, 10, TimeUnit.SECONDS); 600, 10, TimeUnit.SECONDS);
scriptTester.apply(script); scriptTester.apply(script);
} finally { } finally {
if (ssh != null) if (ssh != null)
@ -338,8 +328,7 @@ public class EBSBootEC2ClientLiveTest {
output = ssh.exec(script + " tailerr"); output = ssh.exec(script + " tailerr");
String stderr = output.getOutput().trim(); String stderr = output.getOutput().trim();
throw new RuntimeException(String.format( throw new RuntimeException(String.format(
"script %s ended without token: stdout.log: [%s]; stderr.log: [%s]; ", "script %s ended without token: stdout.log: [%s]; stderr.log: [%s]; ", script, stdout, stderr));
script, stdout, stderr));
} }
} }
return false; return false;
@ -349,47 +338,43 @@ public class EBSBootEC2ClientLiveTest {
@Test(enabled = false, dependsOnMethods = "testBundleInstance") @Test(enabled = false, dependsOnMethods = "testBundleInstance")
void testAMIFromBundle() { void testAMIFromBundle() {
volume = Iterables.getOnlyElement(client.getElasticBlockStoreServices() volume = Iterables.getOnlyElement(client.getElasticBlockStoreServices().describeVolumesInRegion(
.describeVolumesInRegion(volume.getRegion(), volume.getId())); volume.getRegion(), volume.getId()));
if (volume.getAttachments().size() > 0) { if (volume.getAttachments().size() > 0) {
// should be cleanly unmounted, so force is not necessary. // should be cleanly unmounted, so force is not necessary.
client.getElasticBlockStoreServices().detachVolumeInRegion(instance.getRegion(), client.getElasticBlockStoreServices().detachVolumeInRegion(instance.getRegion(), volume.getId(), false);
volume.getId(), false); System.out.printf("%d: %s awaiting detachment to complete%n", System.currentTimeMillis(), volume.getId());
System.out.printf("%d: %s awaiting detachment to complete%n", System.currentTimeMillis(),
volume.getId());
assert volumeTester.apply(volume); assert volumeTester.apply(volume);
} else { } else {
attachment = null; // protect test closer so that it doesn't try to attachment = null; // protect test closer so that it doesn't try to
// detach // detach
} }
snapshot = client.getElasticBlockStoreServices().createSnapshotInRegion(volume.getRegion(), snapshot = client.getElasticBlockStoreServices().createSnapshotInRegion(volume.getRegion(), volume.getId(),
volume.getId(), withDescription("EBS Ubuntu Hardy")); withDescription("EBS Ubuntu Hardy"));
System.out.printf("%d: %s awaiting snapshot to complete%n", System.currentTimeMillis(), System.out.printf("%d: %s awaiting snapshot to complete%n", System.currentTimeMillis(), snapshot.getId());
snapshot.getId());
assert snapshotTester.apply(snapshot); assert snapshotTester.apply(snapshot);
Image image = Iterables.getOnlyElement(client.getAMIServices().describeImagesInRegion( Image image = Iterables.getOnlyElement(client.getAMIServices().describeImagesInRegion(snapshot.getRegion(),
snapshot.getRegion(), imageIds(IMAGE_ID))); imageIds(IMAGE_ID)));
String description = image.getDescription() == null ? "jclouds" : image.getDescription(); String description = image.getDescription() == null ? "jclouds" : image.getDescription();
System.out.printf("%d: %s creating ami from snapshot%n", System.currentTimeMillis(), snapshot System.out.printf("%d: %s creating ami from snapshot%n", System.currentTimeMillis(), snapshot.getId());
.getId());
String amiId = client.getAMIServices().registerUnixImageBackedByEbsInRegion( String amiId = client.getAMIServices().registerUnixImageBackedByEbsInRegion(
snapshot.getRegion(), snapshot.getRegion(),
"ebsboot-" + image.getId(), "ebsboot-" + image.getId(),
snapshot.getId(), snapshot.getId(),
withKernelId(image.getKernelId()).withRamdisk(image.getRamdiskId()).withDescription( withKernelId(image.getKernelId()).withRamdisk(image.getRamdiskId()).withDescription(description)
description).asArchitecture(Architecture.I386)); .asArchitecture(Architecture.I386));
try { try {
ebsImage = Iterables.getOnlyElement(client.getAMIServices().describeImagesInRegion( ebsImage = Iterables.getOnlyElement(client.getAMIServices().describeImagesInRegion(snapshot.getRegion(),
snapshot.getRegion(), imageIds(amiId))); imageIds(amiId)));
} catch (AWSResponseException e) { } catch (AWSResponseException e) {
// TODO add a retry handler for this HTTP code 400 and the below error // TODO add a retry handler for this HTTP code 400 and the below error
if (e.getError().getClass().equals("InvalidAMIID.NotFound")) if (e.getError().getClass().equals("InvalidAMIID.NotFound"))
ebsImage = Iterables.getOnlyElement(client.getAMIServices().describeImagesInRegion( ebsImage = Iterables.getOnlyElement(client.getAMIServices().describeImagesInRegion(snapshot.getRegion(),
snapshot.getRegion(), imageIds(amiId))); imageIds(amiId)));
else else
throw e; throw e;
} }
@ -398,22 +383,17 @@ public class EBSBootEC2ClientLiveTest {
@Test(enabled = false, dependsOnMethods = { "testAMIFromBundle" }) @Test(enabled = false, dependsOnMethods = { "testAMIFromBundle" })
public void testInstanceFromEBS() throws Exception { public void testInstanceFromEBS() throws Exception {
System.out.printf("%d: %s creating instance from ebs-backed ami%n", System System.out.printf("%d: %s creating instance from ebs-backed ami%n", System.currentTimeMillis(), ebsImage.getId());
.currentTimeMillis(), ebsImage.getId());
ebsInstance = createInstance(ebsImage.getId()); ebsInstance = createInstance(ebsImage.getId());
client.getInstanceServices().stopInstancesInRegion(ebsInstance.getRegion(), true, client.getInstanceServices().stopInstancesInRegion(ebsInstance.getRegion(), true, ebsInstance.getId());
ebsInstance.getId());
System.out.printf("%d: %s awaiting instance to stop %n", System.currentTimeMillis(), System.out.printf("%d: %s awaiting instance to stop %n", System.currentTimeMillis(), ebsInstance.getId());
ebsInstance.getId());
stoppedTester.apply(ebsInstance); stoppedTester.apply(ebsInstance);
tryToChangeStuff(); tryToChangeStuff();
System.out.printf("%d: %s awaiting instance to start %n", System.currentTimeMillis(), System.out.printf("%d: %s awaiting instance to start %n", System.currentTimeMillis(), ebsInstance.getId());
ebsInstance.getId()); client.getInstanceServices().startInstancesInRegion(ebsInstance.getRegion(), ebsInstance.getId());
client.getInstanceServices().startInstancesInRegion(ebsInstance.getRegion(),
ebsInstance.getId());
ebsInstance = blockUntilWeCanSshIntoInstance(ebsInstance); ebsInstance = blockUntilWeCanSshIntoInstance(ebsInstance);
} }
@ -422,7 +402,7 @@ public class EBSBootEC2ClientLiveTest {
assertEquals(ebsImage.getRootDeviceType(), RootDeviceType.EBS); assertEquals(ebsImage.getRootDeviceType(), RootDeviceType.EBS);
assertEquals(ebsImage.getRootDeviceName(), "/dev/sda1"); assertEquals(ebsImage.getRootDeviceName(), "/dev/sda1");
assertEquals(ebsImage.getEbsBlockDevices().entrySet(), ImmutableMap.of("/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() { private void tryToChangeStuff() {
@ -435,53 +415,43 @@ public class EBSBootEC2ClientLiveTest {
} }
private void setUserDataForInstanceInRegion() { private void setUserDataForInstanceInRegion() {
client.getInstanceServices().setUserDataForInstanceInRegion(null, ebsInstance.getId(), client.getInstanceServices().setUserDataForInstanceInRegion(null, ebsInstance.getId(), "test".getBytes());
"test".getBytes()); assertEquals("test", client.getInstanceServices().getUserDataForInstanceInRegion(null, ebsInstance.getId()));
assertEquals("test", client.getInstanceServices().getUserDataForInstanceInRegion(null,
ebsInstance.getId()));
} }
private void setRamdiskForInstanceInRegion() { private void setRamdiskForInstanceInRegion() {
String ramdisk = client.getInstanceServices().getRamdiskForInstanceInRegion(null, String ramdisk = client.getInstanceServices().getRamdiskForInstanceInRegion(null, ebsInstance.getId());
ebsInstance.getId()); client.getInstanceServices().setRamdiskForInstanceInRegion(null, ebsInstance.getId(), ramdisk);
client.getInstanceServices() assertEquals(ramdisk, client.getInstanceServices().getRamdiskForInstanceInRegion(null, ebsInstance.getId()));
.setRamdiskForInstanceInRegion(null, ebsInstance.getId(), ramdisk);
assertEquals(ramdisk, client.getInstanceServices().getRamdiskForInstanceInRegion(null,
ebsInstance.getId()));
} }
private void setKernelForInstanceInRegion() { private void setKernelForInstanceInRegion() {
String oldKernel = client.getInstanceServices().getKernelForInstanceInRegion(null, String oldKernel = client.getInstanceServices().getKernelForInstanceInRegion(null, ebsInstance.getId());
ebsInstance.getId()); client.getInstanceServices().setKernelForInstanceInRegion(null, ebsInstance.getId(), oldKernel);
client.getInstanceServices().setKernelForInstanceInRegion(null, ebsInstance.getId(), assertEquals(oldKernel, client.getInstanceServices().getKernelForInstanceInRegion(null, ebsInstance.getId()));
oldKernel);
assertEquals(oldKernel, client.getInstanceServices().getKernelForInstanceInRegion(null,
ebsInstance.getId()));
} }
private void setInstanceTypeForInstanceInRegion() { private void setInstanceTypeForInstanceInRegion() {
client.getInstanceServices().setInstanceTypeForInstanceInRegion(null, ebsInstance.getId(), client.getInstanceServices()
InstanceType.C1_MEDIUM); .setInstanceTypeForInstanceInRegion(null, ebsInstance.getId(), InstanceType.C1_MEDIUM);
assertEquals(InstanceType.C1_MEDIUM, client.getInstanceServices() assertEquals(InstanceType.C1_MEDIUM, client.getInstanceServices().getInstanceTypeForInstanceInRegion(null,
.getInstanceTypeForInstanceInRegion(null, ebsInstance.getId())); ebsInstance.getId()));
client.getInstanceServices().setInstanceTypeForInstanceInRegion(null, ebsInstance.getId(), client.getInstanceServices().setInstanceTypeForInstanceInRegion(null, ebsInstance.getId(), InstanceType.M1_SMALL);
InstanceType.M1_SMALL); assertEquals(InstanceType.M1_SMALL, client.getInstanceServices().getInstanceTypeForInstanceInRegion(null,
assertEquals(InstanceType.M1_SMALL, client.getInstanceServices() ebsInstance.getId()));
.getInstanceTypeForInstanceInRegion(null, ebsInstance.getId()));
} }
private void setBlockDeviceMappingForInstanceInRegion() { private void setBlockDeviceMappingForInstanceInRegion() {
String volumeId = ebsInstance.getEbsBlockDevices().get("/dev/sda1").getVolumeId(); String volumeId = ebsInstance.getEbsBlockDevices().get("/dev/sda1").getVolumeId();
BlockDeviceMapping blockDeviceMapping = new BlockDeviceMapping(); BlockDeviceMapping blockDeviceMapping = new BlockDeviceMapping();
blockDeviceMapping.addEbsBlockDevice("/dev/sda1", new RunningInstance.EbsBlockDevice( blockDeviceMapping.addEbsBlockDevice("/dev/sda1", new RunningInstance.EbsBlockDevice(volumeId, false));
volumeId, false));
try { try {
client.getInstanceServices().setBlockDeviceMappingForInstanceInRegion(null, client.getInstanceServices().setBlockDeviceMappingForInstanceInRegion(null, ebsInstance.getId(),
ebsInstance.getId(), blockDeviceMapping); blockDeviceMapping);
Map<String, RunningInstance.EbsBlockDevice> devices = client.getInstanceServices() Map<String, RunningInstance.EbsBlockDevice> devices = client.getInstanceServices()
.getBlockDeviceMappingForInstanceInRegion(null, ebsInstance.getId()); .getBlockDeviceMappingForInstanceInRegion(null, ebsInstance.getId());
assertEquals(devices.size(), 1); assertEquals(devices.size(), 1);
String deviceName = Iterables.getOnlyElement(devices.keySet()); String deviceName = Iterables.getOnlyElement(devices.keySet());
RunningInstance.EbsBlockDevice device = Iterables.getOnlyElement(devices.values()); RunningInstance.EbsBlockDevice device = Iterables.getOnlyElement(devices.values());
@ -502,17 +472,15 @@ public class EBSBootEC2ClientLiveTest {
try { try {
client.getInstanceServices().setInstanceInitiatedShutdownBehaviorForInstanceInRegion(null, client.getInstanceServices().setInstanceInitiatedShutdownBehaviorForInstanceInRegion(null,
ebsInstance.getId(), InstanceInitiatedShutdownBehavior.STOP); ebsInstance.getId(), InstanceInitiatedShutdownBehavior.STOP);
assertEquals(InstanceInitiatedShutdownBehavior.STOP, client.getInstanceServices() assertEquals(InstanceInitiatedShutdownBehavior.STOP, client.getInstanceServices()
.getInstanceInitiatedShutdownBehaviorForInstanceInRegion(null, .getInstanceInitiatedShutdownBehaviorForInstanceInRegion(null, ebsInstance.getId()));
ebsInstance.getId()));
client.getInstanceServices().setInstanceInitiatedShutdownBehaviorForInstanceInRegion(null, client.getInstanceServices().setInstanceInitiatedShutdownBehaviorForInstanceInRegion(null,
ebsInstance.getId(), InstanceInitiatedShutdownBehavior.TERMINATE); ebsInstance.getId(), InstanceInitiatedShutdownBehavior.TERMINATE);
assertEquals(InstanceInitiatedShutdownBehavior.TERMINATE, client.getInstanceServices() assertEquals(InstanceInitiatedShutdownBehavior.TERMINATE, client.getInstanceServices()
.getInstanceInitiatedShutdownBehaviorForInstanceInRegion(null, .getInstanceInitiatedShutdownBehaviorForInstanceInRegion(null, ebsInstance.getId()));
ebsInstance.getId()));
System.out.println("OK: setInstanceInitiatedShutdownBehaviorForInstanceInRegion"); System.out.println("OK: setInstanceInitiatedShutdownBehaviorForInstanceInRegion");
} catch (Exception e) { } catch (Exception e) {
System.err.println("setInstanceInitiatedShutdownBehaviorForInstanceInRegion"); 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 * @throws UnknownHostException
*/ */
@ -542,8 +511,7 @@ public class EBSBootEC2ClientLiveTest {
} }
private void doCheckKey(String address) { private void doCheckKey(String address) {
SshClient ssh = sshFactory.create(new IPSocket(address, 22), "ubuntu", keyPair SshClient ssh = sshFactory.create(new IPSocket(address, 22), "ubuntu", keyPair.getKeyMaterial().getBytes());
.getKeyMaterial().getBytes());
try { try {
ssh.connect(); ssh.connect();
ExecResponse hello = ssh.exec("echo hello"); ExecResponse hello = ssh.exec("echo hello");
@ -554,15 +522,13 @@ public class EBSBootEC2ClientLiveTest {
} }
} }
private RunningInstance blockUntilWeCanSshIntoInstance(RunningInstance instance) private RunningInstance blockUntilWeCanSshIntoInstance(RunningInstance instance) throws UnknownHostException {
throws UnknownHostException { System.out.printf("%d: %s awaiting instance to run %n", System.currentTimeMillis(), instance.getId());
System.out.printf("%d: %s awaiting instance to run %n", System.currentTimeMillis(), instance
.getId());
assert runningTester.apply(instance); assert runningTester.apply(instance);
// search my identity for the instance I just created // search my identity for the instance I just created
Set<Reservation> reservations = client.getInstanceServices().describeInstancesInRegion( Set<Reservation> reservations = client.getInstanceServices().describeInstancesInRegion(instance.getRegion(),
instance.getRegion(), instance.getId()); // last instance.getId()); // last
// parameter // parameter
// (ids) // (ids)
// narrows // narrows
@ -571,14 +537,11 @@ public class EBSBootEC2ClientLiveTest {
instance = Iterables.getOnlyElement(Iterables.getOnlyElement(reservations)); instance = Iterables.getOnlyElement(Iterables.getOnlyElement(reservations));
System.out.printf("%d: %s awaiting ssh service to start%n", System.currentTimeMillis(), System.out.printf("%d: %s awaiting ssh service to start%n", System.currentTimeMillis(), instance.getIpAddress());
instance.getIpAddress());
assert socketTester.apply(new IPSocket(instance.getIpAddress(), 22)); assert socketTester.apply(new IPSocket(instance.getIpAddress(), 22));
System.out.printf("%d: %s ssh service started%n", System.currentTimeMillis(), instance System.out.printf("%d: %s ssh service started%n", System.currentTimeMillis(), instance.getDnsName());
.getDnsName());
sshPing(instance); sshPing(instance);
System.out.printf("%d: %s ssh connection made%n", System.currentTimeMillis(), instance System.out.printf("%d: %s ssh connection made%n", System.currentTimeMillis(), instance.getId());
.getId());
return instance; return instance;
} }
@ -586,8 +549,7 @@ public class EBSBootEC2ClientLiveTest {
void cleanup() { void cleanup() {
if (ebsInstance != null) { if (ebsInstance != null) {
try { try {
client.getInstanceServices().terminateInstancesInRegion(ebsInstance.getRegion(), client.getInstanceServices().terminateInstancesInRegion(ebsInstance.getRegion(), ebsInstance.getId());
ebsInstance.getId());
terminatedTester.apply(ebsInstance); terminatedTester.apply(ebsInstance);
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
@ -603,16 +565,14 @@ public class EBSBootEC2ClientLiveTest {
if (snapshot != null) { if (snapshot != null) {
try { try {
client.getElasticBlockStoreServices().deleteSnapshotInRegion(snapshot.getRegion(), client.getElasticBlockStoreServices().deleteSnapshotInRegion(snapshot.getRegion(), snapshot.getId());
snapshot.getId());
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
} }
if (attachment != null) { if (attachment != null) {
try { try {
client.getElasticBlockStoreServices().detachVolumeInRegion(volume.getRegion(), client.getElasticBlockStoreServices().detachVolumeInRegion(volume.getRegion(), volume.getId(), true);
volume.getId(), true);
assert volumeTester.apply(volume); assert volumeTester.apply(volume);
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
@ -620,8 +580,7 @@ public class EBSBootEC2ClientLiveTest {
} }
if (instance != null) { if (instance != null) {
try { try {
client.getInstanceServices().terminateInstancesInRegion(instance.getRegion(), client.getInstanceServices().terminateInstancesInRegion(instance.getRegion(), instance.getId());
instance.getId());
terminatedTester.apply(instance); terminatedTester.apply(instance);
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
@ -629,16 +588,14 @@ public class EBSBootEC2ClientLiveTest {
} }
if (volume != null) { if (volume != null) {
try { try {
client.getElasticBlockStoreServices().deleteVolumeInRegion(volume.getRegion(), client.getElasticBlockStoreServices().deleteVolumeInRegion(volume.getRegion(), volume.getId());
volume.getId());
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
} }
if (keyPair != null) { if (keyPair != null) {
try { try {
client.getKeyPairServices().deleteKeyPairInRegion(keyPair.getRegion(), client.getKeyPairServices().deleteKeyPairInRegion(keyPair.getRegion(), keyPair.getKeyName());
keyPair.getKeyName());
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }

View File

@ -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.jclouds.aws.ec2.compute.options.EC2TemplateOptions.Builder.securityGroups;
import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertEquals;
import java.io.IOException;
import org.jclouds.compute.options.TemplateOptions; import org.jclouds.compute.options.TemplateOptions;
import org.jclouds.util.Utils;
import org.testng.annotations.Test; import org.testng.annotations.Test;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
@ -170,17 +173,19 @@ public class EC2TemplateOptionsTest {
} }
// superclass tests // superclass tests
@SuppressWarnings("deprecation")
@Test(expectedExceptions = IllegalArgumentException.class) @Test(expectedExceptions = IllegalArgumentException.class)
public void testinstallPrivateKeyBadFormat() { public void testinstallPrivateKeyBadFormat() {
EC2TemplateOptions options = new EC2TemplateOptions(); EC2TemplateOptions options = new EC2TemplateOptions();
options.installPrivateKey("whompy"); options.installPrivateKey("whompy");
} }
@SuppressWarnings("deprecation")
@Test @Test
public void testinstallPrivateKey() { public void testinstallPrivateKey() throws IOException {
EC2TemplateOptions options = new EC2TemplateOptions(); EC2TemplateOptions options = new EC2TemplateOptions();
options.installPrivateKey("-----BEGIN RSA PRIVATE KEY-----"); options.installPrivateKey("-----BEGIN RSA PRIVATE KEY-----");
assertEquals(options.getPrivateKey(), "-----BEGIN RSA PRIVATE KEY-----"); assertEquals(Utils.toStringAndClose(options.getPrivateKey().getInput()), "-----BEGIN RSA PRIVATE KEY-----");
} }
@Test @Test
@ -190,9 +195,9 @@ public class EC2TemplateOptionsTest {
} }
@Test @Test
public void testinstallPrivateKeyStatic() { public void testinstallPrivateKeyStatic() throws IOException {
EC2TemplateOptions options = installPrivateKey("-----BEGIN RSA PRIVATE KEY-----"); 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) @Test(expectedExceptions = NullPointerException.class)
@ -200,17 +205,19 @@ public class EC2TemplateOptionsTest {
installPrivateKey(null); installPrivateKey(null);
} }
@SuppressWarnings("deprecation")
@Test(expectedExceptions = IllegalArgumentException.class) @Test(expectedExceptions = IllegalArgumentException.class)
public void testauthorizePublicKeyBadFormat() { public void testauthorizePublicKeyBadFormat() {
EC2TemplateOptions options = new EC2TemplateOptions(); EC2TemplateOptions options = new EC2TemplateOptions();
options.authorizePublicKey("whompy"); options.authorizePublicKey("whompy");
} }
@SuppressWarnings("deprecation")
@Test @Test
public void testauthorizePublicKey() { public void testauthorizePublicKey() throws IOException {
EC2TemplateOptions options = new EC2TemplateOptions(); EC2TemplateOptions options = new EC2TemplateOptions();
options.authorizePublicKey("ssh-rsa"); options.authorizePublicKey("ssh-rsa");
assertEquals(options.getPublicKey(), "ssh-rsa"); assertEquals(Utils.toStringAndClose(options.getPublicKey().getInput()), "ssh-rsa");
} }
@Test @Test
@ -220,9 +227,9 @@ public class EC2TemplateOptionsTest {
} }
@Test @Test
public void testauthorizePublicKeyStatic() { public void testauthorizePublicKeyStatic() throws IOException {
EC2TemplateOptions options = authorizePublicKey("ssh-rsa"); EC2TemplateOptions options = authorizePublicKey("ssh-rsa");
assertEquals(options.getPublicKey(), "ssh-rsa"); assertEquals(Utils.toStringAndClose(options.getPublicKey().getInput()), "ssh-rsa");
} }
@Test(expectedExceptions = NullPointerException.class) @Test(expectedExceptions = NullPointerException.class)

View File

@ -19,6 +19,7 @@
package org.jclouds.aws.ec2.services; package org.jclouds.aws.ec2.services;
import static com.google.common.base.Preconditions.checkNotNull; 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.assertEquals;
import static org.testng.Assert.assertNotNull; import static org.testng.Assert.assertNotNull;
@ -82,11 +83,11 @@ public class PlacementGroupClientLiveTest {
String credential = checkNotNull(System.getProperty("jclouds.test.credential"), "jclouds.test.credential"); String credential = checkNotNull(System.getProperty("jclouds.test.credential"), "jclouds.test.credential");
keyPair = BaseComputeServiceLiveTest.setupKeyPair(); keyPair = BaseComputeServiceLiveTest.setupKeyPair();
context = new ComputeServiceContextFactory().createContext("ec2", identity, credential, ImmutableSet.<Module> of( context = new ComputeServiceContextFactory().createContext("ec2", identity, credential, ImmutableSet.<Module> of(
new Log4JLoggingModule(), new JschSshClientModule())); new Log4JLoggingModule(), new JschSshClientModule()));
client = EC2Client.class.cast(context.getProviderSpecificContext().getApi()); client = EC2Client.class.cast(context.getProviderSpecificContext().getApi());
availableTester = new RetryablePredicate<PlacementGroup>(new PlacementGroupAvailable(client), 60, 1, availableTester = new RetryablePredicate<PlacementGroup>(new PlacementGroupAvailable(client), 60, 1,
TimeUnit.SECONDS); TimeUnit.SECONDS);
deletedTester = new RetryablePredicate<PlacementGroup>(new PlacementGroupDeleted(client), 60, 1, TimeUnit.SECONDS); deletedTester = new RetryablePredicate<PlacementGroup>(new PlacementGroupDeleted(client), 60, 1, TimeUnit.SECONDS);
} }
@ -95,12 +96,12 @@ public class PlacementGroupClientLiveTest {
void testDescribe() { void testDescribe() {
for (String region : Lists.newArrayList(Region.US_EAST_1)) { for (String region : Lists.newArrayList(Region.US_EAST_1)) {
SortedSet<PlacementGroup> allResults = Sets.newTreeSet(client.getPlacementGroupServices() SortedSet<PlacementGroup> allResults = Sets.newTreeSet(client.getPlacementGroupServices()
.describePlacementGroupsInRegion(region)); .describePlacementGroupsInRegion(region));
assertNotNull(allResults); assertNotNull(allResults);
if (allResults.size() >= 1) { if (allResults.size() >= 1) {
PlacementGroup group = allResults.last(); PlacementGroup group = allResults.last();
SortedSet<PlacementGroup> result = Sets.newTreeSet(client.getPlacementGroupServices() SortedSet<PlacementGroup> result = Sets.newTreeSet(client.getPlacementGroupServices()
.describePlacementGroupsInRegion(region, group.getName())); .describePlacementGroupsInRegion(region, group.getName()));
assertNotNull(result); assertNotNull(result);
PlacementGroup compare = result.last(); PlacementGroup compare = result.last();
assertEquals(compare, group); assertEquals(compare, group);
@ -129,7 +130,7 @@ public class PlacementGroupClientLiveTest {
private void verifyPlacementGroup(String groupName) { private void verifyPlacementGroup(String groupName) {
assert availableTester.apply(new PlacementGroup(Region.US_EAST_1, groupName, "cluster", State.PENDING)) : group; assert availableTester.apply(new PlacementGroup(Region.US_EAST_1, groupName, "cluster", State.PENDING)) : group;
Set<PlacementGroup> oneResult = client.getPlacementGroupServices().describePlacementGroupsInRegion(null, Set<PlacementGroup> oneResult = client.getPlacementGroupServices().describePlacementGroupsInRegion(null,
groupName); groupName);
assertNotNull(oneResult); assertNotNull(oneResult);
assertEquals(oneResult.size(), 1); assertEquals(oneResult.size(), 1);
group = oneResult.iterator().next(); group = oneResult.iterator().next();
@ -163,8 +164,9 @@ public class PlacementGroupClientLiveTest {
assertEquals(template.getSize().getProviderId(), InstanceType.CC1_4XLARGE); assertEquals(template.getSize().getProviderId(), InstanceType.CC1_4XLARGE);
assertEquals(template.getImage().getId(), "us-east-1/ami-7ea24a17"); assertEquals(template.getImage().getId(), "us-east-1/ami-7ea24a17");
template.getOptions().installPrivateKey(keyPair.get("private")).authorizePublicKey(keyPair.get("public")) template.getOptions().installPrivateKey(newStringPayload(keyPair.get("private"))).authorizePublicKey(
.runScript(BaseComputeServiceLiveTest.buildScript(template.getImage().getOsFamily()).getBytes()); newStringPayload(keyPair.get("public"))).runScript(
newStringPayload(BaseComputeServiceLiveTest.buildScript(template.getImage().getOsFamily())));
String tag = PREFIX + "cccluster"; String tag = PREFIX + "cccluster";
context.getComputeService().destroyNodesMatching(NodePredicates.withTag(tag)); context.getComputeService().destroyNodesMatching(NodePredicates.withTag(tag));
@ -174,7 +176,7 @@ public class PlacementGroupClientLiveTest {
NodeMetadata node = Iterables.getOnlyElement(nodes); NodeMetadata node = Iterables.getOnlyElement(nodes);
RunningInstance instance = Iterables.getOnlyElement(Iterables.getOnlyElement(client.getInstanceServices() 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.getVirtualizationType(), node.getExtra().get("virtualizationType"));
assertEquals(instance.getPlacementGroup(), node.getExtra().get("placementGroup")); assertEquals(instance.getPlacementGroup(), node.getExtra().get("placementGroup"));

View File

@ -13,8 +13,8 @@ import org.easymock.IArgumentMatcher;
import org.jclouds.http.HttpCommand; import org.jclouds.http.HttpCommand;
import org.jclouds.http.HttpRequest; import org.jclouds.http.HttpRequest;
import org.jclouds.http.HttpResponse; import org.jclouds.http.HttpResponse;
import org.jclouds.http.Payloads;
import org.jclouds.http.functions.config.ParserModule; import org.jclouds.http.functions.config.ParserModule;
import org.jclouds.io.Payloads;
import org.jclouds.rest.AuthorizationException; import org.jclouds.rest.AuthorizationException;
import org.jclouds.rest.RequestSigner; import org.jclouds.rest.RequestSigner;
import org.jclouds.rest.ResourceNotFoundException; import org.jclouds.rest.ResourceNotFoundException;

View File

@ -29,7 +29,7 @@ import org.jclouds.aws.s3.domain.S3Object;
import org.jclouds.blobstore.binders.BindUserMetadataToHeadersWithPrefix; import org.jclouds.blobstore.binders.BindUserMetadataToHeadersWithPrefix;
import org.jclouds.blobstore.domain.Blob; import org.jclouds.blobstore.domain.Blob;
import org.jclouds.http.HttpRequest; import org.jclouds.http.HttpRequest;
import org.jclouds.http.Payload; import org.jclouds.io.Payload;
import org.testng.annotations.Test; import org.testng.annotations.Test;
import com.google.common.collect.Multimap; import com.google.common.collect.Multimap;

View File

@ -38,7 +38,7 @@ import org.jclouds.blobstore.functions.ParseSystemAndUserMetadataFromHeaders;
import org.jclouds.encryption.EncryptionService; import org.jclouds.encryption.EncryptionService;
import org.jclouds.encryption.internal.JCEEncryptionService; import org.jclouds.encryption.internal.JCEEncryptionService;
import org.jclouds.http.HttpResponse; import org.jclouds.http.HttpResponse;
import org.jclouds.http.Payloads; import org.jclouds.io.Payloads;
import org.testng.annotations.BeforeTest; import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test; import org.testng.annotations.Test;

View File

@ -37,10 +37,10 @@ import org.jclouds.PerformanceTest;
import org.jclouds.aws.domain.Region; import org.jclouds.aws.domain.Region;
import org.jclouds.aws.sqs.domain.Queue; import org.jclouds.aws.sqs.domain.Queue;
import org.jclouds.http.HttpResponse; import org.jclouds.http.HttpResponse;
import org.jclouds.http.Payloads;
import org.jclouds.http.functions.ParseSax; import org.jclouds.http.functions.ParseSax;
import org.jclouds.http.functions.ParseSax.Factory; import org.jclouds.http.functions.ParseSax.Factory;
import org.jclouds.http.functions.config.ParserModule; import org.jclouds.http.functions.config.ParserModule;
import org.jclouds.io.Payloads;
import org.testng.annotations.BeforeTest; import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test; import org.testng.annotations.Test;

View File

@ -31,7 +31,7 @@ import org.jclouds.aws.domain.AWSError;
import org.jclouds.http.HttpCommand; import org.jclouds.http.HttpCommand;
import org.jclouds.http.HttpRequest; import org.jclouds.http.HttpRequest;
import org.jclouds.http.HttpResponse; import org.jclouds.http.HttpResponse;
import org.jclouds.http.Payloads; import org.jclouds.io.Payloads;
import org.jclouds.logging.config.NullLoggingModule; import org.jclouds.logging.config.NullLoggingModule;
import org.jclouds.rest.RestContextFactory; import org.jclouds.rest.RestContextFactory;
import org.jclouds.rest.BaseRestClientTest.MockModule; import org.jclouds.rest.BaseRestClientTest.MockModule;

View File

@ -24,10 +24,10 @@ import javax.inject.Inject;
import org.jclouds.azure.storage.blob.domain.AzureBlob; import org.jclouds.azure.storage.blob.domain.AzureBlob;
import org.jclouds.azure.storage.blob.domain.MutableBlobProperties; import org.jclouds.azure.storage.blob.domain.MutableBlobProperties;
import org.jclouds.http.Payload;
import org.jclouds.http.PayloadEnclosing; import org.jclouds.http.PayloadEnclosing;
import org.jclouds.http.internal.PayloadEnclosingImpl; 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.LinkedHashMultimap;
import com.google.common.collect.Multimap; import com.google.common.collect.Multimap;

View File

@ -12,7 +12,7 @@ import org.jclouds.azure.storage.blob.domain.MutableBlobProperties;
import org.jclouds.blobstore.binders.BindUserMetadataToHeadersWithPrefix; import org.jclouds.blobstore.binders.BindUserMetadataToHeadersWithPrefix;
import org.jclouds.blobstore.domain.Blob; import org.jclouds.blobstore.domain.Blob;
import org.jclouds.http.HttpRequest; import org.jclouds.http.HttpRequest;
import org.jclouds.http.Payload; import org.jclouds.io.Payload;
import org.testng.annotations.Test; import org.testng.annotations.Test;
import com.google.common.collect.Multimap; import com.google.common.collect.Multimap;

View File

@ -85,8 +85,8 @@ import org.jclouds.http.HttpRequest;
import org.jclouds.http.HttpResponse; import org.jclouds.http.HttpResponse;
import org.jclouds.http.HttpResponseException; import org.jclouds.http.HttpResponseException;
import org.jclouds.http.options.HttpRequestOptions; import org.jclouds.http.options.HttpRequestOptions;
import org.jclouds.http.payloads.ByteArrayPayload; import org.jclouds.io.payloads.ByteArrayPayload;
import org.jclouds.http.payloads.DelegatingPayload; import org.jclouds.io.payloads.DelegatingPayload;
import com.google.common.base.Function; import com.google.common.base.Function;
import com.google.common.base.Predicate; import com.google.common.base.Predicate;

View File

@ -22,9 +22,9 @@ import javax.inject.Singleton;
import org.jclouds.blobstore.domain.Blob; import org.jclouds.blobstore.domain.Blob;
import org.jclouds.http.HttpRequest; import org.jclouds.http.HttpRequest;
import org.jclouds.http.payloads.MultipartForm; import org.jclouds.io.payloads.MultipartForm;
import org.jclouds.http.payloads.Part; import org.jclouds.io.payloads.Part;
import org.jclouds.http.payloads.Part.PartOptions; import org.jclouds.io.payloads.Part.PartOptions;
import org.jclouds.rest.Binder; import org.jclouds.rest.Binder;
/** /**

View File

@ -25,10 +25,10 @@ import javax.inject.Inject;
import org.jclouds.blobstore.domain.Blob; import org.jclouds.blobstore.domain.Blob;
import org.jclouds.blobstore.domain.MutableBlobMetadata; import org.jclouds.blobstore.domain.MutableBlobMetadata;
import org.jclouds.blobstore.domain.StorageMetadata; import org.jclouds.blobstore.domain.StorageMetadata;
import org.jclouds.http.Payload;
import org.jclouds.http.PayloadEnclosing; import org.jclouds.http.PayloadEnclosing;
import org.jclouds.http.internal.PayloadEnclosingImpl; 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.LinkedHashMultimap;
import com.google.common.collect.Multimap; import com.google.common.collect.Multimap;

View File

@ -22,7 +22,7 @@ import javax.inject.Inject;
import org.jclouds.blobstore.domain.Blob; import org.jclouds.blobstore.domain.Blob;
import org.jclouds.encryption.EncryptionService; import org.jclouds.encryption.EncryptionService;
import org.jclouds.http.Payloads; import org.jclouds.io.Payloads;
import com.google.common.base.Function; import com.google.common.base.Function;

View File

@ -20,7 +20,7 @@ package org.jclouds.blobstore.internal;
import static com.google.common.collect.Iterables.transform; import static com.google.common.collect.Iterables.transform;
import static com.google.common.collect.Lists.newArrayList; 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.File;
import java.io.InputStream; 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.PutBlobsStrategy;
import org.jclouds.blobstore.strategy.internal.ListContainerAndRecurseThroughFolders; import org.jclouds.blobstore.strategy.internal.ListContainerAndRecurseThroughFolders;
import org.jclouds.encryption.EncryptionService; import org.jclouds.encryption.EncryptionService;
import org.jclouds.http.Payload; import org.jclouds.io.Payload;
import org.jclouds.http.payloads.ByteArrayPayload; import org.jclouds.io.payloads.ByteArrayPayload;
import org.jclouds.http.payloads.FilePayload; import org.jclouds.io.payloads.FilePayload;
import org.jclouds.http.payloads.InputStreamPayload; import org.jclouds.io.payloads.InputStreamPayload;
import org.jclouds.http.payloads.StringPayload; import org.jclouds.io.payloads.StringPayload;
import com.google.common.annotations.VisibleForTesting; import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Function; import com.google.common.base.Function;

View File

@ -26,7 +26,7 @@ import org.jclouds.blobstore.domain.Blob;
import org.jclouds.blobstore.domain.StorageType; import org.jclouds.blobstore.domain.StorageType;
import org.jclouds.blobstore.reference.BlobStoreConstants; import org.jclouds.blobstore.reference.BlobStoreConstants;
import org.jclouds.blobstore.strategy.MkdirStrategy; import org.jclouds.blobstore.strategy.MkdirStrategy;
import org.jclouds.http.Payloads; import org.jclouds.io.Payloads;
import com.google.inject.Inject; import com.google.inject.Inject;

View File

@ -18,7 +18,7 @@
*/ */
package org.jclouds.blobstore.binders; 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.jclouds.util.Utils.toStringAndClose;
import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertEquals;

View File

@ -34,7 +34,7 @@ import org.jclouds.blobstore.domain.MutableBlobMetadata;
import org.jclouds.blobstore.domain.internal.MutableBlobMetadataImpl; import org.jclouds.blobstore.domain.internal.MutableBlobMetadataImpl;
import org.jclouds.http.HttpException; import org.jclouds.http.HttpException;
import org.jclouds.http.HttpResponse; import org.jclouds.http.HttpResponse;
import org.jclouds.http.Payloads; import org.jclouds.io.Payloads;
import org.testng.annotations.BeforeTest; import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test; import org.testng.annotations.Test;

View File

@ -35,7 +35,7 @@ import org.jclouds.blobstore.domain.internal.MutableBlobMetadataImpl;
import org.jclouds.date.internal.SimpleDateFormatDateService; import org.jclouds.date.internal.SimpleDateFormatDateService;
import org.jclouds.http.HttpException; import org.jclouds.http.HttpException;
import org.jclouds.http.HttpResponse; import org.jclouds.http.HttpResponse;
import org.jclouds.http.Payloads; import org.jclouds.io.Payloads;
import org.jclouds.rest.internal.GeneratedHttpRequest; import org.jclouds.rest.internal.GeneratedHttpRequest;
import org.testng.annotations.BeforeTest; import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test; import org.testng.annotations.Test;

View File

@ -50,8 +50,8 @@ import org.jclouds.blobstore.domain.StorageType;
import org.jclouds.encryption.internal.JCEEncryptionService; import org.jclouds.encryption.internal.JCEEncryptionService;
import org.jclouds.http.BaseJettyTest; import org.jclouds.http.BaseJettyTest;
import org.jclouds.http.HttpResponseException; import org.jclouds.http.HttpResponseException;
import org.jclouds.http.Payload; import org.jclouds.io.Payload;
import org.jclouds.http.Payloads; import org.jclouds.io.Payloads;
import org.jclouds.logging.Logger; import org.jclouds.logging.Logger;
import org.jclouds.util.Utils; import org.jclouds.util.Utils;
import org.testng.ITestContext; import org.testng.ITestContext;

View File

@ -21,7 +21,7 @@ package org.jclouds.chef.domain;
import java.net.URI; import java.net.URI;
import java.util.Arrays; import java.util.Arrays;
import org.jclouds.http.payloads.FilePayload; import org.jclouds.io.payloads.FilePayload;
import com.google.common.primitives.Bytes; import com.google.common.primitives.Bytes;

View File

@ -43,11 +43,11 @@ import org.jclouds.http.HttpException;
import org.jclouds.http.HttpRequest; import org.jclouds.http.HttpRequest;
import org.jclouds.http.HttpRequestFilter; import org.jclouds.http.HttpRequestFilter;
import org.jclouds.http.HttpUtils; 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.internal.SignatureWire;
import org.jclouds.http.payloads.MultipartForm; import org.jclouds.io.Payload;
import org.jclouds.http.payloads.Part; 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.logging.Logger;
import org.jclouds.util.Utils; import org.jclouds.util.Utils;

View File

@ -38,8 +38,8 @@ import org.jclouds.chef.domain.ChecksumStatus;
import org.jclouds.chef.domain.CookbookVersion; import org.jclouds.chef.domain.CookbookVersion;
import org.jclouds.chef.domain.Resource; import org.jclouds.chef.domain.Resource;
import org.jclouds.chef.domain.UploadSandbox; import org.jclouds.chef.domain.UploadSandbox;
import org.jclouds.http.Payloads; import org.jclouds.io.Payloads;
import org.jclouds.http.payloads.FilePayload; import org.jclouds.io.payloads.FilePayload;
import org.jclouds.logging.log4j.config.Log4JLoggingModule; import org.jclouds.logging.log4j.config.Log4JLoggingModule;
import org.jclouds.rest.RestContext; import org.jclouds.rest.RestContext;
import org.jclouds.rest.RestContextFactory; import org.jclouds.rest.RestContextFactory;

View File

@ -12,9 +12,9 @@ import org.jclouds.chef.domain.Metadata;
import org.jclouds.chef.domain.Resource; import org.jclouds.chef.domain.Resource;
import org.jclouds.encryption.EncryptionService; import org.jclouds.encryption.EncryptionService;
import org.jclouds.http.HttpResponse; import org.jclouds.http.HttpResponse;
import org.jclouds.http.Payloads;
import org.jclouds.http.functions.ParseJson; import org.jclouds.http.functions.ParseJson;
import org.jclouds.http.functions.config.ParserModule; import org.jclouds.http.functions.config.ParserModule;
import org.jclouds.io.Payloads;
import org.jclouds.util.Utils; import org.jclouds.util.Utils;
import org.testng.annotations.BeforeTest; import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test; import org.testng.annotations.Test;

View File

@ -29,8 +29,8 @@ import java.io.InputStream;
import java.net.UnknownHostException; import java.net.UnknownHostException;
import org.jclouds.http.HttpResponse; import org.jclouds.http.HttpResponse;
import org.jclouds.http.Payloads;
import org.jclouds.http.functions.ReturnStringIf2xx; import org.jclouds.http.functions.ReturnStringIf2xx;
import org.jclouds.io.Payloads;
import org.jclouds.util.Utils; import org.jclouds.util.Utils;
import org.testng.annotations.Test; import org.testng.annotations.Test;

View File

@ -5,8 +5,8 @@ import static org.testng.Assert.assertEquals;
import java.io.IOException; import java.io.IOException;
import org.jclouds.http.HttpResponse; import org.jclouds.http.HttpResponse;
import org.jclouds.http.Payloads;
import org.jclouds.http.functions.config.ParserModule; import org.jclouds.http.functions.config.ParserModule;
import org.jclouds.io.Payloads;
import org.jclouds.util.Utils; import org.jclouds.util.Utils;
import org.testng.annotations.BeforeTest; import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test; import org.testng.annotations.Test;

View File

@ -5,8 +5,8 @@ import static org.testng.Assert.assertEquals;
import java.io.IOException; import java.io.IOException;
import org.jclouds.http.HttpResponse; import org.jclouds.http.HttpResponse;
import org.jclouds.http.Payloads;
import org.jclouds.http.functions.config.ParserModule; import org.jclouds.http.functions.config.ParserModule;
import org.jclouds.io.Payloads;
import org.jclouds.util.Utils; import org.jclouds.util.Utils;
import org.testng.annotations.BeforeTest; import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test; import org.testng.annotations.Test;

View File

@ -24,9 +24,9 @@ import java.io.IOException;
import org.jclouds.chef.domain.Organization; import org.jclouds.chef.domain.Organization;
import org.jclouds.http.HttpResponse; import org.jclouds.http.HttpResponse;
import org.jclouds.http.Payloads;
import org.jclouds.http.functions.ParseJson; import org.jclouds.http.functions.ParseJson;
import org.jclouds.http.functions.config.ParserModule; import org.jclouds.http.functions.config.ParserModule;
import org.jclouds.io.Payloads;
import org.jclouds.util.Utils; import org.jclouds.util.Utils;
import org.testng.annotations.BeforeTest; import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test; import org.testng.annotations.Test;

View File

@ -7,11 +7,11 @@ import java.io.IOException;
import org.jclouds.chef.domain.Sandbox; import org.jclouds.chef.domain.Sandbox;
import org.jclouds.date.DateService; import org.jclouds.date.DateService;
import org.jclouds.http.HttpResponse; import org.jclouds.http.HttpResponse;
import org.jclouds.http.Payloads;
import org.jclouds.http.functions.ParseJson; import org.jclouds.http.functions.ParseJson;
import org.jclouds.http.functions.config.ParserModule; import org.jclouds.http.functions.config.ParserModule;
import org.jclouds.http.functions.config.ParserModule.DateAdapter; import org.jclouds.http.functions.config.ParserModule.DateAdapter;
import org.jclouds.http.functions.config.ParserModule.Iso8601DateAdapter; import org.jclouds.http.functions.config.ParserModule.Iso8601DateAdapter;
import org.jclouds.io.Payloads;
import org.testng.annotations.BeforeTest; import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test; import org.testng.annotations.Test;

View File

@ -10,9 +10,9 @@ import org.jclouds.chef.domain.ChecksumStatus;
import org.jclouds.chef.domain.UploadSandbox; import org.jclouds.chef.domain.UploadSandbox;
import org.jclouds.encryption.EncryptionService; import org.jclouds.encryption.EncryptionService;
import org.jclouds.http.HttpResponse; import org.jclouds.http.HttpResponse;
import org.jclouds.http.Payloads;
import org.jclouds.http.functions.ParseJson; import org.jclouds.http.functions.ParseJson;
import org.jclouds.http.functions.config.ParserModule; import org.jclouds.http.functions.config.ParserModule;
import org.jclouds.io.Payloads;
import org.testng.annotations.BeforeTest; import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test; import org.testng.annotations.Test;

View File

@ -6,9 +6,9 @@ import java.io.IOException;
import org.jclouds.chef.domain.User; import org.jclouds.chef.domain.User;
import org.jclouds.http.HttpResponse; import org.jclouds.http.HttpResponse;
import org.jclouds.http.Payloads;
import org.jclouds.http.functions.ParseJson; import org.jclouds.http.functions.ParseJson;
import org.jclouds.http.functions.config.ParserModule; import org.jclouds.http.functions.config.ParserModule;
import org.jclouds.io.Payloads;
import org.jclouds.util.Utils; import org.jclouds.util.Utils;
import org.testng.annotations.BeforeTest; import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test; import org.testng.annotations.Test;

View File

@ -31,6 +31,7 @@ import org.jclouds.compute.internal.BaseComputeService;
import org.jclouds.compute.options.RunScriptOptions; import org.jclouds.compute.options.RunScriptOptions;
import org.jclouds.compute.options.TemplateOptions; import org.jclouds.compute.options.TemplateOptions;
import org.jclouds.domain.Location; import org.jclouds.domain.Location;
import org.jclouds.io.Payload;
import org.jclouds.ssh.ExecResponse; import org.jclouds.ssh.ExecResponse;
import com.google.common.base.Predicate; import com.google.common.base.Predicate;
@ -61,48 +62,52 @@ public interface ComputeService {
TemplateOptions templateOptions(); TemplateOptions templateOptions();
/** /**
* The list sizes command shows you the options including virtual cpu count, memory, and disks. * The list sizes command shows you the options including virtual cpu count,
* cpu count is not a portable quantity across clouds, as they are measured differently. However, * memory, and disks. cpu count is not a portable quantity across clouds, as
* it is a good indicator of relative speed within a cloud. memory is measured in megabytes and * they are measured differently. However, it is a good indicator of relative
* disks in gigabytes. * 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<? extends Size> listSizes(); Set<? extends Size> listSizes();
/** /**
* Images define the operating system and metadata related to a node. In some clouds, Images are * Images define the operating system and metadata related to a node. In some
* bound to a specific region, and their identifiers are different across these regions. For this * clouds, Images are bound to a specific region, and their identifiers are
* reason, you should consider matching image requirements like operating system family with * different across these regions. For this reason, you should consider
* TemplateBuilder as opposed to choosing an image explicitly. The getImages() command returns a * matching image requirements like operating system family with
* map of images by id. * TemplateBuilder as opposed to choosing an image explicitly. The
* getImages() command returns a map of images by id.
*/ */
Set<? extends Image> listImages(); Set<? extends Image> listImages();
/** /**
* all nodes available to the current user by id. If possible, the returned set will include * all nodes available to the current user by id. If possible, the returned
* {@link NodeMetadata} objects. * set will include {@link NodeMetadata} objects.
*/ */
Set<? extends ComputeMetadata> listNodes(); Set<? extends ComputeMetadata> listNodes();
/** /**
* The list locations command returns all the valid locations for nodes. A location has a scope, * The list locations command returns all the valid locations for nodes. A
* which is typically region or zone. A region is a general area, like eu-west, where a zone is * location has a scope, which is typically region or zone. A region is a
* similar to a datacenter. If a location has a parent, that implies it is within that location. * general area, like eu-west, where a zone is similar to a datacenter. If a
* For example a location can be a rack, whose parent is likely to be a zone. * 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<? extends Location> listAssignableLocations(); Set<? extends Location> listAssignableLocations();
/** /**
* *
* The compute api treats nodes as a group based on a tag you specify. Using this tag, you can * The compute api treats nodes as a group based on a tag you specify. Using
* choose to operate one or many nodes as a logical unit without regard to the implementation * this tag, you can choose to operate one or many nodes as a logical unit
* details of the cloud. * without regard to the implementation details of the cloud.
* <p/> * <p/>
* *
* The set that is returned will include credentials you can use to ssh into the nodes. The "key" * The set that is returned will include credentials you can use to ssh into
* part of the credentials is either a password or a private key. You have to inspect the value * the nodes. The "key" part of the credentials is either a password or a
* to determine this. * private key. You have to inspect the value to determine this.
* *
* <pre> * <pre>
* if (node.getCredentials().key.startsWith("-----BEGIN RSA PRIVATE KEY-----")) * if (node.getCredentials().key.startsWith("-----BEGIN RSA PRIVATE KEY-----"))
@ -110,11 +115,11 @@ public interface ComputeService {
* </pre> * </pre>
* *
* <p/> * <p/>
* Note. if all you want to do is execute a script at bootup, you should consider use of the * Note. if all you want to do is execute a script at bootup, you should
* runscript option. * consider use of the runscript option.
* <p/> * <p/>
* If resources such as security groups are needed, they will be reused or created for you. * If resources such as security groups are needed, they will be reused or
* Inbound port 22 will always be opened up. * created for you. Inbound port 22 will always be opened up.
* *
* @param tag * @param tag
* - common identifier to group nodes by, cannot contain hyphens * - 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. * @return all of the nodes the api was able to launch in a running state.
* *
* @throws RunNodesException * @throws RunNodesException
* when there's a problem applying options to nodes. Note that successful and failed * when there's a problem applying options to nodes. Note that
* nodes are a part of this exception, so be sure to inspect this carefully. * successful and failed nodes are a part of this exception, so be
* sure to inspect this carefully.
*/ */
Set<? extends NodeMetadata> runNodesWithTag(String tag, int count, Template template) Set<? extends NodeMetadata> runNodesWithTag(String tag, int count, Template template) throws RunNodesException;
throws RunNodesException;
/** /**
* Like {@link ComputeService#runNodesWithTag(String,int,Template)}, except that the template is * Like {@link ComputeService#runNodesWithTag(String,int,Template)}, except
* default, equivalent to {@code templateBuilder().any().options(templateOptions)}. * that the template is default, equivalent to {@code
* templateBuilder().any().options(templateOptions)}.
*/ */
Set<? extends NodeMetadata> runNodesWithTag(String tag, int count, Set<? extends NodeMetadata> runNodesWithTag(String tag, int count, TemplateOptions templateOptions)
TemplateOptions templateOptions) throws RunNodesException; throws RunNodesException;
/** /**
* Like {@link ComputeService#runNodesWithTag(String,int,TemplateOptions)}, except that the * Like {@link ComputeService#runNodesWithTag(String,int,TemplateOptions)},
* options are default, as specified in {@link ComputeService#templateOptions}. * except that the options are default, as specified in
* {@link ComputeService#templateOptions}.
*/ */
Set<? extends NodeMetadata> runNodesWithTag(String tag, int count) throws RunNodesException; Set<? extends NodeMetadata> 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 * destroy the node, given its id. If it is the only node in a tag set, the
* will also be destroyed. * dependent resources will also be destroyed.
*/ */
void destroyNode(String id); void destroyNode(String id);
/** /**
* nodes matching the filter are treated as a logical set. Using the delete command, you can save * nodes matching the filter are treated as a logical set. Using the delete
* time by removing the nodes in parallel. When the last node in a set is destroyed, any indirect * command, you can save time by removing the nodes in parallel. When the
* resources it uses, such as keypairs, are also destroyed. * last node in a set is destroyed, any indirect resources it uses, such as
* keypairs, are also destroyed.
* *
* @return list of nodes destroyed * @return list of nodes destroyed
*/ */
@ -165,8 +173,8 @@ public interface ComputeService {
void rebootNode(String id); void rebootNode(String id);
/** /**
* nodes matching the filter are treated as a logical set. Using this command, you can save time * nodes matching the filter are treated as a logical set. Using this
* by rebooting the nodes in parallel. * command, you can save time by rebooting the nodes in parallel.
*/ */
void rebootNodesMatching(Predicate<NodeMetadata> filter); void rebootNodesMatching(Predicate<NodeMetadata> filter);
@ -176,8 +184,8 @@ public interface ComputeService {
NodeMetadata getNodeMetadata(String id); NodeMetadata getNodeMetadata(String id);
/** /**
* get all nodes including details such as image and ip addresses even if it incurs extra * get all nodes including details such as image and ip addresses even if it
* requests to the service. * incurs extra requests to the service.
* *
* @param filter * @param filter
* how to select the nodes you are interested in details on. * 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 * Runs the script without any additional options
* *
* @see #runScriptOnNodesMatching(Predicate, byte[], * @see #runScriptOnNodesMatching(Predicate, Payload,
* org.jclouds.compute.options.RunScriptOptions) * org.jclouds.compute.options.RunScriptOptions)
* @see org.jclouds.compute.predicates.NodePredicates#runningWithTag(String) * @see org.jclouds.compute.predicates.NodePredicates#runningWithTag(String)
*/ */
Map<? extends NodeMetadata, ExecResponse> runScriptOnNodesMatching( Map<? extends NodeMetadata, ExecResponse> runScriptOnNodesMatching(Predicate<NodeMetadata> filter, Payload runScript)
Predicate<NodeMetadata> filter, byte[] runScript) throws RunScriptOnNodesException; throws RunScriptOnNodesException;
/** /**
* Run the script on all nodes with the specific tag. * Run the script on all nodes with the specific tag.
* *
* @param filter * @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 * @param runScript
* script to run in byte format. If the script is a string, use * payload containing the script to run
* {@link String#getBytes()} to retrieve the bytes
* @param options * @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 * @return map with node identifiers and corresponding responses
* @throws RunScriptOnNodesException * @throws RunScriptOnNodesException
* if anything goes wrong during script execution * if anything goes wrong during script execution
* *
* @see org.jclouds.compute.predicates.NodePredicates#runningWithTag(String) * @see org.jclouds.compute.predicates.NodePredicates#runningWithTag(String)
* @see org.jclouds.io.Payloads
*/ */
Map<? extends NodeMetadata, ExecResponse> runScriptOnNodesMatching( Map<? extends NodeMetadata, ExecResponse> runScriptOnNodesMatching(Predicate<NodeMetadata> filter,
Predicate<NodeMetadata> filter, byte[] runScript, RunScriptOptions options) Payload runScript, RunScriptOptions options) throws RunScriptOnNodesException;
throws RunScriptOnNodesException;
} }

View File

@ -27,6 +27,7 @@ import javax.annotation.Nullable;
import org.jclouds.compute.domain.NodeMetadata; import org.jclouds.compute.domain.NodeMetadata;
import org.jclouds.compute.options.RunScriptOptions; import org.jclouds.compute.options.RunScriptOptions;
import org.jclouds.io.Payload;
import org.jclouds.ssh.ExecResponse; import org.jclouds.ssh.ExecResponse;
/** /**
@ -37,19 +38,17 @@ public class RunScriptOnNodesException extends Exception {
/** The serialVersionUID */ /** The serialVersionUID */
private static final long serialVersionUID = -2272965726680821281L; private static final long serialVersionUID = -2272965726680821281L;
private final byte[] runScript; private final Payload runScript;
private final RunScriptOptions options; private final RunScriptOptions options;
private final Map<NodeMetadata, ExecResponse> successfulNodes; private final Map<NodeMetadata, ExecResponse> successfulNodes;
private final Map<? extends NodeMetadata, ? extends Throwable> failedNodes; private final Map<? extends NodeMetadata, ? extends Throwable> failedNodes;
private final Map<?, Exception> executionExceptions; private final Map<?, Exception> executionExceptions;
public RunScriptOnNodesException(final byte[] runScript, public RunScriptOnNodesException(final Payload runScript, @Nullable final RunScriptOptions options,
@Nullable final RunScriptOptions options, Map<NodeMetadata, ExecResponse> successfulNodes, Map<?, Exception> executionExceptions,
Map<NodeMetadata, ExecResponse> successfulNodes, Map<?, Exception> executionExceptions, Map<? extends NodeMetadata, ? extends Throwable> failedNodes) {
Map<? extends NodeMetadata, ? extends Throwable> failedNodes) {
super(String.format("error runScript on filtered nodes options(%s)%n%s%n%s", options, super(String.format("error runScript on filtered nodes options(%s)%n%s%n%s", options,
createExecutionErrorMessage(executionExceptions), createExecutionErrorMessage(executionExceptions), createNodeErrorMessage(failedNodes)));
createNodeErrorMessage(failedNodes)));
this.runScript = runScript; this.runScript = runScript;
this.options = options; this.options = options;
this.successfulNodes = successfulNodes; 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<?, ? extends Throwable> getExecutionErrors() { public Map<?, ? extends Throwable> getExecutionErrors() {
return executionExceptions; 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<? extends NodeMetadata, ? extends Throwable> getNodeErrors() { public Map<? extends NodeMetadata, ? extends Throwable> getNodeErrors() {
return failedNodes; return failedNodes;
} }
public byte[] getRunScript() { public Payload getRunScript() {
return runScript; return runScript;
} }

View File

@ -20,10 +20,9 @@ package org.jclouds.compute.callables;
import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Preconditions.checkNotNull;
import java.io.ByteArrayInputStream;
import org.jclouds.compute.domain.NodeMetadata; import org.jclouds.compute.domain.NodeMetadata;
import org.jclouds.compute.util.ComputeServiceUtils.SshCallable; import org.jclouds.compute.util.ComputeServiceUtils.SshCallable;
import org.jclouds.io.Payload;
import org.jclouds.logging.Logger; import org.jclouds.logging.Logger;
import org.jclouds.ssh.ExecResponse; import org.jclouds.ssh.ExecResponse;
import org.jclouds.ssh.SshClient; import org.jclouds.ssh.SshClient;
@ -37,11 +36,11 @@ import com.google.common.collect.Iterables;
public class AuthorizeRSAPublicKey implements SshCallable<ExecResponse> { public class AuthorizeRSAPublicKey implements SshCallable<ExecResponse> {
private SshClient ssh; private SshClient ssh;
private final NodeMetadata node; private final NodeMetadata node;
private final String publicKey; private final Payload publicKey;
private Logger logger = Logger.NULL; private Logger logger = Logger.NULL;
public AuthorizeRSAPublicKey(NodeMetadata node, String publicKey) { public AuthorizeRSAPublicKey(NodeMetadata node, Payload publicKey) {
this.node = checkNotNull(node, "node"); this.node = checkNotNull(node, "node");
this.publicKey = checkNotNull(publicKey, "publicKey"); this.publicKey = checkNotNull(publicKey, "publicKey");
} }
@ -49,9 +48,9 @@ public class AuthorizeRSAPublicKey implements SshCallable<ExecResponse> {
@Override @Override
public ExecResponse call() throws Exception { public ExecResponse call() throws Exception {
ssh.exec("mkdir .ssh"); ssh.exec("mkdir .ssh");
ssh.put(".ssh/id_rsa.pub", new ByteArrayInputStream(publicKey.getBytes())); ssh.put(".ssh/id_rsa.pub", publicKey);
logger.debug(">> authorizing rsa public key for %s@%s", node.getCredentials().identity, logger.debug(">> authorizing rsa public key for %s@%s", node.getCredentials().identity, Iterables.get(node
Iterables.get(node.getPublicAddresses(), 0)); .getPublicAddresses(), 0));
ExecResponse returnVal = ssh.exec("cat .ssh/id_rsa.pub >> .ssh/authorized_keys"); ExecResponse returnVal = ssh.exec("cat .ssh/id_rsa.pub >> .ssh/authorized_keys");
returnVal = ssh.exec("chmod 600 .ssh/authorized_keys"); returnVal = ssh.exec("chmod 600 .ssh/authorized_keys");
logger.debug("<< complete(%d)", returnVal.getExitCode()); logger.debug("<< complete(%d)", returnVal.getExitCode());

View File

@ -20,10 +20,9 @@ package org.jclouds.compute.callables;
import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Preconditions.checkNotNull;
import java.io.ByteArrayInputStream;
import org.jclouds.compute.domain.NodeMetadata; import org.jclouds.compute.domain.NodeMetadata;
import org.jclouds.compute.util.ComputeServiceUtils.SshCallable; import org.jclouds.compute.util.ComputeServiceUtils.SshCallable;
import org.jclouds.io.Payload;
import org.jclouds.logging.Logger; import org.jclouds.logging.Logger;
import org.jclouds.ssh.ExecResponse; import org.jclouds.ssh.ExecResponse;
import org.jclouds.ssh.SshClient; import org.jclouds.ssh.SshClient;
@ -37,11 +36,11 @@ import com.google.common.collect.Iterables;
public class InstallRSAPrivateKey implements SshCallable<ExecResponse> { public class InstallRSAPrivateKey implements SshCallable<ExecResponse> {
private SshClient ssh; private SshClient ssh;
private final NodeMetadata node; private final NodeMetadata node;
private final String privateKey; private final Payload privateKey;
private Logger logger = Logger.NULL; private Logger logger = Logger.NULL;
public InstallRSAPrivateKey(NodeMetadata node, String privateKey) { public InstallRSAPrivateKey(NodeMetadata node, Payload privateKey) {
this.node = checkNotNull(node, "node"); this.node = checkNotNull(node, "node");
this.privateKey = checkNotNull(privateKey, "privateKey"); this.privateKey = checkNotNull(privateKey, "privateKey");
} }
@ -49,9 +48,9 @@ public class InstallRSAPrivateKey implements SshCallable<ExecResponse> {
@Override @Override
public ExecResponse call() throws Exception { public ExecResponse call() throws Exception {
ssh.exec("mkdir .ssh"); ssh.exec("mkdir .ssh");
ssh.put(".ssh/id_rsa", new ByteArrayInputStream(privateKey.getBytes())); ssh.put(".ssh/id_rsa", privateKey);
logger.debug(">> installing rsa key for %s@%s", node.getCredentials().identity, Iterables.get( logger.debug(">> installing rsa key for %s@%s", node.getCredentials().identity, Iterables.get(node
node.getPublicAddresses(), 0)); .getPublicAddresses(), 0));
return ssh.exec("chmod 600 .ssh/id_rsa"); return ssh.exec("chmod 600 .ssh/id_rsa");
} }

View File

@ -21,7 +21,8 @@ package org.jclouds.compute.callables;
import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Preconditions.checkNotNull;
import java.io.ByteArrayInputStream; import java.io.IOException;
import java.util.Collections;
import javax.inject.Named; 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.predicates.ScriptStatusReturnsZero.CommandUsingClient;
import org.jclouds.compute.util.ComputeServiceUtils; import org.jclouds.compute.util.ComputeServiceUtils;
import org.jclouds.compute.util.ComputeServiceUtils.SshCallable; 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.logging.Logger;
import org.jclouds.scriptbuilder.InitBuilder; import org.jclouds.scriptbuilder.InitBuilder;
import org.jclouds.scriptbuilder.domain.OsFamily; import org.jclouds.scriptbuilder.domain.OsFamily;
import org.jclouds.ssh.ExecResponse; import org.jclouds.ssh.ExecResponse;
import org.jclouds.ssh.SshClient; import org.jclouds.ssh.SshClient;
import org.jclouds.util.Utils;
import com.google.common.base.Predicate; import com.google.common.base.Predicate;
import com.google.common.base.Splitter; import com.google.common.base.Splitter;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Iterables; import com.google.common.collect.Iterables;
/** /**
@ -49,30 +52,43 @@ public class RunScriptOnNode implements SshCallable<ExecResponse> {
protected final Predicate<CommandUsingClient> runScriptNotRunning; protected final Predicate<CommandUsingClient> runScriptNotRunning;
private final NodeMetadata node; private final NodeMetadata node;
private final String scriptName; private final String scriptName;
private final byte[] script; private final Payload script;
private final boolean runAsRoot; private final boolean runAsRoot;
private Logger logger = Logger.NULL; private Logger logger = Logger.NULL;
public RunScriptOnNode(@Named("SCRIPT_COMPLETE") Predicate<CommandUsingClient> runScriptNotRunning, public RunScriptOnNode(@Named("SCRIPT_COMPLETE") Predicate<CommandUsingClient> runScriptNotRunning,
NodeMetadata node, String scriptName, byte[] script) { NodeMetadata node, String scriptName, Payload script) {
this(runScriptNotRunning, node, scriptName, script, true); this(runScriptNotRunning, node, scriptName, script, true);
} }
public RunScriptOnNode(@Named("SCRIPT_COMPLETE") Predicate<CommandUsingClient> runScriptNotRunning, public RunScriptOnNode(@Named("SCRIPT_COMPLETE") Predicate<CommandUsingClient> runScriptNotRunning,
NodeMetadata node, String scriptName, byte[] script, boolean runAsRoot) { NodeMetadata node, String scriptName, Payload script, boolean runAsRoot) {
this.runScriptNotRunning = runScriptNotRunning; this.runScriptNotRunning = runScriptNotRunning;
this.node = checkNotNull(node, "node"); this.node = checkNotNull(node, "node");
this.scriptName = checkNotNull(scriptName, "scriptName"); this.scriptName = checkNotNull(scriptName, "scriptName");
this.script = new InitBuilder(scriptName, "/tmp/" + scriptName, "/tmp/" + scriptName, this.script = createRunScript(scriptName, script);
ImmutableMap.<String, String> of(), Iterables.toArray(Splitter.on("\n").split(
new String(checkNotNull(script, "script"))), String.class)).build(
OsFamily.UNIX).getBytes();
this.runAsRoot = runAsRoot; this.runAsRoot = runAsRoot;
} }
public static Payload createRunScript(String scriptName, Payload script) {
String path = "/tmp/" + scriptName;
InitBuilder initBuilder = new InitBuilder(scriptName, path, path, Collections.<String, String> 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 @Override
public ExecResponse call() throws Exception { public ExecResponse call() throws Exception {
ssh.put(scriptName, new ByteArrayInputStream(script)); ssh.put(scriptName, script);
ExecResponse returnVal = ssh.exec("chmod 755 " + scriptName); ExecResponse returnVal = ssh.exec("chmod 755 " + scriptName);
returnVal = ssh.exec("./" + scriptName + " init"); returnVal = ssh.exec("./" + scriptName + " init");
@ -83,12 +99,10 @@ public class RunScriptOnNode implements SshCallable<ExecResponse> {
runScriptNotRunning.apply(new CommandUsingClient("./" + scriptName + " status", ssh)); runScriptNotRunning.apply(new CommandUsingClient("./" + scriptName + " status", ssh));
logger.debug("<< complete(%d)", returnVal.getExitCode()); logger.debug("<< complete(%d)", returnVal.getExitCode());
if (logger.isDebugEnabled() || returnVal.getExitCode() != 0) { if (logger.isDebugEnabled() || returnVal.getExitCode() != 0) {
logger.debug("<< stdout from %s as %s@%s\n%s", scriptName, node.getCredentials().identity, logger.debug("<< stdout from %s as %s@%s\n%s", scriptName, node.getCredentials().identity, Iterables.get(node
Iterables.get(node.getPublicAddresses(), 0), ssh .getPublicAddresses(), 0), ssh.exec("./" + scriptName + " tail").getOutput());
.exec("./" + scriptName + " tail").getOutput()); logger.debug("<< stderr from %s as %s@%s\n%s", scriptName, node.getCredentials().identity, Iterables.get(node
logger.debug("<< stderr from %s as %s@%s\n%s", scriptName, node.getCredentials().identity, .getPublicAddresses(), 0), ssh.exec("./" + scriptName + " tailerr").getOutput());
Iterables.get(node.getPublicAddresses(), 0), ssh.exec(
"./" + scriptName + " tailerr").getOutput());
} }
return returnVal; return returnVal;
} }
@ -101,24 +115,24 @@ public class RunScriptOnNode implements SshCallable<ExecResponse> {
private ExecResponse runScriptAsRoot() { private ExecResponse runScriptAsRoot() {
if (node.getCredentials().identity.equals("root")) { if (node.getCredentials().identity.equals("root")) {
logger.debug(">> running %s as %s@%s", scriptName, node.getCredentials().identity, logger.debug(">> running %s as %s@%s", scriptName, node.getCredentials().identity, Iterables.get(node
Iterables.get(node.getPublicAddresses(), 0)); .getPublicAddresses(), 0));
return ssh.exec("./" + scriptName + " start"); return ssh.exec("./" + scriptName + " start");
} else if (ComputeServiceUtils.isKeyAuth(node)) { } else if (ComputeServiceUtils.isKeyAuth(node)) {
logger.debug(">> running sudo %s as %s@%s", scriptName, node.getCredentials().identity, logger.debug(">> running sudo %s as %s@%s", scriptName, node.getCredentials().identity, Iterables.get(node
Iterables.get(node.getPublicAddresses(), 0)); .getPublicAddresses(), 0));
return ssh.exec("sudo ./" + scriptName + " start"); return ssh.exec("sudo ./" + scriptName + " start");
} else { } else {
logger.debug(">> running sudo -S %s as %s@%s", scriptName, node.getCredentials().identity, logger.debug(">> running sudo -S %s as %s@%s", scriptName, node.getCredentials().identity, Iterables.get(node
Iterables.get(node.getPublicAddresses(), 0)); .getPublicAddresses(), 0));
return ssh.exec(String.format("echo '%s'|sudo -S ./%s", node.getCredentials().credential, return ssh.exec(String.format("echo '%s'|sudo -S ./%s", node.getCredentials().credential, scriptName
scriptName + " start")); + " start"));
} }
} }
private ExecResponse runScriptAsDefaultUser() { private ExecResponse runScriptAsDefaultUser() {
logger.debug(">> running script %s as %s@%s", scriptName, node.getCredentials().identity, logger.debug(">> running script %s as %s@%s", scriptName, node.getCredentials().identity, Iterables.get(node
Iterables.get(node.getPublicAddresses(), 0)); .getPublicAddresses(), 0));
return ssh.exec(String.format("./%s", scriptName + " start")); return ssh.exec(String.format("./%s", scriptName + " start"));
} }

View File

@ -25,6 +25,7 @@ package org.jclouds.compute.internal;
import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull; 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.awaitCompletion;
import static org.jclouds.concurrent.ConcurrentUtils.makeListenable; 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.ListNodesStrategy;
import org.jclouds.compute.strategy.RebootNodeStrategy; import org.jclouds.compute.strategy.RebootNodeStrategy;
import org.jclouds.compute.strategy.RunNodesAndAddToSetStrategy; import org.jclouds.compute.strategy.RunNodesAndAddToSetStrategy;
import static org.jclouds.compute.util.ComputeServiceUtils.*;
import org.jclouds.compute.util.ComputeUtils; import org.jclouds.compute.util.ComputeUtils;
import org.jclouds.domain.Location; import org.jclouds.domain.Location;
import org.jclouds.io.Payload;
import org.jclouds.logging.Logger; import org.jclouds.logging.Logger;
import org.jclouds.ssh.ExecResponse; import org.jclouds.ssh.ExecResponse;
import org.jclouds.ssh.SshClient; import org.jclouds.ssh.SshClient;
@ -104,32 +105,25 @@ public class BaseComputeService implements ComputeService {
protected final ExecutorService executor; protected final ExecutorService executor;
@Inject @Inject
protected BaseComputeService(ComputeServiceContext context, protected BaseComputeService(ComputeServiceContext context, Provider<Set<? extends Image>> images,
Provider<Set<? extends Image>> images, Provider<Set<? extends Size>> sizes, Provider<Set<? extends Size>> sizes, Provider<Set<? extends Location>> locations,
Provider<Set<? extends Location>> locations, ListNodesStrategy listNodesStrategy, ListNodesStrategy listNodesStrategy, GetNodeMetadataStrategy getNodeMetadataStrategy,
GetNodeMetadataStrategy getNodeMetadataStrategy, RunNodesAndAddToSetStrategy runNodesAndAddToSetStrategy, RebootNodeStrategy rebootNodeStrategy,
RunNodesAndAddToSetStrategy runNodesAndAddToSetStrategy, DestroyNodeStrategy destroyNodeStrategy, Provider<TemplateBuilder> templateBuilderProvider,
RebootNodeStrategy rebootNodeStrategy, DestroyNodeStrategy destroyNodeStrategy, Provider<TemplateOptions> templateOptionsProvider, @Named("NODE_RUNNING") Predicate<NodeMetadata> nodeRunning,
Provider<TemplateBuilder> templateBuilderProvider, @Named("NODE_TERMINATED") Predicate<NodeMetadata> nodeTerminated, ComputeUtils utils,
Provider<TemplateOptions> templateOptionsProvider, @Named(Constants.PROPERTY_USER_THREADS) ExecutorService executor) {
@Named("NODE_RUNNING") Predicate<NodeMetadata> nodeRunning,
@Named("NODE_TERMINATED") Predicate<NodeMetadata> nodeTerminated, ComputeUtils utils,
@Named(Constants.PROPERTY_USER_THREADS) ExecutorService executor) {
this.context = checkNotNull(context, "context"); this.context = checkNotNull(context, "context");
this.images = checkNotNull(images, "images"); this.images = checkNotNull(images, "images");
this.sizes = checkNotNull(sizes, "sizes"); this.sizes = checkNotNull(sizes, "sizes");
this.locations = checkNotNull(locations, "locations"); this.locations = checkNotNull(locations, "locations");
this.listNodesStrategy = checkNotNull(listNodesStrategy, "listNodesStrategy"); this.listNodesStrategy = checkNotNull(listNodesStrategy, "listNodesStrategy");
this.getNodeMetadataStrategy = checkNotNull(getNodeMetadataStrategy, this.getNodeMetadataStrategy = checkNotNull(getNodeMetadataStrategy, "getNodeMetadataStrategy");
"getNodeMetadataStrategy"); this.runNodesAndAddToSetStrategy = checkNotNull(runNodesAndAddToSetStrategy, "runNodesAndAddToSetStrategy");
this.runNodesAndAddToSetStrategy = checkNotNull(runNodesAndAddToSetStrategy,
"runNodesAndAddToSetStrategy");
this.rebootNodeStrategy = checkNotNull(rebootNodeStrategy, "rebootNodeStrategy"); this.rebootNodeStrategy = checkNotNull(rebootNodeStrategy, "rebootNodeStrategy");
this.destroyNodeStrategy = checkNotNull(destroyNodeStrategy, "destroyNodeStrategy"); this.destroyNodeStrategy = checkNotNull(destroyNodeStrategy, "destroyNodeStrategy");
this.templateBuilderProvider = checkNotNull(templateBuilderProvider, this.templateBuilderProvider = checkNotNull(templateBuilderProvider, "templateBuilderProvider");
"templateBuilderProvider"); this.templateOptionsProvider = checkNotNull(templateOptionsProvider, "templateOptionsProvider");
this.templateOptionsProvider = checkNotNull(templateOptionsProvider,
"templateOptionsProvider");
this.nodeRunning = checkNotNull(nodeRunning, "nodeRunning"); this.nodeRunning = checkNotNull(nodeRunning, "nodeRunning");
this.nodeTerminated = checkNotNull(nodeTerminated, "nodeTerminated"); this.nodeTerminated = checkNotNull(nodeTerminated, "nodeTerminated");
this.utils = checkNotNull(utils, "utils"); this.utils = checkNotNull(utils, "utils");
@ -149,19 +143,17 @@ public class BaseComputeService implements ComputeService {
*/ */
@Override @Override
public Set<? extends NodeMetadata> runNodesWithTag(String tag, int count, Template template) public Set<? extends NodeMetadata> runNodesWithTag(String tag, int count, Template template)
throws RunNodesException { throws RunNodesException {
checkArgument(tag.indexOf('-') == -1, "tag cannot contain hyphens"); checkArgument(tag.indexOf('-') == -1, "tag cannot contain hyphens");
checkNotNull(template.getLocation(), "location"); checkNotNull(template.getLocation(), "location");
logger.debug(">> running %d node%s tag(%s) location(%s) image(%s) size(%s) options(%s)", logger.debug(">> running %d node%s tag(%s) location(%s) image(%s) size(%s) options(%s)", count, count > 1 ? "s"
count, count > 1 ? "s" : "", tag, template.getLocation().getId(), template : "", tag, template.getLocation().getId(), template.getImage().getProviderId(), template.getSize()
.getImage().getProviderId(), template.getSize().getProviderId(), template .getProviderId(), template.getOptions());
.getOptions());
Set<NodeMetadata> nodes = Sets.newHashSet(); Set<NodeMetadata> nodes = Sets.newHashSet();
Map<NodeMetadata, Exception> badNodes = Maps.newLinkedHashMap(); Map<NodeMetadata, Exception> badNodes = Maps.newLinkedHashMap();
Map<?, ListenableFuture<Void>> responses = runNodesAndAddToSetStrategy.execute(tag, count, Map<?, ListenableFuture<Void>> responses = runNodesAndAddToSetStrategy.execute(tag, count, template, nodes,
template, nodes, badNodes); badNodes);
Map<?, Exception> executionExceptions = awaitCompletion(responses, executor, null, logger, Map<?, Exception> executionExceptions = awaitCompletion(responses, executor, null, logger, "starting nodes");
"starting nodes");
if (executionExceptions.size() > 0 || badNodes.size() > 0) { if (executionExceptions.size() > 0 || badNodes.size() > 0) {
throw new RunNodesException(tag, count, template, nodes, executionExceptions, badNodes); throw new RunNodesException(tag, count, template, nodes, executionExceptions, badNodes);
} }
@ -172,8 +164,8 @@ public class BaseComputeService implements ComputeService {
* {@inheritDoc} * {@inheritDoc}
*/ */
@Override @Override
public Set<? extends NodeMetadata> runNodesWithTag(String tag, int count, public Set<? extends NodeMetadata> runNodesWithTag(String tag, int count, TemplateOptions templateOptions)
TemplateOptions templateOptions) throws RunNodesException { throws RunNodesException {
return runNodesWithTag(tag, count, templateBuilder().any().options(templateOptions).build()); return runNodesWithTag(tag, count, templateBuilder().any().options(templateOptions).build());
} }
@ -181,8 +173,7 @@ public class BaseComputeService implements ComputeService {
* {@inheritDoc} * {@inheritDoc}
*/ */
@Override @Override
public Set<? extends NodeMetadata> runNodesWithTag(String tag, int count) public Set<? extends NodeMetadata> runNodesWithTag(String tag, int count) throws RunNodesException {
throws RunNodesException {
return runNodesWithTag(tag, count, templateOptions()); return runNodesWithTag(tag, count, templateOptions());
} }
@ -221,10 +212,8 @@ public class BaseComputeService implements ComputeService {
return destroyedNodes; return destroyedNodes;
} }
private Iterable<? extends NodeMetadata> nodesMatchingFilterAndNotTerminated( private Iterable<? extends NodeMetadata> nodesMatchingFilterAndNotTerminated(Predicate<NodeMetadata> filter) {
Predicate<NodeMetadata> filter) { return Iterables.filter(detailsOnAllNodes(), Predicates.and(filter, Predicates.not(NodePredicates.TERMINATED)));
return Iterables.filter(detailsOnAllNodes(), Predicates.and(filter, Predicates
.not(NodePredicates.TERMINATED)));
} }
/** /**
@ -245,8 +234,7 @@ public class BaseComputeService implements ComputeService {
public Set<? extends NodeMetadata> listNodesDetailsMatching(Predicate<ComputeMetadata> filter) { public Set<? extends NodeMetadata> listNodesDetailsMatching(Predicate<ComputeMetadata> filter) {
checkNotNull(filter, "filter"); checkNotNull(filter, "filter");
logger.debug(">> listing node details matching(%s)", filter); logger.debug(">> listing node details matching(%s)", filter);
Set<? extends NodeMetadata> set = Sets.newLinkedHashSet(listNodesStrategy Set<? extends NodeMetadata> set = Sets.newLinkedHashSet(listNodesStrategy.listDetailsOnNodesMatching(filter));
.listDetailsOnNodesMatching(filter));
logger.debug("<< list(%d)", set.size()); logger.debug("<< list(%d)", set.size());
return set; return set;
} }
@ -329,8 +317,8 @@ public class BaseComputeService implements ComputeService {
* {@inheritDoc} * {@inheritDoc}
*/ */
@Override @Override
public Map<? extends NodeMetadata, ExecResponse> runScriptOnNodesMatching( public Map<? extends NodeMetadata, ExecResponse> runScriptOnNodesMatching(Predicate<NodeMetadata> filter,
Predicate<NodeMetadata> filter, byte[] runScript) throws RunScriptOnNodesException { Payload runScript) throws RunScriptOnNodesException {
return runScriptOnNodesMatching(filter, runScript, RunScriptOptions.NONE); return runScriptOnNodesMatching(filter, runScript, RunScriptOptions.NONE);
} }
@ -339,10 +327,9 @@ public class BaseComputeService implements ComputeService {
*/ */
@Override @Override
public Map<NodeMetadata, ExecResponse> runScriptOnNodesMatching(Predicate<NodeMetadata> filter, public Map<NodeMetadata, ExecResponse> runScriptOnNodesMatching(Predicate<NodeMetadata> filter,
final byte[] runScript, @Nullable final RunScriptOptions options) final Payload runScript, @Nullable final RunScriptOptions options) throws RunScriptOnNodesException {
throws RunScriptOnNodesException {
Iterable<? extends NodeMetadata> nodes = verifyParametersAndListNodes(filter, runScript, Iterable<? extends NodeMetadata> nodes = verifyParametersAndListNodes(filter, runScript,
(options != null) ? options : RunScriptOptions.NONE); (options != null) ? options : RunScriptOptions.NONE);
final Map<NodeMetadata, ExecResponse> execs = Maps.newHashMap(); final Map<NodeMetadata, ExecResponse> execs = Maps.newHashMap();
@ -379,8 +366,7 @@ public class BaseComputeService implements ComputeService {
}), executor)); }), executor));
} }
Map<?, Exception> exceptions = awaitCompletion(responses, executor, null, logger, Map<?, Exception> exceptions = awaitCompletion(responses, executor, null, logger, "starting nodes");
"starting nodes");
if (exceptions.size() > 0 || badNodes.size() > 0) { if (exceptions.size() > 0 || badNodes.size() > 0) {
throw new RunScriptOnNodesException(runScript, options, execs, exceptions, badNodes); throw new RunScriptOnNodesException(runScript, options, execs, exceptions, badNodes);
} }
@ -388,11 +374,10 @@ public class BaseComputeService implements ComputeService {
} }
private Iterable<? extends NodeMetadata> verifyParametersAndListNodes( private Iterable<? extends NodeMetadata> verifyParametersAndListNodes(Predicate<NodeMetadata> filter,
Predicate<NodeMetadata> filter, byte[] runScript, final RunScriptOptions options) { Payload runScript, final RunScriptOptions options) {
checkNotNull(filter, "Filter must be provided"); checkNotNull(filter, "Filter must be provided");
checkNotNull(runScript, checkNotNull(runScript, "The script (represented by bytes array - use \"script\".getBytes() must be provided");
"The script (represented by bytes array - use \"script\".getBytes() must be provided");
checkNotNull(options, "options"); checkNotNull(options, "options");
Iterable<? extends NodeMetadata> nodes = Iterables.filter(detailsOnAllNodes(), filter); Iterable<? extends NodeMetadata> nodes = Iterables.filter(detailsOnAllNodes(), filter);
@ -402,22 +387,18 @@ public class BaseComputeService implements ComputeService {
@Override @Override
public NodeMetadata apply(NodeMetadata node) { public NodeMetadata apply(NodeMetadata node) {
checkArgument(node.getPublicAddresses().size() > 0, "no public ip addresses on node: " checkArgument(node.getPublicAddresses().size() > 0, "no public ip addresses on node: " + node);
+ node);
if (options.getOverrideCredentials() != null) { if (options.getOverrideCredentials() != null) {
// override the credentials with provided to this // override the credentials with provided to this
// method // method
node = installNewCredentials(node, options.getOverrideCredentials()); node = installNewCredentials(node, options.getOverrideCredentials());
} else { } else {
// don't override // don't override
checkNotNull(node.getCredentials(), checkNotNull(node.getCredentials(), "If the default credentials need to be used, they can't be null");
"If the default credentials need to be used, they can't be null"); checkNotNull(node.getCredentials().identity, "Account name for ssh authentication must be "
checkNotNull(node.getCredentials().identity, + "specified. Try passing RunScriptOptions with new credentials");
"Account name for ssh authentication must be " checkNotNull(node.getCredentials().credential, "Key or password for ssh authentication must be "
+ "specified. Try passing RunScriptOptions with new credentials"); + "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; return node;
} }

View File

@ -20,9 +20,13 @@ package org.jclouds.compute.options;
import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull; 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 java.util.Arrays;
import org.jclouds.io.Payload;
/** /**
* Contains options supported in the {@code ComputeService#runNodesWithTag} * Contains options supported in the {@code ComputeService#runNodesWithTag}
* operation. <h2> * operation. <h2>
@ -42,303 +46,384 @@ import java.util.Arrays;
*/ */
public class TemplateOptions { public class TemplateOptions {
public static final TemplateOptions NONE = new ImmutableTemplateOptions( public static final TemplateOptions NONE = new ImmutableTemplateOptions(new TemplateOptions());
new TemplateOptions());
public static class ImmutableTemplateOptions extends TemplateOptions { public static class ImmutableTemplateOptions extends TemplateOptions {
private final TemplateOptions delegate; private final TemplateOptions delegate;
public ImmutableTemplateOptions(TemplateOptions delegate) { public ImmutableTemplateOptions(TemplateOptions delegate) {
this.delegate = delegate; this.delegate = delegate;
} }
@Override @Override
public String toString() { public String toString() {
return delegate.toString(); return delegate.toString();
} }
@Override @Override
public <T extends TemplateOptions> T as(Class<T> clazz) { public <T extends TemplateOptions> T as(Class<T> clazz) {
return delegate.as(clazz); return delegate.as(clazz);
} }
@Override @Override
public TemplateOptions authorizePublicKey(String publicKey) { public TemplateOptions authorizePublicKey(String publicKey) {
throw new IllegalArgumentException( throw new IllegalArgumentException("authorizePublicKey is immutable");
"authorizePublicKey is immutable"); }
}
@Override @Override
public TemplateOptions blockUntilRunning(boolean blockUntilRunning) { public TemplateOptions blockUntilRunning(boolean blockUntilRunning) {
throw new IllegalArgumentException("blockUntilRunning is immutable"); throw new IllegalArgumentException("blockUntilRunning is immutable");
} }
@Override @Override
public TemplateOptions blockOnPort(int port, int seconds) { public TemplateOptions blockOnPort(int port, int seconds) {
throw new IllegalArgumentException("port, seconds are immutable"); throw new IllegalArgumentException("port, seconds are immutable");
} }
@Override @Override
public int[] getInboundPorts() { public int[] getInboundPorts() {
return delegate.getInboundPorts(); return delegate.getInboundPorts();
} }
@Override @Override
public int getPort() { public int getPort() {
return delegate.getPort(); return delegate.getPort();
} }
@Override @Override
public String getPrivateKey() { public Payload getPrivateKey() {
return delegate.getPrivateKey(); return delegate.getPrivateKey();
} }
@Override @Override
public String getPublicKey() { public Payload getPublicKey() {
return delegate.getPublicKey(); return delegate.getPublicKey();
} }
@Override @Override
public byte[] getRunScript() { public Payload getRunScript() {
return delegate.getRunScript(); return delegate.getRunScript();
} }
@Override @Override
public int getSeconds() { public int getSeconds() {
return delegate.getSeconds(); return delegate.getSeconds();
} }
@Override @Override
public boolean shouldBlockUntilRunning() { public boolean shouldBlockUntilRunning() {
return delegate.shouldBlockUntilRunning(); return delegate.shouldBlockUntilRunning();
} }
@Override @Override
public TemplateOptions inboundPorts(int... ports) { public TemplateOptions inboundPorts(int... ports) {
throw new IllegalArgumentException("ports is immutable"); throw new IllegalArgumentException("ports is immutable");
} }
@Override @Override
public TemplateOptions installPrivateKey(String privateKey) { public TemplateOptions installPrivateKey(String privateKey) {
throw new IllegalArgumentException("privateKey is immutable"); throw new IllegalArgumentException("privateKey is immutable");
} }
@Override @Override
public boolean isIncludeMetadata() { public boolean isIncludeMetadata() {
return delegate.isIncludeMetadata(); return delegate.isIncludeMetadata();
} }
@Override @Override
public TemplateOptions runScript(byte[] script) { public TemplateOptions runScript(byte[] script) {
throw new IllegalArgumentException("withMetadata is immutable"); throw new IllegalArgumentException("withMetadata is immutable");
} }
@Override @Override
public TemplateOptions withMetadata() { public TemplateOptions withMetadata() {
throw new IllegalArgumentException("withMetadata is immutable"); 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() { public int getPort() {
return port; return port;
} }
public int getSeconds() { public int getSeconds() {
return seconds; return seconds;
} }
public int[] getInboundPorts() { public int[] getInboundPorts() {
return inboundPorts; return inboundPorts;
} }
public byte[] getRunScript() { public Payload getRunScript() {
return script; return script;
} }
public String getPrivateKey() { public Payload getPrivateKey() {
return privateKey; return privateKey;
} }
public String getPublicKey() { public Payload getPublicKey() {
return publicKey; return publicKey;
} }
public boolean isIncludeMetadata() { public boolean isIncludeMetadata() {
return includeMetadata; return includeMetadata;
} }
public boolean shouldBlockUntilRunning() { public boolean shouldBlockUntilRunning() {
return blockUntilRunning; return blockUntilRunning;
} }
public <T extends TemplateOptions> T as(Class<T> clazz) { public <T extends TemplateOptions> T as(Class<T> clazz) {
return clazz.cast(this); return clazz.cast(this);
} }
/** /**
* When the node is started, wait until the following port is active * When the node is started, wait until the following port is active
*/ */
public TemplateOptions blockOnPort(int port, int seconds) { public TemplateOptions blockOnPort(int port, int seconds) {
checkArgument(port > 0 && port < 65536, checkArgument(port > 0 && port < 65536, "port must be a positive integer < 65535");
"port must be a positive integer < 65535"); checkArgument(seconds > 0, "seconds must be a positive integer");
checkArgument(seconds > 0, "seconds must be a positive integer"); this.port = port;
this.port = port; this.seconds = seconds;
this.seconds = seconds; return this;
return this; }
}
/** /**
* This script will be executed as the root user upon system startup. 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 * script gets a prologue, so no #!/bin/bash required, path set up, etc
*/ * <p/>
public TemplateOptions runScript(byte[] script) { * please use alternative that uses the {@link org.jclouds.io.Payload} object
checkArgument(checkNotNull(script, "script").length <= 16 * 1024, *
"script cannot be larger than 16kb"); * @see org.jclouds.io.Payloads
this.script = script; */
return this; @Deprecated
} public TemplateOptions runScript(byte[] script) {
return runScript(newByteArrayPayload(checkNotNull(script, "script")));
}
/** /**
* replaces the rsa ssh key used at login. * 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 installPrivateKey(String privateKey) { *
checkArgument(checkNotNull(privateKey, "privateKey").startsWith( * @see org.jclouds.io.Payloads
"-----BEGIN RSA PRIVATE KEY-----"), */
"key should start with -----BEGIN RSA PRIVATE KEY-----"); public TemplateOptions runScript(Payload script) {
this.privateKey = privateKey; checkArgument(
return this; 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; * replaces the rsa ssh key used at login.
return this; * <p/>
} * 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 * replaces the rsa ssh key used at login.
* server is provisioned. *
* <p/> * @see org.jclouds.io.Payloads
* default is true */
*/ public TemplateOptions installPrivateKey(Payload privateKey) {
public TemplateOptions blockUntilRunning(boolean blockUntilRunning) { this.privateKey = checkNotNull(privateKey, "privateKey");
this.blockUntilRunning = blockUntilRunning; return this;
if (!blockUntilRunning) }
port = seconds = -1;
return this;
}
/** public TemplateOptions dontAuthorizePublicKey() {
* authorized an rsa ssh key. this.publicKey = null;
*/ return this;
public TemplateOptions authorizePublicKey(String publicKey) { }
checkArgument(checkNotNull(publicKey, "publicKey")
.startsWith("ssh-rsa"), "key should start with ssh-rsa");
this.publicKey = publicKey;
return this;
}
/** /**
* Opens the set of ports to public access. * if true, return when node(s) are NODE_RUNNING, if false, return as soon as
*/ * the server is provisioned.
public TemplateOptions inboundPorts(int... ports) { * <p/>
for (int port : ports) * default is true
checkArgument(port > 0 && port < 65536, */
"port must be a positive integer < 65535"); public TemplateOptions blockUntilRunning(boolean blockUntilRunning) {
this.inboundPorts = ports; this.blockUntilRunning = blockUntilRunning;
return this; if (!blockUntilRunning)
} port = seconds = -1;
return this;
}
public TemplateOptions withMetadata() { /**
this.includeMetadata = true; * authorize an rsa ssh key.
return this; * <p/>
} * 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 * Opens the set of ports to public access.
*/ */
public static TemplateOptions inboundPorts(int... ports) { public TemplateOptions inboundPorts(int... ports) {
TemplateOptions options = new TemplateOptions(); for (int port : ports)
return options.inboundPorts(ports); checkArgument(port > 0 && port < 65536, "port must be a positive integer < 65535");
} this.inboundPorts = ports;
return this;
}
/** public TemplateOptions withMetadata() {
* @see TemplateOptions#port this.includeMetadata = true;
*/ return this;
public static TemplateOptions blockOnPort(int port, int seconds) { }
TemplateOptions options = new TemplateOptions();
return options.blockOnPort(port, seconds);
}
/** public static class Builder {
* @see TemplateOptions#blockUntilRunning
*/
public static TemplateOptions blockUntilRunning(
boolean blockUntilRunning) {
TemplateOptions options = new TemplateOptions();
return options.blockUntilRunning(blockUntilRunning);
}
/** /**
* @see TemplateOptions#runScript * @see TemplateOptions#inboundPorts
*/ */
public static TemplateOptions runScript(byte[] script) { public static TemplateOptions inboundPorts(int... ports) {
TemplateOptions options = new TemplateOptions(); TemplateOptions options = new TemplateOptions();
return options.runScript(script); return options.inboundPorts(ports);
} }
/** /**
* @see TemplateOptions#installPrivateKey * @see TemplateOptions#port
*/ */
public static TemplateOptions installPrivateKey(String rsaKey) { public static TemplateOptions blockOnPort(int port, int seconds) {
TemplateOptions options = new TemplateOptions(); TemplateOptions options = new TemplateOptions();
return options.installPrivateKey(rsaKey); return options.blockOnPort(port, seconds);
} }
/** /**
* @see TemplateOptions#authorizePublicKey * @see TemplateOptions#blockUntilRunning
*/ */
public static TemplateOptions authorizePublicKey(String rsaKey) { public static TemplateOptions blockUntilRunning(boolean blockUntilRunning) {
TemplateOptions options = new TemplateOptions(); TemplateOptions options = new TemplateOptions();
return options.authorizePublicKey(rsaKey); return options.blockUntilRunning(blockUntilRunning);
} }
public static TemplateOptions withDetails() { /**
TemplateOptions options = new TemplateOptions(); * please use alternative that uses the {@link org.jclouds.io.Payload}
return options.withMetadata(); * 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() { * please use alternative that uses the {@link org.jclouds.io.Payload}
return "TemplateOptions [inboundPorts=" + Arrays.toString(inboundPorts) * object
+ ", privateKey=" + (privateKey != null) + ", publicKey=" *
+ (publicKey != null) + ", runScript=" + (script != null) * @see org.jclouds.io.Payloads
+ ", blockUntilRunning=" + blockUntilRunning * @see #installPrivateKey(Payload)
+ ", port:seconds=" + port + ":" + seconds */
+ ", metadata/details: " + includeMetadata + "]"; @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() { public int hashCode() {
final int prime = 31; final int prime = 31;
int result = 1; int result = 1;
@ -346,16 +431,14 @@ public class TemplateOptions {
result = prime * result + Arrays.hashCode(inboundPorts); result = prime * result + Arrays.hashCode(inboundPorts);
result = prime * result + (includeMetadata ? 1231 : 1237); result = prime * result + (includeMetadata ? 1231 : 1237);
result = prime * result + port; result = prime * result + port;
result = prime * result result = prime * result + ((privateKey == null) ? 0 : privateKey.hashCode());
+ ((privateKey == null) ? 0 : privateKey.hashCode()); result = prime * result + ((publicKey == null) ? 0 : publicKey.hashCode());
result = prime * result result = prime * result + ((script == null) ? 0 : script.hashCode());
+ ((publicKey == null) ? 0 : publicKey.hashCode());
result = prime * result + Arrays.hashCode(script);
result = prime * result + seconds; result = prime * result + seconds;
return result; return result;
} }
@Override @Override
public boolean equals(Object obj) { public boolean equals(Object obj) {
if (this == obj) if (this == obj)
return true; return true;
@ -382,7 +465,10 @@ public class TemplateOptions {
return false; return false;
} else if (!publicKey.equals(other.publicKey)) } else if (!publicKey.equals(other.publicKey))
return false; 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; return false;
if (seconds != other.seconds) if (seconds != other.seconds)
return false; return false;

View File

@ -50,6 +50,7 @@ import org.jclouds.compute.reference.ComputeServiceConstants.Timeouts;
import org.jclouds.compute.strategy.GetNodeMetadataStrategy; import org.jclouds.compute.strategy.GetNodeMetadataStrategy;
import org.jclouds.compute.util.ComputeServiceUtils.SshCallable; import org.jclouds.compute.util.ComputeServiceUtils.SshCallable;
import org.jclouds.concurrent.ConcurrentUtils; import org.jclouds.concurrent.ConcurrentUtils;
import org.jclouds.io.Payload;
import org.jclouds.logging.Logger; import org.jclouds.logging.Logger;
import org.jclouds.net.IPSocket; import org.jclouds.net.IPSocket;
import org.jclouds.predicates.RetryablePredicate; import org.jclouds.predicates.RetryablePredicate;
@ -83,10 +84,9 @@ public class ComputeUtils {
@Inject @Inject
public ComputeUtils(Predicate<IPSocket> socketTester, public ComputeUtils(Predicate<IPSocket> socketTester,
@Named("SCRIPT_COMPLETE") Predicate<CommandUsingClient> runScriptNotRunning, @Named("SCRIPT_COMPLETE") Predicate<CommandUsingClient> runScriptNotRunning, GetNodeMetadataStrategy getNode,
GetNodeMetadataStrategy getNode, Timeouts timeouts, Timeouts timeouts, @Named("NODE_RUNNING") Predicate<NodeMetadata> nodeRunning,
@Named("NODE_RUNNING") Predicate<NodeMetadata> nodeRunning, @Named(Constants.PROPERTY_USER_THREADS) ExecutorService executor) {
@Named(Constants.PROPERTY_USER_THREADS) ExecutorService executor) {
this.nodeRunning = nodeRunning; this.nodeRunning = nodeRunning;
this.timeouts = timeouts; this.timeouts = timeouts;
this.getNode = getNode; this.getNode = getNode;
@ -96,20 +96,18 @@ public class ComputeUtils {
} }
public Map<?, ListenableFuture<Void>> runOptionsOnNodesAndAddToGoodSetOrPutExceptionIntoBadMap( public Map<?, ListenableFuture<Void>> runOptionsOnNodesAndAddToGoodSetOrPutExceptionIntoBadMap(
final TemplateOptions options, Iterable<NodeMetadata> runningNodes, final TemplateOptions options, Iterable<NodeMetadata> runningNodes, final Set<NodeMetadata> goodNodes,
final Set<NodeMetadata> goodNodes, final Map<NodeMetadata, Exception> badNodes) { final Map<NodeMetadata, Exception> badNodes) {
Map<NodeMetadata, ListenableFuture<Void>> responses = Maps.newHashMap(); Map<NodeMetadata, ListenableFuture<Void>> responses = Maps.newHashMap();
for (final NodeMetadata node : runningNodes) { for (final NodeMetadata node : runningNodes) {
responses.put(node, makeListenable(executor responses.put(node, makeListenable(executor.submit(runOptionsOnNodeAndAddToGoodSetOrPutExceptionIntoBadMap(
.submit(runOptionsOnNodeAndAddToGoodSetOrPutExceptionIntoBadMap(node, badNodes, node, badNodes, goodNodes, options)), executor));
goodNodes, options)), executor));
} }
return responses; return responses;
} }
public Callable<Void> runOptionsOnNodeAndAddToGoodSetOrPutExceptionIntoBadMap( public Callable<Void> runOptionsOnNodeAndAddToGoodSetOrPutExceptionIntoBadMap(final NodeMetadata node,
final NodeMetadata node, final Map<NodeMetadata, Exception> badNodes, final Map<NodeMetadata, Exception> badNodes, final Set<NodeMetadata> goodNodes, final TemplateOptions options) {
final Set<NodeMetadata> goodNodes, final TemplateOptions options) {
return new Callable<Void>() { return new Callable<Void>() {
@Override @Override
public Void call() throws Exception { public Void call() throws Exception {
@ -118,8 +116,8 @@ public class ComputeUtils {
logger.debug("<< options applied node(%s)", node1.getId()); logger.debug("<< options applied node(%s)", node1.getId());
goodNodes.add(node1); goodNodes.add(node1);
} catch (Exception e) { } catch (Exception e) {
logger.error(e, "<< problem applying options to node(%s): ", node.getId(), logger.error(e, "<< problem applying options to node(%s): ", node.getId(), Throwables.getRootCause(e)
Throwables.getRootCause(e).getMessage()); .getMessage());
badNodes.put(node, e); badNodes.put(node, e);
} }
return null; return null;
@ -134,11 +132,9 @@ public class ComputeUtils {
if (nodeRunning.apply(node)) if (nodeRunning.apply(node))
node = installNewCredentials(getNode.execute(node.getId()), node.getCredentials()); node = installNewCredentials(getNode.execute(node.getId()), node.getCredentials());
else else
throw new IllegalStateException( throw new IllegalStateException(String.format(
String "node didn't achieve the state running on node %s within %d seconds, final state: %s", node.getId(),
.format( timeouts.nodeRunning / 1000, node.getState()));
"node didn't achieve the state running on node %s within %d seconds, final state: %s",
node.getId(), timeouts.nodeRunning / 1000, node.getState()));
List<SshCallable<?>> callables = Lists.newArrayList(); List<SshCallable<?>> callables = Lists.newArrayList();
if (options.getRunScript() != null) { if (options.getRunScript() != null) {
@ -151,27 +147,25 @@ public class ComputeUtils {
// changing the key "MUST" come last or else the other commands may // changing the key "MUST" come last or else the other commands may
// fail. // fail.
if (callables.size() > 0 || options.getPrivateKey() != null) { if (callables.size() > 0 || options.getPrivateKey() != null) {
runCallablesOnNode(node, callables, options.getPrivateKey() != null ? installKeyOnNode( runCallablesOnNode(node, callables, options.getPrivateKey() != null ? installKeyOnNode(node, options
node, options.getPrivateKey()) : null); .getPrivateKey()) : null);
} }
if (options.getPort() > 0) { if (options.getPort() > 0) {
checkNodeHasPublicIps(node); checkNodeHasPublicIps(node);
blockUntilPortIsListeningOnPublicIp(options.getPort(), options.getSeconds(), Iterables blockUntilPortIsListeningOnPublicIp(options.getPort(), options.getSeconds(), Iterables.get(node
.get(node.getPublicAddresses(), 0)); .getPublicAddresses(), 0));
} }
return node; return node;
} }
private void checkNodeHasPublicIps(NodeMetadata node) { private void checkNodeHasPublicIps(NodeMetadata node) {
checkState(node.getPublicAddresses().size() > 0, checkState(node.getPublicAddresses().size() > 0, "node does not have IP addresses configured: " + node);
"node does not have IP addresses configured: " + node);
} }
private void blockUntilPortIsListeningOnPublicIp(int port, int seconds, String inetAddress) { private void blockUntilPortIsListeningOnPublicIp(int port, int seconds, String inetAddress) {
logger.debug(">> blocking on port %s:%d for %d seconds", inetAddress, port, seconds); logger.debug(">> blocking on port %s:%d for %d seconds", inetAddress, port, seconds);
RetryablePredicate<IPSocket> tester = new RetryablePredicate<IPSocket>(socketTester, seconds, RetryablePredicate<IPSocket> tester = new RetryablePredicate<IPSocket>(socketTester, seconds, 1, TimeUnit.SECONDS);
1, TimeUnit.SECONDS);
IPSocket socket = new IPSocket(inetAddress, port); IPSocket socket = new IPSocket(inetAddress, port);
boolean passed = tester.apply(socket); boolean passed = tester.apply(socket);
if (passed) if (passed)
@ -180,25 +174,24 @@ public class ComputeUtils {
logger.warn("<< port %s:%d didn't open after %d seconds", inetAddress, port, seconds); 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); return new InstallRSAPrivateKey(node, privateKey);
} }
public AuthorizeRSAPublicKey authorizeKeyOnNode(NodeMetadata node, String publicKey) { public AuthorizeRSAPublicKey authorizeKeyOnNode(NodeMetadata node, Payload publicKey) {
return new AuthorizeRSAPublicKey(node, 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); return new RunScriptOnNode(runScriptNotRunning, node, scriptName, script);
} }
public RunScriptOnNode runScriptOnNodeAsDefaultUser(NodeMetadata node, String scriptName, public RunScriptOnNode runScriptOnNodeAsDefaultUser(NodeMetadata node, String scriptName, Payload script) {
byte[] script) {
return new RunScriptOnNode(runScriptNotRunning, node, scriptName, script, false); return new RunScriptOnNode(runScriptNotRunning, node, scriptName, script, false);
} }
public Map<SshCallable<?>, ?> runCallablesOnNode(NodeMetadata node, public Map<SshCallable<?>, ?> runCallablesOnNode(NodeMetadata node, Iterable<? extends SshCallable<?>> parallel,
Iterable<? extends SshCallable<?>> parallel, @Nullable SshCallable<?> last) { @Nullable SshCallable<?> last) {
checkState(this.sshFactory != null, "runScript requested, but no SshModule configured"); checkState(this.sshFactory != null, "runScript requested, but no SshModule configured");
checkNodeHasPublicIps(node); checkNodeHasPublicIps(node);
checkNotNull(node.getCredentials().credential, "credentials.key for node " + node.getId()); checkNotNull(node.getCredentials().credential, "credentials.key for node " + node.getId());
@ -212,8 +205,8 @@ public class ComputeUtils {
} }
} }
private Map<SshCallable<?>, ?> runTasksUsingSshClient( private Map<SshCallable<?>, ?> runTasksUsingSshClient(Iterable<? extends SshCallable<?>> parallel,
Iterable<? extends SshCallable<?>> parallel, SshCallable<?> last, SshClient ssh) { SshCallable<?> last, SshClient ssh) {
Map<SshCallable<?>, Object> responses = Maps.newHashMap(); Map<SshCallable<?>, Object> responses = Maps.newHashMap();
if (Iterables.size(parallel) > 0) { if (Iterables.size(parallel) > 0) {
responses.putAll(runCallablesUsingSshClient(parallel, ssh)); responses.putAll(runCallablesUsingSshClient(parallel, ssh));
@ -233,26 +226,23 @@ public class ComputeUtils {
IPSocket socket = new IPSocket(Iterables.get(node.getPublicAddresses(), 0), 22); IPSocket socket = new IPSocket(Iterables.get(node.getPublicAddresses(), 0), 22);
socketTester.apply(socket); socketTester.apply(socket);
SshClient ssh = isKeyAuth(node) ? sshFactory.create(socket, node.getCredentials().identity, SshClient ssh = isKeyAuth(node) ? sshFactory.create(socket, node.getCredentials().identity,
node.getCredentials().credential.getBytes()) : sshFactory.create(socket, node node.getCredentials().credential.getBytes()) : sshFactory.create(socket, node.getCredentials().identity,
.getCredentials().identity, node.getCredentials().credential); node.getCredentials().credential);
return ssh; return ssh;
} }
private Map<SshCallable<?>, Object> runCallablesUsingSshClient( private Map<SshCallable<?>, Object> runCallablesUsingSshClient(Iterable<? extends SshCallable<?>> parallel,
Iterable<? extends SshCallable<?>> parallel, SshClient ssh) { SshClient ssh) {
Map<SshCallable<?>, ListenableFuture<?>> parallelResponses = Maps.newHashMap(); Map<SshCallable<?>, ListenableFuture<?>> parallelResponses = Maps.newHashMap();
for (SshCallable<?> callable : parallel) { for (SshCallable<?> callable : parallel) {
callable.setConnection(ssh, logger); callable.setConnection(ssh, logger);
parallelResponses.put(callable, ConcurrentUtils.makeListenable(executor.submit(callable), parallelResponses.put(callable, ConcurrentUtils.makeListenable(executor.submit(callable), executor));
executor));
} }
Map<SshCallable<?>, Exception> exceptions = awaitCompletion(parallelResponses, executor, Map<SshCallable<?>, Exception> exceptions = awaitCompletion(parallelResponses, executor, null, logger, "ssh");
null, logger, "ssh");
if (exceptions.size() > 0) if (exceptions.size() > 0)
throw new RuntimeException(String.format("error invoking callables on nodes: %s", throw new RuntimeException(String.format("error invoking callables on nodes: %s", exceptions));
exceptions));
Map<SshCallable<?>, Object> newresponses = transform(parallelResponses); Map<SshCallable<?>, Object> newresponses = transform(parallelResponses);
return newresponses; return newresponses;
} }

View File

@ -18,12 +18,10 @@
*/ */
package org.jclouds.ssh; package org.jclouds.ssh;
import java.io.InputStream;
import java.util.Map;
import javax.annotation.PostConstruct; import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy; import javax.annotation.PreDestroy;
import org.jclouds.io.Payload;
import org.jclouds.net.IPSocket; 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, String password);
SshClient create(IPSocket socket, String username, byte[] privateKey); SshClient create(IPSocket socket, String username, byte[] privateKey);
Map<String, String> generateRSAKeyPair(String comment, String passphrase);
} }
String getUsername(); String getUsername();
String getHostAddress(); 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); ExecResponse exec(String command);

View File

@ -19,6 +19,21 @@
package org.jclouds.compute; package org.jclouds.compute;
import static com.google.common.base.Preconditions.checkNotNull; 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.assertEquals;
import static org.testng.Assert.assertNotNull; 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.Size;
import org.jclouds.compute.domain.Template; import org.jclouds.compute.domain.Template;
import org.jclouds.compute.domain.TemplateBuilder; import org.jclouds.compute.domain.TemplateBuilder;
import org.jclouds.compute.options.RunScriptOptions;
import org.jclouds.compute.options.TemplateOptions; import org.jclouds.compute.options.TemplateOptions;
import org.jclouds.compute.predicates.NodePredicates;
import org.jclouds.domain.Credentials; import org.jclouds.domain.Credentials;
import org.jclouds.domain.Location; import org.jclouds.domain.Location;
import org.jclouds.domain.LocationScope; import org.jclouds.domain.LocationScope;
@ -65,12 +78,8 @@ import org.testng.annotations.BeforeGroups;
import org.testng.annotations.Test; import org.testng.annotations.Test;
import com.google.common.base.Charsets; 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.ImmutableMap;
import com.google.common.collect.ImmutableSet; 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.common.io.Files;
import com.google.inject.Guice; import com.google.inject.Guice;
import com.google.inject.Injector; import com.google.inject.Injector;
@ -128,7 +137,7 @@ public abstract class BaseComputeServiceLiveTest {
String secret = Files.toString(new File(secretKeyFile), Charsets.UTF_8); String secret = Files.toString(new File(secretKeyFile), Charsets.UTF_8);
assert secret.startsWith("-----BEGIN RSA PRIVATE KEY-----") : "invalid key:\n" + secret; assert secret.startsWith("-----BEGIN RSA PRIVATE KEY-----") : "invalid key:\n" + secret;
return ImmutableMap.<String, String> of("private", secret, "public", Files.toString(new File(secretKeyFile return ImmutableMap.<String, String> of("private", secret, "public", Files.toString(new File(secretKeyFile
+ ".pub"), Charsets.UTF_8)); + ".pub"), Charsets.UTF_8));
} }
protected void setupCredentials() { protected void setupCredentials() {
@ -144,7 +153,7 @@ public abstract class BaseComputeServiceLiveTest {
if (context != null) if (context != null)
context.close(); context.close();
context = new ComputeServiceContextFactory().createContext(provider, identity, credential, ImmutableSet.of( context = new ComputeServiceContextFactory().createContext(provider, identity, credential, ImmutableSet.of(
new Log4JLoggingModule(), getSshModule())); new Log4JLoggingModule(), getSshModule()));
client = context.getComputeService(); client = context.getComputeService();
} }
@ -161,7 +170,7 @@ public abstract class BaseComputeServiceLiveTest {
@Test(enabled = true, expectedExceptions = AuthorizationException.class) @Test(enabled = true, expectedExceptions = AuthorizationException.class)
public void testCorrectAuthException() throws Exception { public void testCorrectAuthException() throws Exception {
new ComputeServiceContextFactory().createContext(provider, "MOMMA", "MIA", new ComputeServiceContextFactory().createContext(provider, "MOMMA", "MIA",
ImmutableSet.<Module> of(new Log4JLoggingModule())).close(); ImmutableSet.<Module> of(new Log4JLoggingModule())).close();
} }
@Test(enabled = true, dependsOnMethods = "testCorrectAuthException") @Test(enabled = true, dependsOnMethods = "testCorrectAuthException")
@ -179,7 +188,7 @@ public abstract class BaseComputeServiceLiveTest {
public void testAScriptExecutionAfterBootWithBasicTemplate() throws Exception { public void testAScriptExecutionAfterBootWithBasicTemplate() throws Exception {
String tag = this.tag + "run"; String tag = this.tag + "run";
try { try {
client.destroyNodesMatching(NodePredicates.withTag(tag)); client.destroyNodesMatching(withTag(tag));
} catch (Exception e) { } catch (Exception e) {
} }
@ -191,13 +200,13 @@ public abstract class BaseComputeServiceLiveTest {
assert good.identity != null; assert good.identity != null;
assert good.credential != null; assert good.credential != null;
Image image = Iterables.get(nodes, 0).getImage(); Image image = get(nodes, 0).getImage();
try { try {
Map<? extends NodeMetadata, ExecResponse> responses = runScriptWithCreds(tag, image.getOsFamily(), Map<? extends NodeMetadata, ExecResponse> 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; assert false : "shouldn't pass with a bad password\n" + responses;
} catch (RunScriptOnNodesException e) { } 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); runScriptWithCreds(tag, image.getOsFamily(), good);
@ -205,7 +214,7 @@ public abstract class BaseComputeServiceLiveTest {
checkNodes(nodes, tag); checkNodes(nodes, tag);
} finally { } finally {
client.destroyNodesMatching(NodePredicates.withTag(tag)); client.destroyNodesMatching(withTag(tag));
} }
} }
@ -219,7 +228,7 @@ public abstract class BaseComputeServiceLiveTest {
@Test(enabled = true, dependsOnMethods = "testTemplateMatch") @Test(enabled = true, dependsOnMethods = "testTemplateMatch")
public void testCreateTwoNodesWithRunScript() throws Exception { public void testCreateTwoNodesWithRunScript() throws Exception {
try { try {
client.destroyNodesMatching(NodePredicates.withTag(tag)); client.destroyNodesMatching(withTag(tag));
} catch (HttpResponseException e) { } catch (HttpResponseException e) {
// TODO hosting.com throws 400 when we try to delete a vApp // TODO hosting.com throws 400 when we try to delete a vApp
} catch (NoSuchElementException e) { } catch (NoSuchElementException e) {
@ -227,12 +236,13 @@ public abstract class BaseComputeServiceLiveTest {
} }
template = buildTemplate(client.templateBuilder()); template = buildTemplate(client.templateBuilder());
template.getOptions().installPrivateKey(keyPair.get("private")).authorizePublicKey(keyPair.get("public")) template.getOptions().installPrivateKey(newStringPayload(keyPair.get("private"))).authorizePublicKey(
.runScript(buildScript(template.getImage().getOsFamily()).getBytes()); newStringPayload(keyPair.get("public"))).runScript(
newStringPayload(buildScript(template.getImage().getOsFamily())));
try { try {
nodes = Sets.newTreeSet(client.runNodesWithTag(tag, 2, template)); nodes = newTreeSet(client.runNodesWithTag(tag, 2, template));
} catch (RunNodesException e) { } catch (RunNodesException e) {
nodes = Sets.newTreeSet(Iterables.concat(e.getSuccessfulNodes(), e.getNodeErrors().keySet())); nodes = newTreeSet(concat(e.getSuccessfulNodes(), e.getNodeErrors().keySet()));
throw e; throw e;
} }
assertEquals(nodes.size(), 2); assertEquals(nodes.size(), 2);
@ -261,7 +271,7 @@ public abstract class BaseComputeServiceLiveTest {
@Test(enabled = true, dependsOnMethods = "testCreateTwoNodesWithRunScript") @Test(enabled = true, dependsOnMethods = "testCreateTwoNodesWithRunScript")
public void testCreateAnotherNodeWithANewContextToEnsureSharedMemIsntRequired() throws Exception { public void testCreateAnotherNodeWithANewContextToEnsureSharedMemIsntRequired() throws Exception {
initializeContextAndClient(); initializeContextAndClient();
TreeSet<NodeMetadata> nodes = Sets.newTreeSet(client.runNodesWithTag(tag, 1, template)); TreeSet<NodeMetadata> nodes = newTreeSet(client.runNodesWithTag(tag, 1, template));
checkNodes(nodes, tag); checkNodes(nodes, tag);
NodeMetadata node = nodes.first(); NodeMetadata node = nodes.first();
this.nodes.add(node); this.nodes.add(node);
@ -271,12 +281,12 @@ public abstract class BaseComputeServiceLiveTest {
} }
protected Map<? extends NodeMetadata, ExecResponse> runScriptWithCreds(final String tag, OsFamily osFamily, protected Map<? extends NodeMetadata, ExecResponse> runScriptWithCreds(final String tag, OsFamily osFamily,
Credentials creds) throws RunScriptOnNodesException { Credentials creds) throws RunScriptOnNodesException {
try { try {
return client.runScriptOnNodesMatching(NodePredicates.runningWithTag(tag), buildScript(osFamily).getBytes(), return client.runScriptOnNodesMatching(runningWithTag(tag), newStringPayload(buildScript(osFamily)),
RunScriptOptions.Builder.overrideCredentialsWith(creds)); overrideCredentialsWith(creds));
} catch (SshException e) { } 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", // System.err.printf("bad credentials: %s:%s for %s%n",
// creds.identity, creds.key, client // creds.identity, creds.key, client
// .listNodesDetailsMatching(tag)); // .listNodesDetailsMatching(tag));
@ -307,40 +317,38 @@ public abstract class BaseComputeServiceLiveTest {
public static String buildScript(OsFamily osFamily) { public static String buildScript(OsFamily osFamily) {
switch (osFamily) { switch (osFamily) {
case UBUNTU: case UBUNTU:
return new StringBuilder()// return new StringBuilder()//
.append("echo nameserver 208.67.222.222 >> /etc/resolv.conf\n")// .append("echo nameserver 208.67.222.222 >> /etc/resolv.conf\n")//
.append("cp /etc/apt/sources.list /etc/apt/sources.list.old\n")// .append("cp /etc/apt/sources.list /etc/apt/sources.list.old\n")//
.append( .append(
"sed 's~us.archive.ubuntu.com~mirror.anl.gov/pub~g' /etc/apt/sources.list.old >/etc/apt/sources.list\n")// "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 update\n")//
.append("apt-get install -f -y --force-yes openjdk-6-jdk\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("wget -qO/usr/bin/runurl run.alestic.com/runurl\n")//
.append("chmod 755 /usr/bin/runurl\n")// .append("chmod 755 /usr/bin/runurl\n")//
.toString(); .toString();
case CENTOS: case CENTOS:
case RHEL: case RHEL:
return new StringBuilder() return new StringBuilder()
.append("echo nameserver 208.67.222.222 >> /etc/resolv.conf\n") .append("echo nameserver 208.67.222.222 >> /etc/resolv.conf\n")
.append("echo \"[jdkrepo]\" >> /etc/yum.repos.d/CentOS-Base.repo\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 \"name=jdkrepository\" >> /etc/yum.repos.d/CentOS-Base.repo\n")
.append( .append(
"echo \"baseurl=http://ec2-us-east-mirror.rightscale.com/epel/5/i386/\" >> /etc/yum.repos.d/CentOS-Base.repo\n") "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("echo \"enabled=1\" >> /etc/yum.repos.d/CentOS-Base.repo\n").append(
.append("yum --nogpgcheck -y install java-1.6.0-openjdk\n") "yum --nogpgcheck -y install java-1.6.0-openjdk\n").append(
.append( "echo \"export PATH=\\\"/usr/lib/jvm/jre-1.6.0-openjdk/bin/:\\$PATH\\\"\" >> /root/.bashrc\n")
"echo \"export PATH=\\\"/usr/lib/jvm/jre-1.6.0-openjdk/bin/:\\$PATH\\\"\" >> /root/.bashrc\n") .toString();
.toString(); default:
default: throw new IllegalArgumentException(osFamily.toString());
throw new IllegalArgumentException(osFamily.toString());
} }
} }
@Test(enabled = true, dependsOnMethods = "testCreateAnotherNodeWithANewContextToEnsureSharedMemIsntRequired") @Test(enabled = true, dependsOnMethods = "testCreateAnotherNodeWithANewContextToEnsureSharedMemIsntRequired")
public void testGet() throws Exception { public void testGet() throws Exception {
Set<? extends NodeMetadata> metadataSet = Sets.newHashSet(Iterables.filter(client Set<? extends NodeMetadata> metadataSet = newHashSet(filter(client.listNodesDetailsMatching(all()), and(
.listNodesDetailsMatching(NodePredicates.all()), Predicates.and(NodePredicates.withTag(tag), Predicates withTag(tag), not(TERMINATED))));
.not(NodePredicates.TERMINATED))));
for (NodeMetadata node : nodes) { for (NodeMetadata node : nodes) {
metadataSet.remove(node); metadataSet.remove(node);
NodeMetadata metadata = client.getNodeMetadata(node.getId()); NodeMetadata metadata = client.getNodeMetadata(node.getId());
@ -357,12 +365,12 @@ public abstract class BaseComputeServiceLiveTest {
protected void assertNodeZero(Set<? extends NodeMetadata> metadataSet) { protected void assertNodeZero(Set<? extends NodeMetadata> metadataSet) {
assert metadataSet.size() == 0 : String.format("nodes left in set: [%s] which didn't match set: [%s]", 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") @Test(enabled = true, dependsOnMethods = "testGet")
public void testReboot() throws Exception { public void testReboot() throws Exception {
client.rebootNodesMatching(NodePredicates.withTag(tag));// TODO test client.rebootNodesMatching(withTag(tag));// TODO test
// validation // validation
testGet(); testGet();
} }
@ -383,7 +391,7 @@ public abstract class BaseComputeServiceLiveTest {
} }
public void testGetNodesWithDetails() throws Exception { 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.getProviderId() != null : node;
assert node.getLocation() != null : node; assert node.getLocation() != null : node;
assertEquals(node.getType(), ComputeType.NODE); assertEquals(node.getType(), ComputeType.NODE);
@ -418,26 +426,26 @@ public abstract class BaseComputeServiceLiveTest {
assert location != location.getParent() : location; assert location != location.getParent() : location;
assert location.getScope() != null : location; assert location.getScope() != null : location;
switch (location.getScope()) { switch (location.getScope()) {
case PROVIDER: case PROVIDER:
assertProvider(location); assertProvider(location);
break; break;
case REGION: case REGION:
assertProvider(location.getParent()); assertProvider(location.getParent());
break; break;
case ZONE: case ZONE:
Location provider = location.getParent().getParent(); Location provider = location.getParent().getParent();
// zone can be a direct descendant of provider // zone can be a direct descendant of provider
if (provider == null) if (provider == null)
provider = location.getParent(); provider = location.getParent();
assertProvider(provider); assertProvider(provider);
break; break;
case HOST: case HOST:
Location provider2 = location.getParent().getParent().getParent(); Location provider2 = location.getParent().getParent().getParent();
// zone can be a direct descendant of provider // zone can be a direct descendant of provider
if (provider2 == null) if (provider2 == null)
provider2 = location.getParent().getParent(); provider2 = location.getParent().getParent();
assertProvider(provider2); assertProvider(provider2);
break; break;
} }
} }
} }
@ -446,7 +454,7 @@ public abstract class BaseComputeServiceLiveTest {
public void testOptionToNotBlock() throws Exception { public void testOptionToNotBlock() throws Exception {
String tag = this.tag + "block"; String tag = this.tag + "block";
try { try {
client.destroyNodesMatching(NodePredicates.withTag(tag)); client.destroyNodesMatching(withTag(tag));
} catch (Exception e) { } catch (Exception e) {
} }
@ -455,12 +463,12 @@ public abstract class BaseComputeServiceLiveTest {
try { try {
long time = System.currentTimeMillis(); long time = System.currentTimeMillis();
Set<? extends NodeMetadata> nodes = client.runNodesWithTag(tag, 1, options); Set<? extends NodeMetadata> nodes = client.runNodesWithTag(tag, 1, options);
NodeMetadata node = Iterables.getOnlyElement(nodes); NodeMetadata node = getOnlyElement(nodes);
assert node.getState() != NodeState.RUNNING; assert node.getState() != NodeState.RUNNING;
long duration = System.currentTimeMillis() - time; long duration = System.currentTimeMillis() - time;
assert duration < 30 * 1000 : "duration longer than 30 seconds!: " + duration / 1000; assert duration < 30 * 1000 : "duration longer than 30 seconds!: " + duration / 1000;
} finally { } 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 { 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 socketTester.apply(socket); // TODO add transitionTo option that accepts
// a socket conection // a socket conection
// state. // state.
@ -515,9 +523,8 @@ public abstract class BaseComputeServiceLiveTest {
@AfterTest @AfterTest
protected void cleanup() throws InterruptedException, ExecutionException, TimeoutException { protected void cleanup() throws InterruptedException, ExecutionException, TimeoutException {
if (nodes != null) { if (nodes != null) {
client.destroyNodesMatching(NodePredicates.withTag(tag)); client.destroyNodesMatching(withTag(tag));
for (NodeMetadata node : Iterables.filter(client.listNodesDetailsMatching(NodePredicates.all()), for (NodeMetadata node : filter(client.listNodesDetailsMatching(all()), withTag(tag))) {
NodePredicates.withTag(tag))) {
assert node.getState() == NodeState.TERMINATED : node; assert node.getState() == NodeState.TERMINATED : node;
} }
} }

View File

@ -29,7 +29,6 @@ import static org.testng.Assert.assertEquals;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream;
import java.io.Serializable; import java.io.Serializable;
import java.util.Set; import java.util.Set;
import java.util.concurrent.ConcurrentMap; 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.OsFamily;
import org.jclouds.compute.domain.Template; import org.jclouds.compute.domain.Template;
import org.jclouds.compute.stub.config.StubComputeServiceContextModule.StubNodeMetadata; import org.jclouds.compute.stub.config.StubComputeServiceContextModule.StubNodeMetadata;
import org.jclouds.io.Payload;
import org.jclouds.net.IPSocket; import org.jclouds.net.IPSocket;
import org.jclouds.predicates.SocketOpen; import org.jclouds.predicates.SocketOpen;
import org.jclouds.rest.RestContext; 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(open.apply(new IPSocket("144.175.1.4", 22))).andReturn(true);
expect( expect(
factory.create(eq(new IPSocket("144.175.1.1", 22)), eq("root"), aryEq(keyPair factory.create(eq(new IPSocket("144.175.1.1", 22)), eq("root"), aryEq(keyPair.get("private")
.get("private").getBytes()))).andReturn(client1).atLeastOnce(); .getBytes()))).andReturn(client1).atLeastOnce();
expect( expect(
factory.create(eq(new IPSocket("144.175.1.2", 22)), eq("root"), aryEq(keyPair factory.create(eq(new IPSocket("144.175.1.2", 22)), eq("root"), aryEq(keyPair.get("private")
.get("private").getBytes()))).andReturn(client2).atLeastOnce(); .getBytes()))).andReturn(client2).atLeastOnce();
expect( expect(
factory.create(eq(new IPSocket("144.175.1.3", 22)), eq("root"), aryEq(keyPair factory.create(eq(new IPSocket("144.175.1.3", 22)), eq("root"), aryEq(keyPair.get("private")
.get("private").getBytes()))).andReturn(client3).atLeastOnce(); .getBytes()))).andReturn(client3).atLeastOnce();
expect( expect(
factory.create(eq(new IPSocket("144.175.1.4", 22)), eq("root"), aryEq(keyPair factory.create(eq(new IPSocket("144.175.1.4", 22)), eq("root"), aryEq(keyPair.get("private")
.get("private").getBytes()))).andReturn(client4).atLeastOnce(); .getBytes()))).andReturn(client4).atLeastOnce();
helloAndJava(client1); helloAndJava(client1);
helloAndJava(client2); helloAndJava(client2);
@ -163,20 +163,20 @@ public class StubComputeServiceIntegrationTest extends BaseComputeServiceLiveTes
SshClient client4 = createMock(SshClient.class); SshClient client4 = createMock(SshClient.class);
expect(factory.create(new IPSocket("144.175.1.1", 22), "root", "romeo")).andThrow( expect(factory.create(new IPSocket("144.175.1.1", 22), "root", "romeo")).andThrow(
new SshException("Auth fail")); new SshException("Auth fail"));
expect(factory.create(new IPSocket("144.175.1.1", 22), "root", "password1")).andReturn( expect(factory.create(new IPSocket("144.175.1.1", 22), "root", "password1")).andReturn(client1)
client1).atLeastOnce(); .atLeastOnce();
client1.connect(); client1.connect();
runScript(client1, "computeserv", 1); runScript(client1, "computeserv", 1);
client1.disconnect(); client1.disconnect();
expect(factory.create(new IPSocket("144.175.1.2", 22), "root", "password2")).andReturn( expect(factory.create(new IPSocket("144.175.1.2", 22), "root", "password2")).andReturn(client2)
client2).atLeastOnce(); .atLeastOnce();
expect(factory.create(new IPSocket("144.175.1.3", 22), "root", "password3")).andReturn( expect(factory.create(new IPSocket("144.175.1.3", 22), "root", "password3")).andReturn(client3)
client3).atLeastOnce(); .atLeastOnce();
expect(factory.create(new IPSocket("144.175.1.4", 22), "root", "password4")).andReturn( expect(factory.create(new IPSocket("144.175.1.4", 22), "root", "password4")).andReturn(client4)
client4).atLeastOnce(); .atLeastOnce();
runScriptAndInstallSsh(client2, "runscript", 2); runScriptAndInstallSsh(client2, "runscript", 2);
runScriptAndInstallSsh(client3, "runscript", 3); runScriptAndInstallSsh(client3, "runscript", 3);
@ -199,10 +199,10 @@ public class StubComputeServiceIntegrationTest extends BaseComputeServiceLiveTes
expect(client.exec("mkdir .ssh")).andReturn(EXEC_GOOD); 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("cat .ssh/id_rsa.pub >> .ssh/authorized_keys")).andReturn(EXEC_GOOD);
expect(client.exec("chmod 600 .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); 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); expect(client.exec("chmod 600 .ssh/id_rsa")).andReturn(EXEC_GOOD);
client.disconnect(); client.disconnect();
@ -211,8 +211,7 @@ public class StubComputeServiceIntegrationTest extends BaseComputeServiceLiveTes
} }
private void runScript(SshClient client, String scriptName, int nodeId) { private void runScript(SshClient client, String scriptName, int nodeId) {
client.put(eq("" + scriptName + ""), isEq(initScript(scriptName, client.put(eq("" + scriptName + ""), payloadEq(initScript(scriptName, buildScript(OsFamily.UBUNTU))));
buildScript(OsFamily.UBUNTU))));
expect(client.exec("chmod 755 " + scriptName + "")).andReturn(EXEC_GOOD); expect(client.exec("chmod 755 " + scriptName + "")).andReturn(EXEC_GOOD);
expect(client.getUsername()).andReturn("root").atLeastOnce(); expect(client.getUsername()).andReturn("root").atLeastOnce();
@ -240,30 +239,30 @@ public class StubComputeServiceIntegrationTest extends BaseComputeServiceLiveTes
} }
public static String initScript(String scriptName, String script) { public static String initScript(String scriptName, String script) {
return new InitBuilder(scriptName, "/tmp/" + scriptName, "/tmp/" + scriptName, ImmutableMap return new InitBuilder(scriptName, "/tmp/" + scriptName, "/tmp/" + scriptName,
.<String, String> of(), Iterables.toArray(Splitter.on("\n").split( ImmutableMap.<String, String> of(), Iterables.toArray(Splitter.on("\n").split(
new String(checkNotNull(script, "script"))), String.class)) new String(checkNotNull(script, "script"))), String.class))
.build(org.jclouds.scriptbuilder.domain.OsFamily.UNIX); .build(org.jclouds.scriptbuilder.domain.OsFamily.UNIX);
} }
public static InputStream isEq(String value) { public static Payload payloadEq(String value) {
reportMatcher(new InputStreamEquals(value)); reportMatcher(new PayloadEquals(value));
return null; return null;
} }
public void testAssignability() throws Exception { public void testAssignability() throws Exception {
@SuppressWarnings("unused") @SuppressWarnings("unused")
RestContext<ConcurrentMap<Integer, StubNodeMetadata>, ConcurrentMap<Integer, StubNodeMetadata>> stubContext = new ComputeServiceContextFactory() RestContext<ConcurrentMap<Integer, StubNodeMetadata>, ConcurrentMap<Integer, StubNodeMetadata>> 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 static final long serialVersionUID = 583055160049982067L;
private final Object expected; private final Object expected;
public InputStreamEquals(Object expected) { public PayloadEquals(Object expected) {
this.expected = expected; this.expected = expected;
} }
@ -272,7 +271,7 @@ public class StubComputeServiceIntegrationTest extends BaseComputeServiceLiveTes
return actual == null; return actual == null;
} }
try { try {
String real = Utils.toStringAndClose((InputStream) actual); String real = Utils.toStringAndClose(((Payload) actual).getInput());
if (!expected.equals(real)) { if (!expected.equals(real)) {
System.err.println(real); System.err.println(real);
return false; return false;
@ -302,9 +301,9 @@ public class StubComputeServiceIntegrationTest extends BaseComputeServiceLiveTes
public boolean equals(Object o) { public boolean equals(Object o) {
if (o == null || !this.getClass().equals(o.getClass())) if (o == null || !this.getClass().equals(o.getClass()))
return false; return false;
InputStreamEquals other = (InputStreamEquals) o; PayloadEquals other = (PayloadEquals) o;
return this.expected == null && other.expected == null || this.expected != null return this.expected == null && other.expected == null || this.expected != null
&& this.expected.equals(other.expected); && this.expected.equals(other.expected);
} }
@Override @Override
@ -316,11 +315,11 @@ public class StubComputeServiceIntegrationTest extends BaseComputeServiceLiveTes
@Override @Override
protected void setupKeyPairForTest() throws FileNotFoundException, IOException { protected void setupKeyPairForTest() throws FileNotFoundException, IOException {
keyPair = ImmutableMap.<String, String> of("public", "ssh-rsa", "private", keyPair = ImmutableMap.<String, String> of("public", "ssh-rsa", "private", "-----BEGIN RSA PRIVATE KEY-----");
"-----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. // get all sorts of not allowed to depend on errors.
@Override @Override
public void testImagesCache() throws Exception { public void testImagesCache() throws Exception {

View File

@ -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.jclouds.compute.options.TemplateOptions.Builder.installPrivateKey;
import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertEquals;
import java.io.IOException;
import org.jclouds.util.Utils;
import org.testng.annotations.Test; import org.testng.annotations.Test;
/** /**
@ -33,150 +36,157 @@ import org.testng.annotations.Test;
* @author Adrian Cole * @author Adrian Cole
*/ */
public class TemplateOptionsTest { public class TemplateOptionsTest {
@SuppressWarnings("deprecation")
@Test(expectedExceptions = IllegalArgumentException.class)
public void testinstallPrivateKeyBadFormat() {
TemplateOptions options = new TemplateOptions();
options.installPrivateKey("whompy");
}
@Test(expectedExceptions = IllegalArgumentException.class) @SuppressWarnings("deprecation")
public void testinstallPrivateKeyBadFormat() { @Test
TemplateOptions options = new TemplateOptions(); public void testinstallPrivateKey() throws IOException {
options.installPrivateKey("whompy"); TemplateOptions options = new TemplateOptions();
} options.installPrivateKey("-----BEGIN RSA PRIVATE KEY-----");
assertEquals(Utils.toStringAndClose(options.getPrivateKey().getInput()), "-----BEGIN RSA PRIVATE KEY-----");
}
@Test @Test
public void testinstallPrivateKey() { public void testNullinstallPrivateKey() {
TemplateOptions options = new TemplateOptions(); TemplateOptions options = new TemplateOptions();
options.installPrivateKey("-----BEGIN RSA PRIVATE KEY-----"); assertEquals(options.getPrivateKey(), null);
assertEquals(options.getPrivateKey(), "-----BEGIN RSA PRIVATE KEY-----"); }
}
@Test @SuppressWarnings("deprecation")
public void testNullinstallPrivateKey() { @Test
TemplateOptions options = new TemplateOptions(); public void testinstallPrivateKeyStatic() throws IOException {
assertEquals(options.getPrivateKey(), null); TemplateOptions options = installPrivateKey("-----BEGIN RSA PRIVATE KEY-----");
} assertEquals(Utils.toStringAndClose(options.getPrivateKey().getInput()), "-----BEGIN RSA PRIVATE KEY-----");
}
@Test @SuppressWarnings("deprecation")
public void testinstallPrivateKeyStatic() { @Test(expectedExceptions = NullPointerException.class)
TemplateOptions options = installPrivateKey("-----BEGIN RSA PRIVATE KEY-----"); public void testinstallPrivateKeyNPE() {
assertEquals(options.getPrivateKey(), "-----BEGIN RSA PRIVATE KEY-----"); installPrivateKey((String) null);
} }
@Test(expectedExceptions = NullPointerException.class) @SuppressWarnings("deprecation")
public void testinstallPrivateKeyNPE() { @Test(expectedExceptions = IllegalArgumentException.class)
installPrivateKey(null); public void testauthorizePublicKeyBadFormat() {
} TemplateOptions options = new TemplateOptions();
options.authorizePublicKey("whompy");
}
@Test(expectedExceptions = IllegalArgumentException.class) @Test
public void testauthorizePublicKeyBadFormat() { @SuppressWarnings("deprecation")
TemplateOptions options = new TemplateOptions(); public void testauthorizePublicKey() throws IOException {
options.authorizePublicKey("whompy"); TemplateOptions options = new TemplateOptions();
} options.authorizePublicKey("ssh-rsa");
assertEquals(Utils.toStringAndClose(options.getPublicKey().getInput()), "ssh-rsa");
}
@Test @Test
public void testauthorizePublicKey() { public void testNullauthorizePublicKey() {
TemplateOptions options = new TemplateOptions(); TemplateOptions options = new TemplateOptions();
options.authorizePublicKey("ssh-rsa"); assertEquals(options.getPublicKey(), null);
assertEquals(options.getPublicKey(), "ssh-rsa"); }
}
@Test @SuppressWarnings("deprecation")
public void testNullauthorizePublicKey() { @Test
TemplateOptions options = new TemplateOptions(); public void testauthorizePublicKeyStatic() throws IOException {
assertEquals(options.getPublicKey(), null); TemplateOptions options = authorizePublicKey("ssh-rsa");
} assertEquals(Utils.toStringAndClose(options.getPublicKey().getInput()), "ssh-rsa");
}
@Test @SuppressWarnings("deprecation")
public void testauthorizePublicKeyStatic() { @Test(expectedExceptions = NullPointerException.class)
TemplateOptions options = authorizePublicKey("ssh-rsa"); public void testauthorizePublicKeyNPE() {
assertEquals(options.getPublicKey(), "ssh-rsa"); authorizePublicKey((String) null);
} }
@Test(expectedExceptions = NullPointerException.class) @Test(expectedExceptions = IllegalArgumentException.class)
public void testauthorizePublicKeyNPE() { public void testblockOnPortBadFormat() {
authorizePublicKey(null); TemplateOptions options = new TemplateOptions();
} options.blockOnPort(-1, -1);
}
@Test(expectedExceptions = IllegalArgumentException.class) @Test
public void testblockOnPortBadFormat() { public void testblockOnPort() {
TemplateOptions options = new TemplateOptions(); TemplateOptions options = new TemplateOptions();
options.blockOnPort(-1, -1); 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 @Test
public void testNullblockOnPort() { public void testblockOnPortStatic() {
TemplateOptions options = new TemplateOptions(); TemplateOptions options = blockOnPort(22, 30);
assertEquals(options.getPort(), -1); assertEquals(options.getPort(), 22);
assertEquals(options.getSeconds(), -1); assertEquals(options.getSeconds(), 30);
} }
@Test @Test(expectedExceptions = IllegalArgumentException.class)
public void testblockOnPortStatic() { public void testinboundPortsBadFormat() {
TemplateOptions options = blockOnPort(22, 30); TemplateOptions options = new TemplateOptions();
assertEquals(options.getPort(), 22); options.inboundPorts(-1, -1);
assertEquals(options.getSeconds(), 30); }
}
@Test(expectedExceptions = IllegalArgumentException.class) @Test
public void testinboundPortsBadFormat() { public void testinboundPorts() {
TemplateOptions options = new TemplateOptions(); TemplateOptions options = new TemplateOptions();
options.inboundPorts(-1, -1); 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 @Test
public void testDefaultOpen22() { public void testinboundPortsStatic() {
TemplateOptions options = new TemplateOptions(); TemplateOptions options = inboundPorts(22, 30);
assertEquals(options.getInboundPorts()[0], 22); assertEquals(options.getInboundPorts()[0], 22);
} assertEquals(options.getInboundPorts()[1], 30);
}
@Test @Test
public void testinboundPortsStatic() { public void testblockUntilRunningDefault() {
TemplateOptions options = inboundPorts(22, 30); TemplateOptions options = new TemplateOptions();
assertEquals(options.getInboundPorts()[0], 22); assertEquals(options.shouldBlockUntilRunning(), true);
assertEquals(options.getInboundPorts()[1], 30); }
}
@Test @Test
public void testblockUntilRunningDefault() { public void testblockUntilRunning() {
TemplateOptions options = new TemplateOptions(); TemplateOptions options = new TemplateOptions();
assertEquals(options.shouldBlockUntilRunning(), true); options.blockUntilRunning(false);
} assertEquals(options.shouldBlockUntilRunning(), false);
}
@Test @Test
public void testblockUntilRunning() { public void testBlockUntilRunningUnsetsBlockOnPort() {
TemplateOptions options = new TemplateOptions(); TemplateOptions options = new TemplateOptions();
options.blockUntilRunning(false); options.blockOnPort(22, 30);
assertEquals(options.shouldBlockUntilRunning(), false); options.blockUntilRunning(false);
} assertEquals(options.shouldBlockUntilRunning(), false);
assertEquals(options.getPort(), -1);
assertEquals(options.getSeconds(), -1);
}
@Test @Test
public void testBlockUntilRunningUnsetsBlockOnPort() { public void testblockUntilRunningStatic() {
TemplateOptions options = new TemplateOptions(); TemplateOptions options = blockUntilRunning(false);
options.blockOnPort(22, 30); assertEquals(options.shouldBlockUntilRunning(), false);
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);
}
} }

View File

@ -25,9 +25,9 @@ import java.io.OutputStream;
import java.security.Key; import java.security.Key;
import org.jclouds.encryption.internal.JCEEncryptionService; import org.jclouds.encryption.internal.JCEEncryptionService;
import org.jclouds.http.Payload;
import org.jclouds.http.PayloadEnclosing; 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; import com.google.inject.ImplementedBy;

View File

@ -26,8 +26,8 @@ import java.io.UnsupportedEncodingException;
import javax.annotation.Resource; import javax.annotation.Resource;
import org.jclouds.encryption.EncryptionService; import org.jclouds.encryption.EncryptionService;
import org.jclouds.http.Payload;
import org.jclouds.http.PayloadEnclosing; import org.jclouds.http.PayloadEnclosing;
import org.jclouds.io.Payload;
import org.jclouds.logging.Logger; import org.jclouds.logging.Logger;
/** /**

View File

@ -35,7 +35,7 @@ import javax.crypto.Cipher;
import javax.crypto.Mac; import javax.crypto.Mac;
import javax.crypto.spec.SecretKeySpec; import javax.crypto.spec.SecretKeySpec;
import org.jclouds.http.payloads.ByteArrayPayload; import org.jclouds.io.payloads.ByteArrayPayload;
/** /**
* *

View File

@ -23,6 +23,7 @@ import java.util.Collection;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import org.jclouds.http.internal.PayloadEnclosingImpl; import org.jclouds.http.internal.PayloadEnclosingImpl;
import org.jclouds.io.Payload;
import com.google.common.collect.LinkedHashMultimap; import com.google.common.collect.LinkedHashMultimap;
import com.google.common.collect.Multimap; import com.google.common.collect.Multimap;

View File

@ -28,6 +28,8 @@ import java.util.List;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import org.jclouds.io.Payload;
import com.google.common.collect.Multimap; import com.google.common.collect.Multimap;
/** /**

View File

@ -20,6 +20,8 @@ package org.jclouds.http;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import org.jclouds.io.Payload;
/** /**
* Represents a response produced from {@link HttpCommandExecutorService} * Represents a response produced from {@link HttpCommandExecutorService}
* *

View File

@ -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_LENGTH;
import static javax.ws.rs.core.HttpHeaders.CONTENT_TYPE; import static javax.ws.rs.core.HttpHeaders.CONTENT_TYPE;
import static javax.ws.rs.core.HttpHeaders.HOST; 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.CHAR_TO_ENCODED_PATTERN;
import static org.jclouds.util.Patterns.PATTERN_THAT_BREAKS_URI; import static org.jclouds.util.Patterns.PATTERN_THAT_BREAKS_URI;
import static org.jclouds.util.Patterns.PLUS_PATTERN; 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.Constants;
import org.jclouds.encryption.EncryptionService; import org.jclouds.encryption.EncryptionService;
import org.jclouds.io.Payload;
import org.jclouds.io.Payloads;
import org.jclouds.logging.Logger; import org.jclouds.logging.Logger;
import com.google.common.base.Joiner; import com.google.common.base.Joiner;

View File

@ -21,6 +21,8 @@ package org.jclouds.http;
import java.io.File; import java.io.File;
import java.io.InputStream; import java.io.InputStream;
import org.jclouds.io.Payload;
/** /**
* *
* @author Adrian Cole * @author Adrian Cole

View File

@ -53,10 +53,10 @@ import org.jclouds.http.HttpRequest;
import org.jclouds.http.HttpResponse; import org.jclouds.http.HttpResponse;
import org.jclouds.http.HttpUtils; import org.jclouds.http.HttpUtils;
import org.jclouds.http.IOExceptionRetryHandler; 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.DelegatingErrorHandler;
import org.jclouds.http.handlers.DelegatingRetryHandler; import org.jclouds.http.handlers.DelegatingRetryHandler;
import org.jclouds.io.Payload;
import org.jclouds.io.Payloads;
import org.jclouds.logging.Logger; import org.jclouds.logging.Logger;
import com.google.common.collect.LinkedHashMultimap; import com.google.common.collect.LinkedHashMultimap;

View File

@ -19,15 +19,15 @@
package org.jclouds.http.internal; package org.jclouds.http.internal;
import static com.google.common.base.Preconditions.checkNotNull; 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.File;
import java.io.InputStream; import java.io.InputStream;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import org.jclouds.http.Payload;
import org.jclouds.http.PayloadEnclosing; import org.jclouds.http.PayloadEnclosing;
import org.jclouds.io.Payload;
/** /**
* *

View File

@ -16,7 +16,7 @@
* limitations under the License. * limitations under the License.
* ==================================================================== * ====================================================================
*/ */
package org.jclouds.http; package org.jclouds.io;
import java.io.Closeable; import java.io.Closeable;
import java.io.IOException; import java.io.IOException;

View File

@ -16,7 +16,7 @@
* limitations under the License. * limitations under the License.
* ==================================================================== * ====================================================================
*/ */
package org.jclouds.http; package org.jclouds.io;
import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Preconditions.checkNotNull;
@ -27,11 +27,11 @@ import java.util.Map;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import org.jclouds.http.payloads.ByteArrayPayload; import org.jclouds.io.payloads.ByteArrayPayload;
import org.jclouds.http.payloads.FilePayload; import org.jclouds.io.payloads.FilePayload;
import org.jclouds.http.payloads.InputStreamPayload; import org.jclouds.io.payloads.InputStreamPayload;
import org.jclouds.http.payloads.StringPayload; import org.jclouds.io.payloads.StringPayload;
import org.jclouds.http.payloads.UrlEncodedFormPayload; import org.jclouds.io.payloads.UrlEncodedFormPayload;
import com.google.common.collect.Multimap; import com.google.common.collect.Multimap;

View File

@ -16,7 +16,7 @@
* limitations under the License. * 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.checkNotNull;
import static com.google.common.base.Preconditions.checkState; import static com.google.common.base.Preconditions.checkState;
@ -29,7 +29,7 @@ import java.io.OutputStream;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import org.jclouds.http.Payload; import org.jclouds.io.Payload;
/** /**
* @author Adrian Cole * @author Adrian Cole

View File

@ -16,7 +16,7 @@
* limitations under the License. * 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.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Preconditions.checkNotNull;

View File

@ -16,7 +16,7 @@
* limitations under the License. * 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.checkNotNull;
@ -24,7 +24,7 @@ import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.OutputStream; import java.io.OutputStream;
import org.jclouds.http.Payload; import org.jclouds.io.Payload;
/** /**
* *

View File

@ -16,7 +16,7 @@
* limitations under the License. * 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.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Preconditions.checkNotNull;

View File

@ -16,7 +16,7 @@
* limitations under the License. * limitations under the License.
* ==================================================================== * ====================================================================
*/ */
package org.jclouds.http.payloads; package org.jclouds.io.payloads;
import static com.google.common.io.Closeables.closeQuietly; import static com.google.common.io.Closeables.closeQuietly;

View File

@ -16,7 +16,7 @@
* limitations under the License. * 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.base.Throwables.propagate;
import static com.google.common.collect.Lists.newArrayList; import static com.google.common.collect.Lists.newArrayList;

View File

@ -16,7 +16,7 @@
* limitations under the License. * 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.checkNotNull;
import static com.google.common.collect.Multimaps.forMap; import static com.google.common.collect.Multimaps.forMap;
@ -26,8 +26,8 @@ import java.util.LinkedHashMap;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import javax.ws.rs.core.HttpHeaders; import javax.ws.rs.core.HttpHeaders;
import org.jclouds.http.Payload; import org.jclouds.io.Payload;
import org.jclouds.http.Payloads; import org.jclouds.io.Payloads;
import com.google.common.collect.ImmutableMultimap; import com.google.common.collect.ImmutableMultimap;
import com.google.common.collect.Multimap; import com.google.common.collect.Multimap;

View File

@ -16,7 +16,7 @@
* limitations under the License. * limitations under the License.
* ==================================================================== * ====================================================================
*/ */
package org.jclouds.http.payloads; package org.jclouds.io.payloads;
import java.io.InputStream; import java.io.InputStream;

View File

@ -16,7 +16,7 @@
* limitations under the License. * limitations under the License.
* ==================================================================== * ====================================================================
*/ */
package org.jclouds.http.payloads; package org.jclouds.io.payloads;
import static org.jclouds.http.HttpUtils.makeQueryLine; import static org.jclouds.http.HttpUtils.makeQueryLine;

View File

@ -29,9 +29,9 @@ import java.io.InputStream;
import javax.annotation.Resource; import javax.annotation.Resource;
import org.jclouds.http.Payload;
import org.jclouds.http.PayloadEnclosing; 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 org.jclouds.logging.Logger;
import com.google.common.io.ByteStreams; import com.google.common.io.ByteStreams;

View File

@ -9,9 +9,9 @@ import javax.ws.rs.HEAD;
import javax.ws.rs.POST; import javax.ws.rs.POST;
import javax.ws.rs.PUT; import javax.ws.rs.PUT;
import org.jclouds.http.Payload;
import org.jclouds.http.functions.ParseETagHeader; import org.jclouds.http.functions.ParseETagHeader;
import org.jclouds.http.options.HttpRequestOptions; import org.jclouds.http.options.HttpRequestOptions;
import org.jclouds.io.Payload;
import org.jclouds.rest.annotations.EndpointParam; import org.jclouds.rest.annotations.EndpointParam;
import org.jclouds.rest.annotations.ExceptionParser; import org.jclouds.rest.annotations.ExceptionParser;
import org.jclouds.rest.annotations.ResponseParser; import org.jclouds.rest.annotations.ResponseParser;

View File

@ -23,8 +23,8 @@ import java.net.URI;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import org.jclouds.concurrent.Timeout; import org.jclouds.concurrent.Timeout;
import org.jclouds.http.Payload;
import org.jclouds.http.options.HttpRequestOptions; import org.jclouds.http.options.HttpRequestOptions;
import org.jclouds.io.Payload;
/** /**
* Simple client * Simple client

View File

@ -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.makeQueryLine;
import static org.jclouds.http.HttpUtils.parseQueryToMap; import static org.jclouds.http.HttpUtils.parseQueryToMap;
import static org.jclouds.http.HttpUtils.urlEncode; 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 static org.jclouds.util.Utils.replaceTokens;
import java.io.InputStream; import java.io.InputStream;
@ -75,9 +75,7 @@ import org.jclouds.http.HttpRequest;
import org.jclouds.http.HttpRequestFilter; import org.jclouds.http.HttpRequestFilter;
import org.jclouds.http.HttpResponse; import org.jclouds.http.HttpResponse;
import org.jclouds.http.HttpUtils; import org.jclouds.http.HttpUtils;
import org.jclouds.http.Payload;
import org.jclouds.http.PayloadEnclosing; import org.jclouds.http.PayloadEnclosing;
import org.jclouds.http.Payloads;
import org.jclouds.http.functions.ParseJson; import org.jclouds.http.functions.ParseJson;
import org.jclouds.http.functions.ParseSax; import org.jclouds.http.functions.ParseSax;
import org.jclouds.http.functions.ParseURIFromListOrLocationHeaderIf20x; 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.UnwrapOnlyJsonValue;
import org.jclouds.http.functions.ParseSax.HandlerWithResult; import org.jclouds.http.functions.ParseSax.HandlerWithResult;
import org.jclouds.http.options.HttpRequestOptions; 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.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.logging.Logger;
import org.jclouds.rest.Binder; import org.jclouds.rest.Binder;
import org.jclouds.rest.InputParamValidator; import org.jclouds.rest.InputParamValidator;

View File

@ -28,6 +28,7 @@ import java.net.URI;
import org.easymock.IArgumentMatcher; import org.easymock.IArgumentMatcher;
import org.jclouds.http.functions.config.ParserModule; import org.jclouds.http.functions.config.ParserModule;
import org.jclouds.io.Payloads;
import com.google.inject.Guice; import com.google.inject.Guice;

View File

@ -34,7 +34,7 @@ import javax.ws.rs.core.UriBuilder;
import org.jboss.resteasy.specimpl.UriBuilderImpl; import org.jboss.resteasy.specimpl.UriBuilderImpl;
import org.jclouds.http.HttpResponse; import org.jclouds.http.HttpResponse;
import org.jclouds.http.Payload; import org.jclouds.io.Payload;
import org.jclouds.rest.internal.GeneratedHttpRequest; import org.jclouds.rest.internal.GeneratedHttpRequest;
import org.jclouds.util.Utils; import org.jclouds.util.Utils;
import org.mortbay.jetty.HttpHeaders; import org.mortbay.jetty.HttpHeaders;

View File

@ -29,7 +29,7 @@ import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeoutException; import java.util.concurrent.TimeoutException;
import org.jclouds.http.HttpResponse; import org.jclouds.http.HttpResponse;
import org.jclouds.http.Payload; import org.jclouds.io.Payload;
import org.jclouds.util.Utils; import org.jclouds.util.Utils;
import org.testng.annotations.Test; import org.testng.annotations.Test;

View File

@ -39,12 +39,12 @@ import org.jclouds.http.HttpCommand;
import org.jclouds.http.HttpResponse; import org.jclouds.http.HttpResponse;
import org.jclouds.http.HttpUtils; import org.jclouds.http.HttpUtils;
import org.jclouds.http.IntegrationTestAsyncClient; import org.jclouds.http.IntegrationTestAsyncClient;
import org.jclouds.http.Payloads;
import org.jclouds.http.TransformingHttpCommandExecutorServiceImpl; import org.jclouds.http.TransformingHttpCommandExecutorServiceImpl;
import org.jclouds.http.TransformingHttpCommandImpl; import org.jclouds.http.TransformingHttpCommandImpl;
import org.jclouds.http.functions.ReturnStringIf2xx; import org.jclouds.http.functions.ReturnStringIf2xx;
import org.jclouds.http.internal.HttpWire; import org.jclouds.http.internal.HttpWire;
import org.jclouds.http.internal.JavaUrlHttpCommandExecutorService; import org.jclouds.http.internal.JavaUrlHttpCommandExecutorService;
import org.jclouds.io.Payloads;
import org.jclouds.rest.internal.RestAnnotationProcessor; import org.jclouds.rest.internal.RestAnnotationProcessor;
import org.testng.annotations.BeforeTest; import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test; import org.testng.annotations.Test;

View File

@ -16,7 +16,7 @@
* limitations under the License. * limitations under the License.
* ==================================================================== * ====================================================================
*/ */
package org.jclouds.http; package org.jclouds.io.payloads;
import static org.easymock.EasyMock.expect; import static org.easymock.EasyMock.expect;
import static org.easymock.classextension.EasyMock.createMock; import static org.easymock.classextension.EasyMock.createMock;
@ -30,11 +30,12 @@ import java.io.OutputStream;
import javax.ws.rs.core.MediaType; import javax.ws.rs.core.MediaType;
import org.jclouds.http.payloads.FilePayload; import org.jclouds.io.Payloads;
import org.jclouds.http.payloads.MultipartForm; import org.jclouds.io.payloads.FilePayload;
import org.jclouds.http.payloads.Part; import org.jclouds.io.payloads.MultipartForm;
import org.jclouds.http.payloads.StringPayload; import org.jclouds.io.payloads.Part;
import org.jclouds.http.payloads.Part.PartOptions; import org.jclouds.io.payloads.StringPayload;
import org.jclouds.io.payloads.Part.PartOptions;
import org.jclouds.util.Utils; import org.jclouds.util.Utils;
import org.testng.annotations.Test; import org.testng.annotations.Test;

View File

@ -26,8 +26,8 @@ import static org.easymock.EasyMock.expect;
import static org.easymock.EasyMock.reportMatcher; import static org.easymock.EasyMock.reportMatcher;
import static org.easymock.classextension.EasyMock.replay; import static org.easymock.classextension.EasyMock.replay;
import static org.easymock.classextension.EasyMock.verify; import static org.easymock.classextension.EasyMock.verify;
import static org.jclouds.http.Payloads.newInputStreamPayload; import static org.jclouds.io.Payloads.newInputStreamPayload;
import static org.jclouds.http.Payloads.newStringPayload; import static org.jclouds.io.Payloads.newStringPayload;
import static org.jclouds.rest.RestContextFactory.contextSpec; import static org.jclouds.rest.RestContextFactory.contextSpec;
import static org.jclouds.rest.RestContextFactory.createContextBuilder; import static org.jclouds.rest.RestContextFactory.createContextBuilder;
import static org.jclouds.util.Utils.toInputStream; 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.HttpRequestFilter;
import org.jclouds.http.HttpResponse; import org.jclouds.http.HttpResponse;
import org.jclouds.http.IOExceptionRetryHandler; import org.jclouds.http.IOExceptionRetryHandler;
import org.jclouds.http.Payload;
import org.jclouds.http.PayloadEnclosing; import org.jclouds.http.PayloadEnclosing;
import org.jclouds.http.Payloads;
import org.jclouds.http.RequiresHttp; import org.jclouds.http.RequiresHttp;
import org.jclouds.http.TransformingHttpCommandExecutorService; import org.jclouds.http.TransformingHttpCommandExecutorService;
import org.jclouds.http.functions.ParseJson; 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.BaseHttpRequestOptions;
import org.jclouds.http.options.GetOptions; import org.jclouds.http.options.GetOptions;
import org.jclouds.http.options.HttpRequestOptions; 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.logging.config.NullLoggingModule;
import org.jclouds.rest.AsyncClientFactory; import org.jclouds.rest.AsyncClientFactory;
import org.jclouds.rest.BaseRestClientTest; import org.jclouds.rest.BaseRestClientTest;

View File

@ -36,12 +36,12 @@ import org.jclouds.http.HttpRequest;
import org.jclouds.http.HttpResponse; import org.jclouds.http.HttpResponse;
import org.jclouds.http.HttpUtils; import org.jclouds.http.HttpUtils;
import org.jclouds.http.IOExceptionRetryHandler; 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.DelegatingErrorHandler;
import org.jclouds.http.handlers.DelegatingRetryHandler; import org.jclouds.http.handlers.DelegatingRetryHandler;
import org.jclouds.http.internal.BaseHttpCommandExecutorService; import org.jclouds.http.internal.BaseHttpCommandExecutorService;
import org.jclouds.http.internal.HttpWire; 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.LinkedHashMultimap;
import com.google.common.collect.Multimap; import com.google.common.collect.Multimap;

View File

@ -41,12 +41,12 @@ import org.apache.http.entity.FileEntity;
import org.apache.http.entity.InputStreamEntity; import org.apache.http.entity.InputStreamEntity;
import org.apache.http.entity.StringEntity; import org.apache.http.entity.StringEntity;
import org.jclouds.http.HttpRequest; import org.jclouds.http.HttpRequest;
import org.jclouds.http.Payload; import org.jclouds.io.Payload;
import org.jclouds.http.payloads.BasePayload; import org.jclouds.io.payloads.BasePayload;
import org.jclouds.http.payloads.ByteArrayPayload; import org.jclouds.io.payloads.ByteArrayPayload;
import org.jclouds.http.payloads.DelegatingPayload; import org.jclouds.io.payloads.DelegatingPayload;
import org.jclouds.http.payloads.FilePayload; import org.jclouds.io.payloads.FilePayload;
import org.jclouds.http.payloads.StringPayload; import org.jclouds.io.payloads.StringPayload;
import com.google.common.base.Throwables; import com.google.common.base.Throwables;

View File

@ -40,7 +40,7 @@ import org.bouncycastle.crypto.macs.HMac;
import org.bouncycastle.crypto.params.KeyParameter; import org.bouncycastle.crypto.params.KeyParameter;
import org.bouncycastle.util.encoders.Base64; import org.bouncycastle.util.encoders.Base64;
import org.jclouds.encryption.internal.BaseEncryptionService; import org.jclouds.encryption.internal.BaseEncryptionService;
import org.jclouds.http.payloads.ByteArrayPayload; import org.jclouds.io.payloads.ByteArrayPayload;
/** /**
* *

View File

@ -23,8 +23,8 @@ import javax.inject.Singleton;
import org.jclouds.http.HttpResponse; import org.jclouds.http.HttpResponse;
import org.jclouds.http.HttpUtils; import org.jclouds.http.HttpUtils;
import org.jclouds.http.Payload; import org.jclouds.io.Payload;
import org.jclouds.http.Payloads; import org.jclouds.io.Payloads;
import com.google.appengine.api.urlfetch.HTTPHeader; import com.google.appengine.api.urlfetch.HTTPHeader;
import com.google.appengine.api.urlfetch.HTTPResponse; import com.google.appengine.api.urlfetch.HTTPResponse;

View File

@ -31,7 +31,7 @@ import javax.ws.rs.core.HttpHeaders;
import org.jclouds.encryption.internal.JCEEncryptionService; import org.jclouds.encryption.internal.JCEEncryptionService;
import org.jclouds.http.HttpRequest; import org.jclouds.http.HttpRequest;
import org.jclouds.http.Payloads; import org.jclouds.io.Payloads;
import org.jclouds.util.Utils; import org.jclouds.util.Utils;
import org.testng.annotations.BeforeTest; import org.testng.annotations.BeforeTest;
import org.testng.annotations.Parameters; import org.testng.annotations.Parameters;

View File

@ -40,6 +40,8 @@ import javax.inject.Named;
import org.apache.commons.io.input.ProxyInputStream; import org.apache.commons.io.input.ProxyInputStream;
import org.apache.commons.io.output.ByteArrayOutputStream; import org.apache.commons.io.output.ByteArrayOutputStream;
import org.jclouds.http.handlers.BackoffLimitedRetryHandler; import org.jclouds.http.handlers.BackoffLimitedRetryHandler;
import org.jclouds.io.Payload;
import org.jclouds.io.Payloads;
import org.jclouds.logging.Logger; import org.jclouds.logging.Logger;
import org.jclouds.net.IPSocket; import org.jclouds.net.IPSocket;
import org.jclouds.ssh.ExecResponse; import org.jclouds.ssh.ExecResponse;
@ -101,8 +103,7 @@ public class JschSshClient implements SshClient {
@Inject(optional = true) @Inject(optional = true)
@Named("jclouds.ssh.retry_predicate") @Named("jclouds.ssh.retry_predicate")
private Predicate<Throwable> retryPredicate = or(instanceOf(ConnectException.class), private Predicate<Throwable> retryPredicate = or(instanceOf(ConnectException.class), instanceOf(IOException.class));
instanceOf(IOException.class));
@Resource @Resource
protected Logger logger = Logger.NULL; protected Logger logger = Logger.NULL;
private Session session; private Session session;
@ -111,21 +112,20 @@ public class JschSshClient implements SshClient {
private final int timeout; private final int timeout;
private final BackoffLimitedRetryHandler backoffLimitedRetryHandler; private final BackoffLimitedRetryHandler backoffLimitedRetryHandler;
public JschSshClient(BackoffLimitedRetryHandler backoffLimitedRetryHandler, IPSocket socket, public JschSshClient(BackoffLimitedRetryHandler backoffLimitedRetryHandler, IPSocket socket, int timeout,
int timeout, String username, String password, byte[] privateKey) { String username, String password, byte[] privateKey) {
this.host = checkNotNull(socket, "socket").getAddress(); this.host = checkNotNull(socket, "socket").getAddress();
checkArgument(socket.getPort() > 0, "ssh port must be greater then zero" + socket.getPort()); 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"); checkArgument(password != null || privateKey != null, "you must specify a password or a key");
this.port = socket.getPort(); this.port = socket.getPort();
this.username = checkNotNull(username, "username"); this.username = checkNotNull(username, "username");
this.backoffLimitedRetryHandler = checkNotNull(backoffLimitedRetryHandler, this.backoffLimitedRetryHandler = checkNotNull(backoffLimitedRetryHandler, "backoffLimitedRetryHandler");
"backoffLimitedRetryHandler");
this.timeout = timeout; this.timeout = timeout;
this.password = password; this.password = password;
this.privateKey = privateKey; this.privateKey = privateKey;
} }
public InputStream get(String path) { public Payload get(String path) {
checkNotNull(path, "path"); checkNotNull(path, "path");
checkConnected(); checkConnected();
@ -135,18 +135,16 @@ public class JschSshClient implements SshClient {
sftp = (ChannelSftp) session.openChannel("sftp"); sftp = (ChannelSftp) session.openChannel("sftp");
sftp.connect(); sftp.connect();
} catch (JSchException e) { } catch (JSchException e) {
throw new SshException(String.format("%s@%s:%d: Error connecting to sftp.", username, throw new SshException(String.format("%s@%s:%d: Error connecting to sftp.", username, host, port), e);
host, port), e);
} }
try { try {
return new CloseFtpChannelOnCloseInputStream(sftp.get(path), sftp); return Payloads.newInputStreamPayload(new CloseFtpChannelOnCloseInputStream(sftp.get(path), sftp));
} catch (SftpException e) { } catch (SftpException e) {
throw new SshException(String.format("%s@%s:%d: Error getting path: %s", username, host, throw new SshException(String.format("%s@%s:%d: Error getting path: %s", username, host, port, path), e);
port, path), e);
} }
} }
public void put(String path, InputStream contents) { public void put(String path, Payload contents) {
checkNotNull(path, "path"); checkNotNull(path, "path");
checkNotNull(contents, "contents"); checkNotNull(contents, "contents");
@ -157,22 +155,20 @@ public class JschSshClient implements SshClient {
sftp = (ChannelSftp) session.openChannel("sftp"); sftp = (ChannelSftp) session.openChannel("sftp");
sftp.connect(); sftp.connect();
} catch (JSchException e) { } catch (JSchException e) {
throw new SshException(String.format("%s@%s:%d: Error connecting to sftp.", username, throw new SshException(String.format("%s@%s:%d: Error connecting to sftp.", username, host, port), e);
host, port), e);
} }
try { try {
sftp.put(contents, path); sftp.put(contents.getInput(), path);
} catch (SftpException e) { } catch (SftpException e) {
throw new SshException(String.format("%s@%s:%d: Error putting path: %s", username, host, throw new SshException(String.format("%s@%s:%d: Error putting path: %s", username, host, port, path), e);
port, path), e);
} finally { } finally {
Closeables.closeQuietly(contents); Closeables.closeQuietly(contents);
} }
} }
private void checkConnected() { private void checkConnected() {
checkState(session != null && session.isConnected(), String.format( checkState(session != null && session.isConnected(), String.format("%s@%s:%d: SFTP not connected!", username,
"%s@%s:%d: SFTP not connected!", username, host, port)); host, port));
} }
@PostConstruct @PostConstruct
@ -207,19 +203,19 @@ public class JschSshClient implements SshClient {
boolean shouldRetry(Exception from) { boolean shouldRetry(Exception from) {
final String rootMessage = getRootCause(from).getMessage(); final String rootMessage = getRootCause(from).getMessage();
return any(getCausalChain(from), retryPredicate) return any(getCausalChain(from), retryPredicate)
|| Iterables.any(Splitter.on(",").split(retryableMessages), new Predicate<String>() { || Iterables.any(Splitter.on(",").split(retryableMessages), new Predicate<String>() {
@Override @Override
public boolean apply(String input) { public boolean apply(String input) {
return rootMessage.indexOf(input) != -1; return rootMessage.indexOf(input) != -1;
} }
}); });
} }
private void backoffForAttempt(int retryAttempt, String rootMessage) { private void backoffForAttempt(int retryAttempt, String rootMessage) {
backoffLimitedRetryHandler.imposeBackoffExponentialDelay(200L, 2, retryAttempt, sshRetries, backoffLimitedRetryHandler.imposeBackoffExponentialDelay(200L, 2, retryAttempt, sshRetries, String.format(
String.format("%s@%s:%d: connection error: %s", username, host, port, rootMessage)); "%s@%s:%d: connection error: %s", username, host, port, rootMessage));
} }
private void newSession() throws JSchException { private void newSession() throws JSchException {
@ -234,12 +230,10 @@ public class JschSshClient implements SshClient {
session.setPassword(password); session.setPassword(password);
} else { } else {
// jsch wipes out your private key // jsch wipes out your private key
jsch.addIdentity(username, Arrays.copyOf(privateKey, privateKey.length), null, jsch.addIdentity(username, Arrays.copyOf(privateKey, privateKey.length), null, emptyPassPhrase);
emptyPassPhrase);
} }
} catch (JSchException e) { } catch (JSchException e) {
throw new SshException(String.format("%s@%s:%d: Error creating session.", username, host, throw new SshException(String.format("%s@%s:%d: Error creating session.", username, host, port), e);
port), e);
} }
java.util.Properties config = new java.util.Properties(); java.util.Properties config = new java.util.Properties();
config.put("StrictHostKeyChecking", "no"); config.put("StrictHostKeyChecking", "no");
@ -249,8 +243,7 @@ public class JschSshClient implements SshClient {
} }
private SshException propagate(Exception e) { private SshException propagate(Exception e) {
throw new SshException(String.format("%s@%s:%d: Error connecting to session.", username, throw new SshException(String.format("%s@%s:%d: Error connecting to session.", username, host, port), e);
host, port), e);
} }
@PreDestroy @PreDestroy
@ -268,19 +261,18 @@ public class JschSshClient implements SshClient {
try { try {
executor = (ChannelExec) session.openChannel("exec"); executor = (ChannelExec) session.openChannel("exec");
} catch (JSchException e) { } catch (JSchException e) {
throw new SshException(String.format("%s@%s:%d: Error connecting to exec.", username, throw new SshException(String.format("%s@%s:%d: Error connecting to exec.", username, host, port), e);
host, port), e);
} }
executor.setCommand(command); executor.setCommand(command);
ByteArrayOutputStream error = new ByteArrayOutputStream(); ByteArrayOutputStream error = new ByteArrayOutputStream();
executor.setErrStream(error); executor.setErrStream(error);
try { try {
executor.connect(); executor.connect();
return new ExecResponse(Utils.toStringAndClose(executor.getInputStream()), error return new ExecResponse(Utils.toStringAndClose(executor.getInputStream()), error.toString(), executor
.toString(), executor.getExitStatus()); .getExitStatus());
} catch (Exception e) { } catch (Exception e) {
throw new SshException(String.format("%s@%s:%d: Error executing command: %s", username, throw new SshException(String
host, port, command), e); .format("%s@%s:%d: Error executing command: %s", username, host, port, command), e);
} }
} finally { } finally {
if (executor != null) if (executor != null)

View File

@ -18,9 +18,6 @@
*/ */
package org.jclouds.ssh.jsch.config; package org.jclouds.ssh.jsch.config;
import java.io.ByteArrayOutputStream;
import java.util.Map;
import javax.inject.Named; import javax.inject.Named;
import org.jclouds.Constants; import org.jclouds.Constants;
@ -32,15 +29,10 @@ import org.jclouds.ssh.SshClient;
import org.jclouds.ssh.jsch.JschSshClient; import org.jclouds.ssh.jsch.JschSshClient;
import org.jclouds.ssh.jsch.predicates.InetSocketAddressConnect; 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.AbstractModule;
import com.google.inject.Inject; import com.google.inject.Inject;
import com.google.inject.Injector; import com.google.inject.Injector;
import com.google.inject.Scopes; 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; return client;
} }
@Override
public Map<String, String> 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()));
}
} }
} }

View File

@ -24,8 +24,9 @@ import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
import java.io.IOException; 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.net.IPSocket;
import org.jclouds.ssh.ExecResponse; import org.jclouds.ssh.ExecResponse;
import org.jclouds.ssh.SshClient; import org.jclouds.ssh.SshClient;
@ -55,8 +56,8 @@ public class JschSshClientLiveTest {
public SshClient setupClient() throws NumberFormatException, FileNotFoundException, IOException { public SshClient setupClient() throws NumberFormatException, FileNotFoundException, IOException {
int port = (sshPort != null) ? Integer.parseInt(sshPort) : 22; int port = (sshPort != null) ? Integer.parseInt(sshPort) : 22;
if (sshUser == null if (sshUser == null
|| ((sshPass == null || sshPass.trim().equals("")) && (sshKeyFile == null || sshKeyFile || ((sshPass == null || sshPass.trim().equals("")) && (sshKeyFile == null || sshKeyFile.trim().equals("")))
.trim().equals(""))) || sshUser.trim().equals("")) { || sshUser.trim().equals("")) {
System.err.println("ssh credentials not present. Tests will be lame"); System.err.println("ssh credentials not present. Tests will be lame");
return new SshClient() { return new SshClient() {
@ -66,11 +67,11 @@ public class JschSshClientLiveTest {
public void disconnect() { public void disconnect() {
} }
public InputStream get(String path) { public Payload get(String path) {
if (path.equals("/etc/passwd")) { if (path.equals("/etc/passwd")) {
return Utils.toInputStream("root"); return Payloads.newStringPayload("root");
} else if (path.equals(temp.getAbsolutePath())) { } else if (path.equals(temp.getAbsolutePath())) {
return Utils.toInputStream("rabbit"); return Payloads.newStringPayload("rabbit");
} }
throw new RuntimeException("path " + path + " not stubbed"); throw new RuntimeException("path " + path + " not stubbed");
} }
@ -83,7 +84,7 @@ public class JschSshClientLiveTest {
} }
@Override @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.Factory factory = i.getInstance(SshClient.Factory.class);
SshClient connection; SshClient connection;
if (sshKeyFile != null && !sshKeyFile.trim().equals("")) { if (sshKeyFile != null && !sshKeyFile.trim().equals("")) {
connection = factory.create(new IPSocket(sshHost, port), sshUser, Utils connection = factory.create(new IPSocket(sshHost, port), sshUser, Utils.toStringAndClose(
.toStringAndClose(new FileInputStream(sshKeyFile)).getBytes()); new FileInputStream(sshKeyFile)).getBytes());
} else { } else {
connection = factory.create(new IPSocket(sshHost, port), sshUser, sshPass); connection = factory.create(new IPSocket(sshHost, port), sshUser, sshPass);
} }
@ -117,15 +118,15 @@ public class JschSshClientLiveTest {
temp = File.createTempFile("foo", "bar"); temp = File.createTempFile("foo", "bar");
temp.deleteOnExit(); temp.deleteOnExit();
SshClient client = setupClient(); SshClient client = setupClient();
client.put(temp.getAbsolutePath(), Utils.toInputStream("rabbit")); client.put(temp.getAbsolutePath(), Payloads.newStringPayload("rabbit"));
InputStream input = setupClient().get(temp.getAbsolutePath()); Payload input = setupClient().get(temp.getAbsolutePath());
String contents = Utils.toStringAndClose(input); String contents = Utils.toStringAndClose(input.getInput());
assertEquals(contents, "rabbit"); assertEquals(contents, "rabbit");
} }
public void testGetEtcPassword() throws IOException { public void testGetEtcPassword() throws IOException {
InputStream input = setupClient().get("/etc/passwd"); Payload input = setupClient().get("/etc/passwd");
String contents = Utils.toStringAndClose(input); String contents = Utils.toStringAndClose(input.getInput());
assert contents.indexOf("root") >= 0 : "no root in " + contents; assert contents.indexOf("root") >= 0 : "no root in " + contents;
} }

View File

@ -18,10 +18,7 @@
*/ */
package org.jclouds.ssh.jsch.config; package org.jclouds.ssh.jsch.config;
import static org.testng.Assert.assertEquals;
import java.net.UnknownHostException; import java.net.UnknownHostException;
import java.util.Map;
import org.jclouds.net.IPSocket; import org.jclouds.net.IPSocket;
import org.jclouds.ssh.SshClient; import org.jclouds.ssh.SshClient;
@ -45,10 +42,5 @@ public class JschSshClientModuleTest {
SshClient.Factory factory = i.getInstance(SshClient.Factory.class); SshClient.Factory factory = i.getInstance(SshClient.Factory.class);
SshClient connection = factory.create(new IPSocket("localhost", 22), "username", "password"); SshClient connection = factory.create(new IPSocket("localhost", 22), "username", "password");
assert connection instanceof JschSshClient; assert connection instanceof JschSshClient;
Map<String, String> 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;
} }
} }

View File

@ -35,8 +35,8 @@ import org.jclouds.gogrid.domain.ServerImageState;
import org.jclouds.gogrid.domain.ServerImageType; import org.jclouds.gogrid.domain.ServerImageType;
import org.jclouds.gogrid.functions.internal.CustomDeserializers; import org.jclouds.gogrid.functions.internal.CustomDeserializers;
import org.jclouds.http.HttpResponse; import org.jclouds.http.HttpResponse;
import org.jclouds.http.Payloads;
import org.jclouds.http.functions.config.ParserModule; import org.jclouds.http.functions.config.ParserModule;
import org.jclouds.io.Payloads;
import org.testng.annotations.Test; import org.testng.annotations.Test;
import com.google.common.collect.Maps; import com.google.common.collect.Maps;

View File

@ -29,8 +29,8 @@ import java.net.UnknownHostException;
import org.jclouds.gogrid.config.DateSecondsAdapter; import org.jclouds.gogrid.config.DateSecondsAdapter;
import org.jclouds.gogrid.domain.internal.ErrorResponse; import org.jclouds.gogrid.domain.internal.ErrorResponse;
import org.jclouds.http.HttpResponse; import org.jclouds.http.HttpResponse;
import org.jclouds.http.Payloads;
import org.jclouds.http.functions.config.ParserModule; import org.jclouds.http.functions.config.ParserModule;
import org.jclouds.io.Payloads;
import org.testng.annotations.Test; import org.testng.annotations.Test;
import com.google.common.collect.Iterables; import com.google.common.collect.Iterables;

View File

@ -38,8 +38,8 @@ import org.jclouds.gogrid.domain.ObjectType;
import org.jclouds.gogrid.domain.Option; import org.jclouds.gogrid.domain.Option;
import org.jclouds.gogrid.functions.internal.CustomDeserializers; import org.jclouds.gogrid.functions.internal.CustomDeserializers;
import org.jclouds.http.HttpResponse; import org.jclouds.http.HttpResponse;
import org.jclouds.http.Payloads;
import org.jclouds.http.functions.config.ParserModule; import org.jclouds.http.functions.config.ParserModule;
import org.jclouds.io.Payloads;
import org.testng.annotations.Test; import org.testng.annotations.Test;
import com.google.common.collect.ImmutableSortedSet; import com.google.common.collect.ImmutableSortedSet;

View File

@ -41,8 +41,8 @@ import org.jclouds.gogrid.domain.LoadBalancerType;
import org.jclouds.gogrid.domain.Option; import org.jclouds.gogrid.domain.Option;
import org.jclouds.gogrid.functions.internal.CustomDeserializers; import org.jclouds.gogrid.functions.internal.CustomDeserializers;
import org.jclouds.http.HttpResponse; import org.jclouds.http.HttpResponse;
import org.jclouds.http.Payloads;
import org.jclouds.http.functions.config.ParserModule; import org.jclouds.http.functions.config.ParserModule;
import org.jclouds.io.Payloads;
import org.testng.annotations.Test; import org.testng.annotations.Test;
import com.google.common.collect.ImmutableSortedSet; import com.google.common.collect.ImmutableSortedSet;

View File

@ -35,8 +35,8 @@ import org.jclouds.gogrid.domain.ServerImageState;
import org.jclouds.gogrid.domain.ServerImageType; import org.jclouds.gogrid.domain.ServerImageType;
import org.jclouds.gogrid.functions.internal.CustomDeserializers; import org.jclouds.gogrid.functions.internal.CustomDeserializers;
import org.jclouds.http.HttpResponse; import org.jclouds.http.HttpResponse;
import org.jclouds.http.Payloads;
import org.jclouds.http.functions.config.ParserModule; import org.jclouds.http.functions.config.ParserModule;
import org.jclouds.io.Payloads;
import org.testng.annotations.Test; import org.testng.annotations.Test;
import com.google.common.collect.Maps; import com.google.common.collect.Maps;

View File

@ -46,8 +46,8 @@ import org.jclouds.gogrid.domain.ServerImageState;
import org.jclouds.gogrid.domain.ServerImageType; import org.jclouds.gogrid.domain.ServerImageType;
import org.jclouds.gogrid.functions.internal.CustomDeserializers; import org.jclouds.gogrid.functions.internal.CustomDeserializers;
import org.jclouds.http.HttpResponse; import org.jclouds.http.HttpResponse;
import org.jclouds.http.Payloads;
import org.jclouds.http.functions.config.ParserModule; import org.jclouds.http.functions.config.ParserModule;
import org.jclouds.io.Payloads;
import org.testng.annotations.Test; import org.testng.annotations.Test;
import com.google.common.collect.ImmutableSortedSet; import com.google.common.collect.ImmutableSortedSet;

View File

@ -33,8 +33,8 @@ import java.io.InputStream;
import org.jclouds.gogrid.mock.HttpCommandMock; import org.jclouds.gogrid.mock.HttpCommandMock;
import org.jclouds.http.HttpCommand; import org.jclouds.http.HttpCommand;
import org.jclouds.http.HttpResponse; import org.jclouds.http.HttpResponse;
import org.jclouds.http.Payloads;
import org.jclouds.http.functions.config.ParserModule; import org.jclouds.http.functions.config.ParserModule;
import org.jclouds.io.Payloads;
import org.testng.TestException; import org.testng.TestException;
import org.testng.annotations.Test; import org.testng.annotations.Test;

View File

@ -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.options.CreateInstanceOptions.Builder.authorizePublicKey;
import static org.jclouds.ibmdev.reference.IBMDeveloperCloudConstants.PROPERTY_IBMDEVELOPERCLOUD_LOCATION; import static org.jclouds.ibmdev.reference.IBMDeveloperCloudConstants.PROPERTY_IBMDEVELOPERCLOUD_LOCATION;
import java.io.IOException;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.concurrent.ConcurrentHashMap; 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.compute.functions.InstanceToNodeMetadata;
import org.jclouds.ibmdev.domain.Instance; import org.jclouds.ibmdev.domain.Instance;
import org.jclouds.ibmdev.reference.IBMDeveloperCloudConstants; import org.jclouds.ibmdev.reference.IBMDeveloperCloudConstants;
import org.jclouds.io.Payload;
import org.jclouds.logging.Logger; import org.jclouds.logging.Logger;
import org.jclouds.rest.RestContext; import org.jclouds.rest.RestContext;
import org.jclouds.rest.internal.RestContextImpl; import org.jclouds.rest.internal.RestContextImpl;
import org.jclouds.util.Utils;
import com.google.common.base.Function; import com.google.common.base.Function;
import com.google.common.base.Predicate; import com.google.common.base.Predicate;
@ -95,15 +98,11 @@ public class IBMDeveloperCloudComputeServiceContextModule extends AbstractModule
bind(new TypeLiteral<Function<Instance, NodeMetadata>>() { bind(new TypeLiteral<Function<Instance, NodeMetadata>>() {
}).to(InstanceToNodeMetadata.class); }).to(InstanceToNodeMetadata.class);
bind(new TypeLiteral<ComputeServiceContext>() { bind(new TypeLiteral<ComputeServiceContext>() {
}) }).to(new TypeLiteral<ComputeServiceContextImpl<IBMDeveloperCloudClient, IBMDeveloperCloudAsyncClient>>() {
.to( }).in(Scopes.SINGLETON);
new TypeLiteral<ComputeServiceContextImpl<IBMDeveloperCloudClient, IBMDeveloperCloudAsyncClient>>() {
}).in(Scopes.SINGLETON);
bind(new TypeLiteral<RestContext<IBMDeveloperCloudClient, IBMDeveloperCloudAsyncClient>>() { bind(new TypeLiteral<RestContext<IBMDeveloperCloudClient, IBMDeveloperCloudAsyncClient>>() {
}) }).to(new TypeLiteral<RestContextImpl<IBMDeveloperCloudClient, IBMDeveloperCloudAsyncClient>>() {
.to( }).in(Scopes.SINGLETON);
new TypeLiteral<RestContextImpl<IBMDeveloperCloudClient, IBMDeveloperCloudAsyncClient>>() {
}).in(Scopes.SINGLETON);
bind(AddNodeWithTagStrategy.class).to(IBMDeveloperCloudAddNodeWithTagStrategy.class); bind(AddNodeWithTagStrategy.class).to(IBMDeveloperCloudAddNodeWithTagStrategy.class);
bind(ListNodesStrategy.class).to(IBMDeveloperCloudListNodesStrategy.class); bind(ListNodesStrategy.class).to(IBMDeveloperCloudListNodesStrategy.class);
bind(GetNodeMetadataStrategy.class).to(IBMDeveloperCloudGetNodeMetadataStrategy.class); bind(GetNodeMetadataStrategy.class).to(IBMDeveloperCloudGetNodeMetadataStrategy.class);
@ -137,33 +136,37 @@ public class IBMDeveloperCloudComputeServiceContextModule extends AbstractModule
@Singleton @Singleton
public static class CreateKeyPairEncodeTagIntoNameRunNodesAndAddToSet extends public static class CreateKeyPairEncodeTagIntoNameRunNodesAndAddToSet extends
EncodeTagIntoNameRunNodesAndAddToSetStrategy { EncodeTagIntoNameRunNodesAndAddToSetStrategy {
private final IBMDeveloperCloudClient client; private final IBMDeveloperCloudClient client;
private final Map<String, String> credentialsMap; private final Map<String, String> credentialsMap;
@Inject @Inject
protected CreateKeyPairEncodeTagIntoNameRunNodesAndAddToSet( protected CreateKeyPairEncodeTagIntoNameRunNodesAndAddToSet(AddNodeWithTagStrategy addNodeWithTagStrategy,
AddNodeWithTagStrategy addNodeWithTagStrategy, ListNodesStrategy listNodesStrategy, ListNodesStrategy listNodesStrategy, @Named("NAMING_CONVENTION") String nodeNamingConvention,
@Named("NAMING_CONVENTION") String nodeNamingConvention, ComputeUtils utils, ComputeUtils utils, @Named(Constants.PROPERTY_USER_THREADS) ExecutorService executor,
@Named(Constants.PROPERTY_USER_THREADS) ExecutorService executor, IBMDeveloperCloudClient client, @Named("CREDENTIALS") Map<String, String> credentialsMap) {
IBMDeveloperCloudClient client,
@Named("CREDENTIALS") Map<String, String> credentialsMap) {
super(addNodeWithTagStrategy, listNodesStrategy, nodeNamingConvention, utils, executor); super(addNodeWithTagStrategy, listNodesStrategy, nodeNamingConvention, utils, executor);
this.client = checkNotNull(client, "client"); this.client = checkNotNull(client, "client");
this.credentialsMap = checkNotNull(credentialsMap, "credentialsMap"); this.credentialsMap = checkNotNull(credentialsMap, "credentialsMap");
} }
@Override @Override
public Map<?, ListenableFuture<Void>> execute(String tag, int count, Template template, public Map<?, ListenableFuture<Void>> execute(String tag, int count, Template template, Set<NodeMetadata> nodes,
Set<NodeMetadata> nodes, Map<NodeMetadata, Exception> badNodes) { Map<NodeMetadata, Exception> badNodes) {
String key = template.getOptions().getPublicKey(); Payload key = template.getOptions().getPublicKey();
if (key != null) { if (key != null) {
String keyAsText;
try {
keyAsText = Utils.toStringAndClose(key.getInput());
} catch (IOException e1) {
throw new RuntimeException(e1);
}
template.getOptions().dontAuthorizePublicKey(); template.getOptions().dontAuthorizePublicKey();
try { try {
client.addPublicKey(tag, key); client.addPublicKey(tag, keyAsText);
} catch (IllegalStateException e) { } catch (IllegalStateException e) {
// must not have been found // must not have been found
client.updatePublicKey(tag, key); client.updatePublicKey(tag, keyAsText);
} }
} else { } else {
credentialsMap.put(tag, client.generateKeyPair(tag).getKeyMaterial()); credentialsMap.put(tag, client.generateKeyPair(tag).getKeyMaterial());
@ -181,17 +184,15 @@ public class IBMDeveloperCloudComputeServiceContextModule extends AbstractModule
@Inject @Inject
protected IBMDeveloperCloudAddNodeWithTagStrategy(IBMDeveloperCloudClient client, protected IBMDeveloperCloudAddNodeWithTagStrategy(IBMDeveloperCloudClient client,
Function<Instance, NodeMetadata> instanceToNodeMetadata) { Function<Instance, NodeMetadata> instanceToNodeMetadata) {
this.client = checkNotNull(client, "client"); this.client = checkNotNull(client, "client");
this.instanceToNodeMetadata = checkNotNull(instanceToNodeMetadata, this.instanceToNodeMetadata = checkNotNull(instanceToNodeMetadata, "instanceToNodeMetadata");
"instanceToNodeMetadata");
} }
@Override @Override
public NodeMetadata execute(String tag, String name, Template template) { public NodeMetadata execute(String tag, String name, Template template) {
Instance instance = client.createInstanceInLocation(template.getLocation().getId(), name, Instance instance = client.createInstanceInLocation(template.getLocation().getId(), name, template.getImage()
template.getImage().getProviderId(), template.getSize().getProviderId(), .getProviderId(), template.getSize().getProviderId(), authorizePublicKey(tag));
authorizePublicKey(tag));
return instanceToNodeMetadata.apply(client.getInstance(instance.getId())); return instanceToNodeMetadata.apply(client.getInstance(instance.getId()));
} }
} }
@ -203,8 +204,7 @@ public class IBMDeveloperCloudComputeServiceContextModule extends AbstractModule
private final GetNodeMetadataStrategy getNode; private final GetNodeMetadataStrategy getNode;
@Inject @Inject
protected IBMDeveloperCloudRebootNodeStrategy(IBMDeveloperCloudClient client, protected IBMDeveloperCloudRebootNodeStrategy(IBMDeveloperCloudClient client, GetNodeMetadataStrategy getNode) {
GetNodeMetadataStrategy getNode) {
this.client = checkNotNull(client, "client"); this.client = checkNotNull(client, "client");
this.getNode = checkNotNull(getNode, "getNode"); this.getNode = checkNotNull(getNode, "getNode");
} }
@ -219,19 +219,18 @@ public class IBMDeveloperCloudComputeServiceContextModule extends AbstractModule
@Singleton @Singleton
@Provides @Provides
Map<Instance.Status, NodeState> provideServerToNodeState() { Map<Instance.Status, NodeState> provideServerToNodeState() {
return ImmutableMap.<Instance.Status, NodeState> builder().put(Instance.Status.ACTIVE, return ImmutableMap.<Instance.Status, NodeState> builder().put(Instance.Status.ACTIVE, NodeState.RUNNING)//
NodeState.RUNNING)// .put(Instance.Status.STOPPED, NodeState.SUSPENDED)//
.put(Instance.Status.STOPPED, NodeState.SUSPENDED)// .put(Instance.Status.REMOVED, NodeState.TERMINATED)//
.put(Instance.Status.REMOVED, NodeState.TERMINATED)// .put(Instance.Status.DEPROVISIONING, NodeState.PENDING)//
.put(Instance.Status.DEPROVISIONING, NodeState.PENDING)// .put(Instance.Status.FAILED, NodeState.ERROR)//
.put(Instance.Status.FAILED, NodeState.ERROR)// .put(Instance.Status.NEW, NodeState.PENDING)//
.put(Instance.Status.NEW, NodeState.PENDING)// .put(Instance.Status.PROVISIONING, NodeState.PENDING)//
.put(Instance.Status.PROVISIONING, NodeState.PENDING)// .put(Instance.Status.REJECTED, NodeState.ERROR)//
.put(Instance.Status.REJECTED, NodeState.ERROR)// .put(Instance.Status.RESTARTING, NodeState.PENDING)//
.put(Instance.Status.RESTARTING, NodeState.PENDING)// .put(Instance.Status.STARTING, NodeState.PENDING)//
.put(Instance.Status.STARTING, NodeState.PENDING)// .put(Instance.Status.STOPPING, NodeState.PENDING)//
.put(Instance.Status.STOPPING, NodeState.PENDING)// .put(Instance.Status.UNKNOWN, NodeState.UNKNOWN).build();
.put(Instance.Status.UNKNOWN, NodeState.UNKNOWN).build();
} }
@Singleton @Singleton
@ -241,7 +240,7 @@ public class IBMDeveloperCloudComputeServiceContextModule extends AbstractModule
@Inject @Inject
protected IBMDeveloperCloudListNodesStrategy(IBMDeveloperCloudClient client, protected IBMDeveloperCloudListNodesStrategy(IBMDeveloperCloudClient client,
Function<Instance, NodeMetadata> instanceToNodeMetadata) { Function<Instance, NodeMetadata> instanceToNodeMetadata) {
this.client = client; this.client = client;
this.instanceToNodeMetadata = instanceToNodeMetadata; this.instanceToNodeMetadata = instanceToNodeMetadata;
} }
@ -252,10 +251,8 @@ public class IBMDeveloperCloudComputeServiceContextModule extends AbstractModule
} }
@Override @Override
public Iterable<? extends NodeMetadata> listDetailsOnNodesMatching( public Iterable<? extends NodeMetadata> listDetailsOnNodesMatching(Predicate<ComputeMetadata> filter) {
Predicate<ComputeMetadata> filter) { return Iterables.filter(Iterables.transform(client.listInstances(), instanceToNodeMetadata), filter);
return Iterables.filter(Iterables
.transform(client.listInstances(), instanceToNodeMetadata), filter);
} }
} }
@ -266,7 +263,7 @@ public class IBMDeveloperCloudComputeServiceContextModule extends AbstractModule
@Inject @Inject
protected IBMDeveloperCloudGetNodeMetadataStrategy(IBMDeveloperCloudClient client, protected IBMDeveloperCloudGetNodeMetadataStrategy(IBMDeveloperCloudClient client,
Function<Instance, NodeMetadata> instanceToNodeMetadata) { Function<Instance, NodeMetadata> instanceToNodeMetadata) {
this.client = client; this.client = client;
this.instanceToNodeMetadata = instanceToNodeMetadata; this.instanceToNodeMetadata = instanceToNodeMetadata;
} }
@ -284,8 +281,7 @@ public class IBMDeveloperCloudComputeServiceContextModule extends AbstractModule
private final GetNodeMetadataStrategy getNode; private final GetNodeMetadataStrategy getNode;
@Inject @Inject
protected IBMDeveloperCloudDestroyNodeStrategy(IBMDeveloperCloudClient client, protected IBMDeveloperCloudDestroyNodeStrategy(IBMDeveloperCloudClient client, GetNodeMetadataStrategy getNode) {
GetNodeMetadataStrategy getNode) {
this.client = checkNotNull(client, "client"); this.client = checkNotNull(client, "client");
this.getNode = checkNotNull(getNode, "getNode"); this.getNode = checkNotNull(getNode, "getNode");
} }
@ -299,9 +295,8 @@ public class IBMDeveloperCloudComputeServiceContextModule extends AbstractModule
@Provides @Provides
@Singleton @Singleton
Location getDefaultLocation( Location getDefaultLocation(@Named(PROPERTY_IBMDEVELOPERCLOUD_LOCATION) final String defaultLocation,
@Named(PROPERTY_IBMDEVELOPERCLOUD_LOCATION) final String defaultLocation, Set<? extends Location> locations) {
Set<? extends Location> locations) {
return Iterables.find(locations, new Predicate<Location>() { return Iterables.find(locations, new Predicate<Location>() {
@Override @Override
@ -315,14 +310,13 @@ public class IBMDeveloperCloudComputeServiceContextModule extends AbstractModule
@Provides @Provides
@Singleton @Singleton
Set<? extends Location> getAssignableLocations(IBMDeveloperCloudClient sync, LogHolder holder, Set<? extends Location> getAssignableLocations(IBMDeveloperCloudClient sync, LogHolder holder,
@org.jclouds.rest.annotations.Provider String providerName) { @org.jclouds.rest.annotations.Provider String providerName) {
final Set<Location> assignableLocations = Sets.newHashSet(); final Set<Location> assignableLocations = Sets.newHashSet();
holder.logger.debug(">> providing locations"); holder.logger.debug(">> providing locations");
Location parent = new LocationImpl(LocationScope.PROVIDER, providerName, providerName, null); Location parent = new LocationImpl(LocationScope.PROVIDER, providerName, providerName, null);
for (org.jclouds.ibmdev.domain.Location location : sync.listLocations()) for (org.jclouds.ibmdev.domain.Location location : sync.listLocations())
assignableLocations.add(new LocationImpl(LocationScope.ZONE, location.getId(), location assignableLocations.add(new LocationImpl(LocationScope.ZONE, location.getId(), location.getName(), parent));
.getName(), parent));
holder.logger.debug("<< locations(%d)", assignableLocations.size()); holder.logger.debug("<< locations(%d)", assignableLocations.size());
return assignableLocations; return assignableLocations;
@ -331,7 +325,7 @@ public class IBMDeveloperCloudComputeServiceContextModule extends AbstractModule
@Provides @Provides
@Singleton @Singleton
protected Set<? extends Size> provideSizes(IBMDeveloperCloudClient sync, LogHolder holder, protected Set<? extends Size> provideSizes(IBMDeveloperCloudClient sync, LogHolder holder,
Map<String, ? extends Location> locations) { Map<String, ? extends Location> locations) {
final Set<Size> sizes = Sets.newHashSet(); final Set<Size> sizes = Sets.newHashSet();
holder.logger.debug(">> providing sizes"); 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 // TODO we cannot query actual size, yet, so lets make the
// multipliers work out // multipliers work out
int sizeMultiplier = 1; int sizeMultiplier = 1;
for (String i386 : location.getCapabilities().get( for (String i386 : location.getCapabilities().get(IBMDeveloperCloudConstants.CAPABILITY_I386).keySet())
IBMDeveloperCloudConstants.CAPABILITY_I386).keySet())
sizes.add(buildSize(location, i386, assignedLocation, sizeMultiplier++)); sizes.add(buildSize(location, i386, assignedLocation, sizeMultiplier++));
for (String x86_64 : location.getCapabilities().get( for (String x86_64 : location.getCapabilities().get(IBMDeveloperCloudConstants.CAPABILITY_x86_64).keySet())
IBMDeveloperCloudConstants.CAPABILITY_x86_64).keySet())
sizes.add(buildSize(location, x86_64, assignedLocation, sizeMultiplier++)); sizes.add(buildSize(location, x86_64, assignedLocation, sizeMultiplier++));
} }
holder.logger.debug("<< sizes(%d)", sizes.size()); holder.logger.debug("<< sizes(%d)", sizes.size());
return sizes; return sizes;
} }
private SizeImpl buildSize(org.jclouds.ibmdev.domain.Location location, final String id, private SizeImpl buildSize(org.jclouds.ibmdev.domain.Location location, final String id, Location assignedLocation,
Location assignedLocation, int multiplier) { int multiplier) {
return new SizeImpl(id, id, location.getId() + "/" + id, assignedLocation, null, ImmutableMap return new SizeImpl(id, id, location.getId() + "/" + id, assignedLocation, null, ImmutableMap
.<String, String> of(), multiplier, multiplier * 1024, multiplier * 10, .<String, String> of(), multiplier, multiplier * 1024, multiplier * 10, new Predicate<Image>() {
new Predicate<Image>() { @Override
@Override public boolean apply(Image input) {
public boolean apply(Image input) { if (input instanceof IBMImage)
if (input instanceof IBMImage) return IBMImage.class.cast(input).rawImage.getSupportedInstanceTypes().contains(id);
return IBMImage.class.cast(input).rawImage.getSupportedInstanceTypes() return false;
.contains(id); }
return false;
}
}); });
} }
@Provides @Provides
@ -395,8 +385,8 @@ public class IBMDeveloperCloudComputeServiceContextModule extends AbstractModule
@Provides @Provides
@Singleton @Singleton
protected Set<? extends Image> provideImages(final IBMDeveloperCloudClient sync, protected Set<? extends Image> provideImages(final IBMDeveloperCloudClient sync, LogHolder holder,
LogHolder holder, Map<String, ? extends Location> locations) { Map<String, ? extends Location> locations) {
final Set<Image> images = Sets.newHashSet(); final Set<Image> images = Sets.newHashSet();
holder.logger.debug(">> providing images"); 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 manifest fails to parse due to encoding issues in the path
// TODO get correct default credentials // 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 // 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 super(in.getId(), in.getName(), in.getId(), location, null, ImmutableMap.<String, String> of(), in
.<String, String> of(), in.getDescription(), in.getCreatedTime().getTime() + "", .getDescription(), in.getCreatedTime().getTime() + "",
(in.getPlatform().indexOf("Redhat") != -1) ? OsFamily.RHEL : OsFamily.SUSE, in (in.getPlatform().indexOf("Redhat") != -1) ? OsFamily.RHEL : OsFamily.SUSE, in.getPlatform(), (in
.getPlatform(), .getPlatform().indexOf("32") != -1) ? Architecture.X86_32 : Architecture.X86_64, new Credentials(
(in.getPlatform().indexOf("32") != -1) ? Architecture.X86_32 "idcuser", null));
: Architecture.X86_64, new Credentials("idcuser", null));
this.rawImage = in; this.rawImage = in;
} }

View File

@ -24,9 +24,9 @@ import static org.testng.Assert.assertEquals;
import java.io.IOException; import java.io.IOException;
import org.jclouds.http.HttpResponse; import org.jclouds.http.HttpResponse;
import org.jclouds.http.Payloads;
import org.jclouds.http.functions.config.ParserModule; import org.jclouds.http.functions.config.ParserModule;
import org.jclouds.ibmdev.domain.Address; import org.jclouds.ibmdev.domain.Address;
import org.jclouds.io.Payloads;
import org.testng.annotations.BeforeTest; import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test; import org.testng.annotations.Test;

View File

@ -23,9 +23,9 @@ import java.io.IOException;
import java.util.Set; import java.util.Set;
import org.jclouds.http.HttpResponse; import org.jclouds.http.HttpResponse;
import org.jclouds.http.Payloads;
import org.jclouds.http.functions.config.ParserModule; import org.jclouds.http.functions.config.ParserModule;
import org.jclouds.ibmdev.domain.Address; import org.jclouds.ibmdev.domain.Address;
import org.jclouds.io.Payloads;
import org.testng.annotations.BeforeTest; import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test; import org.testng.annotations.Test;

View File

@ -25,8 +25,8 @@ import java.io.IOException;
import java.util.Date; import java.util.Date;
import org.jclouds.http.HttpResponse; import org.jclouds.http.HttpResponse;
import org.jclouds.http.Payloads;
import org.jclouds.http.functions.config.ParserModule; import org.jclouds.http.functions.config.ParserModule;
import org.jclouds.io.Payloads;
import org.testng.annotations.BeforeTest; import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test; import org.testng.annotations.Test;

View File

@ -26,11 +26,11 @@ import java.util.Date;
import org.jclouds.http.HttpResponse; import org.jclouds.http.HttpResponse;
import org.jclouds.http.HttpUtils; import org.jclouds.http.HttpUtils;
import org.jclouds.http.Payloads;
import org.jclouds.http.functions.config.ParserModule; import org.jclouds.http.functions.config.ParserModule;
import org.jclouds.ibmdev.config.IBMDeveloperCloudParserModule; import org.jclouds.ibmdev.config.IBMDeveloperCloudParserModule;
import org.jclouds.ibmdev.domain.Image; import org.jclouds.ibmdev.domain.Image;
import org.jclouds.ibmdev.domain.Image.Visibility; import org.jclouds.ibmdev.domain.Image.Visibility;
import org.jclouds.io.Payloads;
import org.testng.annotations.BeforeTest; import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test; import org.testng.annotations.Test;

Some files were not shown because too many files have changed in this diff Show More