-1

So writing a test storm topology with minimal Java experience, so I'm figuring things out in a brute force way. My experience writing storm topologies is also minimal.

I have three supervisor nodes on my cluster and want each of them to run ls in the terminal, funnel the output to a file and then return it to the nimbus node.

Firstly, how would i code an individual computer to run ls in the terminal? Funneling the output to a file is simple enough for me to figure out. I just don't know how to write programs that execute terminal commands.

Secondly, how do i tell each of my supervisor nodes to run ls individually?

Matthias J. Sax
  • 59,682
  • 7
  • 117
  • 137
Max
  • 95
  • 11

1 Answers1

1

You can use below snippet to run a command in shell. So use this same method to invoke the specific ls command using ssh in all supervisor nodes (from external node like nimbus).

        public String executeCommand(String command) {
        StringBuffer output = new StringBuffer();
        Process p;
        try {
            p = Runtime.getRuntime().exec(command);
            p.waitFor();
            BufferedReader reader =
                    new BufferedReader(new InputStreamReader(p.getInputStream()));

            String line = "";
            while ((line = reader.readLine()) != null) {
                output.append(line + "\n");
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return output.toString();
    }

Hope this helped.

udinnet
  • 26
  • 4
  • Thanks @udinnet . So what I could do is SSH to each of the servers I want to run ls on and then call a function with the above command? How do I ssh to a server from a program? Further, is it really necessary to ssh when on the storm cluster? Does nimbus not already have access to the machines? – Max Jun 17 '15 at 16:24