new-integration-tests/src/test/java/oracle/weblogic/kubernetes/actions/impl/primitive/Kubernetes.java
public static ExecResult exec(V1Pod pod, String containerName, boolean redirectToStdout,
                                String... command)
          throws IOException, ApiException, InterruptedException {

    // Execute command using Kubernetes API
    KubernetesExec kubernetesExec = createKubernetesExec(pod, containerName);
    final Process proc = kubernetesExec.exec(command);

    // If redirect enabled, copy stdout and stderr to corresponding Outputstream
    final CopyingOutputStream copyOut =
            redirectToStdout ? new CopyingOutputStream(System.out) : new CopyingOutputStream(null);
    final CopyingOutputStream copyErr =
            redirectToStdout ? new CopyingOutputStream(System.err) : new CopyingOutputStream(null);

    // Start a thread to begin reading the output stream of the command
    try {
      Thread out = createStreamReader(proc.getInputStream(), copyOut,
              "Exception reading from stdout input stream.");
      out.start();

      // Start a thread to begin reading the error stream of the command
      Thread err = createStreamReader(proc.getErrorStream(), copyErr,
              "Exception reading from stderr input stream.");
      err.start();

      // wait for the process, which represents the executing command, to terminate
      proc.waitFor();

      // wait for stdout reading thread to finish any remaining output
      out.join();

      // wait for stderr reading thread to finish any remaining output
      err.join();

      // Read data from process's stdout
      String stdout = readExecCmdData(copyOut.getInputStream());

      // Read from process's stderr, if data available
      String stderr = readExecCmdData(copyErr.getInputStream());;

      ExecResult result = new ExecResult(proc.exitValue(), stdout, stderr);
      getLogger().fine("result from exec command: " + result);

      if (result.exitValue() != 0) {
        getLogger().info("result.exitValue={0}", result.exitValue());
        getLogger().info("result.stdout={0}", result.stdout());
        getLogger().info("result.stderr={0}", result.stderr());
      }

      return result;
    } finally {
      if (proc != null) {
        proc.destroy();
      }
    }
  }
/**
   * Execute a command in a container.
   *
   * @param pod The pod where the command is to be run
   * @param containerName The container in the Pod where the command is to be run. If no
   *     container name is provided than the first container in the Pod is used.
   * @param redirectToStdout copy process output to stdout
   * @param command The command to run
   * @return result of command execution
   * @throws IOException if an I/O error occurs.
   * @throws ApiException if Kubernetes client API call fails
   * @throws InterruptedException if any thread has interrupted the current thread
   */
Execute a command in a container.
@param pod The pod where the command is to be run
@param containerName The container in the Pod where the command is to be run. If no
container name is provided than the first container in the Pod is used.
@param redirectToStdout copy process output to stdout
@param command The command to run
@return result of command execution
@throws IOException if an I/O error occurs.
@throws ApiException if Kubernetes client API call fails
@throws InterruptedException if any thread has interrupted the current thread
Execute a command in a container . @param pod The pod where the command is to be run @param containerName The container in the Pod where the command is to be run . If no container name is provided than the first container in the Pod is used . @param redirectToStdout copy process output to stdout @param command The command to run @return result of command execution @throws IOException if an I / O error occurs . @throws ApiException if Kubernetes client API call fails @throws InterruptedException if any thread has interrupted the current thread
public static ExecResult exec(V1Pod pod, String containerName, boolean redirectToStdout,
                                String... command)
          throws IOException, ApiException, InterruptedException {
    KubernetesExec kubernetesExec = createKubernetesExec(pod, containerName);
    final Process proc = kubernetesExec.exec(command);
    final CopyingOutputStream copyOut =
            redirectToStdout ? new CopyingOutputStream(System.out) : new CopyingOutputStream(null);
    final CopyingOutputStream copyErr =
            redirectToStdout ? new CopyingOutputStream(System.err) : new CopyingOutputStream(null);
    try {
      Thread out = createStreamReader(proc.getInputStream(), copyOut,
              "Exception reading from stdout input stream.");
      out.start();
      Thread err = createStreamReader(proc.getErrorStream(), copyErr,
              "Exception reading from stderr input stream.");
      err.start();
      proc.waitFor();
      out.join();
      err.join();
      String stdout = readExecCmdData(copyOut.getInputStream());
      String stderr = readExecCmdData(copyErr.getInputStream());;
      ExecResult result = new ExecResult(proc.exitValue(), stdout, stderr);
      getLogger().fine("result from exec command: " + result);
      if (result.exitValue() != 0) {
        getLogger().info("result.exitValue={0}", result.exitValue());
        getLogger().info("result.stdout={0}", result.stdout());
        getLogger().info("result.stderr={0}", result.stderr());
      }
      return result;
    } finally {
      if (proc != null) {
        proc.destroy();
      }
    }
  }
public static ExecResult exec ( V1Pod pod , String containerName , boolean redirectToStdout , String ... command ) throws IOException , ApiException , InterruptedException { KubernetesExec kubernetesExec = createKubernetesExec ( pod , containerName ) ; final Process proc = kubernetesExec . exec ( command ) ; final CopyingOutputStream copyOut = redirectToStdout ? new CopyingOutputStream ( System . out ) : new CopyingOutputStream ( null ) ; final CopyingOutputStream copyErr = redirectToStdout ? new CopyingOutputStream ( System . err ) : new CopyingOutputStream ( null ) ; try { Thread out = createStreamReader ( proc . getInputStream ( ) , copyOut , "Exception reading from stdout input stream." ) ; out . start ( ) ; Thread err = createStreamReader ( proc . getErrorStream ( ) , copyErr , "Exception reading from stderr input stream." ) ; err . start ( ) ; proc . waitFor ( ) ; out . join ( ) ; err . join ( ) ; String stdout = readExecCmdData ( copyOut . getInputStream ( ) ) ; String stderr = readExecCmdData ( copyErr . getInputStream ( ) ) ; ; ExecResult result = new ExecResult ( proc . exitValue ( ) , stdout , stderr ) ; getLogger ( ) . fine ( "result from exec command: " + result ) ; if ( result . exitValue ( ) != 0 ) { getLogger ( ) . info ( "result.exitValue={0}" , result . exitValue ( ) ) ; getLogger ( ) . info ( "result.stdout={0}" , result . stdout ( ) ) ; getLogger ( ) . info ( "result.stderr={0}" , result . stderr ( ) ) ; } return result ; } finally { if ( proc != null ) { proc . destroy ( ) ; } } }
Execute a command in a container.
Execute a command in a container .
// Execute command using Kubernetes API // If redirect enabled, copy stdout and stderr to corresponding Outputstream // Start a thread to begin reading the output stream of the command // Start a thread to begin reading the error stream of the command // wait for the process, which represents the executing command, to terminate // wait for stdout reading thread to finish any remaining output // wait for stderr reading thread to finish any remaining output // Read data from process's stdout // Read from process's stderr, if data available