Search in sources :

Example 6 with Plugin

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);
}
Also used : MockNode(org.opensearch.node.MockNode) UncheckedIOException(java.io.UncheckedIOException) LifecycleListener(org.opensearch.common.component.LifecycleListener) UncheckedIOException(java.io.UncheckedIOException) IOException(java.io.IOException) MockSecureSettings(org.opensearch.common.settings.MockSecureSettings) TransportService(org.opensearch.transport.TransportService) MockTransportService(org.opensearch.test.transport.MockTransportService) MockSecureSettings(org.opensearch.common.settings.MockSecureSettings) SecureSettings(org.opensearch.common.settings.SecureSettings) Plugin(org.opensearch.plugins.Plugin)

Example 7 with Plugin

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();
}
Also used : MockTransportService(org.opensearch.test.transport.MockTransportService) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) AfterClass(org.junit.AfterClass) Settings(org.opensearch.common.settings.Settings) MockNioTransportPlugin(org.opensearch.transport.nio.MockNioTransportPlugin) Plugin(org.opensearch.plugins.Plugin) Before(org.junit.Before)

Example 8 with Plugin

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;
}
Also used : Path(java.nio.file.Path) NodeRoles.dataNode(org.opensearch.test.NodeRoles.dataNode) Node(org.opensearch.node.Node) MockNode(org.opensearch.node.MockNode) MockNode(org.opensearch.node.MockNode) NodeValidationException(org.opensearch.node.NodeValidationException) AfterClass(org.junit.AfterClass) BeforeClass(org.junit.BeforeClass) Settings(org.opensearch.common.settings.Settings) IndexSettings(org.opensearch.index.IndexSettings) DiskThresholdSettings(org.opensearch.cluster.routing.allocation.DiskThresholdSettings) TransportSettings(org.opensearch.transport.TransportSettings) MockScriptService(org.opensearch.script.MockScriptService) Plugin(org.opensearch.plugins.Plugin)

Example 9 with Plugin

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"));
    }
}
Also used : CircuitBreakerPlugin(org.opensearch.plugins.CircuitBreakerPlugin) NodeRoles.dataNode(org.opensearch.test.NodeRoles.dataNode) CircuitBreakerService(org.opensearch.indices.breaker.CircuitBreakerService) Settings(org.opensearch.common.settings.Settings) BreakerSettings(org.opensearch.indices.breaker.BreakerSettings) CircuitBreakerPlugin(org.opensearch.plugins.CircuitBreakerPlugin) Plugin(org.opensearch.plugins.Plugin)

Example 10 with Plugin

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());
    }
}
Also used : NodeRoles.dataNode(org.opensearch.test.NodeRoles.dataNode) BootstrapContext(org.opensearch.bootstrap.BootstrapContext) Matchers.containsString(org.hamcrest.Matchers.containsString) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) BoundTransportAddress(org.opensearch.common.transport.BoundTransportAddress) ArrayList(java.util.ArrayList) List(java.util.List) Settings(org.opensearch.common.settings.Settings) BreakerSettings(org.opensearch.indices.breaker.BreakerSettings) CircuitBreakerPlugin(org.opensearch.plugins.CircuitBreakerPlugin) Plugin(org.opensearch.plugins.Plugin)

Aggregations

Plugin (org.opensearch.plugins.Plugin)10 Settings (org.opensearch.common.settings.Settings)7 ArrayList (java.util.ArrayList)6 CircuitBreakerPlugin (org.opensearch.plugins.CircuitBreakerPlugin)3 NodeRoles.dataNode (org.opensearch.test.NodeRoles.dataNode)3 IOException (java.io.IOException)2 Path (java.nio.file.Path)2 Collection (java.util.Collection)2 List (java.util.List)2 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)2 AfterClass (org.junit.AfterClass)2 PlainActionFuture (org.opensearch.action.support.PlainActionFuture)2 Strings (org.opensearch.common.Strings)2 BreakerSettings (org.opensearch.indices.breaker.BreakerSettings)2 MockNode (org.opensearch.node.MockNode)2 MockTransportService (org.opensearch.test.transport.MockTransportService)2 TransportService (org.opensearch.transport.TransportService)2 Context (com.azure.core.util.Context)1 BlobContainerClient (com.azure.storage.blob.BlobContainerClient)1 BlobServiceClient (com.azure.storage.blob.BlobServiceClient)1