1414import org .elasticsearch .action .support .ActionFilter ;
1515import org .elasticsearch .action .support .TransportAction ;
1616import org .elasticsearch .client .internal .Client ;
17- import org .elasticsearch .cluster .ClusterState ;
1817import org .elasticsearch .cluster .metadata .IndexNameExpressionResolver ;
19- import org .elasticsearch .cluster .metadata .Metadata ;
2018import org .elasticsearch .cluster .node .DiscoveryNode ;
2119import org .elasticsearch .cluster .node .DiscoveryNodes ;
2220import org .elasticsearch .cluster .routing .allocation .AllocationService ;
3331import org .elasticsearch .common .settings .SettingsFilter ;
3432import org .elasticsearch .common .ssl .SslConfiguration ;
3533import org .elasticsearch .common .util .BigArrays ;
36- import org .elasticsearch .core .Booleans ;
3734import org .elasticsearch .env .Environment ;
3835import org .elasticsearch .env .NodeEnvironment ;
3936import org .elasticsearch .index .IndexSettingProvider ;
4239import org .elasticsearch .index .mapper .MetadataFieldMapper ;
4340import org .elasticsearch .indices .recovery .RecoverySettings ;
4441import org .elasticsearch .license .LicenseService ;
45- import org .elasticsearch .license .LicensesMetadata ;
4642import org .elasticsearch .license .Licensing ;
4743import org .elasticsearch .license .XPackLicenseState ;
4844import org .elasticsearch .plugins .ClusterPlugin ;
7874import org .elasticsearch .xpack .core .action .XPackUsageResponse ;
7975import org .elasticsearch .xpack .core .async .DeleteAsyncResultAction ;
8076import org .elasticsearch .xpack .core .async .TransportDeleteAsyncResultAction ;
81- import org .elasticsearch .xpack .core .ml .MlMetadata ;
8277import org .elasticsearch .xpack .core .rest .action .RestReloadAnalyzersAction ;
8378import org .elasticsearch .xpack .core .rest .action .RestXPackInfoAction ;
8479import org .elasticsearch .xpack .core .rest .action .RestXPackUsageAction ;
85- import org .elasticsearch .xpack .core .security .authc .TokenMetadata ;
8680import org .elasticsearch .xpack .core .ssl .SSLConfigurationReloader ;
8781import org .elasticsearch .xpack .core .ssl .SSLService ;
8882import org .elasticsearch .xpack .core .termsenum .action .TermsEnumAction ;
8983import org .elasticsearch .xpack .core .termsenum .action .TransportTermsEnumAction ;
9084import org .elasticsearch .xpack .core .termsenum .rest .RestTermsEnumAction ;
91- import org .elasticsearch .xpack .core .transform .TransformMetadata ;
92- import org .elasticsearch .xpack .core .watcher .WatcherMetadata ;
9385
9486import java .nio .file .Files ;
9587import java .nio .file .Path ;
10496import java .util .Optional ;
10597import java .util .function .LongSupplier ;
10698import java .util .function .Supplier ;
107- import java .util .stream .Collectors ;
10899
109100@ SuppressWarnings ("HiddenField" )
110101public class XPackPlugin extends XPackClientPlugin
@@ -117,7 +108,6 @@ public class XPackPlugin extends XPackClientPlugin
117108 private static final DeprecationLogger deprecationLogger = DeprecationLogger .getLogger (XPackPlugin .class );
118109
119110 public static final String ASYNC_RESULTS_INDEX = ".async-search" ;
120- public static final String XPACK_INSTALLED_NODE_ATTR = "xpack.installed" ;
121111
122112 // TODO: clean up this library to not ask for write access to all system properties!
123113 static {
@@ -227,72 +217,11 @@ public static LongSupplier getSharedEpochMillisSupplier() {
227217 return epochMillisSupplier .get ();
228218 }
229219
230- /**
231- * Checks if the cluster state allows this node to add x-pack metadata to the cluster state,
232- * and throws an exception otherwise.
233- * This check should be called before installing any x-pack metadata to the cluster state,
234- * to ensure that the other nodes that are part of the cluster will be able to deserialize
235- * that metadata. Note that if the cluster state already contains x-pack metadata, this
236- * check assumes that the nodes are already ready to receive additional x-pack metadata.
237- * Having this check properly in place everywhere allows to install x-pack into a cluster
238- * using a rolling restart.
239- */
240- public static void checkReadyForXPackCustomMetadata (ClusterState clusterState ) {
241- if (alreadyContainsXPackCustomMetadata (clusterState )) {
242- return ;
243- }
244- List <DiscoveryNode > notReadyNodes = nodesNotReadyForXPackCustomMetadata (clusterState );
245- if (notReadyNodes .isEmpty () == false ) {
246- throw new IllegalStateException ("The following nodes are not ready yet for enabling x-pack custom metadata: " + notReadyNodes );
247- }
248- }
249-
250- /**
251- * Checks if the cluster state allows this node to add x-pack metadata to the cluster state.
252- * See {@link #checkReadyForXPackCustomMetadata} for more details.
253- */
254- public static boolean isReadyForXPackCustomMetadata (ClusterState clusterState ) {
255- return alreadyContainsXPackCustomMetadata (clusterState ) || nodesNotReadyForXPackCustomMetadata (clusterState ).isEmpty ();
256- }
257-
258- /**
259- * Returns the list of nodes that won't allow this node from adding x-pack metadata to the cluster state.
260- * See {@link #checkReadyForXPackCustomMetadata} for more details.
261- */
262- public static List <DiscoveryNode > nodesNotReadyForXPackCustomMetadata (ClusterState clusterState ) {
263- // check that all nodes would be capable of deserializing newly added x-pack metadata
264- final List <DiscoveryNode > notReadyNodes = clusterState .nodes ().stream ().filter (node -> {
265- final String xpackInstalledAttr = node .getAttributes ().getOrDefault (XPACK_INSTALLED_NODE_ATTR , "false" );
266- return Booleans .parseBoolean (xpackInstalledAttr ) == false ;
267- }).collect (Collectors .toList ());
268-
269- return notReadyNodes ;
270- }
271-
272- private static boolean alreadyContainsXPackCustomMetadata (ClusterState clusterState ) {
273- final Metadata metadata = clusterState .metadata ();
274- return metadata .custom (LicensesMetadata .TYPE ) != null
275- || metadata .custom (MlMetadata .TYPE ) != null
276- || metadata .custom (WatcherMetadata .TYPE ) != null
277- || clusterState .custom (TokenMetadata .TYPE ) != null
278- || metadata .custom (TransformMetadata .TYPE ) != null ;
279- }
280-
281220 @ Override
282221 public Map <String , MetadataFieldMapper .TypeParser > getMetadataMappers () {
283222 return Map .of (DataTierFieldMapper .NAME , DataTierFieldMapper .PARSER );
284223 }
285224
286- @ Override
287- public Settings additionalSettings () {
288- final String xpackInstalledNodeAttrSetting = "node.attr." + XPACK_INSTALLED_NODE_ATTR ;
289-
290- if (settings .get (xpackInstalledNodeAttrSetting ) != null ) {
291- throw new IllegalArgumentException ("Directly setting [" + xpackInstalledNodeAttrSetting + "] is not permitted" );
292- }
293- return Settings .builder ().put (super .additionalSettings ()).put (xpackInstalledNodeAttrSetting , "true" ).build ();
294- }
295-
296225 @ Override
297226 public Collection <Object > createComponents (
298227 Client client ,
0 commit comments