Exemple #1
0
    def _handle_trigger_sobjs(cls,
                              triggers_sobjs,
                              caller,
                              event,
                              output,
                              forced_mode='',
                              project_code=None):

        triggers = []

        # go through each trigger and build the trigger sobject
        for trigger_sobj in triggers_sobjs:

            mode = trigger_sobj.get_value("mode", no_exception=True)
            if not mode:
                mode = 'same process,new transaction'

            if trigger_sobj.get_base_search_type() == "sthpw/notification":
                if forced_mode:
                    trigger_class = "pyasm.command.EmailTriggerTest"
                else:
                    trigger_class = "pyasm.command.EmailTrigger2"
            else:
                trigger_class = trigger_sobj.get_value("class_name")

            try:
                if trigger_class in [
                        'pyasm.command.EmailTrigger2',
                        'pyasm.command.EmailTriggerTest'
                ]:
                    # allow the trigger handler to know the calling sobj
                    trigger = Common.create_from_class_path(trigger_class)
                    trigger.set_trigger_sobj(trigger_sobj)
                    if not forced_mode:
                        mode = 'separate process,non-blocking'
                    else:
                        mode = forced_mode

                elif mode in [
                        'same process,same transaction',
                        'same process,new transaction'
                ]:
                    script_path = trigger_sobj.get_value("script_path")
                    if trigger_class == '':
                        from tactic.command.python_cmd import PythonTrigger
                        trigger = PythonTrigger()
                        trigger.set_script_path(script_path)
                    elif not isinstance(trigger_class, basestring):
                        trigger = trigger_class()
                    else:
                        trigger = Common.create_from_class_path(trigger_class)

                else:
                    if trigger_class == '':
                        script_path = trigger_sobj.get_value("script_path")

                        trigger_class = "tactic.command.PythonTrigger"
                        kwargs = {"script_path": script_path}
                    else:
                        kwargs = {}

                    from subprocess_trigger import SubprocessTrigger
                    trigger = SubprocessTrigger()
                    trigger.set_mode(mode)
                    if not project_code:
                        from pyasm.biz import Project
                        project_code = Project.get_project_code()
                    data = {
                        "project": project_code,
                        "ticket": Environment.get_ticket(),
                        "class_name": trigger_class,
                        "kwargs": kwargs
                    }
                    trigger.set_data(data)

                trigger.set_event(event)

                if isinstance(trigger, Trigger):
                    trigger.set_trigger_sobj(trigger_sobj)

                triggers.append(trigger)

            except ImportError, e:
                Environment.add_warning(
                    "Trigger Not Defined",
                    "Trigger [%s] does not exist" % trigger_class)

                #log = ExceptionLog.log(e)

                # print the stacktrace
                tb = sys.exc_info()[2]
                stacktrace = traceback.format_tb(tb)
                stacktrace_str = "".join(stacktrace)
                print "-" * 50
                print stacktrace_str
                print str(e)
                print "-" * 50
                raise

            if issubclass(trigger.__class__, Trigger):
                trigger.set_caller(caller)
                trigger.set_message(event)

            # if it is a subclass of client api handler

            # create a package
            # transfer outputs to inputs.  This allows a command to deliver
            # from one process to another
            if output:
                input = output.copy()
            else:
                input = caller.get_info()

            trigger.set_input(input)
            # By default, inputs travel through
            trigger.set_output(input)
            # set the description properly for transaction_log
            trigger.set_description(trigger_sobj.get_value('description'))

            # if delayed, then register it to be executed later
            if mode != 'same process,same transaction':
                Container.append_seq("Trigger:called_triggers", trigger)
                continue

            # otherwise call the trigger immediately
            try:
                trigger.execute()
            except Exception, e:
                #log = ExceptionLog.log(e)

                # print the stacktrace
                tb = sys.exc_info()[2]
                stacktrace = traceback.format_tb(tb)
                stacktrace_str = "".join(stacktrace)
                print "-" * 50
                print stacktrace_str
                print str(e)
                print "-" * 50

                caller.errors.append("Trigger [%s] failed: %s" \
                    %(trigger.get_title(), str(e)))

                raise
