当前位置: 首页>>代码示例>>Java>>正文


Java NoNodeAvailableException类代码示例

本文整理汇总了Java中org.elasticsearch.client.transport.NoNodeAvailableException的典型用法代码示例。如果您正苦于以下问题:Java NoNodeAvailableException类的具体用法?Java NoNodeAvailableException怎么用?Java NoNodeAvailableException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


NoNodeAvailableException类属于org.elasticsearch.client.transport包,在下文中一共展示了NoNodeAvailableException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getIndex

import org.elasticsearch.client.transport.NoNodeAvailableException; //导入依赖的package包/类
public static ElasticsearchClient getIndex() {
    if (index == null) {
        // create index
        String elasticsearchAddress = config.getOrDefault("grid.elasticsearch.address", "localhost:9300");
        String elasticsearchClusterName = config.getOrDefault("grid.elasticsearch.clusterName", "");
        String elasticsearchWebIndexName= config.getOrDefault("grid.elasticsearch.webIndexName", "web");
        Path webMappingPath = Paths.get("conf/mappings/web.json");
        if (webMappingPath.toFile().exists()) try {
            index = new ElasticsearchClient(new String[]{elasticsearchAddress}, elasticsearchClusterName.length() == 0 ? null : elasticsearchClusterName);
            index.createIndexIfNotExists(elasticsearchWebIndexName, 1 /*shards*/, 1 /*replicas*/);
            String mapping = new String(Files.readAllBytes(webMappingPath));
            JSONObject mo = new JSONObject(new JSONTokener(mapping));
            mo = mo.getJSONObject("mappings").getJSONObject("_default_");
            index.setMapping("web", mo.toString());
            Data.logger.info("Connected elasticsearch at " + getHost(elasticsearchAddress));
        } catch (IOException | NoNodeAvailableException e) {
            index = null; // index not available
            Data.logger.info("Failed connecting elasticsearch at " + getHost(elasticsearchAddress) + ": " + e.getMessage(), e);
        } else {
            Data.logger.info("no web index mapping available, no connection to elasticsearch attempted");
        }
    }
    return index;
}
 
开发者ID:yacy,项目名称:yacy_grid_mcp,代码行数:25,代码来源:Data.java

示例2: run

import org.elasticsearch.client.transport.NoNodeAvailableException; //导入依赖的package包/类
@Override
public void run() {
	while(true) {
   	    try {
   	        logger.debug("getting es cluster health.");
   	        ActionFuture<ClusterHealthResponse> healthFuture = transportClient.admin().cluster().health(Requests.clusterHealthRequest());
   	        ClusterHealthResponse healthResponse = healthFuture.get(5, TimeUnit.SECONDS);
   	        logger.debug("Get num of node:{}", healthResponse.getNumberOfNodes());
   	        logger.debug("Get cluster health:{} ", healthResponse.getStatus());
   	        isClusterOn.getAndSet(true);
   	    } catch(Throwable t) {
   	        if(t instanceof NoNodeAvailableException){//集群不可用
   	        	logger.error("the cluster no node avaliable.");
   	        	isClusterOn.getAndSet(false);
                  }else{
   	        	isClusterOn.getAndSet(true);
                  }
   	    }
   	    try {
   	        Thread.sleep(1000);//FIXME
   	    } catch (InterruptedException ie) { 
   	    	ie.printStackTrace(); 
   	    }
   	}
}
 
开发者ID:DTStack,项目名称:jlogstash-output-plugin,代码行数:26,代码来源:Elasticsearch5.java

示例3: cleanup

import org.elasticsearch.client.transport.NoNodeAvailableException; //导入依赖的package包/类
@After
public void cleanup() throws IOException
{
  try {
    DeleteIndexResponse delete = store.client.admin().indices().delete(new DeleteIndexRequest(INDEX_NAME)).actionGet();
    if (!delete.isAcknowledged()) {
      logger.error("Index wasn't deleted");
    }

    store.disconnect();
  } catch (NoNodeAvailableException e) {
    //This indicates that elasticsearch is not running on a particular machine.
    //Silently ignore in this case.
  }

}
 
开发者ID:apache,项目名称:apex-malhar,代码行数:17,代码来源:ElasticSearchPercolateTest.java

