Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JENKINS-71554: Reconnect on "RequestExpired" exception #886

Merged
merged 1 commit into from
Sep 2, 2023
Merged
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
43 changes: 25 additions & 18 deletions src/main/java/hudson/plugins/ec2/EC2Cloud.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
package hudson.plugins.ec2;

import com.amazonaws.AmazonClientException;
import com.amazonaws.AmazonServiceException;
import com.amazonaws.ClientConfiguration;
import com.amazonaws.auth.AWSCredentials;
import com.amazonaws.auth.AWSCredentialsProvider;
Expand Down Expand Up @@ -694,7 +695,7 @@
* Obtains a agent whose AMI matches the AMI of the given template, and that also has requiredLabel (if requiredLabel is non-null)
* forceCreateNew specifies that the creation of a new agent is required. Otherwise, an existing matching agent may be re-used
*/
private List<EC2AbstractSlave> getNewOrExistingAvailableSlave(SlaveTemplate t, int number, boolean forceCreateNew) {
private List<EC2AbstractSlave> getNewOrExistingAvailableSlave(SlaveTemplate t, int number, boolean forceCreateNew) throws IOException {
try {
slaveCountingLock.lock();
int possibleSlavesCount = getPossibleNewSlavesCount(t);
Expand All @@ -703,24 +704,19 @@
return null;
}

try {
EnumSet<SlaveTemplate.ProvisionOptions> provisionOptions;
if (forceCreateNew)
provisionOptions = EnumSet.of(SlaveTemplate.ProvisionOptions.FORCE_CREATE);
else
provisionOptions = EnumSet.of(SlaveTemplate.ProvisionOptions.ALLOW_CREATE);

if (number > possibleSlavesCount) {
LOGGER.log(Level.INFO, String.format("%d nodes were requested for the template %s, " +
"but because of instance cap only %d can be provisioned", number, t, possibleSlavesCount));
number = possibleSlavesCount;
}
EnumSet<SlaveTemplate.ProvisionOptions> provisionOptions;
if (forceCreateNew)
provisionOptions = EnumSet.of(SlaveTemplate.ProvisionOptions.FORCE_CREATE);
else
provisionOptions = EnumSet.of(SlaveTemplate.ProvisionOptions.ALLOW_CREATE);

return t.provision(number, provisionOptions);
} catch (IOException e) {
LOGGER.log(Level.WARNING, t + ". Exception during provisioning", e);
return null;
if (number > possibleSlavesCount) {
LOGGER.log(Level.INFO, String.format("%d nodes were requested for the template %s, " +
"but because of instance cap only %d can be provisioned", number, t, possibleSlavesCount));
number = possibleSlavesCount;
}

return t.provision(number, provisionOptions);
} finally { slaveCountingLock.unlock(); }
}

Expand Down Expand Up @@ -761,7 +757,18 @@

LOGGER.log(Level.INFO, "{0}. Attempting provision finished, excess workload: " + excessWorkload, t);
if (excessWorkload == 0) break;
} catch (AmazonClientException e) {
} catch (AmazonServiceException e) {

Check warning on line 760 in src/main/java/hudson/plugins/ec2/EC2Cloud.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered line

Line 760 is not covered by tests
LOGGER.log(Level.WARNING, t + ". Exception during provisioning", e);

Check warning on line 761 in src/main/java/hudson/plugins/ec2/EC2Cloud.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered line

Line 761 is not covered by tests
if (e.getErrorCode().equals("RequestExpired")) {

Check warning on line 762 in src/main/java/hudson/plugins/ec2/EC2Cloud.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Partially covered line

Line 762 is only partially covered, 2 branches are missing
// JENKINS-71554: A RequestExpired error can indicate that credentials have expired so reconnect
LOGGER.log(Level.INFO, "[JENKINS-71554] Reconnecting to EC2 due to RequestExpired error");

Check warning on line 764 in src/main/java/hudson/plugins/ec2/EC2Cloud.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered line

Line 764 is not covered by tests
try {
reconnectToEc2();

Check warning on line 766 in src/main/java/hudson/plugins/ec2/EC2Cloud.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered line

Line 766 is not covered by tests
} catch (IOException e2) {

Check warning on line 767 in src/main/java/hudson/plugins/ec2/EC2Cloud.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered line

Line 767 is not covered by tests
LOGGER.log(Level.WARNING, "Failed to reconnect ec2", e2);

Check warning on line 768 in src/main/java/hudson/plugins/ec2/EC2Cloud.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered line

Line 768 is not covered by tests
}

Check warning on line 769 in src/main/java/hudson/plugins/ec2/EC2Cloud.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered line

Line 769 is not covered by tests
}
} catch (AmazonClientException | IOException e) {

Check warning on line 771 in src/main/java/hudson/plugins/ec2/EC2Cloud.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered line

Line 771 is not covered by tests
LOGGER.log(Level.WARNING, t + ". Exception during provisioning", e);
}
}
Expand Down
Loading