Exemple #2
0
    def _handle_trigger_sobjs(cls, triggers_sobjs, caller, event, output, forced_mode='', project_code=None):

        triggers = []

        # go through each trigger and build the trigger sobject
        for trigger_sobj in triggers_sobjs:

            mode = trigger_sobj.get_value("mode", no_exception=True)
            if not mode:
                mode = 'same process,new transaction'
            
            if trigger_sobj.get_base_search_type() == "sthpw/notification":
                if forced_mode:
                    trigger_class = "pyasm.command.EmailTriggerTest"
                else:
                    trigger_class = "pyasm.command.EmailTrigger2"
            else:
                trigger_class = trigger_sobj.get_value("class_name")

            try:
                if trigger_class in ['pyasm.command.EmailTrigger2', 'pyasm.command.EmailTriggerTest']:
                    # allow the trigger handler to know the calling sobj
                    trigger = Common.create_from_class_path(trigger_class)
                    trigger.set_trigger_sobj(trigger_sobj)   
                    if not forced_mode:
                        mode = 'separate process,non-blocking'
                    else:
                        mode = forced_mode

                elif mode in ['same process,same transaction',
                            'same process,new transaction']:
                    script_path = trigger_sobj.get_value("script_path")
                    if trigger_class == '':
                        from tactic.command.python_cmd import PythonTrigger
                        trigger = PythonTrigger()
                        trigger.set_script_path(script_path)
                    elif not isinstance(trigger_class,basestring):
                        trigger = trigger_class()
                    else:
                        trigger = Common.create_from_class_path(trigger_class)

                else:
                    if trigger_class == '':
                        script_path = trigger_sobj.get_value("script_path")

                        trigger_class = "tactic.command.PythonTrigger"
                        kwargs = {
                            "script_path": script_path
                        }
                    else:
                        kwargs = {}

                    # add any data to the kwargs
                    trigger_data = trigger_sobj.get_value("data")
                    if trigger_data:
                        trigger_data = jsonloads(trigger_data)
                        for name, value in trigger_data.items():
                            kwargs[name] = value


                    from subprocess_trigger import SubprocessTrigger
                    trigger = SubprocessTrigger()
                    trigger.set_mode(mode)
                    if not project_code:
                        from pyasm.biz import Project
                        project_code = Project.get_project_code()
                    data = {
                        "project": project_code,
                        "ticket": Environment.get_ticket(),
                        "class_name": trigger_class,
                        "kwargs": kwargs,
                    }
                    trigger.set_data(data)

                trigger.set_event(event)

                if isinstance(trigger, Trigger):
                    trigger.set_trigger_sobj(trigger_sobj)

                triggers.append(trigger)

            except ImportError, e:
                Environment.add_warning("Trigger Not Defined", "Trigger [%s] does not exist" % trigger_class)

                #log = ExceptionLog.log(e)

                # print the stacktrace
                tb = sys.exc_info()[2]
                stacktrace = traceback.format_tb(tb)
                stacktrace_str = "".join(stacktrace)
                print("-"*50)
                print(stacktrace_str)
                print(str(e))
                print("-"*50)
                raise

            if issubclass( trigger.__class__, Trigger):
                trigger.set_caller(caller)
                trigger.set_message(event)

            # if it is a subclass of client api handler

            # create a package
            # transfer outputs to inputs.  This allows a command to deliver
            # from one process to another
            if output or output == {}:
                input = output.copy()
            else:
                input = caller.get_info()

            trigger.set_input(input)
            # By default, inputs travel through
            trigger.set_output(input)
            # set the description properly for transaction_log
            trigger.set_description(trigger_sobj.get_value('description'))

            # if delayed, then register it to be executed later
            if mode != 'same process,same transaction':
                Container.append_seq("Trigger:called_triggers",trigger)
                continue

            # otherwise call the trigger immediately
            try:
                trigger.execute()
            except Exception as e:
                #log = ExceptionLog.log(e)

                # print the stacktrace
                tb = sys.exc_info()[2]
                stacktrace = traceback.format_tb(tb)
                stacktrace_str = "".join(stacktrace)
                print("-"*50)
                print(stacktrace_str)
                print(str(e))
                print("-"*50)

                caller.errors.append("Trigger [%s] failed: %s" \
                    %(trigger.get_title(), str(e)))

                raise