示例4: testClusterRunning

import org.elasticsearch.client.transport.NoNodeAvailableException; //导入依赖的package包/类
private static boolean testClusterRunning(boolean withSecurity) throws IOException {
        try {
            NodesInfoResponse response = client.admin().cluster().prepareNodesInfo().get();
            Version version = response.getNodes().get(0).getVersion();
            logger.info("Starting integration tests against an external cluster running elasticsearch [{}] with {}",
                    version, withSecurity ? "security" : "no security" );
            return withSecurity;
//        } catch (NoNodeAvailableException e) {
//            // If we have an exception here, let's ignore the test
//            logger.warn("Integration tests are skipped: [{}]", e.getMessage());
//            assumeThat("Integration tests are skipped", e.getMessage(), not(containsString("Connection refused")));
//            return withSecurity;
        } catch (NoNodeAvailableException e) {
            if (e.getMessage() == "401") {
                logger.debug("The cluster is secured. So we need to build a client with security", e);
                return true;
            } else {
                logger.error("Full error is", e);
                throw e;
            }
        }
    }
 
开发者ID:dadoonet,项目名称:elasticsearch-beyonder,代码行数:23,代码来源:BeyonderTransportIT.java

示例5: writeIndex

import org.elasticsearch.client.transport.NoNodeAvailableException; //导入依赖的package包/类
/**
 * A method to persist Liferay index to Elasticsearch server document.
 * 
 * @param esDocument
 *            the json document
 */
private void writeIndex(ElasticserachJSONDocument esDocument) {

    try {
        if (esDocument.isError()) {
            _log.warn("Coudln't store document in index. Error..." + esDocument.getErrorMessage());

        } else {
            Client client = _esConnector.getClient();
            IndexResponse response = client
                    .prepareIndex(ElasticsearchIndexerConstants.ELASTIC_SEARCH_LIFERAY_INDEX,
                            esDocument.getIndexType(), esDocument.getId()).setSource(esDocument.getJsonDocument())
                    .execute().actionGet();
            if (_log.isDebugEnabled()) {
                _log.debug("Document indexed successfully with Id:" + esDocument.getId() + " ,Type:"
                        + esDocument.getIndexType() + " ,Updated index version:" + response.getVersion());
            }
        }
    } catch (NoNodeAvailableException noNodeEx) {
        _log.error("No node available:" + noNodeEx.getDetailedMessage());
    }
}
 
开发者ID:rivetlogic,项目名称:liferay-elasticsearch-integration,代码行数:28,代码来源:ElasticsearchIndexWriterImpl.java

示例6: deleteIndexByQuery

import org.elasticsearch.client.transport.NoNodeAvailableException; //导入依赖的package包/类
/**
 * Delete index by query.
 * 
 * @param uid
 *            the uid
 */
private void deleteIndexByQuery(String uid) {

    try {
        /** Don't handle plugin deployment documents, skip them */
        if(!uid.endsWith(ElasticsearchIndexerConstants.WAR)){
            Client client = _esConnector.getClient();
            DeleteByQueryResponse response = client
                    .prepareDeleteByQuery(ElasticsearchIndexerConstants.ELASTIC_SEARCH_LIFERAY_INDEX)
                    .setQuery(QueryBuilders.queryString(ElasticsearchIndexerConstants.ELASTIC_SEARCH_QUERY_UID + uid))
                    .execute().actionGet();
            
            if (_log.isDebugEnabled()) {
                _log.debug("Document deleted successfully with Id:" + uid + " , Status:" + response.status());
            }
        }
    } catch (NoNodeAvailableException noNodeEx) {
        _log.error("No node available:" + noNodeEx.getDetailedMessage());
    } catch (IndexMissingException indexMissingEx) {
        _log.error("No index availabe:" + indexMissingEx.getDetailedMessage());
    }
}
 
开发者ID:rivetlogic,项目名称:liferay-elasticsearch-integration,代码行数:28,代码来源:ElasticsearchIndexWriterImpl.java

示例7: onFailure

