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 import java.util.Timer;
23 import java.util.TimerTask;
24
25 import jgroup.core.ConfigurationException;
26 import jgroup.experiment.PropertyDefinition;
27 import jgroup.experiment.Runnable;
28 import jgroup.experiment.ShellCommand;
29 import jgroup.relacs.config.ExperimentConfig;
30 import jgroup.relacs.config.Host;
31 import jgroup.relacs.config.HostSet;
32
33 import org.apache.log4j.Logger;
34
35
36
37
38
39 public class DeployExecDaemons
40 implements Runnable
41 {
42
43
44
45
46
47
48 public static final Logger log = Logger.getLogger(DeployExecDaemons.class);
49
50
51
52
53
54
55
56 private static final int WAIT_TIME_PER_HOST = 3000;
57
58
59
60
61
62
63
64 private volatile boolean timeout;
65
66
67
68
69
70
71
72
73
74 public void run(ExperimentConfig ec)
75 throws ConfigurationException
76 {
77 HostSet hosts = (HostSet) ec.getServerConfig().getAllHosts().clone();
78 boolean useWindows = ec.getBooleanProperty(this, "use.separate.windows");
79 int maxWait = hosts.size()*WAIT_TIME_PER_HOST;
80 maxWait = ec.getIntProperty(this, "max.waiting.time", maxWait);
81
82 ThreadGroup threadGroup = new ThreadGroup("DeployExecDaemons");
83 for (Iterator iter = hosts.iterator(); iter.hasNext(); ) {
84 Host host = (Host) iter.next();
85 String hostName = host.getCanonicalHostName();
86 StringBuilder sshCmd = new StringBuilder(50);
87 if (useWindows) {
88 sshCmd.append(ec.getProperty(this, "terminal.cmd", "xterm"));
89 sshCmd.append(" -e ");
90 }
91 sshCmd.append(ec.ssh(hostName));
92 sshCmd.append(ec.ant("execdaemon"));
93 try {
94 ShellCommand.exec(sshCmd.toString(), threadGroup);
95 } catch (Exception e) {
96 e.printStackTrace();
97 System.out.println("Could not start ExecDaemon at " + hostName);
98 }
99 }
100 timeout = false;
101 TimerTask awaitHosts = new TimerTask() {
102 public void run() {
103 log.error("Some hosts seems to be unavailable (check log file)");
104 timeout = true;
105 }
106 };
107 Timer timer = new Timer("AwaitExecDaemons", true);
108 timer.schedule(awaitHosts, maxWait);
109 log.info("Waiting for execdaemons to start: " + hosts.size());
110 while (hosts.size() > 0 && !timeout) {
111 log.debug("Unavailable hosts remaining: " + hosts.size());
112 try {
113 Thread.sleep(2000);
114 } catch (InterruptedException e) {
115 for (Iterator iter = hosts.iterator(); iter.hasNext();) {
116 Host host = (Host) iter.next();
117 log.debug("Checking: " + host.getHostName());
118 if (host.ping()) {
119 log.debug(host.getHostName() + " is available");
120 iter.remove();
121 } else {
122 log.debug(host.getHostName() + " is not available");
123 }
124 }
125 }
126 log.info("Exiting DeplyExecDaemons");
127 timer.cancel();
128 if (!hosts.isEmpty()) {
129 for (Iterator iter = hosts.iterator(); iter.hasNext();) {
130 log.debug("Remaining host: " + iter.next());
131 }
132 }
133 }
134
135
136
137
138 public PropertyDefinition[] getProperties()
139 {
140 return null;
141 }
142
143 }