def execute(self, conf=None, caller=None, apMon=None, logger=None): """ This method is invoked by fdtd once the action object is received from remote fdtcp (where the action instance was created). Options known on fdtd are set on the action instance (e.g. finalizing command for invoking FDT Java - location of fdt.jar is known only at fdtd site). """ # this method is called on PYRO service side, user its logger # from now on localGridUser = self.options["gridUserSrc"] logger.debug("Local grid user is '%s'" % localGridUser) self.options["sudouser"] = localGridUser self._setUp(conf) killTimeout = conf.get("fdtSendingClientKillTimeout") executor = Executor(self.id, self.command, blocking=True, caller=caller, userName=localGridUser, killTimeout=killTimeout, syncFlag=False, logger=logger) try: try: output = executor.execute() except ExecutorException as ex: m = ("FDT Java client on %s failed, " "reason: %s" % (getHostName(), ex)) logger.error(m) raise FDTDException(m) except Exception as ex: m = ("FDT Java client on %s failed, " "reason: %s" % (getHostName(), ex)) logger.error(m, traceBack=True) raise FDTDException(m) else: # no other exception was raised during execution r = Result(self.id) r.status = 0 r.log = output r.msg = "Output from FDT client" logger.debug("FDT client log (as sent to " "fdtcp):\n%s" % output) return r finally: # give signal on this actions Executor instance that its handling # finished (e.g. CleanupProcessesAction may be waiting for this) executor.syncFlag = False
def _setUp(self, conf): """ TODO doc """ # generate FDT fileList, put it into the same location as log file if conf.get("logFile"): logDir = os.path.dirname(conf.get("logFile")) else: logDir = "/tmp" directory = os.path.join(logDir, "fileLists") fileListName = os.path.join(directory, "fdt-fileList-%s" % self.id) try: if not os.path.exists(directory): os.mkdir(directory) fileList = open(fileListName, 'w') except IOError as ex: m = ("Could not create FDT client fileList file %s, " "reason: %s" % (fileListName, ex)) raise FDTDException(m) # this will be propagated to fdtcp for f in self.options["transferFiles"]: # is list of TransferFiles instances fileList.write("%s\n" % f) fileList.close() self.options["fileList"] = fileListName if 'monID' not in self.options: self.options["monID"] = self.id newOptions = self.options newOptions['apmonDest'] = conf.get("apMonDestinations") if self.options['circuitClientIP'] and self.options['circuitServerIP']: newOptions['hostDest'] = self.options['circuitServerIP'] self.command = conf.get("fdtSendingClientCommand") % newOptions
def _setUp(self): """ Set up Sending client action """ # generate FDT fileList, put it into the same location as log file if self.conf.get("logFile"): logDir = os.path.dirname(self.conf.get("logFile")) else: logDir = "/tmp" directory = os.path.join(logDir, "fileLists") fileListName = os.path.join(directory, "fdt-fileList-%s" % self.id) try: if not os.path.exists(directory): os.mkdir(directory) except IOError as ex: msg = ("Could not create FDT client fileList file %s, " "reason: %s" % (fileListName, ex)) self.status = -2 raise FDTDException(msg) # this will be propagated to fdtcp with open(fileListName, 'w') as fd: for fileName in self.options["transferFiles"]: # is list of TransferFiles instances fd.write("%s\n" % fileName) self.options["fileList"] = fileListName if 'monID' not in self.options: self.options["monID"] = self.id newOptions = self.options newOptions['apmonDest'] = self.conf.get("apMonDestinations") if not self.apMon: self.apMon = getApmonObj(newOptions['apmonDest']) self.command = self.conf.get("fdtSendingClientCommand") % newOptions
def execute(self, conf=None, caller=None, apMon=None, logger=None): """ This method is invoked by fdtd once the action object is received from remote fdtcp (where the action instance was created). Options known on fdtd are set on the action instance (e.g. finalizing command for invoking FDT Java - location of fdt.jar is known only at fdtd site). """ # this method is called on PYRO service side, user its logger # from now on localGridUser = self.options["gridUserSrc"] logger.debug("Local grid user is '%s'" % localGridUser) self.options["sudouser"] = localGridUser self._setUp(conf) killTimeout = conf.get("fdtSendingClientKillTimeout") executor = Executor(self.id, self.command, blocking=True, caller=caller, userName=localGridUser, killTimeout=killTimeout, syncFlag=True, logger=logger) try: try: output = executor.execute() except ExecutorException, ex: m = ("FDT Java client on %s failed, " "reason: %s" % (getHostName(), ex)) logger.error(m) raise FDTDException(m) except Exception, ex: m = ("FDT Java client on %s failed, " "reason: %s" % (getHostName(), ex)) logger.error(m, traceBack=True) raise FDTDException(m)
def _setUp(self, conf): # generate FDT fileList, put it into the same location as log file if conf.get("logFile"): logDir = os.path.dirname(conf.get("logFile")) else: logDir = "/tmp" dir = os.path.join(logDir, "fileLists") fileListName = os.path.join(dir, "fdt-fileList-%s" % self.id) try: if not os.path.exists(dir): os.mkdir(dir) fileList = open(fileListName, 'w') except IOError, ex: m = ("Could not create FDT client fileList file %s, " "reason: %s" % (fileListName, ex)) raise FDTDException(m) # this will be propagated to fdtcp
def execute(self, conf=None, caller=None, apMon=None, logger=None): """ This method is is called on the remote site where fdtd runs - here are also known all configuration details, thus final set up has to happen here. """ startTime = datetime.datetime.now() # may fail with subset of FDTDException which will be propagated port = caller.getFreePort() self._setUp(conf, port) destFiles = self.options["destFiles"] logger.info("%s - checking presence of files at target " "location ..." % self.__class__.__name__) logger.debug("Results:\n%s" % self._checkTargetFileNames(destFiles)) user = self.options["sudouser"] logger.debug("Local grid user is '%s'" % user) toWaitFor = conf.get("fdtServerLogOutputToWaitFor") % dict(port=port) toWaitTimeout = conf.get("fdtServerLogOutputTimeout") killTimeout = conf.get("fdtReceivingServerKillTimeout") executor = Executor(self.id, caller=caller, command=self.command, blocking=False, port=port, userName=user, logOutputToWaitFor=toWaitFor, killTimeout=killTimeout, logOutputWaitTime=toWaitTimeout, logger=logger) try: output = executor.execute() # on errors, do not do any cleanup or port releasing, from # Executor.execute() the instance is in the container and shall # be handled by CleanupProcessesAction except Exception, ex: m = ("Could not start FDT server on %s port: %s, reason: %s" % (getHostName(), port, ex)) logger.critical(m, traceBack=True) self._checkForAddressAlreadyInUseError(str(ex), port, logger) raise FDTDException(m)