Skip to content

Commit 1bd696d

Browse files
committed
iter
1 parent d2817fa commit 1bd696d

File tree

13 files changed

+2514
-3531
lines changed

13 files changed

+2514
-3531
lines changed
Lines changed: 5 additions & 134 deletions
Original file line numberDiff line numberDiff line change
@@ -1,138 +1,9 @@
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; you may not use this file except in compliance with the Elastic License
5-
* 2.0.
6-
*/
7-
8-
import org.elasticsearch.gradle.Architecture
9-
import org.elasticsearch.gradle.OS
1+
import org.elasticsearch.gradle.internal.test.RestIntegTestTask
102
import org.elasticsearch.gradle.Version
11-
import org.elasticsearch.gradle.internal.BwcVersions
12-
import org.elasticsearch.gradle.internal.info.BuildParams
13-
import org.elasticsearch.gradle.internal.test.AntFixture
14-
import org.elasticsearch.gradle.testclusters.StandaloneRestIntegTestTask
15-
import org.elasticsearch.gradle.transform.UnzipTransform
16-
import static org.elasticsearch.gradle.PropertyNormalization.IGNORE_VALUE
173

18-
apply plugin: 'elasticsearch.jdk-download'
19-
apply plugin: 'elasticsearch.internal-testclusters'
204
apply plugin: 'elasticsearch.internal-java-rest-test'
21-
apply plugin: 'elasticsearch.internal-yaml-rest-test'
22-
apply plugin: 'elasticsearch.rest-resources'
23-
24-
jdks {
25-
legacy {
26-
vendor = 'adoptium'
27-
version = '8u302+b08'
28-
platform = OS.current().name().toLowerCase()
29-
architecture = Architecture.current().name().toLowerCase()
30-
}
31-
}
32-
33-
restResources {
34-
restApi {
35-
include '_common', 'search'
36-
}
37-
restTests {
38-
includeCore 'search/390_doc_values_search.yml'
39-
}
40-
}
41-
42-
if (OS.current() == OS.MAC && Architecture.current() == Architecture.AARCH64) {
43-
jdks.legacy.vendor = 'zulu'
44-
jdks.legacy.distributionVersion = '8.56.0.23'
45-
}
46-
47-
if (OS.current() == OS.WINDOWS) {
48-
logger.warn("Disabling repository-old-versions tests because we can't get the pid file on windows")
49-
} else {
50-
int currentMajorVersion = org.elasticsearch.gradle.VersionProperties.elasticsearchVersion.major
51-
for (String versionString : ['7.17.25']) {
52-
Version version = Version.fromString(versionString)
53-
String versionNoDots = version.toString().replace('.', '_')
54-
// String configName = "es${versionNoDots}"
55-
56-
// def config = configurations.create(configName)
57-
// config.getAttributes().attribute(ArtifactTypeDefinition.ARTIFACT_TYPE_ATTRIBUTE, ArtifactTypeDefinition.DIRECTORY_TYPE);
58-
// dependencies.add(configName, artifact)
59-
60-
String repoLocation = "${buildDir}/cluster/shared/repo/${versionNoDots}"
61-
String clusterName = versionNoDots
62-
63-
def testClusterProvider = testClusters.register(clusterName) {
64-
testDistribution = 'DEFAULT'
65-
numberOfNodes = 2
66-
versions = [project.version, project.version] // to test full cluster restart
67-
68-
setting 'path.repo', repoLocation, IGNORE_VALUE
69-
setting 'xpack.license.self_generated.type', 'trial'
70-
71-
setting 'xpack.security.enabled', 'true'
72-
user username: 'admin', password: 'admin-password', role: 'superuser'
73-
74-
setting 'xpack.searchable.snapshot.shared_cache.size', '16MB'
75-
setting 'xpack.searchable.snapshot.shared_cache.region_size', '256KB'
76-
}
77-
78-
def oldCluster = testClusters.register("oldES${versionNoDots}Cluster") {
79-
testDistribution = 'DEFAULT'
80-
numberOfNodes = 1
81-
versions = [versionString]
82-
setting 'path.repo', repoLocation, IGNORE_VALUE
83-
setting 'xpack.license.self_generated.type', 'trial'
84-
setting 'xpack.security.enabled', 'true'
85-
user username: 'admin', password: 'admin-password', role: 'superuser'
86-
setting 'xpack.searchable.snapshot.shared_cache.size', '16MB'
87-
setting 'xpack.searchable.snapshot.shared_cache.region_size', '256KB'
88-
}
89-
90-
tasks.register("javaRestTestBeforeRestart#${versionNoDots}", StandaloneRestIntegTestTask) {
91-
useCluster testClusterProvider
92-
useCluster testClusters.named("oldES${versionNoDots}Cluster")
93-
doFirst {
94-
delete(repoLocation)
95-
mkdir(repoLocation)
96-
}
97-
systemProperty 'tests.after_restart', 'false'
98-
}
99-
100-
tasks.register("javaRestTestAfterRestart#${versionNoDots}", StandaloneRestIntegTestTask) {
101-
useCluster testClusterProvider
102-
dependsOn "javaRestTestBeforeRestart#${versionNoDots}"
103-
useCluster testClusters.named("oldES${versionNoDots}Cluster")
104-
systemProperty 'tests.after_restart', 'true'
105-
106-
doFirst {
107-
testClusterProvider.get().goToNextVersion()
108-
}
109-
}
110-
111-
tasks.matching { it.name.startsWith("javaRestTest") && it.name.endsWith(versionNoDots) }.configureEach {
112-
doFirst {
113-
def oldClusterPortProvider = testClusters.named("oldES${versionNoDots}Cluster").map { cluster ->
114-
def local = cluster.allHttpSocketURI.find { it.startsWith("127.0.0.1")}
115-
return local.substring(local.lastIndexOf(':') + 1)
116-
}
117-
it.nonInputProperties.systemProperty "tests.es.port", "${-> oldClusterPortProvider.get()}"
118-
println "oldClusterPortProvider " + oldClusterPortProvider.get()
119-
println "allRemoteAccessPortURI " + testClusters.named("oldES${versionNoDots}Cluster").get().allRemoteAccessPortURI
120-
println "allHttpSocketURI " + testClusters.named("oldES${versionNoDots}Cluster").get().allHttpSocketURI
121-
println "httpSocketURI " + testClusters.named("oldES${versionNoDots}Cluster").get().httpSocketURI
122-
}
123-
it.nonInputProperties.systemProperty "tests.repo.location", repoLocation
124-
it.systemProperty "tests.es.version", version.toString()
125-
126-
/* Use a closure on the string to delay evaluation until right before we
127-
* run the integration tests so that we can be sure that the file is
128-
* ready. */
129-
it.nonInputProperties.systemProperty('tests.rest.cluster', "${-> testClusterProvider.get().allHttpSocketURI.join(",")}")
130-
it.nonInputProperties.systemProperty('tests.clustername', "${-> testClusterProvider.get().getName()}")
131-
}
132-
133-
tasks.named("check").configure {
134-
dependsOn "javaRestTestAfterRestart#${versionNoDots}"
135-
}
136-
}
137-
}
1385

