1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package jgroup.experiment.runnables;
20
21 import java.util.Iterator;
22
23 import jgroup.core.ConfigurationException;
24 import jgroup.experiment.PropertyDefinition;
25 import jgroup.experiment.Runnable;
26 import jgroup.experiment.ShellCommand;
27 import jgroup.relacs.config.ExperimentConfig;
28 import jgroup.relacs.config.Host;
29 import jgroup.relacs.config.HostSet;
30
31
32
33
34 public class CheckSshAccess
35 implements Runnable
36 {
37
38
39
40
41 public void run(ExperimentConfig ec) throws ConfigurationException
42 {
43
44 HostSet hosts = (HostSet) ec.getServerConfig().getAllHosts().clone();
45
46 HostSet clients = ec.getClientConfig().getAllHosts();
47 hosts.addHosts(clients);
48 String userName = ec.getProperty("user.name");
49
50 ThreadGroup threadGroup = new ThreadGroup("CheckSshAccess");
51 boolean toExit = false;
52 for (Iterator iter = hosts.iterator(); iter.hasNext();) {
53 Host host = (Host) iter.next();
54 String hostName = host.getCanonicalHostName();
55 StringBuilder b = new StringBuilder(ec.ssh(hostName));
56 b.append("echo ");
57 b.append(userName);
58 ShellCommand sc = new ShellCommand(b.toString(), threadGroup);
59 if (sc.waitForProcess() && sc.stderrModified()) {
60
61
62
63
64
65 toExit = true;
66 System.out.println("Failed to connect to " + hostName);
67 }
68 }
69 ShellCommand.waitFor(threadGroup);
70 if (toExit)
71 System.exit(1);
72 }
73
74
75
76
77 public PropertyDefinition[] getProperties()
78 {
79 return null;
80 }
81
82 }