Exemple #3
0
    def _handle_trigger_sobjs(cls, triggers_sobjs, caller, event, output, forced_mode=''):

        triggers = []

        # go through each trigger and build the trigger sobject
        for trigger_sobj in triggers_sobjs:

            mode = trigger_sobj.get_value("mode", no_exception=True)
            if not mode:
                mode = 'same process,new transaction'
            
            if trigger_sobj.get_base_search_type() == "sthpw/notification":
                if forced_mode:
                    trigger_class = "pyasm.command.EmailTriggerTest"
                else:
                    trigger_class = "pyasm.command.EmailTrigger2"
            else:
                trigger_class = trigger_sobj.get_value("class_name")

            try:
                # DEPRECATED
                # FIXME: get rid of this hard coding!!!!
                """
                if trigger_class.startswith("SPT."):
                    if trigger_class == 'SPT.MaterialCostTrigger':
                        script_code = '21MMS'
                    elif trigger_class == 'SPT.MaterialAggrgtCostTrigger':
                        script_code = '41MMS'
                    elif trigger_class == 'SPT.SubtaskCreateTrigger':
                        script_code = '161MMS'
                    elif trigger_class == 'SPT.LaborAggrgtTrigger':
                        script_code = '202MMS'
                    elif trigger_class == 'SPT.VndrCostAggrgtTrigger':
                        script_code = '203MMS'
                    elif trigger_class == 'SPT.PiecesAggrgtTrigger':
                        script_code = '204MMS'
                    elif trigger_class == 'SPT.PersonalTimeLogTrigger':
                        script_code = '261MMS'
                    elif trigger_class == 'SPT.SubtaskPiecesTrigger':
                        script_code = '321MMS'
                    elif trigger_class == 'SPT.SubtaskPiecesDeleteTrigger':
                        script_code = '322MMS'
                    elif trigger_class == 'SPT.ProductTypeAggrgtTrigger':
                        script_code = '681MMS'
                    elif trigger_class == 'SPT.JobCreatedTrigger':
                        script_code = '701MMS'
                    elif trigger_class == 'SPT.SubtaskClosedTrigger':
                        script_code = '702MMS'
                    elif trigger_class == 'SPT.JobClosedTrigger':
                        script_code = '703MMS'
                        # script_code = '141MMS'
                    else:
                        raise TriggerException("No script code found for trigger [%s]" % trigger_class)

                    from subprocess_trigger import SubprocessTrigger
                    trigger = SubprocessTrigger()
                    trigger.set_mode("MMS")
                    namespace, class_name = trigger_class.split(".")

                    from pyasm.biz import Project
                    data = {
                        "project": Project.get_project_code(),
                        "ticket": Environment.get_ticket(),
                        "class_name": class_name,
                        "script_code": script_code
                    }
                    trigger.set_data(data)
                """

                if trigger_class in ['pyasm.command.EmailTrigger2', 'pyasm.command.EmailTriggerTest']:
                    # allow the trigger handler to know the calling sobj
                    trigger = Common.create_from_class_path(trigger_class)
                    trigger.set_trigger_sobj(trigger_sobj)   
                    if not forced_mode:
                        mode = 'separate process,non-blocking'
                    else:
                        mode = forced_mode

                elif mode in ['same process,same transaction',
                            'same process,new transaction']:
                    script_path = trigger_sobj.get_value("script_path")
                    if trigger_class == '':
                        from tactic.command.python_cmd import PythonTrigger
                        trigger = PythonTrigger()
                        trigger.set_script_path(script_path)
                    else:
                        trigger = Common.create_from_class_path(trigger_class)

                else:
                    if trigger_class == '':
                        script_path = trigger_sobj.get_value("script_path")
                        #from tactic.command.python_cmd import PythonTrigger
                        #trigger = PythonTrigger()
                        #trigger.set_script_path(script_path)

                        trigger_class = "tactic.command.PythonTrigger"
                        kwargs = {
                            "script_path": script_path
                        }
                    else:
                        kwargs = {}

                    from subprocess_trigger import SubprocessTrigger
                    trigger = SubprocessTrigger()
                    trigger.set_mode(mode)

                    from pyasm.biz import Project
                    data = {
                        "project": Project.get_project_code(),
                        "ticket": Environment.get_ticket(),
                        "class_name": trigger_class,
                        "kwargs": kwargs
                    }
                    trigger.set_data(data)

                trigger.set_event(event)

                if isinstance(trigger, Trigger):
                    trigger.set_trigger_sobj(trigger_sobj)

                triggers.append(trigger)

            except ImportError, e:
                Environment.add_warning("Trigger Not Defined", "Trigger [%s] does not exist" % trigger_class)

                #log = ExceptionLog.log(e)

                # print the stacktrace
                tb = sys.exc_info()[2]
                stacktrace = traceback.format_tb(tb)
                stacktrace_str = "".join(stacktrace)
                print "-"*50
                print stacktrace_str
                print str(e)
                print "-"*50
                raise

            if issubclass( trigger.__class__, Trigger):
                trigger.set_caller(caller)
                trigger.set_message(event)

            # if it is a subclass of client api handler

            # create a package
            # transfer outputs to inputs.  This allows a command to deliver
            # from one process to another
            if output:
                input = output.copy()
            else:
                input = caller.get_info()

            trigger.set_input(input)
            # By default, inputs travel through
            trigger.set_output(input)
            # set the description properly for transaction_log
            trigger.set_description(trigger_sobj.get_value('description'))

            # if delayed, then register it to be executed later
            if mode != 'same process,same transaction':
                Container.append_seq("Trigger:called_triggers",trigger)
                continue

            # otherwise call the trigger immediately
            try:
                trigger.execute()
            except Exception, e:
                #log = ExceptionLog.log(e)

                # print the stacktrace
                tb = sys.exc_info()[2]
                stacktrace = traceback.format_tb(tb)
                stacktrace_str = "".join(stacktrace)
                print "-"*50
                print stacktrace_str
                print str(e)
                print "-"*50

                caller.errors.append("Trigger [%s] failed: %s" \
                    %(trigger.get_title(), str(e)))

                raise
