def start_service(name, service_name, ip, port, config, config_type): print('数据节点[%s]正在 bind service ......' % service_name) ret = dsif.bindService(ip, port, service_name, name) if eval(str(ret)) == 1: print('数据节点[%s] bind service 成功.' % service_name) # bind config print('数据节点[%s]正在 bind config ......' % service_name) ret = dsif.bindConfig(name, config_type, config, 'bind_config') if eval(str(ret)) == 1: print('数据节点[%s] bind config 成功.' % service_name) print('数据节点[%s]正在 start ......' % service_name) ret = dsif.start(name, 'bind_config') if eval(str(ret)) == 1: print('数据节点[%s] start 成功.' % service_name) return 1 else: print('数据节点[%s] start 失败(%s).' % (service_name, ret)) return -1 else: print('数据节点[%s] bind config 失败(%s).' % (service_name, ret)) return -1 else: print('数据节点[%s] bind service 失败(%s).' % (service_name, ret)) return -1
def start_node(path, name, ip, port, node_name, config, config_type): global g_process ''' 启动数据节点,并start和bind config ''' try: is_start = False print('正在启动[%s]......' % path) p = run_app(path) if p: print('启动[%s]成功.' % path) g_process[name] = p # bind service print('数据节点[%s]正在 bind service ......' % node_name) ret = dsif.bindService(ip, port, node_name, name) if eval(str(ret)) == 1: print('数据节点[%s] bind service 成功.' % node_name) # bind config print('数据节点[%s]正在 bind config ......' % node_name) ret = dsif.bindConfig(name, config_type, config, 'bind_config') print('bindconfig-----------type(ret):', type(ret)) if eval(str(ret)) == 1: print('数据节点[%s] bind config 成功.' % node_name) print('数据节点[%s]正在 start ......' % node_name) ret = dsif.start(name, 'bind_config') if eval(str(ret)) == 1: print('数据节点[%s] start 成功.' % node_name) is_start = True else: print('数据节点[%s] start 失败(%s).' % (node_name, ret)) else: print('数据节点[%s] bind config 失败(%s).' % (node_name, ret)) else: print('数据节点[%s] bind service 失败(%s).' % (node_name, ret)) if not is_start: stop_app(name) else: print('启动[%s]失败.' % path) return is_start except Exception as e: print('启动[%s]失败,原因:%s.' % (path, repr(e)))
config = pb_config_rtds.pb_config_rtds() config.rtds_id = 1 config.update_cycle = 5 data1 = config.tag_infors.add() data1.name = '10001' data2 = config.tag_infors.add() data2.name = '10002' data3 = config.tag_infors.add() data3.name = 'tag3' ret = dsif.bindConfig('rtds', 'pb_config_rtds', config, 'rtds_01') print('bindConfig return:', ret) print('%s bindConfig over %s' % ('-' * number, '-' * number)) #------------------------------------------------------------ ret = dsif.start('rtds', 'rtds_01') print('start return:', ret) print('%s start over %s' % ('-' * number, '-' * number)) time.sleep(3) #------------------------------------------------------------ ret = dsif.stop('rtds', 'rtds_01') print('stop return:', ret) print('%s stop over %s' % ('-' * number, '-' * number)) #------------------------------------------------------------ ret = dsif.start('rtds', 'rtds_01') print('start return:', ret) print('%s start over %s' % ('-' * number, '-' * number)) #------------------------------------------------------------
config.port = 27017 config.user_name = 'root' config.user_password = '******' config.cycle = 5 config.database_name = 'Configs' config.collection_name = 'config' config.field_name = 'config_key' # config.search_key_list.append('config_opc_01') ret = dsif.bindConfig('s_mongodb_service', 'pb_config_mongodb', config, 'config_name_01') print('bindConfig return:', ret) print('%s bindConfig over %s' % ('-' * number, '-' * number)) #------------------------------------------------------------ ret = dsif.start('s_mongodb_service', 'config_name_01') print('start return:', ret) print('%s start over %s' % ('-' * number, '-' * number)) #------------------------------------------------------------ import pb_data_mongodb import pb_data_opcalarm_list import pb_data_opcalarm pdol = pb_data_opcalarm_list.pb_data_opcalarm_list() pdol.list_id = 1 count = 1 while count <= 600: pdo = pdol.pb_data_opcalarms.add() pdo.opcalarm_data_id = count pdo.is_publish = False pdo.event_type = pb_data_opcalarm.OPC_CONDITION_EVENT