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.SystemMetadata;
import org.jclouds.atmosonline.saas.domain.UserMetadata;
import org.jclouds.http.Payload;
import org.jclouds.http.PayloadEnclosing;
import org.jclouds.http.internal.PayloadEnclosingImpl;
import org.jclouds.http.payloads.DelegatingPayload;
import org.jclouds.io.Payload;
import org.jclouds.io.payloads.DelegatingPayload;
import com.google.common.collect.LinkedHashMultimap;
import com.google.common.collect.Multimap;

View File

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

View File

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

View File

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

View File

@ -25,10 +25,10 @@ import javax.inject.Inject;
import org.jclouds.aws.s3.domain.AccessControlList;
import org.jclouds.aws.s3.domain.MutableObjectMetadata;
import org.jclouds.aws.s3.domain.S3Object;
import org.jclouds.http.Payload;
import org.jclouds.http.PayloadEnclosing;
import org.jclouds.http.internal.PayloadEnclosingImpl;
import org.jclouds.http.payloads.DelegatingPayload;
import org.jclouds.io.Payload;
import org.jclouds.io.payloads.DelegatingPayload;
import com.google.common.collect.LinkedHashMultimap;
import com.google.common.collect.Multimap;

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

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

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.MutableBlobProperties;
import org.jclouds.http.Payload;
import org.jclouds.http.PayloadEnclosing;
import org.jclouds.http.internal.PayloadEnclosingImpl;
import org.jclouds.http.payloads.DelegatingPayload;
import org.jclouds.io.Payload;
import org.jclouds.io.payloads.DelegatingPayload;
import com.google.common.collect.LinkedHashMultimap;
import com.google.common.collect.Multimap;

View File

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

View File

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

View File

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

View File

@ -25,10 +25,10 @@ import javax.inject.Inject;
import org.jclouds.blobstore.domain.Blob;
import org.jclouds.blobstore.domain.MutableBlobMetadata;
import org.jclouds.blobstore.domain.StorageMetadata;
import org.jclouds.http.Payload;
import org.jclouds.http.PayloadEnclosing;
import org.jclouds.http.internal.PayloadEnclosingImpl;
import org.jclouds.http.payloads.DelegatingPayload;
import org.jclouds.io.Payload;
import org.jclouds.io.payloads.DelegatingPayload;
import com.google.common.collect.LinkedHashMultimap;
import com.google.common.collect.Multimap;

View File

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

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

View File

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

View File

@ -18,7 +18,7 @@
*/
package org.jclouds.blobstore.binders;
import static org.jclouds.http.payloads.MultipartForm.BOUNDARY;
import static org.jclouds.io.payloads.MultipartForm.BOUNDARY;
import static org.jclouds.util.Utils.toStringAndClose;
import static org.testng.Assert.assertEquals;

View File

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

View File

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

View File

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

View File

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

View File

@ -43,11 +43,11 @@ import org.jclouds.http.HttpException;
import org.jclouds.http.HttpRequest;
import org.jclouds.http.HttpRequestFilter;
import org.jclouds.http.HttpUtils;
import org.jclouds.http.Payload;
import org.jclouds.http.Payloads;
import org.jclouds.http.internal.SignatureWire;
import org.jclouds.http.payloads.MultipartForm;
import org.jclouds.http.payloads.Part;
import org.jclouds.io.Payload;
import org.jclouds.io.Payloads;
import org.jclouds.io.payloads.MultipartForm;
import org.jclouds.io.payloads.Part;
import org.jclouds.logging.Logger;
import org.jclouds.util.Utils;

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

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

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

View File

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

View File

