Skip to content

Commit

Permalink
Update set alias
Browse files Browse the repository at this point in the history
  • Loading branch information
muhammadali286 committed Jun 3, 2024
1 parent 6478189 commit 3d4b416
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -119,13 +119,16 @@ def handle(self, *args, **kwargs):
style = self.style.SUCCESS if result else self.style.ERROR
logger.info(style(f'All required mappings present: {result}'))

if not result:
return False

try:
self.set_alias(file_path.split('/')[-1])
except Exception as e:
logger.info(self.style.ERROR(f'Unable to update aliases'))
logger.info(self.style.ERROR(f'Alias are updated to given index: False'))
raise CommandError(f'ERROR exceptio : {e}')

logger.info(style(f'Alias are updated to given index'))
logger.info(style(f'Alias are updated to given index: True'))


def check_mappings(self, catalog_data, required_mappings):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,14 @@ def add_arguments(self, parser):
help='Disables checks limiting the number of records modified.'
)

parser.add_argument(
"-na",
"--no-update-alias",
action="store_false",
dest="update_alias_disabled",
help="Update aliases after creating new index.",
)

def get_record_count(self, conn, index_name):
return conn.count(index_name).get('count')

Expand Down Expand Up @@ -52,15 +60,21 @@ def handle(self, **options):
for backend, index, alias, record_count in alias_mappings:
# Run a sanity check to ensure we aren't drastically changing the
# index, which could be indicative of a bug.
update_alias_disabled = options.get('update_alias_disabled')

if index in indexes_pending and not options.get('disable_change_limit', False):
record_count_is_sane, index_info_string = self.sanity_check_new_index(
backend.conn, index, record_count
)
if not record_count_is_sane:
indexes_pending[index] = index_info_string
else:
if record_count_is_sane:
if not update_alias_disabled:
self.set_alias(backend, alias, index)
indexes_pending.pop(index, None)
else:
indexes_pending[index] = index_info_string
else:
if not update_alias_disabled:
self.set_alias(backend, alias, index)
indexes_pending.pop(index, None)

if indexes_pending:
Expand Down

0 comments on commit 3d4b416

Please sign in to comment.