import org.elasticsearch.client.transport.NoNodeAvailableException; //导入依赖的package包/类
@Override
public void onFailure(Throwable e) {
    if (ExceptionsHelper.unwrapCause(e) instanceof ConnectTransportException) {
        int n = ++this.n;
        if (n >= nodes.size()) {
            listener.onFailure(new NoNodeAvailableException("none of the configured nodes were available: "
                    + nodes, e));
        } else {
            try {
                logger.warn("retrying on anoher node (n={}, nodes={})", n, nodes.size());
                callback.doWithNode(nodes.get((index + n) % nodes.size()), this);
            } catch (final Throwable t) {
                listener.onFailure(t);
            }
        }
    } else {
        listener.onFailure(e);
    }
}
 
开发者ID:jprante,项目名称:elasticsearch-helper,代码行数:20,代码来源:TransportClient.java

示例8: testBulkClient

import org.elasticsearch.client.transport.NoNodeAvailableException; //导入依赖的package包/类
@Test
public void testBulkClient() throws IOException {
    final BulkTransportClient client = ClientBuilder.builder()
            .put(getSettings())
            .put(ClientBuilder.FLUSH_INTERVAL, TimeValue.timeValueSeconds(60))
            .setMetric(new LongAdderIngestMetric())
            .toBulkTransportClient();
    client.newIndex("test");
    if (client.hasThrowable()) {
        logger.error("error", client.getThrowable());
    }
    assertFalse(client.hasThrowable());
    try {
        client.deleteIndex("test")
          .newIndex("test")
          .deleteIndex("test");
    } catch (NoNodeAvailableException e) {
        logger.error("no node available");
    } finally {
        if (client.hasThrowable()) {
            logger.error("error", client.getThrowable());
        }
        assertFalse(client.hasThrowable());
        client.shutdown();
    }
}
 
开发者ID:jprante,项目名称:elasticsearch-helper,代码行数:27,代码来源:BulkTransportClientTest.java

示例9: testRandomDocsNodeClient

import org.elasticsearch.client.transport.NoNodeAvailableException; //导入依赖的package包/类
@Test
public void testRandomDocsNodeClient() throws Exception {
    long numactions = NUM_ACTIONS;
    final BulkNodeClient client = ClientBuilder.builder()
            .put(ClientBuilder.MAX_ACTIONS_PER_REQUEST, MAX_ACTIONS)
            .put(ClientBuilder.FLUSH_INTERVAL, TimeValue.timeValueSeconds(60))
            .setMetric(new ElasticsearchIngestMetric())
            .toBulkNodeClient(client("1"));
    try {
        client.newIndex("test");
        for (int i = 0; i < NUM_ACTIONS; i++) {
            client.index("test", "test", null, "{ \"name\" : \"" + randomString(32) + "\"}");
        }
        client.flushIngest();
        client.waitForResponses(TimeValue.timeValueSeconds(30));
    } catch (NoNodeAvailableException e) {
        logger.warn("skipping, no node available");
    } finally {
        assertEquals(numactions, client.getMetric().getSucceeded().getCount());
        if (client.hasThrowable()) {
            logger.error("error", client.getThrowable());
        }
        assertFalse(client.hasThrowable());
        client.shutdown();
    }
}
 
开发者ID:jprante,项目名称:elasticsearch-helper,代码行数:27,代码来源:BulkNodeClientTest.java

示例10: countRequest

import org.elasticsearch.client.transport.NoNodeAvailableException; //导入依赖的package包/类
/**
 * With retry
 */
public static long countRequest(final String index, final QueryBuilder query, final String... types) {
	CountResponse response = withRetry(new ElasticsearchWithRetry<CountResponse>() {
		public CountResponse call(Client client) throws NoNodeAvailableException {
			CountRequestBuilder request_builder = new CountRequestBuilder(client);
			request_builder.setIndices(index);
			request_builder.setTypes(types);
			request_builder.setQuery(query);
			return request_builder.execute().actionGet();
		}
	});
	if (response == null) {
		return 0;
	}
	return response.getCount();
}
 
开发者ID:hdsdi3g,项目名称:MyDMAM,代码行数:19,代码来源:Elasticsearch.java

示例11: execute

