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


Java ExecCreateCmdResponse类代码示例

本文整理汇总了Java中com.github.dockerjava.api.command.ExecCreateCmdResponse的典型用法代码示例。如果您正苦于以下问题:Java ExecCreateCmdResponse类的具体用法?Java ExecCreateCmdResponse怎么用?Java ExecCreateCmdResponse使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


ExecCreateCmdResponse类属于com.github.dockerjava.api.command包,在下文中一共展示了ExecCreateCmdResponse类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: runCommand

import com.github.dockerjava.api.command.ExecCreateCmdResponse; //导入依赖的package包/类
private boolean runCommand(@NonNull final DockerClient _dockerClient,
                           @NonNull final CreateContainerResponse _container,
                           @NonNull final String[] _commandWithArguments) {
    final ExecCreateCmdResponse mExecCreateCmdResponse = _dockerClient
            .execCreateCmd(_container.getId())
            .withAttachStdout(true)
            .withCmd(_commandWithArguments)
            .exec();

    try {
        return _dockerClient
                .execStartCmd(mExecCreateCmdResponse.getId())
                .exec(new ExecStartResultCallback() {
                    @Override
                    public void onNext(Frame frame) {
                        super.onNext(frame);
                    }
                })
                .awaitCompletion(30, TimeUnit.MINUTES);
    } catch (InterruptedException e) {
        // ignore
    }

    return false;
}
 
开发者ID:jonfryd,项目名称:tifoon,代码行数:26,代码来源:DockerExecutorPlugin.java

示例2: execCommand

import com.github.dockerjava.api.command.ExecCreateCmdResponse; //导入依赖的package包/类
public String execCommand(String containerId, String... command) {
  ExecCreateCmdResponse exec = client.execCreateCmd(containerId).withCmd(command).withTty(false)
      .withAttachStdin(true).withAttachStdout(true).withAttachStderr(true).exec();
  OutputStream outputStream = new ByteArrayOutputStream();
  String output = null;
  try {
    client.execStartCmd(exec.getId()).withDetach(false).withTty(true)
        .exec(new ExecStartResultCallback(outputStream, System.err)).awaitCompletion();
    output = outputStream.toString();// IOUtils.toString(outputStream, Charset.defaultCharset());
  } catch (InterruptedException e) {
    log.warn("Exception executing command {} on container {}", Arrays.toString(command),
        containerId, e);
  }

  return output;
}
 
开发者ID:Kurento,项目名称:kurento-java,代码行数:17,代码来源:Docker.java

示例3: execStartAttached

import com.github.dockerjava.api.command.ExecCreateCmdResponse; //导入依赖的package包/类
@Test
public void execStartAttached() throws Exception {
    String containerName = "generated_" + new SecureRandom().nextInt();

    CreateContainerResponse container = dockerRule.getClient().createContainerCmd("busybox").withCmd("sleep", "9999")
            .withName(containerName).exec();
    LOG.info("Created container {}", container.toString());
    assertThat(container.getId(), not(isEmptyString()));

    dockerRule.getClient().startContainerCmd(container.getId()).exec();

    ExecCreateCmdResponse execCreateCmdResponse = dockerRule.getClient().execCreateCmd(container.getId())
            .withAttachStdout(true).withCmd("touch", "/execStartTest.log").exec();
    dockerRule.getClient().execStartCmd(execCreateCmdResponse.getId()).withDetach(false).withTty(true)
            .exec(new ExecStartResultCallback(System.out, System.err)).awaitCompletion();

    InputStream response = dockerRule.getClient().copyArchiveFromContainerCmd(container.getId(), "/execStartTest.log").exec();
    Boolean bytesAvailable = response.available() > 0;
    assertTrue( "The file was not copied from the container.", bytesAvailable);

    // read the stream fully. Otherwise, the underlying stream will not be closed.
    String responseAsString = asString(response);
    assertNotNull(responseAsString);
    assertTrue(responseAsString.length() > 0);
}
 
开发者ID:docker-java,项目名称:docker-java,代码行数:26,代码来源:ExecStartCmdIT.java

示例4: execStartWithNonExistentUser

