Skip to content

Commit

Permalink
making progress with the EC2 support
Browse files Browse the repository at this point in the history
  • Loading branch information
kohsuke committed Oct 30, 2008
1 parent 6dfe01b commit 8377e25
Show file tree
Hide file tree
Showing 6 changed files with 140 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/main/java/hudson/plugins/ec2/EC2Cloud.java
Expand Up @@ -12,24 +12,30 @@
import javax.servlet.ServletException;
import java.io.IOException;
import java.util.Collections;
import java.util.List;
import java.util.logging.Logger;
import java.util.logging.Level;

import com.xerox.amazonws.ec2.Jec2;
import com.xerox.amazonws.ec2.EC2Exception;
import com.xerox.amazonws.ec2.InstanceType;

/**
* Hudson's view of EC2.
*
* @author Kohsuke Kawaguchi
*/
public class EC2Cloud extends Cloud {
private final String accessId;
private final Secret secretKey;
private final List<SlaveTemplate> templates;

@DataBoundConstructor
public EC2Cloud(String name, String accessId, String secretKey) {
public EC2Cloud(String name, String accessId, String secretKey, List<SlaveTemplate> templates) {
super(name);
this.accessId = accessId.trim();
this.secretKey = Secret.fromString(secretKey.trim());
this.templates = templates;
}

public String getAccessId() {
Expand All @@ -40,6 +46,10 @@ public String getSecretKey() {
return secretKey.getEncryptedValue();
}

public List<SlaveTemplate> getTemplates() {
return Collections.unmodifiableList(templates);
}

public DescriptorImpl getDescriptor() {
return DescriptorImpl.INSTANCE;
}
Expand All @@ -55,6 +65,10 @@ public String getDisplayName() {
return "Amazon EC2";
}

public InstanceType[] getInstanceTypes() {
return InstanceType.values();
}

public void doCheckAccessId(StaplerRequest req, StaplerResponse rsp) throws IOException, ServletException {
new FormFieldValidator.Base64(req,rsp,false,false,Messages.EC2Cloud_InvalidAccessId()).process();
}
Expand Down
52 changes: 52 additions & 0 deletions src/main/java/hudson/plugins/ec2/EC2Slave.java
@@ -0,0 +1,52 @@
package hudson.plugins.ec2;

import com.xerox.amazonws.ec2.InstanceType;
import hudson.model.Descriptor.FormException;
import hudson.model.Slave;
import hudson.slaves.ComputerLauncher;
import hudson.slaves.NodeDescriptor;
import hudson.slaves.RetentionStrategy;
import org.kohsuke.stapler.DataBoundConstructor;

/**
* Slave running on EC2.
*
* @author Kohsuke Kawaguchi
*/
public final class EC2Slave extends Slave {
@DataBoundConstructor
public EC2Slave(String instanceId, String description, String remoteFS, InstanceType type, String label, ComputerLauncher launcher) throws FormException {
// TODO: retention policy for Amazon
super(instanceId, description, remoteFS, toNumExecutors(type), Mode.NORMAL, label, launcher, RetentionStrategy.NOOP);
}

/**
* See http://aws.amazon.com/ec2/instance-types/
*/
private static int toNumExecutors(InstanceType it) {
switch (it) {
case DEFAULT: return 1;
case MEDIUM_HCPU: return 5;
case LARGE: return 4;
case XLARGE: return 8;
case XLARGE_HCPU: return 20;
default: throw new AssertionError();
}
}

public NodeDescriptor getDescriptor() {
return DescriptorImpl.INSTANCE;
}

public static final class DescriptorImpl extends NodeDescriptor {
public static final DescriptorImpl INSTANCE = new DescriptorImpl();

private DescriptorImpl() {
super(EC2Slave.class);
}

public String getDisplayName() {
return "Amazon EC2";
}
}
}
1 change: 1 addition & 0 deletions src/main/java/hudson/plugins/ec2/PluginImpl.java
Expand Up @@ -11,5 +11,6 @@
public class PluginImpl extends Plugin {
public void start() throws Exception {
Cloud.ALL.load(EC2Cloud.class);
SlaveTemplate.DescriptorImpl.INSTANCE.getDisplayName(); // make sure descriptor is registered
}
}
42 changes: 42 additions & 0 deletions src/main/java/hudson/plugins/ec2/SlaveTemplate.java
@@ -0,0 +1,42 @@
package hudson.plugins.ec2;

import com.xerox.amazonws.ec2.InstanceType;
import hudson.slaves.ComputerLauncher;
import hudson.model.Describable;
import hudson.model.Descriptor;

/**
* Template of {@link EC2Slave} to launch.
*
* @author Kohsuke Kawaguchi
*/
public class SlaveTemplate implements Describable<SlaveTemplate> {
public final String ami;
public final String remoteFS;
public final InstanceType type;
public final String label;
public final ComputerLauncher launcher;

public SlaveTemplate(String ami, String remoteFS, InstanceType type, String label, ComputerLauncher launcher) {
this.ami = ami;
this.remoteFS = remoteFS;
this.type = type;
this.label = label;
this.launcher = launcher;
}

public DescriptorImpl getDescriptor() {
return DescriptorImpl.INSTANCE;
}

public static final class DescriptorImpl extends Descriptor<SlaveTemplate> {
public static final DescriptorImpl INSTANCE = new DescriptorImpl();
private DescriptorImpl() {
super(SlaveTemplate.class);
}

public String getDisplayName() {
return null;
}
}
}
27 changes: 27 additions & 0 deletions src/main/resources/hudson/plugins/ec2/EC2Cloud/config.jelly
Expand Up @@ -6,4 +6,31 @@
<f:password field="secretKey" />
</f:entry>
<f:validateButton title="${%Test Connection}" progress="${%Testing...}" method="testConnection" with="secretKey,accessId" />
<f:entry title="${%AMIs}" description="${%List of AMIs to be launched as slaves}">
<f:repeatable field="templates">
<table width="100%">
<f:entry title="${%AMI ID}">
<f:textbox field="ami" />
</f:entry>
<f:entry title="${%Instance Type}" help="/plugin/ec2/help/instanceType.html">
<f:enum field="type">${it.name()}</f:enum>
</f:entry>
<f:entry title="${%Description}" help="/help/system-config/master-slave/description.html">
<f:textbox field="description" />
</f:entry>
<f:entry title="${%Remote FS root}" help="/help/system-config/master-slave/remoteFS.html">
<f:textbox field="remoteFS" />
</f:entry>
<f:entry title="${%Labels}" help="/help/system-config/master-slave/label.html">
<f:textbox field="label" />
</f:entry>

<f:entry title="">
<div align="right">
<f:repeatableDeleteButton />
</div>
</f:entry>
</table>
</f:repeatable>
</f:entry>
</j:jelly>
3 changes: 3 additions & 0 deletions src/main/webapp/help/instanceType.html
@@ -0,0 +1,3 @@
<div>
Choose the instance type you'd want to launch.
</div>

0 comments on commit 8377e25

Please sign in to comment.