org.opensearch.gradle.test.DistroTestPlugin Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of build-tools Show documentation
Show all versions of build-tools Show documentation
OpenSearch subproject :build-tools
/*
* SPDX-License-Identifier: Apache-2.0
*
* The OpenSearch Contributors require contributions made to
* this file be licensed under the Apache-2.0 license or a
* compatible open source license.
*/
/*
* 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.
*/
/*
* Modifications Copyright OpenSearch Contributors. See
* GitHub history for details.
*/
package org.opensearch.gradle.test;
import org.opensearch.gradle.Architecture;
import org.opensearch.gradle.DistributionDownloadPlugin;
import org.opensearch.gradle.JavaPackageType;
import org.opensearch.gradle.Jdk;
import org.opensearch.gradle.JdkDownloadPlugin;
import org.opensearch.gradle.OpenSearchDistribution;
import org.opensearch.gradle.SystemPropertyCommandLineArgumentProvider;
import org.opensearch.gradle.Version;
import org.opensearch.gradle.VersionProperties;
import org.opensearch.gradle.docker.DockerSupportPlugin;
import org.opensearch.gradle.docker.DockerSupportService;
import org.opensearch.gradle.info.BuildParams;
import org.opensearch.gradle.internal.InternalDistributionDownloadPlugin;
import org.opensearch.gradle.util.GradleUtils;
import org.opensearch.gradle.util.Util;
import org.opensearch.gradle.vagrant.VagrantBasePlugin;
import org.opensearch.gradle.vagrant.VagrantExtension;
import org.opensearch.gradle.vagrant.VagrantMachine;
import org.gradle.api.Action;
import org.gradle.api.NamedDomainObjectContainer;
import org.gradle.api.Plugin;
import org.gradle.api.Project;
import org.gradle.api.Task;
import org.gradle.api.artifacts.Configuration;
import org.gradle.api.artifacts.dsl.DependencyHandler;
import org.gradle.api.plugins.JavaBasePlugin;
import org.gradle.api.provider.Provider;
import org.gradle.api.specs.Specs;
import org.gradle.api.tasks.Copy;
import org.gradle.api.tasks.TaskProvider;
import org.gradle.api.tasks.testing.Test;
import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import java.util.function.Supplier;
import java.util.stream.Stream;
public class DistroTestPlugin implements Plugin {
private static final String SYSTEM_JDK_VERSION = "21.0.4+7";
private static final String SYSTEM_JDK_VENDOR = "adoptium";
private static final String GRADLE_JDK_VERSION = "21.0.4+7";
private static final String GRADLE_JDK_VENDOR = "adoptium";
// all distributions used by distro tests. this is temporary until tests are per distribution
private static final String EXAMPLE_PLUGIN_CONFIGURATION = "examplePlugin";
private static final String IN_VM_SYSPROP = "tests.inVM";
private static final String DISTRIBUTION_SYSPROP = "tests.distribution";
private static final String BWC_DISTRIBUTION_SYSPROP = "tests.bwc-distribution";
private static final String EXAMPLE_PLUGIN_SYSPROP = "tests.example-plugin";
@Override
public void apply(Project project) {
project.getRootProject().getPluginManager().apply(DockerSupportPlugin.class);
project.getPlugins().apply(InternalDistributionDownloadPlugin.class);
project.getPlugins().apply(JdkDownloadPlugin.class);
project.getPluginManager().apply("opensearch.build");
Provider dockerSupport = GradleUtils.getBuildService(
project.getGradle().getSharedServices(),
DockerSupportPlugin.DOCKER_SUPPORT_SERVICE_NAME
);
// TODO: it would be useful to also have the SYSTEM_JAVA_HOME setup in the root project, so that running from GCP only needs
// a java for gradle to run, and the tests are self sufficient and consistent with the java they use
NamedDomainObjectContainer allDistributions = DistributionDownloadPlugin.getContainer(project);
List testDistributions = configureDistributions(project);
Map> lifecycleTasks = lifecycleTasks(project, "destructiveDistroTest");
Map> versionTasks = versionTasks(project, "destructiveDistroUpgradeTest");
TaskProvider destructiveDistroTest = project.getTasks().register("destructiveDistroTest");
Configuration examplePlugin = configureExamplePlugin(project);
List> windowsTestTasks = new ArrayList<>();
Map>> linuxTestTasks = new HashMap<>();
Map>> upgradeTestTasks = new HashMap<>();
Map> depsTasks = new HashMap<>();
for (OpenSearchDistribution distribution : testDistributions) {
String taskname = destructiveDistroTestTaskName(distribution);
TaskProvider> depsTask = project.getTasks().register(taskname + "#deps");
depsTask.configure(t -> t.dependsOn(distribution, examplePlugin));
depsTasks.put(taskname, depsTask);
// Avoid duplicate tasks such as docker registered in lifecycleTasks
if (project.getTasksByName(taskname, false).isEmpty()) {
TaskProvider destructiveTask = configureTestTask(project, taskname, distribution, t -> {
t.onlyIf(t2 -> distribution.isDocker() == false || dockerSupport.get().getDockerAvailability().isAvailable);
addSysprop(t, DISTRIBUTION_SYSPROP, distribution::getFilepath);
addSysprop(t, EXAMPLE_PLUGIN_SYSPROP, () -> examplePlugin.getSingleFile().toString());
t.exclude("**/PackageUpgradeTests.class");
}, depsTask);
if (distribution.getPlatform() == OpenSearchDistribution.Platform.WINDOWS) {
windowsTestTasks.add(destructiveTask);
} else {
linuxTestTasks.computeIfAbsent(distribution.getType(), k -> new ArrayList<>()).add(destructiveTask);
}
destructiveDistroTest.configure(t -> t.dependsOn(destructiveTask));
lifecycleTasks.get(distribution.getType()).configure(t -> t.dependsOn(destructiveTask));
}
if ((distribution.getType() == OpenSearchDistribution.Type.DEB || distribution.getType() == OpenSearchDistribution.Type.RPM)
&& distribution.getBundledJdk() != JavaPackageType.NONE) {
for (Version version : BuildParams.getBwcVersions().getIndexCompatible()) {
if (version.before("6.3.0")) {
continue; // before opening xpack
}
final OpenSearchDistribution bwcDistro;
if (version.equals(Version.fromString(distribution.getVersion()))) {
// this is the same as the distribution we are testing
bwcDistro = distribution;
} else {
bwcDistro = createDistro(
allDistributions,
distribution.getArchitecture(),
distribution.getType(),
distribution.getPlatform(),
distribution.getBundledJdk(),
version.toString()
);
}
String upgradeTaskname = destructiveDistroUpgradeTestTaskName(distribution, version.toString());
TaskProvider> upgradeDepsTask = project.getTasks().register(upgradeTaskname + "#deps");
upgradeDepsTask.configure(t -> t.dependsOn(distribution, bwcDistro));
depsTasks.put(upgradeTaskname, upgradeDepsTask);
TaskProvider upgradeTest = configureTestTask(project, upgradeTaskname, distribution, t -> {
addSysprop(t, DISTRIBUTION_SYSPROP, distribution::getFilepath);
addSysprop(t, BWC_DISTRIBUTION_SYSPROP, bwcDistro::getFilepath);
t.include("**/PackageUpgradeTests.class");
}, upgradeDepsTask);
versionTasks.get(version.toString()).configure(t -> t.dependsOn(upgradeTest));
upgradeTestTasks.computeIfAbsent(version.toString(), k -> new ArrayList<>()).add(upgradeTest);
}
}
}
// setup jdks used by no-jdk tests, and by gradle executing
TaskProvider linuxGradleJdk = createJdk(project, "gradle", GRADLE_JDK_VENDOR, GRADLE_JDK_VERSION, "linux", "x64");
TaskProvider linuxSystemJdk = createJdk(project, "system", SYSTEM_JDK_VENDOR, SYSTEM_JDK_VERSION, "linux", "x64");
TaskProvider windowsGradleJdk = createJdk(project, "gradle", GRADLE_JDK_VENDOR, GRADLE_JDK_VERSION, "windows", "x64");
TaskProvider windowsSystemJdk = createJdk(project, "system", SYSTEM_JDK_VENDOR, SYSTEM_JDK_VERSION, "windows", "x64");
project.subprojects(vmProject -> {
vmProject.getPluginManager().apply(VagrantBasePlugin.class);
TaskProvider gradleJdk = isWindows(vmProject) ? windowsGradleJdk : linuxGradleJdk;
TaskProvider systemJdk = isWindows(vmProject) ? windowsSystemJdk : linuxSystemJdk;
configureVM(vmProject, gradleJdk, systemJdk);
List
© 2015 - 2024 Weber Informatics LLC | Privacy Policy