當前位置: 首頁>>代碼示例>>Java>>正文


Java Node類代碼示例

本文整理匯總了Java中org.elasticsearch.node.Node的典型用法代碼示例。如果您正苦於以下問題:Java Node類的具體用法?Java Node怎麽用?Java Node使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


Node類屬於org.elasticsearch.node包,在下文中一共展示了Node類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: EmbeddedElasticsearchServer

import org.elasticsearch.node.Node; //導入依賴的package包/類
public EmbeddedElasticsearchServer(String storagePath) {
    this.storagePath = storagePath;
    try {
        tempFile = File.createTempFile("elasticsearch", "test");
        this.storagePath = tempFile.getParent();
        tempFile.deleteOnExit();
    } catch (IOException e) {
        e.printStackTrace();
    }

    Settings.Builder elasticsearchSettings = Settings.builder()
            .put("http.enabled", "false")
            .put("path.data", this.storagePath)
            .put("path.home", System.getProperty("user.dir"))
            .put("transport.type", "local");

    node = new Node(elasticsearchSettings.build());
    client = node.client();
}
 
開發者ID:rfoltyns,項目名稱:log4j2-elasticsearch,代碼行數:20,代碼來源:BulkProcessorObjectFactoryTest.java

示例2: assertTribeNodeSuccessfullyCreated

