private static boolean execContainerPing(DockerClientExecutor dockerClientExecutor, String containerId, String command) { final String[] commands = {"sh", "-c", command}; CubeOutput result = dockerClientExecutor.execStart(containerId, commands); if (result.getStandard() == null) { throw new IllegalArgumentException( String.format("Command %s in container %s has returned no value.", Arrays.toString(commands), containerId)); } if (result.getStandard().contains(COMMAND_NOT_FOUND) || result.getError().contains(COMMAND_NOT_FOUND)) { throw new UnsupportedOperationException( String.format("Command %s is not available in container %s.", Arrays.toString(commands), containerId)); } try { int numberOfListenConnectons = Integer.parseInt(result.getStandard().trim()); //This number is based in that a port will be opened only as tcp or as udp. //We will need another issue to modify cube internals to save if port is udp or tcp. return numberOfListenConnectons > 0; } catch (NumberFormatException e) { return false; } }
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()); }
@Test public void should_execute_uname() { assertThat(redis.exec("sh", "-c", "uname").getStandard()) .isNotBlank() .isEqualToIgnoringWhitespace("Linux"); } // tag::docs[]
@Test public void should_execute_uname() { assertThat(redis.exec("sh", "-c", "uname").getStandard()) .isNotBlank() .isEqualToIgnoringWhitespace("Linux"); }
private static boolean execContainerPing(DockerClientExecutor dockerClientExecutor, String containerId, String command) { final String[] commands = {"sh", "-c", command}; CubeOutput result = dockerClientExecutor.execStart(containerId, commands); if (result.getStandard() == null) { throw new IllegalArgumentException( String.format("Command %s in container %s has returned no value.", Arrays.toString(commands), containerId)); } if (result.getStandard().contains(COMMAND_NOT_FOUND) || result.getError().contains(COMMAND_NOT_FOUND)) { throw new UnsupportedOperationException( String.format("Command %s is not available in container %s.", Arrays.toString(commands), containerId)); } try { int numberOfListenConnectons = Integer.parseInt(result.getStandard().trim()); //This number is based in that a port will be opened only as tcp or as udp. //We will need another issue to modify cube internals to save if port is udp or tcp. return numberOfListenConnectons > 0; } catch (NumberFormatException e) { return false; } }
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()); }
private boolean executeWaitForIt(String containerIp, int port) { // We copy our wait-for-it-sh.sh file form classpath // Our wait-for-it-sh.sh script also works with busybox/alpine which is not true with the official one. try { if (!alreadyCopiedWaitForIt) { final Path waitForItLocation = copyWaitForItScriptToTempDir(); // Then copy this into the container dockerClientExecutor.copyStreamToContainer(cube.getId(), waitForItLocation.toFile(), new File(CONTAINER_DIRECTORY)); alreadyCopiedWaitForIt = true; } String command = resolveWaitForItCommand(containerIp, port); final String[] commands = {"sh", "-c", command}; CubeOutput result = dockerClientExecutor.execStart(cube.getId(), commands); if (result.getError() != null && result.getError().contains("can't execute")) { throw new UnsupportedOperationException(result.getError()); } return result.getStandard() != null && result.getStandard().trim().contains(MESSAGE); } catch (IOException e) { throw new IllegalArgumentException(e); } }
private boolean executeWaitForIt(String containerIp, int port) { // We copy our wait-for-it-sh.sh file form classpath // Our wait-for-it-sh.sh script also works with busybox/alpine which is not true with the official one. try { if (!alreadyCopiedWaitForIt) { final Path waitForItLocation = copyWaitForItScriptToTempDir(); // Then copy this into the container dockerClientExecutor.copyStreamToContainer(cube.getId(), waitForItLocation.toFile(), new File(CONTAINER_DIRECTORY)); alreadyCopiedWaitForIt = true; } String command = resolveWaitForItCommand(containerIp, port); final String[] commands = {"sh", "-c", command}; CubeOutput result = dockerClientExecutor.execStart(cube.getId(), commands); if (result.getError() != null && result.getError().contains("can't execute")) { throw new UnsupportedOperationException(result.getError()); } return result.getStandard() != null && result.getStandard().trim().contains(MESSAGE); } catch (IOException e) { throw new IllegalArgumentException(e); } }