// Collect all the stdout, and parse the output.
// If the third whitespace-delimited token is the sqooptest user,
// the the first token is the nzsession id. We should kill that id.
public void clearNzSessions() throws IOException, InterruptedException {
    String pathToNzSession = System.getProperty(
        NZ_SESSION_PATH_KEY, DEFAULT_NZ_SESSION_PATH);
    // Run nzsession and capture a list of open transactions.
    ArrayList<String> args = new ArrayList<String>();
    args.add(pathToNzSession);
    args.add("-host");
    args.add(NETEZZA_HOST);
    args.add("-u");
    args.add(ADMIN_USER);
    args.add("-pw");
    args.add(ADMIN_PASS);
    Process p = Runtime.getRuntime().exec(args.toArray(new String[0]));
    InputStream is = p.getInputStream();
    LineBufferingAsyncSink sink = new LineBufferingAsyncSink();
    sink.processStream(is);
    // Wait for the process to end.
    int result = p.waitFor();
    if (0 != result) {
      throw new IOException("Session list command terminated with " + result);
    }
    // Collect all the stdout, and parse the output.
    // If the third whitespace-delimited token is the sqooptest user,
    // the the first token is the nzsession id. We should kill that id.
    sink.join();
    List<String> processList = sink.getLines();
    for (String processLine : processList) {
      if (null == processLine || processLine.length() == 0) {
        continue; // Ignore empty lines.
      }
      String [] tokens = processLine.split(" +");
      if (tokens.length < 3) {
        continue; // Not enough tokens on this line.
      }
      if (tokens[2].equalsIgnoreCase(NETEZZA_USER)) {
        // Found a match.
        killSession(tokens[0]);
      }
    }
  }
throw new IOException("Session list command terminated with " + result);
}
// Collect all the stdout, and parse the output.
// If the third whitespace-delimited token is the sqooptest user,
// the the first token is the nzsession id. We should kill that id.
sink.join();
List<String> processList = sink.getLines();
args.add(ADMIN_PASS);
Process p = Runtime.getRuntime().exec(args.toArray(new String[0]));
InputStream is = p.getInputStream();
LineBufferingAsyncSink sink = new LineBufferingAsyncSink();
sink.processStream(is);
// Wait for the process to end.
int result = p.waitFor();
if (0 != result) {
throw new IOException("Session list command terminated with " + result);
}
// Collect all the stdout, and parse the output.
// If the third whitespace-delimited token is the sqooptest user,
// the the first token is the nzsession id. We should kill that id.
sink.join();
List<String> processList = sink.getLines();
for (String processLine : processList) {
if (null == processLine || processLine.length() == 0) {
continue; // Ignore empty lines.
}
String [] tokens = processLine.split(" +");
if (tokens.length < 3) {
continue; // Not enough tokens on this line.
}
String pathToNzSession = System.getProperty(
NZ_SESSION_PATH_KEY, DEFAULT_NZ_SESSION_PATH);
// Run nzsession and capture a list of open transactions.
ArrayList<String> args = new ArrayList<String>();
args.add(pathToNzSession);
args.add("-host");
args.add(NETEZZA_HOST);
args.add("-u");
args.add(ADMIN_USER);
args.add("-pw");
args.add(ADMIN_PASS);
Process p = Runtime.getRuntime().exec(args.toArray(new String[0]));
InputStream is = p.getInputStream();
LineBufferingAsyncSink sink = new LineBufferingAsyncSink();
sink.processStream(is);
// Wait for the process to end.
int result = p.waitFor();
if (0 != result) {
throw new IOException("Session list command terminated with " + result);
}
// Collect all the stdout, and parse the output.
// If the third whitespace-delimited token is the sqooptest user,
// the the first token is the nzsession id. We should kill that id.
sink.join();
List<String> processList = sink.getLines();
for (String processLine : processList) {
if (null == processLine || processLine.length() == 0) {
continue; // Ignore empty lines.
}
String [] tokens = processLine.split(" +");
if (tokens.length < 3) {
continue; // Not enough tokens on this line.
}
if (tokens[2].equalsIgnoreCase(NETEZZA_USER)) {
// Found a match.
killSession(tokens[0]);
}
}
}