use of org.eclipse.jkube.kit.config.image.WaitConfiguration 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.config.image.WaitConfiguration in project jkube by eclipse.
the class WaitService method getUrlWaitChecker.
// =================================================================================================================
private WaitChecker getUrlWaitChecker(String imageConfigDesc, Properties projectProperties, WaitConfiguration wait) {
String waitUrl = StringSubstitutor.replace(wait.getUrl(), projectProperties);
WaitConfiguration.HttpConfiguration httpConfig = wait.getHttp();
HttpPingChecker checker;
if (httpConfig != null) {
checker = new HttpPingChecker(waitUrl, httpConfig.getMethod(), httpConfig.getStatus(), httpConfig.isAllowAllHosts());
log.info("%s: Waiting on url %s with method %s for status %s.", imageConfigDesc, waitUrl, httpConfig.getMethod(), httpConfig.getStatus());
} else {
checker = new HttpPingChecker(waitUrl);
log.info("%s: Waiting on url %s.", imageConfigDesc, waitUrl);
}
return checker;
}
use of org.eclipse.jkube.kit.config.image.WaitConfiguration in project jkube by eclipse.
the class StartContainerExecutor method waitAndPostExec.
private void waitAndPostExec(String containerId, Properties projProperties) throws IOException, ExecException {
// Wait if requested
hub.getWaitService().wait(imageConfig, projProperties, containerId);
WaitConfiguration waitConfig = imageConfig.getRunConfiguration().getWait();
if (waitConfig != null && waitConfig.getExec() != null && waitConfig.getExec().getPostStart() != null) {
try {
hub.getRunService().execInContainer(containerId, waitConfig.getExec().getPostStart(), imageConfig);
} catch (ExecException exp) {
if (waitConfig.getExec().isBreakOnError()) {
throw exp;
} else {
log.warn("Cannot run postStart: %s", exp.getMessage());
}
}
}
}
use of org.eclipse.jkube.kit.config.image.WaitConfiguration in project jkube by eclipse.
the class PropertyConfigHandlerTest method validateRunConfiguration.
protected void validateRunConfiguration(RunImageConfiguration runConfig) {
assertEquals(a("/foo", "/tmp:/tmp"), runConfig.getVolumeConfiguration().getBind());
assertEquals(a("CAP"), runConfig.getCapAdd());
assertEquals(a("CAP"), runConfig.getCapDrop());
assertEquals(a("seccomp=unconfined"), runConfig.getSecurityOpts());
assertEquals("command.sh", runConfig.getCmd().getShell());
assertEquals(a("8.8.8.8"), runConfig.getDns());
assertEquals("host", runConfig.getNetworkingConfig().getStandardMode(null));
assertEquals(a("example.com"), runConfig.getDnsSearch());
assertEquals("domain.com", runConfig.getDomainname());
assertEquals("entrypoint.sh", runConfig.getEntrypoint().getShell());
assertEquals(a("localhost:127.0.0.1"), runConfig.getExtraHosts());
assertEquals("subdomain", runConfig.getHostname());
assertEquals(a("redis"), runConfig.getLinks());
assertEquals((Long) 1L, runConfig.getMemory());
assertEquals((Long) 1L, runConfig.getMemorySwap());
assertEquals((Long) 1000000000L, runConfig.getCpus());
assertEquals((Long) 1L, runConfig.getCpuShares());
assertEquals("0,1", runConfig.getCpuSet());
assertEquals("/tmp/envProps.txt", runConfig.getEnvPropertyFile());
assertEquals("/tmp/props.txt", runConfig.getPortPropertyFile());
assertEquals("8081:8080", runConfig.getPorts().get(0));
assertEquals(true, runConfig.getPrivileged());
assertEquals("tomcat", runConfig.getUser());
assertEquals(a("from"), runConfig.getVolumeConfiguration().getFrom());
assertEquals("foo", runConfig.getWorkingDir());
assertNotNull(runConfig.getUlimits());
assertEquals(4, runConfig.getUlimits().size());
assertUlimitEquals(ulimit("memlock", 10, 10), runConfig.getUlimits().get(0));
assertUlimitEquals(ulimit("memlock", null, -1), runConfig.getUlimits().get(1));
assertUlimitEquals(ulimit("memlock", 1024, null), runConfig.getUlimits().get(2));
assertUlimitEquals(ulimit("memlock", 2048, null), runConfig.getUlimits().get(3));
assertEquals("/var/lib/mysql:10m", runConfig.getTmpfs().get(0));
assertEquals(1, runConfig.getTmpfs().size());
assertEquals("Never", runConfig.getImagePullPolicy());
assertEquals(true, runConfig.getReadOnly());
assertEquals(true, runConfig.getAutoRemove());
validateEnv(runConfig.getEnv());
// not sure it's worth it to implement 'equals/hashcode' for these
RestartPolicy policy = runConfig.getRestartPolicy();
assertEquals("on-failure", policy.getName());
assertEquals(1, policy.getRetry());
WaitConfiguration wait = runConfig.getWait();
assertEquals("http://foo.com", wait.getUrl());
assertEquals("pattern", wait.getLog());
assertEquals("post_start_command", wait.getExec().getPostStart());
assertEquals("pre_stop_command", wait.getExec().getPreStop());
assertTrue(wait.getExec().isBreakOnError());
assertEquals(5, wait.getTime().intValue());
assertTrue(wait.getHealthy());
assertEquals(0, wait.getExit().intValue());
LogConfiguration config = runConfig.getLog();
assertEquals("green", config.getColor());
assertTrue(config.isEnabled());
assertEquals("SRV", config.getPrefix());
assertEquals("iso8601", config.getDate());
assertEquals("json", config.getDriver().getName());
assertEquals(2, config.getDriver().getOpts().size());
assertEquals("1024", config.getDriver().getOpts().get("max-size"));
assertEquals("10", config.getDriver().getOpts().get("max-file"));
}
Aggregations