import com.github.dockerjava.api.command.ExecCreateCmdResponse; //导入依赖的package包/类
@Test(expected = NotFoundException.class)
public void execStartWithNonExistentUser() throws Exception {
    String containerName = "generated_" + new SecureRandom().nextInt();

    CreateContainerResponse container = dockerRule.getClient().createContainerCmd("busybox").withCmd("sleep", "9999")
            .withName(containerName).exec();
    LOG.info("Created container {}", container.toString());
    assertThat(container.getId(), not(isEmptyString()));

    dockerRule.getClient().startContainerCmd(container.getId()).exec();

    ExecCreateCmdResponse execCreateCmdResponse = dockerRule.getClient().execCreateCmd(container.getId())
            .withAttachStdout(true).withCmd("touch", "/execStartTest.log").withUser("NonExistentUser").exec();
    dockerRule.getClient().execStartCmd(execCreateCmdResponse.getId()).withDetach(false).withTty(true)
            .exec(new ExecStartResultCallback(System.out, System.err)).awaitCompletion();

    dockerRule.getClient().copyArchiveFromContainerCmd(container.getId(), "/execStartTest.log").exec();
}
 
开发者ID:docker-java,项目名称:docker-java,代码行数:19,代码来源:ExecStartCmdIT.java

示例5: container_should_have_static_ip_for_app_net_network

import com.github.dockerjava.api.command.ExecCreateCmdResponse; //导入依赖的package包/类
@Test
public void container_should_have_static_ip_for_app_net_network() throws InterruptedException, IOException {
    final InspectContainerResponse pingpong = dockerClient.inspectContainerCmd("pingpong").exec();

    ExecCreateCmdResponse execCreateCmdResponse = dockerClient.execCreateCmd(pingpong.getId())
        .withAttachStdout(true).withAttachStdin(true).withAttachStderr(true).withTty(false).withCmd("ifconfig")
        .exec();
    try (OutputStream outputStream = new ByteArrayOutputStream();
         OutputStream errorStream = new ByteArrayOutputStream()) {

        dockerClient.execStartCmd(execCreateCmdResponse.getId()).withDetach(false)
            .exec(new ExecStartResultCallback(outputStream, errorStream)).awaitCompletion();

        assertThat(outputStream.toString()).contains("inet addr:172.16.238.10",
            "inet6 addr: fe80::42:acff:fe10:ee0a/64");
    }
}
 
开发者ID:arquillian,项目名称:arquillian-cube,代码行数:18,代码来源:PingPongIT.java

示例6: containerCommand

import com.github.dockerjava.api.command.ExecCreateCmdResponse; //导入依赖的package包/类
private String containerCommand ( String containerId, String... command ) {

		String commandOutput = "";
		try {

			ExecCreateCmdResponse execCreateCmdResponse = dockerClient
				.execCreateCmd( containerId )
				.withAttachStdout( true )
				.withAttachStderr( true )
				.withCmd( command )
				.withUser( "root" )
				.exec();

			ByteArrayOutputStream lsOutputStream = new ByteArrayOutputStream();
			dockerClient
				.execStartCmd( execCreateCmdResponse.getId() )
				.exec(
					new ExecStartResultCallback( lsOutputStream, lsOutputStream ) )
				.awaitCompletion();

			commandOutput = new String( lsOutputStream.toByteArray(), StandardCharsets.UTF_8 );

		} catch (Exception e) {

			String reason = CSAP.getCsapFilteredStackTrace( e );
			logger.warn( "Failed listing files in {}, {}", containerId, reason );

		}

		logger.debug( "Container: {}, Command: {}, output: {}", containerId, Arrays.asList( command ), commandOutput );

		return commandOutput;
	}
 
开发者ID:csap-platform,项目名称:csap-core,代码行数:34,代码来源:Docker_Java.java

示例7: killRetzServerProcess

import com.github.dockerjava.api.command.ExecCreateCmdResponse; //导入依赖的package包/类
boolean killRetzServerProcess() throws InterruptedException, UnsupportedEncodingException {
    int pid = getRetzServerPid();

    ExecCreateCmdResponse checkPs1 = dockerClient.execCreateCmd(containerId).withAttachStdout(true)
            .withAttachStderr(true).withCmd("kill", Integer.toString(pid)).exec();
    dockerClient.execStartCmd(checkPs1.getId()).withDetach(false)
            .exec(new ExecStartResultCallback(System.out, System.err)).awaitCompletion();

    Thread.sleep(3 * 1024); // 3 seconds rule
    String ps = ps();
    return !ps.contains("retz-server-all.jar");
}
 
开发者ID:retz,项目名称:retz,代码行数:13,代码来源:ClosableContainer.java

示例8: system