@ -18,12 +18,10 @@
*/
package org.jclouds.ssh;
import java.io.InputStream;
import java.util.Map;
import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
import org.jclouds.io.Payload;
import org.jclouds.net.IPSocket;
/**
@ -35,17 +33,15 @@ public interface SshClient {
SshClient create(IPSocket socket, String username, String password);
SshClient create(IPSocket socket, String username, byte[] privateKey);
Map<String, String> generateRSAKeyPair(String comment, String passphrase);
}
String getUsername();
String getHostAddress();
void put(String path, InputStream contents);
void put(String path, Payload contents);
InputStream get(String path);
Payload get(String path);
ExecResponse exec(String command);

View File

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

View File

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

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

View File

@ -25,9 +25,9 @@ import java.io.OutputStream;
import java.security.Key;
import org.jclouds.encryption.internal.JCEEncryptionService;
import org.jclouds.http.Payload;
import org.jclouds.http.PayloadEnclosing;
import org.jclouds.http.payloads.ByteArrayPayload;
import org.jclouds.io.Payload;
import org.jclouds.io.payloads.ByteArrayPayload;
import com.google.inject.ImplementedBy;

View File

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

View File

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

View File

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

View File

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

View File

@ -20,6 +20,8 @@ package org.jclouds.http;
import javax.annotation.Nullable;
import org.jclouds.io.Payload;
/**
* 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_TYPE;
import static javax.ws.rs.core.HttpHeaders.HOST;
import static org.jclouds.http.Payloads.newUrlEncodedFormPayload;
import static org.jclouds.io.Payloads.newUrlEncodedFormPayload;
import static org.jclouds.util.Patterns.CHAR_TO_ENCODED_PATTERN;
import static org.jclouds.util.Patterns.PATTERN_THAT_BREAKS_URI;
import static org.jclouds.util.Patterns.PLUS_PATTERN;
@ -64,6 +64,8 @@ import javax.ws.rs.core.UriBuilder;
import org.jclouds.Constants;
import org.jclouds.encryption.EncryptionService;
import org.jclouds.io.Payload;
import org.jclouds.io.Payloads;
import org.jclouds.logging.Logger;
import com.google.common.base.Joiner;

View File

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

View File

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

View File

@ -19,15 +19,15 @@
package org.jclouds.http.internal;
import static com.google.common.base.Preconditions.checkNotNull;
import static org.jclouds.http.Payloads.newPayload;
import static org.jclouds.io.Payloads.newPayload;
import java.io.File;
import java.io.InputStream;
import javax.annotation.Nullable;
import org.jclouds.http.Payload;
import org.jclouds.http.PayloadEnclosing;
import org.jclouds.io.Payload;
/**
*

View File

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

View File

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

View File

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

View File

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

View File

@ -16,7 +16,7 @@
* limitations under the License.
* ====================================================================
*/
package org.jclouds.http.payloads;
package org.jclouds.io.payloads;
import static com.google.common.base.Preconditions.checkNotNull;
@ -24,7 +24,7 @@ import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import org.jclouds.http.Payload;
import org.jclouds.io.Payload;
/**
*

View File

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

View File

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

View File

@ -16,7 +16,7 @@
* limitations under the License.
* ====================================================================
*/
package org.jclouds.http.payloads;
package org.jclouds.io.payloads;
import static com.google.common.base.Throwables.propagate;
import static com.google.common.collect.Lists.newArrayList;

View File

@ -16,7 +16,7 @@
* limitations under the License.
* ====================================================================
*/
package org.jclouds.http.payloads;
package org.jclouds.io.payloads;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.collect.Multimaps.forMap;
@ -26,8 +26,8 @@ import java.util.LinkedHashMap;
import javax.annotation.Nullable;
import javax.ws.rs.core.HttpHeaders;
import org.jclouds.http.Payload;
import org.jclouds.http.Payloads;
import org.jclouds.io.Payload;
import org.jclouds.io.Payloads;
import com.google.common.collect.ImmutableMultimap;
import com.google.common.collect.Multimap;

View File

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

View File

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

View File

@ -29,9 +29,9 @@ import java.io.InputStream;
import javax.annotation.Resource;
import org.jclouds.http.Payload;
import org.jclouds.http.PayloadEnclosing;
import org.jclouds.http.Payloads;
import org.jclouds.io.Payload;
import org.jclouds.io.Payloads;
import org.jclouds.logging.Logger;
import com.google.common.io.ByteStreams;

View File

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

