Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
breskeby committed Jan 8, 2025
1 parent c18b48d commit 1381499
Show file tree
Hide file tree
Showing 6 changed files with 93 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
import org.gradle.api.tasks.util.PatternFilterable;

import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedHashSet;
import java.util.List;
Expand Down Expand Up @@ -214,15 +215,19 @@ public Void call(Object... args) {
}
});

var processedVersions = new HashSet<Version>();
// Add `usesBwcDistribution(version)` extension method to test tasks to indicate they require a BWC distribution
task.getExtensions().getExtraProperties().set("usesBwcDistribution", new Closure<Void>(task) {
@Override
public Void call(Object... args) {
if (args.length != 1 || args[0] instanceof Version == false) {
throw new IllegalArgumentException("Expected exactly one argument of type org.elasticsearch.gradle.Version");
}

if (processedVersions.contains(args[0])) {
return null;
}
Version version = (Version) args[0];
processedVersions.add(version);
boolean isReleased = bwcVersions.unreleasedInfo(version) == null;
String versionString = version.toString();
ElasticsearchDistribution bwcDistro = createDistribution(project, "bwc_" + versionString, versionString);
Expand Down Expand Up @@ -263,7 +268,10 @@ private ElasticsearchDistribution createDistribution(Project project, String nam
if (maybeDistro == null) {
return distributions.create(name, distro -> {
distro.setVersion(version);
distro.setArchitecture(Architecture.current());
// distro.setArchitecture(Architecture.current());
// distro.setArchitecture(Architecture.current());
distro.setArchitecture(Architecture.X64);
// distro.setPlatform(ElasticsearchDistribution.Platform.LINUX);
if (type != null) {
distro.setType(type);
}
Expand Down
1 change: 1 addition & 0 deletions test/fixtures/old-elasticsearch/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
FROM alpine:3.21.0
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ public synchronized void start(Version version) {
if (usesSecureSecretsFile) {
writeSecureSecretsFile();
} else {
createKeystore();
// createKeystore();
addKeystoreSettings();
addKeystoreFiles();
}
Expand Down Expand Up @@ -280,6 +280,15 @@ public void waitUntilReady() {
try {
Retry.retryUntilTrue(NODE_UP_TIMEOUT, Duration.ofMillis(500), () -> {
if (process.isAlive() == false) {
// try (var reader = process.errorReader()) {
// String line;
// while ((line = reader.readLine()) != null) {
// System.out.println("LINE " + line);
// }
// } catch (IOException e) {
// throw new UncheckedIOException("Error reading output from process.", e);
// }
System.out.println("process.exitValue() = " + process.exitValue());
throw new RuntimeException(
"Elasticsearch process died while waiting for ports file. See console output for details."
);
Expand Down Expand Up @@ -428,9 +437,9 @@ private void writeConfiguration() {
String content = Files.readString(jvmOptionsFile);
Map<String, String> expansions = getJvmOptionsReplacements();
for (String key : expansions.keySet()) {
if (content.contains(key) == false) {
throw new IOException("Template property '" + key + "' not found in template.");
}
// if (content.contains(key) == false) {
// throw new IOException("Template property '" + key + "' not found in template.");
// }
content = content.replace(key, expansions.get(key));
}
Files.writeString(jvmOptionsFile, content);
Expand Down Expand Up @@ -762,6 +771,7 @@ private void startElasticsearch() {
true
);


ProcessReaper.instance().registerPid(getServiceName(), process.pid());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,7 @@ public static Process exec(
processBuilder.environment().putAll(environment);

try {
process = processBuilder.start();

process = processBuilder.inheritIO().start();;
startLoggingThread(
process.getInputStream(),
inheritIO ? System.out::println : PROCESS_LOGGER::info,
Expand Down
12 changes: 11 additions & 1 deletion x-pack/qa/repository-old-versions/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,12 @@ import static org.elasticsearch.gradle.PropertyNormalization.IGNORE_VALUE

apply plugin: 'elasticsearch.jdk-download'
apply plugin: 'elasticsearch.internal-testclusters'
apply plugin: 'elasticsearch.standalone-rest-test'
//apply plugin: 'elasticsearch.standalone-rest-test'
apply plugin: 'elasticsearch.internal-java-rest-test'

apply plugin: 'elasticsearch.rest-resources'


configurations {
oldesFixture
}
Expand Down Expand Up @@ -180,5 +183,12 @@ if (OS.current() == OS.WINDOWS) {
dependsOn "javaRestTestAfterRestart#${versionNoDots}"
}
}

tasks.named("javaRestTest").configure {
dependsOn jdks.legacy
usesBwcDistribution(Version.fromString("7.17.20"))
usesBwcDistribution(Version.fromString("6.0.0"))
environment 'JAVA_HOME', jdks.legacy.javaHomePath
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

package org.elasticsearch.oldrepos.tests;

import org.elasticsearch.client.Request;
import org.elasticsearch.client.Response;
import org.elasticsearch.test.cluster.ElasticsearchCluster;
import org.elasticsearch.test.cluster.local.LocalClusterConfigProvider;
import org.elasticsearch.test.cluster.local.LocalClusterSpecBuilder;
import org.elasticsearch.test.cluster.local.distribution.DistributionType;
import org.elasticsearch.test.cluster.util.Version;
import org.elasticsearch.test.rest.ESRestTestCase;
import org.junit.ClassRule;

import java.io.IOException;

import static org.hamcrest.Matchers.is;

public class OldDistroIT extends ESRestTestCase {

@ClassRule
public static ElasticsearchCluster cluster = ElasticsearchCluster.local()
// .version(Version.fromString("7.17.20"))
.version(Version.fromString("6.0.0"))
.distribution(DistributionType.DEFAULT)
.setting("xpack.security.enabled", "false")
.setting("xpack.ml.enabled", "false")
.apply(builder -> {
if (System.getenv("JAVA_HOME") != null) {
builder.environment("JAVA_HOME", System.getenv("JAVA_HOME"));
}
})
.build();

@Override
protected String getTestRestCluster() {
return cluster.getHttpAddresses();
}

public void testCreateIndex() throws IOException {
Request request = request("PUT", "/" + "blubb");
Response response = client().performRequest(request);
assertThat(response.getStatusLine().getStatusCode(), is(200));
}

private Request request(String method, String endpoint) {
Request request = new Request(method, endpoint);
request.setOptions(request.getOptions().toBuilder().addHeader("X-elastic-product-origin", "kibana").build());
return request;
}
}

0 comments on commit 1381499

Please sign in to comment.