use of com.github.dockerjava.api.exception.DockerClientException in project camel by apache.
the class DockerHelper method validateParameters.
/**
* Validates the URI parameters for a given {@link DockerOperation}
*
* @param dockerOperation
* @param parameters
*/
public static void validateParameters(DockerOperation dockerOperation, Map<String, Object> parameters) {
Map<String, Class<?>> validParamMap = new HashMap<String, Class<?>>();
validParamMap.putAll(DockerConstants.DOCKER_DEFAULT_PARAMETERS);
validParamMap.putAll(dockerOperation.getParameters());
for (String key : parameters.keySet()) {
String transformedKey = DockerHelper.transformToHeaderName(key);
// Validate URI parameter name
if (!validParamMap.containsKey(transformedKey)) {
throw new DockerClientException(key + " is not a valid URI parameter");
}
try {
Class<?> parameterClass = validParamMap.get(transformedKey);
Object parameterValue = parameters.get(key);
if (parameterClass == null || parameterValue == null) {
throw new DockerClientException("Failed to validate parameter type for property " + key);
}
if (Integer.class == parameterClass) {
Integer.parseInt((String) parameterValue);
} else if (Boolean.class == parameterClass) {
BooleanUtils.toBooleanObject((String) parameterValue, "true", "false", "null");
}
} catch (Exception e) {
throw new DockerClientException("Failed to validate parameter type for property " + key);
}
}
}
use of com.github.dockerjava.api.exception.DockerClientException in project elastest-torm by elastest.
the class DockerService2 method createTestContainer.
public void createTestContainer(DockerExecution dockerExec) throws TJobStoppedException {
try {
CreateContainerResponse testContainer = createContainer(dockerExec, "tjob");
String testContainerId = testContainer.getId();
dockerExec.setTestcontainer(testContainer);
dockerExec.setTestContainerId(testContainerId);
} catch (DockerClientException dce) {
throw new TJobStoppedException();
} catch (TJobStoppedException dce) {
throw new TJobStoppedException();
}
}
use of com.github.dockerjava.api.exception.DockerClientException in project elastest-torm by elastest.
the class DockerService2 method pullETExecImage.
public void pullETExecImage(String image, String name) throws TJobStoppedException {
DockerClient dockerClient = this.getDockerClient();
try {
logger.debug("Try to Pulling {} Image ({})", name, image);
dockerClient.pullImageCmd(image).exec(new PullImageResultCallback()).awaitCompletion();
logger.debug("{} image pulled succesfully!", name);
} catch (InternalServerErrorException | NotFoundException | InterruptedException e) {
if (imageExistsLocally(image, dockerClient)) {
logger.info("Docker image exits locally.");
} else {
logger.error("Error pulling the {} image: {}", name, image, e.getMessage());
}
} catch (DockerClientException e) {
logger.info("Error on Pulling {} image ({}). Probably because the user has stopped the execution", name, image);
throw new TJobStoppedException();
}
}
use of com.github.dockerjava.api.exception.DockerClientException in project elastest-torm by elastest.
the class UtilTools method getHostIp.
public String getHostIp() {
if (hostIp == null) {
if (inContainer.equals("true")) {
try {
String ipRoute = Shell.runAndWait("sh", "-c", "/sbin/ip route");
String[] tokens = ipRoute.split("\\s");
hostIp = tokens[2];
} catch (Exception e) {
throw new DockerClientException("Exception executing /sbin/ip route", e);
}
} else {
hostIp = "127.0.0.1";
}
}
logger.debug("Host IP is {}", hostIp);
return hostIp;
}
use of com.github.dockerjava.api.exception.DockerClientException in project elastest-torm by elastest.
the class DockerService2 method runDockerContainer.
/**
**************************
*/
/**
*** Container Methods ****
*/
/**
**************************
*/
public String runDockerContainer(DockerClient dockerClient, String imageName, List<String> envs, String containerName, String networkName, Ports portBindings, int listenPort) throws TJobStoppedException {
try {
dockerClient.pullImageCmd(imageName).exec(new PullImageResultCallback()).awaitSuccess();
} catch (InternalServerErrorException | NotFoundException ie) {
if (imageExistsLocally(imageName, dockerClient)) {
logger.info("Docker image exits locally.");
} else {
throw ie;
}
} catch (DockerClientException e) {
logger.info("Error on Pulling " + imageName + " image. Probably because the user has stopped the execution");
throw new TJobStoppedException();
}
CreateContainerResponse container = dockerClient.createContainerCmd(imageName).withName(containerName).withEnv(envs).withNetworkMode(networkName).withExposedPorts(ExposedPort.tcp(listenPort)).withPortBindings(portBindings).withPublishAllPorts(true).exec();
dockerClient.startContainerCmd(container.getId()).exec();
this.insertCreatedContainer(container.getId(), containerName);
logger.info("Id del contenedor:" + container.getId());
return container.getId();
}
Aggregations