当前位置: 首页>>代码示例>>Java>>正文


Java LogStream类代码示例

本文整理汇总了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", " ")
	);
}
 
开发者ID:ProgramLeague,项目名称:Avalon-Executive,代码行数:19,代码来源:DockerOperator.java

示例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("************************************");
}
 
开发者ID:amihaiemil,项目名称:comdor,代码行数:19,代码来源:RtDockerHost.java

示例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();
    }
}
 
开发者ID:alphagov,项目名称:pay-adminusers,代码行数:18,代码来源:PostgresContainer.java

示例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();
    }
}
 
开发者ID:alphagov,项目名称:pay-publicauth,代码行数:18,代码来源:PostgresContainer.java

示例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);
    }
}
 
开发者ID:oncecloud,项目名称:devops-cstack,代码行数:31,代码来源:DockerServiceImpl.java

示例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));
}
 
开发者ID:telstra,项目名称:open-kilda,代码行数:16,代码来源:ClearTablesTest.java

示例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));
    }
}
 
开发者ID:itzg,项目名称:junit-rule-docker,代码行数:30,代码来源:DockerRule.java

示例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));
}
 
开发者ID:geowarin,项目名称:docker-junit-rule,代码行数:12,代码来源:DockerRule.java

示例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);
		}
	});
}
 
开发者ID:openanalytics,项目名称:shinyproxy,代码行数:13,代码来源:LogService.java

示例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;
        }
    });
}
 
开发者ID:tdomzal,项目名称:junit-docker-rule,代码行数:28,代码来源:DockerLogs.java

示例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);
    }

}
 
开发者ID:tdomzal,项目名称:junit-docker-rule,代码行数:16,代码来源:DockerRule.java

示例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);
    }
}
 
开发者ID:sjsucohort6,项目名称:amigo-chatbot,代码行数:45,代码来源:DockerTask.java

示例13: logs

import com.spotify.docker.client.LogStream; //导入依赖的package包/类
@Override
public LogStream logs(String string, LogsParam... lps) {
    throw new IllegalStateException(DISCONNECTED); 
}
 
开发者ID:amihaiemil,项目名称:comdor,代码行数:5,代码来源:Disconnected.java

示例14: execStart

import com.spotify.docker.client.LogStream; //导入依赖的package包/类
@Override
public LogStream execStart(String string, ExecStartParameter... esps) {
    throw new IllegalStateException(DISCONNECTED); 
}
 
开发者ID:amihaiemil,项目名称:comdor,代码行数:5,代码来源:Disconnected.java

示例15: serviceLogs

import com.spotify.docker.client.LogStream; //导入依赖的package包/类
@Override
public LogStream serviceLogs(String string, LogsParam... lps) {
    throw new IllegalStateException(DISCONNECTED); 
}
 
开发者ID:amihaiemil,项目名称:comdor,代码行数:5,代码来源:Disconnected.java


注:本文中的com.spotify.docker.client.LogStream类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。