9090public class ClusterModule extends AbstractModule {
9191
9292 public static final String BALANCED_ALLOCATOR = "balanced" ; // default
93- public static final Setting <String > SHARDS_ALLOCATOR_TYPE_SETTING =
94- new Setting <>("cluster.routing.allocation.type" , BALANCED_ALLOCATOR , Function .identity (), Property .NodeScope );
93+ public static final Setting <String > SHARDS_ALLOCATOR_TYPE_SETTING = new Setting <>(
94+ "cluster.routing.allocation.type" ,
95+ BALANCED_ALLOCATOR ,
96+ Function .identity (),
97+ Property .NodeScope
98+ );
9599
96100 private final ClusterService clusterService ;
97101 private final IndexNameExpressionResolver indexNameExpressionResolver ;
@@ -103,9 +107,15 @@ public class ClusterModule extends AbstractModule {
103107 final Collection <AllocationDecider > deciderList ;
104108 final ShardsAllocator shardsAllocator ;
105109
106- public ClusterModule (Settings settings , ClusterService clusterService , List <ClusterPlugin > clusterPlugins ,
107- ClusterInfoService clusterInfoService , SnapshotsInfoService snapshotsInfoService , ThreadContext threadContext ,
108- SystemIndices systemIndices ) {
110+ public ClusterModule (
111+ Settings settings ,
112+ ClusterService clusterService ,
113+ List <ClusterPlugin > clusterPlugins ,
114+ ClusterInfoService clusterInfoService ,
115+ SnapshotsInfoService snapshotsInfoService ,
116+ ThreadContext threadContext ,
117+ SystemIndices systemIndices
118+ ) {
109119 this .clusterPlugins = clusterPlugins ;
110120 this .deciderList = createAllocationDeciders (settings , clusterService .getClusterSettings (), clusterPlugins );
111121 this .allocationDeciders = new AllocationDeciders (deciderList );
@@ -121,23 +131,47 @@ public static List<Entry> getNamedWriteables() {
121131 // Cluster State
122132 registerClusterCustom (entries , SnapshotsInProgress .TYPE , SnapshotsInProgress ::new , SnapshotsInProgress ::readDiffFrom );
123133 registerClusterCustom (entries , RestoreInProgress .TYPE , RestoreInProgress ::new , RestoreInProgress ::readDiffFrom );
124- registerClusterCustom (entries , SnapshotDeletionsInProgress .TYPE , SnapshotDeletionsInProgress ::new ,
125- SnapshotDeletionsInProgress ::readDiffFrom );
126- registerClusterCustom (entries , RepositoryCleanupInProgress .TYPE , RepositoryCleanupInProgress ::new ,
127- RepositoryCleanupInProgress ::readDiffFrom );
128- registerClusterCustom (entries , SnapshotDeletionsPending .TYPE , SnapshotDeletionsPending ::new ,
129- SnapshotDeletionsPending ::readDiffFrom );
134+ registerClusterCustom (
135+ entries ,
136+ SnapshotDeletionsInProgress .TYPE ,
137+ SnapshotDeletionsInProgress ::new ,
138+ SnapshotDeletionsInProgress ::readDiffFrom
139+ );
140+ registerClusterCustom (
141+ entries ,
142+ RepositoryCleanupInProgress .TYPE ,
143+ RepositoryCleanupInProgress ::new ,
144+ RepositoryCleanupInProgress ::readDiffFrom
145+ );
146+ registerClusterCustom (
147+ entries ,
148+ SnapshotDeletionsPending .TYPE ,
149+ SnapshotDeletionsPending ::new ,
150+ SnapshotDeletionsPending ::readDiffFrom
151+ );
130152 // Metadata
131153 registerMetadataCustom (entries , RepositoriesMetadata .TYPE , RepositoriesMetadata ::new , RepositoriesMetadata ::readDiffFrom );
132154 registerMetadataCustom (entries , IngestMetadata .TYPE , IngestMetadata ::new , IngestMetadata ::readDiffFrom );
133155 registerMetadataCustom (entries , ScriptMetadata .TYPE , ScriptMetadata ::new , ScriptMetadata ::readDiffFrom );
134156 registerMetadataCustom (entries , IndexGraveyard .TYPE , IndexGraveyard ::new , IndexGraveyard ::readDiffFrom );
135- registerMetadataCustom (entries , PersistentTasksCustomMetadata .TYPE , PersistentTasksCustomMetadata ::new ,
136- PersistentTasksCustomMetadata ::readDiffFrom );
137- registerMetadataCustom (entries , ComponentTemplateMetadata .TYPE , ComponentTemplateMetadata ::new ,
138- ComponentTemplateMetadata ::readDiffFrom );
139- registerMetadataCustom (entries , ComposableIndexTemplateMetadata .TYPE , ComposableIndexTemplateMetadata ::new ,
140- ComposableIndexTemplateMetadata ::readDiffFrom );
157+ registerMetadataCustom (
158+ entries ,
159+ PersistentTasksCustomMetadata .TYPE ,
160+ PersistentTasksCustomMetadata ::new ,
161+ PersistentTasksCustomMetadata ::readDiffFrom
162+ );
163+ registerMetadataCustom (
164+ entries ,
165+ ComponentTemplateMetadata .TYPE ,
166+ ComponentTemplateMetadata ::new ,
167+ ComponentTemplateMetadata ::readDiffFrom
168+ );
169+ registerMetadataCustom (
170+ entries ,
171+ ComposableIndexTemplateMetadata .TYPE ,
172+ ComposableIndexTemplateMetadata ::new ,
173+ ComposableIndexTemplateMetadata ::readDiffFrom
174+ );
141175 registerMetadataCustom (entries , DataStreamMetadata .TYPE , DataStreamMetadata ::new , DataStreamMetadata ::readDiffFrom );
142176 registerMetadataCustom (entries , NodesShutdownMetadata .TYPE , NodesShutdownMetadata ::new , NodesShutdownMetadata ::readDiffFrom );
143177
@@ -149,39 +183,85 @@ public static List<Entry> getNamedWriteables() {
149183 public static List <NamedXContentRegistry .Entry > getNamedXWriteables () {
150184 List <NamedXContentRegistry .Entry > entries = new ArrayList <>();
151185 // Metadata
152- entries .add (new NamedXContentRegistry .Entry (Metadata .Custom .class , new ParseField (RepositoriesMetadata .TYPE ),
153- RepositoriesMetadata ::fromXContent ));
154- entries .add (new NamedXContentRegistry .Entry (Metadata .Custom .class , new ParseField (IngestMetadata .TYPE ),
155- IngestMetadata ::fromXContent ));
156- entries .add (new NamedXContentRegistry .Entry (Metadata .Custom .class , new ParseField (ScriptMetadata .TYPE ),
157- ScriptMetadata ::fromXContent ));
158- entries .add (new NamedXContentRegistry .Entry (Metadata .Custom .class , new ParseField (IndexGraveyard .TYPE ),
159- IndexGraveyard ::fromXContent ));
160- entries .add (new NamedXContentRegistry .Entry (Metadata .Custom .class , new ParseField (PersistentTasksCustomMetadata .TYPE ),
161- PersistentTasksCustomMetadata ::fromXContent ));
162- entries .add (new NamedXContentRegistry .Entry (Metadata .Custom .class , new ParseField (ComponentTemplateMetadata .TYPE ),
163- ComponentTemplateMetadata ::fromXContent ));
164- entries .add (new NamedXContentRegistry .Entry (Metadata .Custom .class , new ParseField (ComposableIndexTemplateMetadata .TYPE ),
165- ComposableIndexTemplateMetadata ::fromXContent ));
166- entries .add (new NamedXContentRegistry .Entry (Metadata .Custom .class , new ParseField (DataStreamMetadata .TYPE ),
167- DataStreamMetadata ::fromXContent ));
168- entries .add (new NamedXContentRegistry .Entry (Metadata .Custom .class , new ParseField (NodesShutdownMetadata .TYPE ),
169- NodesShutdownMetadata ::fromXContent ));
186+ entries .add (
187+ new NamedXContentRegistry .Entry (
188+ Metadata .Custom .class ,
189+ new ParseField (RepositoriesMetadata .TYPE ),
190+ RepositoriesMetadata ::fromXContent
191+ )
192+ );
193+ entries .add (
194+ new NamedXContentRegistry .Entry (Metadata .Custom .class , new ParseField (IngestMetadata .TYPE ), IngestMetadata ::fromXContent )
195+ );
196+ entries .add (
197+ new NamedXContentRegistry .Entry (Metadata .Custom .class , new ParseField (ScriptMetadata .TYPE ), ScriptMetadata ::fromXContent )
198+ );
199+ entries .add (
200+ new NamedXContentRegistry .Entry (Metadata .Custom .class , new ParseField (IndexGraveyard .TYPE ), IndexGraveyard ::fromXContent )
201+ );
202+ entries .add (
203+ new NamedXContentRegistry .Entry (
204+ Metadata .Custom .class ,
205+ new ParseField (PersistentTasksCustomMetadata .TYPE ),
206+ PersistentTasksCustomMetadata ::fromXContent
207+ )
208+ );
209+ entries .add (
210+ new NamedXContentRegistry .Entry (
211+ Metadata .Custom .class ,
212+ new ParseField (ComponentTemplateMetadata .TYPE ),
213+ ComponentTemplateMetadata ::fromXContent
214+ )
215+ );
216+ entries .add (
217+ new NamedXContentRegistry .Entry (
218+ Metadata .Custom .class ,
219+ new ParseField (ComposableIndexTemplateMetadata .TYPE ),
220+ ComposableIndexTemplateMetadata ::fromXContent
221+ )
222+ );
223+ entries .add (
224+ new NamedXContentRegistry .Entry (
225+ Metadata .Custom .class ,
226+ new ParseField (DataStreamMetadata .TYPE ),
227+ DataStreamMetadata ::fromXContent
228+ )
229+ );
230+ entries .add (
231+ new NamedXContentRegistry .Entry (
232+ Metadata .Custom .class ,
233+ new ParseField (NodesShutdownMetadata .TYPE ),
234+ NodesShutdownMetadata ::fromXContent
235+ )
236+ );
170237 return entries ;
171238 }
172239
173- private static <T extends ClusterState .Custom > void registerClusterCustom (List <Entry > entries , String name , Reader <? extends T > reader ,
174- Reader <NamedDiff <?>> diffReader ) {
240+ private static <T extends ClusterState .Custom > void registerClusterCustom (
241+ List <Entry > entries ,
242+ String name ,
243+ Reader <? extends T > reader ,
244+ Reader <NamedDiff <?>> diffReader
245+ ) {
175246 registerCustom (entries , ClusterState .Custom .class , name , reader , diffReader );
176247 }
177248
178- private static <T extends Metadata .Custom > void registerMetadataCustom (List <Entry > entries , String name , Reader <? extends T > reader ,
179- Reader <NamedDiff <?>> diffReader ) {
249+ private static <T extends Metadata .Custom > void registerMetadataCustom (
250+ List <Entry > entries ,
251+ String name ,
252+ Reader <? extends T > reader ,
253+ Reader <NamedDiff <?>> diffReader
254+ ) {
180255 registerCustom (entries , Metadata .Custom .class , name , reader , diffReader );
181256 }
182257
183- private static <T extends NamedWriteable > void registerCustom (List <Entry > entries , Class <T > category , String name ,
184- Reader <? extends T > reader , Reader <NamedDiff <?>> diffReader ) {
258+ private static <T extends NamedWriteable > void registerCustom (
259+ List <Entry > entries ,
260+ Class <T > category ,
261+ String name ,
262+ Reader <? extends T > reader ,
263+ Reader <NamedDiff <?>> diffReader
264+ ) {
185265 entries .add (new Entry (category , name , reader ));
186266 entries .add (new Entry (NamedDiff .class , name , diffReader ));
187267 }
@@ -192,8 +272,11 @@ public IndexNameExpressionResolver getIndexNameExpressionResolver() {
192272
193273 // TODO: this is public so allocation benchmark can access the default deciders...can we do that in another way?
194274 /** Return a new {@link AllocationDecider} instance with builtin deciders as well as those from plugins. */
195- public static Collection <AllocationDecider > createAllocationDeciders (Settings settings , ClusterSettings clusterSettings ,
196- List <ClusterPlugin > clusterPlugins ) {
275+ public static Collection <AllocationDecider > createAllocationDeciders (
276+ Settings settings ,
277+ ClusterSettings clusterSettings ,
278+ List <ClusterPlugin > clusterPlugins
279+ ) {
197280 // collect deciders by class so that we can detect duplicates
198281 Map <Class <?>, AllocationDecider > deciders = new LinkedHashMap <>();
199282 addAllocationDecider (deciders , new MaxRetryAllocationDecider ());
@@ -229,8 +312,11 @@ private static void addAllocationDecider(Map<Class<?>, AllocationDecider> decide
229312 }
230313 }
231314
232- private static ShardsAllocator createShardsAllocator (Settings settings , ClusterSettings clusterSettings ,
233- List <ClusterPlugin > clusterPlugins ) {
315+ private static ShardsAllocator createShardsAllocator (
316+ Settings settings ,
317+ ClusterSettings clusterSettings ,
318+ List <ClusterPlugin > clusterPlugins
319+ ) {
234320 Map <String , Supplier <ShardsAllocator >> allocators = new HashMap <>();
235321 allocators .put (BALANCED_ALLOCATOR , () -> new BalancedShardsAllocator (settings , clusterSettings ));
236322
@@ -246,8 +332,7 @@ private static ShardsAllocator createShardsAllocator(Settings settings, ClusterS
246332 if (allocatorSupplier == null ) {
247333 throw new IllegalArgumentException ("Unknown ShardsAllocator [" + allocatorName + "]" );
248334 }
249- return Objects .requireNonNull (allocatorSupplier .get (),
250- "ShardsAllocator factory for [" + allocatorName + "] returned null" );
335+ return Objects .requireNonNull (allocatorSupplier .get (), "ShardsAllocator factory for [" + allocatorName + "] returned null" );
251336 }
252337
253338 public AllocationService getAllocationService () {
@@ -284,12 +369,17 @@ public void setExistingShardsAllocators(GatewayAllocator gatewayAllocator) {
284369 existingShardsAllocators .put (GatewayAllocator .ALLOCATOR_NAME , gatewayAllocator );
285370
286371 for (ClusterPlugin clusterPlugin : clusterPlugins ) {
287- for (Map .Entry <String , ExistingShardsAllocator > existingShardsAllocatorEntry
288- : clusterPlugin . getExistingShardsAllocators () .entrySet ()) {
372+ for (Map .Entry <String , ExistingShardsAllocator > existingShardsAllocatorEntry : clusterPlugin . getExistingShardsAllocators ()
373+ .entrySet ()) {
289374 final String allocatorName = existingShardsAllocatorEntry .getKey ();
290375 if (existingShardsAllocators .put (allocatorName , existingShardsAllocatorEntry .getValue ()) != null ) {
291- throw new IllegalArgumentException ("ExistingShardsAllocator [" + allocatorName + "] from [" +
292- clusterPlugin .getClass ().getName () + "] was already defined" );
376+ throw new IllegalArgumentException (
377+ "ExistingShardsAllocator ["
378+ + allocatorName
379+ + "] from ["
380+ + clusterPlugin .getClass ().getName ()
381+ + "] was already defined"
382+ );
293383 }
294384 }
295385 }
0 commit comments