org.elasticsearch.client.transport.NoNodeAvailableException Java Examples

The following examples show how to use org.elasticsearch.client.transport.NoNodeAvailableException. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TransportReplicationAction.java    From crate with Apache License 2.0 6 votes vote down vote up
@Override
public void performOn(
        final ShardRouting replica,
        final ReplicaRequest request,
        final long globalCheckpoint,
        final long maxSeqNoOfUpdatesOrDeletes,
        final 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 ConcreteReplicaRequest<ReplicaRequest> replicaRequest = new ConcreteReplicaRequest<>(
        request, replica.allocationId().getId(), primaryTerm, globalCheckpoint, maxSeqNoOfUpdatesOrDeletes);
    sendReplicaRequest(replicaRequest, node, listener);
}
 
Example #2
Source File: EsRetryTest.java    From io with Apache License 2.0 6 votes vote down vote up
/**
 * ドキュメント新規作成時_初回NoNodeAvailableExceptionが発生した場合にリトライを繰り返し最終的にEsClient_EsNoResponseExceptionが返されること.
 */
@Test(expected = EsClientException.EsNoResponseException.class)
public void ドキュメント新規作成時_初回NoNodeAvailableExceptionが発生した場合にリトライを繰り返し最終的にEsClient_EsNoResponseExceptionが返されること() {
    PowerMockito.mockStatic(EsClientException.class);
    EsTypeImpl esTypeObject = Mockito.spy(new EsTypeImpl("dummy", "Test", "TestRoutingId", 5, 500, null));

    // EsType#asyncIndex()が呼ばれた場合に、NodeDisconnectedExceptionを投げる。
    // 送出する例外オブジェクトのモックを作成
    NoNodeAvailableException toBeThrown = Mockito.mock(NoNodeAvailableException.class);
    Mockito.doThrow(toBeThrown)
            .when(esTypeObject)
            .asyncIndex(Mockito.anyString(), Mockito.anyMapOf(String.class, Object.class),
                    Mockito.any(OpType.class), Mockito.anyLong());
    // メソッド呼び出し
    esTypeObject.create("dummyId", null);
    fail("EsNoResponseException should be thrown.");
}
 
Example #3
Source File: ElasticsearchChannel.java    From syncer with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 *
 * @param supplier return null if it fails to connect to ES
 */
private <R> R sleepInConnectionLost(Function<Long, R> supplier) throws InterruptedException {
  long sleepInSecond = 1;
  while (true) {
    R apply = null;
    try {
      apply = supplier.apply(sleepInSecond);
    } catch (NoNodeAvailableException e) {
      String error = "Fail to connect to ES server, will retry in {}s";
      logger.error(error, sleepInSecond, e);
      SyncerHealth.consumer(consumerId, id, Health.red(error));
    }
    if (apply != null) {
      return apply;
    }
    sleepInSecond = FallBackPolicy.POW_2.next(sleepInSecond, TimeUnit.SECONDS);
    TimeUnit.SECONDS.sleep(sleepInSecond);
  }
}
 
Example #4
Source File: Main.java    From Siamese with GNU General Public License v3.0 6 votes vote down vote up
public static void main(String[] args) {
      String[] overridingParams = processCommandLine(args);
      if (configFile == null) {
          System.out.println("Couldn't find the config file. Use the default one at ./config.properties");
          configFile = "config.properties";
      }
      Date startDate = MyUtils.getCurrentTime();
      Siamese siamese = new Siamese(configFile, overridingParams);
      siamese.startup();
      try {
	siamese.execute();
} catch(NoNodeAvailableException nne) {
	System.out.println("Elasticsearch is not running. Please execute the following command:\n" +
			"./elasticsearch-2.2.0/bin/elasticsearch -d");
} catch (Exception e) {
          System.out.println(e.getMessage());
}

siamese.shutdown();
      Date endDate = MyUtils.getCurrentTime();
      System.out.println("Elapse time (ms): " + (endDate.getTime() - startDate.getTime()));
  }
 
Example #5
Source File: ElasticSearchPercolateTest.java    From attic-apex-malhar with Apache License 2.0 6 votes vote down vote up
@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.
  }

}
 
Example #6
Source File: AbstractRetryableEsRequestTest.java    From io with Apache License 2.0 6 votes vote down vote up
/**
 * 初回リクエストでNoNodeAvailableException、リトライ1回目で成功した場合、適切な復帰値が返ること.
 */
