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?

1

There are 1 answers

1
udinnet On BEST ANSWER

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.