• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java ExecStartResultCallback类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: runCommand

import com.github.dockerjava.core.command.ExecStartResultCallback; //导入依赖的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: checkDiskSpace

import com.github.dockerjava.core.command.ExecStartResultCallback; //导入依赖的package包/类
private void checkDiskSpace(DockerClient dockerClient, String id) {
    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();

    try {
        dockerClient
                .execStartCmd(dockerClient.execCreateCmd(id).withAttachStdout(true).withCmd("df", "-P").exec().getId())
                .exec(new ExecStartResultCallback(outputStream, null))
                .awaitCompletion();
    } catch (Exception e) {
        log.debug("Can't exec disk checking command", e);
    }

    DiskSpaceUsage df = parseAvailableDiskSpace(outputStream.toString());

    VisibleAssertions.assertTrue(
            "Docker environment should have more than 2GB free disk space",
            df.availableMB.map(it -> it >= 2048).orElse(true)
    );
}
 
开发者ID:testcontainers,项目名称:testcontainers-java,代码行数:20,代码来源:DockerClientFactory.java


示例3: execCommand

import com.github.dockerjava.core.command.ExecStartResultCallback; //导入依赖的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


示例4: call

import com.github.dockerjava.core.command.ExecStartResultCallback; //导入依赖的package包/类
public Void call() throws Exception {
    final ConsoleLogger console = new ConsoleLogger(listener);
    DockerClient client = DockerCommand.getClient(descriptor, cfgData.dockerUrlRes, cfgData.dockerVersionRes, cfgData.dockerCertPathRes, null);

    ExecStartResultCallback callback = new ExecStartResultCallback() {
        @Override
        public void onNext(Frame item) {
            console.logInfo(item.toString());
            super.onNext(item);
        }

        @Override
        public void onError(Throwable throwable) {
            console.logError("Failed to exec start:" + throwable.getMessage());
            super.onError(throwable);
        }
    };
    try {
        client.execStartCmd(cmdId).exec(callback).awaitCompletion();
    } catch (InterruptedException e) {
        console.logError("Failed to exec start:" + e.getMessage());
    }
    
    return null;
}
 
开发者ID:jenkinsci,项目名称:docker-build-step-plugin,代码行数:26,代码来源:ExecStartRemoteCallable.java


示例5: execStartAttached

import com.github.dockerjava.core.command.ExecStartResultCallback; //导入依赖的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


示例6: execStartWithNonExistentUser

import com.github.dockerjava.core.command.ExecStartResultCallback; //导入依赖的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


示例7: container_should_have_static_ip_for_app_net_network

import com.github.dockerjava.core.command.ExecStartResultCallback; //导入依赖的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


示例8: containerCommand

import com.github.dockerjava.core.command.ExecStartResultCallback; //导入依赖的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


示例9: killRetzServerProcess

import com.github.dockerjava.core.command.ExecStartResultCallback; //导入依赖的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


示例10: system

import com.github.dockerjava.core.command.ExecStartResultCallback; //导入依赖的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


示例11: createHolderTask

import com.github.dockerjava.core.command.ExecStartResultCallback; //导入依赖的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


示例12: cmd

import com.github.dockerjava.core.command.ExecStartResultCallback; //导入依赖的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


示例13: testExecuteCompletes

import com.github.dockerjava.core.command.ExecStartResultCallback; //导入依赖的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.core.command.ExecStartResultCallback; //导入依赖的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: execScript

import com.github.dockerjava.core.command.ExecStartResultCallback; //导入依赖的package包/类
/**
 * @param id The container id, will be used only the first one
 * @param serviceName Service name in running environment. Can be null.
 * @param script Script to execute
 */
@Override
public void execScript(List<String> id, String serviceName, String script) {
    log.info(String.format("Executing script: %s, in container: %s", script, id));

    String[] commands = null;
    try {
        /**
         * Due to permissions problems with mounted volume script is moved to some local directory in container
         *
         * 1. create new directory in container
         * 2. move there script
         * 3. chmod script
         * 4. execute script
         */
        commands = new String[] {
            "bash", "-c",
            scriptExecCommand(script)
        };

        ExecCreateCmdResponse exec = dockerClient.execCreateCmd(id.get(0))
                .withCmd(commands)
                .withAttachStdout(true)
                .withAttachStderr(true)
                .exec();

        dockerClient.execStartCmd(exec.getId())
                .exec(new ExecStartResultCallback(System.out, System.err))
                .awaitCompletion();
    } catch (DockerException | InterruptedException ex) {
        log.severe(String.format("Could not execute command: %s", Arrays.toString(commands)));
        throw new EnvironmentException("Could not execute command " + Arrays.toString(commands), ex);
    }
}
 