@Test
public void 初回リクエストでNoNodeAvailableException_リトライ1回目で成功した場合_適切な復帰値が返ること() {

    TestRequest requestMock = Mockito.spy(new TestRequest());

    NoNodeAvailableException toBeThrown = Mockito.mock(NoNodeAvailableException.class);
    Mockito.doThrow(toBeThrown)
            .doReturn(SUCCESS_RESPONSE)
            .when(requestMock)
            .doProcess();

    String result = requestMock.doRequest();
    assertEquals(SUCCESS_RESPONSE, result);
    Mockito.verify(requestMock, Mockito.times(2)).doProcess();
    Mockito.verify(requestMock, Mockito.times(0)).onParticularError(Mockito.any(ElasticsearchException.class));
}
 
Example #7
Source File: AbstractRetryableEsRequestTest.java    From io with Apache License 2.0 6 votes vote down vote up
/**
 * NoNodeAvailableExceptionが続き, リトライ3回目で成功した場合、適切な復帰値が返ること.
 */
@Test
public void NoNodeAvailableExceptionが続き_リトライ3回目で成功した場合_適切な復帰値が返ること() {

    TestRequest requestMock = Mockito.spy(new TestRequest());

    NoNodeAvailableException toBeThrown = Mockito.mock(NoNodeAvailableException.class);
    Mockito.doThrow(toBeThrown) // 初回
            .doThrow(toBeThrown) // リトライ1回目
            .doThrow(toBeThrown) // リトライ2回目
            .doReturn(SUCCESS_RESPONSE) // リトライ3回目で正常復帰
            .when(requestMock)
            .doProcess();

    String result = requestMock.doRequest();
    assertEquals(SUCCESS_RESPONSE, result);
    // doProcessが4回呼び出されるはず
    Mockito.verify(requestMock, Mockito.times(4)).doProcess();
    Mockito.verify(requestMock, Mockito.times(0)).onParticularError(Mockito.any(ElasticsearchException.class));
}
 
Example #8
Source File: EsRetry2Test.java    From io with Apache License 2.0 6 votes vote down vote up
/**
 * ドキュメント新規作成時_初回NoNodeAvailableExceptionが発生した場合にリトライを繰り返し最終的にEsClient_EsNoResponseExceptionが返されること.
 */
@Test(expected = EsClientException.EsNoResponseException.class)
public void ドキュメント新規作成時_初回NoNodeAvailableExceptionが発生した場合にリトライを繰り返し最終的にEsClient_EsNoResponseExceptionが返されること() {
    PowerMockito.mockStatic(EsClientException.class);
    EsTypeImpl esTypeObject = Mockito.spy(new EsTypeImpl("dummy", "Test", "TestRoutingId", 5, 500, null));

    // EsType#asyncIndex()が呼ばれた場合に、NodeDisconnectedExceptionを投げる。
    // 送出する例外オブジェクトのモックを作成
    NoNodeAvailableException toBeThrown = Mockito.mock(NoNodeAvailableException.class);
    Mockito.doThrow(toBeThrown)
            .when(esTypeObject)
            .asyncIndex(Mockito.anyString(), Mockito.anyMapOf(String.class, Object.class),
                    Mockito.any(OpType.class), Mockito.anyLong());
    // メソッド呼び出し
    esTypeObject.create("dummyId", null);
    fail("EsNoResponseException should be thrown.");
}
 
Example #9
Source File: AbstractRetryableEsRequestTest.java    From io with Apache License 2.0 6 votes vote down vote up
/**
 * 初回リクエストでNoNodeAvailableException、リトライ1回目で成功した場合、適切な復帰値が返ること.
 */
@Test
public void 初回リクエストでNoNodeAvailableException_リトライ1回目で成功した場合_適切な復帰値が返ること() {

    TestRequest requestMock = Mockito.spy(new TestRequest());

    NoNodeAvailableException toBeThrown = Mockito.mock(NoNodeAvailableException.class);
    Mockito.doThrow(toBeThrown)
            .doReturn(SUCCESS_RESPONSE)
            .when(requestMock)
            .doProcess();

    String result = requestMock.doRequest();
    assertEquals(SUCCESS_RESPONSE, result);
    Mockito.verify(requestMock, Mockito.times(2)).doProcess();
    Mockito.verify(requestMock, Mockito.times(0)).onParticularError(Mockito.any(ElasticsearchException.class));
}
 
