示例#1
0
def start_workflow(scenario_id,
                   workflowtemplate_id,
                   log_level='INFO',
                   scenario_type="flooding_scenario"):
    """
    Opens connection to broker.
    Creates ActionWorkflow object.
    Creates logging handler to send loggings to broker.
    Sets logging handler to ActionWorkflow object.
    Performs workflow.
    Removes handler.
    Closes connection.

    See also: worker.action_workflow.ActionWorkflow object
    """
    numeric_level = getattr(logging, log_level.upper(), None)
    if not isinstance(numeric_level, int):
        log.error("Invalid log level: %s" % log_level)
        numeric_level = 10

    broker = BrokerConnection()
    connection = broker.connect_to_broker()
    if connection is None:
        log.error("Could not connect to broker.")
        return

    action = ActionWorkflow(connection,
                            scenario_id,
                            workflowtemplate_id,
                            scenario_type=scenario_type)

    logging.handlers.AMQPMessageHandler = AMQPMessageHandler
    broker_handler = logging.handlers.AMQPMessageHandler(action, numeric_level)

    action.set_broker_logging_handler(broker_handler)
    status = action.perform_workflow()
    action.log.removeHandler(broker_handler)
    if connection.is_open:
        connection.close()

    return status
示例#2
0
def start_workflow(
    scenario_id, workflowtemplate_id, log_level='INFO',
    scenario_type="flooding_scenario"):
    """
    Opens connection to broker.
    Creates ActionWorkflow object.
    Creates logging handler to send loggings to broker.
    Sets logging handler to ActionWorkflow object.
    Performs workflow.
    Removes handler.
    Closes connection.

    See also: worker.action_workflow.ActionWorkflow object
    """
    numeric_level = getattr(logging, log_level.upper(), None)
    if not isinstance(numeric_level, int):
        log.error("Invalid log level: %s" % log_level)
        numeric_level = 10

    broker = BrokerConnection()
    connection = broker.connect_to_broker()
    if connection is None:
        log.error("Could not connect to broker.")
        return

    action = ActionWorkflow(
        connection, scenario_id, workflowtemplate_id,
        scenario_type=scenario_type)

    logging.handlers.AMQPMessageHandler = AMQPMessageHandler
    broker_handler = logging.handlers.AMQPMessageHandler(
        action, numeric_level)

    action.set_broker_logging_handler(broker_handler)
    status = action.perform_workflow()
    action.log.removeHandler(broker_handler)
    if connection.is_open:
        connection.close()

    return status
    def handle(self, *args, **options):
        """
        Opens connection to broker.
        Creates ActionWorkflow object.
        Creates logging handler to send loggings to broker.
        Sets logging handler to ActionWorkflow object.
        Performs workflow.
        Closes connection.
        """
        numeric_level = getattr(logging, options["log_level"].upper(), None)
        if not isinstance(numeric_level, int):
            log.error("Invalid log level: %s" % options["log_level"])
            numeric_level = 10

        broker = BrokerConnection()
        connection = broker.connect_to_broker()

        removeFileHandlers()
        setFileHandler('start')

        if connection is None:
            log.error("Could not connect to broker.")
            return

        action = ActionWorkflow(
            connection, options["scenario_id"], options["workflowtemplate_id"])

        logging.handlers.AMQPMessageHandler = AMQPMessageHandler
        broker_handler = logging.handlers.AMQPMessageHandler(action,
                                                             numeric_level)

        action.set_broker_logging_handler(broker_handler)
        action.perform_workflow()

        if connection.is_open:
            connection.close()
    def handle(self, *args, **options):
        """
        Opens connection to broker.
        Creates ActionWorkflow object.
        Creates logging handler to send loggings to broker.
        Sets logging handler to ActionWorkflow object.
        Performs workflow.
        Closes connection.
        """
        numeric_level = getattr(logging, options["log_level"].upper(), None)
        if not isinstance(numeric_level, int):
            log.error("Invalid log level: %s" % options["log_level"])
            numeric_level = 10

        broker = BrokerConnection()
        connection = broker.connect_to_broker()

        removeFileHandlers()
        setFileHandler('start')

        if connection is None:
            log.error("Could not connect to broker.")
            return

        action = ActionWorkflow(connection, options["scenario_id"],
                                options["workflowtemplate_id"])

        logging.handlers.AMQPMessageHandler = AMQPMessageHandler
        broker_handler = logging.handlers.AMQPMessageHandler(
            action, numeric_level)

        action.set_broker_logging_handler(broker_handler)
        action.perform_workflow()

        if connection.is_open:
            connection.close()