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.experiment.PropertyDefinition;
24 import jgroup.experiment.Runnable;
25 import jgroup.experiment.ShellCommand;
26 import jgroup.relacs.config.ExperimentConfig;
27 import jgroup.relacs.config.Host;
28 import jgroup.relacs.config.HostSet;
29
30
31
32
33 public class SynchronizeCodebase
34 implements Runnable
35 {
36
37
38
39
40
41
42
43
44 public void run(ExperimentConfig ec)
45 {
46
47 HostSet hosts = (HostSet) ec.getServerConfig().getAllHosts().clone();
48
49 HostSet clients = ec.getClientConfig().getAllHosts();
50 hosts.addHosts(clients);
51
52 StringBuilder buf = new StringBuilder("rsync ");
53 buf.append(ec.getProperty(this, "rsync.options", "-aL --delete "));
54 String includes = ec.getProperty(this, "rsync.includes", "");
55 String[] tokens = includes.split(",");
56 for (int i = 0; i < tokens.length; i++) {
57 buf.append(" --include=");
58 buf.append(tokens[i]);
59 }
60 String excludes = ec.getProperty(this, "rsync.excludes", "");
61 tokens = excludes.split(",");
62 for (int i = 0; i < tokens.length; i++) {
63 buf.append(" --exclude=");
64 buf.append(tokens[i]);
65 }
66 buf.append(" -e ssh ");
67 String localDir = ec.getProperty(this, "local.code.dir");
68 String remoteDir = ec.getProperty(this, "remote.code.dir");
69 buf.append(localDir);
70 buf.append(" ");
71 buf.append(ec.getProperty("user.name"));
72 buf.append("@");
73
74 ThreadGroup threadGroup = new ThreadGroup("SynchronizeCodebase");
75 for (Iterator iter = hosts.iterator(); iter.hasNext();) {
76 StringBuilder rsyncCmd = new StringBuilder(buf.toString());
77 Host host = (Host) iter.next();
78 if (host.isLocal())
79 continue;
80 String hostName = host.getCanonicalHostName();
81 rsyncCmd.append(hostName);
82 rsyncCmd.append(":");
83 rsyncCmd.append(remoteDir);
84 try {
85 ShellCommand.exec(rsyncCmd.toString(), threadGroup);
86 } catch (Exception e) {
87 e.printStackTrace();
88 System.out.println("Could not synchronize codebase to " + hostName);
89 }
90 }
91 if (ec.getProperty("bootstrap.host", "localhost").equals("localhost")) {
92 StringBuilder rsyncCmd = new StringBuilder(buf.toString());
93 rsyncCmd.append("localhost:");
94 rsyncCmd.append(remoteDir);
95 try {
96 ShellCommand.exec(rsyncCmd.toString(), threadGroup);
97 } catch (Exception e) {
98 e.printStackTrace();
99 System.out.println("Could not synchronize codebase to localhost");
100 }
101 }
102 ShellCommand.waitFor(threadGroup);
103 }
104
105
106
107
108
109 public PropertyDefinition[] getProperties() {
110 return null;
111 }
112
113 }