From 28a6f076eab4198006f012e0038b214a67863fd3 Mon Sep 17 00:00:00 2001 From: Jason Tedor Date: Sat, 27 Jul 2019 19:32:17 +0900 Subject: [PATCH 1/5] Remove client feature tracking This commit removes the infrastructure for client feature tracking. We introduced this functionality to support clients that do not necessarily understand all the features that the server might support, for example, customs in the cluster state provided by plugins that a client might not have. This can arise in situations such as rolling upgrades from the OSS distribution to the default distribution. With the removal of the transport client, this infrastructure is no longer needed. This commit removes client feature tracking from the server in 8.0.0. --- .../elasticsearch/cluster/ClusterState.java | 40 +-- .../cluster/metadata/MetaData.java | 9 +- .../io/stream/VersionedNamedWriteable.java | 5 + .../persistent/PersistentTaskParams.java | 3 +- .../PersistentTasksCustomMetaData.java | 3 +- .../org/elasticsearch/plugins/Plugin.java | 13 - .../elasticsearch/plugins/PluginsService.java | 21 -- .../transport/InboundHandler.java | 8 +- .../transport/InboundMessage.java | 22 +- .../transport/OutboundHandler.java | 8 +- .../transport/OutboundMessage.java | 10 +- .../elasticsearch/transport/TcpTransport.java | 4 +- .../transport/TcpTransportChannel.java | 5 +- .../transport/TransportHandshaker.java | 11 +- .../cluster/FeatureAwareTests.java | 151 -------- .../persistent/TestPersistentTasksPlugin.java | 6 +- .../transport/InboundHandlerTests.java | 6 +- .../transport/InboundMessageTests.java | 5 +- .../transport/OutboundHandlerTests.java | 7 +- .../transport/TransportHandshakerTests.java | 8 +- x-pack/plugin/build.gradle | 47 --- .../xpack/ccr/action/ShardFollowTask.java | 4 +- .../license/LicensesMetaData.java | 3 +- .../xpack/core/XPackClientPlugin.java | 19 +- .../elasticsearch/xpack/core/XPackPlugin.java | 27 -- .../xpack/core/ccr/AutoFollowMetadata.java | 3 +- .../transforms/DataFrameTransform.java | 4 +- .../IndexLifecycleMetadata.java | 3 +- .../xpack/core/ml/MlMetadata.java | 3 +- .../xpack/core/ml/action/OpenJobAction.java | 4 +- .../action/StartDataFrameAnalyticsAction.java | 4 +- .../core/ml/action/StartDatafeedAction.java | 4 +- .../xpack/core/rollup/job/RollupJob.java | 4 +- .../core/security/authc/TokenMetaData.java | 3 +- .../SnapshotLifecycleMetadata.java | 3 +- .../xpack/core/watcher/WatcherMetaData.java | 3 +- x-pack/plugin/sql/build.gradle | 1 - x-pack/test/feature-aware/build.gradle | 17 - .../test/feature_aware/FeatureAwareCheck.java | 179 ---------- .../feature_aware/FeatureAwareCheckTests.java | 323 ------------------ 40 files changed, 78 insertions(+), 925 deletions(-) delete mode 100644 server/src/test/java/org/elasticsearch/cluster/FeatureAwareTests.java delete mode 100644 x-pack/test/feature-aware/build.gradle delete mode 100644 x-pack/test/feature-aware/src/main/java/org/elasticsearch/xpack/test/feature_aware/FeatureAwareCheck.java delete mode 100644 x-pack/test/feature-aware/src/test/java/org/elasticsearch/xpack/test/feature_aware/FeatureAwareCheckTests.java diff --git a/server/src/main/java/org/elasticsearch/cluster/ClusterState.java b/server/src/main/java/org/elasticsearch/cluster/ClusterState.java index 51a1dc3835e9c..356f7e4f9d72e 100644 --- a/server/src/main/java/org/elasticsearch/cluster/ClusterState.java +++ b/server/src/main/java/org/elasticsearch/cluster/ClusterState.java @@ -65,7 +65,6 @@ import java.util.Locale; import java.util.Map; import java.util.Objects; -import java.util.Optional; import java.util.Set; import java.util.stream.StreamSupport; @@ -95,40 +94,7 @@ public class ClusterState implements ToXContentFragment, Diffable public static final ClusterState EMPTY_STATE = builder(ClusterName.CLUSTER_NAME_SETTING.getDefault(Settings.EMPTY)).build(); - /** - * An interface that implementors use when a class requires a client to maybe have a feature. - */ - public interface FeatureAware { - - /** - * An optional feature that is required for the client to have. - * - * @return an empty optional if no feature is required otherwise a string representing the required feature - */ - default Optional getRequiredFeature() { - return Optional.empty(); - } - - /** - * Tests whether or not the custom should be serialized. The criteria are: - *
    - *
  • the output stream must be at least the minimum supported version of the custom
  • - *
- *

- * That is, we only serialize customs to clients than can understand the custom based on the version of the client. - * - * @param out the output stream - * @param custom the custom to serialize - * @param the type of the custom - * @return true if the custom should be serialized and false otherwise - */ - static boolean shouldSerialize(final StreamOutput out, final T custom) { - return out.getVersion().onOrAfter(custom.getMinimalSupportedVersion()); - } - - } - - public interface Custom extends NamedDiffable, ToXContentFragment, FeatureAware { + public interface Custom extends NamedDiffable, ToXContentFragment { /** * Returns true iff this {@link Custom} is private to the cluster and should never be send to a client. @@ -777,13 +743,13 @@ public void writeTo(StreamOutput out) throws IOException { // filter out custom states not supported by the other node int numberOfCustoms = 0; for (final ObjectCursor cursor : customs.values()) { - if (FeatureAware.shouldSerialize(out, cursor.value)) { + if (VersionedNamedWriteable.shouldSerialize(out, cursor.value)) { numberOfCustoms++; } } out.writeVInt(numberOfCustoms); for (final ObjectCursor cursor : customs.values()) { - if (FeatureAware.shouldSerialize(out, cursor.value)) { + if (VersionedNamedWriteable.shouldSerialize(out, cursor.value)) { out.writeNamedWriteable(cursor.value); } } diff --git a/server/src/main/java/org/elasticsearch/cluster/metadata/MetaData.java b/server/src/main/java/org/elasticsearch/cluster/metadata/MetaData.java index 4c2eeec72a970..0b14c692d53a5 100644 --- a/server/src/main/java/org/elasticsearch/cluster/metadata/MetaData.java +++ b/server/src/main/java/org/elasticsearch/cluster/metadata/MetaData.java @@ -27,8 +27,6 @@ import org.apache.lucene.util.CollectionUtil; import org.elasticsearch.Version; import org.elasticsearch.action.AliasesRequest; -import org.elasticsearch.cluster.ClusterState; -import org.elasticsearch.cluster.ClusterState.FeatureAware; import org.elasticsearch.cluster.Diff; import org.elasticsearch.cluster.Diffable; import org.elasticsearch.cluster.DiffableUtils; @@ -44,6 +42,7 @@ import org.elasticsearch.common.collect.ImmutableOpenMap; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; +import org.elasticsearch.common.io.stream.VersionedNamedWriteable; import org.elasticsearch.common.regex.Regex; import org.elasticsearch.common.settings.Setting; import org.elasticsearch.common.settings.Setting.Property; @@ -125,7 +124,7 @@ public enum XContentContext { */ public static EnumSet ALL_CONTEXTS = EnumSet.allOf(XContentContext.class); - public interface Custom extends NamedDiffable, ToXContentFragment, ClusterState.FeatureAware { + public interface Custom extends NamedDiffable, ToXContentFragment { EnumSet context(); } @@ -916,13 +915,13 @@ public void writeTo(StreamOutput out) throws IOException { // filter out custom states not supported by the other node int numberOfCustoms = 0; for (final ObjectCursor cursor : customs.values()) { - if (FeatureAware.shouldSerialize(out, cursor.value)) { + if (VersionedNamedWriteable.shouldSerialize(out, cursor.value)) { numberOfCustoms++; } } out.writeVInt(numberOfCustoms); for (final ObjectCursor cursor : customs.values()) { - if (FeatureAware.shouldSerialize(out, cursor.value)) { + if (VersionedNamedWriteable.shouldSerialize(out, cursor.value)) { out.writeNamedWriteable(cursor.value); } } diff --git a/server/src/main/java/org/elasticsearch/common/io/stream/VersionedNamedWriteable.java b/server/src/main/java/org/elasticsearch/common/io/stream/VersionedNamedWriteable.java index 9eea2c00d56a6..918192f6555b9 100644 --- a/server/src/main/java/org/elasticsearch/common/io/stream/VersionedNamedWriteable.java +++ b/server/src/main/java/org/elasticsearch/common/io/stream/VersionedNamedWriteable.java @@ -35,4 +35,9 @@ public interface VersionedNamedWriteable extends NamedWriteable { * The minimal version of the recipient this object can be sent to */ Version getMinimalSupportedVersion(); + + static boolean shouldSerialize(final StreamOutput out, final T custom) { + return out.getVersion().onOrAfter(custom.getMinimalSupportedVersion()); + } + } diff --git a/server/src/main/java/org/elasticsearch/persistent/PersistentTaskParams.java b/server/src/main/java/org/elasticsearch/persistent/PersistentTaskParams.java index c91727a913f3a..defce2769fa94 100644 --- a/server/src/main/java/org/elasticsearch/persistent/PersistentTaskParams.java +++ b/server/src/main/java/org/elasticsearch/persistent/PersistentTaskParams.java @@ -19,13 +19,12 @@ package org.elasticsearch.persistent; -import org.elasticsearch.cluster.ClusterState; import org.elasticsearch.common.io.stream.VersionedNamedWriteable; import org.elasticsearch.common.xcontent.ToXContentObject; /** * Parameters used to start persistent task */ -public interface PersistentTaskParams extends VersionedNamedWriteable, ToXContentObject, ClusterState.FeatureAware { +public interface PersistentTaskParams extends VersionedNamedWriteable, ToXContentObject { } diff --git a/server/src/main/java/org/elasticsearch/persistent/PersistentTasksCustomMetaData.java b/server/src/main/java/org/elasticsearch/persistent/PersistentTasksCustomMetaData.java index 6c5aa741a797d..618d99cc98f7b 100644 --- a/server/src/main/java/org/elasticsearch/persistent/PersistentTasksCustomMetaData.java +++ b/server/src/main/java/org/elasticsearch/persistent/PersistentTasksCustomMetaData.java @@ -30,6 +30,7 @@ import org.elasticsearch.common.Strings; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; +import org.elasticsearch.common.io.stream.VersionedNamedWriteable; import org.elasticsearch.common.io.stream.Writeable; import org.elasticsearch.common.xcontent.ConstructingObjectParser; import org.elasticsearch.common.xcontent.ObjectParser; @@ -532,7 +533,7 @@ public PersistentTasksCustomMetaData(StreamInput in) throws IOException { public void writeTo(StreamOutput out) throws IOException { out.writeLong(lastAllocationId); Map> filteredTasks = tasks.values().stream() - .filter(t -> ClusterState.FeatureAware.shouldSerialize(out, t.getParams())) + .filter(t -> VersionedNamedWriteable.shouldSerialize(out, t.getParams())) .collect(Collectors.toMap(PersistentTask::getId, Function.identity())); out.writeMap(filteredTasks, StreamOutput::writeString, (stream, value) -> value.writeTo(stream)); } diff --git a/server/src/main/java/org/elasticsearch/plugins/Plugin.java b/server/src/main/java/org/elasticsearch/plugins/Plugin.java index 5bc8e9267a515..950c08fc32650 100644 --- a/server/src/main/java/org/elasticsearch/plugins/Plugin.java +++ b/server/src/main/java/org/elasticsearch/plugins/Plugin.java @@ -21,7 +21,6 @@ import org.elasticsearch.bootstrap.BootstrapCheck; import org.elasticsearch.client.Client; -import org.elasticsearch.cluster.ClusterState; import org.elasticsearch.cluster.metadata.IndexMetaData; import org.elasticsearch.cluster.metadata.IndexTemplateMetaData; import org.elasticsearch.cluster.metadata.MetaData; @@ -49,7 +48,6 @@ import java.util.Collections; import java.util.List; import java.util.Map; -import java.util.Optional; import java.util.Set; import java.util.function.UnaryOperator; @@ -72,17 +70,6 @@ */ public abstract class Plugin implements Closeable { - /** - * A feature exposed by the plugin. This should be used if a plugin exposes {@link ClusterState.Custom} or {@link MetaData.Custom}; see - * also {@link ClusterState.FeatureAware}. - * - * @return a feature set represented by this plugin, or the empty optional if the plugin does not expose cluster state or metadata - * customs - */ - protected Optional getFeature() { - return Optional.empty(); - } - /** * Returns components added by this plugin. * diff --git a/server/src/main/java/org/elasticsearch/plugins/PluginsService.java b/server/src/main/java/org/elasticsearch/plugins/PluginsService.java index feb18c61e3365..991f6952c4473 100644 --- a/server/src/main/java/org/elasticsearch/plugins/PluginsService.java +++ b/server/src/main/java/org/elasticsearch/plugins/PluginsService.java @@ -39,7 +39,6 @@ import org.elasticsearch.common.settings.Settings; import org.elasticsearch.index.IndexModule; import org.elasticsearch.threadpool.ExecutorBuilder; -import org.elasticsearch.transport.TransportSettings; import java.io.IOException; import java.lang.reflect.Constructor; @@ -59,9 +58,7 @@ import java.util.Locale; import java.util.Map; import java.util.Objects; -import java.util.Optional; import java.util.Set; -import java.util.TreeMap; import java.util.function.Function; import java.util.stream.Collectors; @@ -202,7 +199,6 @@ private static void logPluginInfo(final List pluginInfos, final Stri public Settings updatedSettings() { Map foundSettings = new HashMap<>(); - final Map features = new TreeMap<>(); final Settings.Builder builder = Settings.builder(); for (Tuple plugin : plugins) { Settings settings = plugin.v2().additionalSettings(); @@ -214,23 +210,6 @@ public Settings updatedSettings() { } } builder.put(settings); - final Optional maybeFeature = plugin.v2().getFeature(); - if (maybeFeature.isPresent()) { - final String feature = maybeFeature.get(); - if (features.containsKey(feature)) { - final String message = String.format( - Locale.ROOT, - "duplicate feature [%s] in plugin [%s], already added in [%s]", - feature, - plugin.v1().getName(), - features.get(feature)); - throw new IllegalArgumentException(message); - } - features.put(feature, plugin.v1().getName()); - } - } - for (final String feature : features.keySet()) { - builder.put(TransportSettings.FEATURE_PREFIX + "." + feature, true); } return builder.put(this.settings).build(); } diff --git a/server/src/main/java/org/elasticsearch/transport/InboundHandler.java b/server/src/main/java/org/elasticsearch/transport/InboundHandler.java index 83e93cd3b7bbe..f8ee85728ee29 100644 --- a/server/src/main/java/org/elasticsearch/transport/InboundHandler.java +++ b/server/src/main/java/org/elasticsearch/transport/InboundHandler.java @@ -38,7 +38,6 @@ import java.net.InetSocketAddress; import java.util.Collections; import java.util.Map; -import java.util.Set; public class InboundHandler { @@ -153,7 +152,6 @@ private void messageReceived(BytesReference reference, TcpChannel channel) throw } private void handleRequest(TcpChannel channel, InboundMessage.Request message, int messageLengthBytes) { - final Set features = message.getFeatures(); final String action = message.getActionName(); final long requestId = message.getRequestId(); final StreamInput stream = message.getStreamInput(); @@ -162,7 +160,7 @@ private void handleRequest(TcpChannel channel, InboundMessage.Request message, i TransportChannel transportChannel = null; try { if (message.isHandshake()) { - handshaker.handleHandshake(version, features, channel, requestId, stream); + handshaker.handleHandshake(version, channel, requestId, stream); } else { final RequestHandlerRegistry reg = getRequestHandler(action); if (reg == null) { @@ -174,7 +172,7 @@ private void handleRequest(TcpChannel channel, InboundMessage.Request message, i } else { breaker.addWithoutBreaking(messageLengthBytes); } - transportChannel = new TcpTransportChannel(outboundHandler, channel, action, requestId, version, features, + transportChannel = new TcpTransportChannel(outboundHandler, channel, action, requestId, version, circuitBreakerService, messageLengthBytes, message.isCompress()); final TransportRequest request = reg.newRequest(stream); request.remoteAddress(new TransportAddress(channel.getRemoteAddress())); @@ -190,7 +188,7 @@ private void handleRequest(TcpChannel channel, InboundMessage.Request message, i } catch (Exception e) { // the circuit breaker tripped if (transportChannel == null) { - transportChannel = new TcpTransportChannel(outboundHandler, channel, action, requestId, version, features, + transportChannel = new TcpTransportChannel(outboundHandler, channel, action, requestId, version, circuitBreakerService, 0, message.isCompress()); } try { diff --git a/server/src/main/java/org/elasticsearch/transport/InboundMessage.java b/server/src/main/java/org/elasticsearch/transport/InboundMessage.java index ab07c772f927e..641f862f70385 100644 --- a/server/src/main/java/org/elasticsearch/transport/InboundMessage.java +++ b/server/src/main/java/org/elasticsearch/transport/InboundMessage.java @@ -31,10 +31,6 @@ import java.io.Closeable; import java.io.IOException; -import java.util.Arrays; -import java.util.Collections; -import java.util.Set; -import java.util.TreeSet; public abstract class InboundMessage extends NetworkMessage implements Closeable { @@ -96,15 +92,12 @@ InboundMessage deserialize(BytesReference reference) throws IOException { InboundMessage message; if (TransportStatus.isRequest(status)) { - final String[] featuresFound = streamInput.readStringArray(); - final Set features; - if (featuresFound.length == 0) { - features = Collections.emptySet(); - } else { - features = Collections.unmodifiableSet(new TreeSet<>(Arrays.asList(featuresFound))); + if (streamInput.getVersion().before(Version.V_8_0_0)) { + // discard features + streamInput.readStringArray(); } final String action = streamInput.readString(); - message = new Request(threadContext, remoteVersion, status, requestId, action, features, streamInput); + message = new Request(threadContext, remoteVersion, status, requestId, action, streamInput); } else { message = new Response(threadContext, remoteVersion, status, requestId, streamInput); } @@ -146,22 +139,17 @@ private static void ensureVersionCompatibility(Version version, Version currentV public static class Request extends InboundMessage { private final String actionName; - private final Set features; - Request(ThreadContext threadContext, Version version, byte status, long requestId, String actionName, Set features, + Request(ThreadContext threadContext, Version version, byte status, long requestId, String actionName, StreamInput streamInput) { super(threadContext, version, status, requestId, streamInput); this.actionName = actionName; - this.features = features; } String getActionName() { return actionName; } - Set getFeatures() { - return features; - } } public static class Response extends InboundMessage { diff --git a/server/src/main/java/org/elasticsearch/transport/OutboundHandler.java b/server/src/main/java/org/elasticsearch/transport/OutboundHandler.java index 7438a399a9206..d42b91b8efa8b 100644 --- a/server/src/main/java/org/elasticsearch/transport/OutboundHandler.java +++ b/server/src/main/java/org/elasticsearch/transport/OutboundHandler.java @@ -49,17 +49,15 @@ final class OutboundHandler { private final String nodeName; private final Version version; - private final String[] features; private final ThreadPool threadPool; private final BigArrays bigArrays; private final TransportLogger transportLogger; private volatile TransportMessageListener messageListener = TransportMessageListener.NOOP_LISTENER; - OutboundHandler(String nodeName, Version version, String[] features, ThreadPool threadPool, BigArrays bigArrays, + OutboundHandler(String nodeName, Version version, ThreadPool threadPool, BigArrays bigArrays, TransportLogger transportLogger) { this.nodeName = nodeName; this.version = version; - this.features = features; this.threadPool = threadPool; this.bigArrays = bigArrays; this.transportLogger = transportLogger; @@ -83,8 +81,8 @@ void sendRequest(final DiscoveryNode node, final TcpChannel channel, final long final TransportRequest request, final TransportRequestOptions options, final Version channelVersion, final boolean compressRequest, final boolean isHandshake) throws IOException, TransportException { Version version = Version.min(this.version, channelVersion); - OutboundMessage.Request message = new OutboundMessage.Request(threadPool.getThreadContext(), features, request, version, action, - requestId, isHandshake, compressRequest); + OutboundMessage.Request message = + new OutboundMessage.Request(threadPool.getThreadContext(), request, version, action, requestId, isHandshake, compressRequest); ActionListener listener = ActionListener.wrap(() -> messageListener.onRequestSent(node, requestId, action, request, options)); sendMessage(channel, message, listener); diff --git a/server/src/main/java/org/elasticsearch/transport/OutboundMessage.java b/server/src/main/java/org/elasticsearch/transport/OutboundMessage.java index dbea9991db5aa..3e376534fdf17 100644 --- a/server/src/main/java/org/elasticsearch/transport/OutboundMessage.java +++ b/server/src/main/java/org/elasticsearch/transport/OutboundMessage.java @@ -19,6 +19,7 @@ package org.elasticsearch.transport; import org.elasticsearch.Version; +import org.elasticsearch.common.Strings; import org.elasticsearch.common.bytes.BytesArray; import org.elasticsearch.common.bytes.BytesReference; import org.elasticsearch.common.bytes.CompositeBytesReference; @@ -82,19 +83,20 @@ protected BytesReference writeMessage(CompressibleBytesOutputStream stream) thro static class Request extends OutboundMessage { - private final String[] features; private final String action; - Request(ThreadContext threadContext, String[] features, Writeable message, Version version, String action, long requestId, + Request(ThreadContext threadContext, Writeable message, Version version, String action, long requestId, boolean isHandshake, boolean compress) { super(threadContext, version, setStatus(compress, isHandshake, message), requestId, message); - this.features = features; this.action = action; } @Override protected BytesReference writeMessage(CompressibleBytesOutputStream out) throws IOException { - out.writeStringArray(features); + if (out.getVersion().before(Version.V_8_0_0)) { + // empty features array + out.writeStringArray(Strings.EMPTY_ARRAY); + } out.writeString(action); return super.writeMessage(out); } diff --git a/server/src/main/java/org/elasticsearch/transport/TcpTransport.java b/server/src/main/java/org/elasticsearch/transport/TcpTransport.java index b0abc88848584..e434ba50becc8 100644 --- a/server/src/main/java/org/elasticsearch/transport/TcpTransport.java +++ b/server/src/main/java/org/elasticsearch/transport/TcpTransport.java @@ -151,12 +151,12 @@ public TcpTransport(Settings settings, Version version, ThreadPool threadPool, P } BigArrays bigArrays = new BigArrays(pageCacheRecycler, circuitBreakerService, CircuitBreaker.IN_FLIGHT_REQUESTS); - this.outboundHandler = new OutboundHandler(nodeName, version, features, threadPool, bigArrays, transportLogger); + this.outboundHandler = new OutboundHandler(nodeName, version, threadPool, bigArrays, transportLogger); this.handshaker = new TransportHandshaker(version, threadPool, (node, channel, requestId, v) -> outboundHandler.sendRequest(node, channel, requestId, TransportHandshaker.HANDSHAKE_ACTION_NAME, new TransportHandshaker.HandshakeRequest(version), TransportRequestOptions.EMPTY, v, false, true), - (v, features1, channel, response, requestId) -> outboundHandler.sendResponse(v, channel, requestId, + (v, channel, response, requestId) -> outboundHandler.sendResponse(v, channel, requestId, TransportHandshaker.HANDSHAKE_ACTION_NAME, response, false, true)); InboundMessage.Reader reader = new InboundMessage.Reader(version, namedWriteableRegistry, threadPool.getThreadContext()); this.keepAlive = new TransportKeepAlive(threadPool, this.outboundHandler::sendBytes); diff --git a/server/src/main/java/org/elasticsearch/transport/TcpTransportChannel.java b/server/src/main/java/org/elasticsearch/transport/TcpTransportChannel.java index 315b67e92e9d8..3e41477fa8b8b 100644 --- a/server/src/main/java/org/elasticsearch/transport/TcpTransportChannel.java +++ b/server/src/main/java/org/elasticsearch/transport/TcpTransportChannel.java @@ -24,7 +24,6 @@ import org.elasticsearch.indices.breaker.CircuitBreakerService; import java.io.IOException; -import java.util.Set; import java.util.concurrent.atomic.AtomicBoolean; public final class TcpTransportChannel implements TransportChannel { @@ -35,15 +34,13 @@ public final class TcpTransportChannel implements TransportChannel { private final String action; private final long requestId; private final Version version; - private final Set features; private final CircuitBreakerService breakerService; private final long reservedBytes; private final boolean compressResponse; TcpTransportChannel(OutboundHandler outboundHandler, TcpChannel channel, String action, long requestId, Version version, - Set features, CircuitBreakerService breakerService, long reservedBytes, boolean compressResponse) { + CircuitBreakerService breakerService, long reservedBytes, boolean compressResponse) { this.version = version; - this.features = features; this.channel = channel; this.outboundHandler = outboundHandler; this.action = action; diff --git a/server/src/main/java/org/elasticsearch/transport/TransportHandshaker.java b/server/src/main/java/org/elasticsearch/transport/TransportHandshaker.java index 55ce080563421..1449627a8dc6a 100644 --- a/server/src/main/java/org/elasticsearch/transport/TransportHandshaker.java +++ b/server/src/main/java/org/elasticsearch/transport/TransportHandshaker.java @@ -16,6 +16,7 @@ * specific language governing permissions and limitations * under the License. */ + package org.elasticsearch.transport; import org.elasticsearch.Version; @@ -31,7 +32,6 @@ import java.io.EOFException; import java.io.IOException; -import java.util.Set; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentMap; import java.util.concurrent.atomic.AtomicBoolean; @@ -88,7 +88,7 @@ void sendHandshake(long requestId, DiscoveryNode node, TcpChannel channel, TimeV } } - void handleHandshake(Version version, Set features, TcpChannel channel, long requestId, StreamInput stream) throws IOException { + void handleHandshake(Version version, TcpChannel channel, long requestId, StreamInput stream) throws IOException { // Must read the handshake request to exhaust the stream HandshakeRequest handshakeRequest = new HandshakeRequest(stream); final int nextByte = stream.read(); @@ -97,7 +97,7 @@ void handleHandshake(Version version, Set features, TcpChannel channel, + TransportHandshaker.HANDSHAKE_ACTION_NAME + "], available [" + stream.available() + "]; resetting"); } HandshakeResponse response = new HandshakeResponse(this.version); - handshakeResponseSender.sendResponse(version, features, channel, response, requestId); + handshakeResponseSender.sendResponse(version, channel, response, requestId); } TransportResponseHandler removeHandlerForHandshake(long requestId) { @@ -232,7 +232,8 @@ interface HandshakeRequestSender { @FunctionalInterface interface HandshakeResponseSender { - void sendResponse(Version version, Set features, TcpChannel channel, TransportResponse response, long requestId) - throws IOException; + void sendResponse(Version version, TcpChannel channel, TransportResponse response, long requestId) throws IOException; + } + } diff --git a/server/src/test/java/org/elasticsearch/cluster/FeatureAwareTests.java b/server/src/test/java/org/elasticsearch/cluster/FeatureAwareTests.java deleted file mode 100644 index 9da25a4cc6781..0000000000000 --- a/server/src/test/java/org/elasticsearch/cluster/FeatureAwareTests.java +++ /dev/null @@ -1,151 +0,0 @@ -/* - * Licensed to Elasticsearch under one or more contributor - * license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Elasticsearch licenses this file to you under - * the Apache License, Version 2.0 (the "License"); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.cluster; - -import org.elasticsearch.Version; -import org.elasticsearch.cluster.ClusterState.FeatureAware; -import org.elasticsearch.cluster.metadata.MetaData; -import org.elasticsearch.common.io.stream.BytesStreamOutput; -import org.elasticsearch.common.io.stream.StreamOutput; -import org.elasticsearch.common.xcontent.XContentBuilder; -import org.elasticsearch.test.ESTestCase; -import org.elasticsearch.test.VersionUtils; - -import java.io.IOException; -import java.util.Arrays; -import java.util.EnumSet; -import java.util.Optional; - -import static org.elasticsearch.test.VersionUtils.randomVersionBetween; - -public class FeatureAwareTests extends ESTestCase { - - abstract static class Custom implements MetaData.Custom { - - private final Version version; - - Custom(final Version version) { - this.version = version; - } - - @Override - public EnumSet context() { - return MetaData.ALL_CONTEXTS; - } - - @Override - public Diff diff(final MetaData.Custom previousState) { - return null; - } - - @Override - public void writeTo(final StreamOutput out) throws IOException { - - } - - @Override - public XContentBuilder toXContent(final XContentBuilder builder, final Params params) throws IOException { - return builder; - } - - @Override - public Version getMinimalSupportedVersion() { - return version; - } - - } - - static class NoRequiredFeatureCustom extends Custom { - - NoRequiredFeatureCustom(final Version version) { - super(version); - } - - @Override - public String getWriteableName() { - return "no-required-feature"; - } - - } - - static class RequiredFeatureCustom extends Custom { - - RequiredFeatureCustom(final Version version) { - super(version); - } - - @Override - public String getWriteableName() { - return null; - } - - @Override - public Optional getRequiredFeature() { - return Optional.of("required-feature"); - } - - } - - public void testVersion() { - final Version version = randomValueOtherThan(VersionUtils.getFirstVersion(), () -> VersionUtils.randomVersion(random())); - for (final Custom custom : Arrays.asList(new NoRequiredFeatureCustom(version), new RequiredFeatureCustom(version))) { - { - final BytesStreamOutput out = new BytesStreamOutput(); - final Version afterVersion = randomVersionBetween(random(), version, Version.CURRENT); - out.setVersion(afterVersion); - custom.getRequiredFeature(); - assertTrue(FeatureAware.shouldSerialize(out, custom)); - } - { - final BytesStreamOutput out = new BytesStreamOutput(); - final Version beforeVersion = - randomVersionBetween(random(), VersionUtils.getFirstVersion(), VersionUtils.getPreviousVersion(version)); - out.setVersion(beforeVersion); - assertFalse(FeatureAware.shouldSerialize(out, custom)); - } - } - } - - public void testFeature() { - final Version version = VersionUtils.randomVersion(random()); - final Version afterVersion = randomVersionBetween(random(), version, Version.CURRENT); - final Custom custom = new RequiredFeatureCustom(version); - { - // the feature is present - final BytesStreamOutput out = new BytesStreamOutput(); - out.setVersion(afterVersion); - assertTrue(custom.getRequiredFeature().isPresent()); - assertTrue(FeatureAware.shouldSerialize(out, custom)); - } - } - - public void testMissingFeature() { - final Version version = VersionUtils.randomVersion(random()); - final Version afterVersion = randomVersionBetween(random(), version, Version.CURRENT); - final Custom custom = new RequiredFeatureCustom(version); - { - // the feature is missing but we should serialize it anyway - final BytesStreamOutput out = new BytesStreamOutput(); - out.setVersion(afterVersion); - assertTrue(FeatureAware.shouldSerialize(out, custom)); - } - } - -} diff --git a/server/src/test/java/org/elasticsearch/persistent/TestPersistentTasksPlugin.java b/server/src/test/java/org/elasticsearch/persistent/TestPersistentTasksPlugin.java index b92481954bf3d..6f3ac3be58e27 100644 --- a/server/src/test/java/org/elasticsearch/persistent/TestPersistentTasksPlugin.java +++ b/server/src/test/java/org/elasticsearch/persistent/TestPersistentTasksPlugin.java @@ -22,10 +22,10 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.elasticsearch.Version; -import org.elasticsearch.action.ActionType; import org.elasticsearch.action.ActionListener; import org.elasticsearch.action.ActionRequest; import org.elasticsearch.action.ActionResponse; +import org.elasticsearch.action.ActionType; import org.elasticsearch.action.FailedNodeException; import org.elasticsearch.action.TaskOperationFailure; import org.elasticsearch.action.support.ActionFilters; @@ -217,10 +217,6 @@ public Version getMinimalSupportedVersion() { return minVersion; } - @Override - public Optional getRequiredFeature() { - return feature; - } } public static class State implements PersistentTaskState { diff --git a/server/src/test/java/org/elasticsearch/transport/InboundHandlerTests.java b/server/src/test/java/org/elasticsearch/transport/InboundHandlerTests.java index a201b3210376c..2dd9ee7134992 100644 --- a/server/src/test/java/org/elasticsearch/transport/InboundHandlerTests.java +++ b/server/src/test/java/org/elasticsearch/transport/InboundHandlerTests.java @@ -60,10 +60,10 @@ public void setUp() throws Exception { NamedWriteableRegistry namedWriteableRegistry = new NamedWriteableRegistry(Collections.emptyList()); InboundMessage.Reader reader = new InboundMessage.Reader(version, namedWriteableRegistry, threadPool.getThreadContext()); TransportHandshaker handshaker = new TransportHandshaker(version, threadPool, (n, c, r, v) -> { - }, (v, f, c, r, r_id) -> { + }, (v, c, r, r_id) -> { }); TransportKeepAlive keepAlive = new TransportKeepAlive(threadPool, TcpChannel::sendMessage); - OutboundHandler outboundHandler = new OutboundHandler("node", version, new String[0], threadPool, BigArrays.NON_RECYCLING_INSTANCE, + OutboundHandler outboundHandler = new OutboundHandler("node", version, threadPool, BigArrays.NON_RECYCLING_INSTANCE, transportLogger); handler = new InboundHandler(threadPool, outboundHandler, reader, new NoneCircuitBreakerService(), transportLogger, handshaker, keepAlive); @@ -128,7 +128,7 @@ public TestResponse read(StreamInput in) throws IOException { }, ThreadPool.Names.SAME, false, true); handler.registerRequestHandler(registry); String requestValue = randomAlphaOfLength(10); - OutboundMessage.Request request = new OutboundMessage.Request(threadPool.getThreadContext(), new String[0], + OutboundMessage.Request request = new OutboundMessage.Request(threadPool.getThreadContext(), new TestRequest(requestValue), version, action, requestId, false, isCompressed); BytesReference bytes = request.serialize(new BytesStreamOutput()); diff --git a/server/src/test/java/org/elasticsearch/transport/InboundMessageTests.java b/server/src/test/java/org/elasticsearch/transport/InboundMessageTests.java index 4bace54501b1c..aa5233c77651d 100644 --- a/server/src/test/java/org/elasticsearch/transport/InboundMessageTests.java +++ b/server/src/test/java/org/elasticsearch/transport/InboundMessageTests.java @@ -51,7 +51,7 @@ public void testReadRequest() throws IOException { boolean compress = randomBoolean(); threadContext.putHeader("header", "header_value"); Version version = randomFrom(Version.CURRENT, Version.CURRENT.minimumCompatibilityVersion()); - OutboundMessage.Request request = new OutboundMessage.Request(threadContext, features, message, version, action, requestId, + OutboundMessage.Request request = new OutboundMessage.Request(threadContext, message, version, action, requestId, isHandshake, compress); BytesReference reference; try (BytesStreamOutput streamOutput = new BytesStreamOutput()) { @@ -74,7 +74,6 @@ public void testReadRequest() throws IOException { assertEquals(compress, inboundMessage.isCompress()); assertEquals(version, inboundMessage.getVersion()); assertEquals(action, inboundMessage.getActionName()); - assertEquals(new HashSet<>(Arrays.asList(features)), inboundMessage.getFeatures()); assertTrue(inboundMessage.isRequest()); assertFalse(inboundMessage.isResponse()); assertFalse(inboundMessage.isError()); @@ -208,7 +207,7 @@ private void testVersionIncompatibility(Version version, Version currentVersion, String action = randomAlphaOfLength(10); long requestId = randomLong(); boolean compress = randomBoolean(); - OutboundMessage.Request request = new OutboundMessage.Request(threadContext, features, message, version, action, requestId, + OutboundMessage.Request request = new OutboundMessage.Request(threadContext, message, version, action, requestId, isHandshake, compress); BytesReference reference; try (BytesStreamOutput streamOutput = new BytesStreamOutput()) { diff --git a/server/src/test/java/org/elasticsearch/transport/OutboundHandlerTests.java b/server/src/test/java/org/elasticsearch/transport/OutboundHandlerTests.java index 963ba63e1c3e8..b15d444e24061 100644 --- a/server/src/test/java/org/elasticsearch/transport/OutboundHandlerTests.java +++ b/server/src/test/java/org/elasticsearch/transport/OutboundHandlerTests.java @@ -45,13 +45,10 @@ import java.util.concurrent.atomic.AtomicLong; import java.util.concurrent.atomic.AtomicReference; -import static org.hamcrest.Matchers.contains; import static org.hamcrest.Matchers.instanceOf; public class OutboundHandlerTests extends ESTestCase { - private final String feature1 = "feature1"; - private final String feature2 = "feature2"; private final TestThreadPool threadPool = new TestThreadPool(getClass().getName()); private final NamedWriteableRegistry namedWriteableRegistry = new NamedWriteableRegistry(Collections.emptyList()); private final TransportRequestOptions options = TransportRequestOptions.EMPTY; @@ -66,8 +63,7 @@ public void setUp() throws Exception { channel = new FakeTcpChannel(randomBoolean(), buildNewFakeTransportAddress().address(), buildNewFakeTransportAddress().address()); TransportAddress transportAddress = buildNewFakeTransportAddress(); node = new DiscoveryNode("", transportAddress, Version.CURRENT); - String[] features = {feature1, feature2}; - handler = new OutboundHandler("node", Version.CURRENT, features, threadPool, BigArrays.NON_RECYCLING_INSTANCE, transportLogger); + handler = new OutboundHandler("node", Version.CURRENT, threadPool, BigArrays.NON_RECYCLING_INSTANCE, transportLogger); } @After @@ -156,7 +152,6 @@ public void onRequestSent(DiscoveryNode node, long requestId, String action, Tra assertFalse(inboundMessage.isCompress()); } InboundMessage.Request inboundRequest = (InboundMessage.Request) inboundMessage; - assertThat(inboundRequest.getFeatures(), contains(feature1, feature2)); Request readMessage = new Request(inboundMessage.getStreamInput()); assertEquals(value, readMessage.value); diff --git a/server/src/test/java/org/elasticsearch/transport/TransportHandshakerTests.java b/server/src/test/java/org/elasticsearch/transport/TransportHandshakerTests.java index 0b5e52009cecd..c0af767132a75 100644 --- a/server/src/test/java/org/elasticsearch/transport/TransportHandshakerTests.java +++ b/server/src/test/java/org/elasticsearch/transport/TransportHandshakerTests.java @@ -81,11 +81,11 @@ public void testHandshakeRequestAndResponse() throws IOException { BytesStreamOutput bytesStreamOutput = new BytesStreamOutput(); handshakeRequest.writeTo(bytesStreamOutput); StreamInput input = bytesStreamOutput.bytes().streamInput(); - handshaker.handleHandshake(Version.CURRENT, Collections.emptySet(), mockChannel, reqId, input); + handshaker.handleHandshake(Version.CURRENT, mockChannel, reqId, input); ArgumentCaptor responseCaptor = ArgumentCaptor.forClass(TransportResponse.class); - verify(responseSender).sendResponse(eq(Version.CURRENT), eq(Collections.emptySet()), eq(mockChannel), responseCaptor.capture(), + verify(responseSender).sendResponse(eq(Version.CURRENT), eq(mockChannel), responseCaptor.capture(), eq(reqId)); TransportResponseHandler handler = handshaker.removeHandlerForHandshake(reqId); @@ -121,12 +121,12 @@ public void testHandshakeRequestFutureVersionsCompatibility() throws IOException // Otherwise, we need to update the test. assertEquals(currentHandshakeBytes.bytes().length(), lengthCheckingHandshake.bytes().length()); assertEquals(1031, futureHandshakeStream.available()); - handshaker.handleHandshake(Version.CURRENT, Collections.emptySet(), mockChannel, reqId, futureHandshakeStream); + handshaker.handleHandshake(Version.CURRENT, mockChannel, reqId, futureHandshakeStream); assertEquals(0, futureHandshakeStream.available()); ArgumentCaptor responseCaptor = ArgumentCaptor.forClass(TransportResponse.class); - verify(responseSender).sendResponse(eq(Version.CURRENT), eq(Collections.emptySet()), eq(mockChannel), responseCaptor.capture(), + verify(responseSender).sendResponse(eq(Version.CURRENT), eq(mockChannel), responseCaptor.capture(), eq(reqId)); TransportHandshaker.HandshakeResponse response = (TransportHandshaker.HandshakeResponse) responseCaptor.getValue(); diff --git a/x-pack/plugin/build.gradle b/x-pack/plugin/build.gradle index 7473977f08da5..210888b87f15b 100644 --- a/x-pack/plugin/build.gradle +++ b/x-pack/plugin/build.gradle @@ -1,9 +1,3 @@ -import org.elasticsearch.gradle.LoggedExec -import org.elasticsearch.gradle.plugin.PluginBuildPlugin -import org.elasticsearch.gradle.test.NodeInfo - -import java.nio.charset.StandardCharsets - apply plugin: 'elasticsearch.testclusters' apply plugin: 'elasticsearch.standalone-rest-test' apply plugin: 'elasticsearch.rest-test' @@ -17,47 +11,6 @@ dependencies { } } -subprojects { - afterEvaluate { - if (project.plugins.hasPlugin(PluginBuildPlugin)) { - // see the root Gradle file for additional logic regarding this configuration - project.configurations.create('featureAwarePlugin') - project.dependencies.add('featureAwarePlugin', project.configurations.compileClasspath) - project.dependencies.add('featureAwarePlugin', project(':x-pack:test:feature-aware')) - project.dependencies.add('featureAwarePlugin', project.sourceSets.main.output.getClassesDirs()) - - File successMarker = file("$buildDir/markers/featureAware") - task featureAwareCheck(type: LoggedExec) { - description = "Runs FeatureAwareCheck on main classes." - dependsOn project.configurations.featureAwarePlugin - outputs.file(successMarker) - - executable = "${project.runtimeJavaHome}/bin/java" - - // default to main class files if such a source set exists - final List files = [] - if (project.sourceSets.findByName("main")) { - files.add(project.sourceSets.main.output.classesDirs) - dependsOn project.tasks.classes - } - // filter out non-existent classes directories from empty source sets - final FileCollection classDirectories = project.files(files).filter { it.exists() } - - doFirst { - args('-cp', project.configurations.featureAwarePlugin.asPath, 'org.elasticsearch.xpack.test.feature_aware.FeatureAwareCheck') - classDirectories.each { args it.getAbsolutePath() } - } - doLast { - successMarker.parentFile.mkdirs() - successMarker.setText("", 'UTF-8') - } - } - - project.precommit.dependsOn featureAwareCheck - } - } -} - // https://github.com/elastic/x-plugins/issues/724 configurations { testArtifacts.extendsFrom testRuntime diff --git a/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/action/ShardFollowTask.java b/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/action/ShardFollowTask.java index 50b32679aee0c..28f06505a0060 100644 --- a/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/action/ShardFollowTask.java +++ b/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/action/ShardFollowTask.java @@ -17,7 +17,7 @@ import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.index.shard.ShardId; -import org.elasticsearch.xpack.core.XPackPlugin; +import org.elasticsearch.persistent.PersistentTaskParams; import org.elasticsearch.xpack.core.ccr.action.ImmutableFollowParameters; import java.io.IOException; @@ -26,7 +26,7 @@ import java.util.Objects; import java.util.Set; -public class ShardFollowTask extends ImmutableFollowParameters implements XPackPlugin.XPackPersistentTaskParams { +public class ShardFollowTask extends ImmutableFollowParameters implements PersistentTaskParams { public static final String NAME = "xpack/ccr/shard_follow_task"; diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/license/LicensesMetaData.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/license/LicensesMetaData.java index f131b24252e5b..26223e1340e0a 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/license/LicensesMetaData.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/license/LicensesMetaData.java @@ -16,7 +16,6 @@ import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.license.License.OperationMode; -import org.elasticsearch.xpack.core.XPackPlugin; import java.io.IOException; import java.util.EnumSet; @@ -24,7 +23,7 @@ /** * Contains metadata about registered licenses */ -public class LicensesMetaData extends AbstractNamedDiffable implements XPackPlugin.XPackMetaDataCustom, +public class LicensesMetaData extends AbstractNamedDiffable implements MetaData.Custom, MergableCustomMetaData { public static final String TYPE = "licenses"; diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/XPackClientPlugin.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/XPackClientPlugin.java index 6384f42eaa2ee..98a69cc09fbf6 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/XPackClientPlugin.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/XPackClientPlugin.java @@ -5,8 +5,8 @@ */ package org.elasticsearch.xpack.core; -import org.elasticsearch.action.ActionType; import org.elasticsearch.action.ActionResponse; +import org.elasticsearch.action.ActionType; import org.elasticsearch.cluster.ClusterState; import org.elasticsearch.cluster.NamedDiff; import org.elasticsearch.cluster.metadata.MetaData; @@ -30,11 +30,11 @@ import org.elasticsearch.plugins.NetworkPlugin; import org.elasticsearch.plugins.Plugin; import org.elasticsearch.tasks.Task; +import org.elasticsearch.xpack.ccr.CCRInfoTransportAction; import org.elasticsearch.xpack.core.action.XPackInfoAction; import org.elasticsearch.xpack.core.action.XPackUsageAction; import org.elasticsearch.xpack.core.beats.BeatsFeatureSetUsage; import org.elasticsearch.xpack.core.ccr.AutoFollowMetadata; -import org.elasticsearch.xpack.ccr.CCRInfoTransportAction; import org.elasticsearch.xpack.core.dataframe.DataFrameFeatureSetUsage; import org.elasticsearch.xpack.core.dataframe.DataFrameField; import org.elasticsearch.xpack.core.dataframe.action.DeleteDataFrameTransformAction; @@ -192,6 +192,11 @@ import org.elasticsearch.xpack.core.security.authc.support.mapper.expressiondsl.RoleMapperExpression; import org.elasticsearch.xpack.core.security.authz.privilege.ConditionalClusterPrivilege; import org.elasticsearch.xpack.core.security.authz.privilege.ConditionalClusterPrivileges; +import org.elasticsearch.xpack.core.snapshotlifecycle.SnapshotLifecycleMetadata; +import org.elasticsearch.xpack.core.snapshotlifecycle.action.DeleteSnapshotLifecycleAction; +import org.elasticsearch.xpack.core.snapshotlifecycle.action.ExecuteSnapshotLifecycleAction; +import org.elasticsearch.xpack.core.snapshotlifecycle.action.GetSnapshotLifecycleAction; +import org.elasticsearch.xpack.core.snapshotlifecycle.action.PutSnapshotLifecycleAction; import org.elasticsearch.xpack.core.spatial.SpatialFeatureSetUsage; import org.elasticsearch.xpack.core.sql.SqlFeatureSetUsage; import org.elasticsearch.xpack.core.ssl.action.GetCertificateInfoAction; @@ -209,11 +214,6 @@ import org.elasticsearch.xpack.core.watcher.transport.actions.put.PutWatchAction; import org.elasticsearch.xpack.core.watcher.transport.actions.service.WatcherServiceAction; import org.elasticsearch.xpack.core.watcher.transport.actions.stats.WatcherStatsAction; -import org.elasticsearch.xpack.core.snapshotlifecycle.SnapshotLifecycleMetadata; -import org.elasticsearch.xpack.core.snapshotlifecycle.action.DeleteSnapshotLifecycleAction; -import org.elasticsearch.xpack.core.snapshotlifecycle.action.ExecuteSnapshotLifecycleAction; -import org.elasticsearch.xpack.core.snapshotlifecycle.action.GetSnapshotLifecycleAction; -import org.elasticsearch.xpack.core.snapshotlifecycle.action.PutSnapshotLifecycleAction; import java.util.ArrayList; import java.util.Arrays; @@ -225,11 +225,6 @@ public class XPackClientPlugin extends Plugin implements ActionPlugin, NetworkPl static Optional X_PACK_FEATURE = Optional.of("x-pack"); - @Override - protected Optional getFeature() { - return X_PACK_FEATURE; - } - private final Settings settings; public XPackClientPlugin(final Settings settings) { diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/XPackPlugin.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/XPackPlugin.java index 0604f409ccd1e..efad81146cdb0 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/XPackPlugin.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/XPackPlugin.java @@ -40,7 +40,6 @@ import org.elasticsearch.license.LicensesMetaData; import org.elasticsearch.license.Licensing; import org.elasticsearch.license.XPackLicenseState; -import org.elasticsearch.persistent.PersistentTaskParams; import org.elasticsearch.plugins.EnginePlugin; import org.elasticsearch.plugins.ExtensiblePlugin; import org.elasticsearch.plugins.RepositoryPlugin; @@ -311,32 +310,6 @@ public static Path resolveConfigFile(Environment env, String name) { return config; } - public interface XPackClusterStateCustom extends ClusterState.Custom { - - @Override - default Optional getRequiredFeature() { - return XPackClientPlugin.X_PACK_FEATURE; - } - - } - - public interface XPackMetaDataCustom extends MetaData.Custom { - - @Override - default Optional getRequiredFeature() { - return XPackClientPlugin.X_PACK_FEATURE; - } - - } - - public interface XPackPersistentTaskParams extends PersistentTaskParams { - - @Override - default Optional getRequiredFeature() { - return XPackClientPlugin.X_PACK_FEATURE; - } - } - @Override public Map getRepositories(Environment env, NamedXContentRegistry namedXContentRegistry, ThreadPool threadPool) { diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ccr/AutoFollowMetadata.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ccr/AutoFollowMetadata.java index b06ba584178c0..f775256272c56 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ccr/AutoFollowMetadata.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ccr/AutoFollowMetadata.java @@ -19,7 +19,6 @@ import org.elasticsearch.common.xcontent.ToXContentObject; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentParser; -import org.elasticsearch.xpack.core.XPackPlugin; import org.elasticsearch.xpack.core.ccr.action.ImmutableFollowParameters; import java.io.IOException; @@ -34,7 +33,7 @@ /** * Custom metadata that contains auto follow patterns and what leader indices an auto follow pattern has already followed. */ -public class AutoFollowMetadata extends AbstractNamedDiffable implements XPackPlugin.XPackMetaDataCustom { +public class AutoFollowMetadata extends AbstractNamedDiffable implements MetaData.Custom { public static final String TYPE = "ccr_auto_follow"; diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/dataframe/transforms/DataFrameTransform.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/dataframe/transforms/DataFrameTransform.java index f7c14b0439ad3..d6e37c80dfe21 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/dataframe/transforms/DataFrameTransform.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/dataframe/transforms/DataFrameTransform.java @@ -15,13 +15,13 @@ import org.elasticsearch.common.xcontent.ConstructingObjectParser; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentParser; -import org.elasticsearch.xpack.core.XPackPlugin; +import org.elasticsearch.persistent.PersistentTaskParams; import org.elasticsearch.xpack.core.dataframe.DataFrameField; import java.io.IOException; import java.util.Objects; -public class DataFrameTransform extends AbstractDiffable implements XPackPlugin.XPackPersistentTaskParams { +public class DataFrameTransform extends AbstractDiffable implements PersistentTaskParams { public static final String NAME = DataFrameField.TASK_NAME; public static final ParseField VERSION = new ParseField(DataFrameField.VERSION); diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/indexlifecycle/IndexLifecycleMetadata.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/indexlifecycle/IndexLifecycleMetadata.java index 161033601ee3f..37348f4a7f2b2 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/indexlifecycle/IndexLifecycleMetadata.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/indexlifecycle/IndexLifecycleMetadata.java @@ -18,7 +18,6 @@ import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.xcontent.ConstructingObjectParser; import org.elasticsearch.common.xcontent.XContentBuilder; -import org.elasticsearch.xpack.core.XPackPlugin.XPackMetaDataCustom; import java.io.IOException; import java.util.Collections; @@ -31,7 +30,7 @@ import java.util.stream.Collectors; -public class IndexLifecycleMetadata implements XPackMetaDataCustom { +public class IndexLifecycleMetadata implements MetaData.Custom { public static final String TYPE = "index_lifecycle"; public static final ParseField OPERATION_MODE_FIELD = new ParseField("operation_mode"); public static final ParseField POLICIES_FIELD = new ParseField("policies"); diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/MlMetadata.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/MlMetadata.java index dfe5560da3303..0781ea31434dc 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/MlMetadata.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/MlMetadata.java @@ -23,7 +23,6 @@ import org.elasticsearch.common.xcontent.ToXContent; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.xpack.core.ClientHelper; -import org.elasticsearch.xpack.core.XPackPlugin; import org.elasticsearch.xpack.core.ml.datafeed.DatafeedConfig; import org.elasticsearch.xpack.core.ml.datafeed.DatafeedJobValidator; import org.elasticsearch.xpack.core.ml.job.config.Job; @@ -44,7 +43,7 @@ import java.util.TreeMap; import java.util.stream.Collectors; -public class MlMetadata implements XPackPlugin.XPackMetaDataCustom { +public class MlMetadata implements MetaData.Custom { public static final String TYPE = "ml"; private static final ParseField JOBS_FIELD = new ParseField("jobs"); diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/action/OpenJobAction.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/action/OpenJobAction.java index 6854e59d8f4ca..63b664c0bd99e 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/action/OpenJobAction.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/action/OpenJobAction.java @@ -24,8 +24,8 @@ import org.elasticsearch.common.xcontent.ToXContentObject; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentParser; +import org.elasticsearch.persistent.PersistentTaskParams; import org.elasticsearch.tasks.Task; -import org.elasticsearch.xpack.core.XPackPlugin; import org.elasticsearch.xpack.core.ml.MachineLearningField; import org.elasticsearch.xpack.core.ml.MlTasks; import org.elasticsearch.xpack.core.ml.job.config.Job; @@ -119,7 +119,7 @@ public String toString() { } } - public static class JobParams implements XPackPlugin.XPackPersistentTaskParams { + public static class JobParams implements PersistentTaskParams { public static final ParseField TIMEOUT = new ParseField("timeout"); public static final ParseField JOB = new ParseField("job"); diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/action/StartDataFrameAnalyticsAction.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/action/StartDataFrameAnalyticsAction.java index 6cc64de34017f..2c782fe851953 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/action/StartDataFrameAnalyticsAction.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/action/StartDataFrameAnalyticsAction.java @@ -23,8 +23,8 @@ import org.elasticsearch.common.xcontent.ToXContentObject; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentParser; +import org.elasticsearch.persistent.PersistentTaskParams; import org.elasticsearch.tasks.Task; -import org.elasticsearch.xpack.core.XPackPlugin; import org.elasticsearch.xpack.core.ml.MlTasks; import org.elasticsearch.xpack.core.ml.dataframe.DataFrameAnalyticsConfig; import org.elasticsearch.xpack.core.ml.job.messages.Messages; @@ -146,7 +146,7 @@ static class RequestBuilder extends ActionRequestBuilder implements XPackPlugin.XPackPersistentTaskParams { +public class RollupJob extends AbstractDiffable implements PersistentTaskParams { public static final String NAME = "xpack/rollup/job"; diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/authc/TokenMetaData.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/authc/TokenMetaData.java index 8d9b9c762e35f..0e41013d69b68 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/authc/TokenMetaData.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/authc/TokenMetaData.java @@ -12,14 +12,13 @@ import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.xcontent.XContentBuilder; -import org.elasticsearch.xpack.core.XPackPlugin; import java.io.IOException; import java.util.Arrays; import java.util.Collections; import java.util.List; -public final class TokenMetaData extends AbstractNamedDiffable implements XPackPlugin.XPackClusterStateCustom { +public final class TokenMetaData extends AbstractNamedDiffable implements ClusterState.Custom { /** * The type of {@link ClusterState} data. diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/snapshotlifecycle/SnapshotLifecycleMetadata.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/snapshotlifecycle/SnapshotLifecycleMetadata.java index 542014b46dbe7..8aedbd9ac135a 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/snapshotlifecycle/SnapshotLifecycleMetadata.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/snapshotlifecycle/SnapshotLifecycleMetadata.java @@ -18,7 +18,6 @@ import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.xcontent.ConstructingObjectParser; import org.elasticsearch.common.xcontent.XContentBuilder; -import org.elasticsearch.xpack.core.XPackPlugin.XPackMetaDataCustom; import org.elasticsearch.xpack.core.indexlifecycle.OperationMode; import java.io.IOException; @@ -36,7 +35,7 @@ * Custom cluster state metadata that stores all the snapshot lifecycle * policies and their associated metadata */ -public class SnapshotLifecycleMetadata implements XPackMetaDataCustom { +public class SnapshotLifecycleMetadata implements MetaData.Custom { public static final String TYPE = "snapshot_lifecycle"; public static final ParseField OPERATION_MODE_FIELD = new ParseField("operation_mode"); diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/watcher/WatcherMetaData.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/watcher/WatcherMetaData.java index bddeb5f5e3281..22dadab830baf 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/watcher/WatcherMetaData.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/watcher/WatcherMetaData.java @@ -14,13 +14,12 @@ import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentParser; -import org.elasticsearch.xpack.core.XPackPlugin; import java.io.IOException; import java.util.EnumSet; import java.util.Objects; -public class WatcherMetaData extends AbstractNamedDiffable implements XPackPlugin.XPackMetaDataCustom { +public class WatcherMetaData extends AbstractNamedDiffable implements MetaData.Custom { public static final String TYPE = "watcher"; diff --git a/x-pack/plugin/sql/build.gradle b/x-pack/plugin/sql/build.gradle index dac38447c78fe..116d5615855df 100644 --- a/x-pack/plugin/sql/build.gradle +++ b/x-pack/plugin/sql/build.gradle @@ -40,7 +40,6 @@ check.dependsOn internalClusterTest dependencies { compileOnly project(path: xpackModule('core'), configuration: 'default') compileOnly(project(':modules:lang-painless')) { - // exclude ASM to not affect featureAware task on Java 10+ exclude group: "org.ow2.asm" } compile project('sql-action') diff --git a/x-pack/test/feature-aware/build.gradle b/x-pack/test/feature-aware/build.gradle deleted file mode 100644 index 9d7f1504418d2..0000000000000 --- a/x-pack/test/feature-aware/build.gradle +++ /dev/null @@ -1,17 +0,0 @@ -apply plugin: 'elasticsearch.build' - -dependencies { - compile 'org.ow2.asm:asm:7.1' - compile project(':server') - compile project(':x-pack:plugin:core') - testCompile project(':test:framework') -} - -forbiddenApisMain.enabled = true - -dependencyLicenses.enabled = false -dependenciesInfo.enabled = false - -jarHell.enabled = false - -thirdPartyAudit.enabled = false diff --git a/x-pack/test/feature-aware/src/main/java/org/elasticsearch/xpack/test/feature_aware/FeatureAwareCheck.java b/x-pack/test/feature-aware/src/main/java/org/elasticsearch/xpack/test/feature_aware/FeatureAwareCheck.java deleted file mode 100644 index e7dae5bdd46be..0000000000000 --- a/x-pack/test/feature-aware/src/main/java/org/elasticsearch/xpack/test/feature_aware/FeatureAwareCheck.java +++ /dev/null @@ -1,179 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License; - * you may not use this file except in compliance with the Elastic License. - */ - -package org.elasticsearch.xpack.test.feature_aware; - -import org.elasticsearch.cluster.ClusterState; -import org.elasticsearch.cluster.metadata.MetaData; -import org.elasticsearch.common.SuppressForbidden; -import org.elasticsearch.persistent.PersistentTaskParams; -import org.elasticsearch.xpack.core.XPackPlugin; -import org.objectweb.asm.ClassReader; - -import java.io.FileNotFoundException; -import java.io.IOException; -import java.io.InputStream; -import java.nio.file.FileVisitResult; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.Paths; -import java.nio.file.SimpleFileVisitor; -import java.nio.file.attribute.BasicFileAttributes; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; -import java.util.Set; -import java.util.TreeSet; -import java.util.function.Consumer; - -/** - * Used in the featureAwareCheck to check for classes in X-Pack that implement customs but do not extend the appropriate marker interface. - */ -public final class FeatureAwareCheck { - - /** - * Check the class directories specified by the arguments for classes in X-Pack that implement customs but do not extend the appropriate - * marker interface that provides a mix-in implementation of {@link ClusterState.FeatureAware#getRequiredFeature()}. - * - * @param args the class directories to check - * @throws IOException if an I/O exception is walking the class directories - */ - public static void main(final String[] args) throws IOException { - systemOutPrintln("checking for custom violations"); - final List violations = new ArrayList<>(); - checkDirectories(violations::add, args); - if (violations.isEmpty()) { - systemOutPrintln("no custom violations found"); - } else { - violations.forEach(violation -> - systemOutPrintln( - "class [" + violation.name + "] implements" - + " [" + violation.interfaceName + " but does not implement" - + " [" + violation.expectedInterfaceName + "]") - ); - throw new IllegalStateException( - "found custom" + (violations.size() == 1 ? "" : "s") + " in X-Pack not extending appropriate X-Pack mix-in"); - } - } - - @SuppressForbidden(reason = "System.out#println") - private static void systemOutPrintln(final String s) { - System.out.println(s); - } - - private static void checkDirectories( - final Consumer callback, - final String... classDirectories) throws IOException { - for (final String classDirectory : classDirectories) { - final Path root = pathsGet(classDirectory); - if (Files.isDirectory(root)) { - Files.walkFileTree(root, new SimpleFileVisitor() { - @Override - public FileVisitResult visitFile(final Path file, final BasicFileAttributes attrs) throws IOException { - if (Files.isRegularFile(file) && file.getFileName().toString().endsWith(".class")) { - try (InputStream in = Files.newInputStream(file)) { - checkClass(in, callback); - } - } - return super.visitFile(file, attrs); - } - }); - } else { - throw new FileNotFoundException("class directory [" + classDirectory + "] should exist"); - } - } - } - - @SuppressForbidden(reason = "Paths#get") - private static Path pathsGet(final String pathString) { - return Paths.get(pathString); - } - - /** - * Represents a feature-aware violation. - */ - static class FeatureAwareViolation { - - final String name; - final String interfaceName; - final String expectedInterfaceName; - - /** - * Constructs a representation of a feature-aware violation. - * - * @param name the name of the custom class - * @param interfaceName the name of the feature-aware interface - * @param expectedInterfaceName the name of the expected mix-in class - */ - FeatureAwareViolation(final String name, final String interfaceName, final String expectedInterfaceName) { - this.name = name; - this.interfaceName = interfaceName; - this.expectedInterfaceName = expectedInterfaceName; - } - - } - - /** - * Loads a class from the specified input stream and checks that if it implements a feature-aware custom then it extends the appropriate - * mix-in interface from X-Pack. If the class does not, then the specified callback is invoked. - * - * @param in the input stream - * @param callback the callback to invoke - * @throws IOException if an I/O exception occurs loading the class hierarchy - */ - static void checkClass(final InputStream in, final Consumer callback) throws IOException { - // the class format only reports declared interfaces so we have to walk the hierarchy looking for all interfaces - final List interfaces = new ArrayList<>(); - ClassReader cr = new ClassReader(in); - final String name = cr.getClassName(); - do { - interfaces.addAll(Arrays.asList(cr.getInterfaces())); - final String superName = cr.getSuperName(); - if ("java/lang/Object".equals(superName)) { - break; - } - cr = new ClassReader(superName); - } while (true); - checkClass(name, interfaces, callback); - } - - private static void checkClass( - final String name, - final List interfaces, - final Consumer callback) { - checkCustomForClass(ClusterState.Custom.class, XPackPlugin.XPackClusterStateCustom.class, name, interfaces, callback); - checkCustomForClass(MetaData.Custom.class, XPackPlugin.XPackMetaDataCustom.class, name, interfaces, callback); - checkCustomForClass(PersistentTaskParams.class, XPackPlugin.XPackPersistentTaskParams.class, name, interfaces, callback); - } - - private static void checkCustomForClass( - final Class interfaceToCheck, - final Class expectedInterface, - final String name, - final List interfaces, - final Consumer callback) { - final Set interfaceSet = new TreeSet<>(interfaces); - final String interfaceToCheckName = formatClassName(interfaceToCheck); - final String expectedXPackInterfaceName = formatClassName(expectedInterface); - if (interfaceSet.contains(interfaceToCheckName) - && name.equals(expectedXPackInterfaceName) == false - && interfaceSet.contains(expectedXPackInterfaceName) == false) { - assert name.startsWith("org/elasticsearch/license") || name.startsWith("org/elasticsearch/xpack"); - callback.accept(new FeatureAwareViolation(name, interfaceToCheckName, expectedXPackInterfaceName)); - } - } - - /** - * Format the specified class to a name in the ASM format replacing all dots in the class name with forward-slashes. - * - * @param clazz the class whose name to format - * @return the formatted class name - */ - static String formatClassName(final Class clazz) { - return clazz.getName().replace(".", "/"); - } - -} diff --git a/x-pack/test/feature-aware/src/test/java/org/elasticsearch/xpack/test/feature_aware/FeatureAwareCheckTests.java b/x-pack/test/feature-aware/src/test/java/org/elasticsearch/xpack/test/feature_aware/FeatureAwareCheckTests.java deleted file mode 100644 index 2dde9efce42bb..0000000000000 --- a/x-pack/test/feature-aware/src/test/java/org/elasticsearch/xpack/test/feature_aware/FeatureAwareCheckTests.java +++ /dev/null @@ -1,323 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License; - * you may not use this file except in compliance with the Elastic License. - */ - -package org.elasticsearch.xpack.test.feature_aware; - -import org.elasticsearch.Version; -import org.elasticsearch.cluster.ClusterState; -import org.elasticsearch.cluster.Diff; -import org.elasticsearch.cluster.metadata.MetaData; -import org.elasticsearch.common.io.stream.StreamOutput; -import org.elasticsearch.common.xcontent.XContentBuilder; -import org.elasticsearch.persistent.PersistentTaskParams; -import org.elasticsearch.test.ESTestCase; -import org.elasticsearch.xpack.core.XPackPlugin; - -import java.io.IOException; -import java.util.EnumSet; -import java.util.concurrent.atomic.AtomicBoolean; -import java.util.function.Consumer; - -import static org.hamcrest.Matchers.equalTo; - -public class FeatureAwareCheckTests extends ESTestCase { - - public void testClusterStateCustomViolation() throws IOException { - runCustomViolationTest( - ClusterStateCustomViolation.class, - getClass(), - ClusterState.Custom.class, - XPackPlugin.XPackClusterStateCustom.class); - } - - public void testClusterStateCustom() throws IOException { - runCustomTest(XPackClusterStateCustom.class, getClass(), ClusterState.Custom.class, XPackPlugin.XPackClusterStateCustom.class); - } - - public void testClusterStateCustomMarkerInterface() throws IOException { - // marker interfaces do not implement the marker interface but should not fail the feature aware check - runCustomTest( - XPackPlugin.XPackClusterStateCustom.class, - XPackPlugin.class, - ClusterState.Custom.class, - XPackPlugin.XPackClusterStateCustom.class); - } - - public void testMetaDataCustomViolation() throws IOException { - runCustomViolationTest(MetaDataCustomViolation.class, getClass(), MetaData.Custom.class, XPackPlugin.XPackMetaDataCustom.class); - } - - public void testMetaDataCustom() throws IOException { - runCustomTest(XPackMetaDataCustom.class, getClass(), MetaData.Custom.class, XPackPlugin.XPackMetaDataCustom.class); - } - - public void testMetaDataCustomMarkerInterface() throws IOException { - // marker interfaces do not implement the marker interface but should not fail the feature aware check - runCustomTest( - XPackPlugin.XPackMetaDataCustom.class, - XPackPlugin.class, - MetaData.Custom.class, - XPackPlugin.XPackMetaDataCustom.class); - } - - public void testPersistentTaskParamsViolation() throws IOException { - runCustomViolationTest( - PersistentTaskParamsViolation.class, - getClass(), - PersistentTaskParams.class, - XPackPlugin.XPackPersistentTaskParams.class); - } - - public void testPersistentTaskParams() throws IOException { - runCustomTest(XPackPersistentTaskParams.class, getClass(), PersistentTaskParams.class, XPackPlugin.XPackPersistentTaskParams.class); - } - - public void testPersistentTaskParamsMarkerInterface() throws IOException { - // marker interfaces do not implement the marker interface but should not fail the feature aware check - runCustomTest( - XPackPlugin.XPackPersistentTaskParams.class, - XPackPlugin.class, - PersistentTaskParams.class, - XPackPlugin.XPackPersistentTaskParams.class); - } - - abstract class ClusterStateCustomFeatureAware implements ClusterState.Custom { - - private final String writeableName; - - ClusterStateCustomFeatureAware(final String writeableName) { - this.writeableName = writeableName; - } - - @Override - public Diff diff(ClusterState.Custom previousState) { - return null; - } - - @Override - public String getWriteableName() { - return writeableName; - } - - @Override - public Version getMinimalSupportedVersion() { - return Version.CURRENT.minimumCompatibilityVersion(); - } - - @Override - public void writeTo(final StreamOutput out) throws IOException { - - } - - @Override - public XContentBuilder toXContent(final XContentBuilder builder, final Params params) throws IOException { - return builder; - } - - } - - class ClusterStateCustomViolation extends ClusterStateCustomFeatureAware { - - ClusterStateCustomViolation() { - super("cluster_state_custom_violation"); - } - } - - class XPackClusterStateCustom extends ClusterStateCustomFeatureAware implements XPackPlugin.XPackClusterStateCustom { - - XPackClusterStateCustom() { - super("x_pack_cluster_state_custom"); - } - - } - - abstract class MetaDataCustomFeatureAware implements MetaData.Custom { - - private final String writeableName; - - MetaDataCustomFeatureAware(final String writeableName) { - this.writeableName = writeableName; - } - - @Override - public EnumSet context() { - return MetaData.ALL_CONTEXTS; - } - - @Override - public Diff diff(MetaData.Custom previousState) { - return null; - } - - @Override - public String getWriteableName() { - return writeableName; - } - - @Override - public Version getMinimalSupportedVersion() { - return Version.CURRENT.minimumCompatibilityVersion(); - } - - @Override - public void writeTo(final StreamOutput out) throws IOException { - - } - - @Override - public XContentBuilder toXContent(final XContentBuilder builder, final Params params) throws IOException { - return builder; - } - - } - - class MetaDataCustomViolation extends MetaDataCustomFeatureAware { - - MetaDataCustomViolation() { - super("meta_data_custom_violation"); - } - - } - - class XPackMetaDataCustom extends MetaDataCustomFeatureAware implements XPackPlugin.XPackMetaDataCustom { - - XPackMetaDataCustom() { - super("x_pack_meta_data_custom"); - } - - } - - abstract class PersistentTaskParamsFeatureAware implements PersistentTaskParams { - - private final String writeableName; - - PersistentTaskParamsFeatureAware(final String writeableName) { - this.writeableName = writeableName; - } - - @Override - public String getWriteableName() { - return writeableName; - } - - @Override - public Version getMinimalSupportedVersion() { - return Version.CURRENT.minimumCompatibilityVersion(); - } - - @Override - public void writeTo(final StreamOutput out) throws IOException { - - } - - @Override - public XContentBuilder toXContent(final XContentBuilder builder, final Params params) throws IOException { - return builder; - } - - } - - class PersistentTaskParamsViolation extends PersistentTaskParamsFeatureAware { - - PersistentTaskParamsViolation() { - super("persistent_task_params_violation"); - } - - } - - class XPackPersistentTaskParams extends PersistentTaskParamsFeatureAware implements XPackPlugin.XPackPersistentTaskParams { - - XPackPersistentTaskParams() { - super("x_pack_persistent_task_params"); - } - - } - - private class FeatureAwareViolationConsumer implements Consumer { - - private final AtomicBoolean called = new AtomicBoolean(); - private final String name; - private final String interfaceName; - private final String expectedInterfaceName; - - FeatureAwareViolationConsumer(final String name, final String interfaceName, final String expectedInterfaceName) { - this.name = name; - this.interfaceName = interfaceName; - this.expectedInterfaceName = expectedInterfaceName; - } - - @Override - public void accept(final org.elasticsearch.xpack.test.feature_aware.FeatureAwareCheck.FeatureAwareViolation featureAwareViolation) { - called.set(true); - assertThat(featureAwareViolation.name, equalTo(name)); - assertThat(featureAwareViolation.interfaceName, equalTo(interfaceName)); - assertThat(featureAwareViolation.expectedInterfaceName, equalTo(expectedInterfaceName)); - } - - } - - /** - * Runs a test on an actual class implementing a custom interface and not the expected marker interface. - * - * @param clazz the custom implementation - * @param outerClazz the outer class to load the custom implementation relative to - * @param interfaceClazz the custom - * @param expectedInterfaceClazz the marker interface - * @throws IOException if an I/O error occurs reading the class - */ - private void runCustomViolationTest( - final Class clazz, - final Class outerClazz, - final Class interfaceClazz, - final Class expectedInterfaceClazz) throws IOException { - runTest(clazz, outerClazz, interfaceClazz, expectedInterfaceClazz, true); - } - - /** - * Runs a test on an actual class implementing a custom interface and the expected marker interface. - * - * @param clazz the custom implementation - * @param outerClazz the outer class to load the custom implementation relative to - * @param interfaceClazz the custom - * @param expectedInterfaceClazz the marker interface - * @throws IOException if an I/O error occurs reading the class - */ - private void runCustomTest( - final Class clazz, - final Class outerClazz, - final Class interfaceClazz, - final Class expectedInterfaceClazz) throws IOException { - runTest(clazz, outerClazz, interfaceClazz, expectedInterfaceClazz, false); - } - - /** - * Runs a test on an actual class implementing a custom interface and should implement the expected marker interface if and only if - * the specified violation parameter is false. - * - * @param clazz the custom implementation - * @param outerClazz the outer class to load the custom implementation relative to - * @param interfaceClazz the custom - * @param expectedInterfaceClazz the marker interface - * @param violation whether or not the actual class is expected to fail the feature aware check - * @throws IOException if an I/O error occurs reading the class - */ - private void runTest( - final Class clazz, - final Class outerClazz, - final Class interfaceClazz, - final Class expectedInterfaceClazz, - final boolean violation) throws IOException { - final String name = clazz.getName(); - final FeatureAwareViolationConsumer callback = - new FeatureAwareViolationConsumer( - FeatureAwareCheck.formatClassName(clazz), - FeatureAwareCheck.formatClassName(interfaceClazz), - FeatureAwareCheck.formatClassName(expectedInterfaceClazz)); - FeatureAwareCheck.checkClass(outerClazz.getResourceAsStream(name.substring(1 + name.lastIndexOf(".")) + ".class"), callback); - assertThat(callback.called.get(), equalTo(violation)); - } - -} From 76a6de7239c1682330d19e2d841fc5f57d2857e9 Mon Sep 17 00:00:00 2001 From: Jason Tedor Date: Sun, 28 Jul 2019 09:47:35 +0900 Subject: [PATCH 2/5] Carry over javadoc --- .../common/io/stream/VersionedNamedWriteable.java | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/server/src/main/java/org/elasticsearch/common/io/stream/VersionedNamedWriteable.java b/server/src/main/java/org/elasticsearch/common/io/stream/VersionedNamedWriteable.java index 918192f6555b9..4e35b33b03819 100644 --- a/server/src/main/java/org/elasticsearch/common/io/stream/VersionedNamedWriteable.java +++ b/server/src/main/java/org/elasticsearch/common/io/stream/VersionedNamedWriteable.java @@ -36,6 +36,16 @@ public interface VersionedNamedWriteable extends NamedWriteable { */ Version getMinimalSupportedVersion(); + /** + * Tests whether or not the custom should be serialized. The criteria is the output stream must be at least the minimum supported + * version of the custom. That is, we only serialize customs to clients than can understand the custom based on the version of the + * client. + * + * @param out the output stream + * @param custom the custom to serialize + * @param the type of the custom + * @return true if the custom should be serialized and false otherwise + */ static boolean shouldSerialize(final StreamOutput out, final T custom) { return out.getVersion().onOrAfter(custom.getMinimalSupportedVersion()); } From 8576d0357b0b3c1cdc87aa01dc5f724e75435b8d Mon Sep 17 00:00:00 2001 From: Jason Tedor Date: Sun, 28 Jul 2019 10:12:43 +0900 Subject: [PATCH 3/5] Fix transport logger --- .../java/org/elasticsearch/transport/TransportLogger.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/server/src/main/java/org/elasticsearch/transport/TransportLogger.java b/server/src/main/java/org/elasticsearch/transport/TransportLogger.java index 770554477b684..4f7af505de5a7 100644 --- a/server/src/main/java/org/elasticsearch/transport/TransportLogger.java +++ b/server/src/main/java/org/elasticsearch/transport/TransportLogger.java @@ -97,8 +97,10 @@ private String format(TcpChannel channel, BytesReference message, String event) try (ThreadContext context = new ThreadContext(Settings.EMPTY)) { context.readHeaders(streamInput); } - // now we decode the features - streamInput.readStringArray(); + if (streamInput.getVersion().before(Version.V_8_0_0)) { + // discard the features + streamInput.readStringArray(); + } sb.append(", action: ").append(streamInput.readString()); } sb.append(']'); From 5daeff95365b983232223fbbaf1674e806eef25d Mon Sep 17 00:00:00 2001 From: Jason Tedor Date: Sun, 28 Jul 2019 12:47:24 +0900 Subject: [PATCH 4/5] Fix serialization --- .../main/java/org/elasticsearch/transport/InboundMessage.java | 2 +- .../main/java/org/elasticsearch/transport/OutboundMessage.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/server/src/main/java/org/elasticsearch/transport/InboundMessage.java b/server/src/main/java/org/elasticsearch/transport/InboundMessage.java index 641f862f70385..681e6144ed05b 100644 --- a/server/src/main/java/org/elasticsearch/transport/InboundMessage.java +++ b/server/src/main/java/org/elasticsearch/transport/InboundMessage.java @@ -92,7 +92,7 @@ InboundMessage deserialize(BytesReference reference) throws IOException { InboundMessage message; if (TransportStatus.isRequest(status)) { - if (streamInput.getVersion().before(Version.V_8_0_0)) { + if (remoteVersion.before(Version.V_8_0_0)) { // discard features streamInput.readStringArray(); } diff --git a/server/src/main/java/org/elasticsearch/transport/OutboundMessage.java b/server/src/main/java/org/elasticsearch/transport/OutboundMessage.java index 3e376534fdf17..7653ff6b59b90 100644 --- a/server/src/main/java/org/elasticsearch/transport/OutboundMessage.java +++ b/server/src/main/java/org/elasticsearch/transport/OutboundMessage.java @@ -93,7 +93,7 @@ static class Request extends OutboundMessage { @Override protected BytesReference writeMessage(CompressibleBytesOutputStream out) throws IOException { - if (out.getVersion().before(Version.V_8_0_0)) { + if (version.before(Version.V_8_0_0)) { // empty features array out.writeStringArray(Strings.EMPTY_ARRAY); } From ec45d9e54e0689ef76f2029ea806eed140784a72 Mon Sep 17 00:00:00 2001 From: Jason Tedor Date: Sun, 28 Jul 2019 13:14:55 +0900 Subject: [PATCH 5/5] Fix serialization in test --- .../java/org/elasticsearch/transport/TransportLoggerTests.java | 1 - 1 file changed, 1 deletion(-) diff --git a/server/src/test/java/org/elasticsearch/transport/TransportLoggerTests.java b/server/src/test/java/org/elasticsearch/transport/TransportLoggerTests.java index 8187ceba19824..45145c47f2d0c 100644 --- a/server/src/test/java/org/elasticsearch/transport/TransportLoggerTests.java +++ b/server/src/test/java/org/elasticsearch/transport/TransportLoggerTests.java @@ -95,7 +95,6 @@ private BytesReference buildRequest() throws IOException { try (ThreadContext context = new ThreadContext(Settings.EMPTY)) { context.writeTo(messageOutput); } - messageOutput.writeStringArray(new String[0]); messageOutput.writeString(ClusterStatsAction.NAME); new ClusterStatsRequest().writeTo(messageOutput); BytesReference messageBody = messageOutput.bytes();