Exemple #1
0
    def parse_out_message(self, message):
        """
        Parse output or error messages from payload.

        :param message: The message string received from payload.

        :returns: a dict {'id': <id>, 'status': <status>, 'output': <output if produced>, 'cpu': <cpu>, 'wall': <wall>, 'message': <full message>}
        :raises: PilotExecption: when a PilotException is caught.
                 UnknownException: when other unknown exception is caught.
        """

        logger.debug('parsing message: %s' % message)
        try:
            if message.startswith("/"):
                parts = message.split(",")
                ret = {'output': parts[0]}
                parts = parts[1:]
                for part in parts:
                    name, value = part.split(":")
                    name = name.lower()
                    ret[name] = value
                ret['status'] = 'finished'
                return ret
            elif message.startswith('ERR'):
                if "ERR_ATHENAMP_PARSE" in message:
                    pattern = re.compile(r"(ERR\_[A-Z\_]+)\ (.+)\:\ ?(.+)")
                    found = re.findall(pattern, message)
                    event_range = found[0][1]
                    if "eventRangeID" in event_range:
                        pattern = re.compile(
                            r"eventRangeID\'\:\ ?.?\'([0-9\-]+)")
                        found = re.findall(pattern, event_range)
                        event_range_id = found[0]
                        ret = {
                            'id': event_range_id,
                            'status': 'failed',
                            'message': message
                        }
                        return ret
                    else:
                        raise Exception("Failed to parse %s" % message)
                else:
                    pattern = re.compile(
                        r"(ERR\_[A-Z\_]+)\ ([0-9\-]+)\:\ ?(.+)")
                    found = re.findall(pattern, message)
                    event_range_id = found[0][1]
                    ret = {
                        'id': event_range_id,
                        'status': 'failed',
                        'message': message
                    }
                    return ret
            else:
                raise UnknownException("Unknown message %s" % message)
        except PilotException as e:
            raise e
        except Exception as e:
            raise UnknownException(e)
Exemple #2
0
    def kill(self):
        """
        Terminate running threads and processes.

        :param time_to_wait: integer, seconds to wait to force kill the payload process.

        :raises: PilotExecption: when a PilotException is caught.
                 UnknownException: when other unknown exception is caught.
        """
        logger.info('terminate running threads and processes.')
        try:
            self.stop()
            if self.__process:
                if not self.__process.poll() is None:
                    if self.__process.poll() == 0:
                        logger.info("payload finished successfully.")
                    else:
                        logger.error("payload finished with error code: %s" %
                                     self.__process.poll())
                else:
                    logger.info('killing payload process.')
                    pgid = os.getpgid(self.__process.pid)
                    logger.info('got process group id for pid %s: %s' %
                                (self.__process.pid, pgid))
                    # logger.info('send SIGKILL to process group: %s' % pgid)
                    # os.killpg(pgid, signal.SIGKILL)
                    logger.info('send SIGKILL to process: %s' %
                                self.__process.pid)
                    kill_child_processes(self.__process.pid)
        except Exception as e:
            logger.error('Exception caught when terminating ESProcess: %s' % e)
            self.stop()
            raise UnknownException(e)
Exemple #3
0
    def fit(self, x, y, model='linear'):
        """
        Fitting function.
        For a linear model: y(x) = slope * x + intersect

        :param x: list of input data (list of floats or ints).
        :param y: list of input data (list of floats or ints).
        :param model: model name (string).
        :raises UnknownException: in case Fit() fails.
        :return:
        """

        try:
            self._fit = Fit(x=x, y=y, model=model)
        except Exception as e:
            raise UnknownException(e)

        return self._fit