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-73096 Create config for check interval and use the same default #968

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
20 changes: 11 additions & 9 deletions src/main/java/hudson/plugins/ec2/EC2RetentionStrategy.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@
private transient ReentrantLock checkLock;
private static final int STARTUP_TIME_DEFAULT_VALUE = 30;

private static final Integer CHECK_INTERVAL_MINUTES = Integer.getInteger("jenkins.ec2.checkIntervalMinutes", 1);

@DataBoundConstructor
public EC2RetentionStrategy(String idleTerminationMinutes) {
readResolve();
Expand Down Expand Up @@ -99,7 +101,7 @@
@Override
public long check(EC2Computer c) {
if (!checkLock.tryLock()) {
return 1;
return CHECK_INTERVAL_MINUTES;

Check warning on line 104 in src/main/java/hudson/plugins/ec2/EC2RetentionStrategy.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered line

Line 104 is not covered by tests
} else {
try {
long currentTime = this.clock.millis();
Expand All @@ -109,7 +111,7 @@
nextCheckAfter = currentTime + TimeUnit.MINUTES.toMillis(intervalMins);
return intervalMins;
} else {
return 1;
return CHECK_INTERVAL_MINUTES;
}
} finally {
checkLock.unlock();
Expand All @@ -122,7 +124,7 @@
* If we've been told never to terminate, or node is null(deleted), no checks to perform
*/
if (idleTerminationMinutes == 0 || computer.getNode() == null) {
return 1;
return CHECK_INTERVAL_MINUTES;
}

/*
Expand All @@ -134,7 +136,7 @@
if (numberOfCurrentInstancesForTemplate > 0 && numberOfCurrentInstancesForTemplate <= slaveTemplate.getMinimumNumberOfInstances()) {
//Check if we're in an active time-range for keeping minimum number of instances
if (MinimumInstanceChecker.minimumInstancesActive(slaveTemplate.getMinimumNumberOfInstancesTimeRangeConfig())) {
return 1;
return CHECK_INTERVAL_MINUTES;
}
}
}
Expand All @@ -152,32 +154,32 @@
// We'll just retry next time we test for idleness.
LOGGER.fine("Exception while checking host uptime for " + computer.getName()
+ ", will retry next check. Exception: " + e);
return 1;
return CHECK_INTERVAL_MINUTES;
}

//Don't bother checking anything else if the instance is already in the desired state:
// * Already Terminated
// * We use stop-on-terminate and the instance is currently stopped or stopping
if (InstanceState.TERMINATED.equals(state)
|| (slaveTemplate != null && slaveTemplate.stopOnTerminate) && (InstanceState.STOPPED.equals(state) || InstanceState.STOPPING.equals(state))) {
if (computer.isOnline()) {
LOGGER.info("External Stop of " + computer.getName() + " detected - disconnecting. instance status" + state.toString());
computer.disconnect(null);
}
return 1;
return CHECK_INTERVAL_MINUTES;
}

//on rare occasions, AWS may return fault instance which shows running in AWS console but can not be connected.
//need terminate such fault instance.
// An instance may also fail running user data scripts and
// need to be cleaned up.
if (computer.isOffline()){
if (computer.isConnecting()) {
LOGGER.log(Level.FINE, "Computer {0} connecting and still offline, will check if the launch timeout has expired", computer.getInstanceId());

EC2AbstractSlave node = computer.getNode();
if (Objects.isNull(node)) {
return 1;
return CHECK_INTERVAL_MINUTES;

Check warning on line 182 in src/main/java/hudson/plugins/ec2/EC2RetentionStrategy.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered lines

Lines 157-182 are not covered by tests
}
long launchTimeout = node.getLaunchTimeoutInMillis();
if (launchTimeout > 0 && uptime > launchTimeout) {
Expand All @@ -187,7 +189,7 @@
" milliseconds (timeout: " + launchTimeout + " milliseconds), instance status: " + state.toString());
node.launchTimeout();
}
return 1;
return CHECK_INTERVAL_MINUTES;
} else {
LOGGER.log(Level.FINE, "Computer {0} offline but not connecting, will check if it should be terminated because of the idle time configured", computer.getInstanceId());
}
Expand Down Expand Up @@ -232,7 +234,7 @@
}
}
}
return 1;
return CHECK_INTERVAL_MINUTES;
}

/*
Expand Down
Loading