Search in sources :

Example 1 with ContainerException

use of com.github.qzagarese.dockerunit.exception.ContainerException in project dockerunit by qzagarese.

the class DefaultServiceBuilder method startContainer.

private String startContainer(CreateContainerCmd cmd, DockerClient client) {
    CreateContainerResponse createResp = cmd.exec();
    StartContainerCmd startCmd = client.startContainerCmd(createResp.getId());
    try {
        startCmd.exec();
    } catch (Throwable t) {
        throw new ContainerException(createResp.getId(), t);
    }
    return startCmd.getContainerId();
}
Also used : ContainerException(com.github.qzagarese.dockerunit.exception.ContainerException) StartContainerCmd(com.github.dockerjava.api.command.StartContainerCmd) CreateContainerResponse(com.github.dockerjava.api.command.CreateContainerResponse)

Example 2 with ContainerException

use of com.github.qzagarese.dockerunit.exception.ContainerException in project dockerunit by qzagarese.

the class DefaultServiceBuilder method createInstance.

private ServiceInstance createInstance(TestDescriptor descriptor, DockerClient client, int i) {
    CreateContainerCmd cmd = client.createContainerCmd(descriptor.getImage().value());
    cmd = computeContainerName(descriptor, i, cmd);
    cmd = executeOptionBuilders(descriptor, cmd);
    if (descriptor.getCustomisationHook() != null) {
        cmd = executeCustomisationHook(descriptor.getCustomisationHook(), descriptor.getInstance(), cmd);
    }
    String containerId = null;
    Status status = null;
    String statusDetails = null;
    try {
        containerId = createAndStartContainer(cmd, descriptor.getImage().pull(), client);
        status = Status.STARTED;
        statusDetails = "Started.";
    } catch (Throwable t) {
        if (t instanceof CompletionException) {
            if (t.getCause() != null && t.getCause() instanceof ContainerException) {
                containerId = ((ContainerException) t.getCause()).getContainerId();
                statusDetails = t.getCause().getCause() != null ? t.getCause().getCause().getMessage() : null;
            } else {
                statusDetails = t.getCause() != null ? t.getCause().getMessage() : null;
            }
        } else {
            statusDetails = t.getMessage();
        }
        status = Status.ABORTED;
    }
    return ServiceInstance.builder().containerName(cmd.getName()).containerId(containerId).status(status).statusDetails(statusDetails).build();
}
Also used : CreateContainerCmd(com.github.dockerjava.api.command.CreateContainerCmd) Status(com.github.qzagarese.dockerunit.ServiceInstance.Status) ContainerException(com.github.qzagarese.dockerunit.exception.ContainerException) CompletionException(java.util.concurrent.CompletionException)

Aggregations

ContainerException (com.github.qzagarese.dockerunit.exception.ContainerException)2 CreateContainerCmd (com.github.dockerjava.api.command.CreateContainerCmd)1 CreateContainerResponse (com.github.dockerjava.api.command.CreateContainerResponse)1 StartContainerCmd (com.github.dockerjava.api.command.StartContainerCmd)1 Status (com.github.qzagarese.dockerunit.ServiceInstance.Status)1 CompletionException (java.util.concurrent.CompletionException)1