1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174
|
"""Shrink Index Singleton"""
import click
from curator.cli_singletons.object_class import CLIAction
from curator.cli_singletons.utils import json_to_dict, validate_filter_json
# pylint: disable=line-too-long
@click.command()
@click.option(
'--search_pattern', type=str, default='*', help='Elasticsearch Index Search Pattern'
)
@click.option(
'--shrink_node',
default='DETERMINISTIC',
type=str,
help='Named node, or DETERMINISTIC',
show_default=True,
)
@click.option(
'--node_filters',
help='JSON version of node_filters (see documentation)',
callback=json_to_dict,
)
@click.option(
'--number_of_shards',
default=1,
type=int,
help='Shrink to this many shards per index',
)
@click.option(
'--number_of_replicas',
default=1,
type=int,
help='Number of replicas for the target index',
show_default=True,
)
@click.option('--shrink_prefix', type=str, help='Prefix for the target index name')
@click.option(
'--shrink_suffix',
default='-shrink',
type=str,
help='Suffix for the target index name',
show_default=True,
)
@click.option(
'--copy_aliases',
is_flag=True,
help='Copy each source index aliases to target index',
)
@click.option(
'--delete_after/--no-delete_after',
default=True,
help='Delete source index after shrink',
show_default=True,
)
@click.option(
'--post_allocation',
help='JSON version of post_allocation (see documentation)',
callback=json_to_dict,
)
@click.option(
'--extra_settings',
help='JSON version of extra_settings (see documentation)',
callback=json_to_dict,
)
@click.option(
'--wait_for_active_shards',
default=1,
type=int,
help='Wait for number of active shards before continuing',
)
@click.option(
'--wait_for_rebalance/--no-wait_for_rebalance',
default=True,
help='Wait for rebalance to complete',
)
@click.option(
'--wait_for_completion/--no-wait_for_completion',
default=True,
help='Wait for the shrink to complete',
)
@click.option(
'--wait_interval',
default=9,
type=int,
help='Seconds to wait between completion checks.',
)
@click.option(
'--max_wait',
default=-1,
type=int,
help='Maximum number of seconds to wait_for_completion',
)
@click.option(
'--ignore_empty_list',
is_flag=True,
help='Do not raise exception if there are no actionable indices',
)
@click.option(
'--allow_ilm_indices/--no-allow_ilm_indices',
help='Allow Curator to operate on Index Lifecycle Management monitored indices.',
default=False,
show_default=True,
)
@click.option(
'--include_hidden/--no-include_hidden',
help='Allow Curator to operate on hidden indices (and data_streams).',
default=False,
show_default=True,
)
@click.option(
'--filter_list',
callback=validate_filter_json,
help='JSON array of filters selecting indices to act on.',
required=True,
)
@click.pass_context
def shrink(
ctx,
search_pattern,
shrink_node,
node_filters,
number_of_shards,
number_of_replicas,
shrink_prefix,
shrink_suffix,
copy_aliases,
delete_after,
post_allocation,
extra_settings,
wait_for_active_shards,
wait_for_rebalance,
wait_for_completion,
wait_interval,
max_wait,
ignore_empty_list,
allow_ilm_indices,
include_hidden,
filter_list,
):
"""
Shrink Indices to --number_of_shards
"""
manual_options = {
'search_pattern': search_pattern,
'shrink_node': shrink_node,
'node_filters': node_filters,
'number_of_shards': number_of_shards,
'number_of_replicas': number_of_replicas,
'shrink_prefix': shrink_prefix,
'shrink_suffix': shrink_suffix,
'copy_aliases': copy_aliases,
'delete_after': delete_after,
'post_allocation': post_allocation,
'extra_settings': extra_settings,
'wait_for_active_shards': wait_for_active_shards,
'wait_for_rebalance': wait_for_rebalance,
'wait_for_completion': wait_for_completion,
'wait_interval': wait_interval,
'max_wait': max_wait,
'allow_ilm_indices': allow_ilm_indices,
'include_hidden': include_hidden,
}
# ctx.info_name is the name of the function or name specified in
# @click.command decorator
action = CLIAction(
ctx.info_name,
ctx.obj['configdict'],
manual_options,
filter_list,
ignore_empty_list,
)
action.do_singleton_action(dry_run=ctx.obj['dry_run'])
|