Search in sources :

Example 1 with WaitConfiguration

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;
}
Also used : WaitConfiguration(org.eclipse.jkube.kit.config.image.WaitConfiguration) HealthCheckChecker(org.eclipse.jkube.kit.build.service.docker.wait.HealthCheckChecker) Container(org.eclipse.jkube.kit.build.api.model.Container) LogWaitChecker(org.eclipse.jkube.kit.build.service.docker.wait.LogWaitChecker) DockerAccessException(org.eclipse.jkube.kit.build.service.docker.access.DockerAccessException) ArrayList(java.util.ArrayList) ExitCodeChecker(org.eclipse.jkube.kit.build.service.docker.wait.ExitCodeChecker) IOException(java.io.IOException) WaitChecker(org.eclipse.jkube.kit.build.service.docker.wait.WaitChecker) LogWaitChecker(org.eclipse.jkube.kit.build.service.docker.wait.LogWaitChecker)

Example 2 with WaitConfiguration

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;
}
Also used : HttpPingChecker(org.eclipse.jkube.kit.build.service.docker.wait.HttpPingChecker) WaitConfiguration(org.eclipse.jkube.kit.config.image.WaitConfiguration)

Example 3 with WaitConfiguration

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());
            }
        }
    }
}
Also used : WaitConfiguration(org.eclipse.jkube.kit.config.image.WaitConfiguration) ExecException(org.eclipse.jkube.kit.build.service.docker.access.ExecException)

Example 4 with WaitConfiguration

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"));
}
Also used : WaitConfiguration(org.eclipse.jkube.kit.config.image.WaitConfiguration) RestartPolicy(org.eclipse.jkube.kit.config.image.RestartPolicy) LogConfiguration(org.eclipse.jkube.kit.config.image.LogConfiguration)

Aggregations

WaitConfiguration (org.eclipse.jkube.kit.config.image.WaitConfiguration)4 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 Container (org.eclipse.jkube.kit.build.api.model.Container)1 DockerAccessException (org.eclipse.jkube.kit.build.service.docker.access.DockerAccessException)1 ExecException (org.eclipse.jkube.kit.build.service.docker.access.ExecException)1 ExitCodeChecker (org.eclipse.jkube.kit.build.service.docker.wait.ExitCodeChecker)1 HealthCheckChecker (org.eclipse.jkube.kit.build.service.docker.wait.HealthCheckChecker)1 HttpPingChecker (org.eclipse.jkube.kit.build.service.docker.wait.HttpPingChecker)1 LogWaitChecker (org.eclipse.jkube.kit.build.service.docker.wait.LogWaitChecker)1 WaitChecker (org.eclipse.jkube.kit.build.service.docker.wait.WaitChecker)1 LogConfiguration (org.eclipse.jkube.kit.config.image.LogConfiguration)1 RestartPolicy (org.eclipse.jkube.kit.config.image.RestartPolicy)1