use of com.github.dockerjava.core.command.LogContainerResultCallback 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 com.github.dockerjava.core.command.LogContainerResultCallback in project engineblock by engineblock.
the class DockerMetricsHelper method startMetrics.
public void startMetrics() {
logger.info("preparing to startg graphite exporter container");
// docker run -d -p 9108:9108 -p 9109:9109 -p 9109:9109/udp prom/graphite-exporter
String GRAPHITE_EXPORTER_IMG = "prom/graphite-exporter";
String tag = "latest";
String name = "graphite-exporter";
// TODO: look into UDP
List<Integer> port = Arrays.asList(9108, 9109);
List<String> volumeDescList = Arrays.asList();
List<String> envList = Arrays.asList();
String reload = null;
startDocker(GRAPHITE_EXPORTER_IMG, tag, name, port, volumeDescList, envList, null, reload);
logger.info("graphite exporter container started");
logger.info("searching for graphite exporter container ip");
ContainerNetworkSettings settings = searchContainer(name, null).getNetworkSettings();
Map<String, ContainerNetwork> networks = settings.getNetworks();
String ip = null;
for (String key : networks.keySet()) {
ContainerNetwork network = networks.get(key);
ip = network.getIpAddress();
}
logger.info("preparing to start docker metrics");
String PROMETHEUS_IMG = "prom/prometheus";
tag = "v2.4.3";
name = "prom";
port = Arrays.asList(9090);
setupPromFiles(ip);
volumeDescList = Arrays.asList(// cwd+"/docker-metrics/prometheus:/prometheus",
userHome + "/.eb/prometheus-conf:/etc/prometheus", userHome + "/.eb/prometheus:/prometheus");
envList = null;
List<String> cmdList = Arrays.asList("--config.file=/etc/prometheus/prometheus.yml", "--storage.tsdb.path=/prometheus", "--storage.tsdb.retention=183d", "--web.enable-lifecycle");
reload = "http://localhost:9090/-/reload";
startDocker(PROMETHEUS_IMG, tag, name, port, volumeDescList, envList, cmdList, reload);
String GRAFANA_IMG = "grafana/grafana";
tag = "5.3.2";
name = "grafana";
port = Arrays.asList(3000);
setupGrafanaFiles(ip);
volumeDescList = Arrays.asList(userHome + "/.eb/grafana:/var/lib/grafana:rw");
envList = Arrays.asList("GF_SECURITY_ADMIN_PASSWORD=admin", "GF_AUTH_ANONYMOUS_ENABLED=\"true\"", "GF_SNAPSHOTS_EXTERNAL_SNAPSHOT_URL=https://assethub.datastax.com:3001", "GF_SNAPSHOTS_EXTERNAL_SNAPSHOT_NAME=\"Upload to DataStax\"");
reload = null;
String containerId = startDocker(GRAFANA_IMG, tag, name, port, volumeDescList, envList, null, reload);
LogContainerResultCallback loggingCallback = new LogContainerResultCallback();
try {
LogContainerCmd cmd = dockerClient.logContainerCmd(containerId).withStdOut(true).withFollowStream(true).withTailAll();
final boolean[] httpStarted = { false };
cmd.exec(new LogCallback());
loggingCallback.awaitCompletion(10, TimeUnit.SECONDS);
logger.info("grafana container started, http listenning");
configureGrafana();
} catch (InterruptedException e) {
e.printStackTrace();
logger.error("unable to detect grafana start");
}
}
Aggregations