Skip to content
This repository has been archived by the owner on Jan 15, 2022. It is now read-only.

OverShell

chrislewis edited this page Sep 5, 2011 · 7 revisions

Parallel Command Execution

The main goal of rugu is to simplify automated administrative tasks over ssh through a script-like interface. It is a common scenario that some agent, human or otherwise, must manage various server clusters; often times these clusters are heterogeneous in part or whole. For such scenarios, rugu provides the OverShell. An OverShell provides the same script-like interface used for a single server, but instead parallelizes execution over an arbitrary number of servers.

val base = Template(Host("host0"), UsernameAndPassword("xx", "xx"), knownHosts)
val hosts = (1 to 10).map("host%s".format(_))
val overshell = OverShell.stageHosts(hosts)(base)

overshell is now an OverShell instance for administering 10 servers in parallel. To execute a command we can use the same DSL as if we were executing on a single host. Here's how we print the host names as reported by executing the hostname command on each server:

overshell("hostname" :| identity).foreach(f => println(f.get))
Right(host1)
Right(host2)
Right(host3)
Right(host4)
Right(host5)
Right(host6)
Right(host7)
Right(host8)
Right(host9)
Right(host10)

Instead of returning a single result, OverShell#apply returns a sequence of Futures when all remote commands terminate. Sticking with the same example:

val futures = overshell("hostname" :| identity)

The type of futures is Seq[java.util.concurrent.Future[Either[Throwable,String]]]. OverShell uses ExecutorService#invokeAll to parallelize command execution, which means OverShell#apply blocks the calling thread until all remote commands terminate.

Parallel Uploads

OverShell also supports file uploads in parallel:

overshell.upload("local-fat.jar", "uploaded-fat.jar")

As for command execution, upload blocks the calling thread until all uploads complete. Just like commands, the actual uploads occur in parallel and only block the caller until all are finished.

Clone this wiki locally