use of org.eclipse.jkube.kit.build.service.docker.wait.WaitChecker in project jkube by eclipse.
the class WaitService method prepareWaitCheckers.
private List<WaitChecker> prepareWaitCheckers(ImageConfiguration imageConfig, Properties projectProperties, String containerId) throws IOException {
WaitConfiguration wait = getWaitConfiguration(imageConfig);
if (wait == null) {
return Collections.emptyList();
}
List<WaitChecker> checkers = new ArrayList<>();
if (wait.getUrl() != null) {
checkers.add(getUrlWaitChecker(imageConfig.getDescription(), projectProperties, wait));
}
if (wait.getLog() != null) {
log.debug("LogWaitChecker: Waiting on %s", wait.getLog());
checkers.add(new LogWaitChecker(wait.getLog(), dockerAccess, containerId, log));
}
if (wait.getTcp() != null) {
try {
Container container = queryService.getMandatoryContainer(containerId);
checkers.add(getTcpWaitChecker(container, imageConfig.getDescription(), projectProperties, wait.getTcp()));
} catch (DockerAccessException e) {
throw new IOException("Unable to access container " + containerId, e);
}
}
if (wait.getHealthy() == Boolean.TRUE) {
checkers.add(new HealthCheckChecker(dockerAccess, containerId, imageConfig.getDescription(), log));
}
if (wait.getExit() != null) {
checkers.add(new ExitCodeChecker(wait.getExit(), queryService, containerId));
}
return checkers;
}
use of org.eclipse.jkube.kit.build.service.docker.wait.WaitChecker in project jkube by eclipse.
the class WaitService method wait.
// ========================================================================================================
public void wait(ImageConfiguration imageConfig, Properties projectProperties, String containerId) throws IOException {
List<WaitChecker> checkers = prepareWaitCheckers(imageConfig, projectProperties, containerId);
int timeout = getTimeOut(imageConfig);
if (checkers.isEmpty()) {
if (timeout > 0) {
log.info("%s: Pausing for %d ms", imageConfig.getDescription(), timeout);
WaitUtil.sleep(timeout);
}
return;
}
String logLine = extractCheckerLog(checkers);
ContainerRunningPrecondition precondition = new ContainerRunningPrecondition(dockerAccess, containerId);
try {
long waited = WaitUtil.wait(precondition, timeout, checkers);
log.info("%s: Waited %s %d ms", imageConfig.getDescription(), logLine, waited);
} catch (WaitTimeoutException exp) {
String desc = String.format("%s: Timeout after %d ms while waiting %s", imageConfig.getDescription(), exp.getWaited(), logLine);
log.error(desc);
throw new IOException(desc);
} catch (PreconditionFailedException exp) {
String desc = String.format("%s: Container stopped with exit code %d unexpectedly after %d ms while waiting %s", imageConfig.getDescription(), precondition.getExitCode(), exp.getWaited(), logLine);
log.error(desc);
throw new IOException(desc);
}
}
Aggregations