import org.elasticsearch.node.Node; //導入依賴的package包/類
private static void assertTribeNodeSuccessfullyCreated(Settings extraSettings) throws Exception {
    //The tribe clients do need it to make sure they can find their corresponding tribes using the proper transport
    Settings settings = Settings.builder().put(NetworkModule.HTTP_ENABLED.getKey(), false).put("node.name", "tribe_node")
            .put("transport.type", MockTcpTransportPlugin.MOCK_TCP_TRANSPORT_NAME).put("discovery.type", "local")
            .put("tribe.t1.transport.type", MockTcpTransportPlugin.MOCK_TCP_TRANSPORT_NAME)
            .put("tribe.t2.transport.type",MockTcpTransportPlugin.MOCK_TCP_TRANSPORT_NAME)
            .put(Environment.PATH_HOME_SETTING.getKey(), createTempDir())
            .put(extraSettings).build();

    try (Node node = new MockNode(settings, Arrays.asList(MockTcpTransportPlugin.class, TestZenDiscovery.TestPlugin.class)).start()) {
        try (Client client = node.client()) {
            assertBusy(() -> {
                ClusterState state = client.admin().cluster().prepareState().clear().setNodes(true).get().getState();
                assertThat(state.getClusterName().value(), equalTo("tribe_node_cluster"));
                assertThat(state.getNodes().getSize(), equalTo(5));
                for (DiscoveryNode discoveryNode : state.getNodes()) {
                    assertThat(discoveryNode.getName(), either(equalTo("tribe1_node")).or(equalTo("tribe2_node"))
                            .or(equalTo("tribe_node")).or(equalTo("tribe_node/t1")).or(equalTo("tribe_node/t2")));
                }
            });
        }
    }
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:24,代碼來源:TribeUnitTests.java

示例3: testBindUnavailableAddress

import org.elasticsearch.node.Node; //導入依賴的package包/類
public void testBindUnavailableAddress() {
    // this is on a lower level since it needs access to the TransportService before it's started
    int port = serviceA.boundAddress().publishAddress().getPort();
    Settings settings = Settings.builder()
        .put(Node.NODE_NAME_SETTING.getKey(), "foobar")
        .put(TransportService.TRACE_LOG_INCLUDE_SETTING.getKey(), "")
        .put(TransportService.TRACE_LOG_EXCLUDE_SETTING.getKey(), "NOTHING")
        .put("transport.tcp.port", port)
        .build();
    ClusterSettings clusterSettings = new ClusterSettings(settings, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS);
    BindTransportException bindTransportException = expectThrows(BindTransportException.class, () -> {
        MockTransportService transportService = nettyFromThreadPool(settings, threadPool, Version.CURRENT, clusterSettings, true);
        try {
            transportService.start();
        } finally {
            transportService.stop();
            transportService.close();
        }
    });
    assertEquals("Failed to bind to ["+ port + "]", bindTransportException.getMessage());
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:22,代碼來源:SimpleNetty4TransportTests.java

示例4: testProperties

import org.elasticsearch.node.Node; //導入依賴的package包/類
public void testProperties() throws IOException, UserException {
    final Settings.Builder builder = Settings.builder().put("cluster.name", randomAsciiOfLength(16));
    if (randomBoolean()) {
        builder.put("node.name", randomAsciiOfLength(16));
    }
    final Settings settings = builder.build();
    setupLogging("minimal", settings);

    assertNotNull(System.getProperty("es.logs.base_path"));

    assertThat(System.getProperty("es.logs.cluster_name"), equalTo(ClusterName.CLUSTER_NAME_SETTING.get(settings).value()));
    if (Node.NODE_NAME_SETTING.exists(settings)) {
        assertThat(System.getProperty("es.logs.node_name"), equalTo(Node.NODE_NAME_SETTING.get(settings)));
    } else {
        assertNull(System.getProperty("es.logs.node_name"));
    }
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:18,代碼來源:EvilLoggerTests.java

示例5: buildService

import org.elasticsearch.node.Node; //導入依賴的package包/類
private MockTransportService buildService(final String name, final Version version, ClusterSettings clusterSettings,
                                          Settings settings, boolean acceptRequests, boolean doHandshake) {
    MockTransportService service = build(
        Settings.builder()
            .put(settings)
            .put(Node.NODE_NAME_SETTING.getKey(), name)
            .put(TransportService.TRACE_LOG_INCLUDE_SETTING.getKey(), "")
            .put(TransportService.TRACE_LOG_EXCLUDE_SETTING.getKey(), "NOTHING")
            .build(),
        version,
        clusterSettings, doHandshake);
    if (acceptRequests) {
        service.acceptIncomingRequests();
    }
    return service;
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:17,代碼來源:AbstractSimpleTransportTestCase.java

示例6: getRoleSuffix

import org.elasticsearch.node.Node; //導入依賴的package包/類
/**
 * returns a suffix string based on the node role. If no explicit role is defined, the suffix will be empty
 */
private String getRoleSuffix(Settings settings) {
    String suffix = "";
    if (Node.NODE_MASTER_SETTING.exists(settings) && Node.NODE_MASTER_SETTING.get(settings)) {
        suffix = suffix + Role.MASTER.getAbbreviation();
    }
    if (Node.NODE_DATA_SETTING.exists(settings) && Node.NODE_DATA_SETTING.get(settings)) {
        suffix = suffix + Role.DATA.getAbbreviation();
    }
    if (Node.NODE_MASTER_SETTING.exists(settings) && Node.NODE_MASTER_SETTING.get(settings) == false &&
        Node.NODE_DATA_SETTING.exists(settings) && Node.NODE_DATA_SETTING.get(settings) == false
        ) {
        suffix = suffix + "c";
    }
    return suffix;
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:19,代碼來源:InternalTestCluster.java

示例7: startNodes

import org.elasticsearch.node.Node; //導入依賴的package包/類
/**
 * Starts multiple nodes with the given settings and returns their names
 */
public synchronized List<String> startNodes(Settings... settings) {
    final int defaultMinMasterNodes;
    if (autoManageMinMasterNodes) {
        int mastersDelta = (int) Stream.of(settings).filter(Node.NODE_MASTER_SETTING::get).count();
        defaultMinMasterNodes = getMinMasterNodes(getMasterNodesCount() + mastersDelta);
    } else {
        defaultMinMasterNodes = -1;
    }
    List<NodeAndClient> nodes = new ArrayList<>();
    for (Settings nodeSettings: settings) {
        nodes.add(buildNode(nodeSettings, defaultMinMasterNodes));
    }
    startAndPublishNodesAndClients(nodes);
    if (autoManageMinMasterNodes) {
        validateClusterFormed();
    }

    return nodes.stream().map(NodeAndClient::getName).collect(Collectors.toList());
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:23,代碼來源:InternalTestCluster.java

示例8: routingKeyForShard

import org.elasticsearch.node.Node; //導入依賴的package包/類
synchronized String routingKeyForShard(Index index, int shard, Random random) {
    assertThat(shard, greaterThanOrEqualTo(0));
    assertThat(shard, greaterThanOrEqualTo(0));
    for (NodeAndClient n : nodes.values()) {
        Node node = n.node;
        IndicesService indicesService = getInstanceFromNode(IndicesService.class, node);
        ClusterService clusterService = getInstanceFromNode(ClusterService.class, node);
        IndexService indexService = indicesService.indexService(index);
        if (indexService != null) {
            assertThat(indexService.getIndexSettings().getSettings().getAsInt(IndexMetaData.SETTING_NUMBER_OF_SHARDS, -1), greaterThan(shard));
            OperationRouting operationRouting = clusterService.operationRouting();
            while (true) {
                String routing = RandomStrings.randomAsciiOfLength(random, 10);
                final int targetShard = operationRouting.indexShards(clusterService.state(), index.getName(), null, routing).shardId().getId();
                if (shard == targetShard) {
                    return routing;
                }
            }
        }
    }
    fail("Could not find a node that holds " + index);
    return null;
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:24,代碼來源:InternalTestCluster.java

示例9: startNodes

import org.elasticsearch.node.Node; //導入依賴的package包/類
public void startNodes() {
    for (Node node : nodes) {
        try {
            getClusterService(node).addListener(new TribeClusterStateListener(node));
            node.start();
        } catch (Exception e) {
            // calling close is safe for non started nodes, we can just iterate over all
            for (Node otherNode : nodes) {
                try {
                    otherNode.close();
                } catch (Exception inner) {
                    inner.addSuppressed(e);
                    logger.warn((Supplier<?>) () -> new ParameterizedMessage("failed to close node {} on failed start", otherNode), inner);
                }
            }
            if (e instanceof RuntimeException) {
                throw (RuntimeException) e;
            }
            throw new ElasticsearchException(e);
        }
    }
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:23,代碼來源:TribeService.java

示例10: testFailToPublishWithLessThanMinMasterNodes

import org.elasticsearch.node.Node; //導入依賴的package包/類
public void testFailToPublishWithLessThanMinMasterNodes() throws Exception {
    final int masterNodes = randomIntBetween(1, 10);

    MockNode master = createMockNode("master");
    DiscoveryNodes.Builder discoveryNodesBuilder = DiscoveryNodes.builder().add(master.discoveryNode);
    for (int i = 1; i < masterNodes; i++) {
        discoveryNodesBuilder.add(createMockNode("node" + i).discoveryNode);
    }
    final int dataNodes = randomIntBetween(0, 5);
    final Settings dataSettings = Settings.builder().put(Node.NODE_MASTER_SETTING.getKey(), false).build();
    for (int i = 0; i < dataNodes; i++) {
        discoveryNodesBuilder.add(createMockNode("data_" + i, dataSettings, null).discoveryNode);
    }
    discoveryNodesBuilder.localNodeId(master.discoveryNode.getId()).masterNodeId(master.discoveryNode.getId());
    DiscoveryNodes discoveryNodes = discoveryNodesBuilder.build();
    MetaData metaData = MetaData.EMPTY_META_DATA;
    ClusterState clusterState = ClusterState.builder(CLUSTER_NAME).metaData(metaData).nodes(discoveryNodes).build();
    ClusterState previousState = master.clusterState;
    try {
        publishState(master.action, clusterState, previousState, masterNodes + randomIntBetween(1, 5));
        fail("cluster state publishing didn't fail despite of not having enough nodes");
    } catch (Discovery.FailedToCommitClusterStateException expected) {
        logger.debug("failed to publish as expected", expected);
    }
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:26,代碼來源:PublishClusterStateActionTests.java

示例11: build

import org.elasticsearch.node.Node; //導入依賴的package包/類
protected MockTransportService build(Settings settings, Version version) {
    NamedWriteableRegistry namedWriteableRegistry = new NamedWriteableRegistry(Collections.emptyList());
    MockTransportService transportService =
        new MockTransportService(
            Settings.builder()
                .put(settings)
                // trace zenfd actions but keep the default otherwise
                .put(TransportService.TRACE_LOG_EXCLUDE_SETTING.getKey(), singleton(TransportLivenessAction.NAME))
                .build(),
            new MockTcpTransport(settings, threadPool, BigArrays.NON_RECYCLING_INSTANCE, circuitBreakerService,
                namedWriteableRegistry, new NetworkService(settings, Collections.emptyList()), version),
            threadPool,
            TransportService.NOOP_TRANSPORT_INTERCEPTOR,
            (boundAddress) ->
                new DiscoveryNode(Node.NODE_NAME_SETTING.get(settings), boundAddress.publishAddress(),
                    Node.NODE_ATTRIBUTES.get(settings).getAsMap(), DiscoveryNode.getRolesFromSettings(settings), version),
            null);
    transportService.start();
    transportService.acceptIncomingRequests();
    return transportService;
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:22,代碼來源:ZenFaultDetectionTests.java

示例12: testJustMasterNode

import org.elasticsearch.node.Node; //導入依賴的package包/類
public void testJustMasterNode() throws Exception {
    logger.info("--> cleaning nodes");

    logger.info("--> starting 1 master node non data");
    internalCluster().startNode(Settings.builder().put(Node.NODE_DATA_SETTING.getKey(), false).build());

    logger.info("--> create an index");
    client().admin().indices().prepareCreate("test").setWaitForActiveShards(ActiveShardCount.NONE).execute().actionGet();

    logger.info("--> closing master node");
    internalCluster().closeNonSharedNodes(false);

    logger.info("--> starting 1 master node non data again");
    internalCluster().startNode(Settings.builder().put(Node.NODE_DATA_SETTING.getKey(), false).build());

    logger.info("--> waiting for test index to be created");
    ClusterHealthResponse health = client().admin().cluster().prepareHealth().setWaitForEvents(Priority.LANGUID).setIndices("test")
        .execute().actionGet();
    assertThat(health.isTimedOut(), equalTo(false));

    logger.info("--> verify we have an index");
    ClusterStateResponse clusterStateResponse = client().admin().cluster().prepareState().setIndices("test").execute().actionGet();
    assertThat(clusterStateResponse.getState().metaData().hasIndex("test"), equalTo(true));
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:25,代碼來源:GatewayIndexStateIT.java

示例13: createTribeSettings

import org.elasticsearch.node.Node; //導入依賴的package包/類
private Settings.Builder createTribeSettings(Predicate<InternalTestCluster> filter) {
    assertNotNull(filter);

    final Settings.Builder settings = Settings.builder();
    settings.put(Node.NODE_NAME_SETTING.getKey(), TRIBE_NODE);
    settings.put(Node.NODE_DATA_SETTING.getKey(), false);
    settings.put(Node.NODE_MASTER_SETTING.getKey(), true);
    settings.put(NetworkModule.HTTP_ENABLED.getKey(), false);
    settings.put(NetworkModule.TRANSPORT_TYPE_SETTING.getKey(), MockTcpTransportPlugin.MOCK_TCP_TRANSPORT_NAME);

    doWithAllClusters(filter, c -> {
        String tribeSetting = "tribe." + c.getClusterName() + ".";
        settings.put(tribeSetting + ClusterName.CLUSTER_NAME_SETTING.getKey(), c.getClusterName());
        settings.put(tribeSetting + DiscoverySettings.INITIAL_STATE_TIMEOUT_SETTING.getKey(), "100ms");
        settings.put(tribeSetting + NetworkModule.TRANSPORT_TYPE_SETTING.getKey(), MockTcpTransportPlugin.MOCK_TCP_TRANSPORT_NAME);
    });

    return settings;
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:20,代碼來源:TribeIT.java

示例14: testElectOnlyBetweenMasterNodes

import org.elasticsearch.node.Node; //導入依賴的package包/類
public void testElectOnlyBetweenMasterNodes() throws IOException {
    logger.info("--> start data node / non master node");
    internalCluster().startNode(Settings.builder().put(Node.NODE_DATA_SETTING.getKey(), true).put(Node.NODE_MASTER_SETTING.getKey(), false).put("discovery.initial_state_timeout", "1s"));
    try {
        assertThat(client().admin().cluster().prepareState().setMasterNodeTimeout("100ms").execute().actionGet().getState().nodes().getMasterNodeId(), nullValue());
        fail("should not be able to find master");
    } catch (MasterNotDiscoveredException e) {
        // all is well, no master elected
    }
    logger.info("--> start master node (1)");
    final String masterNodeName = internalCluster().startNode(Settings.builder().put(Node.NODE_DATA_SETTING.getKey(), false).put(Node.NODE_MASTER_SETTING.getKey(), true));
    assertThat(internalCluster().nonMasterClient().admin().cluster().prepareState().execute().actionGet().getState().nodes().getMasterNode().getName(), equalTo(masterNodeName));
    assertThat(internalCluster().masterClient().admin().cluster().prepareState().execute().actionGet().getState().nodes().getMasterNode().getName(), equalTo(masterNodeName));

    logger.info("--> start master node (2)");
    final String nextMasterEligableNodeName = internalCluster().startNode(Settings.builder().put(Node.NODE_DATA_SETTING.getKey(), false).put(Node.NODE_MASTER_SETTING.getKey(), true));
    assertThat(internalCluster().nonMasterClient().admin().cluster().prepareState().execute().actionGet().getState().nodes().getMasterNode().getName(), equalTo(masterNodeName));
    assertThat(internalCluster().nonMasterClient().admin().cluster().prepareState().execute().actionGet().getState().nodes().getMasterNode().getName(), equalTo(masterNodeName));
    assertThat(internalCluster().masterClient().admin().cluster().prepareState().execute().actionGet().getState().nodes().getMasterNode().getName(), equalTo(masterNodeName));

    logger.info("--> closing master node (1)");
    internalCluster().stopCurrentMasterNode();
    assertThat(internalCluster().nonMasterClient().admin().cluster().prepareState().execute().actionGet().getState().nodes().getMasterNode().getName(), equalTo(nextMasterEligableNodeName));
    assertThat(internalCluster().masterClient().admin().cluster().prepareState().execute().actionGet().getState().nodes().getMasterNode().getName(), equalTo(nextMasterEligableNodeName));
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:26,代碼來源:SpecificMasterNodesIT.java

示例15: testCustomDefaultMapping

import org.elasticsearch.node.Node; //導入依賴的package包/類
/**
 * Tests that putting custom default mapping and then putting a type mapping will have the default mapping merged
 * to the type mapping.
 */
public void testCustomDefaultMapping() throws Exception {
    logger.info("--> start master node / non data");
    internalCluster().startNode(Settings.builder().put(Node.NODE_DATA_SETTING.getKey(), false).put(Node.NODE_MASTER_SETTING.getKey(), true));

    logger.info("--> start data node / non master node");
    internalCluster().startNode(Settings.builder().put(Node.NODE_DATA_SETTING.getKey(), true).put(Node.NODE_MASTER_SETTING.getKey(), false));

    createIndex("test");
    assertAcked(client().admin().indices().preparePutMapping("test").setType("_default_").setSource("timestamp", "type=date"));

    MappingMetaData defaultMapping = client().admin().cluster().prepareState().get().getState().getMetaData().getIndices().get("test").getMappings().get("_default_");
    Map<?,?> properties = (Map<?, ?>) defaultMapping.getSourceAsMap().get("properties");
    assertThat(properties.get("timestamp"), notNullValue());

    assertAcked(client().admin().indices().preparePutMapping("test").setType("_default_").setSource("timestamp", "type=date"));

    assertAcked(client().admin().indices().preparePutMapping("test").setType("type1").setSource("foo", "enabled=true"));
    MappingMetaData type1Mapping = client().admin().cluster().prepareState().get().getState().getMetaData().getIndices().get("test").getMappings().get("type1");
    properties = (Map<?, ?>) type1Mapping.getSourceAsMap().get("properties");
    assertThat(properties.get("timestamp"), notNullValue());
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:26,代碼來源:SpecificMasterNodesIT.java


注:本文中的org.elasticsearch.node.Node類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。