use of org.opensearch.plugins.Plugin in project OpenSearch by opensearch-project.
the class InternalTestCluster method buildNode.
/**
* builds a new node
*
* @param nodeId node ordinal
* @param settings the settings to use
* @param reuseExisting if a node with the same name is already part of {@link #nodes}, no new node will be built and
* the method will return the existing one
* @param onTransportServiceStarted callback to run when transport service is started
*/
private synchronized NodeAndClient buildNode(int nodeId, Settings settings, boolean reuseExisting, Runnable onTransportServiceStarted) {
assert Thread.holdsLock(this);
ensureOpen();
Collection<Class<? extends Plugin>> plugins = getPlugins();
String name = settings.get("node.name");
final NodeAndClient nodeAndClient = nodes.get(name);
if (reuseExisting && nodeAndClient != null) {
// reusing an existing node implies its transport service already started
onTransportServiceStarted.run();
return nodeAndClient;
}
assert reuseExisting || nodeAndClient == null : "node name [" + name + "] already exists but not allowed to use it";
SecureSettings secureSettings = Settings.builder().put(settings).getSecureSettings();
if (secureSettings instanceof MockSecureSettings) {
// we clone this here since in the case of a node restart we might need it again
secureSettings = ((MockSecureSettings) secureSettings).clone();
}
MockNode node = new MockNode(settings, plugins, nodeConfigurationSource.nodeConfigPath(nodeId), forbidPrivateIndexSettings);
node.injector().getInstance(TransportService.class).addLifecycleListener(new LifecycleListener() {
@Override
public void afterStart() {
onTransportServiceStarted.run();
}
});
try {
IOUtils.close(secureSettings);
} catch (IOException e) {
throw new UncheckedIOException(e);
}
return new NodeAndClient(name, node, settings, nodeId);
}
use of org.opensearch.plugins.Plugin in project OpenSearch by opensearch-project.
the class AbstractMultiClustersTestCase method startClusters.
@Before
public final void startClusters() throws Exception {
if (clusterGroup != null && reuseClusters()) {
return;
}
stopClusters();
final Map<String, InternalTestCluster> clusters = new HashMap<>();
final List<String> clusterAliases = new ArrayList<>(remoteClusterAlias());
clusterAliases.add(LOCAL_CLUSTER);
for (String clusterAlias : clusterAliases) {
final String clusterName = clusterAlias.equals(LOCAL_CLUSTER) ? "main-cluster" : clusterAlias;
final int numberOfNodes = randomIntBetween(1, 3);
final List<Class<? extends Plugin>> mockPlugins = Arrays.asList(MockHttpTransport.TestPlugin.class, MockTransportService.TestPlugin.class, MockNioTransportPlugin.class);
final Collection<Class<? extends Plugin>> nodePlugins = nodePlugins(clusterAlias);
final Settings nodeSettings = Settings.EMPTY;
final NodeConfigurationSource nodeConfigurationSource = nodeConfigurationSource(nodeSettings, nodePlugins);
final InternalTestCluster cluster = new InternalTestCluster(randomLong(), createTempDir(), true, true, numberOfNodes, numberOfNodes, clusterName, nodeConfigurationSource, 0, clusterName + "-", mockPlugins, Function.identity());
cluster.beforeTest(random());
clusters.put(clusterAlias, cluster);
}
clusterGroup = new ClusterGroup(clusters);
configureAndConnectsToRemoteClusters();
}
use of org.opensearch.plugins.Plugin in project OpenSearch by opensearch-project.
the class OpenSearchSingleNodeTestCase method newNode.
private Node newNode() {
final Path tempDir = createTempDir();
final String nodeName = nodeSettings().get(Node.NODE_NAME_SETTING.getKey(), "node_s_0");
Settings settings = Settings.builder().put(ClusterName.CLUSTER_NAME_SETTING.getKey(), InternalTestCluster.clusterName("single-node-cluster", random().nextLong())).put(Environment.PATH_HOME_SETTING.getKey(), tempDir).put(Environment.PATH_REPO_SETTING.getKey(), tempDir.resolve("repo")).put(Environment.PATH_SHARED_DATA_SETTING.getKey(), createTempDir().getParent()).put(Node.NODE_NAME_SETTING.getKey(), nodeName).put(OpenSearchExecutors.NODE_PROCESSORS_SETTING.getKey(), // limit the number of threads created
1).put("transport.type", getTestTransportType()).put(TransportSettings.PORT.getKey(), getPortRange()).put(dataNode()).put(NodeEnvironment.NODE_ID_SEED_SETTING.getKey(), random().nextLong()).put(DiskThresholdSettings.CLUSTER_ROUTING_ALLOCATION_LOW_DISK_WATERMARK_SETTING.getKey(), "1b").put(DiskThresholdSettings.CLUSTER_ROUTING_ALLOCATION_HIGH_DISK_WATERMARK_SETTING.getKey(), "1b").put(DiskThresholdSettings.CLUSTER_ROUTING_ALLOCATION_DISK_FLOOD_STAGE_WATERMARK_SETTING.getKey(), "1b").put(HierarchyCircuitBreakerService.USE_REAL_MEMORY_USAGE_SETTING.getKey(), false).putList(// empty list disables a port scan for other nodes
DISCOVERY_SEED_HOSTS_SETTING.getKey()).putList(INITIAL_MASTER_NODES_SETTING.getKey(), nodeName).put(// allow test cases to provide their own settings or override these
nodeSettings()).build();
Collection<Class<? extends Plugin>> plugins = getPlugins();
if (plugins.contains(getTestTransportPlugin()) == false) {
plugins = new ArrayList<>(plugins);
plugins.add(getTestTransportPlugin());
}
if (addMockHttpTransport()) {
plugins.add(MockHttpTransport.TestPlugin.class);
}
plugins.add(MockScriptService.TestPlugin.class);
Node node = new MockNode(settings, plugins, forbidPrivateIndexSettings());
try {
node.start();
} catch (NodeValidationException e) {
throw new RuntimeException(e);
}
return node;
}
use of org.opensearch.plugins.Plugin in project OpenSearch by opensearch-project.
the class NodeTests method testCreateWithCircuitBreakerPlugins.
public void testCreateWithCircuitBreakerPlugins() throws IOException {
Settings.Builder settings = baseSettings().put("breaker.test_breaker.limit", "50b");
List<Class<? extends Plugin>> plugins = basePlugins();
plugins.add(MockCircuitBreakerPlugin.class);
try (Node node = new MockNode(settings.build(), plugins)) {
CircuitBreakerService service = node.injector().getInstance(CircuitBreakerService.class);
assertThat(service.getBreaker("test_breaker"), is(not(nullValue())));
assertThat(service.getBreaker("test_breaker").getLimit(), equalTo(50L));
CircuitBreakerPlugin breakerPlugin = node.getPluginsService().filterPlugins(CircuitBreakerPlugin.class).get(0);
assertTrue(breakerPlugin instanceof MockCircuitBreakerPlugin);
assertSame("plugin circuit breaker instance is not the same as breaker service's instance", ((MockCircuitBreakerPlugin) breakerPlugin).myCircuitBreaker.get(), service.getBreaker("test_breaker"));
}
}
use of org.opensearch.plugins.Plugin in project OpenSearch by opensearch-project.
the class NodeTests method testLoadPluginBootstrapChecks.
public void testLoadPluginBootstrapChecks() throws IOException {
final String name = randomBoolean() ? randomAlphaOfLength(10) : null;
Settings.Builder settings = baseSettings();
if (name != null) {
settings.put(Node.NODE_NAME_SETTING.getKey(), name);
}
AtomicBoolean executed = new AtomicBoolean(false);
List<Class<? extends Plugin>> plugins = basePlugins();
plugins.add(CheckPlugin.class);
try (Node node = new MockNode(settings.build(), plugins) {
@Override
protected void validateNodeBeforeAcceptingRequests(BootstrapContext context, BoundTransportAddress boundTransportAddress, List<BootstrapCheck> bootstrapChecks) throws NodeValidationException {
assertEquals(1, bootstrapChecks.size());
assertSame(CheckPlugin.CHECK, bootstrapChecks.get(0));
executed.set(true);
throw new NodeValidationException("boom");
}
}) {
expectThrows(NodeValidationException.class, () -> node.start());
assertTrue(executed.get());
}
}
Aggregations