use of org.apache.camel.component.docker.exception.DockerException in project camel by apache.
the class AsyncDockerProducer method executeBuildImageRequest.
/**
* Produces a build image request
*
* @param client
* @param message
* @return
* @throws DockerException
*/
private BuildImageCmd executeBuildImageRequest(DockerClient client, Message message) throws DockerException {
LOGGER.debug("Executing Docker Build Image Request");
Object body = message.getBody();
BuildImageCmd buildImageCmd;
if (body != null && body instanceof InputStream) {
buildImageCmd = client.buildImageCmd((InputStream) body);
} else if (body != null && body instanceof File) {
buildImageCmd = client.buildImageCmd((File) body);
} else {
throw new DockerException("Unable to location source Image");
}
Boolean noCache = DockerHelper.getProperty(DockerConstants.DOCKER_NO_CACHE, configuration, message, Boolean.class);
if (noCache != null) {
buildImageCmd.withNoCache(noCache);
}
Boolean quiet = DockerHelper.getProperty(DockerConstants.DOCKER_QUIET, configuration, message, Boolean.class);
if (quiet != null) {
buildImageCmd.withQuiet(quiet);
}
Boolean remove = DockerHelper.getProperty(DockerConstants.DOCKER_REMOVE, configuration, message, Boolean.class);
if (remove != null) {
buildImageCmd.withRemove(remove);
}
String tag = DockerHelper.getProperty(DockerConstants.DOCKER_TAG, configuration, message, String.class);
if (tag != null) {
buildImageCmd.withTag(tag);
}
return buildImageCmd;
}
use of org.apache.camel.component.docker.exception.DockerException in project camel by apache.
the class DockerProducer method process.
public void process(Exchange exchange) throws Exception {
Message message = exchange.getIn();
DockerClient client = DockerClientFactory.getDockerClient(component, configuration, message);
DockerOperation operation = configuration.getOperation();
Object result = null;
switch(operation) {
/** General **/
case AUTH:
result = executeAuthRequest(client, message).exec();
break;
case INFO:
result = executeInfoRequest(client, message).exec();
break;
case PING:
result = executePingRequest(client, message).exec();
break;
case VERSION:
result = executeVersionRequest(client, message).exec();
break;
case CREATE_IMAGE:
result = executeCreateImageRequest(client, message).exec();
break;
case INSPECT_IMAGE:
result = executeInspectImageRequest(client, message).exec();
break;
case LIST_IMAGES:
result = executeListImagesRequest(client, message).exec();
break;
case REMOVE_IMAGE:
result = executeRemoveImageRequest(client, message).exec();
break;
case SEARCH_IMAGES:
result = executeSearchImageRequest(client, message).exec();
break;
case TAG_IMAGE:
result = executeTagImageRequest(client, message).exec();
break;
case COMMIT_CONTAINER:
result = executeCommitContainerRequest(client, message).exec();
break;
case COPY_FILE_CONTAINER:
result = executeCopyFileContainerRequest(client, message).exec();
break;
case CREATE_CONTAINER:
result = executeCreateContainerRequest(client, message).exec();
break;
case DIFF_CONTAINER:
result = executeDiffContainerRequest(client, message).exec();
break;
case INSPECT_CONTAINER:
result = executeInspectContainerRequest(client, message).exec();
break;
case LIST_CONTAINERS:
result = executeListContainersRequest(client, message).exec();
break;
case KILL_CONTAINER:
result = executeKillContainerRequest(client, message).exec();
break;
case PAUSE_CONTAINER:
result = executePauseContainerRequest(client, message).exec();
break;
case REMOVE_CONTAINER:
result = executeRemoveContainerRequest(client, message).exec();
break;
case RESTART_CONTAINER:
result = executeRestartContainerRequest(client, message).exec();
break;
case START_CONTAINER:
result = executeStartContainerRequest(client, message).exec();
break;
case STOP_CONTAINER:
result = executeStopContainerRequest(client, message).exec();
break;
case TOP_CONTAINER:
result = executeTopContainerRequest(client, message).exec();
break;
case UNPAUSE_CONTAINER:
result = executeUnpauseContainerRequest(client, message).exec();
break;
case EXEC_CREATE:
result = executeExecCreateRequest(client, message).exec();
break;
default:
throw new DockerException("Invalid operation: " + operation);
}
// If request included a response, set as body
if (result != null) {
exchange.getIn().setBody(result);
}
}
use of org.apache.camel.component.docker.exception.DockerException in project camel by apache.
the class AsyncDockerProducer method process.
@Override
public boolean process(Exchange exchange, AsyncCallback callback) {
try {
Message message = exchange.getIn();
DockerClient client = DockerClientFactory.getDockerClient(component, configuration, message);
DockerOperation operation = configuration.getOperation();
Object result = null;
switch(operation) {
/** Images **/
case BUILD_IMAGE:
// result contain an image id value
result = executeBuildImageRequest(client, message).exec(new BuildImageResultCallback() {
@Override
public void onNext(BuildResponseItem item) {
log.trace("build image callback {}", item);
super.onNext(item);
}
});
if (result != null) {
String imageId = ((BuildImageResultCallback) result).awaitImageId();
((BuildImageResultCallback) result).close();
result = imageId;
}
break;
case PULL_IMAGE:
result = executePullImageRequest(client, message).exec(new PullImageResultCallback() {
@Override
public void onNext(PullResponseItem item) {
log.trace("pull image callback {}", item);
super.onNext(item);
}
});
if (result != null) {
result = ((PullImageResultCallback) result).awaitCompletion();
((PullImageResultCallback) result).close();
}
break;
case PUSH_IMAGE:
result = executePushImageRequest(client, message).exec(new PushImageResultCallback() {
@Override
public void onNext(PushResponseItem item) {
log.trace("push image callback {}", item);
super.onNext(item);
}
});
if (result != null) {
result = ((PushImageResultCallback) result).awaitCompletion();
((PushImageResultCallback) result).close();
}
break;
/** Containers **/
case ATTACH_CONTAINER:
result = executeAttachContainerRequest(client, message).exec(new AttachContainerResultCallback() {
@Override
public void onNext(Frame item) {
log.trace("attach container callback {}", item);
super.onNext(item);
}
});
if (result != null) {
result = ((AttachContainerResultCallback) result).awaitCompletion();
((AttachContainerResultCallback) result).close();
}
break;
case LOG_CONTAINER:
result = executeLogContainerRequest(client, message).exec(new LogContainerResultCallback() {
@Override
public void onNext(Frame item) {
log.trace("log container callback {}", item);
super.onNext(item);
}
});
if (result != null) {
result = ((LogContainerResultCallback) result).awaitCompletion();
((LogContainerResultCallback) result).close();
}
break;
case WAIT_CONTAINER:
// result contain a status code value
result = executeWaitContainerRequest(client, message).exec(new WaitContainerResultCallback() {
@Override
public void onNext(WaitResponse item) {
log.trace("wait contanier callback {}", item);
super.onNext(item);
}
});
if (result != null) {
Integer statusCode = ((WaitContainerResultCallback) result).awaitStatusCode();
((WaitContainerResultCallback) result).close();
result = statusCode;
}
break;
case EXEC_START:
result = executeExecStartRequest(client, message).exec(new ExecStartResultCallback() {
@Override
public void onNext(Frame item) {
log.trace("exec start callback {}", item);
super.onNext(item);
}
});
if (result != null) {
result = ((ExecStartResultCallback) result).awaitCompletion();
((ExecStartResultCallback) result).close();
}
break;
default:
throw new DockerException("Invalid operation: " + operation);
}
// If request included a response, set as body
if (result != null) {
exchange.getIn().setBody(result);
return true;
}
} catch (DockerException | InterruptedException | IOException e) {
log.error(e.getMessage(), e);
return false;
}
return false;
}
use of org.apache.camel.component.docker.exception.DockerException in project camel by apache.
the class DockerComponent method createEndpoint.
@Override
protected Endpoint createEndpoint(String uri, String remaining, Map<String, Object> parameters) throws Exception {
// Each endpoint can have its own configuration so make
// a copy of the configuration
DockerConfiguration configuration = getConfiguration().copy();
String normalizedRemaining = remaining.replaceAll("/", "");
DockerOperation operation = DockerOperation.getDockerOperation(normalizedRemaining);
if (operation == null) {
throw new DockerException(remaining + " is not a valid operation");
}
configuration.setOperation(operation);
// Validate URI Parameters
DockerHelper.validateParameters(operation, parameters);
Endpoint endpoint = new DockerEndpoint(uri, this, configuration);
setProperties(configuration, parameters);
configuration.setParameters(parameters);
return endpoint;
}
Aggregations