本文整理汇总了Java中com.spotify.docker.client.LogStream类的典型用法代码示例。如果您正苦于以下问题:Java LogStream类的具体用法?Java LogStream怎么用?Java LogStream使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
LogStream类属于com.spotify.docker.client包,在下文中一共展示了LogStream类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: exec
import com.spotify.docker.client.LogStream; //导入依赖的package包/类
public ExecPair exec(String containerId, String cmd) throws DockerException, InterruptedException, IOException {
final String execId = client.execCreate(
containerId,
cmd.split(" "),
ExecCreateParam.attachStdout(),
ExecCreateParam.tty())
.id();
SafetyOutputStream outputStream = new SafetyOutputStream();
try (final LogStream stream = client.execStart(execId)) {
stream.attach(outputStream, outputStream);
}
LOGGER.info("execute cmd to container successful - execId: " + execId);
String r = outputStream.get();
return new ExecPair(execId, r
.replace("\r", "")
.replace("\n", " ")
);
}
示例2: followLogs
import com.spotify.docker.client.LogStream; //导入依赖的package包/类
@Override
public void followLogs(final String containerId, final Logger logger) {
logger.info("********** Container logs **********");
try {
final LogStream logs = this.client.logs(
containerId,
DockerClient.LogsParam.stdout(),
DockerClient.LogsParam.stderr(),
DockerClient.LogsParam.follow()
);
logger.info(logs.readFully());
} catch (final DockerException | InterruptedException ex) {
throw new IllegalStateException(
"Exception when starting container with id " + containerId, ex
);
}
logger.info("************************************");
}
示例3: stop
import com.spotify.docker.client.LogStream; //导入依赖的package包/类
public void stop() {
if (stopped) {
return;
}
try {
stopped = true;
System.out.println("Killing postgres container with ID: " + containerId);
LogStream logs = docker.logs(containerId, DockerClient.LogsParam.stdout(), DockerClient.LogsParam.stderr());
System.out.println("Killed container logs:\n");
logs.attach(System.out, System.err);
docker.stopContainer(containerId, 5);
docker.removeContainer(containerId);
} catch (DockerException | InterruptedException | IOException e) {
System.err.println("Could not shutdown " + containerId);
e.printStackTrace();
}
}
示例4: stop
import com.spotify.docker.client.LogStream; //导入依赖的package包/类
public void stop() {
if (stopped) {
return;
}
try {
stopped = true;
System.err.println("Killing postgres container with ID: " + containerId);
LogStream logs = docker.logs(containerId, DockerClient.LogsParam.stdout(), DockerClient.LogsParam.stderr());
System.err.println("Killed container logs:\n");
logs.attach(System.err, System.err);
docker.stopContainer(containerId, 5);
docker.removeContainer(containerId);
} catch (DockerException | InterruptedException | IOException e) {
System.err.println("Could not shutdown " + containerId);
e.printStackTrace();
}
}
示例5: execCommand
import com.spotify.docker.client.LogStream; //导入依赖的package包/类
@Override
public String execCommand(String containerName, String command, boolean privileged, boolean detached)
throws FatalDockerJSONException {
final String[] commands = { "bash", "-c", command };
String execId = null;
try {
if (privileged) {
execId = dockerClient.execCreate(containerName, commands,
com.spotify.docker.client.DockerClient.ExecCreateParam.detach(detached),
com.spotify.docker.client.DockerClient.ExecCreateParam.attachStdout(),
com.spotify.docker.client.DockerClient.ExecCreateParam.attachStderr(),
com.spotify.docker.client.DockerClient.ExecCreateParam.user("root")).id();
} else {
execId = dockerClient.execCreate(containerName, commands,
com.spotify.docker.client.DockerClient.ExecCreateParam.detach(detached),
com.spotify.docker.client.DockerClient.ExecCreateParam.attachStdout(),
com.spotify.docker.client.DockerClient.ExecCreateParam.attachStderr()).id();
}
try (final LogStream stream = dockerClient.execStart(execId)) {
final String output = stream.readFully();
logger.debug(output);
return output;
}
} catch (DockerException | InterruptedException e) {
StringBuilder msgError = new StringBuilder();
msgError.append("containerName:[").append(containerName).append("]");
msgError.append(", command:[").append(command).append("]");
throw new FatalDockerJSONException(msgError.toString(), e);
}
}
示例6: addRules
import com.spotify.docker.client.LogStream; //导入依赖的package包/类
@Given("^added custom flow rules")
public void addRules() throws Exception {
Container mininetContainer = dockerClient.listContainers()
.stream()
.filter(container -> container.image().startsWith(MININET_CONTAINER_PREFIX))
.findFirst().orElseThrow(() -> new IllegalStateException("Floodlight controller should be active"));
final String[] commands = {"ovs-ofctl", "-O", "Openflow13", "add-flow", SWITCH_NAME, RULE};
ExecCreation execCreation = dockerClient.execCreate(mininetContainer.id(), commands,
DockerClient.ExecCreateParam.attachStdout(), DockerClient.ExecCreateParam.attachStderr());
final LogStream output = dockerClient.execStart(execCreation.id());
final String execOutput = output.readFully();
assertTrue(StringUtils.isEmpty(execOutput));
}
示例7: handleWaitingForLog
import com.spotify.docker.client.LogStream; //导入依赖的package包/类
private void handleWaitingForLog(String containerId, Semaphore ready) throws DockerException, InterruptedException {
final LogStream logStream = dockerClient.logs(containerId,
DockerClient.LogsParam.stdout(), DockerClient.LogsParam.stderr(), DockerClient.LogsParam.follow());
LOGGER.debug("Waiting for log snippet '{}'", waitForLog);
new Thread(() -> {
try {
while (logStream.hasNext()) {
final LogMessage msg = logStream.next();
final String logStr = StandardCharsets.UTF_8.decode(msg.content()).toString();
LOGGER.debug("CONTAINER: {}", logStr);
if (logStr.contains(waitForLog)) {
ready.release();
return;
}
}
} finally {
logStream.close();
}
}).start();
if (!ready.tryAcquire(waitForLogTimeout, TimeUnit.MILLISECONDS)) {
Assert.fail(String.format(
"Did not observe desired Docker container log snippet within %d ms",
waitForLogTimeout));
}
}
示例8: waitForLog
import com.spotify.docker.client.LogStream; //导入依赖的package包/类
protected void waitForLog(String messageToMatch) throws DockerException, InterruptedException, UnsupportedEncodingException {
LogStream logs = dockerClient.logs(container.id(), follow(), stdout());
String log;
do {
LogMessage logMessage = logs.next();
ByteBuffer buffer = logMessage.content();
byte[] bytes = new byte[buffer.remaining()];
buffer.get(bytes);
log = new String(bytes);
} while (!log.contains(messageToMatch));
}
示例9: attachLogWriter
import com.spotify.docker.client.LogStream; //导入依赖的package包/类
public void attachLogWriter(Proxy proxy, LogStream logStream) {
if (!isContainerLoggingEnabled()) return;
executor.submit(() -> {
try {
Path[] paths = getLogFilePaths(proxy.containerId);
// Note that this call will block until the container is stopped.
logStream.attach(new FileOutputStream(paths[0].toFile()), new FileOutputStream(paths[1].toFile()));
} catch (IOException e) {
log.error("Failed to attach logging of container " + proxy.containerId, e);
}
});
}
示例10: start
import com.spotify.docker.client.LogStream; //导入依赖的package包/类
public void start() throws IOException, InterruptedException {
final String containerShortId = StringUtils.left(containerId, SHORT_ID_LEN);
final LogSplitter logSplitter = new LogSplitter();
if (lineListener != null) {
executor.submit(new LogPrinter("", logSplitter.getCombinedInput(), null, lineListener));
}
if (stdoutWriter != null) {
executor.submit(new LogPrinter(containerShortId+"-stdout> ", logSplitter.getStdoutInput(), stdoutWriter, null));
}
if (stderrWriter != null) {
executor.submit(new LogPrinter(containerShortId+"-stderr> ", logSplitter.getStderrInput(), stderrWriter, null));
}
executor.submit(new Callable<Void>() {
@Override
public Void call() throws Exception {
log.trace("{} attaching to logs", containerShortId);
LogStream logs = dockerClient.logs(containerId, LogsParam.stdout(), LogsParam.stderr(), LogsParam.follow());
try {
logs.attach(logSplitter.getStdoutOutput(), logSplitter.getStderrOutput());
} finally {
IOUtils.closeQuietly(logs, logSplitter);
log.trace("{} dettached from logs", containerShortId);
}
return null;
}
});
}
示例11: getLog
import com.spotify.docker.client.LogStream; //导入依赖的package包/类
/**
* Container log.
*/
public String getLog() {
try (LogStream stream = dockerClient.logs(container.id(), LogsParam.stdout(), LogsParam.stderr());) {
String fullLog = stream.readFully();
if (log.isTraceEnabled()) {
log.trace("{} full log: {}", containerShortId, StringUtils.replace(fullLog, "\n", "|"));
}
return fullLog;
} catch (DockerException | InterruptedException | IOException e) {
throw new IllegalStateException(e);
}
}
示例12: execute
import com.spotify.docker.client.LogStream; //导入依赖的package包/类
/**
* Executes a containerized command on AWS.
*/
public String execute(String dockerImage, List<String> envList, List<String> commandList, String entryPoint) throws CommandExecutionException {
try( DockerClient dockerClient = new DefaultDockerClient("unix:///var/run/docker.sock")) {
String response = null;
//pullImage(dockerClient, dockerImage);
dockerClient.pull(dockerImage);
if (commandList != null && !commandList.isEmpty()) {
if (commandList.get(0).equalsIgnoreCase(entryPoint)) {
commandList = commandList.subList(1, commandList.size());
}
}
final ContainerConfig containerConfig = ContainerConfig.builder()
.image(dockerImage)
.env(envList)
.entrypoint(entryPoint)
.cmd(commandList)
.build();
final ContainerCreation container = dockerClient.createContainer(containerConfig);
final String containerId = container.id();
dockerClient.startContainer(containerId);
// Wait for the container to exit.
// If we don't wait, docker.logs() might return an epmty string because the container
// cmd hasn't run yet.
dockerClient.waitContainer(containerId);
final String log;
try (LogStream logs = dockerClient.logs(containerId, stdout(), stderr())) {
log = logs.readFully();
}
logger.info(log);
response = log;
dockerClient.removeContainer(containerId);
return response;
} catch (DockerException | InterruptedException e) {
throw new CommandExecutionException(e);
}
}
示例13: logs
import com.spotify.docker.client.LogStream; //导入依赖的package包/类
@Override
public LogStream logs(String string, LogsParam... lps) {
throw new IllegalStateException(DISCONNECTED);
}
示例14: execStart
import com.spotify.docker.client.LogStream; //导入依赖的package包/类
@Override
public LogStream execStart(String string, ExecStartParameter... esps) {
throw new IllegalStateException(DISCONNECTED);
}
示例15: serviceLogs
import com.spotify.docker.client.LogStream; //导入依赖的package包/类
@Override
public LogStream serviceLogs(String string, LogsParam... lps) {
throw new IllegalStateException(DISCONNECTED);
}