import com.github.dockerjava.api.command.ExecCreateCmdResponse; //导入依赖的package包/类
public String system(String[] command) throws Exception {
    ExecCreateCmdResponse spawnAgent = dockerClient
            .execCreateCmd(containerId).withTty(true)
            .withAttachStdout(true).withAttachStderr(true)
            .withCmd(command).exec();
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    dockerClient.execStartCmd(spawnAgent.getId()).withDetach(false)
            .exec(new ExecStartResultCallback(out, System.err))
            .awaitCompletion(8, TimeUnit.SECONDS);
    return out.toString(String.valueOf(StandardCharsets.UTF_8));
}
 
开发者ID:retz,项目名称:retz,代码行数:12,代码来源:ClosableContainer.java

示例9: createHolderTask

import com.github.dockerjava.api.command.ExecCreateCmdResponse; //导入依赖的package包/类
private Runnable createHolderTask(String name, String[] command) {
    return () -> {
        try {
            ExecCreateCmdResponse spawnAgent = dockerClient
                    .execCreateCmd(containerId).withTty(false)
                    .withAttachStdout(false).withAttachStderr(false)
                    .withCmd(command).exec();
            dockerClient.execStartCmd(spawnAgent.getId()).withDetach(true)
                    .exec(new ExecStartResultCallback(System.out, System.err));
            System.err.println("Thread: " + name + " finished. Id=" + spawnAgent.getId());
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    };
}
 
开发者ID:retz,项目名称:retz,代码行数:16,代码来源:ClosableContainer.java

示例10: cmd

import com.github.dockerjava.api.command.ExecCreateCmdResponse; //导入依赖的package包/类
private String cmd(String... cmds) throws InterruptedException, UnsupportedEncodingException {
    ExecCreateCmdResponse checkPs1 = dockerClient.execCreateCmd(containerId).withAttachStdout(true)
            .withAttachStderr(true).withCmd(cmds).exec();
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    dockerClient.execStartCmd(checkPs1.getId()).withDetach(false)
            .exec(new ExecStartResultCallback(out, System.err)).awaitCompletion();
    return out.toString(String.valueOf(StandardCharsets.UTF_8));
}
 
开发者ID:retz,项目名称:retz,代码行数:9,代码来源:ClosableContainer.java

示例11: JediDockerClient

import com.github.dockerjava.api.command.ExecCreateCmdResponse; //导入依赖的package包/类
public JediDockerClient(DockerClientBuilder builder) throws InterruptedException {
    this.commands = builder.requiredCommands;
    this.bindings = builder.bindings;
    this.imageName = builder.imageName;
    this.containerName = builder.containerName;
    this.stdOutputStream = builder.stdOutputStream;
    this.errOutputStream = builder.errOutputStream;

    String containerId = null;
    if(containerExistsByName(containerName)){
        containerId = getContainerByName(containerName).getId();

        if(!isRunningById(containerId)){
            dockerClient.startContainerCmd(containerId).exec();
        }
    }
    else {
        containerId = createContainer();
        dockerClient.startContainerCmd(containerId).exec();
    }

    // Information about docker-java API usage is available at
    //      https://github.com/docker-java/docker-java/wiki
    // and
    //      https://github.com/docker-java/docker-java/tree/master/src/test/java/com/github/dockerjava/core/command
    ExecCreateCmdResponse aCommand = createCommand(containerId);
    runCommand(aCommand);

}
 
开发者ID:b-long,项目名称:jedi,代码行数:30,代码来源:JediDockerClient.java

示例12: createCommand

import com.github.dockerjava.api.command.ExecCreateCmdResponse; //导入依赖的package包/类
private ExecCreateCmdResponse createCommand(String containerId){
    logger.debug("Preparing commands: '%s'", commands);
    return dockerClient
            .execCreateCmd(containerId)
            .withAttachStdout(true)
            .withAttachStderr(true)
            .withCmd(commands)
            .exec();
}
 
开发者ID:b-long,项目名称:jedi,代码行数:10,代码来源:JediDockerClient.java

示例13: testExecuteCompletes

import com.github.dockerjava.api.command.ExecCreateCmdResponse; //导入依赖的package包/类
@Test
public void testExecuteCompletes() throws Exception {
    final String containerId = "container-id";
    final String[] command = new String[] {"/bin/ls", "-l"};
    final String execId = "exec-id";
    final int exitCode = 3;

    final DockerClient dockerClient = mock(DockerClient.class);

    final ExecCreateCmdResponse response = mock(ExecCreateCmdResponse.class);
    when(response.getId()).thenReturn(execId);

    final ExecCreateCmd execCreateCmd = mock(ExecCreateCmd.class);
    when(dockerClient.execCreateCmd(any(String.class))).thenReturn(execCreateCmd);
    when(execCreateCmd.withCmd(Matchers.<String>anyVararg())).thenReturn(execCreateCmd);
    when(execCreateCmd.withAttachStdout(any(Boolean.class))).thenReturn(execCreateCmd);
    when(execCreateCmd.withAttachStderr(any(Boolean.class))).thenReturn(execCreateCmd);
    when(execCreateCmd.withUser(any(String.class))).thenReturn(execCreateCmd);
    when(execCreateCmd.exec()).thenReturn(response);

    final ExecStartCmd execStartCmd = mock(ExecStartCmd.class);
    when(dockerClient.execStartCmd(any(String.class))).thenReturn(execStartCmd);
    when(execStartCmd.exec(any(ExecStartResultCallback.class))).thenReturn(mock(ExecStartResultCallback.class));

    final InspectExecCmd inspectExecCmd = mock(InspectExecCmd.class);
    final InspectExecResponse state = mock(InspectExecResponse.class);
    when(dockerClient.inspectExecCmd(any(String.class))).thenReturn(inspectExecCmd);
    when(inspectExecCmd.exec()).thenReturn(state);
    when(state.isRunning()).thenReturn(false);
    when(state.getExitCode()).thenReturn(exitCode);

    final Docker docker = new DockerImpl(dockerClient);
    final ProcessResult result = docker.executeInContainer(new ContainerName(containerId), command);
    assertThat(result.getExitStatus(), is(exitCode));
}
 
开发者ID:vespa-engine,项目名称:vespa,代码行数:36,代码来源:DockerImplTest.java

示例14: executeInContainer

import com.github.dockerjava.api.command.ExecCreateCmdResponse; //导入依赖的package包/类
private Integer executeInContainer(ContainerName containerName, String runAsUser, String... args) throws InterruptedException {
    logger.info("Executing as '" + runAsUser + "' in '" + containerName.asString() + "': " + String.join(" ", args));
    ExecCreateCmdResponse response = docker.dockerClient.execCreateCmd(containerName.asString())
            .withCmd(args)
            .withAttachStdout(true)
            .withAttachStderr(true)
            .withUser(runAsUser)
            .exec();

    ExecStartCmd execStartCmd = docker.dockerClient.execStartCmd(response.getId());
    execStartCmd.exec(new ExecStartResultCallback(System.out, System.err)).awaitCompletion();

    InspectExecResponse state = docker.dockerClient.inspectExecCmd(execStartCmd.getExecId()).exec();
    return state.getExitCode();
}
 
开发者ID:vespa-engine,项目名称:vespa,代码行数:16,代码来源:RunSystemTests.java

示例15: execRootInContainer

import com.github.dockerjava.api.command.ExecCreateCmdResponse; //导入依赖的package包/类
public ExecResult execRootInContainer(String... command) throws UnsupportedOperationException, IOException, InterruptedException {
	Charset outputCharset = UTF8;

	if (!TestEnvironment.dockerExecutionDriverSupportsExec()) {
		// at time of writing, this is the expected result in CircleCI.
		throw new UnsupportedOperationException("Your docker daemon is running the \"lxc\" driver, which doesn't support \"docker exec\".");
	}

	if (!isRunning()) {
		throw new IllegalStateException("Container is not running so exec cannot be run");
	}

	this.dockerClient.execCreateCmd(this.containerId).withCmd(command);

	logger().debug("Running \"exec\" command: " + String.join(" ", command));
	final ExecCreateCmdResponse execCreateCmdResponse = dockerClient.execCreateCmd(this.containerId).withAttachStdout(true).withAttachStderr(true)
			.withUser("root")
			// .withPrivileged(true)
			.withCmd(command).exec();

	final ToStringConsumer stdoutConsumer = new ToStringConsumer();
	final ToStringConsumer stderrConsumer = new ToStringConsumer();

	FrameConsumerResultCallback callback = new FrameConsumerResultCallback();
	callback.addConsumer(OutputFrame.OutputType.STDOUT, stdoutConsumer);
	callback.addConsumer(OutputFrame.OutputType.STDERR, stderrConsumer);

	dockerClient.execStartCmd(execCreateCmdResponse.getId()).exec(callback).awaitCompletion();

	final ExecResult result = new ExecResult(stdoutConsumer.toString(outputCharset), stderrConsumer.toString(outputCharset));

	logger().trace("stdout: " + result.getStdout());
	logger().trace("stderr: " + result.getStderr());
	return result;
}
 
开发者ID:gentics,项目名称:mesh,代码行数:36,代码来源:MeshDockerServer.java


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