Skip to content

Commit

Permalink
Change extension integration testing to reflect new initialization se…
Browse files Browse the repository at this point in the history
…quence (#8145) (#8588)

(cherry picked from commit 52a5e3f)

Signed-off-by: Ryan Bogan <[email protected]>
Signed-off-by: Darshit Chanpura <[email protected]>
  • Loading branch information
DarshitChanpura authored Jul 10, 2023
1 parent d9bbdd6 commit 4f5e40b
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 45 deletions.
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

0 comments on commit 4f5e40b

Please sign in to comment.