Esempio n. 1
0
 def emitEvents(self):
     self.harvestErrors()
     if not self._events or self._emitPid:
         return
     if ((time.time() - self._lastEmit) < self._emitEventTimeThreshold
         and self._numEvents < self._emitEventSizeThreshold):
         return
     events = self._events
     self._events = {}
     self.reader, writer = pipereader.makeMarshalPipes()
     pid = self._fork('emitEvents')
     if pid:
         writer.close()
         self._numEvents = 0
         self._lastEmit = time.time()
         self._emitPid = pid
         #self.debug('_emitEvents forked pid %d' % pid)
         return
     self.reader.close()
     try:
         try:
             for jobId, eventList in events.iteritems():
                 self.db.reopen()
                 self._emitEvents(jobId, eventList, writer)
             os._exit(0)
         except Exception, err:
             self.logger.error('Emit Events failed: %s\n%s', err, 
                               traceback.format_exc())
             os._exit(1)
     finally:
         os._exit(1)
Esempio n. 2
0
 def emitEvents(self):
     self.harvestErrors()
     if not self._events or self._emitPid:
         return
     if ((time.time() - self._lastEmit) < self._emitEventTimeThreshold
             and self._numEvents < self._emitEventSizeThreshold):
         return
     events = self._events
     self._events = {}
     self.reader, writer = pipereader.makeMarshalPipes()
     pid = self._fork('emitEvents')
     if pid:
         writer.close()
         self._numEvents = 0
         self._lastEmit = time.time()
         self._emitPid = pid
         #self.debug('_emitEvents forked pid %d' % pid)
         return
     self.reader.close()
     try:
         try:
             for jobId, eventList in events.iteritems():
                 self.db.reopen()
                 self._emitEvents(jobId, eventList, writer)
             os._exit(0)
         except Exception, err:
             self.logger.error('Emit Events failed: %s\n%s', err,
                               traceback.format_exc())
             os._exit(1)
     finally:
         os._exit(1)
Esempio n. 3
0
    def runCommand(self, commandClass, cfg, commandId, *args):
        """
            Start the given command by instantiating the given class.

            Returns the command object that was created unless there
            was an error instantiating the command object, in which
            case None is returned.

            The function may also return False, which means that the
            command could not be run at this time (but did not error)

            If the command is forked, then the command object is appended
            the the list of running commands.
        """
        command = None
        try:
            # errors before this point imply a problem w/ the node.
            # Below this point it is a problem w/ the command.
            command = commandClass(cfg, commandId, *args)
            if not command.isReady():
                return False
            if command.shouldFork():
                inF, outF = pipereader.makeMarshalPipes()
                pid = self._fork('Command %s' % command.getCommandId())
                if not pid:
                    try:
                        self._resetSignalHandlers()
                        inF.close()
                        command.setWritePipe(outF)
                        command.runCommandAndExit()
                    finally:
                        os._exit(1)
                else:
                    command.pid = pid
                    outF.close()
                    command.setReadPipe(inF)
                    self.commands.append(command)
            else:
                command.runCommandNoExit()
                self.commandCompleted(command.getCommandId())
        except Exception, err:
            self.error(
                'Command %s got exception: %s: %s' % (commandId, err.__class__.__name__, err))
            tb = traceback.format_exc()
            self.commandErrored(commandId, str(err), tb)
            if command:
                command.commandErrored(str(err), tb)
Esempio n. 4
0
    def runCommand(self, commandClass, cfg, commandId, *args):
        """
            Start the given command by instantiating the given class.

            Returns the command object that was created unless there
            was an error instantiating the command object, in which
            case None is returned.

            The function may also return False, which means that the
            command could not be run at this time (but did not error)

            If the command is forked, then the command object is appended
            the the list of running commands.
        """
        command = None
        try:
            # errors before this point imply a problem w/ the node.
            # Below this point it is a problem w/ the command.
            command = commandClass(cfg, commandId, *args)
            if not command.isReady():
                return False
            if command.shouldFork():
                inF, outF = pipereader.makeMarshalPipes()
                pid = self._fork('Command %s' % command.getCommandId())
                if not pid:
                    try:
                        self._resetSignalHandlers()
                        inF.close()
                        command.setWritePipe(outF)
                        command.runCommandAndExit()
                    finally:
                        os._exit(1)
                else:
                    command.pid = pid
                    outF.close()
                    command.setReadPipe(inF)
                    self.commands.append(command)
            else:
                command.runCommandNoExit()
                self.commandCompleted(command.getCommandId())
        except Exception, err:
            self.error('Command %s got exception: %s: %s' %
                       (commandId, err.__class__.__name__, err))
            tb = traceback.format_exc()
            self.commandErrored(commandId, str(err), tb)
            if command:
                command.commandErrored(str(err), tb)