source: fedd/fedd/split.py @ ec4fb42

axis_examplecompt_changesinfo-opsversion-1.30version-2.00version-3.01version-3.02
Last change on this file since ec4fb42 was ec4fb42, checked in by Ted Faber <faber@…>, 15 years ago

Clean up some names that start with fedd_ that are ugly with the new package
structure. A couple other bugs cleaned up, too.

  • Property mode set to 100644
File size: 3.7 KB
Line 
1#!/usr/local/bin/python
2
3import os,sys
4import subprocess
5import tempfile
6import logging
7
8from fedd_services import *
9from fedd_internal_services import *
10from util import *
11from fedid import fedid
12from remote_service import xmlrpc_handler, soap_handler
13import parse_detail
14from service_error import *
15
16
17class nullHandler(logging.Handler):
18    def emit(self, record): pass
19
20fl = logging.getLogger("fedd.splitter")
21fl.addHandler(nullHandler())
22
23class split_local:
24    def __init__(self, config=None, auth=None):
25        """
26        Intialize the various attributes, most from the config object
27        """
28        if config.has_section("splitter"):
29            self.debug = config.getboolean("splitter", "debug")
30            self.muxmax = config.getint("splitter", "muxmax", 3)
31            self.tclsh = config.get("splitter", "tclsh", 
32                    "/usr/local/bin/otclsh")
33            self.tcl_splitter = config.get("splitter", "tcl_splitter",
34                    "/usr/testbed/lib/ns2ir/parse.tcl")
35        else:
36            self.debug = False
37            self.muxmax = 3
38            self.tclsh = "/usr/local/bin/otclsh"
39            self.tcl_splitter = "/usr/testbed/lib/ns2ir/parse.tcl"
40
41        self.log = logging.getLogger("fedd.splitter")
42        set_log_level(config, "splitter", self.log)
43        self.trace_file = sys.stderr
44
45        set_log_level(config, "splitter", self.log)
46        # Dispatch tables
47        self.soap_services = {\
48                'Ns2Split': soap_handler(\
49                        Ns2SplitRequestMessage.typecode,
50                        getattr(self, "run_splitter"), 
51                        Ns2SplitResponseMessage,
52                        "Ns2SplitResponseBody"),
53        }
54
55        self.xmlrpc_services = {\
56                'Ns2Split': xmlrpc_handler(\
57                        getattr(self, "run_splitter"), 
58                        "Ns2SplitResponseBody"),
59        }
60
61    def run_splitter(self, req, fid):
62        """
63        The external interface to experiment creation called from the
64        dispatcher.
65
66        Creates a working directory, splits the incoming description using the
67        splitter script and parses out the avrious subsections using the
68        lcasses above.  Once each sub-experiment is created, use pooled threads
69        to instantiate them and start it all up.
70        """
71        try:
72            tmpdir = tempfile.mkdtemp(prefix="split-")
73        except IOError:
74            raise service_error(service_error.internal, "Cannot create tmp dir")
75
76        tclfile = tmpdir + "/experiment.tcl"
77        pid = "dummy"
78        gid = "dummy"
79        eid = "dummy"
80
81        req = req.get('Ns2SplitRequestBody', None)
82        if not req:
83            raise service_error(service_error.req,
84                    "Bad request format (no Ns2SplitRequestBody)")
85        # The tcl parser needs to read a file so put the content into that file
86        descr=req.get('description', None)
87        if descr:
88            file_content=descr.get('ns2description', None)
89            if file_content:
90                try:
91                    f = open(tclfile, 'w')
92                    f.write(file_content)
93                    f.close()
94                except IOError:
95                    raise service_error(service_error.internal,
96                            "Cannot write temp experiment description")
97            else:
98                raise service_error(service_error.req, 
99                        "Only ns2descriptions supported")
100        else:
101            raise service_error(service_error.req, "No description")
102
103        master = req.get('master', None)
104        if master == None:
105            raise service_error(service_error.req, "No master testbed label")
106       
107        include_fedkit = req.get('include_fedkit', None)
108        if include_fedkit == None:
109            raise service_error(service_error.req, 
110                    "No federation kit inclusion directive")
111       
112       
113        tclcmd = [self.tclsh, self.tcl_splitter, '-s', '-x', 
114            str(self.muxmax), '-m', master]
115        if include_fedkit: tclcmd.append('-k')
116        tclcmd.extend([pid, gid, eid, tclfile])
117        self.log.debug("Calling splitter %s" % " ".join(tclcmd))
118        tclparser = subprocess.Popen(tclcmd, stdout=subprocess.PIPE)
119
120        out = ""
121        # Package up the split data
122        for line in tclparser.stdout:
123            out += line
124
125        # Walk up tmpdir, deleting as we go
126        for path, dirs, files in os.walk(tmpdir, topdown=False):
127            for f in files:
128                os.remove(os.path.join(path, f))
129            for d in dirs:
130                os.rmdir(os.path.join(path, d))
131        os.rmdir(tmpdir)
132
133        resp = { 'output' : out }
134
135        return resp
136
137
Note: See TracBrowser for help on using the repository browser.