2 # NEPI, a framework to manage network experiments
3 # Copyright (C) 2013 INRIA
5 # This program is free software: you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation, either version 3 of the License, or
8 # (at your option) any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program. If not, see <http://www.gnu.org/licenses/>.
18 # Author: Alina Quereilhac <alina.quereilhac@inria.fr>
20 from nepi.execution.attribute import Attribute, Flags, Types
21 from nepi.execution.trace import Trace, TraceAttr
22 from nepi.execution.resource import ResourceManager, clsinit, ResourceState, \
24 from nepi.util.sshfuncs import ProcStatus
30 class Collector(ResourceManager):
31 """ The collector is reponsible of collecting traces
32 of a same type associated to RMs into a local directory.
34 .. class:: Class Args :
36 :param ec: The Experiment controller
37 :type ec: ExperimentController
38 :param guid: guid of the RM
40 :param creds: Credentials to communicate with the rm (XmppClient)
47 def _register_attributes(cls):
48 trace_name = Attribute("traceName", "Name of the trace to be collected",
49 flags = Flags.ExecReadOnly)
50 store_dir = Attribute("storeDir", "Path to local directory to store trace results",
51 default = tempfile.gettempdir(),
52 flags = Flags.ExecReadOnly)
53 sub_dir = Attribute("subDir", "Sub directory to collect traces into",
54 flags = Flags.ExecReadOnly)
56 cls._register_attribute(trace_name)
57 cls._register_attribute(store_dir)
58 cls._register_attribute(sub_dir)
60 def __init__(self, ec, guid):
61 super(Collector, self).__init__(ec, guid)
62 self._store_path = None
66 return self._store_path
69 trace_name = self.get("traceName")
73 msg = "No traceName was specified"
75 raise RuntimeError, msg
77 store_dir = self.get("storeDir")
78 self._store_path = os.path.join(store_dir, self.ec.exp_id, self.ec.run_id)
80 subdir = self.get("subDir")
82 self._store_path = os.path.join(self._store_path, subdir)
84 msg = "Creating local directory at %s to store %s traces " % (
85 store_dir, trace_name)
89 os.makedirs(self.store_path)
93 super(Collector, self).provision()
103 super(Collector, self).deploy()
106 trace_name = self.get("traceName")
108 msg = "Collecting '%s' traces to local directory %s" % (
109 trace_name, self.store_path)
112 rms = self.get_connected()
114 result = self.ec.trace(rm.guid, trace_name)
115 fpath = os.path.join(self.store_path, "%d.%s" % (rm.guid,
121 super(Collector, self).release()
123 def valid_connection(self, guid):