def execute()

in test-support/src/main/scala/com/datastax/spark/connector/ccm/CcmBridge.scala [98:141]


  def execute(cli: CommandLine): Seq[String] = {
    logger.info("Executing: " + cli)

    val watchDog: ExecuteWatchdog = new ExecuteWatchdog(TimeUnit.MINUTES.toMillis(10))

    val outStream = new LogOutputStream() {
      val lines: mutable.Buffer[String] = mutable.Buffer[String]()
      override def processLine(line: String, logLevel: Int): Unit = {
        lines += line
        logger.debug("ccmout> {}", line)
      }
    }
    val errStream = new LogOutputStream() {
      override def processLine(line: String, logLevel: Int): Unit = logger.error("ccmerr> {}", line)
    }

    try {
      val executor = new DefaultExecutor()
      val streamHandler = new PumpStreamHandler(outStream, errStream)
      executor.setStreamHandler(streamHandler)
      executor.setWatchdog(watchDog)
      val env =
        if (sys.env.contains("CCM_JAVA_HOME")) {
          sys.env + ("JAVA_HOME" -> sys.env("CCM_JAVA_HOME"))
        } else {
          sys.env
        }

      val retValue = executor.execute(cli, env.asJava)
      if (retValue != 0) {
        logger.error(
          "Non-zero exit code ({}) returned from executing ccm command: {}", retValue, cli)
      }
      outStream.lines.toSeq
    } catch {
      case _: IOException if watchDog.killedProcess() =>
        throw new RuntimeException(s"The command $cli was killed after 10 minutes")
      case ex: IOException =>
        throw new RuntimeException(s"The command $cli failed to execute", ex)
    } finally {
      Try(outStream.close())
      Try(errStream.close())
    }
  }