当前位置: 首页>>代码示例>>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;未经允许,请勿转载。