added jdk to computeservice

git-svn-id: http://jclouds.googlecode.com/svn/trunk@2629 3d8758e0-26b5-11de-8745-db77d3ebf521
This commit is contained in:
adrian.f.cole 2010-01-11 03:00:42 +00:00
parent 646cad3202
commit 340d58e030
3 changed files with 24 additions and 19 deletions

View File

@ -20,6 +20,7 @@ package org.jclouds.aws.ec2.compute;
import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Preconditions.checkNotNull;
import static org.jclouds.aws.ec2.options.RunInstancesOptions.Builder.withKeyName; import static org.jclouds.aws.ec2.options.RunInstancesOptions.Builder.withKeyName;
import static org.jclouds.scriptbuilder.domain.Statements.exec;
import java.net.InetAddress; import java.net.InetAddress;
import java.util.Map; import java.util.Map;
@ -52,6 +53,8 @@ import org.jclouds.compute.domain.internal.ServerIdentityImpl;
import org.jclouds.compute.domain.internal.ServerMetadataImpl; import org.jclouds.compute.domain.internal.ServerMetadataImpl;
import org.jclouds.domain.Credentials; import org.jclouds.domain.Credentials;
import org.jclouds.logging.Logger; import org.jclouds.logging.Logger;
import org.jclouds.scriptbuilder.ScriptBuilder;
import org.jclouds.scriptbuilder.domain.OsFamily;
import com.google.common.base.Function; import com.google.common.base.Function;
import com.google.common.base.Predicate; import com.google.common.base.Predicate;
@ -101,20 +104,24 @@ public class EC2ComputeService implements ComputeService {
"profile not supported: " + profile); "profile not supported: " + profile);
KeyPair keyPair = createKeyPair(name); KeyPair keyPair = createKeyPair(name);
String securityGroupName = name; String securityGroupName = name;
createSecurityGroup(securityGroupName, 22, 80, 443); createSecurityGroup(securityGroupName, 22, 80, 8080, 443);
String script = new ScriptBuilder() // update and install jdk
.addStatement(exec("runurl run.alestic.com/apt/upgrade"))//
.addStatement(exec("apt-get install -y openjdk-6-jdk"))//
.build(OsFamily.UNIX);
logger.debug(">> running instance ami(%s) type(%s) keyPair(%s) securityGroup(%s)", ami, type, logger.debug(">> running instance ami(%s) type(%s) keyPair(%s) securityGroup(%s)", ami, type,
keyPair.getKeyName(), securityGroupName); keyPair.getKeyName(), securityGroupName);
RunningInstance runningInstance = Iterables RunningInstance runningInstance = Iterables.getLast(ec2Client.getInstanceServices()
.getLast(ec2Client.getInstanceServices().runInstancesInRegion( .runInstancesInRegion(Region.DEFAULT, null, ami, 1, 1,
Region.DEFAULT, withKeyName(keyPair.getKeyName())// key I created above
null, .asType(type)// instance size
ami, .withSecurityGroup(securityGroupName)// group I created above
1, .withAdditionalInfo(name)// description
1, .withUserData(script.getBytes()) // script to run as root
withKeyName(keyPair.getKeyName()).asType(type).withSecurityGroup( ).getRunningInstances());
securityGroupName).withAdditionalInfo(name)).getRunningInstances());
logger.debug("<< started instance(%s)", runningInstance.getId()); logger.debug("<< started instance(%s)", runningInstance.getId());
instanceStateRunning.apply(runningInstance); instanceStateRunning.apply(runningInstance);
logger.debug("<< running instance(%s)", runningInstance.getId()); logger.debug("<< running instance(%s)", runningInstance.getId());
@ -127,10 +134,9 @@ public class EC2ComputeService implements ComputeService {
Set<InetAddress> privateAddresses = runningInstance.getPrivateIpAddress() == null ? ImmutableSet Set<InetAddress> privateAddresses = runningInstance.getPrivateIpAddress() == null ? ImmutableSet
.<InetAddress> of() .<InetAddress> of()
: ImmutableSet.<InetAddress> of(runningInstance.getPrivateIpAddress()); : ImmutableSet.<InetAddress> of(runningInstance.getPrivateIpAddress());
return new CreateServerResponseImpl(runningInstance.getId(), name, return new CreateServerResponseImpl(runningInstance.getId(), name, instanceToServerState
instanceToServerState.get(runningInstance.getInstanceState()), publicAddresses, .get(runningInstance.getInstanceState()), publicAddresses, privateAddresses, 22,
privateAddresses, 22, LoginType.SSH, new Credentials("root", keyPair LoginType.SSH, new Credentials("root", keyPair.getKeyMaterial()));
.getKeyMaterial()));
} }
private KeyPair createKeyPair(String name) { private KeyPair createKeyPair(String name) {
@ -189,10 +195,9 @@ public class EC2ComputeService implements ComputeService {
@Override @Override
public ServerMetadata apply(RunningInstance from) { public ServerMetadata apply(RunningInstance from) {
return new ServerMetadataImpl(from.getId(), from.getKeyName(), return new ServerMetadataImpl(from.getId(), from.getKeyName(), instanceToServerState
instanceToServerState.get(from.getInstanceState()), nullSafeSet(from .get(from.getInstanceState()), nullSafeSet(from.getIpAddress()), nullSafeSet(from
.getIpAddress()), nullSafeSet(from.getPrivateIpAddress()), 22, .getPrivateIpAddress()), 22, LoginType.SSH);
LoginType.SSH);
} }
Set<InetAddress> nullSafeSet(InetAddress in) { Set<InetAddress> nullSafeSet(InetAddress in) {

View File

@ -133,6 +133,7 @@ public class SpeedTest {
entry.getKey(), queue.getRegion(), ((double) complete) entry.getKey(), queue.getRegion(), ((double) complete)
/ (duration / 1000.0)); / (duration / 1000.0));
System.out.println("pausing 5 seconds before the next run"); System.out.println("pausing 5 seconds before the next run");
System.gc();
Thread.sleep(5000);// let the network quiet down Thread.sleep(5000);// let the network quiet down
} }
} }

View File

@ -46,7 +46,6 @@
<groupId>${project.groupId}</groupId> <groupId>${project.groupId}</groupId>
<artifactId>jclouds-scriptbuilder</artifactId> <artifactId>jclouds-scriptbuilder</artifactId>
<version>${project.version}</version> <version>${project.version}</version>
<scope>test</scope>
</dependency> </dependency>
<dependency> <dependency>
<groupId>${project.groupId}</groupId> <groupId>${project.groupId}</groupId>