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

[Backport 2.x] Change extension integration testing to reflect new initialization sequence (#8145) #8588

Merged
Show file tree
Hide file tree
Changes from all 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 @@ -181,8 +181,8 @@ public void setTestDistribution(TestDistribution distribution) {
}

@Override
public void extension(ExtensionsProperties extension) {
nodes.all(each -> each.extension(extension));
public void extension(boolean extensionsEnabled) {
nodes.all(each -> each.extension(extensionsEnabled));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,6 @@
import org.opensearch.gradle.Version;
import org.opensearch.gradle.VersionProperties;
import org.opensearch.gradle.info.BuildParams;
import org.yaml.snakeyaml.DumperOptions;
import org.yaml.snakeyaml.Yaml;
import org.gradle.api.Action;
import org.gradle.api.Named;
import org.gradle.api.NamedDomainObjectContainer;
Expand Down Expand Up @@ -94,7 +92,6 @@
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Scanner;
import java.util.Set;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
Expand Down Expand Up @@ -145,7 +142,7 @@ public class OpenSearchNode implements TestClusterConfiguration {
private final Map<String, Configuration> pluginAndModuleConfigurations = new HashMap<>();
private final List<Provider<File>> plugins = new ArrayList<>();
private final List<Provider<File>> modules = new ArrayList<>();
private final List<ExtensionsProperties> extensions = new ArrayList<>();
private boolean extensionsEnabled = false;
final LazyPropertyMap<String, CharSequence> settings = new LazyPropertyMap<>("Settings", this);
private final LazyPropertyMap<String, CharSequence> keystoreSettings = new LazyPropertyMap<>("Keystore", this);
private final LazyPropertyMap<String, File> keystoreFiles = new LazyPropertyMap<>("Keystore files", this, FileEntry::new);
Expand Down Expand Up @@ -437,39 +434,8 @@ public void module(String moduleProjectPath) {
}

@Override
public void extension(ExtensionsProperties extensions) {
this.extensions.add(extensions);
}

public void writeExtensionFiles() {
try {
// Creates extensions.yml in the target directory
Path destination = getDistroDir().resolve("extensions").resolve("extensions.yml");
if (!Files.exists(getDistroDir().resolve("extensions"))) {
Files.createDirectory(getDistroDir().resolve("extensions"));
}
DumperOptions dumperOptions = new DumperOptions();
TestExtensionsList extensionsList = new TestExtensionsList(this.extensions);
dumperOptions.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK);
Yaml yaml = new Yaml(dumperOptions);
Files.write(destination, yaml.dump(extensionsList).getBytes());

/*
* SnakeYaml creates a Yaml file with an unnecessary line at the top with the class name
* This section of code removes that line while keeping everything else the same.
*/

Scanner scanner = new Scanner(destination);
scanner.nextLine();
StringBuilder extensionsString = new StringBuilder();
while (scanner.hasNextLine()) {
extensionsString.append("\n" + scanner.nextLine());
}
Files.write(destination, extensionsString.toString().getBytes());

} catch (IOException e) {
throw new UncheckedIOException("Failed to write to extensions.yml", e);
}
public void extension(boolean extensionsEnabled) {
this.extensionsEnabled = extensionsEnabled;
}

@Override
Expand Down Expand Up @@ -648,10 +614,6 @@ public synchronized void start() {
}
}

if (!extensions.isEmpty()) {
writeExtensionFiles();
}

logToProcessStdout("Creating " + currentConfig.command + " keystore with password set to [" + keystorePassword + "]");

if (keystorePassword.length() > 0) {
Expand Down Expand Up @@ -937,7 +899,7 @@ private void startOpenSearchProcess() {
environment.clear();
environment.putAll(getOpenSearchEnvironment());

if (!extensions.isEmpty()) {
if (extensionsEnabled) {
environment.put("OPENSEARCH_JAVA_OPTS", "-Dopensearch.experimental.feature.extensions.enabled=true");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public interface TestClusterConfiguration {

void setTestDistribution(TestDistribution distribution);

void extension(ExtensionsProperties extension);
void extension(boolean extensionsEnabled);

void plugin(Provider<RegularFile> plugin);

Expand Down