source: fedd/fedd_split.py @ 9c166cf

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

Add support for a real fedkit tar file rather than the ad hoc script stuff.

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