Skip to content

Commit 577531b

Browse files
committed
init removal - remove key bits and fix compilation
1 parent b0ba832 commit 577531b

File tree

13 files changed

+4
-221
lines changed

13 files changed

+4
-221
lines changed

x-pack/plugin/core/src/main/java/org/elasticsearch/license/LicenseService.java

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,6 @@ protected PutLicenseResponse newResponse(boolean acknowledged) {
315315

316316
@Override
317317
public ClusterState execute(ClusterState currentState) throws Exception {
318-
XPackPlugin.checkReadyForXPackCustomMetadata(currentState);
319318
final Version oldestNodeVersion = currentState.nodes().getSmallestNonClientNodeVersion();
320319
if (licenseIsCompatible(newLicense, oldestNodeVersion) == false) {
321320
throw new IllegalStateException(
@@ -477,8 +476,7 @@ protected void doStart() throws ElasticsearchException {
477476
if (clusterService.lifecycleState() == Lifecycle.State.STARTED) {
478477
final ClusterState clusterState = clusterService.state();
479478
if (clusterState.blocks().hasGlobalBlock(GatewayService.STATE_NOT_RECOVERED_BLOCK) == false
480-
&& clusterState.nodes().getMasterNode() != null
481-
&& XPackPlugin.isReadyForXPackCustomMetadata(clusterState)) {
479+
&& clusterState.nodes().getMasterNode() != null) {
482480
final LicensesMetadata currentMetadata = clusterState.metadata().custom(LicensesMetadata.TYPE);
483481
boolean noLicense = currentMetadata == null || currentMetadata.getLicense() == null;
484482
if (clusterState.getNodes().isLocalNodeElectedMaster()
@@ -510,14 +508,6 @@ public void clusterChanged(ClusterChangedEvent event) {
510508
final ClusterState previousClusterState = event.previousState();
511509
final ClusterState currentClusterState = event.state();
512510
if (currentClusterState.blocks().hasGlobalBlock(GatewayService.STATE_NOT_RECOVERED_BLOCK) == false) {
513-
if (XPackPlugin.isReadyForXPackCustomMetadata(currentClusterState) == false) {
514-
logger.debug(
515-
"cannot add license to cluster as the following nodes might not understand the license metadata: {}",
516-
() -> XPackPlugin.nodesNotReadyForXPackCustomMetadata(currentClusterState)
517-
);
518-
return;
519-
}
520-
521511
final LicensesMetadata prevLicensesMetadata = previousClusterState.getMetadata().custom(LicensesMetadata.TYPE);
522512
final LicensesMetadata currentLicensesMetadata = currentClusterState.getMetadata().custom(LicensesMetadata.TYPE);
523513
// notify all interested plugins

x-pack/plugin/core/src/main/java/org/elasticsearch/license/StartBasicClusterTask.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
import org.elasticsearch.cluster.metadata.Metadata;
1616
import org.elasticsearch.cluster.node.DiscoveryNodes;
1717
import org.elasticsearch.core.Nullable;
18-
import org.elasticsearch.xpack.core.XPackPlugin;
1918

2019
import java.time.Clock;
2120
import java.util.Map;
@@ -124,7 +123,6 @@ static class Executor implements ClusterStateTaskExecutor<StartBasicClusterTask>
124123
@Override
125124
public ClusterState execute(BatchExecutionContext<StartBasicClusterTask> batchExecutionContext) throws Exception {
126125
final var initialState = batchExecutionContext.initialState();
127-
XPackPlugin.checkReadyForXPackCustomMetadata(initialState);
128126
final LicensesMetadata originalLicensesMetadata = initialState.metadata().custom(LicensesMetadata.TYPE);
129127
var currentLicensesMetadata = originalLicensesMetadata;
130128
for (final var taskContext : batchExecutionContext.taskContexts()) {

x-pack/plugin/core/src/main/java/org/elasticsearch/license/StartTrialClusterTask.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
import org.elasticsearch.cluster.metadata.Metadata;
1616
import org.elasticsearch.cluster.node.DiscoveryNodes;
1717
import org.elasticsearch.core.Nullable;
18-
import org.elasticsearch.xpack.core.XPackPlugin;
1918

2019
import java.time.Clock;
2120
import java.util.Collections;
@@ -111,7 +110,6 @@ static class Executor implements ClusterStateTaskExecutor<StartTrialClusterTask>
111110
@Override
112111
public ClusterState execute(BatchExecutionContext<StartTrialClusterTask> batchExecutionContext) throws Exception {
113112
final var initialState = batchExecutionContext.initialState();
114-
XPackPlugin.checkReadyForXPackCustomMetadata(initialState);
115113
final LicensesMetadata originalLicensesMetadata = initialState.metadata().custom(LicensesMetadata.TYPE);
116114
var currentLicensesMetadata = originalLicensesMetadata;
117115
for (final var taskContext : batchExecutionContext.taskContexts()) {

x-pack/plugin/core/src/main/java/org/elasticsearch/license/StartupSelfGeneratedLicenseTask.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
import org.elasticsearch.cluster.service.ClusterService;
1717
import org.elasticsearch.common.settings.Settings;
1818
import org.elasticsearch.core.Nullable;
19-
import org.elasticsearch.xpack.core.XPackPlugin;
2019

2120
import java.time.Clock;
2221
import java.util.UUID;
@@ -51,7 +50,6 @@ public void clusterStateProcessed(ClusterState oldState, ClusterState newState)
5150

5251
@Override
5352
public ClusterState execute(ClusterState currentState) throws Exception {
54-
XPackPlugin.checkReadyForXPackCustomMetadata(currentState);
5553
final Metadata metadata = currentState.metadata();
5654
final LicensesMetadata currentLicensesMetadata = metadata.custom(LicensesMetadata.TYPE);
5755
// do not generate a license if any license is present

x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/XPackPlugin.java

Lines changed: 0 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,7 @@
1414
import org.elasticsearch.action.support.ActionFilter;
1515
import org.elasticsearch.action.support.TransportAction;
1616
import org.elasticsearch.client.internal.Client;
17-
import org.elasticsearch.cluster.ClusterState;
1817
import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver;
19-
import org.elasticsearch.cluster.metadata.Metadata;
2018
import org.elasticsearch.cluster.node.DiscoveryNode;
2119
import org.elasticsearch.cluster.node.DiscoveryNodes;
2220
import org.elasticsearch.cluster.routing.allocation.AllocationService;
@@ -33,7 +31,6 @@
3331
import org.elasticsearch.common.settings.SettingsFilter;
3432
import org.elasticsearch.common.ssl.SslConfiguration;
3533
import org.elasticsearch.common.util.BigArrays;
36-
import org.elasticsearch.core.Booleans;
3734
import org.elasticsearch.env.Environment;
3835
import org.elasticsearch.env.NodeEnvironment;
3936
import org.elasticsearch.index.IndexSettingProvider;
@@ -42,7 +39,6 @@
4239
import org.elasticsearch.index.mapper.MetadataFieldMapper;
4340
import org.elasticsearch.indices.recovery.RecoverySettings;
4441
import org.elasticsearch.license.LicenseService;
45-
import org.elasticsearch.license.LicensesMetadata;
4642
import org.elasticsearch.license.Licensing;
4743
import org.elasticsearch.license.XPackLicenseState;
4844
import org.elasticsearch.plugins.ClusterPlugin;
@@ -78,18 +74,14 @@
7874
import org.elasticsearch.xpack.core.action.XPackUsageResponse;
7975
import org.elasticsearch.xpack.core.async.DeleteAsyncResultAction;
8076
import org.elasticsearch.xpack.core.async.TransportDeleteAsyncResultAction;
81-
import org.elasticsearch.xpack.core.ml.MlMetadata;
8277
import org.elasticsearch.xpack.core.rest.action.RestReloadAnalyzersAction;
8378
import org.elasticsearch.xpack.core.rest.action.RestXPackInfoAction;
8479
import org.elasticsearch.xpack.core.rest.action.RestXPackUsageAction;
85-
import org.elasticsearch.xpack.core.security.authc.TokenMetadata;
8680
import org.elasticsearch.xpack.core.ssl.SSLConfigurationReloader;
8781
import org.elasticsearch.xpack.core.ssl.SSLService;
8882
import org.elasticsearch.xpack.core.termsenum.action.TermsEnumAction;
8983
import org.elasticsearch.xpack.core.termsenum.action.TransportTermsEnumAction;
9084
import org.elasticsearch.xpack.core.termsenum.rest.RestTermsEnumAction;
91-
import org.elasticsearch.xpack.core.transform.TransformMetadata;
92-
import org.elasticsearch.xpack.core.watcher.WatcherMetadata;
9385

9486
import java.nio.file.Files;
9587
import java.nio.file.Path;
@@ -104,7 +96,6 @@
10496
import java.util.Optional;
10597
import java.util.function.LongSupplier;
10698
import java.util.function.Supplier;
107-
import java.util.stream.Collectors;
10899

109100
@SuppressWarnings("HiddenField")
110101
public 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,

x-pack/plugin/core/src/test/java/org/elasticsearch/license/AbstractLicenseServiceTestCase.java

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,15 @@
2121
import org.elasticsearch.threadpool.TestThreadPool;
2222
import org.elasticsearch.threadpool.ThreadPool;
2323
import org.elasticsearch.watcher.ResourceWatcherService;
24-
import org.elasticsearch.xpack.core.XPackPlugin;
2524
import org.elasticsearch.xpack.core.watcher.watch.ClockMock;
2625
import org.junit.After;
2726
import org.junit.Before;
2827

2928
import java.nio.file.Path;
3029
import java.util.stream.Stream;
3130

31+
import static java.util.Collections.emptyMap;
3232
import static java.util.Collections.emptySet;
33-
import static java.util.Collections.singletonMap;
3433
import static org.mockito.Mockito.mock;
3534
import static org.mockito.Mockito.when;
3635

@@ -90,13 +89,7 @@ protected void setInitialState(License license, XPackLicenseState licenseState,
9089
}
9190

9291
protected DiscoveryNode getLocalNode() {
93-
return new DiscoveryNode(
94-
"b",
95-
buildNewFakeTransportAddress(),
96-
singletonMap(XPackPlugin.XPACK_INSTALLED_NODE_ATTR, "true"),
97-
emptySet(),
98-
Version.CURRENT
99-
);
92+
return new DiscoveryNode("b", buildNewFakeTransportAddress(), emptyMap(), emptySet(), Version.CURRENT);
10093
}
10194

10295
@After

x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/XPackPluginTests.java

Lines changed: 0 additions & 103 deletions
This file was deleted.

x-pack/plugin/rollup/src/main/java/org/elasticsearch/xpack/rollup/action/TransportPutRollupJobAction.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@
4747
import org.elasticsearch.xcontent.XContentBuilder;
4848
import org.elasticsearch.xcontent.XContentType;
4949
import org.elasticsearch.xpack.core.ClientHelper;
50-
import org.elasticsearch.xpack.core.XPackPlugin;
5150
import org.elasticsearch.xpack.core.rollup.RollupField;
5251
import org.elasticsearch.xpack.core.rollup.action.PutRollupJobAction;
5352
import org.elasticsearch.xpack.core.rollup.job.RollupJob;
@@ -100,7 +99,6 @@ protected void masterOperation(
10099
ClusterState clusterState,
101100
ActionListener<AcknowledgedResponse> listener
102101
) {
103-
XPackPlugin.checkReadyForXPackCustomMetadata(clusterState);
104102
checkForDeprecatedTZ(request);
105103

106104
FieldCapabilitiesRequest fieldCapsRequest = new FieldCapabilitiesRequest().indices(request.indices())

0 commit comments

Comments
 (0)