View Javadoc

1   /*
2    * Copyright (c) 1998-2004 The Jgroup Team.
3    *
4    * This program is free software; you can redistribute it and/or modify
5    * it under the terms of the GNU Lesser General Public License version 2 as
6    * published by the Free Software Foundation.
7    *
8    * This program is distributed in the hope that it will be useful,
9    * but WITHOUT ANY WARRANTY; without even the implied warranty of
10   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11   * GNU Lesser General Public License for more details.
12   *
13   * You should have received a copy of the GNU Lesser General Public License
14   * along with this program; if not, write to the Free Software
15   * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
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   * @author Bjarte Svaeren
33   * @author Hein Meling
34   */
35  public class DeleteRemoteLogs
36   implements Runnable
37  {
38  
39    ////////////////////////////////////////////////////////////////////////////////////////////
40    // Methods from Runnable
41    ////////////////////////////////////////////////////////////////////////////////////////////
42  
43    /* (non-Javadoc)
44     * @see jgroup.experiment.Runnable#run()
45     */
46    public void run(ExperimentConfig ec)
47    {
48      // get the server hosts
49      HostSet hosts = (HostSet) ec.getServerConfig().getAllHosts().clone();
50      // get the client hosts
51      HostSet clients = ec.getClientConfig().getAllHosts();
52      hosts.addHosts(clients);
53  
54      /* Get the remote directory as a String */
55      String remoteDir = ec.getProperty(this, "exp.remote.dir");
56  
57      ThreadGroup threadGroup = new ThreadGroup("DeleteRemoteLogs");
58      for (Iterator iter = hosts.iterator(); iter.hasNext();) {
59        Host host = (Host) iter.next();
60        String hostName = host.getCanonicalHostName();
61        try {
62          ShellCommand.exec(ec.ssh(hostName) + " rm -rf " + remoteDir + "/*", threadGroup);
63        } catch (Exception e) {
64          e.printStackTrace();
65          System.out.println("Could not delete logs at " + hostName);
66        }
67      }
68      ShellCommand.waitFor(threadGroup);  
69    }
70  
71    /* (non-Javadoc)
72     * @see jgroup.experiment.Runnable#getProperties()
73     */
74    public PropertyDefinition[] getProperties() {
75      return null;
76    }
77  
78  } // END DeleteRemoteLogs