View File

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

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.parseQueryToMap;
import static org.jclouds.http.HttpUtils.urlEncode;
import static org.jclouds.http.Payloads.newPayload;
import static org.jclouds.io.Payloads.newPayload;
import static org.jclouds.util.Utils.replaceTokens;
import java.io.InputStream;
@ -75,9 +75,7 @@ import org.jclouds.http.HttpRequest;
import org.jclouds.http.HttpRequestFilter;
import org.jclouds.http.HttpResponse;
import org.jclouds.http.HttpUtils;
import org.jclouds.http.Payload;
import org.jclouds.http.PayloadEnclosing;
import org.jclouds.http.Payloads;
import org.jclouds.http.functions.ParseJson;
import org.jclouds.http.functions.ParseSax;
import org.jclouds.http.functions.ParseURIFromListOrLocationHeaderIf20x;
@ -88,10 +86,12 @@ import org.jclouds.http.functions.ReturnTrueIf2xx;
import org.jclouds.http.functions.UnwrapOnlyJsonValue;
import org.jclouds.http.functions.ParseSax.HandlerWithResult;
import org.jclouds.http.options.HttpRequestOptions;
import org.jclouds.http.payloads.MultipartForm;
import org.jclouds.http.payloads.Part;
import org.jclouds.http.payloads.Part.PartOptions;
import org.jclouds.internal.ClassMethodArgs;
import org.jclouds.io.Payload;
import org.jclouds.io.Payloads;
import org.jclouds.io.payloads.MultipartForm;
import org.jclouds.io.payloads.Part;
import org.jclouds.io.payloads.Part.PartOptions;
import org.jclouds.logging.Logger;
import org.jclouds.rest.Binder;
import org.jclouds.rest.InputParamValidator;

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -26,8 +26,8 @@ import static org.easymock.EasyMock.expect;
import static org.easymock.EasyMock.reportMatcher;
import static org.easymock.classextension.EasyMock.replay;
import static org.easymock.classextension.EasyMock.verify;
import static org.jclouds.http.Payloads.newInputStreamPayload;
import static org.jclouds.http.Payloads.newStringPayload;
import static org.jclouds.io.Payloads.newInputStreamPayload;
import static org.jclouds.io.Payloads.newStringPayload;
import static org.jclouds.rest.RestContextFactory.contextSpec;
import static org.jclouds.rest.RestContextFactory.createContextBuilder;
import static org.jclouds.util.Utils.toInputStream;
@ -84,9 +84,7 @@ import org.jclouds.http.HttpRequest;
import org.jclouds.http.HttpRequestFilter;
import org.jclouds.http.HttpResponse;
import org.jclouds.http.IOExceptionRetryHandler;
import org.jclouds.http.Payload;
import org.jclouds.http.PayloadEnclosing;
import org.jclouds.http.Payloads;
import org.jclouds.http.RequiresHttp;
import org.jclouds.http.TransformingHttpCommandExecutorService;
import org.jclouds.http.functions.ParseJson;
@ -101,6 +99,8 @@ import org.jclouds.http.internal.PayloadEnclosingImpl;
import org.jclouds.http.options.BaseHttpRequestOptions;
import org.jclouds.http.options.GetOptions;
import org.jclouds.http.options.HttpRequestOptions;
import org.jclouds.io.Payload;
import org.jclouds.io.Payloads;
import org.jclouds.logging.config.NullLoggingModule;
import org.jclouds.rest.AsyncClientFactory;
import org.jclouds.rest.BaseRestClientTest;

View File

