Exemple #1
0
def failure(error_code=-1, reason=None, *args, **kwargs) -> dict:
    result = {
        CONST.STATUS: CONST.FAILURE,
        CONST.ERROR_CODE: error_code,
        CONST.REASON: reason
    }
    result.update(get_dict(*args, **kwargs))
    logger.error(result)
    return result
    def read_config(self):
        try:
            with open(self.local_config_path, 'r', encoding='utf-8') as f:
                cfg = f.read()
                self.__yaml_dict = yaml.load(cfg)
                self.__config_dict = self.__get_config_dict(self.__yaml_dict)
                self.__yaml_chain_info_list = self.__get_yaml_chain_info_list(
                    self.__yaml_dict)

        except Exception as e:
            logger.error("load local config failed")
            logger.error(e)
    def read_etcd_config_data(self):

        config_dict = dict()
        try:
            config_object = self.etcd_client.read('/{}'.format(
                CONST.SYSTEM_NAME),
                                                  recursive=True)
            for child in config_object.children:
                key_path = child.key
                key = key_path.split('/')[-1]
                value = child.value

                config_dict[key.upper()] = value

            return config_dict
        except Exception as e:
            logger.error('read_etcd_config_data error')
            logger.error(e)

        return config_dict
    def load_config_by_etcd(self, settings_server):
        while True:
            try:
                time.sleep(180)
                logger.debug('load ETCD config')

                etcd_wrapper_server = EtcdWrapper(
                    host=os.environ.get('ETCD_SERVICE_SERVICE_HOST',
                                        '127.0.0.1'),
                    port=int(
                        os.environ.get('ETCD_SERVICE_SERVICE_PORT', '2379')))
                # etcd_wrapper.connect_etcd_cluster()
                etcd_wrapper_server.connect_etcd_client()

                self.reset_etcd_config(etcd_wrapper_server)

                config_dict = etcd_wrapper_server.read_etcd_config_data()
                settings_server.generate_settings_file(config_dict)
                GLOBAL.set_settings(type("SETTING", (), config_dict))
                logger.debug('reload ETCD config success! ')

            except Exception as e:
                logger.error(e)
                time.sleep(5)
 def create_tables(self, Base):
     try:
         logger.info('creating sql tables.')
         Base.metadata.create_all(self.engine)
     except Exception as e:
         logger.error('create tables failed {}'.format(str(e)))