Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge remote-tracking branch 'origin/master'

  • Loading branch information...
commit 9e24c5467f5174b48d9711d1aba08fc681833158 2 parents 7cb1874 + 1ffecc4
Francis Upton IV authored
View
39 src/main/java/hudson/plugins/ec2/EC2Computer.java
@@ -31,6 +31,7 @@
import org.kohsuke.stapler.HttpRedirect;
import org.kohsuke.stapler.HttpResponse;
import com.amazonaws.AmazonClientException;
+import com.amazonaws.AmazonServiceException;
import com.amazonaws.services.ec2.AmazonEC2;
import com.amazonaws.services.ec2.model.DescribeInstancesRequest;
import com.amazonaws.services.ec2.model.GetConsoleOutputRequest;
@@ -77,7 +78,7 @@ public String getConsoleOutput() throws AmazonClientException {
*
* The cache can be flushed using {@link #updateInstanceDescription()}
*/
- public Instance describeInstance() throws AmazonClientException {
+ public Instance describeInstance() throws AmazonClientException, InterruptedException {
if(ec2InstanceDescription==null)
ec2InstanceDescription = _describeInstance();
return ec2InstanceDescription;
@@ -86,7 +87,7 @@ public Instance describeInstance() throws AmazonClientException {
/**
* This will flush any cached description held by {@link #describeInstance()}.
*/
- public Instance updateInstanceDescription() throws AmazonClientException {
+ public Instance updateInstanceDescription() throws AmazonClientException, InterruptedException {
return ec2InstanceDescription = _describeInstance();
}
@@ -96,7 +97,7 @@ public Instance updateInstanceDescription() throws AmazonClientException {
* <p>
* Unlike {@link #describeInstance()}, this method always return the current status by calling EC2.
*/
- public InstanceState getState() throws AmazonClientException {
+ public InstanceState getState() throws AmazonClientException, InterruptedException {
ec2InstanceDescription=_describeInstance();
return InstanceState.find(ec2InstanceDescription.getState().getName());
}
@@ -104,23 +105,43 @@ public InstanceState getState() throws AmazonClientException {
/**
* Number of milli-secs since the instance was started.
*/
- public long getUptime() throws AmazonClientException {
+ public long getUptime() throws AmazonClientException, InterruptedException {
return System.currentTimeMillis()-describeInstance().getLaunchTime().getTime();
}
/**
* Returns uptime in the human readable form.
*/
- public String getUptimeString() throws AmazonClientException {
+ public String getUptimeString() throws AmazonClientException, InterruptedException {
return Util.getTimeSpanString(getUptime());
}
- private Instance _describeInstance() throws AmazonClientException {
- DescribeInstancesRequest request = new DescribeInstancesRequest();
- request.setInstanceIds(Collections.<String>singletonList(getNode().getInstanceId()));
- return EC2Cloud.get().connect().describeInstances(request).getReservations().get(0).getInstances().get(0);
+ private Instance _describeInstance() throws AmazonClientException, InterruptedException {
+ // Sometimes even after a successful RunInstances, DescribeInstances
+ // returns an error for a few seconds. We do a few retries instead of
+ // failing instantly. See [JENKINS-15319].
+ for (int i = 0; i < 5; i++) {
+ try {
+ return _describeInstanceOnce();
+ } catch (AmazonServiceException e) {
+ if (e.getErrorCode().equals("InvalidInstanceID.NotFound")) {
+ // retry in 5 seconds.
+ Thread.sleep(5000);
+ continue;
+ }
+ throw e;
+ }
+ }
+ // Last time, throw on any error.
+ return _describeInstanceOnce();
}
+ private Instance _describeInstanceOnce() throws AmazonClientException {
+ DescribeInstancesRequest request = new DescribeInstancesRequest();
+ request.setInstanceIds(Collections.<String>singletonList(getNode().getInstanceId()));
+ return EC2Cloud.get().connect().describeInstances(request).getReservations().get(0).getInstances().get(0);
+ }
+
/**
* When the slave is deleted, terminate the instance.
*/
View
18 src/main/java/hudson/plugins/ec2/EC2Slave.java
@@ -61,7 +61,7 @@
* @author Kohsuke Kawaguchi
*/
public final class EC2Slave extends Slave {
- public final String instanceId;
+ private String instanceId;
/**
* Comes from {@link SlaveTemplate#initScript}.
*/
@@ -123,6 +123,20 @@ public EC2Slave(String instanceId, String description, String remoteFS, int sshP
this.usePrivateDnsName = usePrivateDnsName;
}
+ protected Object readResolve() {
+ /*
+ * If instanceId is null, this object was deserialized from an old
+ * version of the plugin, where this field did not exist (prior to
+ * version 1.18). In those versions, the node name *was* the instance
+ * ID, so we can get it from there.
+ */
+ if (instanceId == null) {
+ instanceId = getNodeName();
+ }
+
+ return this;
+ }
+
/**
* Constructor for debugging.
*/
@@ -143,8 +157,10 @@ public EC2Slave(String instanceId) throws FormException, IOException {
case M2Xlarge: return 6;
case M1Xlarge: return 8;
case M22xlarge: return 13;
+ case M3Xlarge: return 13;
case C1Xlarge: return 20;
case M24xlarge: return 26;
+ case M32xlarge: return 26;
case Cc14xlarge: return 33;
case Cg14xlarge: return 33;
default: throw new AssertionError();
View
36 src/main/java/hudson/plugins/ec2/InstanceTypeConverter.java
@@ -39,21 +39,23 @@
*/
public class InstanceTypeConverter implements Converter {
- private static final Map<String, InstanceType> TYPICA_INSTANCE_TYPES = new HashMap<String, InstanceType>();
-
+ private static final Map<String, InstanceType> TYPICAL_INSTANCE_TYPES = new HashMap<String, InstanceType>();
+
static {
- TYPICA_INSTANCE_TYPES.put("DEFAULT", InstanceType.M1Small);
- TYPICA_INSTANCE_TYPES.put("LARGE", InstanceType.M1Large);
- TYPICA_INSTANCE_TYPES.put("XLARGE", InstanceType.M1Xlarge);
- TYPICA_INSTANCE_TYPES.put("MEDIUM_HCPU", InstanceType.C1Medium);
- TYPICA_INSTANCE_TYPES.put("XLARGE_HCPU", InstanceType.C1Xlarge);
- TYPICA_INSTANCE_TYPES.put("XLARGE_HMEM", InstanceType.M2Xlarge);
- TYPICA_INSTANCE_TYPES.put("XLARGE_DOUBLE_HMEM", InstanceType.M22xlarge);
- TYPICA_INSTANCE_TYPES.put("XLARGE_QUAD_HMEM", InstanceType.M24xlarge);
- TYPICA_INSTANCE_TYPES.put("XLARGE_CLUSTER_COMPUTE", InstanceType.Cc14xlarge);
+ TYPICAL_INSTANCE_TYPES.put("DEFAULT", InstanceType.M1Small);
+ TYPICAL_INSTANCE_TYPES.put("LARGE", InstanceType.M1Large);
+ TYPICAL_INSTANCE_TYPES.put("XLARGE", InstanceType.M1Xlarge);
+ TYPICAL_INSTANCE_TYPES.put("MEDIUM_HCPU", InstanceType.C1Medium);
+ TYPICAL_INSTANCE_TYPES.put("XLARGE_HCPU", InstanceType.C1Xlarge);
+ TYPICAL_INSTANCE_TYPES.put("XLARGE_HMEM", InstanceType.M2Xlarge);
+ TYPICAL_INSTANCE_TYPES.put("XLARGE_HMEM_M3", InstanceType.M3Xlarge);
+ TYPICAL_INSTANCE_TYPES.put("XLARGE_DOUBLE_HMEM", InstanceType.M22xlarge);
+ TYPICAL_INSTANCE_TYPES.put("XLARGE_QUAD_HMEM", InstanceType.M24xlarge);
+ TYPICAL_INSTANCE_TYPES.put("XLARGE_QUAD_HMEM_M3", InstanceType.M32xlarge);
+ TYPICAL_INSTANCE_TYPES.put("XLARGE_CLUSTER_COMPUTE", InstanceType.Cc14xlarge);
}
-
- public boolean canConvert(Class type) {
+
+ public boolean canConvert(Class type) {
return InstanceType.class == type;
}
@@ -64,15 +66,15 @@ public void marshal(Object source, HierarchicalStreamWriter writer, MarshallingC
public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) {
InstanceType instanceType = null;
-
+
String stringValue = reader.getValue();
-
+
try {
instanceType = InstanceType.valueOf(stringValue);
} catch (IllegalArgumentException e) {
- instanceType = TYPICA_INSTANCE_TYPES.get(stringValue.toUpperCase());
+ instanceType = TYPICAL_INSTANCE_TYPES.get(stringValue.toUpperCase());
}
-
+
return instanceType;
}
View
1  src/main/java/hudson/plugins/ec2/SlaveTemplate.java
@@ -299,6 +299,7 @@ public EC2Slave provision(TaskListener listener) throws AmazonClientException, I
if (tags != null && !tags.isEmpty()) {
inst_tags = new HashSet<Tag>();
for(EC2Tag t : tags) {
+ inst_tags.add(new Tag(t.getName(), t.getValue()));
diFilters.add(new Filter("tag:"+t.getName()).withValues(t.getValue()));
}
}
View
37 src/test/java/hudson/plugins/ec2/EC2InstanceTypesTest.java
@@ -0,0 +1,37 @@
+/*
+ * The MIT License
+ *
+ * Copyright (c) 2013, Bloomberg L.P.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+package hudson.plugins.ec2;
+
+import org.jvnet.hudson.test.HudsonTestCase;
+
+import com.amazonaws.services.ec2.model.InstanceType;
+
+public class EC2InstanceTypesTest extends HudsonTestCase {
+ public void testListTypes() throws Exception {
+ System.out.println("EC2 Instance Types available:");
+ for (InstanceType t : InstanceType.values()) {
+ System.out.println(t.toString());
+ }
+ }
+}
Please sign in to comment.
Something went wrong with that request. Please try again.