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.io.File;
22 import java.io.IOException;
23 import java.util.Iterator;
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
34
35
36
37 public class SaveLogs
38 implements Runnable
39 {
40
41
42
43
44 private static final PropertyDefinition[] properties = {
45 new PropertyDefinition("remote.dir", PropertyDefinition.STRING_TYPE),
46 new PropertyDefinition("save.dir", PropertyDefinition.STRING_TYPE),
47 new PropertyDefinition("variables", PropertyDefinition.STRING_TYPE)
48 };
49
50
51
52
53
54
55
56
57
58 public void run(ExperimentConfig ec)
59 throws ConfigurationException
60 {
61
62 String remoteDir = ec.getProperty(this, "remote.dir");
63
64 StringBuilder buf = new StringBuilder(30);
65 buf.append(ec.getProperty(this, "save.dir"));
66 buf.append(File.separator);
67 buf.append(ec.getExperimentName());
68 buf.append(File.separator);
69 buf.append(ec.getProperty(this, "variables"));
70 String repeat = ec.getProperty("repeat", "1");
71 if (repeat != null && repeat.length() > 0) {
72 buf.append(File.separator);
73 buf.append(repeat);
74 }
75 String logStorage = buf.toString();
76
77 File resultsDir = new File(logStorage);
78
79 if (!resultsDir.exists()) {
80 if (!resultsDir.mkdirs()) {
81 throw new ConfigurationException("Could not create results directory: " + resultsDir);
82 }
83 }
84
85
86 HostSet hosts = (HostSet) ec.getServerConfig().getAllHosts().clone();
87
88 HostSet clients = ec.getClientConfig().getAllHosts();
89 hosts.addHosts(clients);
90
91 ThreadGroup threadGroup = new ThreadGroup("SaveLogs");
92 for (Iterator iter = hosts.iterator(); iter.hasNext();) {
93 Host host = (Host) iter.next();
94 String hostName = host.getCanonicalHostName();
95 try {
96 ShellCommand.exec(ec.scp(hostName, remoteDir, logStorage), threadGroup);
97 } catch (IOException e) {
98 e.printStackTrace();
99 System.out.println("Could not save logs from " + hostName);
100 }
101 }
102 ShellCommand.waitFor(threadGroup);
103 }
104
105
106
107
108 public PropertyDefinition[] getProperties() {
109 return properties;
110 }
111
112 }