Skip to content

Allow integrationTestFramework to use new constructor of Node that accepts pluginInfos #5321

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

Merged
merged 4 commits into from
May 8, 2025
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
2 changes: 2 additions & 0 deletions sample-resource-plugin/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ configurations.all {
force 'org.apache.httpcomponents:httpclient:4.5.14'
force 'org.apache.httpcomponents:httpcore:4.4.16'
force 'commons-codec:commons-codec:1.18.0'
force 'org.hamcrest:hamcrest:2.2'
force 'org.mockito:mockito-core:5.17.0'
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,13 @@
import java.util.Collections;

import org.opensearch.common.settings.Settings;
import org.opensearch.plugins.Plugin;
import org.opensearch.plugins.PluginInfo;

public class PluginAwareNode extends Node {

private final boolean clusterManagerEligible;

public PluginAwareNode(
boolean clusterManagerEligible,
final Settings preparedSettings,
final Collection<Class<? extends Plugin>> plugins
) {
public PluginAwareNode(boolean clusterManagerEligible, final Settings preparedSettings, final Collection<PluginInfo> plugins) {
super(
InternalSettingsPreparer.prepareEnvironment(preparedSettings, Collections.emptyMap(), null, () -> System.getenv("HOSTNAME")),
plugins,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
import org.opensearch.common.settings.Settings;
import org.opensearch.node.PluginAwareNode;
import org.opensearch.plugins.Plugin;
import org.opensearch.plugins.PluginInfo;
import org.opensearch.security.action.configupdate.ConfigUpdateAction;
import org.opensearch.security.action.configupdate.ConfigUpdateRequest;
import org.opensearch.security.action.configupdate.ConfigUpdateResponse;
Expand Down Expand Up @@ -84,6 +85,7 @@ public class LocalCluster extends ExternalResource implements AutoCloseable, Ope
private boolean sslOnly;

private final List<Class<? extends Plugin>> plugins;
private final List<PluginInfo> additionalPlugins;
private final ClusterManager clusterManager;
private final TestSecurityConfig testSecurityConfig;
private Map<Integer, Settings> nodeSpecificOverride;
Expand All @@ -107,6 +109,7 @@ private LocalCluster(
Settings nodeOverride,
ClusterManager clusterManager,
List<Class<? extends Plugin>> plugins,
List<PluginInfo> additionalPlugins,
TestCertificates testCertificates,
List<LocalCluster> clusterDependencies,
Map<String, LocalCluster> remotes,
Expand All @@ -116,6 +119,7 @@ private LocalCluster(
Integer expectedNodeStartupCount
) {
this.plugins = plugins;
this.additionalPlugins = additionalPlugins;
this.testCertificates = testCertificates;
this.clusterManager = clusterManager;
this.testSecurityConfig = testSgConfig;
Expand Down Expand Up @@ -247,6 +251,7 @@ private void start() {
clusterManager,
nodeSettingsSupplier,
plugins,
additionalPlugins,
testCertificates,
expectedNodeStartupCount
);
Expand Down Expand Up @@ -326,6 +331,7 @@ public static class Builder {
private boolean sslOnly = false;
private Integer expectedNodeStartupCount;
private final List<Class<? extends Plugin>> plugins = new ArrayList<>();
private final List<PluginInfo> additionalPlugins = new ArrayList<>();
private Map<String, LocalCluster> remoteClusters = new HashMap<>();
private List<LocalCluster> clusterDependencies = new ArrayList<>();
private List<TestIndex> testIndices = new ArrayList<>();
Expand Down Expand Up @@ -423,6 +429,16 @@ public final Builder plugin(Class<? extends Plugin>... plugins) {
return this;
}

/**
* Adds additional plugins to the cluster
*/
@SafeVarargs
public final Builder plugin(PluginInfo... plugins) {
this.additionalPlugins.addAll(List.of(plugins));

return this;
}

public Builder authFailureListeners(AuthFailureListeners listener) {
testSecurityConfig.authFailureListeners(listener);
return this;
Expand Down Expand Up @@ -584,6 +600,7 @@ public LocalCluster build() {
settings,
clusterManager,
plugins,
additionalPlugins,
testCertificates,
clusterDependencies,
remoteClusters,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import org.opensearch.Version;
import org.opensearch.action.admin.cluster.health.ClusterHealthResponse;
import org.opensearch.cluster.health.ClusterHealthStatus;
import org.opensearch.common.settings.Settings;
Expand All @@ -63,6 +64,7 @@
import org.opensearch.http.BindHttpException;
import org.opensearch.node.PluginAwareNode;
import org.opensearch.plugins.Plugin;
import org.opensearch.plugins.PluginInfo;
import org.opensearch.test.framework.certificate.TestCertificates;
import org.opensearch.test.framework.cluster.ClusterManager.NodeSettings;
import org.opensearch.transport.BindTransportException;
Expand Down Expand Up @@ -94,7 +96,8 @@ public class LocalOpenSearchCluster {
private final String clusterName;
private final ClusterManager clusterManager;
private final NodeSettingsSupplier nodeSettingsSupplier;
private final List<Class<? extends Plugin>> additionalPlugins;
private final List<Class<? extends Plugin>> plugins;
private final List<PluginInfo> additionalPlugins;
private final List<Node> nodes = new ArrayList<>();
private final TestCertificates testCertificates;
private final Integer expectedNodeStartupCount;
Expand All @@ -112,13 +115,15 @@ public LocalOpenSearchCluster(
String clusterName,
ClusterManager clusterManager,
NodeSettingsSupplier nodeSettingsSupplier,
List<Class<? extends Plugin>> additionalPlugins,
List<Class<? extends Plugin>> plugins,
List<PluginInfo> additionalPlugins,
TestCertificates testCertificates,
Integer expectedNodeStartCount
) {
this.clusterName = clusterName;
this.clusterManager = clusterManager;
this.nodeSettingsSupplier = nodeSettingsSupplier;
this.plugins = plugins;
this.additionalPlugins = additionalPlugins;
this.testCertificates = testCertificates;
this.expectedNodeStartupCount = expectedNodeStartCount;
Expand Down Expand Up @@ -426,8 +431,24 @@ public int nodeNumber() {

CompletableFuture<StartStage> start() {
CompletableFuture<StartStage> completableFuture = new CompletableFuture<>();
final Collection<Class<? extends Plugin>> mergedPlugins = nodeSettings.pluginsWithAddition(additionalPlugins);
this.node = new PluginAwareNode(nodeSettings.containRole(NodeRole.CLUSTER_MANAGER), getOpenSearchSettings(), mergedPlugins);
final Collection<Class<? extends Plugin>> mergedPlugins = nodeSettings.pluginsWithAddition(plugins);
final List<PluginInfo> classpathPlugins = mergedPlugins.stream()
.map(
p -> new PluginInfo(
p.getName(),
"classpath plugin",
"NA",
Version.CURRENT,
"1.8",
p.getName(),
null,
Collections.emptyList(),
false
)
)
.collect(Collectors.toList());
classpathPlugins.addAll(additionalPlugins);
this.node = new PluginAwareNode(nodeSettings.containRole(NodeRole.CLUSTER_MANAGER), getOpenSearchSettings(), classpathPlugins);

new Thread(new Runnable() {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2300,10 +2300,11 @@ private void tryAddSecurityProvider() {
@Override
public void loadExtensions(ExtensiblePlugin.ExtensionLoader loader) {

if (settings.getAsBoolean(
FeatureConfigConstants.OPENSEARCH_RESOURCE_SHARING_ENABLED,
FeatureConfigConstants.OPENSEARCH_RESOURCE_SHARING_ENABLED_DEFAULT
)) {
if (settings != null
&& settings.getAsBoolean(
FeatureConfigConstants.OPENSEARCH_RESOURCE_SHARING_ENABLED,
FeatureConfigConstants.OPENSEARCH_RESOURCE_SHARING_ENABLED_DEFAULT
)) {
// load all resource-sharing extensions
Set<ResourceSharingExtension> resourceSharingExtensions = new HashSet<>(loader.loadExtensions(ResourceSharingExtension.class));
resourcePluginInfo.setResourceSharingExtensions(resourceSharingExtensions);
Expand Down
18 changes: 17 additions & 1 deletion src/test/java/org/opensearch/node/PluginAwareNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,10 @@
import java.util.Collection;
import java.util.Collections;

import org.opensearch.Version;
import org.opensearch.common.settings.Settings;
import org.opensearch.plugins.Plugin;
import org.opensearch.plugins.PluginInfo;

public class PluginAwareNode extends Node {

Expand All @@ -43,7 +45,21 @@ public PluginAwareNode(
) {
super(
InternalSettingsPreparer.prepareEnvironment(preparedSettings, Collections.emptyMap(), null, () -> System.getenv("HOSTNAME")),
plugins,
plugins.stream()
.map(
p -> new PluginInfo(
p.getName(),
"classpath plugin",
"NA",
Version.CURRENT,
"1.8",
p.getName(),
null,
Collections.emptyList(),
false
)
)
.toList(),
true
);
this.clusterManagerEligible = clusterManagerEligible;
Expand Down
Loading