Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 13 additions & 5 deletions src/main/java/hudson/plugins/ec2/EC2Cloud.java
Original file line number Diff line number Diff line change
Expand Up @@ -1047,14 +1047,22 @@ public Collection<PlannedNode> provision(final Label label, int excessWorkload)
}
} catch (AwsServiceException e) {
LOGGER.log(Level.WARNING, t + ". Exception during provisioning", e);
if (e.awsErrorDetails().errorCode().equals("RequestExpired")
|| e.awsErrorDetails().errorCode().equals("ExpiredToken")) {
// A RequestExpired or ExpiredToken error can indicate that credentials have expired so reconnect
LOGGER.log(Level.INFO, "Reconnecting to EC2 due to RequestExpired or ExpiredToken error");
if (e.awsErrorDetails().errorCode().equals("RequestExpired")) {
// A RequestExpired error can indicate that request has expired so reconnect
LOGGER.log(Level.INFO, "Reconnecting to EC2 due to RequestExpired error");
try {
reconnectToEc2();
} catch (IOException e2) {
LOGGER.log(Level.WARNING, "Failed to reconnect ec2", e2);
LOGGER.log(Level.WARNING, "Failed to reconnect EC2", e2);
}
} else if (e.awsErrorDetails().errorCode().equals("ExpiredToken")) {
// A ExpiredToken error can indicate that token has expired so re-save the cloud
LOGGER.log(Level.INFO, "Re-saving EC2 cloud due to ExpiredToken error");
try {
Jenkins.get().clouds.replace(this, this);
Jenkins.get().save();
} catch (IOException e2) {
LOGGER.log(Level.WARNING, "Failed to re-save EC2 cloud: " + getCloudName(), e2);
}
}
} catch (SdkException | IOException e) {
Expand Down