Example #10
Source File: AbstractRetryableEsRequestTest.java    From io with Apache License 2.0 6 votes vote down vote up
/**
 * NoNodeAvailableExceptionが続き, リトライ3回目で成功した場合、適切な復帰値が返ること.
 */
@Test
public void NoNodeAvailableExceptionが続き_リトライ3回目で成功した場合_適切な復帰値が返ること() {

    TestRequest requestMock = Mockito.spy(new TestRequest());

    NoNodeAvailableException toBeThrown = Mockito.mock(NoNodeAvailableException.class);
    Mockito.doThrow(toBeThrown) // 初回
            .doThrow(toBeThrown) // リトライ1回目
            .doThrow(toBeThrown) // リトライ2回目
            .doReturn(SUCCESS_RESPONSE) // リトライ3回目で正常復帰
            .when(requestMock)
            .doProcess();

    String result = requestMock.doRequest();
    assertEquals(SUCCESS_RESPONSE, result);
    // doProcessが4回呼び出されるはず
    Mockito.verify(requestMock, Mockito.times(4)).doProcess();
    Mockito.verify(requestMock, Mockito.times(0)).onParticularError(Mockito.any(ElasticsearchException.class));
}
 
Example #11
Source File: EsRetry2Test.java    From io with Apache License 2.0 6 votes vote down vote up
/**
 * ドキュメント新規作成時_初回NoNodeAvailableExceptionが発生した場合にリトライを繰り返し最終的にEsClient_EsNoResponseExceptionが返されること.
 */
@Test(expected = EsClientException.EsNoResponseException.class)
public void ドキュメント新規作成時_初回NoNodeAvailableExceptionが発生した場合にリトライを繰り返し最終的にEsClient_EsNoResponseExceptionが返されること() {
    PowerMockito.mockStatic(EsClientException.class);
    EsTypeImpl esTypeObject = Mockito.spy(new EsTypeImpl("dummy", "Test", "TestRoutingId", 5, 500, null));

    // EsType#asyncIndex()が呼ばれた場合に、NodeDisconnectedExceptionを投げる。
    // 送出する例外オブジェクトのモックを作成
    NoNodeAvailableException toBeThrown = Mockito.mock(NoNodeAvailableException.class);
    Mockito.doThrow(toBeThrown)
            .when(esTypeObject)
            .asyncIndex(Mockito.anyString(), Mockito.anyMapOf(String.class, Object.class),
                    Mockito.any(OpType.class), Mockito.anyLong());
    // メソッド呼び出し
    esTypeObject.create("dummyId", null);
    fail("EsNoResponseException should be thrown.");
}
 
Example #12
Source File: TransportClient.java    From elasticsearch-helper with Apache License 2.0 6 votes vote down vote up
@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);
    }
}
 
Example #13
Source File: BulkTransportClientTest.java    From elasticsearch-helper with Apache License 2.0 6 votes vote down vote up
@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();
    }
}
 
Example #14
Source File: BulkNodeClientTest.java    From elasticsearch-helper with Apache License 2.0 6 votes vote down vote up
@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();
    }
}
 
Example #15
Source File: EsRetryTest.java    From io with Apache License 2.0 5 votes vote down vote up
void throwException() {
    // 3回目の呼び出しまではNoNodeAvailableExceptionをスローする
    if (this.retryTimes == 3) {
        this.retryTimes = 0;
        // 4回目の呼び出しでthis.successがtrueの場合、例外を上げない
        // 呼出しもとで正常な処理を行う
        if (this.flag) {
            return;
        }
        // 4回目の呼び出しでthis.successがfalseの場合、IllegalStateExceptionをスローする
        throw new IllegalStateException();
    }
    this.retryTimes++;
    throw new NoNodeAvailableException("retry error");
}
 
