Coverage for curator/cli_singletons/shrink.py: 100%
27 statements
« prev ^ index » next coverage.py v7.3.0, created at 2023-08-16 15:27 -0600
« prev ^ index » next coverage.py v7.3.0, created at 2023-08-16 15:27 -0600
1"""Shrink Index Singleton"""
2import click
3from curator.cli_singletons.object_class import cli_action
4from curator.cli_singletons.utils import get_width, json_to_dict, validate_filter_json
6@click.command(context_settings=get_width())
7@click.option(
8 '--shrink_node',
9 default='DETERMINISTIC',
10 type=str,
11 help='Named node, or DETERMINISTIC',
12 show_default=True
13)
14@click.option(
15 '--node_filters',
16 help='JSON version of node_filters (see documentation)',
17 callback=json_to_dict
18)
19@click.option(
20 '--number_of_shards',
21 default=1,
22 type=int,
23 help='Shrink to this many shards per index'
24)
25@click.option(
26 '--number_of_replicas',
27 default=1,
28 type=int,
29 help='Number of replicas for the target index',
30 show_default=True
31)
32@click.option(
33 '--shrink_prefix',
34 type=str,
35 help='Prefix for the target index name'
36)
37@click.option(
38 '--shrink_suffix',
39 default='-shrink',
40 type=str,
41 help='Suffix for the target index name',
42 show_default=True
43)
44@click.option(
45 '--copy_aliases',
46 is_flag=True,
47 help='Copy each source index aliases to target index'
48)
49@click.option(
50 '--delete_after/--no-delete_after',
51 default=True,
52 help='Delete source index after shrink',
53 show_default=True
54)
55@click.option(
56 '--post_allocation',
57 help='JSON version of post_allocation (see documentation)',
58 callback=json_to_dict
59)
60@click.option(
61 '--extra_settings',
62 help='JSON version of extra_settings (see documentation)',
63 callback=json_to_dict
64)
65@click.option(
66 '--wait_for_active_shards',
67 default=1,
68 type=int,
69 help='Wait for number of active shards before continuing'
70)
71@click.option(
72 '--wait_for_rebalance/--no-wait_for_rebalance',
73 default=True,
74 help='Wait for rebalance to complete'
75)
76@click.option(
77 '--wait_for_completion/--no-wait_for_completion',
78 default=True,
79 help='Wait for the shrink to complete'
80)
81@click.option(
82 '--wait_interval',
83 default=9,
84 type=int,
85 help='Seconds to wait between completion checks.'
86)
87@click.option(
88 '--max_wait',
89 default=-1,
90 type=int,
91 help='Maximum number of seconds to wait_for_completion'
92)
93@click.option(
94 '--ignore_empty_list',
95 is_flag=True,
96 help='Do not raise exception if there are no actionable indices'
97)
98@click.option(
99 '--allow_ilm_indices/--no-allow_ilm_indices',
100 help='Allow Curator to operate on Index Lifecycle Management monitored indices.',
101 default=False,
102 show_default=True
103)
104@click.option(
105 '--filter_list',
106 callback=validate_filter_json,
107 help='JSON array of filters selecting indices to act on.',
108 required=True
109)
110@click.pass_context
111def shrink(
112 ctx, shrink_node, node_filters, number_of_shards, number_of_replicas, shrink_prefix,
113 shrink_suffix, copy_aliases, delete_after, post_allocation, extra_settings,
114 wait_for_active_shards, wait_for_rebalance, wait_for_completion, wait_interval, max_wait,
115 ignore_empty_list, allow_ilm_indices, filter_list
116 ):
117 """
118 Shrink Indices to --number_of_shards
119 """
120 manual_options = {
121 'shrink_node': shrink_node,
122 'node_filters': node_filters,
123 'number_of_shards': number_of_shards,
124 'number_of_replicas': number_of_replicas,
125 'shrink_prefix': shrink_prefix,
126 'shrink_suffix': shrink_suffix,
127 'copy_aliases': copy_aliases,
128 'delete_after': delete_after,
129 'post_allocation': post_allocation,
130 'extra_settings': extra_settings,
131 'wait_for_active_shards': wait_for_active_shards,
132 'wait_for_rebalance': wait_for_rebalance,
133 'wait_for_completion': wait_for_completion,
134 'wait_interval': wait_interval,
135 'max_wait': max_wait,
136 'allow_ilm_indices': allow_ilm_indices,
137 }
138 # ctx.info_name is the name of the function or name specified in @click.command decorator
139 action = cli_action(
140 ctx.info_name, ctx.obj['config']['client'], manual_options, filter_list, ignore_empty_list)
141 action.do_singleton_action(dry_run=ctx.obj['dry_run'])