本文整理汇总了Java中com.github.dockerjava.core.command.ExecStartResultCallback类的典型用法代码示例。如果您正苦于以下问题:Java ExecStartResultCallback类的具体用法?Java ExecStartResultCallback怎么用?Java ExecStartResultCallback使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ExecStartResultCallback类属于com.github.dockerjava.core.command包,在下文中一共展示了ExecStartResultCallback类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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;
}
示例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)
);
}
示例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;
}
示例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;
}
示例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);
}
示例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();
}
示例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");
}
}
示例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;
}
示例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");
}
示例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));
}
示例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);
}
};
}
示例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));
}
示例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));
}
示例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();
}
示例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);
}
}