def start_fm(fmname, fmconf, zone=None, user=None, withbackstore=False, dryrun=False): import subprocess if withbackstore: bakfilebasename = "jc_%s" % (fmname) log.debug("Creating executives in %s" % (fmname)) for idx, e in enumerate(fmconf): # loop over executives hostname = e["hostname"] port = e["port"] endpoint = e["endpoint"] apps = e["apps"] # user = e['unixUser'] #jc command takes -u argument rather than read unixUser config environmentStr = e["environmentString"] evs = [x.split("=") for x in environmentStr.split(" ")] environmentStr = " ".join(["=".join([e[0], '"' + e[1] + '"']) for e in evs]) xmlresult = api.makecontextxml(hostname, port, endpoint, apps, zone=zone, withxmlhead=False) if withbackstore: xmlfilename = bakfilebasename + "_%d.xml" % (idx) log.debug(" write xml config to backstore: %s" % xmlfilename) with open(xmlfilename, "w") as xmlf: xmlf.write(xmlresult) cmmd = ["./jc.py", "startXdaqExe", hostname, "-e", str(port), "--envs", environmentStr] if zone is not None: cmmd += ["-z", zone] if user is not None: cmmd += ["-u", user] if dryrun: cmmd += ["--dryrun"] p = subprocess.Popen(cmmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=subprocess.PIPE) out, err = p.communicate() log.info(out) log.info("Executive %d started" % idx) cmmd = ["./jc.py", "configExec", hostname, "-e", str(port), "-x", xmlresult] if dryrun: cmmd += ["--dryrun"] p = subprocess.Popen(cmmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=subprocess.PIPE) out, err = p.communicate() log.info(out) log.info("Executive %d configured" % idx) sleep(5)
def makelistofexecutive(listofexecutives,zone=None,plainxml=False): result = [] exetmpl = '''<XdaqExecutive hostname="%(hostname)s" port="%(port)s" urn="/urn:xdaq-application:lid=0" qualifiedResourceType="rcms.fm.resource.qualifiedresource.XdaqExecutive" role="%(role)s" instance="0" logURL="%(logURL)s" logLevel="%(logLevel)s" pathToExecutive="/opt/xdaq/bin/xdaq.exe" unixUser="******" environmentString="%(environmentString)s"> <configFile>%(contextconfig)s</configFile> </XdaqExecutive> ''' hostlist=[] for e in listofexecutives: contextconfig_xml = api.makecontextxml(e['hostname'],e['port'],e['endpoint'],e['apps'],zone=zone,withxmlhead=True) contextconfig = contextconfig_xml if not plainxml: contextconfig = _wrapinxml(contextconfig_xml) #print contextconfig result.append(exetmpl%({'hostname':e['hostname'],'port':str(e['port']),'role':e['role'],'logURL':e['logURL'],'logLevel':e['logLevel'],'unixUser':e['unixUser'],'environmentString':e['environmentString'],'contextconfig':contextconfig})) hostlist.append(e['hostname']) hosts = set(hostlist) jctmpl = '''<Service name="JobControl" hostname="%(hostname)s" port="9999" urn="/urn:xdaq-application:lid=10" qualifiedResourceType="rcms.fm.resource.qualifiedresource.JobControl" />''' for h in hosts: result.append(jctmpl%({'hostname':h})) return result
def start_fm(fmname, fmconf, zone=None, user=None, withbackstore=False, dryrun=False): import subprocess if withbackstore: bakfilebasename = 'jc_%s' % (fmname) log.debug('Creating executives in %s' % (fmname)) for idx, e in enumerate(fmconf): #loop over executives hostname = e['hostname'] port = e['port'] endpoint = e['endpoint'] apps = e['apps'] #user = e['unixUser'] #jc command takes -u argument rather than read unixUser config environmentStr = e['environmentString'] evs = [x.split('=') for x in environmentStr.split(' ')] environmentStr = ' '.join( ['='.join([e[0], '"' + e[1] + '"']) for e in evs]) xmlresult = api.makecontextxml(hostname, port, endpoint, apps, zone=zone, withxmlhead=False) if withbackstore: xmlfilename = bakfilebasename + '_%d.xml' % (idx) log.debug(' write xml config to backstore: %s' % xmlfilename) with open(xmlfilename, 'w') as xmlf: xmlf.write(xmlresult) cmmd = [ './jc.py', 'startXdaqExe', hostname, '-e', str(port), '--envs', environmentStr ] if zone is not None: cmmd += ['-z', zone] if user is not None: cmmd += ['-u', user] if dryrun: cmmd += ['--dryrun'] p = subprocess.Popen(cmmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=subprocess.PIPE) out, err = p.communicate() log.info(out) log.info('Executive %d started' % idx) cmmd = [ './jc.py', 'configExec', hostname, '-e', str(port), '-x', xmlresult ] if dryrun: cmmd += ['--dryrun'] p = subprocess.Popen(cmmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=subprocess.PIPE) out, err = p.communicate() log.info(out) log.info('Executive %d configured' % idx) sleep(5)