Example #16
Source File: TestPutElasticsearch.java    From localization_nifi with Apache License 2.0 5 votes vote down vote up
@Override
public void createElasticsearchClient(ProcessContext context) throws ProcessException {
    final Client mockClient = mock(Client.class);
    BulkRequestBuilder bulkRequestBuilder = spy(new BulkRequestBuilder(mockClient, BulkAction.INSTANCE));
    if (exceptionToThrow != null) {
        doThrow(exceptionToThrow).when(bulkRequestBuilder).execute();
    } else {
        doReturn(new MockBulkRequestBuilderExecutor(responseHasFailures)).when(bulkRequestBuilder).execute();
    }
    when(mockClient.prepareBulk()).thenReturn(bulkRequestBuilder);

    when(mockClient.prepareIndex(anyString(), anyString(), anyString())).thenAnswer(new Answer<IndexRequestBuilder>() {
        @Override
        public IndexRequestBuilder answer(InvocationOnMock invocationOnMock) throws Throwable {
            Object[] args = invocationOnMock.getArguments();
            String arg1 = (String) args[0];
            if (arg1.isEmpty()) {
                throw new NoNodeAvailableException("Needs index");
            }
            String arg2 = (String) args[1];
            if (arg2.isEmpty()) {
                throw new NoNodeAvailableException("Needs doc type");
            } else {
                IndexRequestBuilder indexRequestBuilder = new IndexRequestBuilder(mockClient, IndexAction.INSTANCE);
                return indexRequestBuilder;
            }
        }
    });

    esClient.set(mockClient);
}
 
Example #17
Source File: TestPutElasticsearch.java    From nifi with Apache License 2.0 5 votes vote down vote up
@Override
public void createElasticsearchClient(ProcessContext context) throws ProcessException {
    final Client mockClient = mock(Client.class);
    BulkRequestBuilder bulkRequestBuilder = spy(new BulkRequestBuilder(mockClient, BulkAction.INSTANCE));
    if (exceptionToThrow != null) {
        doThrow(exceptionToThrow).when(bulkRequestBuilder).execute();
    } else {
        doReturn(new MockBulkRequestBuilderExecutor(responseHasFailures)).when(bulkRequestBuilder).execute();
    }
    when(mockClient.prepareBulk()).thenReturn(bulkRequestBuilder);

    when(mockClient.prepareIndex(anyString(), anyString(), anyString())).thenAnswer(new Answer<IndexRequestBuilder>() {
        @Override
        public IndexRequestBuilder answer(InvocationOnMock invocationOnMock) throws Throwable {
            Object[] args = invocationOnMock.getArguments();
            String arg1 = (String) args[0];
            if (arg1.isEmpty()) {
                throw new NoNodeAvailableException("Needs index");
            }
            String arg2 = (String) args[1];
            if (arg2.isEmpty()) {
                throw new NoNodeAvailableException("Needs doc type");
            } else {
                IndexRequestBuilder indexRequestBuilder = new IndexRequestBuilder(mockClient, IndexAction.INSTANCE);
                return indexRequestBuilder;
            }
        }
    });

    esClient.set(mockClient);
}
 
Example #18
Source File: HttpBulkNodeClientTest.java    From elasticsearch-helper with Apache License 2.0 5 votes vote down vote up
@Test
public void testRandomDocs() throws Exception {
    long numactions = NUM_ACTIONS;
    final HttpBulkNodeClient client = ClientBuilder.builder()
            .setMetric(new LongAdderIngestMetric())
            .put("host", "127.0.0.1")
            .put("port", 9200)
            .put(ClientBuilder.MAX_ACTIONS_PER_REQUEST, MAX_ACTIONS)
            .put(ClientBuilder.FLUSH_INTERVAL, TimeValue.timeValueSeconds(60))
            .toHttpBulkNodeClient();
    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();
    }
}
 
Example #19
Source File: TestPutElasticsearch5.java    From nifi with Apache License 2.0 5 votes vote down vote up
@Override
protected Client getTransportClient(Settings.Builder settingsBuilder, String xPackPath,
                                    String username, String password,
                                    List<InetSocketAddress> esHosts, ComponentLog log)
        throws MalformedURLException {
    final Client mockClient = mock(Client.class);
    BulkRequestBuilder bulkRequestBuilder = spy(new BulkRequestBuilder(mockClient, BulkAction.INSTANCE));
    if (exceptionToThrow != null) {
        doThrow(exceptionToThrow).when(bulkRequestBuilder).execute();
    } else {
        doReturn(new MockBulkRequestBuilderExecutor(responseHasFailures, esHosts.get(0))).when(bulkRequestBuilder).execute();
    }
    when(mockClient.prepareBulk()).thenReturn(bulkRequestBuilder);

    when(mockClient.prepareIndex(anyString(), anyString(), anyString())).thenAnswer(new Answer<IndexRequestBuilder>() {
        @Override
        public IndexRequestBuilder answer(InvocationOnMock invocationOnMock) throws Throwable {
            Object[] args = invocationOnMock.getArguments();
            String arg1 = (String) args[0];
            if (arg1.isEmpty()) {
                throw new NoNodeAvailableException("Needs index");
            }
            String arg2 = (String) args[1];
            if (arg2.isEmpty()) {
                throw new NoNodeAvailableException("Needs doc type");
            } else {
                IndexRequestBuilder indexRequestBuilder = new IndexRequestBuilder(mockClient, IndexAction.INSTANCE);
                return indexRequestBuilder;
            }
        }
    });

    return mockClient;
}
 
