def test_internal_index_name_return_valid_values(sm_config): es_config = sm_config['elasticsearch'] alias = es_config['index'] es_man = ESIndexManager(es_config) assert es_man.internal_index_name(alias) in [ '{}-yin'.format(alias), '{}-yang'.format(alias) ]
def get_inactive_index_es_config(es_config): es_man = ESIndexManager(es_config) old_index = es_man.internal_index_name(es_config['index']) new_index = es_man.another_index_name(old_index) tmp_es_config = deepcopy(es_config) tmp_es_config['index'] = new_index return tmp_es_config
def _reindex_all(conf): es_config = conf['elasticsearch'] alias = es_config['index'] es_man = ESIndexManager(es_config) new_index = es_man.another_index_name(es_man.internal_index_name(alias)) es_man.create_index(new_index) try: tmp_es_config = deepcopy(es_config) tmp_es_config['index'] = new_index db = DB(conf['db']) es_exp = ESExporter(db, tmp_es_config) rows = db.select('select id, name, config from dataset') _reindex_datasets(rows, es_exp) es_man.remap_alias(tmp_es_config['index'], alias=alias) except Exception as e: es_man.delete_index(new_index) raise e
def sm_index(sm_config, request): es_config = sm_config['elasticsearch'] es_man = ESIndexManager(es_config) es_man.delete_index(es_config['index']) es_man.create_index(es_config['index']) def fin(): es_man = ESIndexManager(es_config) es_man.delete_index(sm_config['elasticsearch']['index']) request.addfinalizer(fin)
help='Delete existing index if exists') swap_subparser = subparsers.add_parser( 'swap', help='Swap the active and inactive indexes') drop_subparser = subparsers.add_parser( 'drop', help='Drop the index. Can only be used on the inactive index') status_subparser = subparsers.add_parser('status', help='Show current index mapping') args = parser.parse_args() SMConfig.set_path(args.config_path) init_loggers(SMConfig.get_conf()['logs']) es_config = SMConfig.get_conf()['elasticsearch'] es_man = ESIndexManager(es_config) alias = es_config['index'] active_index = es_man.internal_index_name(alias) inactive_index = es_man.another_index_name(active_index) index = inactive_index if args.inactive else active_index if args.action == 'create': if args.drop: es_man.delete_index(index) es_man.create_index(index) if not args.inactive: es_man.remap_alias(index, alias) elif args.action == 'swap': es_man.remap_alias(inactive_index, alias) elif args.action == 'drop': assert args.inactive, 'drop must be used with --inactive '
def test_rename_index_works(test_db, sm_config): es_config = sm_config['elasticsearch'] alias = es_config['index'] es_man = ESIndexManager(es_config) es_man.create_index('{}-yin'.format(alias)) es_man.remap_alias('{}-yin'.format(alias), alias=alias) assert es_man.exists_index(alias) assert es_man.exists_index('{}-yin'.format(alias)) assert not es_man.exists_index('{}-yang'.format(alias)) es_man.create_index('{}-yang'.format(alias)) es_man.remap_alias('{}-yang'.format(alias), alias=alias) assert es_man.exists_index(alias) assert es_man.exists_index('{}-yang'.format(alias)) assert not es_man.exists_index('{}-yin'.format(alias))
def fin(): es_man = ESIndexManager(es_config) es_man.delete_index(sm_config['elasticsearch']['index'])
def test_internal_index_name_return_valid_values(sm_config): es_config = sm_config['elasticsearch'] alias = es_config['index'] es_man = ESIndexManager(es_config) assert es_man.internal_index_name(alias) in ['{}-yin'.format(alias), '{}-yang'.format(alias)]
def test_rename_index_works(test_db, sm_config): es_config = sm_config['elasticsearch'] alias = es_config['index'] es_man = ESIndexManager(es_config) es_man.create_index('{}-yin'.format(alias)) es_man.remap_alias('{}-yin'.format(alias), alias=alias) assert es_man.exists_index(alias) assert es_man.exists_index('{}-yin'.format(alias)) assert not es_man.exists_index('{}-yang'.format(alias)) es_man.create_index('{}-yang'.format(alias)) es_man.remap_alias('{}-yang'.format(alias), alias=alias) assert es_man.exists_index(alias) assert es_man.exists_index('{}-yang'.format(alias)) assert not es_man.exists_index('{}-yin'.format(alias))
def test_rename_index_works(sm_config, test_db): es_config = sm_config['elasticsearch'] alias = es_config['index'] yin_index = f'{alias}-yin' yang_index = f'{alias}-yang' es_man = ESIndexManager(es_config) # Clean up previous test runs if needed es_man.delete_index(alias) es_man.delete_index(yin_index) es_man.delete_index(yang_index) try: es_man.create_index(yin_index) es_man.remap_alias(yin_index, alias=alias) assert es_man.exists_index(alias) assert es_man.exists_index(yin_index) assert not es_man.exists_index(yang_index) es_man.create_index(yang_index) es_man.remap_alias(yang_index, alias=alias) assert es_man.exists_index(alias) assert es_man.exists_index(yang_index) assert es_man.exists_index(yin_index) finally: es_man.delete_index(alias) es_man.delete_index(yin_index) es_man.delete_index(yang_index)
def _reindex_all(sm_config): es_config = sm_config['elasticsearch'] alias = es_config['index'] es_man = ESIndexManager(es_config) old_index = es_man.internal_index_name(alias) new_index = es_man.another_index_name(old_index) es_man.create_index(new_index) try: inactive_es_config = get_inactive_index_es_config(es_config) db = DB() es_exp = ESExporter(db, { **sm_config, 'elasticsearch': inactive_es_config }) ds_ids = [r[0] for r in db.select('select id from dataset')] _reindex_datasets(ds_ids, es_exp) es_man.remap_alias(inactive_es_config['index'], alias=alias) except Exception as e: es_man.delete_index(new_index) raise e else: es_man.delete_index(old_index)