Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make feature usage version aware #55246

Merged
merged 9 commits into from
Apr 15, 2020
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*/
package org.elasticsearch.xpack.ccr;

import org.elasticsearch.Version;
import org.elasticsearch.action.support.ActionFilters;
import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.io.stream.StreamInput;
Expand Down Expand Up @@ -78,6 +79,11 @@ public Usage(StreamInput in) throws IOException {
}
}

@Override
public Version getMinimalSupportedVersion() {
return Version.V_7_0_0;
}

public int getNumberOfFollowerIndices() {
return numberOfFollowerIndices;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
*/
package org.elasticsearch.xpack.core;

import org.elasticsearch.common.io.stream.NamedWriteable;
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.xcontent.ToXContentObject;
import org.elasticsearch.common.xcontent.XContentBuilder;

Expand All @@ -21,7 +21,7 @@ public interface XPackFeatureSet {

boolean enabled();

abstract class Usage implements ToXContentObject, NamedWriteable {
abstract class Usage implements ToXContentObject, VersionedNamedWriteable {

private static final String AVAILABLE_XFIELD = "available";
private static final String ENABLED_XFIELD = "enabled";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,36 +11,38 @@
import org.elasticsearch.xpack.core.XPackFeatureSet;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;

public class XPackUsageResponse extends ActionResponse {

private List<XPackFeatureSet.Usage> usages;
private final List<XPackFeatureSet.Usage> usages;

public XPackUsageResponse(StreamInput in) throws IOException {
super(in);
int size = in.readVInt();
usages = new ArrayList<>(size);
for (int i = 0; i < size; i++) {
usages.add(in.readNamedWriteable(XPackFeatureSet.Usage.class));
}
public XPackUsageResponse(final List<XPackFeatureSet.Usage> usages) {
this.usages = Objects.requireNonNull(usages);
}

public XPackUsageResponse(List<XPackFeatureSet.Usage> usages) {
this.usages = usages;
public XPackUsageResponse(final StreamInput in) throws IOException {
usages = in.readNamedWriteableList(XPackFeatureSet.Usage.class);
}

public List<XPackFeatureSet.Usage> getUsages() {
return usages;
}

@Override
public void writeTo(StreamOutput out) throws IOException {
out.writeVInt(usages.size());
for (XPackFeatureSet.Usage usage : usages) {
out.writeNamedWriteable(usage);
}
public void writeTo(final StreamOutput out) throws IOException {
// we can only write the usages with version the coordinating node is compatible with otherwise it will not know the named writeable
final List<XPackFeatureSet.Usage> usagesToWrite = usages
.stream()
.filter(usage -> out.getVersion().onOrAfter(usage.getMinimalSupportedVersion()))
.collect(Collectors.toUnmodifiableList());
writeTo(out, usagesToWrite);
}

private static void writeTo(final StreamOutput out, final List<XPackFeatureSet.Usage> usages) throws IOException {
out.writeNamedWriteableList(usages);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ public AnalyticsFeatureSetUsage(StreamInput input) throws IOException {
}
}

@Override
public Version getMinimalSupportedVersion() {
return Version.V_7_4_0;
}

@Override
public void writeTo(StreamOutput out) throws IOException {
super.writeTo(out);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

package org.elasticsearch.xpack.core.eql;

import org.elasticsearch.Version;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.xcontent.XContentBuilder;
Expand All @@ -16,7 +17,7 @@
import java.util.Map;

public class EqlFeatureSetUsage extends XPackFeatureSet.Usage {

private final Map<String, Object> stats;

public EqlFeatureSetUsage(StreamInput in) throws IOException {
Expand Down Expand Up @@ -48,4 +49,10 @@ public void writeTo(StreamOutput out) throws IOException {
super.writeTo(out);
out.writeMap(stats);
}

@Override
public Version getMinimalSupportedVersion() {
return Version.V_7_7_0;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*/
package org.elasticsearch.xpack.core.frozen;

import org.elasticsearch.Version;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.xcontent.XContentBuilder;
Expand All @@ -23,6 +24,11 @@ public FrozenIndicesFeatureSetUsage(StreamInput input) throws IOException {
numberOfFrozenIndices = input.readVInt();
}

@Override
public Version getMinimalSupportedVersion() {
return Version.V_7_0_0;
}

@Override
public void writeTo(StreamOutput out) throws IOException {
super.writeTo(out);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*/
package org.elasticsearch.xpack.core.graph;

import org.elasticsearch.Version;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.xpack.core.XPackFeatureSet;
import org.elasticsearch.xpack.core.XPackField;
Expand All @@ -20,4 +21,10 @@ public GraphFeatureSetUsage(StreamInput input) throws IOException {
public GraphFeatureSetUsage(boolean available, boolean enabled) {
super(XPackField.GRAPH, available, enabled);
}

@Override
public Version getMinimalSupportedVersion() {
return Version.V_7_0_0;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*/
package org.elasticsearch.xpack.core.ilm;

import org.elasticsearch.Version;
import org.elasticsearch.common.ParseField;
import org.elasticsearch.common.Strings;
import org.elasticsearch.common.io.stream.StreamInput;
Expand Down Expand Up @@ -33,6 +34,11 @@ public IndexLifecycleFeatureSetUsage(StreamInput input) throws IOException {
}
}

@Override
public Version getMinimalSupportedVersion() {
return Version.V_7_0_0;
}

@Override
public void writeTo(StreamOutput out) throws IOException {
super.writeTo(out);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*/
package org.elasticsearch.xpack.core.logstash;

import org.elasticsearch.Version;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.xpack.core.XPackFeatureSet;
import org.elasticsearch.xpack.core.XPackField;
Expand All @@ -21,4 +22,9 @@ public LogstashFeatureSetUsage(boolean available, boolean enabled) {
super(XPackField.LOGSTASH, available, enabled);
}

@Override
public Version getMinimalSupportedVersion() {
return Version.V_7_0_0;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,11 @@ public MachineLearningFeatureSetUsage(StreamInput in) throws IOException {
this.nodeCount = in.readInt();
}

@Override
public Version getMinimalSupportedVersion() {
return Version.V_7_0_0;
}

@Override
public void writeTo(StreamOutput out) throws IOException {
super.writeTo(out);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*/
package org.elasticsearch.xpack.core.monitoring;

import org.elasticsearch.Version;
import org.elasticsearch.common.Nullable;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
Expand Down Expand Up @@ -36,6 +37,11 @@ public MonitoringFeatureSetUsage(boolean available, boolean enabled,
this.collectionEnabled = collectionEnabled;
}

@Override
public Version getMinimalSupportedVersion() {
return Version.V_7_0_0;
}

public Map<String, Object> getExporters() {
return exporters == null ? Collections.emptyMap() : Collections.unmodifiableMap(exporters);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*/
package org.elasticsearch.xpack.core.rollup;

import org.elasticsearch.Version;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.xpack.core.XPackFeatureSet;
import org.elasticsearch.xpack.core.XPackField;
Expand All @@ -20,4 +21,10 @@ public RollupFeatureSetUsage(StreamInput input) throws IOException {
public RollupFeatureSetUsage(boolean available, boolean enabled) {
super(XPackField.ROLLUP, available, enabled);
}
}

@Override
public Version getMinimalSupportedVersion() {
return Version.V_7_0_0;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,11 @@ public SecurityFeatureSetUsage(boolean available, boolean enabled, Map<String, O
this.fips140Usage = fips140Usage;
}

@Override
public Version getMinimalSupportedVersion() {
return Version.V_7_0_0;
}

@Override
public void writeTo(StreamOutput out) throws IOException {
super.writeTo(out);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

package org.elasticsearch.xpack.core.slm;

import org.elasticsearch.Version;
import org.elasticsearch.common.Nullable;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
Expand Down Expand Up @@ -37,6 +38,11 @@ public SLMFeatureSetUsage(boolean available, boolean enabled, @Nullable Snapshot
this.slmStats = slmStats;
}

@Override
public Version getMinimalSupportedVersion() {
return Version.V_7_5_0;
}

public SnapshotLifecycleStats getStats() {
return this.slmStats;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

package org.elasticsearch.xpack.core.spatial;

import org.elasticsearch.Version;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.xpack.core.XPackFeatureSet;
Expand All @@ -24,6 +25,11 @@ public SpatialFeatureSetUsage(StreamInput input) throws IOException {
super(input);
}

@Override
public Version getMinimalSupportedVersion() {
return Version.V_7_4_0;
}

@Override
public void writeTo(StreamOutput out) throws IOException {
super.writeTo(out);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

package org.elasticsearch.xpack.core.sql;

import org.elasticsearch.Version;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.xcontent.XContentBuilder;
Expand All @@ -16,7 +17,7 @@
import java.util.Map;

public class SqlFeatureSetUsage extends XPackFeatureSet.Usage {

private final Map<String, Object> stats;

public SqlFeatureSetUsage(StreamInput in) throws IOException {
Expand All @@ -29,6 +30,11 @@ public SqlFeatureSetUsage(boolean available, boolean enabled, Map<String, Object
this.stats = stats;
}

@Override
public Version getMinimalSupportedVersion() {
return Version.V_7_0_0;
}

public Map<String, Object> stats() {
return stats;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

package org.elasticsearch.xpack.core.transform;

import org.elasticsearch.Version;
import org.elasticsearch.cluster.metadata.Metadata;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
Expand Down Expand Up @@ -37,6 +38,11 @@ public TransformFeatureSetUsage(boolean available, boolean enabled, Map<String,
this.accumulatedStats = Objects.requireNonNull(accumulatedStats);
}

@Override
public Version getMinimalSupportedVersion() {
return Version.V_7_5_0;
}

@Override
public void writeTo(StreamOutput out) throws IOException {
super.writeTo(out);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ public void writeTo(StreamOutput out) throws IOException {
out.writeVInt(avgDenseVectorDims);
}

@Override
public Version getMinimalSupportedVersion() {
return Version.V_7_3_0;
}

public VectorsFeatureSetUsage(boolean available, boolean enabled, int numDenseVectorFields, int avgDenseVectorDims) {
super(XPackField.VECTORS, available, enabled);
this.numDenseVectorFields = numDenseVectorFields;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*/
package org.elasticsearch.xpack.core.votingonly;

import org.elasticsearch.Version;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.xpack.core.XPackFeatureSet;
import org.elasticsearch.xpack.core.XPackField;
Expand All @@ -19,4 +20,10 @@ public VotingOnlyNodeFeatureSetUsage(StreamInput input) throws IOException {
public VotingOnlyNodeFeatureSetUsage(boolean available) {
super(XPackField.VOTING_ONLY, available, true);
}

@Override
public Version getMinimalSupportedVersion() {
return Version.V_7_3_0;
}

}
Loading