mirror of https://github.com/apache/jclouds.git
Issue 339: refactor so that scripts can be named
This commit is contained in:
parent
cf5080b550
commit
4dec489d42
|
@ -26,8 +26,11 @@ import static com.google.common.base.Preconditions.checkState;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
|
import org.jclouds.aws.cloudwatch.CloudWatchClient;
|
||||||
import org.jclouds.compute.options.TemplateOptions;
|
import org.jclouds.compute.options.TemplateOptions;
|
||||||
|
import org.jclouds.domain.Credentials;
|
||||||
import org.jclouds.io.Payload;
|
import org.jclouds.io.Payload;
|
||||||
|
import org.jclouds.scriptbuilder.domain.Statement;
|
||||||
import org.jclouds.util.Utils;
|
import org.jclouds.util.Utils;
|
||||||
|
|
||||||
import com.google.common.collect.ImmutableSet;
|
import com.google.common.collect.ImmutableSet;
|
||||||
|
@ -261,7 +264,7 @@ public class EC2TemplateOptions extends TemplateOptions {
|
||||||
// methods that only facilitate returning the correct object type
|
// methods that only facilitate returning the correct object type
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see TemplateOptions#blockOnPort
|
* {@inheritDoc}
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public EC2TemplateOptions blockOnPort(int port, int seconds) {
|
public EC2TemplateOptions blockOnPort(int port, int seconds) {
|
||||||
|
@ -269,12 +272,7 @@ public class EC2TemplateOptions extends TemplateOptions {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
* {@inheritDoc}
|
||||||
* 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
|
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public EC2TemplateOptions inboundPorts(int... ports) {
|
public EC2TemplateOptions inboundPorts(int... ports) {
|
||||||
|
@ -282,41 +280,41 @@ public class EC2TemplateOptions extends TemplateOptions {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see TemplateOptions#authorizePublicKey(String)
|
* {@inheritDoc}
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
@Deprecated
|
|
||||||
public EC2TemplateOptions authorizePublicKey(String publicKey) {
|
public EC2TemplateOptions authorizePublicKey(String publicKey) {
|
||||||
return EC2TemplateOptions.class.cast(super.authorizePublicKey(publicKey));
|
return EC2TemplateOptions.class.cast(super.authorizePublicKey(publicKey));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see TemplateOptions#authorizePublicKey(Payload)
|
* {@inheritDoc}
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
|
@Deprecated
|
||||||
public EC2TemplateOptions authorizePublicKey(Payload publicKey) {
|
public EC2TemplateOptions authorizePublicKey(Payload publicKey) {
|
||||||
return EC2TemplateOptions.class.cast(super.authorizePublicKey(publicKey));
|
return EC2TemplateOptions.class.cast(super.authorizePublicKey(publicKey));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see TemplateOptions#installPrivateKey(String)
|
* {@inheritDoc}
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
@Deprecated
|
|
||||||
public EC2TemplateOptions installPrivateKey(String privateKey) {
|
public EC2TemplateOptions installPrivateKey(String privateKey) {
|
||||||
return EC2TemplateOptions.class.cast(super.installPrivateKey(privateKey));
|
return EC2TemplateOptions.class.cast(super.installPrivateKey(privateKey));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see TemplateOptions#installPrivateKey(Payload)
|
* {@inheritDoc}
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
|
@Deprecated
|
||||||
public EC2TemplateOptions installPrivateKey(Payload privateKey) {
|
public EC2TemplateOptions installPrivateKey(Payload privateKey) {
|
||||||
return EC2TemplateOptions.class.cast(super.installPrivateKey(privateKey));
|
return EC2TemplateOptions.class.cast(super.installPrivateKey(privateKey));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see TemplateOptions#runScript(Payload)
|
* {@inheritDoc}
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public EC2TemplateOptions runScript(Payload script) {
|
public EC2TemplateOptions runScript(Payload script) {
|
||||||
|
@ -324,7 +322,7 @@ public class EC2TemplateOptions extends TemplateOptions {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see TemplateOptions#runScript(byte[])
|
* {@inheritDoc}
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
@Deprecated
|
@Deprecated
|
||||||
|
@ -333,13 +331,61 @@ public class EC2TemplateOptions extends TemplateOptions {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see TemplateOptions#withMetadata
|
* {@inheritDoc}
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public EC2TemplateOptions withMetadata() {
|
public EC2TemplateOptions withMetadata() {
|
||||||
return EC2TemplateOptions.class.cast(super.withMetadata());
|
return EC2TemplateOptions.class.cast(super.withMetadata());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public EC2TemplateOptions blockUntilRunning(boolean blockUntilRunning) {
|
||||||
|
return EC2TemplateOptions.class.cast(super.blockUntilRunning(blockUntilRunning));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public EC2TemplateOptions dontAuthorizePublicKey() {
|
||||||
|
return EC2TemplateOptions.class.cast(super.dontAuthorizePublicKey());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public EC2TemplateOptions nameTask(String name) {
|
||||||
|
return EC2TemplateOptions.class.cast(super.nameTask(name));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public EC2TemplateOptions runAsRoot(boolean runAsRoot) {
|
||||||
|
return EC2TemplateOptions.class.cast(super.runAsRoot(runAsRoot));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public EC2TemplateOptions runScript(Statement script) {
|
||||||
|
return EC2TemplateOptions.class.cast(super.runScript(script));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public EC2TemplateOptions withOverridingCredentials(Credentials overridingCredentials) {
|
||||||
|
return EC2TemplateOptions.class.cast(super.withOverridingCredentials(overridingCredentials));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return groupIds the user specified to run instances with, or zero length set to create an
|
* @return groupIds the user specified to run instances with, or zero length set to create an
|
||||||
* implicit group
|
* implicit group
|
||||||
|
|
|
@ -172,7 +172,7 @@ public class CloudApplicationArchitecturesEC2ClientLiveTest {
|
||||||
String script = new ScriptBuilder() // lamp install script
|
String script = new ScriptBuilder() // lamp install script
|
||||||
.addStatement(exec("runurl run.alestic.com/apt/upgrade"))//
|
.addStatement(exec("runurl run.alestic.com/apt/upgrade"))//
|
||||||
.addStatement(exec("runurl run.alestic.com/install/lamp"))//
|
.addStatement(exec("runurl run.alestic.com/install/lamp"))//
|
||||||
.build(OsFamily.UNIX);
|
.render(OsFamily.UNIX);
|
||||||
|
|
||||||
RunningInstance instance = null;
|
RunningInstance instance = null;
|
||||||
while (instance == null) {
|
while (instance == null) {
|
||||||
|
|
|
@ -299,7 +299,7 @@ public class EBSBootEC2ClientLiveTest {
|
||||||
"du -sk {varl}EBS_MOUNT_POINT{varr}", "echo size of source",
|
"du -sk {varl}EBS_MOUNT_POINT{varr}", "echo size of source",
|
||||||
"du -sk {varl}IMAGE_DIR{varr}", "rm -rf {varl}IMAGE_DIR{varr}/*",
|
"du -sk {varl}IMAGE_DIR{varr}", "rm -rf {varl}IMAGE_DIR{varr}/*",
|
||||||
"umount {varl}EBS_MOUNT_POINT{varr}", "echo " + SCRIPT_END)))
|
"umount {varl}EBS_MOUNT_POINT{varr}", "echo " + SCRIPT_END)))
|
||||||
.build(OsFamily.UNIX);
|
.render(OsFamily.UNIX);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(enabled = false, dependsOnMethods = "testCreateAndAttachVolume")
|
@Test(enabled = false, dependsOnMethods = "testCreateAndAttachVolume")
|
||||||
|
|
|
@ -44,7 +44,7 @@ import com.google.common.collect.ImmutableSet;
|
||||||
@Test(groups = "unit", testName = "ec2.RegionAndIdToImageTest")
|
@Test(groups = "unit", testName = "ec2.RegionAndIdToImageTest")
|
||||||
public class RegionAndIdToImageTest {
|
public class RegionAndIdToImageTest {
|
||||||
|
|
||||||
@SuppressWarnings({ "unchecked", "rawtypes" })
|
@SuppressWarnings({ "unchecked"})
|
||||||
@Test
|
@Test
|
||||||
public void testApply() {
|
public void testApply() {
|
||||||
|
|
||||||
|
@ -76,7 +76,7 @@ public class RegionAndIdToImageTest {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings({ "unchecked", "rawtypes" })
|
@SuppressWarnings({ "unchecked"})
|
||||||
@Test
|
@Test
|
||||||
public void testApplyNotFound() {
|
public void testApplyNotFound() {
|
||||||
|
|
||||||
|
|
|
@ -83,7 +83,7 @@ public class RunningInstanceToNodeMetadataTest {
|
||||||
|
|
||||||
DateService dateService = new SimpleDateFormatDateService();
|
DateService dateService = new SimpleDateFormatDateService();
|
||||||
|
|
||||||
@SuppressWarnings({ "unchecked", "rawtypes" })
|
@SuppressWarnings( { "unchecked" })
|
||||||
@Test
|
@Test
|
||||||
public void testApplyWithEBSWhenBootIsInstanceStoreAndAvailabilityZoneNotFound() throws UnknownHostException {
|
public void testApplyWithEBSWhenBootIsInstanceStoreAndAvailabilityZoneNotFound() throws UnknownHostException {
|
||||||
EC2Client client = createMock(EC2Client.class);
|
EC2Client client = createMock(EC2Client.class);
|
||||||
|
@ -129,12 +129,9 @@ public class RunningInstanceToNodeMetadataTest {
|
||||||
|
|
||||||
expect(instance.getInstanceType()).andReturn(InstanceType.M1_SMALL).atLeastOnce();
|
expect(instance.getInstanceType()).andReturn(InstanceType.M1_SMALL).atLeastOnce();
|
||||||
expect(instance.getEbsBlockDevices()).andReturn(
|
expect(instance.getEbsBlockDevices()).andReturn(
|
||||||
ImmutableMap.<String, EbsBlockDevice> of(
|
ImmutableMap.<String, EbsBlockDevice> of("/dev/sdg", new EbsBlockDevice("vol-1f20d376",
|
||||||
"/dev/sdg",
|
Attachment.Status.ATTACHED, dateService.iso8601DateParse("2009-12-11T16:32:46.000Z"), false),
|
||||||
new EbsBlockDevice("vol-1f20d376", Attachment.Status.ATTACHED, dateService
|
"/dev/sdj", new EbsBlockDevice("vol-c0eb78aa", Attachment.Status.ATTACHED, dateService
|
||||||
.iso8601DateParse("2009-12-11T16:32:46.000Z"), false),
|
|
||||||
"/dev/sdj",
|
|
||||||
new EbsBlockDevice("vol-c0eb78aa", Attachment.Status.ATTACHED, dateService
|
|
||||||
.iso8601DateParse("2010-06-17T10:43:28.000Z"), false)));
|
.iso8601DateParse("2010-06-17T10:43:28.000Z"), false)));
|
||||||
expect(instance.getRootDeviceType()).andReturn(RootDeviceType.INSTANCE_STORE);
|
expect(instance.getRootDeviceType()).andReturn(RootDeviceType.INSTANCE_STORE);
|
||||||
expect(instance.getRootDeviceName()).andReturn(null).atLeastOnce();
|
expect(instance.getRootDeviceName()).andReturn(null).atLeastOnce();
|
||||||
|
@ -160,8 +157,8 @@ public class RunningInstanceToNodeMetadataTest {
|
||||||
assertEquals(metadata.getHardware().getProviderId(), "m1.small");
|
assertEquals(metadata.getHardware().getProviderId(), "m1.small");
|
||||||
assertEquals(metadata.getHardware().getProcessors(), ImmutableList.<Processor> of(new Processor(1.0, 1.0)));
|
assertEquals(metadata.getHardware().getProcessors(), ImmutableList.<Processor> of(new Processor(1.0, 1.0)));
|
||||||
assertEquals(metadata.getHardware().getRam(), 1740);
|
assertEquals(metadata.getHardware().getRam(), 1740);
|
||||||
assertEquals(metadata.getHardware().getVolumes(),
|
assertEquals(metadata.getHardware().getVolumes(), ImmutableList.<Volume> of(new VolumeImpl(null,
|
||||||
ImmutableList.<Volume> of(new VolumeImpl(null, Volume.Type.LOCAL, 10.0f, "/dev/sda1", true, false),//
|
Volume.Type.LOCAL, 10.0f, "/dev/sda1", true, false),//
|
||||||
new VolumeImpl(null, Volume.Type.LOCAL, 150.0f, "/dev/sda2", false, false),//
|
new VolumeImpl(null, Volume.Type.LOCAL, 150.0f, "/dev/sda2", false, false),//
|
||||||
new VolumeImpl("vol-1f20d376", Volume.Type.SAN, null, "/dev/sdg", false, true),//
|
new VolumeImpl("vol-1f20d376", Volume.Type.SAN, null, "/dev/sdg", false, true),//
|
||||||
new VolumeImpl("vol-c0eb78aa", Volume.Type.SAN, null, "/dev/sdj", false, true)));
|
new VolumeImpl("vol-c0eb78aa", Volume.Type.SAN, null, "/dev/sdj", false, true)));
|
||||||
|
@ -178,7 +175,7 @@ public class RunningInstanceToNodeMetadataTest {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings({ "unchecked", "rawtypes" })
|
@SuppressWarnings( { "unchecked" })
|
||||||
@Test
|
@Test
|
||||||
public void testApplyForNovaWhereNullAvailabilityZoneIpAddressNoGroups() throws UnknownHostException {
|
public void testApplyForNovaWhereNullAvailabilityZoneIpAddressNoGroups() throws UnknownHostException {
|
||||||
EC2Client client = createMock(EC2Client.class);
|
EC2Client client = createMock(EC2Client.class);
|
||||||
|
@ -246,8 +243,8 @@ public class RunningInstanceToNodeMetadataTest {
|
||||||
assertEquals(metadata.getHardware().getProviderId(), "m1.small");
|
assertEquals(metadata.getHardware().getProviderId(), "m1.small");
|
||||||
assertEquals(metadata.getHardware().getProcessors(), ImmutableList.<Processor> of(new Processor(1.0, 1.0)));
|
assertEquals(metadata.getHardware().getProcessors(), ImmutableList.<Processor> of(new Processor(1.0, 1.0)));
|
||||||
assertEquals(metadata.getHardware().getRam(), 1740);
|
assertEquals(metadata.getHardware().getRam(), 1740);
|
||||||
assertEquals(metadata.getHardware().getVolumes(),
|
assertEquals(metadata.getHardware().getVolumes(), ImmutableList.<Volume> of(new VolumeImpl(null,
|
||||||
ImmutableList.<Volume> of(new VolumeImpl(null, Volume.Type.LOCAL, 10.0f, "/dev/sda1", true, false),//
|
Volume.Type.LOCAL, 10.0f, "/dev/sda1", true, false),//
|
||||||
new VolumeImpl(null, Volume.Type.LOCAL, 150.0f, "/dev/sda2", false, false)));
|
new VolumeImpl(null, Volume.Type.LOCAL, 150.0f, "/dev/sda2", false, false)));
|
||||||
|
|
||||||
assertEquals(metadata.getCredentials(), new Credentials("user", null));
|
assertEquals(metadata.getCredentials(), new Credentials("user", null));
|
||||||
|
@ -262,7 +259,7 @@ public class RunningInstanceToNodeMetadataTest {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings({ "unchecked", "rawtypes" })
|
@SuppressWarnings( { "unchecked" })
|
||||||
@Test
|
@Test
|
||||||
public void testApplyWhereUnknownInstanceType() throws UnknownHostException {
|
public void testApplyWhereUnknownInstanceType() throws UnknownHostException {
|
||||||
EC2Client client = createMock(EC2Client.class);
|
EC2Client client = createMock(EC2Client.class);
|
||||||
|
@ -337,7 +334,7 @@ public class RunningInstanceToNodeMetadataTest {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings({ "unchecked", "rawtypes" })
|
@SuppressWarnings( { "unchecked" })
|
||||||
@Test
|
@Test
|
||||||
public void testApplyForNovaWhereImageNotFound() throws UnknownHostException {
|
public void testApplyForNovaWhereImageNotFound() throws UnknownHostException {
|
||||||
EC2Client client = createMock(EC2Client.class);
|
EC2Client client = createMock(EC2Client.class);
|
||||||
|
@ -404,8 +401,8 @@ public class RunningInstanceToNodeMetadataTest {
|
||||||
assertEquals(metadata.getHardware().getProviderId(), "m1.small");
|
assertEquals(metadata.getHardware().getProviderId(), "m1.small");
|
||||||
assertEquals(metadata.getHardware().getProcessors(), ImmutableList.<Processor> of(new Processor(1.0, 1.0)));
|
assertEquals(metadata.getHardware().getProcessors(), ImmutableList.<Processor> of(new Processor(1.0, 1.0)));
|
||||||
assertEquals(metadata.getHardware().getRam(), 1740);
|
assertEquals(metadata.getHardware().getRam(), 1740);
|
||||||
assertEquals(metadata.getHardware().getVolumes(),
|
assertEquals(metadata.getHardware().getVolumes(), ImmutableList.<Volume> of(new VolumeImpl(null,
|
||||||
ImmutableList.<Volume> of(new VolumeImpl(null, Volume.Type.LOCAL, 10.0f, "/dev/sda1", true, false),//
|
Volume.Type.LOCAL, 10.0f, "/dev/sda1", true, false),//
|
||||||
new VolumeImpl(null, Volume.Type.LOCAL, 150.0f, "/dev/sda2", false, false)));
|
new VolumeImpl(null, Volume.Type.LOCAL, 150.0f, "/dev/sda2", false, false)));
|
||||||
|
|
||||||
assertEquals(metadata.getCredentials(), new Credentials("root", null));
|
assertEquals(metadata.getCredentials(), new Credentials("root", null));
|
||||||
|
@ -734,7 +731,7 @@ public class RunningInstanceToNodeMetadataTest {
|
||||||
verify(instance);
|
verify(instance);
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings({ "unchecked", "rawtypes" })
|
@SuppressWarnings( { "unchecked" })
|
||||||
@Test
|
@Test
|
||||||
public void testApplyWithKeyPairCreatesTagOfParsedSecurityGroupAndCredentialsBasedOnIt() throws UnknownHostException {
|
public void testApplyWithKeyPairCreatesTagOfParsedSecurityGroupAndCredentialsBasedOnIt() throws UnknownHostException {
|
||||||
EC2Client client = createMock(EC2Client.class);
|
EC2Client client = createMock(EC2Client.class);
|
||||||
|
@ -808,7 +805,7 @@ public class RunningInstanceToNodeMetadataTest {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings({ "unchecked", "rawtypes" })
|
@SuppressWarnings( { "unchecked" })
|
||||||
@Test
|
@Test
|
||||||
public void testApplyWithTwoSecurityGroups() throws UnknownHostException {
|
public void testApplyWithTwoSecurityGroups() throws UnknownHostException {
|
||||||
EC2Client client = createMock(EC2Client.class);
|
EC2Client client = createMock(EC2Client.class);
|
||||||
|
|
|
@ -32,7 +32,6 @@ import static org.testng.Assert.assertEquals;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
import org.jclouds.compute.options.TemplateOptions;
|
import org.jclouds.compute.options.TemplateOptions;
|
||||||
import org.jclouds.util.Utils;
|
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
import com.google.common.collect.ImmutableSet;
|
import com.google.common.collect.ImmutableSet;
|
||||||
|
@ -194,19 +193,17 @@ public class EC2TemplateOptionsTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
// superclass tests
|
// superclass tests
|
||||||
@SuppressWarnings("deprecation")
|
|
||||||
@Test(expectedExceptions = IllegalArgumentException.class)
|
@Test(expectedExceptions = IllegalArgumentException.class)
|
||||||
public void testinstallPrivateKeyBadFormat() {
|
public void testinstallPrivateKeyBadFormat() {
|
||||||
EC2TemplateOptions options = new EC2TemplateOptions();
|
EC2TemplateOptions options = new EC2TemplateOptions();
|
||||||
options.installPrivateKey("whompy");
|
options.installPrivateKey("whompy");
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("deprecation")
|
|
||||||
@Test
|
@Test
|
||||||
public void testinstallPrivateKey() throws IOException {
|
public void testinstallPrivateKey() throws IOException {
|
||||||
EC2TemplateOptions options = new EC2TemplateOptions();
|
EC2TemplateOptions options = new EC2TemplateOptions();
|
||||||
options.installPrivateKey("-----BEGIN RSA PRIVATE KEY-----");
|
options.installPrivateKey("-----BEGIN RSA PRIVATE KEY-----");
|
||||||
assertEquals(Utils.toStringAndClose(options.getPrivateKey().getInput()), "-----BEGIN RSA PRIVATE KEY-----");
|
assertEquals(options.getPrivateKey(), "-----BEGIN RSA PRIVATE KEY-----");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -218,7 +215,7 @@ public class EC2TemplateOptionsTest {
|
||||||
@Test
|
@Test
|
||||||
public void testinstallPrivateKeyStatic() throws IOException {
|
public void testinstallPrivateKeyStatic() throws IOException {
|
||||||
EC2TemplateOptions options = installPrivateKey("-----BEGIN RSA PRIVATE KEY-----");
|
EC2TemplateOptions options = installPrivateKey("-----BEGIN RSA PRIVATE KEY-----");
|
||||||
assertEquals(Utils.toStringAndClose(options.getPrivateKey().getInput()), "-----BEGIN RSA PRIVATE KEY-----");
|
assertEquals(options.getPrivateKey(), "-----BEGIN RSA PRIVATE KEY-----");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expectedExceptions = NullPointerException.class)
|
@Test(expectedExceptions = NullPointerException.class)
|
||||||
|
@ -226,19 +223,17 @@ public class EC2TemplateOptionsTest {
|
||||||
installPrivateKey(null);
|
installPrivateKey(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("deprecation")
|
|
||||||
@Test(expectedExceptions = IllegalArgumentException.class)
|
@Test(expectedExceptions = IllegalArgumentException.class)
|
||||||
public void testauthorizePublicKeyBadFormat() {
|
public void testauthorizePublicKeyBadFormat() {
|
||||||
EC2TemplateOptions options = new EC2TemplateOptions();
|
EC2TemplateOptions options = new EC2TemplateOptions();
|
||||||
options.authorizePublicKey("whompy");
|
options.authorizePublicKey("whompy");
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("deprecation")
|
|
||||||
@Test
|
@Test
|
||||||
public void testauthorizePublicKey() throws IOException {
|
public void testauthorizePublicKey() throws IOException {
|
||||||
EC2TemplateOptions options = new EC2TemplateOptions();
|
EC2TemplateOptions options = new EC2TemplateOptions();
|
||||||
options.authorizePublicKey("ssh-rsa");
|
options.authorizePublicKey("ssh-rsa");
|
||||||
assertEquals(Utils.toStringAndClose(options.getPublicKey().getInput()), "ssh-rsa");
|
assertEquals(options.getPublicKey(), "ssh-rsa");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -250,7 +245,7 @@ public class EC2TemplateOptionsTest {
|
||||||
@Test
|
@Test
|
||||||
public void testauthorizePublicKeyStatic() throws IOException {
|
public void testauthorizePublicKeyStatic() throws IOException {
|
||||||
EC2TemplateOptions options = authorizePublicKey("ssh-rsa");
|
EC2TemplateOptions options = authorizePublicKey("ssh-rsa");
|
||||||
assertEquals(Utils.toStringAndClose(options.getPublicKey().getInput()), "ssh-rsa");
|
assertEquals(options.getPublicKey(), "ssh-rsa");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expectedExceptions = NullPointerException.class)
|
@Test(expectedExceptions = NullPointerException.class)
|
||||||
|
|
|
@ -90,7 +90,7 @@ public class EC2RunNodesAndAddToSetStrategyTest {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings({ "unchecked", "rawtypes" })
|
@SuppressWarnings({ "unchecked"})
|
||||||
private void assertRegionAndZoneForLocation(Location location, String region, String zone) {
|
private void assertRegionAndZoneForLocation(Location location, String region, String zone) {
|
||||||
String imageId = "ami1";
|
String imageId = "ami1";
|
||||||
String instanceCreatedId = "instance1";
|
String instanceCreatedId = "instance1";
|
||||||
|
|
|
@ -192,9 +192,10 @@ public class PlacementGroupClientLiveTest {
|
||||||
assertEquals(template.getHardware().getProviderId(), InstanceType.CC1_4XLARGE);
|
assertEquals(template.getHardware().getProviderId(), InstanceType.CC1_4XLARGE);
|
||||||
assertEquals(template.getImage().getId(), "us-east-1/ami-7ea24a17");
|
assertEquals(template.getImage().getId(), "us-east-1/ami-7ea24a17");
|
||||||
|
|
||||||
template.getOptions().installPrivateKey(newStringPayload(keyPair.get("private"))).authorizePublicKey(
|
template.getOptions().installPrivateKey(keyPair.get("private")).authorizePublicKey(keyPair.get("public"))
|
||||||
newStringPayload(keyPair.get("public"))).runScript(
|
.runScript(
|
||||||
newStringPayload(BaseComputeServiceLiveTest.buildScript(template.getImage().getOperatingSystem())));
|
newStringPayload(BaseComputeServiceLiveTest.buildScript(template.getImage()
|
||||||
|
.getOperatingSystem())));
|
||||||
|
|
||||||
String tag = PREFIX + "cccluster";
|
String tag = PREFIX + "cccluster";
|
||||||
context.getComputeService().destroyNodesMatching(NodePredicates.withTag(tag));
|
context.getComputeService().destroyNodesMatching(NodePredicates.withTag(tag));
|
||||||
|
|
|
@ -160,7 +160,7 @@ public class MainApp {
|
||||||
.addStatement(exec("runurl run.alestic.com/apt/upgrade"))//
|
.addStatement(exec("runurl run.alestic.com/apt/upgrade"))//
|
||||||
.addStatement(exec("runurl run.alestic.com/install/lamp"))//
|
.addStatement(exec("runurl run.alestic.com/install/lamp"))//
|
||||||
.addStatement(exec("apt-get -y install openjdk-6-jdk"))// no license agreement!
|
.addStatement(exec("apt-get -y install openjdk-6-jdk"))// no license agreement!
|
||||||
.build(OsFamily.UNIX);
|
.render(OsFamily.UNIX);
|
||||||
|
|
||||||
System.out.printf("%d: running instance%n", System.currentTimeMillis());
|
System.out.printf("%d: running instance%n", System.currentTimeMillis());
|
||||||
Reservation<? extends RunningInstance> reservation = client.getInstanceServices().runInstancesInRegion(null, null, // allow
|
Reservation<? extends RunningInstance> reservation = client.getInstanceServices().runInstancesInRegion(null, null, // allow
|
||||||
|
|
|
@ -1,71 +0,0 @@
|
||||||
/**
|
|
||||||
*
|
|
||||||
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
|
|
||||||
*
|
|
||||||
* ====================================================================
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
* ====================================================================
|
|
||||||
*/
|
|
||||||
|
|
||||||
package org.jclouds.compute.callables;
|
|
||||||
|
|
||||||
import static com.google.common.base.Preconditions.checkNotNull;
|
|
||||||
|
|
||||||
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;
|
|
||||||
|
|
||||||
import com.google.common.collect.Iterables;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @author Adrian Cole
|
|
||||||
*/
|
|
||||||
public class AuthorizeRSAPublicKey implements SshCallable<ExecResponse> {
|
|
||||||
private SshClient ssh;
|
|
||||||
private final NodeMetadata node;
|
|
||||||
private final Payload publicKey;
|
|
||||||
|
|
||||||
private Logger logger = Logger.NULL;
|
|
||||||
|
|
||||||
public AuthorizeRSAPublicKey(NodeMetadata node, Payload publicKey) {
|
|
||||||
this.node = checkNotNull(node, "node");
|
|
||||||
this.publicKey = checkNotNull(publicKey, "publicKey");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public ExecResponse call() throws Exception {
|
|
||||||
ssh.exec("mkdir .ssh");
|
|
||||||
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());
|
|
||||||
return returnVal;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setConnection(SshClient ssh, Logger logger) {
|
|
||||||
this.logger = checkNotNull(logger, "logger");
|
|
||||||
this.ssh = checkNotNull(ssh, "ssh");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public NodeMetadata getNode() {
|
|
||||||
return node;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -0,0 +1,102 @@
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||||
|
*
|
||||||
|
* ====================================================================
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
* ====================================================================
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.jclouds.compute.callables;
|
||||||
|
|
||||||
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
|
|
||||||
|
import org.jclouds.compute.domain.NodeMetadata;
|
||||||
|
import org.jclouds.compute.util.ComputeServiceUtils;
|
||||||
|
import org.jclouds.compute.util.ComputeServiceUtils.SshCallable;
|
||||||
|
import org.jclouds.io.Payloads;
|
||||||
|
import org.jclouds.logging.Logger;
|
||||||
|
import org.jclouds.scriptbuilder.domain.OsFamily;
|
||||||
|
import org.jclouds.scriptbuilder.domain.Statement;
|
||||||
|
import org.jclouds.ssh.ExecResponse;
|
||||||
|
import org.jclouds.ssh.SshClient;
|
||||||
|
|
||||||
|
import com.google.common.collect.Iterables;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author Adrian Cole
|
||||||
|
*/
|
||||||
|
public class InitAndStartScriptOnNode implements SshCallable<ExecResponse> {
|
||||||
|
protected SshClient ssh;
|
||||||
|
protected final NodeMetadata node;
|
||||||
|
protected final String scriptName;
|
||||||
|
protected final Statement script;
|
||||||
|
protected final boolean runAsRoot;
|
||||||
|
protected Logger logger = Logger.NULL;
|
||||||
|
|
||||||
|
public InitAndStartScriptOnNode(NodeMetadata node, String scriptName, Statement script, boolean runAsRoot) {
|
||||||
|
this.node = checkNotNull(node, "node");
|
||||||
|
this.scriptName = checkNotNull(scriptName, "scriptName");
|
||||||
|
this.script = checkNotNull(script, "script");
|
||||||
|
this.runAsRoot = runAsRoot;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ExecResponse call() {
|
||||||
|
ssh.put(scriptName, Payloads.newPayload(script.render(OsFamily.UNIX)));
|
||||||
|
ExecResponse returnVal = ssh.exec("chmod 755 " + scriptName);
|
||||||
|
returnVal = ssh.exec("./" + scriptName + " init");
|
||||||
|
logger.debug("<< initialized(%d)", returnVal.getExitCode());
|
||||||
|
|
||||||
|
String command = (runAsRoot) ? startScriptAsRoot() : startScriptAsDefaultUser();
|
||||||
|
returnVal = runCommand(command);
|
||||||
|
logger.debug("<< start(%d)", returnVal.getExitCode());
|
||||||
|
return returnVal;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected ExecResponse runCommand(String command) {
|
||||||
|
ExecResponse returnVal;
|
||||||
|
logger.debug(">> running [%s] as %s@%s", command.replace(node.getCredentials().credential, "XXXXX"), node
|
||||||
|
.getCredentials().identity, Iterables.get(node.getPublicAddresses(), 0));
|
||||||
|
returnVal = ssh.exec(command);
|
||||||
|
return returnVal;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setConnection(SshClient ssh, Logger logger) {
|
||||||
|
this.logger = checkNotNull(logger, "logger");
|
||||||
|
this.ssh = checkNotNull(ssh, "ssh");
|
||||||
|
}
|
||||||
|
|
||||||
|
protected String startScriptAsRoot() {
|
||||||
|
String command;
|
||||||
|
if (node.getCredentials().identity.equals("root")) {
|
||||||
|
command = "./" + scriptName + " start";
|
||||||
|
} else if (ComputeServiceUtils.isKeyAuth(node)) {
|
||||||
|
command = "sudo ./" + scriptName + " start";
|
||||||
|
} else {
|
||||||
|
command = String.format("echo '%s'|sudo -S ./%s", node.getCredentials().credential, scriptName + " start");
|
||||||
|
}
|
||||||
|
return command;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected String startScriptAsDefaultUser() {
|
||||||
|
return "./" + scriptName + " start";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public NodeMetadata getNode() {
|
||||||
|
return node;
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,68 +0,0 @@
|
||||||
/**
|
|
||||||
*
|
|
||||||
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
|
|
||||||
*
|
|
||||||
* ====================================================================
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
* ====================================================================
|
|
||||||
*/
|
|
||||||
|
|
||||||
package org.jclouds.compute.callables;
|
|
||||||
|
|
||||||
import static com.google.common.base.Preconditions.checkNotNull;
|
|
||||||
|
|
||||||
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;
|
|
||||||
|
|
||||||
import com.google.common.collect.Iterables;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @author Adrian Cole
|
|
||||||
*/
|
|
||||||
public class InstallRSAPrivateKey implements SshCallable<ExecResponse> {
|
|
||||||
private SshClient ssh;
|
|
||||||
private final NodeMetadata node;
|
|
||||||
private final Payload privateKey;
|
|
||||||
|
|
||||||
private Logger logger = Logger.NULL;
|
|
||||||
|
|
||||||
public InstallRSAPrivateKey(NodeMetadata node, Payload privateKey) {
|
|
||||||
this.node = checkNotNull(node, "node");
|
|
||||||
this.privateKey = checkNotNull(privateKey, "privateKey");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public ExecResponse call() throws Exception {
|
|
||||||
ssh.exec("mkdir .ssh");
|
|
||||||
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");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setConnection(SshClient ssh, Logger logger) {
|
|
||||||
this.logger = checkNotNull(logger, "logger");
|
|
||||||
this.ssh = checkNotNull(ssh, "ssh");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public NodeMetadata getNode() {
|
|
||||||
return node;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -19,86 +19,46 @@
|
||||||
|
|
||||||
package org.jclouds.compute.callables;
|
package org.jclouds.compute.callables;
|
||||||
|
|
||||||
import static com.google.common.base.Preconditions.checkNotNull;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
|
||||||
import javax.inject.Named;
|
import javax.inject.Named;
|
||||||
|
|
||||||
import org.jclouds.compute.domain.NodeMetadata;
|
import org.jclouds.compute.domain.NodeMetadata;
|
||||||
import org.jclouds.compute.predicates.ScriptStatusReturnsZero.CommandUsingClient;
|
import org.jclouds.compute.predicates.ScriptStatusReturnsZero.CommandUsingClient;
|
||||||
import org.jclouds.compute.util.ComputeServiceUtils;
|
|
||||||
import org.jclouds.compute.util.ComputeServiceUtils.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.InitBuilder;
|
||||||
import org.jclouds.scriptbuilder.domain.OsFamily;
|
|
||||||
import org.jclouds.scriptbuilder.domain.Statement;
|
import org.jclouds.scriptbuilder.domain.Statement;
|
||||||
import org.jclouds.scriptbuilder.domain.Statements;
|
|
||||||
import org.jclouds.ssh.ExecResponse;
|
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.Predicate;
|
||||||
import com.google.common.base.Splitter;
|
|
||||||
import com.google.common.collect.ImmutableList;
|
|
||||||
import com.google.common.collect.Iterables;
|
import com.google.common.collect.Iterables;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @author Adrian Cole
|
* @author Adrian Cole
|
||||||
*/
|
*/
|
||||||
public class RunScriptOnNode implements SshCallable<ExecResponse> {
|
public class RunScriptOnNode extends InitAndStartScriptOnNode {
|
||||||
private SshClient ssh;
|
|
||||||
protected final Predicate<CommandUsingClient> runScriptNotRunning;
|
protected final Predicate<CommandUsingClient> runScriptNotRunning;
|
||||||
private final NodeMetadata node;
|
|
||||||
private final String scriptName;
|
|
||||||
private final Payload script;
|
|
||||||
private final boolean runAsRoot;
|
|
||||||
private Logger logger = Logger.NULL;
|
|
||||||
|
|
||||||
public RunScriptOnNode(@Named("SCRIPT_COMPLETE") Predicate<CommandUsingClient> runScriptNotRunning,
|
public RunScriptOnNode(@Named("SCRIPT_COMPLETE") Predicate<CommandUsingClient> runScriptNotRunning,
|
||||||
NodeMetadata node, String scriptName, Payload script) {
|
NodeMetadata node, String scriptName, Statement script) {
|
||||||
this(runScriptNotRunning, node, scriptName, script, true);
|
this(runScriptNotRunning, node, scriptName, script, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public RunScriptOnNode(@Named("SCRIPT_COMPLETE") Predicate<CommandUsingClient> runScriptNotRunning,
|
public RunScriptOnNode(@Named("SCRIPT_COMPLETE") Predicate<CommandUsingClient> runScriptNotRunning,
|
||||||
NodeMetadata node, String scriptName, Payload script, boolean runAsRoot) {
|
NodeMetadata node, String scriptName, Statement script, boolean runAsRoot) {
|
||||||
|
super(node, scriptName, createInitScript(scriptName, script), runAsRoot);
|
||||||
this.runScriptNotRunning = runScriptNotRunning;
|
this.runScriptNotRunning = runScriptNotRunning;
|
||||||
this.node = checkNotNull(node, "node");
|
|
||||||
this.scriptName = checkNotNull(scriptName, "scriptName");
|
|
||||||
this.script = createRunScript(scriptName, script);
|
|
||||||
this.runAsRoot = runAsRoot;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Payload createRunScript(String scriptName, Payload script) {
|
public static Statement createInitScript(String scriptName, Statement script) {
|
||||||
String path = "/tmp/" + scriptName;
|
String path = "/tmp/" + scriptName;
|
||||||
InitBuilder initBuilder = new InitBuilder(scriptName, path, path, Collections.<String, String> emptyMap(),
|
return new InitBuilder(scriptName, path, path, Collections.<String, String> emptyMap(), Collections
|
||||||
ImmutableList.<Statement> of(Statements.interpret(splitOnNewlines(script))));
|
.singleton(script));
|
||||||
return Payloads.newByteArrayPayload(initBuilder.build(OsFamily.UNIX).getBytes());
|
|
||||||
}
|
|
||||||
|
|
||||||
static String[] splitOnNewlines(Payload script) {
|
|
||||||
try {
|
|
||||||
String asString = Utils.toStringAndClose(checkNotNull(script, "script").getInput());
|
|
||||||
return Iterables.toArray(Splitter.on("\n").split(asString), String.class);
|
|
||||||
} catch (IOException e) {
|
|
||||||
throw new RuntimeException(e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ExecResponse call() throws Exception {
|
public ExecResponse call() {
|
||||||
ssh.put(scriptName, script);
|
ExecResponse returnVal = super.call();
|
||||||
ExecResponse returnVal = ssh.exec("chmod 755 " + scriptName);
|
|
||||||
returnVal = ssh.exec("./" + scriptName + " init");
|
|
||||||
logger.debug("<< initialized(%d)", returnVal.getExitCode());
|
|
||||||
|
|
||||||
String command = (runAsRoot) ? runScriptAsRoot() : runScriptAsDefaultUser();
|
|
||||||
returnVal = runCommand(command);
|
|
||||||
logger.debug("<< start(%d)", returnVal.getExitCode());
|
|
||||||
|
|
||||||
boolean complete = runScriptNotRunning.apply(new CommandUsingClient("./" + scriptName + " status", ssh));
|
boolean complete = runScriptNotRunning.apply(new CommandUsingClient("./" + scriptName + " status", ssh));
|
||||||
logger.debug("<< complete(%s)", complete);
|
logger.debug("<< complete(%s)", complete);
|
||||||
|
@ -110,39 +70,4 @@ public class RunScriptOnNode implements SshCallable<ExecResponse> {
|
||||||
}
|
}
|
||||||
return returnVal;
|
return returnVal;
|
||||||
}
|
}
|
||||||
|
|
||||||
private ExecResponse runCommand(String command) {
|
|
||||||
ExecResponse returnVal;
|
|
||||||
logger.debug(">> running [%s] as %s@%s", command.replace(node.getCredentials().credential, "XXXXX"), node
|
|
||||||
.getCredentials().identity, Iterables.get(node.getPublicAddresses(), 0));
|
|
||||||
returnVal = ssh.exec(command);
|
|
||||||
return returnVal;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setConnection(SshClient ssh, Logger logger) {
|
|
||||||
this.logger = checkNotNull(logger, "logger");
|
|
||||||
this.ssh = checkNotNull(ssh, "ssh");
|
|
||||||
}
|
|
||||||
|
|
||||||
private String runScriptAsRoot() {
|
|
||||||
String command;
|
|
||||||
if (node.getCredentials().identity.equals("root")) {
|
|
||||||
command = "./" + scriptName + " start";
|
|
||||||
} else if (ComputeServiceUtils.isKeyAuth(node)) {
|
|
||||||
command = "sudo ./" + scriptName + " start";
|
|
||||||
} else {
|
|
||||||
command = String.format("echo '%s'|sudo -S ./%s", node.getCredentials().credential, scriptName + " start");
|
|
||||||
}
|
|
||||||
return command;
|
|
||||||
}
|
|
||||||
|
|
||||||
private String runScriptAsDefaultUser() {
|
|
||||||
return "./" + scriptName + " start";
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public NodeMetadata getNode() {
|
|
||||||
return node;
|
|
||||||
}
|
|
||||||
}
|
}
|
|
@ -45,7 +45,6 @@ import org.jclouds.compute.ComputeService;
|
||||||
import org.jclouds.compute.ComputeServiceContext;
|
import org.jclouds.compute.ComputeServiceContext;
|
||||||
import org.jclouds.compute.RunNodesException;
|
import org.jclouds.compute.RunNodesException;
|
||||||
import org.jclouds.compute.RunScriptOnNodesException;
|
import org.jclouds.compute.RunScriptOnNodesException;
|
||||||
import org.jclouds.compute.callables.RunScriptOnNode;
|
|
||||||
import org.jclouds.compute.domain.ComputeMetadata;
|
import org.jclouds.compute.domain.ComputeMetadata;
|
||||||
import org.jclouds.compute.domain.Hardware;
|
import org.jclouds.compute.domain.Hardware;
|
||||||
import org.jclouds.compute.domain.Image;
|
import org.jclouds.compute.domain.Image;
|
||||||
|
@ -63,12 +62,14 @@ import org.jclouds.compute.strategy.ListNodesStrategy;
|
||||||
import org.jclouds.compute.strategy.RebootNodeStrategy;
|
import org.jclouds.compute.strategy.RebootNodeStrategy;
|
||||||
import org.jclouds.compute.strategy.RunNodesAndAddToSetStrategy;
|
import org.jclouds.compute.strategy.RunNodesAndAddToSetStrategy;
|
||||||
import org.jclouds.compute.util.ComputeUtils;
|
import org.jclouds.compute.util.ComputeUtils;
|
||||||
|
import org.jclouds.domain.Credentials;
|
||||||
import org.jclouds.domain.Location;
|
import org.jclouds.domain.Location;
|
||||||
import org.jclouds.io.Payload;
|
import org.jclouds.io.Payload;
|
||||||
import org.jclouds.logging.Logger;
|
import org.jclouds.logging.Logger;
|
||||||
import org.jclouds.predicates.RetryablePredicate;
|
import org.jclouds.predicates.RetryablePredicate;
|
||||||
|
import org.jclouds.scriptbuilder.domain.Statements;
|
||||||
import org.jclouds.ssh.ExecResponse;
|
import org.jclouds.ssh.ExecResponse;
|
||||||
import org.jclouds.ssh.SshClient;
|
import org.jclouds.util.Utils;
|
||||||
|
|
||||||
import com.google.common.base.Function;
|
import com.google.common.base.Function;
|
||||||
import com.google.common.base.Predicate;
|
import com.google.common.base.Predicate;
|
||||||
|
@ -151,6 +152,8 @@ public class BaseComputeService implements ComputeService {
|
||||||
throws RunNodesException {
|
throws RunNodesException {
|
||||||
checkArgument(tag.indexOf('-') == -1, "tag cannot contain hyphens");
|
checkArgument(tag.indexOf('-') == -1, "tag cannot contain hyphens");
|
||||||
checkNotNull(template.getLocation(), "location");
|
checkNotNull(template.getLocation(), "location");
|
||||||
|
if (template.getOptions().getTaskName() == null && template.getOptions().getRunScript() != null)
|
||||||
|
template.getOptions().nameTask("bootstrap");
|
||||||
logger.debug(">> running %d node%s tag(%s) location(%s) image(%s) hardwareProfile(%s) options(%s)", count,
|
logger.debug(">> running %d node%s tag(%s) location(%s) image(%s) hardwareProfile(%s) options(%s)", count,
|
||||||
count > 1 ? "s" : "", tag, template.getLocation().getId(), template.getImage().getId(), template
|
count > 1 ? "s" : "", tag, template.getLocation().getId(), template.getImage().getId(), template
|
||||||
.getHardware().getId(), template.getOptions());
|
.getHardware().getId(), template.getOptions());
|
||||||
|
@ -350,14 +353,19 @@ public class BaseComputeService implements ComputeService {
|
||||||
@Override
|
@Override
|
||||||
public Map<NodeMetadata, ExecResponse> runScriptOnNodesMatching(Predicate<NodeMetadata> filter,
|
public Map<NodeMetadata, ExecResponse> runScriptOnNodesMatching(Predicate<NodeMetadata> filter,
|
||||||
final Payload runScript, @Nullable final RunScriptOptions options) throws RunScriptOnNodesException {
|
final Payload runScript, @Nullable final RunScriptOptions options) throws RunScriptOnNodesException {
|
||||||
Iterable<NodeMetadata> nodes = verifyParametersAndListNodes(filter, runScript, (options != null) ? options
|
|
||||||
: RunScriptOptions.NONE);
|
checkNotNull(filter, "Filter must be provided");
|
||||||
|
checkNotNull(runScript, "runScript");
|
||||||
|
checkNotNull(options, "options");
|
||||||
|
if (options.getTaskName() == null)
|
||||||
|
options.nameTask("jclouds-script-" + System.currentTimeMillis());
|
||||||
|
|
||||||
|
Iterable<? extends NodeMetadata> nodes = Iterables.filter(detailsOnAllNodes(), filter);
|
||||||
|
|
||||||
final Map<NodeMetadata, ExecResponse> execs = Maps.newHashMap();
|
final Map<NodeMetadata, ExecResponse> execs = Maps.newHashMap();
|
||||||
|
final Map<NodeMetadata, Future<Void>> responses = Maps.newHashMap();
|
||||||
final Map<NodeMetadata, Exception> badNodes = Maps.newLinkedHashMap();
|
final Map<NodeMetadata, Exception> badNodes = Maps.newLinkedHashMap();
|
||||||
|
nodes = filterNodesWhoCanRunScripts(nodes, badNodes, options.getOverrideCredentials());
|
||||||
Map<NodeMetadata, Future<Void>> responses = Maps.newHashMap();
|
|
||||||
|
|
||||||
for (final NodeMetadata node : nodes) {
|
for (final NodeMetadata node : nodes) {
|
||||||
|
|
||||||
|
@ -365,57 +373,39 @@ public class BaseComputeService implements ComputeService {
|
||||||
@Override
|
@Override
|
||||||
public Void call() throws Exception {
|
public Void call() throws Exception {
|
||||||
try {
|
try {
|
||||||
RunScriptOnNode callable;
|
ExecResponse response = utils.runScriptOnNode(node, Statements.exec(Utils.toStringAndClose(runScript
|
||||||
if (options.isRunAsRoot())
|
.getInput())), options);
|
||||||
callable = utils.runScriptOnNode(node, "computeserv", runScript);
|
if (response != null)
|
||||||
else
|
execs.put(node, response);
|
||||||
callable = utils.runScriptOnNodeAsDefaultUser(node, "computeserv", runScript);
|
|
||||||
SshClient ssh = utils.createSshClientOncePortIsListeningOnNode(node);
|
|
||||||
try {
|
|
||||||
ssh.connect();
|
|
||||||
callable.setConnection(ssh, logger);
|
|
||||||
execs.put(node, callable.call());
|
|
||||||
} finally {
|
|
||||||
if (ssh != null)
|
|
||||||
ssh.disconnect();
|
|
||||||
}
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
badNodes.put(node, e);
|
badNodes.put(node, e);
|
||||||
|
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
}));
|
}));
|
||||||
|
|
||||||
}
|
}
|
||||||
Map<?, Exception> exceptions = awaitCompletion(responses, executor, null, logger, "starting nodes");
|
Map<?, Exception> exceptions = awaitCompletion(responses, executor, null, logger, "running script on nodes");
|
||||||
if (exceptions.size() > 0 || badNodes.size() > 0) {
|
if (exceptions.size() > 0 || badNodes.size() > 0) {
|
||||||
throw new RunScriptOnNodesException(runScript, options, execs, exceptions, badNodes);
|
throw new RunScriptOnNodesException(runScript, options, execs, exceptions, badNodes);
|
||||||
}
|
}
|
||||||
|
|
||||||
return execs;
|
return execs;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private Iterable<NodeMetadata> verifyParametersAndListNodes(Predicate<NodeMetadata> filter, Payload runScript,
|
private Iterable<? extends NodeMetadata> filterNodesWhoCanRunScripts(Iterable<? extends NodeMetadata> nodes,
|
||||||
final RunScriptOptions options) {
|
final Map<NodeMetadata, Exception> badNodes, final @Nullable Credentials overridingCredentials) {
|
||||||
checkNotNull(filter, "Filter must be provided");
|
nodes = Iterables.filter(Iterables.transform(nodes, new Function<NodeMetadata, NodeMetadata>() {
|
||||||
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);
|
|
||||||
// TODO parallel
|
|
||||||
return Iterables.transform(nodes, new Function<NodeMetadata, NodeMetadata>() {
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public NodeMetadata apply(NodeMetadata node) {
|
public NodeMetadata apply(NodeMetadata node) {
|
||||||
|
try {
|
||||||
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) {
|
if (overridingCredentials != null) {
|
||||||
// override the credentials with provided to this
|
node = installNewCredentials(node, overridingCredentials);
|
||||||
// method
|
|
||||||
node = installNewCredentials(node, options.getOverrideCredentials());
|
|
||||||
} else {
|
} else {
|
||||||
// don't override
|
|
||||||
checkNotNull(node.getCredentials(), "If the default credentials need to be used, they can't be null");
|
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 "
|
checkNotNull(node.getCredentials().identity, "Account name for ssh authentication must be "
|
||||||
+ "specified. Try passing RunScriptOptions with new credentials");
|
+ "specified. Try passing RunScriptOptions with new credentials");
|
||||||
|
@ -423,8 +413,13 @@ public class BaseComputeService implements ComputeService {
|
||||||
+ "specified. Try passing RunScriptOptions with new credentials");
|
+ "specified. Try passing RunScriptOptions with new credentials");
|
||||||
}
|
}
|
||||||
return node;
|
return node;
|
||||||
|
} catch (Exception e) {
|
||||||
|
badNodes.put(node, e);
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
|
}), Predicates.notNull());
|
||||||
|
return nodes;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Set<? extends NodeMetadata> detailsOnAllNodes() {
|
private Set<? extends NodeMetadata> detailsOnAllNodes() {
|
||||||
|
|
|
@ -41,7 +41,7 @@ public class ComputeServiceContextImpl<S, A> implements ComputeServiceContext {
|
||||||
private final RestContext<S, A> providerSpecificContext;
|
private final RestContext<S, A> providerSpecificContext;
|
||||||
private final Utils utils;
|
private final Utils utils;
|
||||||
|
|
||||||
@SuppressWarnings({ "unchecked", "rawtypes" })
|
@SuppressWarnings({ "unchecked" })
|
||||||
@Inject
|
@Inject
|
||||||
public ComputeServiceContextImpl(ComputeService computeService, Utils utils,
|
public ComputeServiceContextImpl(ComputeService computeService, Utils utils,
|
||||||
@Nullable LoadBalancerService loadBalancerService, RestContext providerSpecificContext) {
|
@Nullable LoadBalancerService loadBalancerService, RestContext providerSpecificContext) {
|
||||||
|
|
|
@ -19,6 +19,7 @@
|
||||||
|
|
||||||
package org.jclouds.compute.options;
|
package org.jclouds.compute.options;
|
||||||
|
|
||||||
|
import static com.google.common.base.Preconditions.checkArgument;
|
||||||
import static com.google.common.base.Preconditions.checkNotNull;
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
|
|
||||||
import org.jclouds.domain.Credentials;
|
import org.jclouds.domain.Credentials;
|
||||||
|
@ -74,10 +75,37 @@ public class RunScriptOptions {
|
||||||
throw new IllegalArgumentException("overridingCredentials is immutable");
|
throw new IllegalArgumentException("overridingCredentials is immutable");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getTaskName() {
|
||||||
|
return delegate.getTaskName();
|
||||||
}
|
}
|
||||||
|
|
||||||
private Credentials overridingCredentials;
|
@Override
|
||||||
private boolean runAsRoot = true;
|
public RunScriptOptions nameTask(String name) {
|
||||||
|
throw new IllegalArgumentException("taskName is immutable");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public RunScriptOptions blockOnPort(int port, int seconds) {
|
||||||
|
throw new IllegalArgumentException("port, seconds are immutable");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getPort() {
|
||||||
|
return delegate.getPort();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getSeconds() {
|
||||||
|
return delegate.getSeconds();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected int port = -1;
|
||||||
|
protected int seconds = -1;
|
||||||
|
protected String taskName;
|
||||||
|
protected Credentials overridingCredentials;
|
||||||
|
protected boolean runAsRoot = true;
|
||||||
|
|
||||||
public RunScriptOptions withOverridingCredentials(Credentials overridingCredentials) {
|
public RunScriptOptions withOverridingCredentials(Credentials overridingCredentials) {
|
||||||
checkNotNull(overridingCredentials, "overridingCredentials");
|
checkNotNull(overridingCredentials, "overridingCredentials");
|
||||||
|
@ -86,11 +114,43 @@ public class RunScriptOptions {
|
||||||
this.overridingCredentials = overridingCredentials;
|
this.overridingCredentials = overridingCredentials;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* @return What to call the task relating to this script; default {@code
|
||||||
|
* jclouds-script-timestamp} where timestamp is millis since epoch
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public RunScriptOptions nameTask(String name) {
|
||||||
|
this.taskName = name;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
public RunScriptOptions runAsRoot(boolean runAsRoot) {
|
public RunScriptOptions runAsRoot(boolean runAsRoot) {
|
||||||
this.runAsRoot = runAsRoot;
|
this.runAsRoot = runAsRoot;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* When the node is started, wait until the following port is active
|
||||||
|
*/
|
||||||
|
public RunScriptOptions 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getTaskName() {
|
||||||
|
return taskName;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public int getPort() {
|
||||||
|
return port;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getSeconds() {
|
||||||
|
return seconds;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Whether to override the credentials with ones supplied in call to
|
* Whether to override the credentials with ones supplied in call to
|
||||||
|
@ -113,6 +173,11 @@ public class RunScriptOptions {
|
||||||
|
|
||||||
public static class Builder {
|
public static class Builder {
|
||||||
|
|
||||||
|
public static RunScriptOptions nameTask(String name) {
|
||||||
|
RunScriptOptions options = new RunScriptOptions();
|
||||||
|
return options.nameTask(name);
|
||||||
|
}
|
||||||
|
|
||||||
public static RunScriptOptions overrideCredentialsWith(Credentials credentials) {
|
public static RunScriptOptions overrideCredentialsWith(Credentials credentials) {
|
||||||
RunScriptOptions options = new RunScriptOptions();
|
RunScriptOptions options = new RunScriptOptions();
|
||||||
return options.withOverridingCredentials(credentials);
|
return options.withOverridingCredentials(credentials);
|
||||||
|
@ -123,12 +188,19 @@ public class RunScriptOptions {
|
||||||
return options.runAsRoot(value);
|
return options.runAsRoot(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see RunScriptOptions#blockOnPort
|
||||||
|
*/
|
||||||
|
public static RunScriptOptions blockOnPort(int port, int seconds) {
|
||||||
|
RunScriptOptions options = new RunScriptOptions();
|
||||||
|
return options.blockOnPort(port, seconds);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "RunScriptOptions [overridingCredentials=" + (overridingCredentials != null)
|
return "[overridingCredentials=" + (overridingCredentials != null) + ", port:seconds=" + port + ":" + seconds + ", runAsRoot=" + runAsRoot + "]";
|
||||||
+ ", runAsRoot=" + runAsRoot + "]";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,18 +21,17 @@ package org.jclouds.compute.options;
|
||||||
|
|
||||||
import static com.google.common.base.Preconditions.checkArgument;
|
import static com.google.common.base.Preconditions.checkArgument;
|
||||||
import static com.google.common.base.Preconditions.checkNotNull;
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
import static org.jclouds.io.Payloads.newByteArrayPayload;
|
|
||||||
import static org.jclouds.io.Payloads.newStringPayload;
|
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
import org.jclouds.domain.Credentials;
|
||||||
|
|
||||||
import org.jclouds.compute.domain.OperatingSystem;
|
|
||||||
import org.jclouds.compute.predicates.OperatingSystemPredicates;
|
|
||||||
import org.jclouds.io.Payload;
|
import org.jclouds.io.Payload;
|
||||||
import org.jclouds.scriptbuilder.domain.OsFamily;
|
|
||||||
import org.jclouds.scriptbuilder.domain.Statement;
|
import org.jclouds.scriptbuilder.domain.Statement;
|
||||||
|
import org.jclouds.scriptbuilder.domain.Statements;
|
||||||
|
import org.jclouds.util.Utils;
|
||||||
|
|
||||||
|
import com.google.common.base.Throwables;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Contains options supported in the {@code ComputeService#runNodesWithTag} operation. <h2>
|
* Contains options supported in the {@code ComputeService#runNodesWithTag} operation. <h2>
|
||||||
|
@ -50,7 +49,7 @@ import org.jclouds.scriptbuilder.domain.Statement;
|
||||||
*
|
*
|
||||||
* @author Adrian Cole
|
* @author Adrian Cole
|
||||||
*/
|
*/
|
||||||
public class TemplateOptions {
|
public class TemplateOptions extends RunScriptOptions {
|
||||||
|
|
||||||
public static final TemplateOptions NONE = new ImmutableTemplateOptions(new TemplateOptions());
|
public static final TemplateOptions NONE = new ImmutableTemplateOptions(new TemplateOptions());
|
||||||
|
|
||||||
|
@ -81,41 +80,26 @@ public class TemplateOptions {
|
||||||
throw new IllegalArgumentException("blockUntilRunning is immutable");
|
throw new IllegalArgumentException("blockUntilRunning is immutable");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public TemplateOptions blockOnPort(int port, int seconds) {
|
|
||||||
throw new IllegalArgumentException("port, seconds are immutable");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int[] getInboundPorts() {
|
public int[] getInboundPorts() {
|
||||||
return delegate.getInboundPorts();
|
return delegate.getInboundPorts();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getPort() {
|
public String getPrivateKey() {
|
||||||
return delegate.getPort();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Payload getPrivateKey() {
|
|
||||||
return delegate.getPrivateKey();
|
return delegate.getPrivateKey();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Payload getPublicKey() {
|
public String getPublicKey() {
|
||||||
return delegate.getPublicKey();
|
return delegate.getPublicKey();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Payload getRunScript() {
|
public Statement getRunScript() {
|
||||||
return delegate.getRunScript();
|
return delegate.getRunScript();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getSeconds() {
|
|
||||||
return delegate.getSeconds();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean shouldBlockUntilRunning() {
|
public boolean shouldBlockUntilRunning() {
|
||||||
return delegate.shouldBlockUntilRunning();
|
return delegate.shouldBlockUntilRunning();
|
||||||
|
@ -150,41 +134,29 @@ public class TemplateOptions {
|
||||||
|
|
||||||
protected int[] inboundPorts = new int[] { 22 };
|
protected int[] inboundPorts = new int[] { 22 };
|
||||||
|
|
||||||
protected Payload script;
|
protected Statement script;
|
||||||
|
|
||||||
protected Payload privateKey;
|
protected String privateKey;
|
||||||
|
|
||||||
protected Payload publicKey;
|
protected String publicKey;
|
||||||
|
|
||||||
protected int port = -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 getSeconds() {
|
|
||||||
return seconds;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int[] getInboundPorts() {
|
public int[] getInboundPorts() {
|
||||||
return inboundPorts;
|
return inboundPorts;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Payload getRunScript() {
|
public Statement getRunScript() {
|
||||||
return script;
|
return script;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Payload getPrivateKey() {
|
public String getPrivateKey() {
|
||||||
return privateKey;
|
return privateKey;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Payload getPublicKey() {
|
public String getPublicKey() {
|
||||||
return publicKey;
|
return publicKey;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -200,28 +172,17 @@ public class TemplateOptions {
|
||||||
return clazz.cast(this);
|
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This script will be executed as the root user upon system startup. This script gets a
|
* 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
|
* prologue, so no #!/bin/bash required, path set up, etc
|
||||||
* <p/>
|
* <p/>
|
||||||
* please use alternative that uses the {@link org.jclouds.io.Payload} object
|
* please use alternative that uses the {@link org.jclouds.scriptbuilder.domain.Statement} object
|
||||||
*
|
*
|
||||||
* @see org.jclouds.io.Payloads
|
* @see org.jclouds.io.Payloads
|
||||||
*/
|
*/
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public TemplateOptions runScript(byte[] script) {
|
public TemplateOptions runScript(byte[] script) {
|
||||||
return runScript(newByteArrayPayload(checkNotNull(script, "script")));
|
return runScript(Statements.exec(new String(checkNotNull(script, "script"))));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -231,45 +192,45 @@ public class TemplateOptions {
|
||||||
* @see org.jclouds.io.Payloads
|
* @see org.jclouds.io.Payloads
|
||||||
*/
|
*/
|
||||||
public TemplateOptions runScript(Payload script) {
|
public TemplateOptions runScript(Payload script) {
|
||||||
checkNotNull(script, "script");
|
try {
|
||||||
this.script = script;
|
return runScript(Statements.exec(Utils.toStringAndClose(checkNotNull(script, "script").getInput())));
|
||||||
|
} catch (IOException e) {
|
||||||
|
Throwables.propagate(e);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public TemplateOptions runScript(Statement script, @Nullable OperatingSystem os) {
|
|
||||||
return runScript(newStringPayload(checkNotNull(script, "script").render(
|
|
||||||
os == null || OperatingSystemPredicates.isUnix().apply(os) ? OsFamily.UNIX : OsFamily.WINDOWS)));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public TemplateOptions runScript(Statement script) {
|
public TemplateOptions runScript(Statement script) {
|
||||||
return runScript(script, null);
|
this.script = checkNotNull(script, "script");
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* replaces the rsa ssh key used at login.
|
* replaces the rsa ssh key used at login.
|
||||||
* <p/>
|
* <p/>
|
||||||
* please use alternative that uses the {@link org.jclouds.io.Payload} object
|
* please use alternative that uses {@link java.lang.String}
|
||||||
*
|
*
|
||||||
* @see org.jclouds.io.Payloads
|
* @see org.jclouds.io.Payloads
|
||||||
*/
|
*/
|
||||||
@Deprecated
|
@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.getContentMetadata().setContentType("text/plain");
|
|
||||||
return installPrivateKey(payload);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* replaces the rsa ssh key used at login.
|
|
||||||
*
|
|
||||||
* @see org.jclouds.io.Payloads
|
|
||||||
*/
|
|
||||||
public TemplateOptions installPrivateKey(Payload privateKey) {
|
public TemplateOptions installPrivateKey(Payload privateKey) {
|
||||||
this.privateKey = checkNotNull(privateKey, "privateKey");
|
try {
|
||||||
|
return installPrivateKey(Utils.toStringAndClose(checkNotNull(privateKey, "privateKey").getInput()));
|
||||||
|
} catch (IOException e) {
|
||||||
|
Throwables.propagate(e);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public TemplateOptions dontAuthorizePublicKey() {
|
public TemplateOptions dontAuthorizePublicKey() {
|
||||||
this.publicKey = null;
|
this.publicKey = null;
|
||||||
|
@ -277,42 +238,30 @@ public class TemplateOptions {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* if true, return when node(s) are NODE_RUNNING, if false, return as soon as the server is
|
* authorize an rsa ssh key.
|
||||||
* provisioned.
|
|
||||||
* <p/>
|
|
||||||
* default is true
|
|
||||||
*/
|
*/
|
||||||
public TemplateOptions blockUntilRunning(boolean blockUntilRunning) {
|
public TemplateOptions authorizePublicKey(String publicKey) {
|
||||||
this.blockUntilRunning = blockUntilRunning;
|
checkArgument(checkNotNull(publicKey, "publicKey").startsWith("ssh-rsa"), "key should start with ssh-rsa");
|
||||||
if (!blockUntilRunning)
|
this.publicKey = publicKey;
|
||||||
port = seconds = -1;
|
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* authorize an rsa ssh key.
|
* authorize an rsa ssh key.
|
||||||
* <p/>
|
* <p/>
|
||||||
* please use alternative that uses the {@link org.jclouds.io.Payload} object
|
* please use alternative that uses {@link java.lang.String}
|
||||||
*
|
*
|
||||||
* @see org.jclouds.io.Payloads
|
* @see org.jclouds.io.Payloads
|
||||||
*/
|
*/
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public TemplateOptions authorizePublicKey(String publicKey) {
|
|
||||||
checkArgument(checkNotNull(publicKey, "publicKey").startsWith("ssh-rsa"), "key should start with ssh-rsa");
|
|
||||||
Payload payload = newStringPayload(publicKey);
|
|
||||||
payload.getContentMetadata().setContentType("text/plain");
|
|
||||||
return authorizePublicKey(payload);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* authorize an rsa ssh key.
|
|
||||||
*
|
|
||||||
* @see org.jclouds.io.Payloads
|
|
||||||
*/
|
|
||||||
public TemplateOptions authorizePublicKey(Payload publicKey) {
|
public TemplateOptions authorizePublicKey(Payload publicKey) {
|
||||||
this.publicKey = checkNotNull(publicKey, "publicKey");
|
try {
|
||||||
|
return authorizePublicKey(Utils.toStringAndClose(checkNotNull(publicKey, "publicKey").getInput()));
|
||||||
|
} catch (IOException e) {
|
||||||
|
Throwables.propagate(e);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Opens the set of ports to public access.
|
* Opens the set of ports to public access.
|
||||||
|
@ -329,7 +278,30 @@ public class TemplateOptions {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class Builder {
|
public static class Builder extends org.jclouds.compute.options.RunScriptOptions.Builder {
|
||||||
|
|
||||||
|
public static TemplateOptions nameTask(String name) {
|
||||||
|
TemplateOptions options = new TemplateOptions();
|
||||||
|
return options.nameTask(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static TemplateOptions overrideCredentialsWith(Credentials credentials) {
|
||||||
|
TemplateOptions options = new TemplateOptions();
|
||||||
|
return options.withOverridingCredentials(credentials);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static TemplateOptions runAsRoot(boolean value) {
|
||||||
|
TemplateOptions options = new TemplateOptions();
|
||||||
|
return options.runAsRoot(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see TemplateOptions#blockOnPort
|
||||||
|
*/
|
||||||
|
public static TemplateOptions blockOnPort(int port, int seconds) {
|
||||||
|
TemplateOptions options = new TemplateOptions();
|
||||||
|
return options.blockOnPort(port, seconds);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see TemplateOptions#inboundPorts
|
* @see TemplateOptions#inboundPorts
|
||||||
|
@ -339,14 +311,6 @@ public class TemplateOptions {
|
||||||
return options.inboundPorts(ports);
|
return options.inboundPorts(ports);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @see TemplateOptions#port
|
|
||||||
*/
|
|
||||||
public static TemplateOptions blockOnPort(int port, int seconds) {
|
|
||||||
TemplateOptions options = new TemplateOptions();
|
|
||||||
return options.blockOnPort(port, seconds);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see TemplateOptions#blockUntilRunning
|
* @see TemplateOptions#blockUntilRunning
|
||||||
*/
|
*/
|
||||||
|
@ -436,10 +400,16 @@ public class TemplateOptions {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "TemplateOptions [inboundPorts=" + Arrays.toString(inboundPorts) + ", privateKey=" + (privateKey != null)
|
return "[inboundPorts=" + Arrays.toString(inboundPorts) + ", privateKey=" + (privateKey != null) + ", publicKey="
|
||||||
+ ", publicKey=" + (publicKey != null) + ", runScript=" + (script != null) + ", blockUntilRunning="
|
+ (publicKey != null) + ", runScript=" + (script != null) + ", blockUntilRunning=" + blockUntilRunning
|
||||||
+ blockUntilRunning + ", port:seconds=" + port + ":" + seconds + ", metadata/details: "
|
+ ", port:seconds=" + port + ":" + seconds + ", metadata/details: " + includeMetadata + "]";
|
||||||
+ includeMetadata + "]";
|
}
|
||||||
|
|
||||||
|
public TemplateOptions blockUntilRunning(boolean blockUntilRunning) {
|
||||||
|
this.blockUntilRunning = blockUntilRunning;
|
||||||
|
if (!blockUntilRunning)
|
||||||
|
port = seconds = -1;
|
||||||
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -493,4 +463,24 @@ public class TemplateOptions {
|
||||||
return false;
|
return false;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public TemplateOptions blockOnPort(int port, int seconds) {
|
||||||
|
return TemplateOptions.class.cast(super.blockOnPort(port, seconds));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public TemplateOptions nameTask(String name) {
|
||||||
|
return TemplateOptions.class.cast(super.nameTask(name));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public TemplateOptions runAsRoot(boolean runAsRoot) {
|
||||||
|
return TemplateOptions.class.cast(super.runAsRoot(runAsRoot));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public TemplateOptions withOverridingCredentials(Credentials overridingCredentials) {
|
||||||
|
return TemplateOptions.class.cast(super.withOverridingCredentials(overridingCredentials));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,7 +33,7 @@ import com.google.inject.Module;
|
||||||
*
|
*
|
||||||
* @author Adrian Cole
|
* @author Adrian Cole
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("rawtypes")
|
@SuppressWarnings("unchecked")
|
||||||
public class StubComputeServiceContextBuilder extends ComputeServiceContextBuilder<ConcurrentMap, ConcurrentMap> {
|
public class StubComputeServiceContextBuilder extends ComputeServiceContextBuilder<ConcurrentMap, ConcurrentMap> {
|
||||||
|
|
||||||
public StubComputeServiceContextBuilder(Properties props) {
|
public StubComputeServiceContextBuilder(Properties props) {
|
||||||
|
|
|
@ -25,7 +25,7 @@ import org.jclouds.http.RequiresHttp;
|
||||||
import org.jclouds.rest.ConfiguresRestClient;
|
import org.jclouds.rest.ConfiguresRestClient;
|
||||||
import org.jclouds.rest.config.RestClientModule;
|
import org.jclouds.rest.config.RestClientModule;
|
||||||
|
|
||||||
@SuppressWarnings("rawtypes")
|
@SuppressWarnings("unchecked")
|
||||||
@ConfiguresRestClient
|
@ConfiguresRestClient
|
||||||
@RequiresHttp
|
@RequiresHttp
|
||||||
public class StubComputeServiceClientModule extends RestClientModule<ConcurrentMap, ConcurrentMap> {
|
public class StubComputeServiceClientModule extends RestClientModule<ConcurrentMap, ConcurrentMap> {
|
||||||
|
|
|
@ -158,7 +158,7 @@ public class StubComputeServiceContextModule extends BaseComputeServiceContextMo
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings( { "rawtypes" })
|
@SuppressWarnings("unchecked")
|
||||||
@Override
|
@Override
|
||||||
protected void configure() {
|
protected void configure() {
|
||||||
bind(new TypeLiteral<ComputeServiceContext>() {
|
bind(new TypeLiteral<ComputeServiceContext>() {
|
||||||
|
|
|
@ -87,6 +87,20 @@ public class ComputeServiceUtils {
|
||||||
return extractTargzIntoDirectory(new HttpRequest("GET", targz), directory);
|
return extractTargzIntoDirectory(new HttpRequest("GET", targz), directory);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* build a shell script that invokes the contents of the http request in bash.
|
||||||
|
*
|
||||||
|
* @return a shell script that will invoke the http request
|
||||||
|
*/
|
||||||
|
public static Statement extractZipIntoDirectory(HttpRequest zip, String directory) {
|
||||||
|
return Statements
|
||||||
|
.extractZipIntoDirectory(zip.getMethod(), zip.getEndpoint(), zip.getHeaders(), directory);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Statement extractZipIntoDirectory(URI zip, String directory) {
|
||||||
|
return extractZipIntoDirectory(new HttpRequest("GET", zip), directory);
|
||||||
|
}
|
||||||
|
|
||||||
public static String parseTagFromName(String from) {
|
public static String parseTagFromName(String from) {
|
||||||
Matcher matcher = DELIMETED_BY_HYPHEN_ENDING_IN_HYPHEN_HEX.matcher(from);
|
Matcher matcher = DELIMETED_BY_HYPHEN_ENDING_IN_HYPHEN_HEX.matcher(from);
|
||||||
return matcher.find() ? matcher.group(1) : "NOTAG-" + from;
|
return matcher.find() ? matcher.group(1) : "NOTAG-" + from;
|
||||||
|
|
|
@ -40,20 +40,23 @@ import javax.inject.Named;
|
||||||
import javax.inject.Singleton;
|
import javax.inject.Singleton;
|
||||||
|
|
||||||
import org.jclouds.Constants;
|
import org.jclouds.Constants;
|
||||||
import org.jclouds.compute.callables.AuthorizeRSAPublicKey;
|
|
||||||
import org.jclouds.compute.callables.InstallRSAPrivateKey;
|
|
||||||
import org.jclouds.compute.callables.RunScriptOnNode;
|
import org.jclouds.compute.callables.RunScriptOnNode;
|
||||||
import org.jclouds.compute.domain.NodeMetadata;
|
import org.jclouds.compute.domain.NodeMetadata;
|
||||||
|
import org.jclouds.compute.options.RunScriptOptions;
|
||||||
import org.jclouds.compute.options.TemplateOptions;
|
import org.jclouds.compute.options.TemplateOptions;
|
||||||
import org.jclouds.compute.predicates.ScriptStatusReturnsZero.CommandUsingClient;
|
import org.jclouds.compute.predicates.ScriptStatusReturnsZero.CommandUsingClient;
|
||||||
import org.jclouds.compute.reference.ComputeServiceConstants;
|
import org.jclouds.compute.reference.ComputeServiceConstants;
|
||||||
import org.jclouds.compute.reference.ComputeServiceConstants.Timeouts;
|
import org.jclouds.compute.reference.ComputeServiceConstants.Timeouts;
|
||||||
import org.jclouds.compute.strategy.GetNodeMetadataStrategy;
|
import org.jclouds.compute.strategy.GetNodeMetadataStrategy;
|
||||||
import org.jclouds.compute.util.ComputeServiceUtils.SshCallable;
|
import org.jclouds.compute.util.ComputeServiceUtils.SshCallable;
|
||||||
import org.jclouds.io.Payload;
|
|
||||||
import org.jclouds.logging.Logger;
|
import org.jclouds.logging.Logger;
|
||||||
import org.jclouds.net.IPSocket;
|
import org.jclouds.net.IPSocket;
|
||||||
import org.jclouds.predicates.RetryablePredicate;
|
import org.jclouds.predicates.RetryablePredicate;
|
||||||
|
import org.jclouds.scriptbuilder.domain.AuthorizeRSAPublicKey;
|
||||||
|
import org.jclouds.scriptbuilder.domain.InstallRSAPrivateKey;
|
||||||
|
import org.jclouds.scriptbuilder.domain.Statement;
|
||||||
|
import org.jclouds.scriptbuilder.domain.StatementList;
|
||||||
|
import org.jclouds.ssh.ExecResponse;
|
||||||
import org.jclouds.ssh.SshClient;
|
import org.jclouds.ssh.SshClient;
|
||||||
|
|
||||||
import com.google.common.base.Predicate;
|
import com.google.common.base.Predicate;
|
||||||
|
@ -136,35 +139,49 @@ public class ComputeUtils {
|
||||||
throw new IllegalStateException(String.format(
|
throw new IllegalStateException(String.format(
|
||||||
"node didn't achieve the state running on node %s within %d seconds, final state: %s", node.getId(),
|
"node didn't achieve the state running on node %s within %d seconds, final state: %s", node.getId(),
|
||||||
timeouts.nodeRunning / 1000, node.getState()));
|
timeouts.nodeRunning / 1000, node.getState()));
|
||||||
|
List<Statement> bootstrap = Lists.newArrayList();
|
||||||
List<SshCallable<?>> callables = Lists.newArrayList();
|
if (options.getRunScript() != null)
|
||||||
if (options.getRunScript() != null) {
|
bootstrap.add(options.getRunScript());
|
||||||
callables.add(runScriptOnNode(node, "runscript", options.getRunScript()));
|
if (options.getPublicKey() != null)
|
||||||
}
|
bootstrap.add(new AuthorizeRSAPublicKey(options.getPublicKey()));
|
||||||
if (options.getPublicKey() != null) {
|
if (options.getPrivateKey() != null)
|
||||||
callables.add(authorizeKeyOnNode(node, options.getPublicKey()));
|
bootstrap.add(new InstallRSAPrivateKey(options.getPrivateKey()));
|
||||||
|
if (bootstrap.size() >0)
|
||||||
|
runScriptOnNode(node, new StatementList(bootstrap), options);
|
||||||
|
return node;
|
||||||
}
|
}
|
||||||
|
|
||||||
// changing the key "MUST" come last or else the other commands may
|
public void checkNodeHasPublicIps(NodeMetadata node) {
|
||||||
// fail.
|
checkState(node.getPublicAddresses().size() > 0, "node does not have IP addresses configured: " + node);
|
||||||
if (callables.size() > 0 || options.getPrivateKey() != null) {
|
|
||||||
runCallablesOnNode(node, callables, options.getPrivateKey() != null ? installKeyOnNode(node, options
|
|
||||||
.getPrivateKey()) : null);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ExecResponse runScriptOnNode(NodeMetadata node, Statement runScript, RunScriptOptions options)
|
||||||
|
{
|
||||||
|
RunScriptOnNode callable;
|
||||||
|
String taskName = options.getTaskName();
|
||||||
|
ExecResponse response;
|
||||||
|
if (options.isRunAsRoot()) {
|
||||||
|
callable = runScriptOnNode(node, taskName, runScript);
|
||||||
|
} else
|
||||||
|
callable = runScriptOnNodeAsDefaultUser(node, taskName, runScript);
|
||||||
|
SshClient ssh = createSshClientOncePortIsListeningOnNode(node);
|
||||||
|
try {
|
||||||
|
ssh.connect();
|
||||||
|
callable.setConnection(ssh, logger);
|
||||||
|
response = callable.call();
|
||||||
|
} finally {
|
||||||
|
if (ssh != null)
|
||||||
|
ssh.disconnect();
|
||||||
|
}
|
||||||
if (options.getPort() > 0) {
|
if (options.getPort() > 0) {
|
||||||
checkNodeHasPublicIps(node);
|
checkNodeHasPublicIps(node);
|
||||||
blockUntilPortIsListeningOnPublicIp(options.getPort(), options.getSeconds(), Iterables.get(node
|
blockUntilPortIsListeningOnPublicIp(options.getPort(), options.getSeconds(), Iterables.get(node
|
||||||
.getPublicAddresses(), 0));
|
.getPublicAddresses(), 0));
|
||||||
}
|
}
|
||||||
return node;
|
return response;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void checkNodeHasPublicIps(NodeMetadata node) {
|
public void blockUntilPortIsListeningOnPublicIp(int port, int seconds, String inetAddress) {
|
||||||
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);
|
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);
|
IPSocket socket = new IPSocket(inetAddress, port);
|
||||||
|
@ -175,19 +192,11 @@ public class ComputeUtils {
|
||||||
logger.warn("<< port %s:%d didn't open after %d seconds", inetAddress, port, seconds);
|
logger.warn("<< port %s:%d didn't open after %d seconds", inetAddress, port, seconds);
|
||||||
}
|
}
|
||||||
|
|
||||||
public InstallRSAPrivateKey installKeyOnNode(NodeMetadata node, Payload privateKey) {
|
public RunScriptOnNode runScriptOnNode(NodeMetadata node, String scriptName, Statement script) {
|
||||||
return new InstallRSAPrivateKey(node, privateKey);
|
|
||||||
}
|
|
||||||
|
|
||||||
public AuthorizeRSAPublicKey authorizeKeyOnNode(NodeMetadata node, Payload publicKey) {
|
|
||||||
return new AuthorizeRSAPublicKey(node, publicKey);
|
|
||||||
}
|
|
||||||
|
|
||||||
public RunScriptOnNode runScriptOnNode(NodeMetadata node, String scriptName, Payload script) {
|
|
||||||
return new RunScriptOnNode(runScriptNotRunning, node, scriptName, script);
|
return new RunScriptOnNode(runScriptNotRunning, node, scriptName, script);
|
||||||
}
|
}
|
||||||
|
|
||||||
public RunScriptOnNode runScriptOnNodeAsDefaultUser(NodeMetadata node, String scriptName, Payload script) {
|
public RunScriptOnNode runScriptOnNodeAsDefaultUser(NodeMetadata node, String scriptName, Statement script) {
|
||||||
return new RunScriptOnNode(runScriptNotRunning, node, scriptName, script, false);
|
return new RunScriptOnNode(runScriptNotRunning, node, scriptName, script, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -320,9 +320,8 @@ public abstract class BaseComputeServiceLiveTest {
|
||||||
private void refreshTemplate() {
|
private void refreshTemplate() {
|
||||||
template = buildTemplate(client.templateBuilder());
|
template = buildTemplate(client.templateBuilder());
|
||||||
|
|
||||||
template.getOptions().installPrivateKey(newStringPayload(keyPair.get("private"))).authorizePublicKey(
|
template.getOptions().installPrivateKey(keyPair.get("private")).authorizePublicKey(keyPair.get("public"))
|
||||||
newStringPayload(keyPair.get("public"))).runScript(
|
.runScript(newStringPayload(buildScript(template.getImage().getOperatingSystem())));
|
||||||
newStringPayload(buildScript(template.getImage().getOperatingSystem())));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void checkImageIdMatchesTemplate(NodeMetadata node) {
|
protected void checkImageIdMatchesTemplate(NodeMetadata node) {
|
||||||
|
@ -362,7 +361,7 @@ public abstract class BaseComputeServiceLiveTest {
|
||||||
Credentials creds) throws RunScriptOnNodesException {
|
Credentials creds) throws RunScriptOnNodesException {
|
||||||
try {
|
try {
|
||||||
return client.runScriptOnNodesMatching(runningWithTag(tag), newStringPayload(buildScript(os)),
|
return client.runScriptOnNodesMatching(runningWithTag(tag), newStringPayload(buildScript(os)),
|
||||||
overrideCredentialsWith(creds));
|
overrideCredentialsWith(creds).nameTask("runScriptWithCreds"));
|
||||||
} catch (SshException e) {
|
} catch (SshException e) {
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
|
@ -606,7 +605,7 @@ public abstract class BaseComputeServiceLiveTest {
|
||||||
ExecResponse hello = ssh.exec("echo hello");
|
ExecResponse hello = ssh.exec("echo hello");
|
||||||
assertEquals(hello.getOutput().trim(), "hello");
|
assertEquals(hello.getOutput().trim(), "hello");
|
||||||
ExecResponse exec = ssh.exec("java -version");
|
ExecResponse exec = ssh.exec("java -version");
|
||||||
assert exec.getError().indexOf("OpenJDK") != -1 : exec;
|
assert exec.getError().indexOf("OpenJDK") != -1 || exec.getOutput().indexOf("OpenJDK") != -1 : exec;
|
||||||
} finally {
|
} finally {
|
||||||
if (ssh != null)
|
if (ssh != null)
|
||||||
ssh.disconnect();
|
ssh.disconnect();
|
||||||
|
|
|
@ -19,7 +19,6 @@
|
||||||
|
|
||||||
package org.jclouds.compute;
|
package org.jclouds.compute;
|
||||||
|
|
||||||
import static com.google.common.base.Preconditions.checkNotNull;
|
|
||||||
import static org.easymock.EasyMock.aryEq;
|
import static org.easymock.EasyMock.aryEq;
|
||||||
import static org.easymock.EasyMock.eq;
|
import static org.easymock.EasyMock.eq;
|
||||||
import static org.easymock.EasyMock.expect;
|
import static org.easymock.EasyMock.expect;
|
||||||
|
@ -48,9 +47,6 @@ import org.jclouds.net.IPSocket;
|
||||||
import org.jclouds.predicates.RetryablePredicate;
|
import org.jclouds.predicates.RetryablePredicate;
|
||||||
import org.jclouds.predicates.SocketOpen;
|
import org.jclouds.predicates.SocketOpen;
|
||||||
import org.jclouds.rest.RestContext;
|
import org.jclouds.rest.RestContext;
|
||||||
import org.jclouds.scriptbuilder.InitBuilder;
|
|
||||||
import org.jclouds.scriptbuilder.domain.Statement;
|
|
||||||
import org.jclouds.scriptbuilder.domain.Statements;
|
|
||||||
import org.jclouds.ssh.ExecResponse;
|
import org.jclouds.ssh.ExecResponse;
|
||||||
import org.jclouds.ssh.SshClient;
|
import org.jclouds.ssh.SshClient;
|
||||||
import org.jclouds.ssh.SshException;
|
import org.jclouds.ssh.SshException;
|
||||||
|
@ -58,11 +54,8 @@ import org.jclouds.util.Utils;
|
||||||
import org.testng.annotations.BeforeClass;
|
import org.testng.annotations.BeforeClass;
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
import com.google.common.base.Splitter;
|
|
||||||
import com.google.common.base.Throwables;
|
import com.google.common.base.Throwables;
|
||||||
import com.google.common.collect.ImmutableList;
|
|
||||||
import com.google.common.collect.ImmutableMap;
|
import com.google.common.collect.ImmutableMap;
|
||||||
import com.google.common.collect.Iterables;
|
|
||||||
import com.google.inject.AbstractModule;
|
import com.google.inject.AbstractModule;
|
||||||
import com.google.inject.Module;
|
import com.google.inject.Module;
|
||||||
|
|
||||||
|
@ -127,7 +120,12 @@ public class StubComputeServiceIntegrationTest extends BaseComputeServiceLiveTes
|
||||||
.atLeastOnce();
|
.atLeastOnce();
|
||||||
|
|
||||||
client1.connect();
|
client1.connect();
|
||||||
runScript(client1, "computeserv", 1);
|
try {
|
||||||
|
runScript(client1, "runScriptWithCreds", Utils.toStringAndClose(StubComputeServiceIntegrationTest.class
|
||||||
|
.getResourceAsStream("/runscript.sh")), 1);
|
||||||
|
} catch (IOException e) {
|
||||||
|
Throwables.propagate(e);
|
||||||
|
}
|
||||||
client1.disconnect();
|
client1.disconnect();
|
||||||
|
|
||||||
expect(factory.create(new IPSocket("144.175.1.2", 22), "root", "password2")).andReturn(client2)
|
expect(factory.create(new IPSocket("144.175.1.2", 22), "root", "password2")).andReturn(client2)
|
||||||
|
@ -137,9 +135,9 @@ public class StubComputeServiceIntegrationTest extends BaseComputeServiceLiveTes
|
||||||
expect(factory.create(new IPSocket("144.175.1.4", 22), "root", "password4")).andReturn(client4)
|
expect(factory.create(new IPSocket("144.175.1.4", 22), "root", "password4")).andReturn(client4)
|
||||||
.atLeastOnce();
|
.atLeastOnce();
|
||||||
|
|
||||||
runScriptAndInstallSsh(client2, "runscript", 2);
|
runScriptAndInstallSsh(client2, "bootstrap", 2);
|
||||||
runScriptAndInstallSsh(client3, "runscript", 3);
|
runScriptAndInstallSsh(client3, "bootstrap", 3);
|
||||||
runScriptAndInstallSsh(client4, "runscript", 4);
|
runScriptAndInstallSsh(client4, "bootstrap", 4);
|
||||||
|
|
||||||
expect(
|
expect(
|
||||||
factory.create(eq(new IPSocket("144.175.1.1", 22)), eq("root"), aryEq(keyPair.get("private")
|
factory.create(eq(new IPSocket("144.175.1.1", 22)), eq("root"), aryEq(keyPair.get("private")
|
||||||
|
@ -171,24 +169,19 @@ public class StubComputeServiceIntegrationTest extends BaseComputeServiceLiveTes
|
||||||
private void runScriptAndInstallSsh(SshClient client, String scriptName, int nodeId) {
|
private void runScriptAndInstallSsh(SshClient client, String scriptName, int nodeId) {
|
||||||
client.connect();
|
client.connect();
|
||||||
|
|
||||||
runScript(client, scriptName, nodeId);
|
try {
|
||||||
|
runScript(client, scriptName, Utils.toStringAndClose(StubComputeServiceIntegrationTest.class
|
||||||
expect(client.exec("mkdir .ssh")).andReturn(EXEC_GOOD);
|
.getResourceAsStream("/initscript_with_keys.sh")), nodeId);
|
||||||
expect(client.exec("cat .ssh/id_rsa.pub >> .ssh/authorized_keys")).andReturn(EXEC_GOOD);
|
} catch (IOException e) {
|
||||||
expect(client.exec("chmod 600 .ssh/authorized_keys")).andReturn(EXEC_GOOD);
|
Throwables.propagate(e);
|
||||||
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"), payloadEq(keyPair.get("private")));
|
|
||||||
expect(client.exec("chmod 600 .ssh/id_rsa")).andReturn(EXEC_GOOD);
|
|
||||||
|
|
||||||
client.disconnect();
|
client.disconnect();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void runScript(SshClient client, String scriptName, int nodeId) {
|
private void runScript(SshClient client, String scriptName, String script, int nodeId) {
|
||||||
client.put(eq("" + scriptName + ""), payloadEq(initScript(scriptName,
|
client.put(eq("" + scriptName + ""), payloadEq(script));
|
||||||
BaseComputeServiceLiveTest.APT_RUN_SCRIPT)));
|
|
||||||
expect(client.exec("chmod 755 " + scriptName + "")).andReturn(EXEC_GOOD);
|
expect(client.exec("chmod 755 " + scriptName + "")).andReturn(EXEC_GOOD);
|
||||||
expect(client.getUsername()).andReturn("root").atLeastOnce();
|
expect(client.getUsername()).andReturn("root").atLeastOnce();
|
||||||
expect(client.getHostAddress()).andReturn(nodeId + "").atLeastOnce();
|
expect(client.getHostAddress()).andReturn(nodeId + "").atLeastOnce();
|
||||||
|
@ -223,13 +216,6 @@ public class StubComputeServiceIntegrationTest extends BaseComputeServiceLiveTes
|
||||||
// TODO: this fails so we override it.
|
// TODO: this fails so we override it.
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String initScript(String scriptName, String script) {
|
|
||||||
return new InitBuilder(scriptName, "/tmp/" + scriptName, "/tmp/" + scriptName,
|
|
||||||
ImmutableMap.<String, String> of(), ImmutableList.<Statement> of(Statements.interpret(Iterables.toArray(
|
|
||||||
Splitter.on("\n").split(new String(checkNotNull(script, "script"))), String.class))))
|
|
||||||
.build(org.jclouds.scriptbuilder.domain.OsFamily.UNIX);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Payload payloadEq(String value) {
|
public static Payload payloadEq(String value) {
|
||||||
reportMatcher(new PayloadEquals(value));
|
reportMatcher(new PayloadEquals(value));
|
||||||
return null;
|
return null;
|
||||||
|
@ -257,10 +243,7 @@ public class StubComputeServiceIntegrationTest extends BaseComputeServiceLiveTes
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
String real = Utils.toStringAndClose(((Payload) actual).getInput());
|
String real = Utils.toStringAndClose(((Payload) actual).getInput());
|
||||||
if (!expected.equals(real)) {
|
assertEquals(real, expected);
|
||||||
System.err.println(real);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
return true;
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
Throwables.propagate(e);
|
Throwables.propagate(e);
|
||||||
|
|
|
@ -28,7 +28,6 @@ import static org.testng.Assert.assertEquals;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
import org.jclouds.util.Utils;
|
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -37,19 +36,17 @@ import org.testng.annotations.Test;
|
||||||
* @author Adrian Cole
|
* @author Adrian Cole
|
||||||
*/
|
*/
|
||||||
public class TemplateOptionsTest {
|
public class TemplateOptionsTest {
|
||||||
@SuppressWarnings("deprecation")
|
|
||||||
@Test(expectedExceptions = IllegalArgumentException.class)
|
@Test(expectedExceptions = IllegalArgumentException.class)
|
||||||
public void testinstallPrivateKeyBadFormat() {
|
public void testinstallPrivateKeyBadFormat() {
|
||||||
TemplateOptions options = new TemplateOptions();
|
TemplateOptions options = new TemplateOptions();
|
||||||
options.installPrivateKey("whompy");
|
options.installPrivateKey("whompy");
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("deprecation")
|
|
||||||
@Test
|
@Test
|
||||||
public void testinstallPrivateKey() throws IOException {
|
public void testinstallPrivateKey() throws IOException {
|
||||||
TemplateOptions options = new TemplateOptions();
|
TemplateOptions options = new TemplateOptions();
|
||||||
options.installPrivateKey("-----BEGIN RSA PRIVATE KEY-----");
|
options.installPrivateKey("-----BEGIN RSA PRIVATE KEY-----");
|
||||||
assertEquals(Utils.toStringAndClose(options.getPrivateKey().getInput()), "-----BEGIN RSA PRIVATE KEY-----");
|
assertEquals(options.getPrivateKey(), "-----BEGIN RSA PRIVATE KEY-----");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -62,7 +59,7 @@ public class TemplateOptionsTest {
|
||||||
@Test
|
@Test
|
||||||
public void testinstallPrivateKeyStatic() throws IOException {
|
public void testinstallPrivateKeyStatic() throws IOException {
|
||||||
TemplateOptions options = installPrivateKey("-----BEGIN RSA PRIVATE KEY-----");
|
TemplateOptions options = installPrivateKey("-----BEGIN RSA PRIVATE KEY-----");
|
||||||
assertEquals(Utils.toStringAndClose(options.getPrivateKey().getInput()), "-----BEGIN RSA PRIVATE KEY-----");
|
assertEquals(options.getPrivateKey(), "-----BEGIN RSA PRIVATE KEY-----");
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("deprecation")
|
@SuppressWarnings("deprecation")
|
||||||
|
@ -71,7 +68,6 @@ public class TemplateOptionsTest {
|
||||||
installPrivateKey((String) null);
|
installPrivateKey((String) null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("deprecation")
|
|
||||||
@Test(expectedExceptions = IllegalArgumentException.class)
|
@Test(expectedExceptions = IllegalArgumentException.class)
|
||||||
public void testauthorizePublicKeyBadFormat() {
|
public void testauthorizePublicKeyBadFormat() {
|
||||||
TemplateOptions options = new TemplateOptions();
|
TemplateOptions options = new TemplateOptions();
|
||||||
|
@ -79,11 +75,10 @@ public class TemplateOptionsTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@SuppressWarnings("deprecation")
|
|
||||||
public void testauthorizePublicKey() throws IOException {
|
public void testauthorizePublicKey() throws IOException {
|
||||||
TemplateOptions options = new TemplateOptions();
|
TemplateOptions options = new TemplateOptions();
|
||||||
options.authorizePublicKey("ssh-rsa");
|
options.authorizePublicKey("ssh-rsa");
|
||||||
assertEquals(Utils.toStringAndClose(options.getPublicKey().getInput()), "ssh-rsa");
|
assertEquals(options.getPublicKey(), "ssh-rsa");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -96,7 +91,7 @@ public class TemplateOptionsTest {
|
||||||
@Test
|
@Test
|
||||||
public void testauthorizePublicKeyStatic() throws IOException {
|
public void testauthorizePublicKeyStatic() throws IOException {
|
||||||
TemplateOptions options = authorizePublicKey("ssh-rsa");
|
TemplateOptions options = authorizePublicKey("ssh-rsa");
|
||||||
assertEquals(Utils.toStringAndClose(options.getPublicKey().getInput()), "ssh-rsa");
|
assertEquals(options.getPublicKey(), "ssh-rsa");
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("deprecation")
|
@SuppressWarnings("deprecation")
|
||||||
|
|
|
@ -0,0 +1,136 @@
|
||||||
|
#!/bin/bash
|
||||||
|
set +u
|
||||||
|
shopt -s xpg_echo
|
||||||
|
shopt -s expand_aliases
|
||||||
|
unset PATH JAVA_HOME LD_LIBRARY_PATH
|
||||||
|
function abort {
|
||||||
|
echo "aborting: $@" 1>&2
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
function default {
|
||||||
|
export INSTANCE_NAME="bootstrap"
|
||||||
|
export INSTANCE_HOME="/tmp/bootstrap"
|
||||||
|
export LOG_DIR="/tmp/bootstrap"
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
function bootstrap {
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
function findPid {
|
||||||
|
unset FOUND_PID;
|
||||||
|
[ $# -eq 1 ] || {
|
||||||
|
abort "findPid requires a parameter of pattern to match"
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
local PATTERN="$1"; shift
|
||||||
|
local _FOUND=`ps auxwww|grep "$PATTERN"|grep -v " $0"|grep -v grep|awk '{print $2}'`
|
||||||
|
[ -n "$_FOUND" ] && {
|
||||||
|
export FOUND_PID=$_FOUND
|
||||||
|
return 0
|
||||||
|
} || {
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
function forget {
|
||||||
|
unset FOUND_PID;
|
||||||
|
[ $# -eq 3 ] || {
|
||||||
|
abort "forget requires parameters INSTANCE_NAME SCRIPT LOG_DIR"
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
local INSTANCE_NAME="$1"; shift
|
||||||
|
local SCRIPT="$1"; shift
|
||||||
|
local LOG_DIR="$1"; shift
|
||||||
|
mkdir -p $LOG_DIR
|
||||||
|
findPid $INSTANCE_NAME
|
||||||
|
[ -n "$FOUND_PID" ] && {
|
||||||
|
echo $INSTANCE_NAME already running pid [$FOUND_PID]
|
||||||
|
} || {
|
||||||
|
nohup $SCRIPT >$LOG_DIR/stdout.log 2>$LOG_DIR/stderr.log &
|
||||||
|
sleep 1
|
||||||
|
findPid $INSTANCE_NAME
|
||||||
|
[ -n "$FOUND_PID" ] || abort "$INSTANCE_NAME did not start"
|
||||||
|
}
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
export PATH=/usr/ucb/bin:/bin:/sbin:/usr/bin:/usr/sbin
|
||||||
|
case $1 in
|
||||||
|
init)
|
||||||
|
default || exit 1
|
||||||
|
bootstrap || exit 1
|
||||||
|
mkdir -p $INSTANCE_HOME
|
||||||
|
|
||||||
|
# create runscript header
|
||||||
|
cat > $INSTANCE_HOME/bootstrap.sh <<END_OF_SCRIPT
|
||||||
|
#!/bin/bash
|
||||||
|
set +u
|
||||||
|
shopt -s xpg_echo
|
||||||
|
shopt -s expand_aliases
|
||||||
|
PROMPT_COMMAND='echo -ne "\033]0;bootstrap\007"'
|
||||||
|
export PATH=/usr/ucb/bin:/bin:/sbin:/usr/bin:/usr/sbin
|
||||||
|
export INSTANCE_NAME='bootstrap'
|
||||||
|
export INSTANCE_NAME='$INSTANCE_NAME'
|
||||||
|
export INSTANCE_HOME='$INSTANCE_HOME'
|
||||||
|
export LOG_DIR='$LOG_DIR'
|
||||||
|
END_OF_SCRIPT
|
||||||
|
|
||||||
|
# add desired commands from the user
|
||||||
|
cat >> $INSTANCE_HOME/bootstrap.sh <<'END_OF_SCRIPT'
|
||||||
|
cd $INSTANCE_HOME
|
||||||
|
echo nameserver 208.67.222.222 >> /etc/resolv.conf
|
||||||
|
cp /etc/apt/sources.list /etc/apt/sources.list.old
|
||||||
|
sed 's~us.archive.ubuntu.com~mirror.anl.gov/pub~g' /etc/apt/sources.list.old >/etc/apt/sources.list
|
||||||
|
apt-get update
|
||||||
|
apt-get install -f -y --force-yes openjdk-6-jdk
|
||||||
|
|
||||||
|
mkdir -p .ssh
|
||||||
|
cat >> .ssh/authorized_keys <<'END_OF_FILE'
|
||||||
|
ssh-rsa
|
||||||
|
END_OF_FILE
|
||||||
|
chmod 600 .ssh/authorized_keys
|
||||||
|
mkdir -p .ssh
|
||||||
|
rm .ssh/id_rsa
|
||||||
|
cat >> .ssh/id_rsa <<'END_OF_FILE'
|
||||||
|
-----BEGIN RSA PRIVATE KEY-----
|
||||||
|
END_OF_FILE
|
||||||
|
chmod 600 .ssh/id_rsa
|
||||||
|
|
||||||
|
END_OF_SCRIPT
|
||||||
|
|
||||||
|
# add runscript footer
|
||||||
|
cat >> $INSTANCE_HOME/bootstrap.sh <<'END_OF_SCRIPT'
|
||||||
|
exit 0
|
||||||
|
END_OF_SCRIPT
|
||||||
|
|
||||||
|
chmod u+x $INSTANCE_HOME/bootstrap.sh
|
||||||
|
;;
|
||||||
|
status)
|
||||||
|
default || exit 1
|
||||||
|
findPid $INSTANCE_NAME || exit 1
|
||||||
|
echo [$FOUND_PID]
|
||||||
|
;;
|
||||||
|
stop)
|
||||||
|
default || exit 1
|
||||||
|
findPid $INSTANCE_NAME || exit 1
|
||||||
|
[ -n "$FOUND_PID" ] && {
|
||||||
|
echo stopping $FOUND_PID
|
||||||
|
kill -9 $FOUND_PID
|
||||||
|
}
|
||||||
|
;;
|
||||||
|
start)
|
||||||
|
default || exit 1
|
||||||
|
forget $INSTANCE_NAME $INSTANCE_HOME/$INSTANCE_NAME.sh $LOG_DIR || exit 1
|
||||||
|
;;
|
||||||
|
tail)
|
||||||
|
default || exit 1
|
||||||
|
tail $LOG_DIR/stdout.log
|
||||||
|
;;
|
||||||
|
tailerr)
|
||||||
|
default || exit 1
|
||||||
|
tail $LOG_DIR/stderr.log
|
||||||
|
;;
|
||||||
|
run)
|
||||||
|
default || exit 1
|
||||||
|
$INSTANCE_HOME/$INSTANCE_NAME.sh
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
exit 0
|
|
@ -0,0 +1,125 @@
|
||||||
|
#!/bin/bash
|
||||||
|
set +u
|
||||||
|
shopt -s xpg_echo
|
||||||
|
shopt -s expand_aliases
|
||||||
|
unset PATH JAVA_HOME LD_LIBRARY_PATH
|
||||||
|
function abort {
|
||||||
|
echo "aborting: $@" 1>&2
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
function default {
|
||||||
|
export INSTANCE_NAME="runScriptWithCreds"
|
||||||
|
export INSTANCE_HOME="/tmp/runScriptWithCreds"
|
||||||
|
export LOG_DIR="/tmp/runScriptWithCreds"
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
function runScriptWithCreds {
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
function findPid {
|
||||||
|
unset FOUND_PID;
|
||||||
|
[ $# -eq 1 ] || {
|
||||||
|
abort "findPid requires a parameter of pattern to match"
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
local PATTERN="$1"; shift
|
||||||
|
local _FOUND=`ps auxwww|grep "$PATTERN"|grep -v " $0"|grep -v grep|awk '{print $2}'`
|
||||||
|
[ -n "$_FOUND" ] && {
|
||||||
|
export FOUND_PID=$_FOUND
|
||||||
|
return 0
|
||||||
|
} || {
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
function forget {
|
||||||
|
unset FOUND_PID;
|
||||||
|
[ $# -eq 3 ] || {
|
||||||
|
abort "forget requires parameters INSTANCE_NAME SCRIPT LOG_DIR"
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
local INSTANCE_NAME="$1"; shift
|
||||||
|
local SCRIPT="$1"; shift
|
||||||
|
local LOG_DIR="$1"; shift
|
||||||
|
mkdir -p $LOG_DIR
|
||||||
|
findPid $INSTANCE_NAME
|
||||||
|
[ -n "$FOUND_PID" ] && {
|
||||||
|
echo $INSTANCE_NAME already running pid [$FOUND_PID]
|
||||||
|
} || {
|
||||||
|
nohup $SCRIPT >$LOG_DIR/stdout.log 2>$LOG_DIR/stderr.log &
|
||||||
|
sleep 1
|
||||||
|
findPid $INSTANCE_NAME
|
||||||
|
[ -n "$FOUND_PID" ] || abort "$INSTANCE_NAME did not start"
|
||||||
|
}
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
export PATH=/usr/ucb/bin:/bin:/sbin:/usr/bin:/usr/sbin
|
||||||
|
case $1 in
|
||||||
|
init)
|
||||||
|
default || exit 1
|
||||||
|
runScriptWithCreds || exit 1
|
||||||
|
mkdir -p $INSTANCE_HOME
|
||||||
|
|
||||||
|
# create runscript header
|
||||||
|
cat > $INSTANCE_HOME/runScriptWithCreds.sh <<END_OF_SCRIPT
|
||||||
|
#!/bin/bash
|
||||||
|
set +u
|
||||||
|
shopt -s xpg_echo
|
||||||
|
shopt -s expand_aliases
|
||||||
|
PROMPT_COMMAND='echo -ne "\033]0;runScriptWithCreds\007"'
|
||||||
|
export PATH=/usr/ucb/bin:/bin:/sbin:/usr/bin:/usr/sbin
|
||||||
|
export INSTANCE_NAME='runScriptWithCreds'
|
||||||
|
export INSTANCE_NAME='$INSTANCE_NAME'
|
||||||
|
export INSTANCE_HOME='$INSTANCE_HOME'
|
||||||
|
export LOG_DIR='$LOG_DIR'
|
||||||
|
END_OF_SCRIPT
|
||||||
|
|
||||||
|
# add desired commands from the user
|
||||||
|
cat >> $INSTANCE_HOME/runScriptWithCreds.sh <<'END_OF_SCRIPT'
|
||||||
|
cd $INSTANCE_HOME
|
||||||
|
echo nameserver 208.67.222.222 >> /etc/resolv.conf
|
||||||
|
cp /etc/apt/sources.list /etc/apt/sources.list.old
|
||||||
|
sed 's~us.archive.ubuntu.com~mirror.anl.gov/pub~g' /etc/apt/sources.list.old >/etc/apt/sources.list
|
||||||
|
apt-get update
|
||||||
|
apt-get install -f -y --force-yes openjdk-6-jdk
|
||||||
|
|
||||||
|
|
||||||
|
END_OF_SCRIPT
|
||||||
|
|
||||||
|
# add runscript footer
|
||||||
|
cat >> $INSTANCE_HOME/runScriptWithCreds.sh <<'END_OF_SCRIPT'
|
||||||
|
exit 0
|
||||||
|
END_OF_SCRIPT
|
||||||
|
|
||||||
|
chmod u+x $INSTANCE_HOME/runScriptWithCreds.sh
|
||||||
|
;;
|
||||||
|
status)
|
||||||
|
default || exit 1
|
||||||
|
findPid $INSTANCE_NAME || exit 1
|
||||||
|
echo [$FOUND_PID]
|
||||||
|
;;
|
||||||
|
stop)
|
||||||
|
default || exit 1
|
||||||
|
findPid $INSTANCE_NAME || exit 1
|
||||||
|
[ -n "$FOUND_PID" ] && {
|
||||||
|
echo stopping $FOUND_PID
|
||||||
|
kill -9 $FOUND_PID
|
||||||
|
}
|
||||||
|
;;
|
||||||
|
start)
|
||||||
|
default || exit 1
|
||||||
|
forget $INSTANCE_NAME $INSTANCE_HOME/$INSTANCE_NAME.sh $LOG_DIR || exit 1
|
||||||
|
;;
|
||||||
|
tail)
|
||||||
|
default || exit 1
|
||||||
|
tail $LOG_DIR/stdout.log
|
||||||
|
;;
|
||||||
|
tailerr)
|
||||||
|
default || exit 1
|
||||||
|
tail $LOG_DIR/stderr.log
|
||||||
|
;;
|
||||||
|
run)
|
||||||
|
default || exit 1
|
||||||
|
$INSTANCE_HOME/$INSTANCE_NAME.sh
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
exit 0
|
|
@ -32,6 +32,7 @@ import org.jclouds.scriptbuilder.util.Utils;
|
||||||
|
|
||||||
import com.google.common.annotations.VisibleForTesting;
|
import com.google.common.annotations.VisibleForTesting;
|
||||||
import com.google.common.base.Function;
|
import com.google.common.base.Function;
|
||||||
|
import com.google.common.collect.ImmutableSet;
|
||||||
import com.google.common.collect.Iterables;
|
import com.google.common.collect.Iterables;
|
||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
import com.google.common.collect.Maps;
|
import com.google.common.collect.Maps;
|
||||||
|
@ -41,7 +42,7 @@ import com.google.common.collect.Maps;
|
||||||
*
|
*
|
||||||
* @author Adrian Cole
|
* @author Adrian Cole
|
||||||
*/
|
*/
|
||||||
public class ScriptBuilder {
|
public class ScriptBuilder implements Statement {
|
||||||
|
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
List<Statement> statements = Lists.newArrayList();
|
List<Statement> statements = Lists.newArrayList();
|
||||||
|
@ -69,8 +70,7 @@ public class ScriptBuilder {
|
||||||
* Exports a variable inside the script
|
* Exports a variable inside the script
|
||||||
*/
|
*/
|
||||||
public ScriptBuilder addEnvironmentVariableScope(String scopeName, Map<String, String> variables) {
|
public ScriptBuilder addEnvironmentVariableScope(String scopeName, Map<String, String> variables) {
|
||||||
variableScopes
|
variableScopes.put(checkNotNull(scopeName, "scopeName"), checkNotNull(variables, "variables"));
|
||||||
.put(checkNotNull(scopeName, "scopeName"), checkNotNull(variables, "variables"));
|
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -85,19 +85,21 @@ public class ScriptBuilder {
|
||||||
* @param osFamily
|
* @param osFamily
|
||||||
* whether to write a cmd or bash script.
|
* whether to write a cmd or bash script.
|
||||||
*/
|
*/
|
||||||
public String build(final OsFamily osFamily) {
|
|
||||||
|
@Override
|
||||||
|
public String render(OsFamily osFamily) {
|
||||||
Map<String, String> functions = Maps.newLinkedHashMap();
|
Map<String, String> functions = Maps.newLinkedHashMap();
|
||||||
functions.put("abort", Utils.writeFunctionFromResource("abort", osFamily));
|
functions.put("abort", Utils.writeFunctionFromResource("abort", osFamily));
|
||||||
|
|
||||||
for (Entry<String, Map<String, String>> entry : variableScopes.entrySet()) {
|
for (Entry<String, Map<String, String>> entry : variableScopes.entrySet()) {
|
||||||
functions.put(entry.getKey(), Utils.writeFunction(entry.getKey(), Utils
|
functions.put(entry.getKey(), Utils.writeFunction(entry.getKey(), Utils.writeVariableExporters(entry
|
||||||
.writeVariableExporters(entry.getValue())));
|
.getValue())));
|
||||||
}
|
}
|
||||||
final Map<String, String> tokenValueMap = ShellToken.tokenValueMap(osFamily);
|
final Map<String, String> tokenValueMap = ShellToken.tokenValueMap(osFamily);
|
||||||
StringBuilder builder = new StringBuilder();
|
StringBuilder builder = new StringBuilder();
|
||||||
builder.append(ShellToken.BEGIN_SCRIPT.to(osFamily));
|
builder.append(ShellToken.BEGIN_SCRIPT.to(osFamily));
|
||||||
builder.append(Utils.writeUnsetVariables(Lists.newArrayList(Iterables.transform(
|
builder.append(Utils.writeUnsetVariables(Lists.newArrayList(Iterables.transform(variablesToUnset,
|
||||||
variablesToUnset, new Function<String, String>() {
|
new Function<String, String>() {
|
||||||
@Override
|
@Override
|
||||||
public String apply(String from) {
|
public String apply(String from) {
|
||||||
if (tokenValueMap.containsKey(from + "Variable"))
|
if (tokenValueMap.containsKey(from + "Variable"))
|
||||||
|
@ -141,4 +143,9 @@ public class ScriptBuilder {
|
||||||
functions.put(functionName, Utils.writeFunctionFromResource(functionName, osFamily));
|
functions.put(functionName, Utils.writeFunctionFromResource(functionName, osFamily));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Iterable<String> functionDependecies(OsFamily family) {
|
||||||
|
return ImmutableSet.<String> of();
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -39,12 +39,12 @@ import com.google.common.collect.Maps;
|
||||||
*
|
*
|
||||||
* @author Adrian Cole
|
* @author Adrian Cole
|
||||||
*/
|
*/
|
||||||
public class CreateFile implements Statement {
|
public class AppendFile implements Statement {
|
||||||
public final static String MARKER = "END_OF_FILE";
|
public final static String MARKER = "END_OF_FILE";
|
||||||
final String path;
|
final String path;
|
||||||
final Iterable<String> lines;
|
final Iterable<String> lines;
|
||||||
|
|
||||||
public CreateFile(String path, Iterable<String> lines) {// TODO: convert so
|
public AppendFile(String path, Iterable<String> lines) {// TODO: convert so
|
||||||
this.path = checkNotNull(path, "path");
|
this.path = checkNotNull(path, "path");
|
||||||
this.lines = checkNotNull(lines, "lines");
|
this.lines = checkNotNull(lines, "lines");
|
||||||
checkState(Iterables.size(lines) > 0, "you must pass something to execute");
|
checkState(Iterables.size(lines) > 0, "you must pass something to execute");
|
||||||
|
@ -77,7 +77,6 @@ public class CreateFile implements Statement {
|
||||||
hereFile(path, builder);
|
hereFile(path, builder);
|
||||||
statements.add(interpret(builder.toString()));
|
statements.add(interpret(builder.toString()));
|
||||||
} else {
|
} else {
|
||||||
statements.add(interpret(String.format("{rm} %s 2{closeFd}{lf}", path)));
|
|
||||||
for (String line : lines) {
|
for (String line : lines) {
|
||||||
statements.add(appendToFile(line, path, family));
|
statements.add(appendToFile(line, path, family));
|
||||||
}
|
}
|
||||||
|
@ -86,7 +85,7 @@ public class CreateFile implements Statement {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void hereFile(String path, StringBuilder builder) {
|
private void hereFile(String path, StringBuilder builder) {
|
||||||
builder.append("cat > ").append(path).append(" <<'").append(MARKER).append("'\n");
|
builder.append("cat >> ").append(path).append(" <<'").append(MARKER).append("'\n");
|
||||||
for (String line : lines) {
|
for (String line : lines) {
|
||||||
builder.append(line).append("\n");
|
builder.append(line).append("\n");
|
||||||
}
|
}
|
|
@ -0,0 +1,56 @@
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||||
|
*
|
||||||
|
* ====================================================================
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
* ====================================================================
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.jclouds.scriptbuilder.domain;
|
||||||
|
|
||||||
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
|
import static org.jclouds.scriptbuilder.domain.Statements.appendFile;
|
||||||
|
import static org.jclouds.scriptbuilder.domain.Statements.exec;
|
||||||
|
|
||||||
|
import java.util.Collections;
|
||||||
|
|
||||||
|
import com.google.common.base.Splitter;
|
||||||
|
import com.google.common.collect.ImmutableList;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author Adrian Cole
|
||||||
|
*/
|
||||||
|
public class AuthorizeRSAPublicKey implements Statement {
|
||||||
|
|
||||||
|
private final String publicKey;
|
||||||
|
|
||||||
|
public AuthorizeRSAPublicKey(String publicKey) {
|
||||||
|
this.publicKey = checkNotNull(publicKey, "publicKey");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Iterable<String> functionDependecies(OsFamily family) {
|
||||||
|
return Collections.emptyList();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String render(OsFamily family) {
|
||||||
|
checkNotNull(family, "family");
|
||||||
|
if (family == OsFamily.WINDOWS)
|
||||||
|
throw new UnsupportedOperationException("windows not yet implemented");
|
||||||
|
return new StatementList(ImmutableList.of(exec("{md} .ssh"), appendFile(".ssh/authorized_keys", Splitter.on('\n')
|
||||||
|
.split(publicKey)), exec("chmod 600 .ssh/authorized_keys"))).render(family);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,57 @@
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||||
|
*
|
||||||
|
* ====================================================================
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
* ====================================================================
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.jclouds.scriptbuilder.domain;
|
||||||
|
|
||||||
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
|
import static org.jclouds.scriptbuilder.domain.Statements.appendFile;
|
||||||
|
import static org.jclouds.scriptbuilder.domain.Statements.exec;
|
||||||
|
import static org.jclouds.scriptbuilder.domain.Statements.rm;
|
||||||
|
|
||||||
|
import java.util.Collections;
|
||||||
|
|
||||||
|
import com.google.common.base.Splitter;
|
||||||
|
import com.google.common.collect.ImmutableList;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author Adrian Cole
|
||||||
|
*/
|
||||||
|
public class InstallRSAPrivateKey implements Statement {
|
||||||
|
|
||||||
|
private final String privateKey;
|
||||||
|
|
||||||
|
public InstallRSAPrivateKey(String privateKey) {
|
||||||
|
this.privateKey = checkNotNull(privateKey, "privateKey");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Iterable<String> functionDependecies(OsFamily family) {
|
||||||
|
return Collections.emptyList();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String render(OsFamily family) {
|
||||||
|
checkNotNull(family, "family");
|
||||||
|
if (family == OsFamily.WINDOWS)
|
||||||
|
throw new UnsupportedOperationException("windows not yet implemented");
|
||||||
|
return new StatementList(ImmutableList.of(exec("{md} .ssh"), rm(".ssh/id_rsa"), appendFile(".ssh/id_rsa", Splitter.on('\n')
|
||||||
|
.split(privateKey)), exec("chmod 600 .ssh/id_rsa"))).render(family);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,59 @@
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||||
|
*
|
||||||
|
* ====================================================================
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
* ====================================================================
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.jclouds.scriptbuilder.domain;
|
||||||
|
|
||||||
|
import java.net.URI;
|
||||||
|
import java.util.Map.Entry;
|
||||||
|
|
||||||
|
import com.google.common.base.Function;
|
||||||
|
import com.google.common.base.Joiner;
|
||||||
|
import com.google.common.collect.Iterables;
|
||||||
|
import com.google.common.collect.Multimap;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* saves the content of the http response to a file
|
||||||
|
*
|
||||||
|
* @author Adrian Cole
|
||||||
|
*/
|
||||||
|
public class SaveHttpResponseTo extends InterpretableStatement {
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param dir
|
||||||
|
* location to save file
|
||||||
|
* @param method
|
||||||
|
* http method: ex GET
|
||||||
|
* @param endpoint
|
||||||
|
* uri corresponding to the request
|
||||||
|
* @param headers
|
||||||
|
* request headers to send
|
||||||
|
*/
|
||||||
|
public SaveHttpResponseTo(String dir, String file, String method, URI endpoint, Multimap<String, String> headers) {
|
||||||
|
super(String.format("({md} %s &&{cd} %s &&curl -X %s -s --retry 20 %s %s >%s\n", dir, dir, method, Joiner.on(' ')
|
||||||
|
.join(Iterables.transform(headers.entries(), new Function<Entry<String, String>, String>() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String apply(Entry<String, String> from) {
|
||||||
|
return String.format("-H \"%s: %s\"", from.getKey(), from.getValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
})), endpoint.toASCIIString(), file));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -22,6 +22,7 @@ package org.jclouds.scriptbuilder.domain;
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
import com.google.common.collect.ImmutableList;
|
||||||
import com.google.common.collect.Multimap;
|
import com.google.common.collect.Multimap;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -40,12 +41,31 @@ public class Statements {
|
||||||
return new SwitchArg(arg, valueToActions);
|
return new SwitchArg(arg, valueToActions);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static Statement rm(final String path) {
|
||||||
|
return new Statement() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Iterable<String> functionDependecies(OsFamily family) {
|
||||||
|
return ImmutableList.of();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String render(OsFamily family) {
|
||||||
|
if (family == OsFamily.WINDOWS)
|
||||||
|
return exec(String.format("{rm} %s 2{closeFd}", path)).render(family);
|
||||||
|
else
|
||||||
|
return exec(String.format("{rm} %s", path)).render(family);
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
public static Statement call(String function, String... args) {
|
public static Statement call(String function, String... args) {
|
||||||
return new Call(function, args);
|
return new Call(function, args);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Statement createFile(String path, Iterable<String> lines) {
|
public static Statement appendFile(String path, Iterable<String> lines) {
|
||||||
return new CreateFile(path, lines);
|
return new AppendFile(path, lines);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Statement createRunScript(String instanceName, Iterable<String> exports, String pwd,
|
public static Statement createRunScript(String instanceName, Iterable<String> exports, String pwd,
|
||||||
|
@ -120,10 +140,27 @@ public class Statements {
|
||||||
* uri corresponding to the request
|
* uri corresponding to the request
|
||||||
* @param headers
|
* @param headers
|
||||||
* request headers to send
|
* request headers to send
|
||||||
|
* @param directory
|
||||||
*/
|
*/
|
||||||
public static Statement extractTargzIntoDirectory(String method, URI endpoint, Multimap<String, String> headers,
|
public static Statement extractTargzIntoDirectory(String method, URI endpoint, Multimap<String, String> headers,
|
||||||
String directory) {
|
String directory) {
|
||||||
return new PipeHttpResponseToTarxpzfIntoDirectory( method, endpoint, headers,directory);
|
return new PipeHttpResponseToTarxpzfIntoDirectory(method, endpoint, headers, directory);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* unzip the data received from the request parameters.
|
||||||
|
*
|
||||||
|
* @param method
|
||||||
|
* http method: ex GET
|
||||||
|
* @param endpoint
|
||||||
|
* uri corresponding to the request
|
||||||
|
* @param headers
|
||||||
|
* request headers to send
|
||||||
|
* @param directory
|
||||||
|
*/
|
||||||
|
public static Statement extractZipIntoDirectory(String method, URI endpoint, Multimap<String, String> headers,
|
||||||
|
String directory) {
|
||||||
|
return new UnzipHttpResponseIntoDirectory(method, endpoint, headers, directory);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -99,7 +99,7 @@ public class SwitchArg implements Statement {
|
||||||
inRunScript = inRunScript ? false : true;
|
inRunScript = inRunScript ? false : true;
|
||||||
|
|
||||||
}
|
}
|
||||||
if (line.indexOf(CreateFile.MARKER) != -1) {
|
if (line.indexOf(AppendFile.MARKER) != -1) {
|
||||||
inCreateFile = inCreateFile ? false : true;
|
inCreateFile = inCreateFile ? false : true;
|
||||||
}
|
}
|
||||||
shouldIndent = !inCreateFile && !inRunScript;
|
shouldIndent = !inCreateFile && !inRunScript;
|
||||||
|
|
|
@ -0,0 +1,62 @@
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||||
|
*
|
||||||
|
* ====================================================================
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
* ====================================================================
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.jclouds.scriptbuilder.domain;
|
||||||
|
|
||||||
|
import static com.google.common.collect.Iterables.transform;
|
||||||
|
import static java.lang.String.format;
|
||||||
|
|
||||||
|
import java.net.URI;
|
||||||
|
import java.util.Map.Entry;
|
||||||
|
|
||||||
|
import com.google.common.base.Function;
|
||||||
|
import com.google.common.base.Joiner;
|
||||||
|
import com.google.common.collect.Multimap;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* unzips the content into a directory
|
||||||
|
*
|
||||||
|
* @author Adrian Cole
|
||||||
|
*/
|
||||||
|
public class UnzipHttpResponseIntoDirectory extends InterpretableStatement {
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @param method
|
||||||
|
* http method: ex GET
|
||||||
|
* @param endpoint
|
||||||
|
* uri corresponding to the request
|
||||||
|
* @param headers
|
||||||
|
* request headers to send
|
||||||
|
*/
|
||||||
|
public UnzipHttpResponseIntoDirectory(String method, URI endpoint, Multimap<String, String> headers, String dir) {
|
||||||
|
super(
|
||||||
|
format(
|
||||||
|
"({md} %s &&{cd} %s &&curl -X %s -s --retry 20 %s %s >extract.zip && unzip -qq extract.zip&& rm extract.zip)\n",
|
||||||
|
dir, dir, method, Joiner.on(' ').join(
|
||||||
|
transform(headers.entries(), new Function<Entry<String, String>, String>() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String apply(Entry<String, String> from) {
|
||||||
|
return String.format("-H \"%s: %s\"", from.getKey(), from.getValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
})), endpoint.toASCIIString()));
|
||||||
|
}
|
||||||
|
}
|
|
@ -20,7 +20,7 @@
|
||||||
package org.jclouds.scriptbuilder;
|
package org.jclouds.scriptbuilder;
|
||||||
|
|
||||||
import static org.jclouds.scriptbuilder.domain.Statements.call;
|
import static org.jclouds.scriptbuilder.domain.Statements.call;
|
||||||
import static org.jclouds.scriptbuilder.domain.Statements.createFile;
|
import static org.jclouds.scriptbuilder.domain.Statements.appendFile;
|
||||||
import static org.testng.Assert.assertEquals;
|
import static org.testng.Assert.assertEquals;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
@ -47,17 +47,17 @@ public class InitBuilderTest {
|
||||||
|
|
||||||
InitBuilder testInitBuilder = new InitBuilder("mkebsboot", "/mnt/tmp", "/mnt/tmp", ImmutableMap.of("tmpDir",
|
InitBuilder testInitBuilder = new InitBuilder("mkebsboot", "/mnt/tmp", "/mnt/tmp", ImmutableMap.of("tmpDir",
|
||||||
"/mnt/tmp"), ImmutableList.<Statement> of(
|
"/mnt/tmp"), ImmutableList.<Statement> of(
|
||||||
createFile("{tmp}{fs}{uid}{fs}scripttest{fs}temp.txt", ImmutableList.<String> of("hello world")), call("find /")));
|
appendFile("{tmp}{fs}{uid}{fs}scripttest{fs}temp.txt", ImmutableList.<String> of("hello world")), call("find /")));
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testBuildSimpleWindows() throws MalformedURLException, IOException {
|
public void testBuildSimpleWindows() throws MalformedURLException, IOException {
|
||||||
assertEquals(testInitBuilder.build(OsFamily.WINDOWS), CharStreams.toString(Resources.newReaderSupplier(Resources
|
assertEquals(testInitBuilder.render(OsFamily.WINDOWS), CharStreams.toString(Resources.newReaderSupplier(Resources
|
||||||
.getResource("test_init." + ShellToken.SH.to(OsFamily.WINDOWS)), Charsets.UTF_8)));
|
.getResource("test_init." + ShellToken.SH.to(OsFamily.WINDOWS)), Charsets.UTF_8)));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testBuildSimpleUNIX() throws MalformedURLException, IOException {
|
public void testBuildSimpleUNIX() throws MalformedURLException, IOException {
|
||||||
assertEquals(testInitBuilder.build(OsFamily.UNIX), CharStreams.toString(Resources.newReaderSupplier(Resources
|
assertEquals(testInitBuilder.render(OsFamily.UNIX), CharStreams.toString(Resources.newReaderSupplier(Resources
|
||||||
.getResource("test_init." + ShellToken.SH.to(OsFamily.UNIX)), Charsets.UTF_8)));
|
.getResource("test_init." + ShellToken.SH.to(OsFamily.UNIX)), Charsets.UTF_8)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -87,7 +87,7 @@ public class InitBuilderTest {
|
||||||
"tar -cSf - * | tar xf - -C {varl}EBS_MOUNT_POINT{varr}", "echo size of ebs",
|
"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}",
|
"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 ----COMPLETE----")
|
"rm -rf {varl}IMAGE_DIR{varr}/*", "umount {varl}EBS_MOUNT_POINT{varr}", "echo ----COMPLETE----")
|
||||||
)).build(OsFamily.UNIX), CharStreams.toString(Resources.newReaderSupplier(Resources
|
)).render(OsFamily.UNIX), CharStreams.toString(Resources.newReaderSupplier(Resources
|
||||||
.getResource("test_ebs." + ShellToken.SH.to(OsFamily.UNIX)), Charsets.UTF_8)));
|
.getResource("test_ebs." + ShellToken.SH.to(OsFamily.UNIX)), Charsets.UTF_8)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,7 +20,7 @@
|
||||||
package org.jclouds.scriptbuilder;
|
package org.jclouds.scriptbuilder;
|
||||||
|
|
||||||
import static org.jclouds.scriptbuilder.domain.Statements.call;
|
import static org.jclouds.scriptbuilder.domain.Statements.call;
|
||||||
import static org.jclouds.scriptbuilder.domain.Statements.createFile;
|
import static org.jclouds.scriptbuilder.domain.Statements.appendFile;
|
||||||
import static org.jclouds.scriptbuilder.domain.Statements.findPid;
|
import static org.jclouds.scriptbuilder.domain.Statements.findPid;
|
||||||
import static org.jclouds.scriptbuilder.domain.Statements.interpret;
|
import static org.jclouds.scriptbuilder.domain.Statements.interpret;
|
||||||
import static org.jclouds.scriptbuilder.domain.Statements.kill;
|
import static org.jclouds.scriptbuilder.domain.Statements.kill;
|
||||||
|
@ -65,19 +65,19 @@ public class ScriptBuilderTest {
|
||||||
interpret("echo stop {varl}RUNTIME{varr}{lf}")),
|
interpret("echo stop {varl}RUNTIME{varr}{lf}")),
|
||||||
"status",
|
"status",
|
||||||
newStatementList(
|
newStatementList(
|
||||||
createFile("{tmp}{fs}{uid}{fs}scripttest{fs}temp.txt",
|
appendFile("{tmp}{fs}{uid}{fs}scripttest{fs}temp.txt",
|
||||||
ImmutableList.<String> of("hello world")),
|
ImmutableList.<String> of("hello world")),
|
||||||
interpret("echo {vq}the following should be []: [{varl}RUNTIME{varr}]{vq}{lf}")))));
|
interpret("echo {vq}the following should be []: [{varl}RUNTIME{varr}]{vq}{lf}")))));
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testBuildSimpleWindows() throws MalformedURLException, IOException {
|
public void testBuildSimpleWindows() throws MalformedURLException, IOException {
|
||||||
assertEquals(testScriptBuilder.build(OsFamily.WINDOWS), CharStreams.toString(Resources.newReaderSupplier(
|
assertEquals(testScriptBuilder.render(OsFamily.WINDOWS), CharStreams.toString(Resources.newReaderSupplier(
|
||||||
Resources.getResource("test_script." + ShellToken.SH.to(OsFamily.WINDOWS)), Charsets.UTF_8)));
|
Resources.getResource("test_script." + ShellToken.SH.to(OsFamily.WINDOWS)), Charsets.UTF_8)));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testBuildSimpleUNIX() throws MalformedURLException, IOException {
|
public void testBuildSimpleUNIX() throws MalformedURLException, IOException {
|
||||||
assertEquals(testScriptBuilder.build(OsFamily.UNIX), CharStreams.toString(Resources.newReaderSupplier(Resources
|
assertEquals(testScriptBuilder.render(OsFamily.UNIX), CharStreams.toString(Resources.newReaderSupplier(Resources
|
||||||
.getResource("test_script." + ShellToken.SH.to(OsFamily.UNIX)), Charsets.UTF_8)));
|
.getResource("test_script." + ShellToken.SH.to(OsFamily.UNIX)), Charsets.UTF_8)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -86,13 +86,13 @@ public class ScriptBuilderTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testFindPidWindows() throws MalformedURLException, IOException {
|
public void testFindPidWindows() throws MalformedURLException, IOException {
|
||||||
assertEquals(findPidBuilder.build(OsFamily.WINDOWS), CharStreams.toString(Resources.newReaderSupplier(Resources
|
assertEquals(findPidBuilder.render(OsFamily.WINDOWS), CharStreams.toString(Resources.newReaderSupplier(Resources
|
||||||
.getResource("test_find_pid." + ShellToken.SH.to(OsFamily.WINDOWS)), Charsets.UTF_8)));
|
.getResource("test_find_pid." + ShellToken.SH.to(OsFamily.WINDOWS)), Charsets.UTF_8)));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testFindPidUNIX() throws MalformedURLException, IOException {
|
public void testFindPidUNIX() throws MalformedURLException, IOException {
|
||||||
assertEquals(findPidBuilder.build(OsFamily.UNIX), CharStreams.toString(Resources.newReaderSupplier(Resources
|
assertEquals(findPidBuilder.render(OsFamily.UNIX), CharStreams.toString(Resources.newReaderSupplier(Resources
|
||||||
.getResource("test_find_pid." + ShellToken.SH.to(OsFamily.UNIX)), Charsets.UTF_8)));
|
.getResource("test_find_pid." + ShellToken.SH.to(OsFamily.UNIX)), Charsets.UTF_8)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -100,13 +100,13 @@ public class ScriptBuilderTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSeekAndDestroyWindows() throws MalformedURLException, IOException {
|
public void testSeekAndDestroyWindows() throws MalformedURLException, IOException {
|
||||||
assertEquals(seekAndDestroyBuilder.build(OsFamily.WINDOWS), CharStreams.toString(Resources.newReaderSupplier(
|
assertEquals(seekAndDestroyBuilder.render(OsFamily.WINDOWS), CharStreams.toString(Resources.newReaderSupplier(
|
||||||
Resources.getResource("test_seek_and_destroy." + ShellToken.SH.to(OsFamily.WINDOWS)), Charsets.UTF_8)));
|
Resources.getResource("test_seek_and_destroy." + ShellToken.SH.to(OsFamily.WINDOWS)), Charsets.UTF_8)));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSeekAndDestroyUNIX() throws MalformedURLException, IOException {
|
public void testSeekAndDestroyUNIX() throws MalformedURLException, IOException {
|
||||||
assertEquals(seekAndDestroyBuilder.build(OsFamily.UNIX), CharStreams.toString(Resources.newReaderSupplier(
|
assertEquals(seekAndDestroyBuilder.render(OsFamily.UNIX), CharStreams.toString(Resources.newReaderSupplier(
|
||||||
Resources.getResource("test_seek_and_destroy." + ShellToken.SH.to(OsFamily.UNIX)), Charsets.UTF_8)));
|
Resources.getResource("test_seek_and_destroy." + ShellToken.SH.to(OsFamily.UNIX)), Charsets.UTF_8)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -19,7 +19,7 @@
|
||||||
|
|
||||||
package org.jclouds.scriptbuilder.domain;
|
package org.jclouds.scriptbuilder.domain;
|
||||||
|
|
||||||
import static org.jclouds.scriptbuilder.domain.Statements.createFile;
|
import static org.jclouds.scriptbuilder.domain.Statements.appendFile;
|
||||||
import static org.testng.Assert.assertEquals;
|
import static org.testng.Assert.assertEquals;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
@ -34,9 +34,9 @@ import com.google.common.io.Resources;
|
||||||
/**
|
/**
|
||||||
* @author Adrian Cole
|
* @author Adrian Cole
|
||||||
*/
|
*/
|
||||||
@Test(groups = "unit", testName = "scriptbuilder.CreateFileTest")
|
@Test(groups = "unit", testName = "scriptbuilder.AppendFileTest")
|
||||||
public class CreateFileTest {
|
public class AppendFileTest {
|
||||||
Statement statement = createFile("{root}etc{fs}chef{fs}client.rb", ImmutableList.of("log_level :info",
|
Statement statement = appendFile("{root}etc{fs}chef{fs}client.rb", ImmutableList.of("log_level :info",
|
||||||
"log_location STDOUT", String.format("chef_server_url \"%s\"", "http://localhost:4000")));
|
"log_location STDOUT", String.format("chef_server_url \"%s\"", "http://localhost:4000")));
|
||||||
|
|
||||||
public void testUNIX() throws IOException {
|
public void testUNIX() throws IOException {
|
||||||
|
@ -50,10 +50,10 @@ public class CreateFileTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testRedirectGuard() {
|
public void testRedirectGuard() {
|
||||||
assertEquals(CreateFile.addSpaceToEnsureWeDontAccidentallyRedirectFd("foo>>"), "foo>>");
|
assertEquals(AppendFile.addSpaceToEnsureWeDontAccidentallyRedirectFd("foo>>"), "foo>>");
|
||||||
assertEquals(CreateFile.addSpaceToEnsureWeDontAccidentallyRedirectFd("foo0>>"), "foo0 >>");
|
assertEquals(AppendFile.addSpaceToEnsureWeDontAccidentallyRedirectFd("foo0>>"), "foo0 >>");
|
||||||
assertEquals(CreateFile.addSpaceToEnsureWeDontAccidentallyRedirectFd("foo1>>"), "foo1 >>");
|
assertEquals(AppendFile.addSpaceToEnsureWeDontAccidentallyRedirectFd("foo1>>"), "foo1 >>");
|
||||||
assertEquals(CreateFile.addSpaceToEnsureWeDontAccidentallyRedirectFd("foo2>>"), "foo2 >>");
|
assertEquals(AppendFile.addSpaceToEnsureWeDontAccidentallyRedirectFd("foo2>>"), "foo2 >>");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -0,0 +1,43 @@
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||||
|
*
|
||||||
|
* ====================================================================
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
* ====================================================================
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.jclouds.scriptbuilder.domain;
|
||||||
|
|
||||||
|
import static org.testng.Assert.assertEquals;
|
||||||
|
|
||||||
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Adrian Cole
|
||||||
|
*/
|
||||||
|
@Test(groups = "unit", testName = "scriptbuilder.AuthorizeRSAPublicKeyTest")
|
||||||
|
public class CopyOfAuthorizeRSAPublicKeyTest {
|
||||||
|
|
||||||
|
AuthorizeRSAPublicKey auth = new AuthorizeRSAPublicKey("ssh-dss AAAAB");
|
||||||
|
|
||||||
|
public void testAuthorizeRSAPublicKeyUNIX() {
|
||||||
|
assertEquals(
|
||||||
|
auth.render(OsFamily.UNIX),
|
||||||
|
"mkdir -p .ssh\ncat >> .ssh/authorized_keys <<'END_OF_FILE'\nssh-dss AAAAB\nEND_OF_FILE\nchmod 600 .ssh/authorized_keys\n"); }
|
||||||
|
|
||||||
|
@Test(expectedExceptions = UnsupportedOperationException.class)
|
||||||
|
public void testAuthorizeRSAPublicKeyWINDOWS() {
|
||||||
|
auth.render(OsFamily.WINDOWS);
|
||||||
|
}
|
||||||
|
}
|
|
@ -20,7 +20,7 @@
|
||||||
package org.jclouds.scriptbuilder.domain;
|
package org.jclouds.scriptbuilder.domain;
|
||||||
|
|
||||||
import static org.jclouds.scriptbuilder.domain.Statements.call;
|
import static org.jclouds.scriptbuilder.domain.Statements.call;
|
||||||
import static org.jclouds.scriptbuilder.domain.Statements.createFile;
|
import static org.jclouds.scriptbuilder.domain.Statements.appendFile;
|
||||||
import static org.jclouds.scriptbuilder.domain.Statements.createRunScript;
|
import static org.jclouds.scriptbuilder.domain.Statements.createRunScript;
|
||||||
import static org.testng.Assert.assertEquals;
|
import static org.testng.Assert.assertEquals;
|
||||||
|
|
||||||
|
@ -45,7 +45,7 @@ public class CreateRunScriptTest {
|
||||||
ImmutableList
|
ImmutableList
|
||||||
.<Statement> of(
|
.<Statement> of(
|
||||||
call("echo hello"),
|
call("echo hello"),
|
||||||
createFile("{tmp}{fs}{uid}{fs}scripttest{fs}temp.txt", ImmutableList
|
appendFile("{tmp}{fs}{uid}{fs}scripttest{fs}temp.txt", ImmutableList
|
||||||
.<String> of("hello world")),
|
.<String> of("hello world")),
|
||||||
call("echo {varl}JAVA_HOME{varr}{fs}bin{fs}java -DinstanceName={varl}INSTANCE_NAME{varr} myServer.Main")));
|
call("echo {varl}JAVA_HOME{varr}{fs}bin{fs}java -DinstanceName={varl}INSTANCE_NAME{varr} myServer.Main")));
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,44 @@
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||||
|
*
|
||||||
|
* ====================================================================
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
* ====================================================================
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.jclouds.scriptbuilder.domain;
|
||||||
|
|
||||||
|
import static org.testng.Assert.assertEquals;
|
||||||
|
|
||||||
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Adrian Cole
|
||||||
|
*/
|
||||||
|
@Test(groups = "unit", testName = "scriptbuilder.InstallRSAPrivateKeyTest")
|
||||||
|
public class InstallRSAPrivateKeyTest {
|
||||||
|
|
||||||
|
InstallRSAPrivateKey key = new InstallRSAPrivateKey("-----BEGIN RSA PRIVATE KEY-----\n-----END RSA PRIVATE KEY-----\n");
|
||||||
|
|
||||||
|
public void testInstallRSAPrivateKeyUNIX() {
|
||||||
|
assertEquals(
|
||||||
|
key.render(OsFamily.UNIX),
|
||||||
|
"mkdir -p .ssh\nrm .ssh/id_rsa\ncat >> .ssh/id_rsa <<'END_OF_FILE'\n-----BEGIN RSA PRIVATE KEY-----\n-----END RSA PRIVATE KEY-----\n\nEND_OF_FILE\nchmod 600 .ssh/id_rsa\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(expectedExceptions = UnsupportedOperationException.class)
|
||||||
|
public void testInstallRSAPrivateKeyWINDOWS() {
|
||||||
|
key.render(OsFamily.WINDOWS);
|
||||||
|
}
|
||||||
|
}
|
|
@ -19,7 +19,7 @@
|
||||||
|
|
||||||
package org.jclouds.scriptbuilder.domain;
|
package org.jclouds.scriptbuilder.domain;
|
||||||
|
|
||||||
import static org.jclouds.scriptbuilder.domain.Statements.createFile;
|
import static org.jclouds.scriptbuilder.domain.Statements.appendFile;
|
||||||
import static org.jclouds.scriptbuilder.domain.Statements.interpret;
|
import static org.jclouds.scriptbuilder.domain.Statements.interpret;
|
||||||
import static org.jclouds.scriptbuilder.domain.Statements.newStatementList;
|
import static org.jclouds.scriptbuilder.domain.Statements.newStatementList;
|
||||||
import static org.testng.Assert.assertEquals;
|
import static org.testng.Assert.assertEquals;
|
||||||
|
@ -37,10 +37,10 @@ import com.google.common.collect.ImmutableMap;
|
||||||
public class SwitchArgTest {
|
public class SwitchArgTest {
|
||||||
|
|
||||||
public void testSwitchArgUNIX() {
|
public void testSwitchArgUNIX() {
|
||||||
assertEquals(new SwitchArg(1, ImmutableMap.of("0", newStatementList(createFile(
|
assertEquals(new SwitchArg(1, ImmutableMap.of("0", newStatementList(appendFile(
|
||||||
"{tmp}{fs}{uid}{fs}scripttest{fs}temp.txt", Collections.singleton("hello world")),
|
"{tmp}{fs}{uid}{fs}scripttest{fs}temp.txt", Collections.singleton("hello world")),
|
||||||
interpret("echo hello zero{lf}")), "1", interpret("echo hello one{lf}"))).render(OsFamily.UNIX),
|
interpret("echo hello zero{lf}")), "1", interpret("echo hello one{lf}"))).render(OsFamily.UNIX),
|
||||||
"case $1 in\n0)\n cat > /tmp/$USER/scripttest/temp.txt <<'END_OF_FILE'\nhello world\nEND_OF_FILE\n echo hello zero\n ;;\n1)\n echo hello one\n ;;\nesac\n");
|
"case $1 in\n0)\n cat >> /tmp/$USER/scripttest/temp.txt <<'END_OF_FILE'\nhello world\nEND_OF_FILE\n echo hello zero\n ;;\n1)\n echo hello one\n ;;\nesac\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testSwitchArgWindows() {
|
public void testSwitchArgWindows() {
|
||||||
|
|
|
@ -0,0 +1,50 @@
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||||
|
*
|
||||||
|
* ====================================================================
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
* ====================================================================
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.jclouds.scriptbuilder.domain;
|
||||||
|
|
||||||
|
import static org.testng.Assert.assertEquals;
|
||||||
|
|
||||||
|
import java.net.URI;
|
||||||
|
|
||||||
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
|
import com.google.common.collect.ImmutableMultimap;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Adrian Cole
|
||||||
|
*/
|
||||||
|
@Test(groups = "unit", testName = "scriptbuilder.UnzipHttpResponseIntoDirectoryToTest")
|
||||||
|
public class UnzipHttpResponseIntoDirectoryToTest {
|
||||||
|
|
||||||
|
UnzipHttpResponseIntoDirectory jboss = new UnzipHttpResponseIntoDirectory(
|
||||||
|
"GET",
|
||||||
|
URI
|
||||||
|
.create("http://superb-sea2.dl.sourceforge.net/project/jboss/JBoss/JBoss-5.0.0.CR2/jboss-5.0.0.CR2-jdk6.zip"),
|
||||||
|
ImmutableMultimap.<String, String> of(), "/tmp");
|
||||||
|
|
||||||
|
public void testUnzipHttpResponseIntoDirectoryUNIX() {
|
||||||
|
assertEquals(
|
||||||
|
jboss.render(OsFamily.UNIX),
|
||||||
|
"(mkdir -p /tmp &&cd /tmp &&curl -X GET -s --retry 20 http://superb-sea2.dl.sourceforge.net/project/jboss/JBoss/JBoss-5.0.0.CR2/jboss-5.0.0.CR2-jdk6.zip >extract.zip && unzip -qq extract.zip&& rm extract.zip)\n");
|
||||||
|
}
|
||||||
|
public void testUnzipHttpResponseIntoDirectoryWINDOWS() {
|
||||||
|
|
||||||
|
jboss.render(OsFamily.WINDOWS); }
|
||||||
|
}
|
|
@ -1,4 +1,3 @@
|
||||||
del c:\etc\chef\client.rb 2>NUL
|
|
||||||
echo log_level :info>>c:\etc\chef\client.rb
|
echo log_level :info>>c:\etc\chef\client.rb
|
||||||
echo log_location STDOUT>>c:\etc\chef\client.rb
|
echo log_location STDOUT>>c:\etc\chef\client.rb
|
||||||
echo chef_server_url "http://localhost:4000">>c:\etc\chef\client.rb
|
echo chef_server_url "http://localhost:4000">>c:\etc\chef\client.rb
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
cat > /etc/chef/client.rb <<'END_OF_FILE'
|
cat >> /etc/chef/client.rb <<'END_OF_FILE'
|
||||||
log_level :info
|
log_level :info
|
||||||
log_location STDOUT
|
log_location STDOUT
|
||||||
chef_server_url "http://localhost:4000"
|
chef_server_url "http://localhost:4000"
|
||||||
|
|
|
@ -78,7 +78,7 @@ END_OF_SCRIPT
|
||||||
# add desired commands from the user
|
# add desired commands from the user
|
||||||
cat >> $INSTANCE_HOME/mkebsboot.sh <<'END_OF_SCRIPT'
|
cat >> $INSTANCE_HOME/mkebsboot.sh <<'END_OF_SCRIPT'
|
||||||
cd $INSTANCE_HOME
|
cd $INSTANCE_HOME
|
||||||
cat > /tmp/$USER/scripttest/temp.txt <<'END_OF_FILE'
|
cat >> /tmp/$USER/scripttest/temp.txt <<'END_OF_FILE'
|
||||||
hello world
|
hello world
|
||||||
END_OF_FILE
|
END_OF_FILE
|
||||||
|
|
||||||
|
|
|
@ -17,7 +17,7 @@ cat >> /tmp/$USER/scripttest/yahooprod.sh <<'END_OF_SCRIPT'
|
||||||
cd /tmp/$USER/scripttest
|
cd /tmp/$USER/scripttest
|
||||||
echo hello || return 1
|
echo hello || return 1
|
||||||
|
|
||||||
cat > /tmp/$USER/scripttest/temp.txt <<'END_OF_FILE'
|
cat >> /tmp/$USER/scripttest/temp.txt <<'END_OF_FILE'
|
||||||
hello world
|
hello world
|
||||||
END_OF_FILE
|
END_OF_FILE
|
||||||
|
|
||||||
|
|
|
@ -28,7 +28,6 @@ goto CASE_%1
|
||||||
echo stop %RUNTIME%
|
echo stop %RUNTIME%
|
||||||
GOTO END_SWITCH
|
GOTO END_SWITCH
|
||||||
:CASE_status
|
:CASE_status
|
||||||
del %TEMP%\%USERNAME%\scripttest\temp.txt 2>NUL
|
|
||||||
echo hello world>>%TEMP%\%USERNAME%\scripttest\temp.txt
|
echo hello world>>%TEMP%\%USERNAME%\scripttest\temp.txt
|
||||||
echo the following should be []: [%RUNTIME%]
|
echo the following should be []: [%RUNTIME%]
|
||||||
GOTO END_SWITCH
|
GOTO END_SWITCH
|
||||||
|
|
|
@ -22,7 +22,7 @@ stop)
|
||||||
echo stop $RUNTIME
|
echo stop $RUNTIME
|
||||||
;;
|
;;
|
||||||
status)
|
status)
|
||||||
cat > /tmp/$USER/scripttest/temp.txt <<'END_OF_FILE'
|
cat >> /tmp/$USER/scripttest/temp.txt <<'END_OF_FILE'
|
||||||
hello world
|
hello world
|
||||||
END_OF_FILE
|
END_OF_FILE
|
||||||
echo "the following should be []: [$RUNTIME]"
|
echo "the following should be []: [$RUNTIME]"
|
||||||
|
|
|
@ -98,6 +98,8 @@ public class ComputeTask extends Task {
|
||||||
invokeActionOnService(act, context.getComputeService());
|
invokeActionOnService(act, context.getComputeService());
|
||||||
} catch (RunNodesException e) {
|
} catch (RunNodesException e) {
|
||||||
throw new BuildException(e);
|
throw new BuildException(e);
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new BuildException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
|
@ -105,7 +107,7 @@ public class ComputeTask extends Task {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void invokeActionOnService(Action action, ComputeService computeService) throws RunNodesException {
|
private void invokeActionOnService(Action action, ComputeService computeService) throws RunNodesException, IOException {
|
||||||
switch (action) {
|
switch (action) {
|
||||||
case CREATE:
|
case CREATE:
|
||||||
case GET:
|
case GET:
|
||||||
|
@ -191,7 +193,7 @@ public class ComputeTask extends Task {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void create(ComputeService computeService) throws RunNodesException {
|
private void create(ComputeService computeService) throws RunNodesException, IOException {
|
||||||
String tag = nodeElement.getTag();
|
String tag = nodeElement.getTag();
|
||||||
|
|
||||||
log(String.format("create tag: %s, count: %d, hardware: %s, os: %s", tag, nodeElement.getCount(), nodeElement
|
log(String.format("create tag: %s, count: %d, hardware: %s, os: %s", tag, nodeElement.getCount(), nodeElement
|
||||||
|
|
|
@ -21,6 +21,7 @@ package org.jclouds.tools.ant.taskdefs.compute;
|
||||||
|
|
||||||
import static org.jclouds.rest.RestContextFactory.getPropertiesFromResource;
|
import static org.jclouds.rest.RestContextFactory.getPropertiesFromResource;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.NoSuchElementException;
|
import java.util.NoSuchElementException;
|
||||||
|
@ -42,11 +43,13 @@ import org.jclouds.io.Payloads;
|
||||||
import org.jclouds.ssh.jsch.config.JschSshClientModule;
|
import org.jclouds.ssh.jsch.config.JschSshClientModule;
|
||||||
import org.jclouds.tools.ant.logging.config.AntLoggingModule;
|
import org.jclouds.tools.ant.logging.config.AntLoggingModule;
|
||||||
|
|
||||||
|
import com.google.common.base.Charsets;
|
||||||
import com.google.common.base.Function;
|
import com.google.common.base.Function;
|
||||||
import com.google.common.base.Splitter;
|
import com.google.common.base.Splitter;
|
||||||
import com.google.common.collect.ImmutableSet;
|
import com.google.common.collect.ImmutableSet;
|
||||||
import com.google.common.collect.Iterables;
|
import com.google.common.collect.Iterables;
|
||||||
import com.google.common.collect.MapMaker;
|
import com.google.common.collect.MapMaker;
|
||||||
|
import com.google.common.io.Files;
|
||||||
import com.google.inject.Module;
|
import com.google.inject.Module;
|
||||||
import com.google.inject.Provider;
|
import com.google.inject.Provider;
|
||||||
|
|
||||||
|
@ -58,12 +61,12 @@ public class ComputeTaskUtils {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* Creates a Map that associates a uri with a live connection to the compute
|
* Creates a Map that associates a uri with a live connection to the compute provider. This is
|
||||||
* provider. This is done on-demand.
|
* done on-demand.
|
||||||
*
|
*
|
||||||
* @param projectProvider
|
* @param projectProvider
|
||||||
* allows access to the ant project to retrieve default properties
|
* allows access to the ant project to retrieve default properties needed for compute
|
||||||
* needed for compute providers.
|
* providers.
|
||||||
*/
|
*/
|
||||||
static Map<URI, ComputeServiceContext> buildComputeMap(final Provider<Project> projectProvider) {
|
static Map<URI, ComputeServiceContext> buildComputeMap(final Provider<Project> projectProvider) {
|
||||||
return new MapMaker().makeComputingMap(new Function<URI, ComputeServiceContext>() {
|
return new MapMaker().makeComputingMap(new Function<URI, ComputeServiceContext>() {
|
||||||
|
@ -87,7 +90,7 @@ public class ComputeTaskUtils {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static Template createTemplateFromElement(NodeElement nodeElement, ComputeService computeService) {
|
static Template createTemplateFromElement(NodeElement nodeElement, ComputeService computeService) throws IOException {
|
||||||
TemplateBuilder templateBuilder = computeService.templateBuilder();
|
TemplateBuilder templateBuilder = computeService.templateBuilder();
|
||||||
if (nodeElement.getLocation() != null && !"".equals(nodeElement.getLocation()))
|
if (nodeElement.getLocation() != null && !"".equals(nodeElement.getLocation()))
|
||||||
templateBuilder.locationId(nodeElement.getLocation());
|
templateBuilder.locationId(nodeElement.getLocation());
|
||||||
|
@ -120,7 +123,7 @@ public class ComputeTaskUtils {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static TemplateOptions getNodeOptionsFromElement(NodeElement nodeElement) {
|
static TemplateOptions getNodeOptionsFromElement(NodeElement nodeElement) throws IOException {
|
||||||
TemplateOptions options = new TemplateOptions().inboundPorts(getPortsToOpenFromElement(nodeElement));
|
TemplateOptions options = new TemplateOptions().inboundPorts(getPortsToOpenFromElement(nodeElement));
|
||||||
addRunScriptToOptionsIfPresentInNodeElement(nodeElement, options);
|
addRunScriptToOptionsIfPresentInNodeElement(nodeElement, options);
|
||||||
addPrivateKeyToOptionsIfPresentInNodeElement(nodeElement, options);
|
addPrivateKeyToOptionsIfPresentInNodeElement(nodeElement, options);
|
||||||
|
@ -133,14 +136,15 @@ public class ComputeTaskUtils {
|
||||||
options.runScript(Payloads.newFilePayload(nodeElement.getRunscript()));
|
options.runScript(Payloads.newFilePayload(nodeElement.getRunscript()));
|
||||||
}
|
}
|
||||||
|
|
||||||
static void addPrivateKeyToOptionsIfPresentInNodeElement(NodeElement nodeElement, TemplateOptions options) {
|
static void addPrivateKeyToOptionsIfPresentInNodeElement(NodeElement nodeElement, TemplateOptions options)
|
||||||
|
throws IOException {
|
||||||
if (nodeElement.getPrivatekeyfile() != null)
|
if (nodeElement.getPrivatekeyfile() != null)
|
||||||
options.installPrivateKey(Payloads.newFilePayload(nodeElement.getPrivatekeyfile()));
|
options.installPrivateKey(Files.toString(nodeElement.getPrivatekeyfile(), Charsets.UTF_8));
|
||||||
}
|
}
|
||||||
|
|
||||||
static void addPublicKeyToOptionsIfPresentInNodeElement(NodeElement nodeElement, TemplateOptions options) {
|
static void addPublicKeyToOptionsIfPresentInNodeElement(NodeElement nodeElement, TemplateOptions options) throws IOException {
|
||||||
if (nodeElement.getPrivatekeyfile() != null)
|
if (nodeElement.getPrivatekeyfile() != null)
|
||||||
options.authorizePublicKey(Payloads.newFilePayload(nodeElement.getPublickeyfile()));
|
options.authorizePublicKey(Files.toString(nodeElement.getPublickeyfile(), Charsets.UTF_8));
|
||||||
}
|
}
|
||||||
|
|
||||||
static String ipOrEmptyString(Set<String> set) {
|
static String ipOrEmptyString(Set<String> set) {
|
||||||
|
|
|
@ -376,7 +376,7 @@ public class SSHJava extends Java {
|
||||||
|
|
||||||
InitBuilder testInitBuilder = new InitBuilder(id, basedir, basedir, envVariables,
|
InitBuilder testInitBuilder = new InitBuilder(id, basedir, basedir, envVariables,
|
||||||
ImmutableList.<Statement> of(Statements.interpret( commandBuilder.toString())));
|
ImmutableList.<Statement> of(Statements.interpret( commandBuilder.toString())));
|
||||||
return testInitBuilder.build(osFamily);
|
return testInitBuilder.render(osFamily);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -152,7 +152,6 @@ public class VCloudTemplateOptions extends TemplateOptions {
|
||||||
* @see TemplateOptions#authorizePublicKey(String)
|
* @see TemplateOptions#authorizePublicKey(String)
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
@Deprecated
|
|
||||||
public VCloudTemplateOptions authorizePublicKey(String publicKey) {
|
public VCloudTemplateOptions authorizePublicKey(String publicKey) {
|
||||||
return VCloudTemplateOptions.class.cast(super.authorizePublicKey(publicKey));
|
return VCloudTemplateOptions.class.cast(super.authorizePublicKey(publicKey));
|
||||||
}
|
}
|
||||||
|
@ -161,6 +160,7 @@ public class VCloudTemplateOptions extends TemplateOptions {
|
||||||
* @see TemplateOptions#authorizePublicKey(Payload)
|
* @see TemplateOptions#authorizePublicKey(Payload)
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
|
@Deprecated
|
||||||
public VCloudTemplateOptions authorizePublicKey(Payload publicKey) {
|
public VCloudTemplateOptions authorizePublicKey(Payload publicKey) {
|
||||||
return VCloudTemplateOptions.class.cast(super.authorizePublicKey(publicKey));
|
return VCloudTemplateOptions.class.cast(super.authorizePublicKey(publicKey));
|
||||||
}
|
}
|
||||||
|
@ -169,7 +169,6 @@ public class VCloudTemplateOptions extends TemplateOptions {
|
||||||
* @see TemplateOptions#installPrivateKey(String)
|
* @see TemplateOptions#installPrivateKey(String)
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
@Deprecated
|
|
||||||
public VCloudTemplateOptions installPrivateKey(String privateKey) {
|
public VCloudTemplateOptions installPrivateKey(String privateKey) {
|
||||||
return VCloudTemplateOptions.class.cast(super.installPrivateKey(privateKey));
|
return VCloudTemplateOptions.class.cast(super.installPrivateKey(privateKey));
|
||||||
}
|
}
|
||||||
|
@ -178,6 +177,7 @@ public class VCloudTemplateOptions extends TemplateOptions {
|
||||||
* @see TemplateOptions#installPrivateKey(Payload)
|
* @see TemplateOptions#installPrivateKey(Payload)
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
|
@Deprecated
|
||||||
public VCloudTemplateOptions installPrivateKey(Payload privateKey) {
|
public VCloudTemplateOptions installPrivateKey(Payload privateKey) {
|
||||||
return VCloudTemplateOptions.class.cast(super.installPrivateKey(privateKey));
|
return VCloudTemplateOptions.class.cast(super.installPrivateKey(privateKey));
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,7 +30,6 @@ import java.io.IOException;
|
||||||
|
|
||||||
import org.jclouds.compute.options.TemplateOptions;
|
import org.jclouds.compute.options.TemplateOptions;
|
||||||
import org.jclouds.io.Payloads;
|
import org.jclouds.io.Payloads;
|
||||||
import org.jclouds.util.Utils;
|
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -78,8 +77,8 @@ public class VCloudTemplateOptionsTest {
|
||||||
@Test
|
@Test
|
||||||
public void testinstallPrivateKey() throws IOException {
|
public void testinstallPrivateKey() throws IOException {
|
||||||
VCloudTemplateOptions options = new VCloudTemplateOptions();
|
VCloudTemplateOptions options = new VCloudTemplateOptions();
|
||||||
options.installPrivateKey(Payloads.newPayload("-----BEGIN RSA PRIVATE KEY-----"));
|
options.installPrivateKey("-----BEGIN RSA PRIVATE KEY-----");
|
||||||
assertEquals(Utils.toStringAndClose(options.getPrivateKey().getInput()), "-----BEGIN RSA PRIVATE KEY-----");
|
assertEquals(options.getPrivateKey(), "-----BEGIN RSA PRIVATE KEY-----");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -91,7 +90,7 @@ public class VCloudTemplateOptionsTest {
|
||||||
@Test
|
@Test
|
||||||
public void testinstallPrivateKeyStatic() throws IOException {
|
public void testinstallPrivateKeyStatic() throws IOException {
|
||||||
VCloudTemplateOptions options = installPrivateKey(Payloads.newPayload("-----BEGIN RSA PRIVATE KEY-----"));
|
VCloudTemplateOptions options = installPrivateKey(Payloads.newPayload("-----BEGIN RSA PRIVATE KEY-----"));
|
||||||
assertEquals(Utils.toStringAndClose(options.getPrivateKey().getInput()), "-----BEGIN RSA PRIVATE KEY-----");
|
assertEquals(options.getPrivateKey(), "-----BEGIN RSA PRIVATE KEY-----");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expectedExceptions = NullPointerException.class)
|
@Test(expectedExceptions = NullPointerException.class)
|
||||||
|
@ -102,8 +101,8 @@ public class VCloudTemplateOptionsTest {
|
||||||
@Test
|
@Test
|
||||||
public void testauthorizePublicKey() throws IOException {
|
public void testauthorizePublicKey() throws IOException {
|
||||||
VCloudTemplateOptions options = new VCloudTemplateOptions();
|
VCloudTemplateOptions options = new VCloudTemplateOptions();
|
||||||
options.authorizePublicKey(Payloads.newPayload("ssh-rsa"));
|
options.authorizePublicKey("ssh-rsa");
|
||||||
assertEquals(Utils.toStringAndClose(options.getPublicKey().getInput()), "ssh-rsa");
|
assertEquals(options.getPublicKey(), "ssh-rsa");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -115,7 +114,7 @@ public class VCloudTemplateOptionsTest {
|
||||||
@Test
|
@Test
|
||||||
public void testauthorizePublicKeyStatic() throws IOException {
|
public void testauthorizePublicKeyStatic() throws IOException {
|
||||||
VCloudTemplateOptions options = authorizePublicKey(Payloads.newPayload("ssh-rsa"));
|
VCloudTemplateOptions options = authorizePublicKey(Payloads.newPayload("ssh-rsa"));
|
||||||
assertEquals(Utils.toStringAndClose(options.getPublicKey().getInput()), "ssh-rsa");
|
assertEquals(options.getPublicKey(), "ssh-rsa");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expectedExceptions = NullPointerException.class)
|
@Test(expectedExceptions = NullPointerException.class)
|
||||||
|
|
|
@ -29,11 +29,10 @@ import org.jclouds.io.Payload;
|
||||||
import org.jclouds.util.Utils;
|
import org.jclouds.util.Utils;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Contains options supported in the {@code ComputeService#runNode} operation on
|
* Contains options supported in the {@code ComputeService#runNode} operation on the
|
||||||
* the "trmk-vcloudexpress" provider. <h2>
|
* "trmk-vcloudexpress" provider. <h2>
|
||||||
* Usage</h2> The recommended way to instantiate a
|
* Usage</h2> The recommended way to instantiate a TerremarkVCloudTemplateOptions object is to
|
||||||
* TerremarkVCloudTemplateOptions object is to statically import
|
* statically import TerremarkVCloudTemplateOptions.* and invoke a static creation method followed
|
||||||
* TerremarkVCloudTemplateOptions.* and invoke a static creation method followed
|
|
||||||
* by an instance mutator (if needed):
|
* by an instance mutator (if needed):
|
||||||
* <p/>
|
* <p/>
|
||||||
* <code>
|
* <code>
|
||||||
|
@ -162,10 +161,9 @@ public class TerremarkVCloudTemplateOptions extends TemplateOptions {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* special thing is that we do assume if you are passing groups that you have
|
* special thing is that we do assume if you are passing groups that you have everything you need
|
||||||
* everything you need already defined. for example, our option inboundPorts
|
* already defined. for example, our option inboundPorts normally creates ingress rules
|
||||||
* normally creates ingress rules accordingly but if we notice you've
|
* accordingly but if we notice you've specified securityGroups, we do not mess with rules at all
|
||||||
* specified securityGroups, we do not mess with rules at all
|
|
||||||
*
|
*
|
||||||
* @see TemplateOptions#inboundPorts
|
* @see TemplateOptions#inboundPorts
|
||||||
*/
|
*/
|
||||||
|
@ -178,7 +176,6 @@ public class TerremarkVCloudTemplateOptions extends TemplateOptions {
|
||||||
* @see TemplateOptions#authorizePublicKey(String)
|
* @see TemplateOptions#authorizePublicKey(String)
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
@Deprecated
|
|
||||||
public TerremarkVCloudTemplateOptions authorizePublicKey(String publicKey) {
|
public TerremarkVCloudTemplateOptions authorizePublicKey(String publicKey) {
|
||||||
return TerremarkVCloudTemplateOptions.class.cast(super.authorizePublicKey(publicKey));
|
return TerremarkVCloudTemplateOptions.class.cast(super.authorizePublicKey(publicKey));
|
||||||
}
|
}
|
||||||
|
@ -187,6 +184,7 @@ public class TerremarkVCloudTemplateOptions extends TemplateOptions {
|
||||||
* @see TemplateOptions#authorizePublicKey(Payload)
|
* @see TemplateOptions#authorizePublicKey(Payload)
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
|
@Deprecated
|
||||||
public TerremarkVCloudTemplateOptions authorizePublicKey(Payload publicKey) {
|
public TerremarkVCloudTemplateOptions authorizePublicKey(Payload publicKey) {
|
||||||
return TerremarkVCloudTemplateOptions.class.cast(super.authorizePublicKey(publicKey));
|
return TerremarkVCloudTemplateOptions.class.cast(super.authorizePublicKey(publicKey));
|
||||||
}
|
}
|
||||||
|
@ -195,7 +193,6 @@ public class TerremarkVCloudTemplateOptions extends TemplateOptions {
|
||||||
* @see TemplateOptions#installPrivateKey(String)
|
* @see TemplateOptions#installPrivateKey(String)
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
@Deprecated
|
|
||||||
public TerremarkVCloudTemplateOptions installPrivateKey(String privateKey) {
|
public TerremarkVCloudTemplateOptions installPrivateKey(String privateKey) {
|
||||||
return TerremarkVCloudTemplateOptions.class.cast(super.installPrivateKey(privateKey));
|
return TerremarkVCloudTemplateOptions.class.cast(super.installPrivateKey(privateKey));
|
||||||
}
|
}
|
||||||
|
@ -204,6 +201,7 @@ public class TerremarkVCloudTemplateOptions extends TemplateOptions {
|
||||||
* @see TemplateOptions#installPrivateKey(Payload)
|
* @see TemplateOptions#installPrivateKey(Payload)
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
|
@Deprecated
|
||||||
public TerremarkVCloudTemplateOptions installPrivateKey(Payload privateKey) {
|
public TerremarkVCloudTemplateOptions installPrivateKey(Payload privateKey) {
|
||||||
return TerremarkVCloudTemplateOptions.class.cast(super.installPrivateKey(privateKey));
|
return TerremarkVCloudTemplateOptions.class.cast(super.installPrivateKey(privateKey));
|
||||||
}
|
}
|
||||||
|
@ -234,8 +232,7 @@ public class TerremarkVCloudTemplateOptions extends TemplateOptions {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return keyPair to use when running the instance or null, to generate a
|
* @return keyPair to use when running the instance or null, to generate a keypair.
|
||||||
* keypair.
|
|
||||||
*/
|
*/
|
||||||
public String getSshKeyFingerprint() {
|
public String getSshKeyFingerprint() {
|
||||||
return keyPair;
|
return keyPair;
|
||||||
|
|
|
@ -30,7 +30,6 @@ import static org.testng.Assert.assertEquals;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
import org.jclouds.compute.options.TemplateOptions;
|
import org.jclouds.compute.options.TemplateOptions;
|
||||||
import org.jclouds.util.Utils;
|
|
||||||
import org.jclouds.vcloud.terremark.compute.options.TerremarkVCloudTemplateOptions;
|
import org.jclouds.vcloud.terremark.compute.options.TerremarkVCloudTemplateOptions;
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
|
@ -114,19 +113,17 @@ public class TerremarkVCloudTemplateOptionsTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
// superclass tests
|
// superclass tests
|
||||||
@SuppressWarnings("deprecation")
|
|
||||||
@Test(expectedExceptions = IllegalArgumentException.class)
|
@Test(expectedExceptions = IllegalArgumentException.class)
|
||||||
public void testinstallPrivateKeyBadFormat() {
|
public void testinstallPrivateKeyBadFormat() {
|
||||||
TerremarkVCloudTemplateOptions options = new TerremarkVCloudTemplateOptions();
|
TerremarkVCloudTemplateOptions options = new TerremarkVCloudTemplateOptions();
|
||||||
options.installPrivateKey("whompy");
|
options.installPrivateKey("whompy");
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("deprecation")
|
|
||||||
@Test
|
@Test
|
||||||
public void testinstallPrivateKey() throws IOException {
|
public void testinstallPrivateKey() throws IOException {
|
||||||
TerremarkVCloudTemplateOptions options = new TerremarkVCloudTemplateOptions();
|
TerremarkVCloudTemplateOptions options = new TerremarkVCloudTemplateOptions();
|
||||||
options.installPrivateKey("-----BEGIN RSA PRIVATE KEY-----");
|
options.installPrivateKey("-----BEGIN RSA PRIVATE KEY-----");
|
||||||
assertEquals(Utils.toStringAndClose(options.getPrivateKey().getInput()), "-----BEGIN RSA PRIVATE KEY-----");
|
assertEquals(options.getPrivateKey(), "-----BEGIN RSA PRIVATE KEY-----");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -138,7 +135,7 @@ public class TerremarkVCloudTemplateOptionsTest {
|
||||||
@Test
|
@Test
|
||||||
public void testinstallPrivateKeyStatic() throws IOException {
|
public void testinstallPrivateKeyStatic() throws IOException {
|
||||||
TerremarkVCloudTemplateOptions options = installPrivateKey("-----BEGIN RSA PRIVATE KEY-----");
|
TerremarkVCloudTemplateOptions options = installPrivateKey("-----BEGIN RSA PRIVATE KEY-----");
|
||||||
assertEquals(Utils.toStringAndClose(options.getPrivateKey().getInput()), "-----BEGIN RSA PRIVATE KEY-----");
|
assertEquals(options.getPrivateKey(), "-----BEGIN RSA PRIVATE KEY-----");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expectedExceptions = NullPointerException.class)
|
@Test(expectedExceptions = NullPointerException.class)
|
||||||
|
@ -146,19 +143,17 @@ public class TerremarkVCloudTemplateOptionsTest {
|
||||||
installPrivateKey(null);
|
installPrivateKey(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("deprecation")
|
|
||||||
@Test(expectedExceptions = IllegalArgumentException.class)
|
@Test(expectedExceptions = IllegalArgumentException.class)
|
||||||
public void testauthorizePublicKeyBadFormat() {
|
public void testauthorizePublicKeyBadFormat() {
|
||||||
TerremarkVCloudTemplateOptions options = new TerremarkVCloudTemplateOptions();
|
TerremarkVCloudTemplateOptions options = new TerremarkVCloudTemplateOptions();
|
||||||
options.authorizePublicKey("whompy");
|
options.authorizePublicKey("whompy");
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("deprecation")
|
|
||||||
@Test
|
@Test
|
||||||
public void testauthorizePublicKey() throws IOException {
|
public void testauthorizePublicKey() throws IOException {
|
||||||
TerremarkVCloudTemplateOptions options = new TerremarkVCloudTemplateOptions();
|
TerremarkVCloudTemplateOptions options = new TerremarkVCloudTemplateOptions();
|
||||||
options.authorizePublicKey("ssh-rsa");
|
options.authorizePublicKey("ssh-rsa");
|
||||||
assertEquals(Utils.toStringAndClose(options.getPublicKey().getInput()), "ssh-rsa");
|
assertEquals(options.getPublicKey(), "ssh-rsa");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -170,7 +165,7 @@ public class TerremarkVCloudTemplateOptionsTest {
|
||||||
@Test
|
@Test
|
||||||
public void testauthorizePublicKeyStatic() throws IOException {
|
public void testauthorizePublicKeyStatic() throws IOException {
|
||||||
TerremarkVCloudTemplateOptions options = authorizePublicKey("ssh-rsa");
|
TerremarkVCloudTemplateOptions options = authorizePublicKey("ssh-rsa");
|
||||||
assertEquals(Utils.toStringAndClose(options.getPublicKey().getInput()), "ssh-rsa");
|
assertEquals(options.getPublicKey(), "ssh-rsa");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expectedExceptions = NullPointerException.class)
|
@Test(expectedExceptions = NullPointerException.class)
|
||||||
|
|
Loading…
Reference in New Issue