Example #20
Source File: SearchTransportClient.java    From elasticsearch-helper with Apache License 2.0 5 votes vote down vote up
@Override
public SearchTransportClient init(Settings settings) throws IOException {
    super.createClient(settings);
    Collection<InetSocketTransportAddress> addrs = findAddresses(settings);
    if (!connect(addrs, settings.getAsBoolean("autodiscover", false))) {
        throw new NoNodeAvailableException("no cluster nodes available, check settings "
                + settings.getAsMap());
    }
    return this;
}
 
Example #21
Source File: IngestTransportUpdateReplicaLevelTest.java    From elasticsearch-helper with Apache License 2.0 5 votes vote down vote up
@Test
public void testUpdateReplicaLevel() throws Exception {

    int numberOfShards = 2;
    int replicaLevel = 3;

    // we need 3 nodes for replica level 3
    startNode("2");
    startNode("3");

    int shardsAfterReplica;

    Settings settings = Settings.settingsBuilder()
            .put("index.number_of_shards", numberOfShards)
            .put("index.number_of_replicas", 0)
            .build();
    final IngestTransportClient ingest = ClientBuilder.builder()
            .put(getSettings())
            .setMetric(new LongAdderIngestMetric())
            .toIngestTransportClient();
    try {
        ingest.newIndex("replicatest", settings, null);
        ingest.waitForCluster("GREEN", TimeValue.timeValueSeconds(30));
        for (int i = 0; i < 12345; i++) {
            ingest.index("replicatest", "replicatest", null, "{ \"name\" : \"" + randomString(32) + "\"}");
        }
        ingest.flushIngest();
        ingest.waitForResponses(TimeValue.timeValueSeconds(30));
        shardsAfterReplica = ingest.updateReplicaLevel("replicatest", replicaLevel);
        assertEquals(shardsAfterReplica, numberOfShards * (replicaLevel + 1));
    } catch (NoNodeAvailableException e) {
        logger.warn("skipping, no node available");
    } finally {
        ingest.shutdown();
        if (ingest.hasThrowable()) {
            logger.error("error", ingest.getThrowable());
        }
        assertFalse(ingest.hasThrowable());
    }
}
 
Example #22
Source File: BulkTransportDuplicateIDTest.java    From elasticsearch-helper with Apache License 2.0 5 votes vote down vote up
@Test
public void testDuplicateDocIDs() throws Exception {
    long numactions = NUM_ACTIONS;
    final BulkTransportClient client = ClientBuilder.builder()
            .put(getSettings())
            .put(ClientBuilder.MAX_ACTIONS_PER_REQUEST, MAX_ACTIONS)
            .setMetric(new LongAdderIngestMetric())
            .toBulkTransportClient();
    try {
        client.newIndex("test");
        for (int i = 0; i < NUM_ACTIONS; i++) {
            client.index("test", "test", randomString(1), "{ \"name\" : \"" + randomString(32) + "\"}");
        }
        client.flushIngest();
        client.waitForResponses(TimeValue.timeValueSeconds(30));
        client.refreshIndex("test");
        SearchRequestBuilder searchRequestBuilder = new SearchRequestBuilder(client.client(), SearchAction.INSTANCE)
                .setIndices("test")
                .setTypes("test")
                .setQuery(matchAllQuery());
        long hits = searchRequestBuilder.execute().actionGet().getHits().getTotalHits();
        logger.info("hits = {}", hits);
        assertTrue(hits < NUM_ACTIONS);
    } catch (NoNodeAvailableException e) {
        logger.warn("skipping, no node available");
    } finally {
        client.shutdown();
        assertEquals(numactions, client.getMetric().getSucceeded().getCount());
        if (client.hasThrowable()) {
            logger.error("error", client.getThrowable());
        }
        assertFalse(client.hasThrowable());
    }
}
 
