manager.stopContainer(stopRequest);
boolean completed = false;
while (!completed) {
GetContainerStatusRequest statusRequest = Records.newRecord(GetContainerStatusRequest.class);
statusRequest.setContainerId(container.getId());
GetContainerStatusResponse statusResponse = manager.getContainerStatus(statusRequest);
LOG.info("Container status: {} {}", statusResponse.getStatus(), statusResponse.getStatus().getDiagnostics());
completed = (statusResponse.getStatus().getState() == ContainerState.COMPLETE);
}
LOG.info("Container {} stopped.", container.getId());
} catch (YarnRemoteException e) {
LOG.error("Fail to stop container {}", container.getId(), e);
throw Throwables.propagate(e);