本文整理汇总了Java中com.github.dockerjava.api.command.LogContainerCmd类的典型用法代码示例。如果您正苦于以下问题:Java LogContainerCmd类的具体用法?Java LogContainerCmd怎么用?Java LogContainerCmd使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
LogContainerCmd类属于com.github.dockerjava.api.command包,在下文中一共展示了LogContainerCmd类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: run
import com.github.dockerjava.api.command.LogContainerCmd; //导入依赖的package包/类
@Override
protected Stream<LogEntry> run() throws Exception {
LogContainerCmd cmd = dockerClient.logContainerCmd(containerId);
if (params.isWithStdOut()) {
cmd.withStdOut(true);
}
if (params.isWithStdErr()) {
cmd.withStdErr(true);
}
if (params.isWithTimestamps()) {
cmd.withTimestamps(true);
}
if (params.getTail() > 0) {
cmd.withTail(params.getTail());
}
LogContainerCallback callBack = new LogContainerCallback();
Sssh.waitForCompletion(cmd.exec(callBack));
return callBack.entries.stream();
}
示例2: getDockerLogs
import com.github.dockerjava.api.command.LogContainerCmd; //导入依赖的package包/类
/**
* Synchronized method for returning logs of docker container
*
* @param containerId - ID of the container ot lookup logs
* @return list of strings, where every string is log line
*/
public static List<String> getDockerLogs(String containerId) {
final List<String> logs = new ArrayList<>();
LogContainerCmd logContainerCmd = DockerClientFactory.build().logContainerCmd(containerId);
logContainerCmd.withStdOut(true).withStdErr(true);
try {
logContainerCmd.exec(new LogContainerResultCallback() {
@Override
public void onNext(Frame item) {
logs.add(item.toString());
}
}).awaitCompletion();
} catch (InterruptedException e) {
throw new MinimesosException("Failed to retrieve logs of container " + containerId, e);
}
return logs;
}
示例3: followOutput
import com.github.dockerjava.api.command.LogContainerCmd; //导入依赖的package包/类
/**
* {@inheritDoc}
*/
public void followOutput(DockerClient dockerClient, String containerId,
Consumer<OutputFrame> consumer, OutputFrame.OutputType... types) {
final LogContainerCmd cmd = dockerClient.logContainerCmd(containerId)
.withFollowStream(true)
.withSince(0);
final FrameConsumerResultCallback callback = new FrameConsumerResultCallback();
for (OutputFrame.OutputType type : types) {
callback.addConsumer(type, consumer);
if (type == STDOUT) cmd.withStdOut(true);
if (type == STDERR) cmd.withStdErr(true);
}
cmd.exec(callback);
}
示例4: callbackNotifier
import com.github.dockerjava.api.command.LogContainerCmd; //导入依赖的package包/类
@Override
protected AbstractCallbackNotifier<Frame> callbackNotifier(LogContainerCmd command,
ResultCallback<Frame> resultCallback) {
WebTarget webTarget = getBaseResource().path("/containers/{id}/logs").resolveTemplate("id",
command.getContainerId());
if (command.getTail() != null) {
webTarget = webTarget.queryParam("tail", command.getTail());
}
if (command.getSince() != null) {
webTarget = webTarget.queryParam("since", command.getSince());
}
webTarget = booleanQueryParam(webTarget, "timestamps", command.hasTimestampsEnabled());
webTarget = booleanQueryParam(webTarget, "stdout", command.hasStdoutEnabled());
webTarget = booleanQueryParam(webTarget, "stderr", command.hasStderrEnabled());
webTarget = booleanQueryParam(webTarget, "follow", command.hasFollowStreamEnabled());
LOGGER.trace("GET: {}", webTarget);
return new GETCallbackNotifier<Frame>(new FrameStreamProcessor(), resultCallback, webTarget.request());
}
示例5: execute0
import com.github.dockerjava.api.command.LogContainerCmd; //导入依赖的package包/类
@Override
protected Void execute0(LogContainerCmd command, ResultCallback<Frame> resultCallback) {
WebTarget webTarget = getBaseResource().path("/containers/{id}/logs").resolveTemplate("id",
command.getContainerId());
if (command.getTail() != null) {
webTarget = webTarget.queryParam("tail", command.getTail());
}
if (command.getSince() != null) {
webTarget = webTarget.queryParam("since", command.getSince());
}
webTarget = booleanQueryParam(webTarget, "timestamps", command.hasTimestampsEnabled());
webTarget = booleanQueryParam(webTarget, "stdout", command.hasStdoutEnabled());
webTarget = booleanQueryParam(webTarget, "stderr", command.hasStderrEnabled());
webTarget = booleanQueryParam(webTarget, "follow", command.hasFollowStreamEnabled());
LOGGER.trace("GET: {}", webTarget);
webTarget.request().get(resultCallback);
return null;
}
示例6: containerTailStream
import com.github.dockerjava.api.command.LogContainerCmd; //导入依赖的package包/类
public void containerTailStream (
String id,
String name,
HttpServletResponse response,
int numberOfLines ) {
try {
String targetId = getContainerId( id, name );
// docker.startContainer( container.id());
DockerContainerLogCallback loggingCallback = new DockerContainerLogCallback( response.getWriter() );
LogContainerCmd logCommand = dockerClient
.logContainerCmd( targetId )
.withStdErr( true )
.withStdOut( true );
if ( numberOfLines > 0 ) {
logCommand.withTail( numberOfLines );
}
logCommand.exec( loggingCallback );
loggingCallback.awaitCompletion( 3, TimeUnit.SECONDS );
} catch (Exception e) {
String reason = CSAP.getCsapFilteredStackTrace( e );
logger.warn( "Failed starting {}, {}", name, reason );
try {
response.getWriter().println( "Failed getting file: " + reason );
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
return;
}
示例7: copyLog
import com.github.dockerjava.api.command.LogContainerCmd; //导入依赖的package包/类
public void copyLog(String containerId, boolean follow, boolean stdout, boolean stderr, boolean timestamps, int tail,
OutputStream outputStream) throws IOException {
this.readWriteLock.readLock().lock();
try {
LogContainerCmd logContainerCmd =
dockerClient.logContainerCmd(containerId).withStdErr(false).withStdOut(false);
logContainerCmd.withFollowStream(follow);
logContainerCmd.withStdOut(stdout);
logContainerCmd.withStdErr(stderr);
logContainerCmd.withTimestamps(timestamps);
if (tail < 0) {
logContainerCmd.withTailAll();
} else {
logContainerCmd.withTail(tail);
}
OutputStreamLogsResultCallback outputStreamLogsResultCallback =
new OutputStreamLogsResultCallback(outputStream);
logContainerCmd.exec(outputStreamLogsResultCallback);
try {
outputStreamLogsResultCallback.awaitCompletion();
} catch (InterruptedException e) {
throw new IOException(e);
}
} finally {
this.readWriteLock.readLock().unlock();
}
}
示例8: containerTail
import com.github.dockerjava.api.command.LogContainerCmd; //导入依赖的package包/类
public ObjectNode containerTail (
String id,
String name,
int numberOfLines,
int since ) {
ObjectNode result = jacksonMapper.createObjectNode();
result.put( "since", since );
try {
String targetId = getContainerId( id, name );
// docker.startContainer( container.id());
if ( targetId == null ) {
result.put( "result", "View logs: " + targetId );
result.put( "plainText", "Unable to locate container - verify it is created and running" );
return result;
}
DockerContainerLogCallback loggingCallback = new DockerContainerLogCallback( true );
LogContainerCmd logCommand = dockerClient
.logContainerCmd( targetId )
.withStdErr( true )
.withStdOut( true )
.withTail( numberOfLines );
if ( since < 0 ) {
int timestamp = (int) (System.currentTimeMillis() / 1000) - 1;
since = timestamp;
}
if ( since > 0 ) {
logCommand.withSince( since );
}
result.put( "since", since );
logCommand.exec( loggingCallback );
loggingCallback.awaitCompletion( 3, TimeUnit.SECONDS );
result.put( "result", "View logs: " + targetId );
result.put( "plainText", loggingCallback.toString() );
String parameterName = "?id=" + id;
if ( id == null )
parameterName = "?name=" + name;
result.put( "url", parameterName + "&numberOfLines="
+ numberOfLines );
} catch (Exception e) {
String reason = CSAP.getCsapFilteredStackTrace( e );
logger.warn( "Failed getting logs {}, {}", name, reason );
result.put( DockerJson.error.key, "Failed starting: " + name );
result.put( DockerJson.errorReason.key, reason );
}
return result;
}
示例9: createLogContainerCmdExec
import com.github.dockerjava.api.command.LogContainerCmd; //导入依赖的package包/类
@Override
public LogContainerCmd.Exec createLogContainerCmdExec() {
return new LogContainerCmdExec(getBaseResource(), getDockerClientConfig());
}
示例10: logContainerCmd
import com.github.dockerjava.api.command.LogContainerCmd; //导入依赖的package包/类
@Override
public LogContainerCmd logContainerCmd(String containerId) {
return new LogContainerCmdImpl(getDockerCmdExecFactory().createLogContainerCmdExec(), containerId);
}
示例11: LogContainerCmdImpl
import com.github.dockerjava.api.command.LogContainerCmd; //导入依赖的package包/类
public LogContainerCmdImpl(LogContainerCmd.Exec exec, String containerId) {
super(exec);
withContainerId(containerId);
}
示例12: withContainerId
import com.github.dockerjava.api.command.LogContainerCmd; //导入依赖的package包/类
@Override
public LogContainerCmd withContainerId(String containerId) {
checkNotNull(containerId, "containerId was not specified");
this.containerId = containerId;
return this;
}
示例13: withFollowStream
import com.github.dockerjava.api.command.LogContainerCmd; //导入依赖的package包/类
@Override
public LogContainerCmd withFollowStream(Boolean followStream) {
this.followStream = followStream;
return this;
}
示例14: withTimestamps
import com.github.dockerjava.api.command.LogContainerCmd; //导入依赖的package包/类
@Override
public LogContainerCmd withTimestamps(Boolean timestamps) {
this.timestamps = timestamps;
return this;
}
示例15: withStdOut
import com.github.dockerjava.api.command.LogContainerCmd; //导入依赖的package包/类
@Override
public LogContainerCmd withStdOut(Boolean stdout) {
this.stdout = stdout;
return this;
}