Example #23
Source File: TestPutElasticsearch5.java    From localization_nifi with Apache License 2.0 5 votes vote down vote up
@Override
protected Client getTransportClient(Settings.Builder settingsBuilder, String xPackPath,
                                    String username, String password,
                                    List<InetSocketAddress> esHosts, ComponentLog log)
        throws MalformedURLException {
    final Client mockClient = mock(Client.class);
    BulkRequestBuilder bulkRequestBuilder = spy(new BulkRequestBuilder(mockClient, BulkAction.INSTANCE));
    if (exceptionToThrow != null) {
        doThrow(exceptionToThrow).when(bulkRequestBuilder).execute();
    } else {
        doReturn(new MockBulkRequestBuilderExecutor(responseHasFailures, esHosts.get(0))).when(bulkRequestBuilder).execute();
    }
    when(mockClient.prepareBulk()).thenReturn(bulkRequestBuilder);

    when(mockClient.prepareIndex(anyString(), anyString(), anyString())).thenAnswer(new Answer<IndexRequestBuilder>() {
        @Override
        public IndexRequestBuilder answer(InvocationOnMock invocationOnMock) throws Throwable {
            Object[] args = invocationOnMock.getArguments();
            String arg1 = (String) args[0];
            if (arg1.isEmpty()) {
                throw new NoNodeAvailableException("Needs index");
            }
            String arg2 = (String) args[1];
            if (arg2.isEmpty()) {
                throw new NoNodeAvailableException("Needs doc type");
            } else {
                IndexRequestBuilder indexRequestBuilder = new IndexRequestBuilder(mockClient, IndexAction.INSTANCE);
                return indexRequestBuilder;
            }
        }
    });

    return mockClient;
}
 
Example #24
Source File: EsRetryTest.java    From io with Apache License 2.0 5 votes vote down vote up
void throwException() {
    // 3回目の呼び出しまではNoNodeAvailableExceptionをスローする
    if (this.retryTimes == 3) {
        this.retryTimes = 0;
        // 4回目の呼び出しでthis.successがtrueの場合、例外を上げない
        // 呼出しもとで正常な処理を行う
        if (this.flag) {
            return;
        }
        // 4回目の呼び出しでthis.successがfalseの場合、IllegalStateExceptionをスローする
        throw new IllegalStateException();
    }
    this.retryTimes++;
    throw new NoNodeAvailableException();
}
 
Example #25
Source File: EsRetryTest.java    From io with Apache License 2.0 5 votes vote down vote up
void throwException() {
    // 3回目の呼び出しまではNoNodeAvailableExceptionをスローする
    if (this.retryTimes == 3) {
        this.retryTimes = 0;
        // 4回目の呼び出しでthis.successがtrueの場合、例外を上げない
        // 呼出しもとで正常な処理を行う
        if (this.flag) {
            return;
        }
        // 4回目の呼び出しでthis.successがfalseの場合、IllegalStateExceptionをスローする
        throw new IllegalStateException();
    }
    this.retryTimes++;
    throw new NoNodeAvailableException();
}
 
Example #26
Source File: SSLTest.java    From deprecated-security-ssl with Apache License 2.0 5 votes vote down vote up
@Test
public void testTransportClientSSLFail() throws Exception {
    thrown.expect(NoNodeAvailableException.class);

    final Settings settings = Settings.builder().put("opendistro_security.ssl.transport.enabled", true)
            .put(SSLConfigConstants.OPENDISTRO_SECURITY_SSL_HTTP_ENABLE_OPENSSL_IF_AVAILABLE, allowOpenSSL)
            .put(SSLConfigConstants.OPENDISTRO_SECURITY_SSL_TRANSPORT_ENABLE_OPENSSL_IF_AVAILABLE, allowOpenSSL)
            .put(SSLConfigConstants.OPENDISTRO_SECURITY_SSL_TRANSPORT_KEYSTORE_ALIAS, "node-0")
            .put("opendistro_security.ssl.transport.keystore_filepath", getAbsoluteFilePathFromClassPath("node-0-keystore.jks"))
            .put("opendistro_security.ssl.transport.truststore_filepath", getAbsoluteFilePathFromClassPath("truststore.jks"))
            .put("opendistro_security.ssl.transport.enforce_hostname_verification", false)
            .put("opendistro_security.ssl.transport.resolve_hostname", false).build();

    startES(settings);

    final Settings tcSettings = Settings.builder().put("cluster.name", clustername)
            .put("path.home", getAbsoluteFilePathFromClassPath("node-0-keystore.jks").getParent())
            .put("opendistro_security.ssl.transport.keystore_filepath", getAbsoluteFilePathFromClassPath("node-0-keystore.jks"))
            .put("opendistro_security.ssl.transport.truststore_filepath", getAbsoluteFilePathFromClassPath("truststore_fail.jks"))
            .put("opendistro_security.ssl.transport.enforce_hostname_verification", false)
            .put("opendistro_security.ssl.transport.resolve_hostname", false).build();

    try (TransportClient tc = new TransportClientImpl(tcSettings, asCollection(OpenDistroSecuritySSLPlugin.class))) {
        tc.addTransportAddress(new TransportAddress(new InetSocketAddress(nodeHost, nodePort)));
        Assert.assertEquals(3, tc.admin().cluster().nodesInfo(new NodesInfoRequest()).actionGet().getNodes().size());
    }
}
 