@ -36,12 +36,12 @@ import org.jclouds.http.HttpRequest;
import org.jclouds.http.HttpResponse;
import org.jclouds.http.HttpUtils;
import org.jclouds.http.IOExceptionRetryHandler;
import org.jclouds.http.Payload;
import org.jclouds.http.Payloads;
import org.jclouds.http.handlers.DelegatingErrorHandler;
import org.jclouds.http.handlers.DelegatingRetryHandler;
import org.jclouds.http.internal.BaseHttpCommandExecutorService;
import org.jclouds.http.internal.HttpWire;
import org.jclouds.io.Payload;
import org.jclouds.io.Payloads;
import com.google.common.collect.LinkedHashMultimap;
import com.google.common.collect.Multimap;

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -18,9 +18,6 @@
*/
package org.jclouds.ssh.jsch.config;
import java.io.ByteArrayOutputStream;
import java.util.Map;
import javax.inject.Named;
import org.jclouds.Constants;
@ -32,15 +29,10 @@ import org.jclouds.ssh.SshClient;
import org.jclouds.ssh.jsch.JschSshClient;
import org.jclouds.ssh.jsch.predicates.InetSocketAddressConnect;
import com.google.common.base.Throwables;
import com.google.common.collect.ImmutableMap;
import com.google.inject.AbstractModule;
import com.google.inject.Inject;
import com.google.inject.Injector;
import com.google.inject.Scopes;
import com.jcraft.jsch.JSch;
import com.jcraft.jsch.JSchException;
import com.jcraft.jsch.KeyPair;
/**
*
@ -81,22 +73,5 @@ public class JschSshClientModule extends AbstractModule {
return client;
}
@Override
public Map<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.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import org.jclouds.io.Payload;
import org.jclouds.io.Payloads;
import org.jclouds.net.IPSocket;
import org.jclouds.ssh.ExecResponse;
import org.jclouds.ssh.SshClient;
@ -55,8 +56,8 @@ public class JschSshClientLiveTest {
public SshClient setupClient() throws NumberFormatException, FileNotFoundException, IOException {
int port = (sshPort != null) ? Integer.parseInt(sshPort) : 22;
if (sshUser == null
|| ((sshPass == null || sshPass.trim().equals("")) && (sshKeyFile == null || sshKeyFile
.trim().equals(""))) || sshUser.trim().equals("")) {
|| ((sshPass == null || sshPass.trim().equals("")) && (sshKeyFile == null || sshKeyFile.trim().equals("")))
|| sshUser.trim().equals("")) {
System.err.println("ssh credentials not present. Tests will be lame");
return new SshClient() {
@ -66,11 +67,11 @@ public class JschSshClientLiveTest {
public void disconnect() {
}
public InputStream get(String path) {
public Payload get(String path) {
if (path.equals("/etc/passwd")) {
return Utils.toInputStream("root");
return Payloads.newStringPayload("root");
} else if (path.equals(temp.getAbsolutePath())) {
return Utils.toInputStream("rabbit");
return Payloads.newStringPayload("rabbit");
}
throw new RuntimeException("path " + path + " not stubbed");
}
@ -83,7 +84,7 @@ public class JschSshClientLiveTest {
}
@Override
public void put(String path, InputStream contents) {
public void put(String path, Payload contents) {
}
@ -103,8 +104,8 @@ public class JschSshClientLiveTest {
SshClient.Factory factory = i.getInstance(SshClient.Factory.class);
SshClient connection;
if (sshKeyFile != null && !sshKeyFile.trim().equals("")) {
connection = factory.create(new IPSocket(sshHost, port), sshUser, Utils
.toStringAndClose(new FileInputStream(sshKeyFile)).getBytes());
connection = factory.create(new IPSocket(sshHost, port), sshUser, Utils.toStringAndClose(
new FileInputStream(sshKeyFile)).getBytes());
} else {
connection = factory.create(new IPSocket(sshHost, port), sshUser, sshPass);
}
@ -117,15 +118,15 @@ public class JschSshClientLiveTest {
temp = File.createTempFile("foo", "bar");
temp.deleteOnExit();
SshClient client = setupClient();
client.put(temp.getAbsolutePath(), Utils.toInputStream("rabbit"));
InputStream input = setupClient().get(temp.getAbsolutePath());
String contents = Utils.toStringAndClose(input);
client.put(temp.getAbsolutePath(), Payloads.newStringPayload("rabbit"));
Payload input = setupClient().get(temp.getAbsolutePath());
String contents = Utils.toStringAndClose(input.getInput());
assertEquals(contents, "rabbit");
}
public void testGetEtcPassword() throws IOException {
InputStream input = setupClient().get("/etc/passwd");
String contents = Utils.toStringAndClose(input);
Payload input = setupClient().get("/etc/passwd");
String contents = Utils.toStringAndClose(input.getInput());
assert contents.indexOf("root") >= 0 : "no root in " + contents;
}

View File

@ -18,10 +18,7 @@
*/
package org.jclouds.ssh.jsch.config;
import static org.testng.Assert.assertEquals;
import java.net.UnknownHostException;
import java.util.Map;
import org.jclouds.net.IPSocket;
import org.jclouds.ssh.SshClient;
@ -45,10 +42,5 @@ public class JschSshClientModuleTest {
SshClient.Factory factory = i.getInstance(SshClient.Factory.class);
SshClient connection = factory.create(new IPSocket("localhost", 22), "username", "password");
assert connection instanceof JschSshClient;
Map<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.functions.internal.CustomDeserializers;
import org.jclouds.http.HttpResponse;
import org.jclouds.http.Payloads;
import org.jclouds.http.functions.config.ParserModule;
import org.jclouds.io.Payloads;
import org.testng.annotations.Test;
import com.google.common.collect.Maps;

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

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

View File

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

View File

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

View File

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

View File

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

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