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();
}
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();
}
Aggregations