Example #27
Source File: EsRetryTest.java    From io with Apache License 2.0 5 votes vote down vote up
void throwException() {
    // 3回目の呼び出しまではNoNodeAvailableExceptionをスローする
    if (this.retryTimes == 3) {
        this.retryTimes = 0;
        // 4回目の呼び出しでthis.successがtrueの場合、例外を上げない
        // 呼出しもとで正常な処理を行う
        if (this.flag) {
            return;
        }
        // 4回目の呼び出しでthis.successがfalseの場合、IllegalStateExceptionをスローする
        throw new IllegalStateException();
    }
    this.retryTimes++;
    throw new NoNodeAvailableException("retry error");
}
 
Example #28
Source File: BulkNodeDuplicateIDTest.java    From elasticsearch-helper with Apache License 2.0 5 votes vote down vote up
@Test
public void testDuplicateDocIDs() throws Exception {
    long numactions = NUM_ACTIONS;
    final BulkNodeClient client = ClientBuilder.builder()
            .put(ClientBuilder.MAX_ACTIONS_PER_REQUEST, MAX_ACTIONS)
            .setMetric(new LongAdderIngestMetric())
            .toBulkNodeClient(client("1"));
    try {
        client.newIndex("test");
        for (int i = 0; i < NUM_ACTIONS; i++) {
            client.index("test", "test", randomString(1), "{ \"name\" : \"" + randomString(32) + "\"}");
        }
        client.flushIngest();
        client.waitForResponses(TimeValue.timeValueSeconds(30));
        client.refreshIndex("test");
        SearchRequestBuilder searchRequestBuilder = new SearchRequestBuilder(client.client(), SearchAction.INSTANCE)
                .setIndices("test")
                .setTypes("test")
                .setQuery(matchAllQuery());
        long hits = searchRequestBuilder.execute().actionGet().getHits().getTotalHits();
        logger.info("hits = {}", hits);
        assertTrue(hits < NUM_ACTIONS);
    } catch (NoNodeAvailableException e) {
        logger.warn("skipping, no node available");
    } finally {
        client.shutdown();
        assertEquals(numactions, client.getMetric().getSucceeded().getCount());
        if (client.hasThrowable()) {
            logger.error("error", client.getThrowable());
        }
        assertFalse(client.hasThrowable());
    }
}
 
Example #29
Source File: ElasticsearchClient.java    From yacy_grid_mcp with GNU Lesser General Public License v2.1 5 votes vote down vote up
public void setMapping(String indexName, String mapping) {
    try {
        this.elasticsearchClient.admin().indices().preparePutMapping(indexName)
            .setSource(mapping, XContentType.JSON)
            .setType("_default_").execute().actionGet();
    } catch (NoNodeAvailableException | IllegalStateException | ClusterBlockException | SearchPhaseExecutionException e) {
        Data.logger.warn("", e);
    };
}
 
Example #30
Source File: EsRetryTest.java    From io with Apache License 2.0 5 votes vote down vote up
void throwException() {
    // 3回目の呼び出しまではNoNodeAvailableExceptionをスローする
    if (this.retryTimes == 3) {
        this.retryTimes = 0;
        // 4回目の呼び出しでthis.successがtrueの場合、例外を上げない
        // 呼出しもとで正常な処理を行う
        if (this.flag) {
            return;
        }
        // 4回目の呼び出しでthis.successがfalseの場合、IllegalStateExceptionをスローする
        throw new IllegalStateException();
    }
    this.retryTimes++;
    throw new NoNodeAvailableException("retry error");
}