Skip to content

Commit

Permalink
Be smarter about shutting down containers when we get exceptions chec…
Browse files Browse the repository at this point in the history
…king their status
  • Loading branch information
Josh Wills committed Jul 5, 2012
1 parent a3eda2d commit bcf23c5
Showing 1 changed file with 12 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ private class ContainerService extends AbstractScheduledService {
private final ContainerLaunchParameters params;

private ContainerManager containerManager;
private ContainerStatus status;
private ContainerState state;
private int failedStatusChecks;

public ContainerService(Container container, ContainerLaunchParameters params) {
Expand Down Expand Up @@ -348,28 +348,28 @@ protected void runOneIteration() throws Exception {
req.setContainerId(container.getId());
try {
GetContainerStatusResponse resp = containerManager.getContainerStatus(req);
this.status = resp.getStatus();
this.state = resp.getStatus().getState();
} catch (YarnRemoteException e) {
LOG.warn("Exception getting status for " + container.getId(), e);
failedStatusChecks++;
// TODO: configure this
if (status == null || failedStatusChecks == 3) {
stop();
return;
LOG.info("Exception checking status of " + container.getId() + ", stopping");
if (LOG.isDebugEnabled()) {
LOG.debug("Exception details for " + container.getId(), e);
}
this.state = ContainerState.COMPLETE;
stop();
return;
}

if (status != null) {
LOG.info("Current status for " + container.getId() + ": " + status.getState());
if (state != null) {
LOG.info("Current status for " + container.getId() + ": " + state);
}
if (status != null && status.getState() == ContainerState.COMPLETE) {
if (state != null && state == ContainerState.COMPLETE) {
stop();
}
}

@Override
protected void shutDown() throws Exception {
if (status != null && status.getState() != ContainerState.COMPLETE) {
if (state != null && state != ContainerState.COMPLETE) {
// We need to explicitly release the container.
LOG.info("Stopping " + container.getId());
StopContainerRequest req = Records.newRecord(StopContainerRequest.class);
Expand Down

0 comments on commit bcf23c5

Please sign in to comment.