6+
tasks.named("javaRestTest").configure {
7+
usesDefaultDistribution()
8+
usesBwcDistribution(Version.fromString("7.17.25"))
9+
}
Lines changed: 194 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,194 @@
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; you may not use this file except in compliance with the Elastic License
5+
* 2.0.
6+
*/
7+
8+
package org.elasticsearch.oldrepos7x;
9+
10+
import org.apache.http.HttpHost;
11+
import org.elasticsearch.client.Request;
12+
import org.elasticsearch.client.RequestOptions;
13+
import org.elasticsearch.client.RestClient;
14+
import org.elasticsearch.client.WarningsHandler;
15+
import org.elasticsearch.common.Strings;
16+
import org.elasticsearch.common.xcontent.support.XContentMapValues;
17+
import org.elasticsearch.test.cluster.ElasticsearchCluster;
18+
import org.elasticsearch.test.cluster.local.distribution.DistributionType;
19+
import org.elasticsearch.test.cluster.util.Version;
20+
import org.elasticsearch.test.rest.ESRestTestCase;
21+
import org.elasticsearch.xcontent.XContentBuilder;
22+
import org.elasticsearch.xcontent.XContentFactory;
23+
import org.elasticsearch.xcontent.XContentType;
24+
import org.junit.Before;
25+
import org.junit.ClassRule;
26+
import org.junit.rules.RuleChain;
27+
import org.junit.rules.TemporaryFolder;
28+
import org.junit.rules.TestRule;
29+
30+
import java.io.IOException;
31+
import java.util.Arrays;
32+
import java.util.List;
33+
import java.util.Map;
34+
import java.util.stream.Collectors;
35+
36+
public class OldMappingsIT extends ESRestTestCase {
37+
38+
public static TemporaryFolder repoDirectory = new TemporaryFolder();
39+
40+
public static ElasticsearchCluster currentCluster = ElasticsearchCluster.local()
41+
.distribution(DistributionType.DEFAULT)
42+
.distribution(DistributionType.DEFAULT)
43+
.setting("xpack.security.enabled", "false")
44+
.setting("xpack.license.self_generated.type", "trial")
45+
.setting("xpack.ml.enabled", "false")
46+
.setting("path.repo", () -> repoDirectory.getRoot().getPath())
47+
.build();
48+
49+
public static ElasticsearchCluster oldCluster = ElasticsearchCluster.local()
50+
.version(Version.fromString("7.17.25"))
51+
.distribution(DistributionType.DEFAULT)
52+
.setting("xpack.security.enabled", "false")
53+
.setting("xpack.license.self_generated.type", "trial")
54+
.setting("xpack.ml.enabled", "false")
55+
.setting("path.repo", () -> repoDirectory.getRoot().getPath())
56+
.build();
57+
58+
@ClassRule
59+
public static TestRule ruleChain = RuleChain.outerRule(repoDirectory).around(oldCluster).around(currentCluster);
60+
61+
@Override
62+
protected String getTestRestCluster() {
63+
return oldCluster.getHttpAddresses();
64+
}
65+
66+
private Request createIndex(String indexName, String file) throws IOException {
67+
Request createIndex = new Request("PUT", "/" + indexName);
68+
int numberOfShards = randomIntBetween(1, 3);
69+
70+
XContentBuilder builder = XContentFactory.jsonBuilder()
71+
.startObject()
72+
.startObject("settings")
73+
.field("index.number_of_shards", numberOfShards)
74+
.endObject()
75+
.startObject("mappings");
76+
builder.rawValue(getClass().getResourceAsStream(file), XContentType.JSON);
77+
builder.endObject().endObject();
78+
79+
createIndex.setJsonEntity(Strings.toString(builder));
80+
return createIndex;
81+
}
82+
83+
@Before
84+
public void setupIndex() throws IOException {
85+
// String repoLocation = PathUtils.get(System.getProperty("tests.repo.location"))
86+
// .resolve(RandomizedTest.getContext().getTargetClass().getName())
87+
// .toString();
88+
89+
String repoLocation = repoDirectory.getRoot().getPath();
90+
91+
String repoName = "old_mappings_repo";
92+
String snapshotName = "snap";
93+
List<String> indices;
94+
indices = Arrays.asList("filebeat", "custom", "nested");
95+
96+
List<HttpHost> oldClusterHosts = parseClusterHosts(oldCluster.getHttpAddresses());
97+
List<HttpHost> clusterHosts = parseClusterHosts(currentCluster.getHttpAddresses());
98+
// try (RestClient oldEsClient = client()) {
99+
try (
100+
RestClient oldEsClient = RestClient.builder(oldClusterHosts.toArray(new HttpHost[oldClusterHosts.size()])).build();
101+
RestClient esClient = RestClient.builder(clusterHosts.toArray(new HttpHost[clusterHosts.size()])).build();
102+
) {
103+
assertOK(oldEsClient.performRequest(createIndex("filebeat", "filebeat.json")));
104+
105+
assertOK(oldEsClient.performRequest(createIndex("custom", "custom.json")));
106+
assertOK(oldEsClient.performRequest(createIndex("nested", "nested.json")));
107+
108+
Request doc1 = new Request("PUT", "/" + "custom" + "/" + "_doc" + "/" + "1");
109+
doc1.addParameter("refresh", "true");
110+
XContentBuilder bodyDoc1 = XContentFactory.jsonBuilder()
111+
.startObject()
112+
.startObject("apache2")
113+
.startObject("access")
114+
.field("url", "myurl1")
115+
.field("agent", "agent1")
116+
.endObject()
117+
.endObject()
118+
.endObject();
119+
doc1.setJsonEntity(Strings.toString(bodyDoc1));
120+
assertOK(oldEsClient.performRequest(doc1));
121+
122+
Request doc2 = new Request("PUT", "/" + "custom" + "/" + "_doc" + "/" + "2");
123+
doc2.addParameter("refresh", "true");
124+
XContentBuilder bodyDoc2 = XContentFactory.jsonBuilder()
125+
.startObject()
126+
.startObject("apache2")
127+
.startObject("access")
128+
.field("url", "myurl2")
129+
.field("agent", "agent2 agent2")
130+
.endObject()
131+
.endObject()
132+
.field("completion", "some_value")
133+
.endObject();
134+
doc2.setJsonEntity(Strings.toString(bodyDoc2));
135+
assertOK(oldEsClient.performRequest(doc2));
136+
137+
Request doc3 = new Request("PUT", "/" + "nested" + "/" + "_doc" + "/" + "1");
138+
doc3.addParameter("refresh", "true");
139+
XContentBuilder bodyDoc3 = XContentFactory.jsonBuilder()
140+
.startObject()
141+
.field("group", "fans")
142+
.startArray("user")
143+
.startObject()
144+
.field("first", "John")
145+
.field("last", "Smith")
146+
.endObject()
147+
.startObject()
148+
.field("first", "Alice")
149+
.field("last", "White")
150+
.endObject()
151+
.endArray()
152+
.endObject();
153+
doc3.setJsonEntity(Strings.toString(bodyDoc3));
154+
assertOK(oldEsClient.performRequest(doc3));
155+
156+
Request getSettingsRequest = new Request("GET", "/_cluster/settings?include_defaults=true");
157+
Map<String, Object> response = entityAsMap(oldEsClient.performRequest(getSettingsRequest));
158+
assertEquals(repoLocation, ((List<?>) (XContentMapValues.extractValue("defaults.path.repo", response))).get(0));
159+
160+
// register repo on old ES and take snapshot
161+
Request createRepoRequest = new Request("PUT", "/_snapshot/" + repoName);
162+
createRepoRequest.setJsonEntity(Strings.format("""
163+
{"type":"fs","settings":{"location":"%s"}}
164+
""", repoLocation));
165+
assertOK(oldEsClient.performRequest(createRepoRequest));
166+
167+
Request createSnapshotRequest = new Request("PUT", "/_snapshot/" + repoName + "/" + snapshotName);
168+
createSnapshotRequest.addParameter("wait_for_completion", "true");
169+
createSnapshotRequest.setJsonEntity("{\"indices\":\"" + indices.stream().collect(Collectors.joining(",")) + "\"}");
170+
assertOK(oldEsClient.performRequest(createSnapshotRequest));
171+
// }
172+
173+
// register repo on new ES and restore snapshot
174+
Request createRepoRequest2 = new Request("PUT", "/_snapshot/" + repoName);
175+
createRepoRequest2.setJsonEntity(Strings.format("""
176+
{"type":"fs","settings":{"location":"%s"}}
177+
""", repoLocation));
178+
assertOK(esClient.performRequest(createRepoRequest2));
179+
180+
final Request createRestoreRequest = new Request("POST", "/_snapshot/" + repoName + "/" + snapshotName + "/_restore");
181+
createRestoreRequest.addParameter("wait_for_completion", "true");
182+
createRestoreRequest.setJsonEntity("{\"indices\":\"" + indices.stream().collect(Collectors.joining(",")) + "\"}");
183+
createRestoreRequest.setOptions(RequestOptions.DEFAULT.toBuilder().setWarningsHandler(WarningsHandler.PERMISSIVE));
184+
assertOK(esClient.performRequest(createRestoreRequest));
185+
}
186+
}
187+
188+
public void testMappingOk() throws IOException {
189+
// Request mappingRequest = new Request("GET", "/" + "filebeat" + "/_mapping");
190+
// Map<String, Object> mapping = entityAsMap(client().performRequest(mappingRequest));
191+
// assertNotNull(XContentMapValues.extractValue(mapping, "filebeat", "mappings", "properties", "apache2"));
192+
}
193+
194+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
"properties": {
2+
"apache2": {
3+
"properties": {
4+
"access": {
5+
"properties": {
6+
"agent": {
7+
"type": "text"
8+
},
9+
"url": {
10+
"ignore_above": 1024,
11+
"type": "keyword"
12+
}
13+
}
14+
}
15+
}
16+
},
17+
"completion": {
18+
"type": "completion"
19+
}
20+
}
21+

0 commit comments

Comments
 (0)