Exemple #4
0
    def _handle_trigger_sobjs(cls,
                              triggers_sobjs,
                              caller,
                              event,
                              output,
                              forced_mode='',
                              project_code=None):

        triggers = []

        # go through each trigger and build the trigger sobject
        for trigger_sobj in triggers_sobjs:

            mode = trigger_sobj.get_value("mode", no_exception=True)
            if not mode:
                mode = 'same process,new transaction'

            if trigger_sobj.get_base_search_type() == "sthpw/notification":
                if forced_mode:
                    trigger_class = "pyasm.command.EmailTriggerTest"
                else:
                    trigger_class = "pyasm.command.EmailTrigger2"
            else:
                trigger_class = trigger_sobj.get_value("class_name")

            try:
                # DEPRECATED
                # FIXME: get rid of this hard coding!!!!
                """
                if trigger_class.startswith("SPT."):
                    if trigger_class == 'SPT.MaterialCostTrigger':
                        script_code = '21MMS'
                    elif trigger_class == 'SPT.MaterialAggrgtCostTrigger':
                        script_code = '41MMS'
                    elif trigger_class == 'SPT.SubtaskCreateTrigger':
                        script_code = '161MMS'
                    elif trigger_class == 'SPT.LaborAggrgtTrigger':
                        script_code = '202MMS'
                    elif trigger_class == 'SPT.VndrCostAggrgtTrigger':
                        script_code = '203MMS'
                    elif trigger_class == 'SPT.PiecesAggrgtTrigger':
                        script_code = '204MMS'
                    elif trigger_class == 'SPT.PersonalTimeLogTrigger':
                        script_code = '261MMS'
                    elif trigger_class == 'SPT.SubtaskPiecesTrigger':
                        script_code = '321MMS'
                    elif trigger_class == 'SPT.SubtaskPiecesDeleteTrigger':
                        script_code = '322MMS'
                    elif trigger_class == 'SPT.ProductTypeAggrgtTrigger':
                        script_code = '681MMS'
                    elif trigger_class == 'SPT.JobCreatedTrigger':
                        script_code = '701MMS'
                    elif trigger_class == 'SPT.SubtaskClosedTrigger':
                        script_code = '702MMS'
                    elif trigger_class == 'SPT.JobClosedTrigger':
                        script_code = '703MMS'
                        # script_code = '141MMS'
                    else:
                        raise TriggerException("No script code found for trigger [%s]" % trigger_class)

                    from subprocess_trigger import SubprocessTrigger
                    trigger = SubprocessTrigger()
                    trigger.set_mode("MMS")
                    namespace, class_name = trigger_class.split(".")

                    from pyasm.biz import Project
                    data = {
                        "project": Project.get_project_code(),
                        "ticket": Environment.get_ticket(),
                        "class_name": class_name,
                        "script_code": script_code
                    }
                    trigger.set_data(data)
                """

                if trigger_class in [
                        'pyasm.command.EmailTrigger2',
                        'pyasm.command.EmailTriggerTest'
                ]:
                    # allow the trigger handler to know the calling sobj
                    trigger = Common.create_from_class_path(trigger_class)
                    trigger.set_trigger_sobj(trigger_sobj)
                    if not forced_mode:
                        mode = 'separate process,non-blocking'
                    else:
                        mode = forced_mode

                elif mode in [
                        'same process,same transaction',
                        'same process,new transaction'
                ]:
                    script_path = trigger_sobj.get_value("script_path")
                    if trigger_class == '':
                        from tactic.command.python_cmd import PythonTrigger
                        trigger = PythonTrigger()
                        trigger.set_script_path(script_path)
                    else:
                        trigger = Common.create_from_class_path(trigger_class)

                else:
                    if trigger_class == '':
                        script_path = trigger_sobj.get_value("script_path")
                        #from tactic.command.python_cmd import PythonTrigger
                        #trigger = PythonTrigger()
                        #trigger.set_script_path(script_path)

                        trigger_class = "tactic.command.PythonTrigger"
                        kwargs = {"script_path": script_path}
                    else:
                        kwargs = {}

                    from subprocess_trigger import SubprocessTrigger
                    trigger = SubprocessTrigger()
                    trigger.set_mode(mode)
                    if not project_code:
                        from pyasm.biz import Project
                        project_code = Project.get_project_code()
                    data = {
                        "project": project_code,
                        "ticket": Environment.get_ticket(),
                        "class_name": trigger_class,
                        "kwargs": kwargs
                    }
                    trigger.set_data(data)

                trigger.set_event(event)

                if isinstance(trigger, Trigger):
                    trigger.set_trigger_sobj(trigger_sobj)

                triggers.append(trigger)

            except ImportError, e:
                Environment.add_warning(
                    "Trigger Not Defined",
                    "Trigger [%s] does not exist" % trigger_class)

                #log = ExceptionLog.log(e)

                # print the stacktrace
                tb = sys.exc_info()[2]
                stacktrace = traceback.format_tb(tb)
                stacktrace_str = "".join(stacktrace)
                print "-" * 50
                print stacktrace_str
                print str(e)
                print "-" * 50
                raise

            if issubclass(trigger.__class__, Trigger):
                trigger.set_caller(caller)
                trigger.set_message(event)

            # if it is a subclass of client api handler

            # create a package
            # transfer outputs to inputs.  This allows a command to deliver
            # from one process to another
            if output:
                input = output.copy()
            else:
                input = caller.get_info()

            trigger.set_input(input)
            # By default, inputs travel through
            trigger.set_output(input)
            # set the description properly for transaction_log
            trigger.set_description(trigger_sobj.get_value('description'))

            # if delayed, then register it to be executed later
            if mode != 'same process,same transaction':
                Container.append_seq("Trigger:called_triggers", trigger)
                continue

            # otherwise call the trigger immediately
            try:
                trigger.execute()
            except Exception, e:
                #log = ExceptionLog.log(e)

                # print the stacktrace
                tb = sys.exc_info()[2]
                stacktrace = traceback.format_tb(tb)
                stacktrace_str = "".join(stacktrace)
                print "-" * 50
                print stacktrace_str
                print str(e)
                print "-" * 50

                caller.errors.append("Trigger [%s] failed: %s" \
                    %(trigger.get_title(), str(e)))

                raise