def call_impdp(tables, data_dir, timeout = 60*60): """ Function: call_impdp Description: 调用oracle的impdp命令 Parameter: tables: 需要导入的数据表(list) data_dir: 数据文件所在磁盘的路径 timeout: 超时时间 Return: 错误码 Others: """ #impdp user_sync/user_sync@orcl directory=db_sync_dir dumpfile=ne_mocs.dmp TABLES=user_acp.tbl_TestAntenna,user_acp.tbl_TestPhysicalReader TABLE_EXISTS_ACTION=APPEND REMAP_SCHEMA=user_acp:user_sync oracle_info = db_cfg_info.get_configure("oracle sync") conn_string = "%s/%s@%s" % (oracle_info["username"] , oracle_info["password"] , oracle_info["db"]) cmd_line = ["impdp" , conn_string , "DIRECTORY=db_sync_dir" , "DUMPFILE=%s" % db_sync_common_const.DB_SYNC_FILE_NAME , "TABLES=%s" % ",".join(tables) , "TABLE_EXISTS_ACTION=APPEND" #, "REMAP_SCHEMA=user_acp:user_sync" , "PARALLEL=3" , "CONTENT=DATA_ONLY"] log_file_path = os.path.join(data_dir, "import.log") ret = __call_oracle_cmd(cmd_line, timeout, log_file_path) return ret
def _ready_for_work(self): """ Method: _ready_for_work Description: 父类实现方法,注册MOC对象 Parameter: 无 Return: 0,成功 其他,失败 Others: """ bf.BasicApp._ready_for_work(self) # Reister MOC object conn_info = oradb.ConnectionInfo(**db_cfg_info.get_configure(db_cfg_info.ORACLE_SYNC_CON_NAME)) self.__connection_pool = DBConnectionPool() self.__connection_pool.create_connection(db_cfg_info.ORACLE_SYNC_CON_NAME , conn_info , oradb.create_connection , 10) mit_manager = mit.Mit() mit_manager.open_oracle(**db_cfg_info.get_configure(db_cfg_info.ORACLE_DEFAULT_CON_NAME)) with self.get_connection(db_cfg_info.ORACLE_SYNC_CON_NAME) as db_conn: db_sync_event_manager = DBSyncEventManager(db_conn) db_sync_event_manager.remove_schema() db_sync_event_manager.create_schema() testdir = os.path.join(self.get_app_top_path(), 'moc_def', 'moc_test') sys.path.append(testdir) import TestAntenna import TestPhysicalReader mit_manager.regist_moc(TestAntenna.TestAntenna, TestAntenna.TestAntennaRule) mit_manager.regist_moc(TestPhysicalReader.TestPhysicalReader, TestPhysicalReader.TestPhysicalReaderRule) for i in xrange(1, int(math.ceil(float(EVENTS_NUM)/5)) + 1): ta = TestAntenna.TestAntenna() ta.readerId = 'readerId-%d' % i mit_manager.rdm_add(ta) ta.ChannelIndex = 99 mit_manager.rdm_mod(ta) mit_manager.rdm_remove(ta) reader = TestPhysicalReader.TestPhysicalReader() reader.readerId = 'readerId-%d' % i mit_manager.rdm_add(reader) mit_manager.rdm_remove(reader) #db_sync_event_manager.add_full_event() return 1
def _ready_for_work(self): """ Method: _ready_for_work Description: 父类实现方法,注册MOC对象 Parameter: 无 Return: 0,成功 其他,失败 Others: """ bf.BasicApp._ready_for_work(self) self.__mit_manager = db_sync_mit.DBSyncMit() ret = self.__mit_manager.reset_NE_state() if ret != 0: return ret # Register MOC objects to be synchonized curdir = os.path.join(self.get_app_top_path(), 'moc_def', 'moc_for_sync') DBSyncUtil.load_mocs(curdir, self.__synchronized_mocs) conn_info = oradb.ConnectionInfo(**db_cfg_info.get_configure(db_cfg_info.ORACLE_SYNC_CON_NAME)) self.__connection_pool = DBConnectionPool() self.__connection_pool.create_connection(self.get_connection_name() , conn_info , oradb.create_connection , 10) self.__data_manager = DBSyncDataManager(self) self.__data_manager.create_schemas(self.__synchronized_mocs.values()) # 初始化同步优先级数据 moc_priority = OraSyncPriority.OraSyncPriority() self.__data_manager.create_schemas([moc_priority], False); self.__priority_mit_manager = db_sync_priority_mit.DBSyncPriorityMit() rows = self.__priority_mit_manager.rdm_find(moc_priority.get_moc_name()) tracelog.info('priority records: %d' % len(rows)) for row in rows: tracelog.info('ne_id: %d, priority: %d, event_id: %d' % (row.ne_id, row.priority, row.event_id)) self.set_sync_sn(row.ne_id, row.priority, row.event_id) # 初始化网元信息 ret = self.__init_NE_info() if ret != 0: tracelog.info("initialize NE information failed.") return ret # Register db sync update worker work_thread = bf.WorkThread() self.register_worker(db_sync_update_worker.DBSyncUpdateWorker(), work_thread, False) self.register_worker(sync_full_exp_worker.SyncFullExpWorker(), work_thread, True) self.register_worker(sync_full_imp_worker.SyncFullImpWorker()) return 0
def _ready_for_work(self): """ Method: _ready_for_work Description: 父类实现方法,注册MOC对象 Parameter: 无 Return: 0,成功 其他,失败 Others: """ tracelog.info('_ready_for_work started.') bf.BasicApp._ready_for_work(self) # 创建数据库连接 self.__connection_pool = DBConnectionPool() conn_info = oradb.ConnectionInfo(**db_cfg_info.get_configure(db_cfg_info.ORACLE_DEFAULT_CON_NAME)) self.__connection_pool.create_connection(db_cfg_info.ORACLE_DEFAULT_CON_NAME , conn_info , oradb.create_connection , 5) conn_info = oradb.ConnectionInfo(**db_cfg_info.get_configure(db_cfg_info.ORACLE_SYNC_CON_NAME)) self.__connection_pool.create_connection(db_cfg_info.ORACLE_SYNC_CON_NAME , conn_info , oradb.create_connection , 1) with self.get_connection(db_cfg_info.ORACLE_SYNC_CON_NAME) as db_conn: db_sync_event_manager = DBSyncEventManager(db_conn) db_sync_event_manager.create_schema() # 加载所有MOC对象 curdir = os.path.join(self.get_app_top_path(), 'moc_def') DBSyncUtil.load_mocs(curdir, self.__synchronized_mocs) self.__init_moc_data_to_sync_tbl_sqls() # Register db sync worker self.register_worker(db_sync_worker.DBSyncWorker()) tracelog.info('_ready_for_work ended.') return 0
def __init__(self): """ Method: __init__ Description: 构造函数 Parameter: 无 Return: Others: """ mit.Mit.__init__(self) self.regist_moc(OraSyncPriority.OraSyncPriority, OraSyncPriority.OraSyncPriorityRule) self.open_oracle(**db_cfg_info.get_configure(db_cfg_info.ORACLE_SYNC_CON_NAME)) self.init_mit_lock()
def __init__(self): """ Method: __init__ Description: 构造函数 Parameter: 无 Return: Others: """ mit.Mit.__init__(self) self.regist_moc(NEDbSyncState.NEDbSyncState , NEDbSyncState.NEDbSyncStateRule) self.open_oracle(**db_cfg_info.get_configure(db_cfg_info.ORACLE_DEFAULT_CON_NAME)) self.init_mit_lock()
def call_expdp(tables, data_dir, timeout = 60*60): """ Function: call_expdp Description: 调用expdp命令 Parameter: tables: 需要导出的表(list) data_dir: 导出的数据所在的磁盘目录 timeout: 超时时间(秒) Return: 错误码 Others: 数据导出,使用了user_sync用户 """ # expdp user_acp/user_acp@orcl directory=db_sync_dir dumpfile=ne_mocs.dmp TABLES=user_acp.tbl_TestAntenna,user_acp.tbl_TestPhysicalReader parallel=3 job_name=dbsync CONTENT=DATA_ONLY # 导出前,先删除旧文件 dmp_file_path = os.path.join(data_dir , db_sync_common_const.DB_SYNC_FILE_NAME) try: if os.path.exists(dmp_file_path): os.remove(dmp_file_path) except: tracelog.exception("remove out of date file %s failed." % dmp_file_path) # 这里不返回,继续执行后面的导出 oracle_info = db_cfg_info.get_configure("oracle sync") conn_string = "%s/%s@%s" % (oracle_info["username"] , oracle_info["password"] , oracle_info["db"]) cmd_line = ["expdp" , conn_string , "DIRECTORY=db_sync_dir" , "DUMPFILE=%s" % db_sync_common_const.DB_SYNC_FILE_NAME , "TABLES=%s" % ",".join(tables) , "PARALLEL=3" , "CONTENT=DATA_ONLY"] log_file_path = os.path.join(data_dir, "export.log") ret = __call_oracle_cmd(cmd_line, timeout, log_file_path) return ret