Skip to content

Commit f6bd947

Browse files
committed
Jack reset this commit
1 parent e23275f commit f6bd947

File tree

12 files changed

+282
-1
lines changed

12 files changed

+282
-1
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the "Elastic License
4+
* 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side
5+
* Public License v 1"; you may not use this file except in compliance with, at
6+
* your election, the "Elastic License 2.0", the "GNU Affero General Public
7+
* License v3.0 only", or the "Server Side Public License, v 1".
8+
*/
9+
10+
package org.elasticsearch.upgrades;
11+
12+
import com.carrotsearch.randomizedtesting.annotations.Name;
13+
import org.apache.logging.log4j.Logger;
14+
15+
public class TVBackportRollingUpgradeIT extends AbstractRollingUpgradeTestCase {
16+
17+
public TVBackportRollingUpgradeIT(@Name("upgradedNodes") int upgradedNodes) {
18+
super(upgradedNodes);
19+
}
20+
// We'd be most interested to see this failing on the patch issue where 9.0 thinks it's ahead of 8.x but it's not.
21+
/*
22+
v2 TV1,TV3,
23+
v3 TV1,TV2,TV3,TV4
24+
25+
*/
26+
public void testTVBackport() {
27+
if (isOldCluster()) {
28+
// TODO: Implement the test for old cluster
29+
} else if (isMixedCluster()) {
30+
// TODO: Test mixed cluster behavior
31+
} else if (isUpgradedCluster()) {
32+
// TODO: Test upgraded cluster behavior
33+
} else {
34+
fail("Unknown cluster state");
35+
}
36+
}
37+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the "Elastic License
4+
* 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side
5+
* Public License v 1"; you may not use this file except in compliance with, at
6+
* your election, the "Elastic License 2.0", the "GNU Affero General Public
7+
* License v3.0 only", or the "Server Side Public License, v 1".
8+
*/
9+
10+
package org.elasticsearch;
11+
12+
import java.util.List;
13+
14+
public abstract class TVAssociations {
15+
public final List<TransportVersion> TVs;
16+
17+
public TVAssociations(List<TransportVersion> TVs) {
18+
if (TVs.isEmpty()) {
19+
throw new IllegalArgumentException("TVAssociations must have at least one TransportVersion");
20+
}
21+
this.TVs = TVs;
22+
// TODO filter out versions we don't know about.
23+
24+
}
25+
26+
public boolean isCompatable(TransportVersion version) {
27+
return version.onOrAfter(TVs.getFirst()) ; // TODO
28+
}
29+
30+
31+
}

server/src/main/java/org/elasticsearch/TransportVersions.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,13 @@
2929
*/
3030
public class TransportVersions {
3131

32+
33+
static final List<TransportVersion> ALL_VERSIONS = new ArrayList<>();
34+
35+
public static void register(TVAssociations version) {
36+
// ALL_VERSIONS.add(version);
37+
}
38+
3239
/*
3340
* NOTE: IntelliJ lies!
3441
* This map is used during class construction, referenced by the registerTransportVersion method.

server/src/main/java/org/elasticsearch/action/ActionModule.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,9 @@
210210
import org.elasticsearch.action.termvectors.TransportMultiTermVectorsAction;
211211
import org.elasticsearch.action.termvectors.TransportShardMultiTermsVectorAction;
212212
import org.elasticsearch.action.termvectors.TransportTermVectorsAction;
213+
import org.elasticsearch.action.tvbackport.RestTVBackportAction;
214+
import org.elasticsearch.action.tvbackport.TVBackportAction;
215+
import org.elasticsearch.action.tvbackport.TransportTVBackportAction;
213216
import org.elasticsearch.action.update.TransportUpdateAction;
214217
import org.elasticsearch.client.internal.node.NodeClient;
215218
import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver;
@@ -809,6 +812,9 @@ public <Request extends ActionRequest, Response extends ActionResponse> void reg
809812
actions.register(GetSynonymRuleAction.INSTANCE, TransportGetSynonymRuleAction.class);
810813
actions.register(DeleteSynonymRuleAction.INSTANCE, TransportDeleteSynonymRuleAction.class);
811814

815+
// Transport Version Backport Testing
816+
actions.register(TVBackportAction.INSTANCE, TransportTVBackportAction.class);
817+
812818
return unmodifiableMap(actions.getRegistry());
813819
}
814820

@@ -1036,6 +1042,9 @@ public void initRestHandlers(Supplier<DiscoveryNodes> nodesInCluster, Predicate<
10361042
registerHandler.accept(new RestPutSynonymRuleAction());
10371043
registerHandler.accept(new RestGetSynonymRuleAction());
10381044
registerHandler.accept(new RestDeleteSynonymRuleAction());
1045+
1046+
// Transport Version Backport Testing
1047+
registerHandler.accept(new RestTVBackportAction());
10391048
}
10401049

10411050
@Override
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the "Elastic License
4+
* 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side
5+
* Public License v 1"; you may not use this file except in compliance with, at
6+
* your election, the "Elastic License 2.0", the "GNU Affero General Public
7+
* License v3.0 only", or the "Server Side Public License, v 1".
8+
*/
9+
10+
package org.elasticsearch.action.tvbackport;
11+
12+
import org.elasticsearch.client.internal.node.NodeClient;
13+
import org.elasticsearch.rest.BaseRestHandler;
14+
import org.elasticsearch.rest.RestRequest;
15+
import org.elasticsearch.rest.action.RestToXContentListener;
16+
17+
import java.io.IOException;
18+
import java.util.List;
19+
20+
public class RestTVBackportAction extends BaseRestHandler {
21+
@Override
22+
public String getName() {
23+
return "_tv_backport_action";
24+
}
25+
26+
@Override
27+
public List<Route> routes() {
28+
return List.of(new Route(RestRequest.Method.GET, "/_tv_backport"));
29+
}
30+
31+
@Override
32+
protected RestChannelConsumer prepareRequest(RestRequest request, NodeClient client) throws IOException {
33+
TVBackportRequest tvBackportRequest = new TVBackportRequest();
34+
// Here you can set any parameters from the request to the tvBackportRequest if needed
35+
return channel -> client.execute(TVBackportAction.INSTANCE, tvBackportRequest, new RestToXContentListener<>(channel));
36+
}
37+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the "Elastic License
4+
* 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side
5+
* Public License v 1"; you may not use this file except in compliance with, at
6+
* your election, the "Elastic License 2.0", the "GNU Affero General Public
7+
* License v3.0 only", or the "Server Side Public License, v 1".
8+
*/
9+
10+
package org.elasticsearch.action.tvbackport;
11+
12+
import org.elasticsearch.action.ActionType;
13+
14+
public class TVBackportAction extends ActionType<TVBackportResponse> {
15+
public static final TVBackportAction INSTANCE = new TVBackportAction();
16+
public static final String NAME = "cluster:monitor/tvbackport";
17+
18+
private TVBackportAction() {
19+
super(NAME);
20+
}
21+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the "Elastic License
4+
* 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side
5+
* Public License v 1"; you may not use this file except in compliance with, at
6+
* your election, the "Elastic License 2.0", the "GNU Affero General Public
7+
* License v3.0 only", or the "Server Side Public License, v 1".
8+
*/
9+
10+
package org.elasticsearch.action.tvbackport;
11+
12+
import org.elasticsearch.action.ActionRequest;
13+
import org.elasticsearch.action.ActionRequestValidationException;
14+
15+
public class TVBackportRequest extends ActionRequest {
16+
17+
@Override
18+
public ActionRequestValidationException validate() {
19+
return null;
20+
}
21+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the "Elastic License
4+
* 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side
5+
* Public License v 1"; you may not use this file except in compliance with, at
6+
* your election, the "Elastic License 2.0", the "GNU Affero General Public
7+
* License v3.0 only", or the "Server Side Public License, v 1".
8+
*/
9+
10+
package org.elasticsearch.action.tvbackport;
11+
12+
import org.elasticsearch.action.ActionResponse;
13+
import org.elasticsearch.common.io.stream.StreamOutput;
14+
import org.elasticsearch.versions.TestTV;
15+
import org.elasticsearch.xcontent.ToXContentObject;
16+
import org.elasticsearch.xcontent.XContentBuilder;
17+
18+
import java.io.IOException;
19+
20+
public class TVBackportResponse extends ActionResponse implements ToXContentObject {
21+
String message;
22+
23+
public TVBackportResponse(String message) {
24+
this.message = message;
25+
}
26+
27+
@Override
28+
public void writeTo(StreamOutput out) throws IOException {
29+
if (TestTV.INSTANCE.isCompatable(out.getTransportVersion()) {
30+
out.writeString("TestTV");
31+
}
32+
out.writeString(message);
33+
34+
}
35+
36+
@Override
37+
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
38+
builder.startObject();
39+
builder.field("message", message);
40+
builder.endObject();
41+
return builder;
42+
}
43+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the "Elastic License
4+
* 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side
5+
* Public License v 1"; you may not use this file except in compliance with, at
6+
* your election, the "Elastic License 2.0", the "GNU Affero General Public
7+
* License v3.0 only", or the "Server Side Public License, v 1".
8+
*/
9+
10+
package org.elasticsearch.action.tvbackport;
11+
12+
import org.apache.logging.log4j.LogManager;
13+
import org.apache.logging.log4j.Logger;
14+
import org.elasticsearch.action.ActionListener;
15+
import org.elasticsearch.action.support.ActionFilters;
16+
import org.elasticsearch.action.support.TransportAction;
17+
import org.elasticsearch.common.util.concurrent.EsExecutors;
18+
import org.elasticsearch.injection.guice.Inject;
19+
import org.elasticsearch.tasks.Task;
20+
import org.elasticsearch.transport.TransportService;
21+
22+
public class TransportTVBackportAction extends TransportAction<TVBackportRequest, TVBackportResponse> {
23+
private static final Logger logger = LogManager.getLogger(TransportTVBackportAction.class);
24+
25+
@Inject
26+
public TransportTVBackportAction(
27+
ActionFilters actionFilters,
28+
TransportService transportService
29+
) {
30+
super(TVBackportAction.NAME, actionFilters, transportService.getTaskManager(), EsExecutors.DIRECT_EXECUTOR_SERVICE);
31+
}
32+
33+
@Override
34+
protected void doExecute(Task task, TVBackportRequest request, ActionListener<TVBackportResponse> listener) {
35+
logger.info("Executing TVBackportAction for request");
36+
listener.onResponse(new TVBackportResponse("This is a TV Backport response"));
37+
}
38+
}

server/src/main/java/org/elasticsearch/common/VersionId.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public interface VersionId<T extends VersionId<T>> extends Comparable<T> {
1616
/**
1717
* The version id this object represents
1818
*/
19-
int id();
19+
int[] id();
2020

2121
default boolean after(T version) {
2222
return version.id() < id();

0 commit comments

Comments
 (0)