import org.elasticsearch.client.transport.NoNodeAvailableException; //导入依赖的package包/类
private void execute() {
	Loggers.ElasticSearch.debug("Prepare to update database with numberOfActions: " + bulk_request_builder.numberOfActions());
	
	final BulkRequest bu_r = bulk_request_builder.request();
	
	BulkResponse bulkresponse = null;
	
	bulkresponse = Elasticsearch.withRetry(new ElasticsearchWithRetry<BulkResponse>() {
		public BulkResponse call(Client client) throws NoNodeAvailableException {
			return client.bulk(bu_r).actionGet();
		}
	});
	
	if (bulkresponse != null) {
		if (bulkresponse.hasFailures()) {
			Loggers.ElasticSearch.error("Errors during update database: " + bulkresponse.buildFailureMessage());
		}
	}
	
	bulk_request_builder.request().requests().clear();
	
	if (on_push_callback != null) {
		on_push_callback.run();
	}
}
 
开发者ID:hdsdi3g,项目名称:MyDMAM,代码行数:26,代码来源:ElasticsearchBulkOperation.java

示例12: createIndexIfNotExists

import org.elasticsearch.client.transport.NoNodeAvailableException; //导入依赖的package包/类
/**
 * create a new index. This method must be called to ensure that an elasticsearch index is available and can be used.
 * @param indexName
 * @param shards
 * @param replicas
 * @throws NoNodeAvailableException in case that no elasticsearch server can be contacted.
 */
public void createIndexIfNotExists(String indexName, final int shards, final int replicas) throws NoNodeAvailableException {
    // create an index if not existent
    if (!this.elasticsearchClient.admin().indices().prepareExists(indexName).execute().actionGet().isExists()) {
        Settings.Builder settings = Settings.builder()
                .put("number_of_shards", shards)
                .put("number_of_replicas", replicas);
        this.elasticsearchClient.admin().indices().prepareCreate(indexName)
            .setSettings(settings)
            .setUpdateAllTypes(true)
            .execute().actionGet();
    } else {
        //LOGGER.debug("Index with name {} already exists", indexName);
    }
}
 
开发者ID:yacy,项目名称:yacy_grid_mcp,代码行数:22,代码来源:ElasticsearchClient.java

示例13: performOn

import org.elasticsearch.client.transport.NoNodeAvailableException; //导入依赖的package包/类
@Override
public void performOn(ShardRouting replica, ReplicaRequest request, ActionListener<ReplicationOperation.ReplicaResponse> listener) {
    String nodeId = replica.currentNodeId();
    final DiscoveryNode node = clusterService.state().nodes().get(nodeId);
    if (node == null) {
        listener.onFailure(new NoNodeAvailableException("unknown node [" + nodeId + "]"));
        return;
    }
    final ConcreteShardRequest<ReplicaRequest> concreteShardRequest =
            new ConcreteShardRequest<>(request, replica.allocationId().getId());
    sendReplicaRequest(concreteShardRequest, node, listener);
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:13,代码来源:TransportReplicationAction.java

示例14: portDefaultsTo9300

import org.elasticsearch.client.transport.NoNodeAvailableException; //导入依赖的package包/类
@Test
public void portDefaultsTo9300() throws IOException {
  try (LazyClient lazyClient = new LazyClient(ElasticsearchStorage.builder()
      .hosts(asList("localhost")))) {

    assertThat(((NativeClient) lazyClient.get()).client.transportAddresses())
        .extracting(TransportAddress::getPort)
        .containsOnly(9300);

  } catch (NoNodeAvailableException e) {
    throw new AssumptionViolatedException(e.getMessage());
  }
}
 
开发者ID:liaominghua,项目名称:zipkin,代码行数:14,代码来源:LazyClientTest.java

示例15: check_failsInsteadOfThrowing

import org.elasticsearch.client.transport.NoNodeAvailableException; //导入依赖的package包/类
@Test
public void check_failsInsteadOfThrowing() {
  CheckResult result =
      ElasticsearchStorage.builder().cluster("1.1.1.1").build().check();

  assertThat(result.ok).isFalse();
  assertThat(result.exception)
      .isInstanceOf(NoNodeAvailableException.class);
}
 
开发者ID:liaominghua,项目名称:zipkin,代码行数:10,代码来源:ElasticsearchStorageTest.java


注:本文中的org.elasticsearch.client.transport.NoNodeAvailableException类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。