use of com.github.dockerjava.api.model.Frame in project spring-boot by spring-projects.
the class SysVinitLaunchScriptIT method doTest.
private String doTest(String script) throws Exception {
DockerClient docker = createClient();
String imageId = buildImage(docker);
String container = createContainer(docker, imageId, script);
try {
copyFilesToContainer(docker, container, script);
docker.startContainerCmd(container).exec();
StringBuilder output = new StringBuilder();
AttachContainerResultCallback resultCallback = docker.attachContainerCmd(container).withStdOut(true).withStdErr(true).withFollowStream(true).withLogs(true).exec(new AttachContainerResultCallback() {
@Override
public void onNext(Frame item) {
output.append(new String(item.getPayload()));
super.onNext(item);
}
});
resultCallback.awaitCompletion(60, TimeUnit.SECONDS).close();
docker.waitContainerCmd(container).exec();
return output.toString();
} finally {
docker.removeContainerCmd(container).exec();
}
}
use of com.github.dockerjava.api.model.Frame 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;
}
Aggregations