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 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) 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() except ExecutorException, ex: m = ("Could not start FDT server on %s port: %s, reason: %s" % (getHostName(), port, ex)) caller.releasePort(port) logger.error(m) raise FDTDException(m)
def __init__(self, id): """Result object always, id associated with previously launched action.""" CarrierBase.__init__(self, id) self.log = None self.msg = None self.status = None self.host = getHostName() self.serverPort = None
def __init__(self, id): """ Result object always, id associated with previously launched action. """ CarrierBase.__init__(self, id) self.log = None self.msg = None self.status = None self.host = getHostName() self.serverPort = None
def _getId(self): """Transfer job / request / id will consist of hostname of the machine fdtcp is invoked on and timestamp. This id will be used in all requests to fdtd for tracking the state of the transfer job, esp. by MonALISA ApMon. Transfers at fdtd will be associated with this ID - make it as unique as possible to avoid collisions. """ h = getHostName() u = getUserName() dt = getDateTime() r = getRandomString('a', 'z', 5) id = "fdtcp-%s-%s-%s-%s" % (h, u, dt, r) return id
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 _getId(self, srcHostName, dstHostName): """ Transfer job / request / id will consist of hostname of the machine fdtcp is invoked on and timestamp. This id will be used in all requests to fdtd for tracking the state of the transfer job, esp. by MonALISA ApMon. Transfers at fdtd will be associated with this ID - make it as unique as possible to avoid collisions. """ h = getHostName() # u = getUserName() dt = getDateTime() r = getRandomString('a', 'z', 5) template = "fdtcp-%(host)s--%(source)s-to-%(dest)s--%(datetime)s-%(randomStr)s" d = dict(host=h, source=srcHostName, dest=dstHostName, datetime=dt, randomStr=r) idT = template % d return idT
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)
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, logger = logger) try: output = executor.execute() except ExecutorException, ex: m = ("Could not start FDT client on %s, reason: %s" % (getHostName(), ex)) logger.error(m) raise FDTDException(m)
def testResult(): r = Result("some_id") str(r) assert r.id == "some_id" assert r.host == getHostName()
def testGetHostName(): host = getHostName() assert isinstance(host, str) assert len(host) > 1
def getHost(self): """ Returns hostname """ return self.conf.get("hostname") or getHostName()
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 = None if 'portServer' in self.options: logger.info("Forcing to use user specified port %s" % self.options['portServer']) try: port = int(self.options['portServer']) except TypeError as er: logger.info("Provided portServer key is not convertable to integer: %, Error: %s", self.options['portServer'], er) port = int(caller.getFreePort()) else: logger.info("Try to get a free port") port = int(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 as ex: raiser, ex = self._checkForAddressAlreadyInUseError(str(ex), port, logger) m = ("Could not start FDT server on %s port: %s, reason: %s" % (getHostName(), port, ex)) logger.critical(m, traceBack=True) raise raiser(m) else: r = Result(self.id) r.status = 0 # port on which FDT Java server runs r.serverPort = port r.msg = "FDT server is running" r.log = output logger.debug("Response to client: %s" % r) endTime = datetime.datetime.now() elapsed = (endTime - startTime).seconds par = dict(id=self.id, fdt_server_init=elapsed) logger.debug("Starting FDT server lasted: %s [s]." % elapsed) if apMon: logger.debug("Sending data to ApMon ...") apMon.sendParameters("fdtd_server_writer", None, par) return r
def execute(self): """ 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 if 'portServer' in self.options and self.options['portServer']: self.logger.info("Forcing to use user specified port %s" % self.options['portServer']) try: self.port = int(self.options['portServer']) except TypeError as ex: self.logger.info( "Provided portServer key is not convertable to integer: %s, Error: %s" % (self.options['portServer'], ex)) self.port = int(self.caller.getFreePort()) else: self.logger.info("Try to get a free port") self.port = int(self.caller.getFreePort()) self._setUp(self.conf, self.port) destFiles = self.options["destFiles"] self.logger.info("%s - checking presence of files at target " "location ..." % self.__class__.__name__) self.logger.debug("Results:\n%s" % self._checkTargetFileNames(destFiles)) user = self.options["sudouser"] self.logger.debug("Local grid user is '%s'" % user) self.executor = Executor(self.id, caller=self.caller, command=self.command, port=self.port, userName=user, logger=self.logger) try: output = self.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 as ex: raiser, ex = self._checkAddrAlreadyInUseError(str(ex)) msg = ("Could not start FDT server on %s port: %s, reason: %s" % (getHostName(), self.port, ex)) self.logger.critical(msg, traceBack=True) self.status = -2 raise raiser(msg) else: rObj = Result(self.id) rObj.status = 0 self.status = 0 # port on which FDT Java server runs rObj.serverPort = self.port rObj.msg = "FDT server is running" rObj.log = output self.logger.debug("Response to client: %s" % rObj) endTime = datetime.datetime.now() elapsed = (endTime - startTime).seconds par = dict(id=self.id, fdt_server_init=elapsed) self.logger.debug("Starting FDT server lasted: %s [s]." % elapsed) if self.apMon: self.logger.debug("Sending data to ApMon ...") self.apMon.sendParameters("fdtd_server_writer", None, par) return rObj
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, logger = logger) try: output = executor.execute() except ExecutorException, ex: m = ("Could not start FDT client on %s, reason: %s" % (getHostName(), ex)) logger.error(m) raise FDTDException(m) except Exception, ex: m = ("Could not start FDT client on %s, reason: %s" % (getHostName(), ex)) logger.error(m, traceBack = True) raise FDTDException(m) else: # no exception was raised during execution (or handled well) r = Result(self.id) r.status = 0 r.log = output r.msg = "Output from FDT client" return r class AuthClientAction(Action): """This action is run purely locally, everything happens from fdtcp.