def module_execute(module_name, entry_name, skull_txn=None, data=None, skull_txndata=None): if module_name is None or isinstance(module_name, types.StringType) is False: return if entry_name is None or isinstance(entry_name, types.StringType) is False: return user_module = UserModuleTables.get(module_name) if user_module is None: Logger.fatal('module_execute', 'Cannot find user module: {}'.format(module_name), 'please check the module has contained correct entries') return entry_func = user_module['entries'][entry_name] if entry_name == MODULE_INIT_FUNCNAME: config = user_module['config'] skull_module_executor.run_module_init(entry_func, config) elif entry_name == MODULE_RELEASE_FUNCNAME: skull_module_executor.run_module_release(entry_func) elif entry_name == MODULE_RUN_FUNCNAME: return skull_module_executor.run_module_run(entry_func, skull_txn) elif entry_name == MODULE_UNPACK_FUNCNAME: return skull_module_executor.run_module_unpack(entry_func, skull_txn, data) elif entry_name == MODULE_PACK_FUNCNAME: skull_module_executor.run_module_pack(entry_func, skull_txn, skull_txndata) else: Logger.error('module_execute', 'Unknown entry name for execution: {}'.format(entry_name), 'Please check the engine code, it shouldn\'t be') raise
def module_init(config): print "py module init" Logger.trace('py module init: trace test') Logger.debug('py module init: debug test') Logger.info('1', 'py module init: info test') Logger.warn('2', 'py module init: warn test', 'no suggestion') Logger.error('3', 'py module init: error test', 'no solution') Logger.fatal('4', 'py module init: fatal test', 'no solution') return
def run_module_pack(pack_func, skull_txn, skull_txndata): txn = Txn.Txn(skull_txn) txndata = TxnData.TxnData(skull_txndata) try: pack_func(txn, txndata) except Exception as e: Logger.error( 'module_pack', 'module_pack failed due to: {}'.format(e), 'Please check the logic why return False or Exception occurred') finally: txn.destroyMsgData()
def run_module_run(run_func, skull_txn): try: txn = Txn.Txn(skull_txn) ret = run_func(txn) txn.storeMsgData() return ret except Exception as e: Logger.error( 'module_run', 'module_run failed due to: {}'.format(e), 'Please check the logic why return False or Exception occurred') return False
def module_pack(txn, txndata): mod_metrics = Metrics.module() mod_metrics.response.inc(1) mod_dymetrics = Metrics.transaction('test') mod_dymetrics.response.inc(1) if txn.status() != Txn.Txn.TXN_OK: txndata.append('error') Logger.error('6', 'module_pack error', 'no solution') else: example_msg = txn.data() print "pack data: %s" % example_msg.data Logger.info('7', 'module_pack: data sz: {}'.format(len(example_msg.data))) txndata.append(example_msg.data)
def run_module_unpack(unpack_func, skull_txn, data): txn = Txn.Txn(skull_txn) try: consumed_length = unpack_func(txn, data) txn.storeMsgData() if consumed_length is None: return -1 return int(consumed_length) except Exception as e: Logger.error( 'module_unpack', 'module_unpack failed due to: {}'.format(e), 'Please check the logic why return False or Exception occurred') return -1 # Error occurred