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

Wait for complete disconnection with pod slaves #248

Merged
Changes from 2 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
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@
import java.security.cert.CertificateEncodingException;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import java.util.concurrent.ExecutionException;

/**
* @author Carlos Sanchez carlos@apache.org
Expand Down Expand Up @@ -166,7 +170,26 @@ protected void _terminate(TaskListener listener) throws IOException, Interrupted
}

OfflineCause offlineCause = OfflineCause.create(new Localizable(HOLDER, "offline"));
computer.disconnect(offlineCause);
Future disconnected = computer.disconnect(offlineCause);
long timeout = 5;
try {
disconnected.get(timeout, TimeUnit.SECONDS);
} catch(TimeoutException tme){
String msg = String.format("disconnection with kubernetes pod %s timeout after %ds", name, timeout);
LOGGER.log(Level.WARNING, msg, tme);
return;
} catch(InterruptedException inte) {
String msg = String.format("disconnection with kubernetes pod %s interrupted", name);
LOGGER.log(Level.WARNING, msg, inte);
throw inte;
} catch(ExecutionException ee) {
String msg = String.format("disconnection with kubernetes pod %s execution aborted", name);
LOGGER.log(Level.WARNING, msg, ee);
listener.error(msg);
// Assuming pod template has some error itself
// Simply return might leave some kuberentes pod of ERROR state
return;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

} catch(TimeoutException | InterruptedException | ExecutionException e){
String msg = String.format("Error waiting for agent disconnection %s: %s", name, e.getMessage());
LOGGER.log(Level.INFO, msg, e);


if (getCloudName() == null) {
String msg = String.format("Cloud name is not set for agent, can't terminate: %s", name);
Expand Down