@@ -124,38 +124,23 @@ public Decision canAllocate(ShardRouting shardRouting, RoutingAllocation allocat
124124 enable = this .enableAllocation ;
125125 usedIndexSetting = false ;
126126 }
127- switch (enable ) {
128- case ALL :
129- return allocation .decision (Decision .YES , NAME , "all allocations are allowed" );
130- case NONE :
131- return allocation .decision (Decision .NO , NAME , "no allocations are allowed due to %s" , setting (enable , usedIndexSetting ));
132- case NEW_PRIMARIES :
133- if (shardRouting .primary ()
134- && shardRouting .active () == false
135- && shardRouting .recoverySource ().getType () != RecoverySource .Type .EXISTING_STORE ) {
136- return allocation .decision (Decision .YES , NAME , "new primary allocations are allowed" );
137- } else {
138- return allocation .decision (
127+ return switch (enable ) {
128+ case ALL -> allocation .decision (Decision .YES , NAME , "all allocations are allowed" );
129+ case NONE -> allocation .decision (Decision .NO , NAME , "no allocations are allowed due to %s" , setting (enable , usedIndexSetting ));
130+ case NEW_PRIMARIES -> (shardRouting .primary ()
131+ && shardRouting .active () == false
132+ && shardRouting .recoverySource ().getType () != RecoverySource .Type .EXISTING_STORE )
133+ ? allocation .decision (Decision .YES , NAME , "new primary allocations are allowed" )
134+ : allocation .decision (
139135 Decision .NO ,
140136 NAME ,
141137 "non-new primary allocations are forbidden due to %s" ,
142138 setting (enable , usedIndexSetting )
143139 );
144- }
145- case PRIMARIES :
146- if (shardRouting .primary ()) {
147- return allocation .decision (Decision .YES , NAME , "primary allocations are allowed" );
148- } else {
149- return allocation .decision (
150- Decision .NO ,
151- NAME ,
152- "replica allocations are forbidden due to %s" ,
153- setting (enable , usedIndexSetting )
154- );
155- }
156- default :
157- throw new IllegalStateException ("Unknown allocation option" );
158- }
140+ case PRIMARIES -> shardRouting .primary ()
141+ ? allocation .decision (Decision .YES , NAME , "primary allocations are allowed" )
142+ : allocation .decision (Decision .NO , NAME , "replica allocations are forbidden due to %s" , setting (enable , usedIndexSetting ));
143+ };
159144 }
160145
161146 @ Override
@@ -193,36 +178,16 @@ public Decision canRebalance(ShardRouting shardRouting, RoutingAllocation alloca
193178 enable = this .enableRebalance ;
194179 usedIndexSetting = false ;
195180 }
196- switch (enable ) {
197- case ALL :
198- return allocation .decision (Decision .YES , NAME , "all rebalancing is allowed" );
199- case NONE :
200- return allocation .decision (Decision .NO , NAME , "no rebalancing is allowed due to %s" , setting (enable , usedIndexSetting ));
201- case PRIMARIES :
202- if (shardRouting .primary ()) {
203- return allocation .decision (Decision .YES , NAME , "primary rebalancing is allowed" );
204- } else {
205- return allocation .decision (
206- Decision .NO ,
207- NAME ,
208- "replica rebalancing is forbidden due to %s" ,
209- setting (enable , usedIndexSetting )
210- );
211- }
212- case REPLICAS :
213- if (shardRouting .primary () == false ) {
214- return allocation .decision (Decision .YES , NAME , "replica rebalancing is allowed" );
215- } else {
216- return allocation .decision (
217- Decision .NO ,
218- NAME ,
219- "primary rebalancing is forbidden due to %s" ,
220- setting (enable , usedIndexSetting )
221- );
222- }
223- default :
224- throw new IllegalStateException ("Unknown rebalance option" );
225- }
181+ return switch (enable ) {
182+ case ALL -> allocation .decision (Decision .YES , NAME , "all rebalancing is allowed" );
183+ case NONE -> allocation .decision (Decision .NO , NAME , "no rebalancing is allowed due to %s" , setting (enable , usedIndexSetting ));
184+ case PRIMARIES -> shardRouting .primary ()
185+ ? allocation .decision (Decision .YES , NAME , "primary rebalancing is allowed" )
186+ : allocation .decision (Decision .NO , NAME , "replica rebalancing is forbidden due to %s" , setting (enable , usedIndexSetting ));
187+ case REPLICAS -> shardRouting .primary ()
188+ ? allocation .decision (Decision .NO , NAME , "primary rebalancing is forbidden due to %s" , setting (enable , usedIndexSetting ))
189+ : allocation .decision (Decision .YES , NAME , "replica rebalancing is allowed" );
190+ };
226191 }
227192
228193 private static String setting (Allocation allocation , boolean usedIndexSetting ) {
0 commit comments