开发者ID:hawkular,项目名称:hawkular-apm,代码行数:39,代码来源:DockerImageExecutor.java


示例16: execStart

import com.github.dockerjava.core.command.ExecStartResultCallback; //导入依赖的package包/类
@Test
public void execStart() throws Exception {
    assumeNotSwarm("no network in swarm", dockerRule);

    String containerName = "generated_" + new SecureRandom().nextInt();

    CreateContainerResponse container = dockerRule.getClient().createContainerCmd("busybox").withCmd("top")
            .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("root")
            .exec();
    dockerRule.getClient().execStartCmd(execCreateCmdResponse.getId())
            .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,代码行数:32,代码来源:ExecStartCmdIT.java


示例17: execStartDetached

import com.github.dockerjava.core.command.ExecStartResultCallback; //导入依赖的package包/类
public void execStartDetached(String containerId, String... commands) {
    this.readWriteLock.readLock().lock();
    try {
        String id = execCreate(containerId, commands);
        this.dockerClient.execStartCmd(id).withDetach(true).exec(new ExecStartResultCallback());
    } finally {
        this.readWriteLock.readLock().unlock();
    }
}
 
开发者ID:arquillian,项目名称:arquillian-cube,代码行数:10,代码来源:DockerClientExecutor.java


示例18: execStartOutput

import com.github.dockerjava.core.command.ExecStartResultCallback; //导入依赖的package包/类
private CubeOutput execStartOutput(String id) {
    OutputStream outputStream = new ByteArrayOutputStream();
    OutputStream errorStream = new ByteArrayOutputStream();
    try {
        dockerClient.execStartCmd(id).withDetach(false)
            .exec(new ExecStartResultCallback(outputStream, errorStream)).awaitCompletion();
    } catch (InterruptedException e) {
        return new CubeOutput("", "");
    }

    return new CubeOutput(outputStream.toString(), errorStream.toString());
}
 
开发者ID:arquillian,项目名称:arquillian-cube,代码行数:13,代码来源:DockerClientExecutor.java


示例19: network_should_reach_pingpong_by_alias_ping

import com.github.dockerjava.core.command.ExecStartResultCallback; //导入依赖的package包/类
@Test
public void network_should_reach_pingpong_by_alias_ping() throws UnsupportedEncodingException, InterruptedException {
    ExecCreateCmdResponse exec = dockerClient.execCreateCmd("pingpong2").withCmd("curl", "http://ping:8080/").withAttachStdout(true).exec();
    ByteArrayOutputStream stdOut = new ByteArrayOutputStream();
    dockerClient.execStartCmd(exec.getId()).exec(new ExecStartResultCallback(stdOut, null)).awaitCompletion(2, TimeUnit.SECONDS);
    assertThat(stdOut.toString("UTF-8")).isEqualToIgnoringWhitespace(EXPECTED_RESPONSE);
}
 
开发者ID:arquillian,项目名称:arquillian-cube,代码行数:8,代码来源:PingPongIT.java


示例20: network_should_reach_pingpong2_by_alias_pong

import com.github.dockerjava.core.command.ExecStartResultCallback; //导入依赖的package包/类
@Test
public void network_should_reach_pingpong2_by_alias_pong() throws UnsupportedEncodingException, InterruptedException {
    ExecCreateCmdResponse exec = dockerClient.execCreateCmd("pingpong").withCmd("curl", "http://pong:8080/").withAttachStdout(true).exec();
    ByteArrayOutputStream stdOut = new ByteArrayOutputStream();
    dockerClient.execStartCmd(exec.getId()).exec(new ExecStartResultCallback(stdOut, null)).awaitCompletion(2, TimeUnit.SECONDS);
    assertThat(stdOut.toString("UTF-8")).isEqualToIgnoringWhitespace(EXPECTED_RESPONSE);
}
 
开发者ID:arquillian,项目名称:arquillian-cube,代码行数:8,代码来源:PingPongIT.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java Token类代码示例发布时间:2022-05-22
下一篇:
Java SimpleSVD类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap