org.elasticsearch.common.transport.LocalTransportAddress Java Examples

The following examples show how to use org.elasticsearch.common.transport.LocalTransportAddress. 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: ElasticsearchSinkITCase.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
@Override
protected ElasticsearchSinkBase<Tuple2<Integer, String>, Client> createElasticsearchSinkForEmbeddedNode(
		int bulkFlushMaxActions,
		String clusterName,
		ElasticsearchSinkFunction<Tuple2<Integer, String>> elasticsearchSinkFunction) throws Exception {

	Map<String, String> userConfig = createUserConfig(bulkFlushMaxActions, clusterName);

	// Elasticsearch 1.x requires this setting when using
	// LocalTransportAddress to connect to a local embedded node
	userConfig.put("node.local", "true");

	List<TransportAddress> transports = new ArrayList<>();
	transports.add(new LocalTransportAddress("1"));

	return new ElasticsearchSink<>(
		Collections.unmodifiableMap(userConfig),
		transports,
		elasticsearchSinkFunction);
}
 
Example #2
Source File: ElasticsearchSinkITCase.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
/**
 * Tests that behaviour of the deprecated {@link IndexRequestBuilder} constructor works properly.
 */
@Test
public void testDeprecatedIndexRequestBuilderVariant() throws Exception {
	final String index = "index-req-builder-test-index";

	final StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();

	DataStreamSource<Tuple2<Integer, String>> source = env.addSource(new SourceSinkDataTestKit.TestDataSourceFunction());

	Map<String, String> userConfig = new HashMap<>();
	// This instructs the sink to emit after every element, otherwise they would be buffered
	userConfig.put(ElasticsearchSinkBase.CONFIG_KEY_BULK_FLUSH_MAX_ACTIONS, "1");
	userConfig.put("cluster.name", CLUSTER_NAME);
	userConfig.put("node.local", "true");

	List<TransportAddress> transports = new ArrayList<>();
	transports.add(new LocalTransportAddress("1"));

	source.addSink(new ElasticsearchSink<>(
		userConfig,
		transports,
		new TestIndexRequestBuilder(index))
	);

	env.execute("Elasticsearch Deprecated IndexRequestBuilder Bridge Test");

	// verify the results
	Client client = embeddedNodeEnv.getClient();
	SourceSinkDataTestKit.verifyProducedSinkData(client, index);

	client.close();
}
 
Example #3
Source File: LocalTransport.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
@Override
protected void doStart() {
    String address = settings.get(TRANSPORT_LOCAL_ADDRESS);
    if (address == null) {
        address = Long.toString(transportAddressIdGenerator.incrementAndGet());
    }
    localAddress = new LocalTransportAddress(address);
    LocalTransport previous = transports.put(localAddress, this);
    if (previous != null) {
        throw new ElasticsearchException("local address [" + address + "] is already bound");
    }
    boundAddress = new BoundTransportAddress(new TransportAddress[] { localAddress }, localAddress);
}
 
Example #4
Source File: BulkProcessorObjectFactoryTest.java    From log4j2-elasticsearch with Apache License 2.0 5 votes vote down vote up
@Test
public void clientIsCalledWhenBatchItemIsAdded() {

    // given
    Builder builder = createTestObjectFactoryBuilder();
    ClientObjectFactory<TransportClient, BulkRequest> config = spy(builder.build());

    Settings settings = Settings.builder().build();
    TransportClient client = spy(new PreBuiltTransportClient(settings));
    client.addTransportAddress(new LocalTransportAddress("1"));
    when(config.createClient()).thenReturn(client);

    FailoverPolicy failoverPolicy = spy(new NoopFailoverPolicy());

    BulkProcessorFactory bulkProcessorFactory = new BulkProcessorFactory();
    BatchEmitter batchEmitter = bulkProcessorFactory.createInstance(
                    1,
                    100,
                    config,
                    failoverPolicy);

    String payload1 = "test1";
    ActionRequest testRequest = createTestRequest(payload1);

    // when
    batchEmitter.add(testRequest);

    // then
    ArgumentCaptor<BulkRequest> captor = ArgumentCaptor.forClass(BulkRequest.class);
    verify(client, times(1)).bulk(captor.capture(), Mockito.any());

    assertEquals(payload1, new BulkRequestIntrospector().items(captor.getValue()).iterator().next());
}
 
Example #5
Source File: BulkProcessorObjectFactoryTest.java    From log4j2-elasticsearch with Apache License 2.0 5 votes vote down vote up
@Test
public void failoverIsExecutedAfterNonSuccessfulRequest() {

    // given
    Builder builder = createTestObjectFactoryBuilder();
    ClientObjectFactory<TransportClient, BulkRequest> config = spy(builder.build());

    FailoverPolicy failoverPolicy = spy(new NoopFailoverPolicy());
    Function handler = spy(config.createFailureHandler(failoverPolicy));
    when(config.createFailureHandler(any())).thenReturn(handler);

    Settings settings = Settings.builder().build();
    TransportClient client = spy(new PreBuiltTransportClient(settings));
    client.addTransportAddress(new LocalTransportAddress("1"));
    when(config.createClient()).thenReturn(client);

    BulkProcessorFactory bulkProcessorFactory = new BulkProcessorFactory();
    BatchEmitter batchEmitter = bulkProcessorFactory.createInstance(
            1,
            100,
            config,
            failoverPolicy);

    String payload1 = "test1";
    ActionRequest testRequest = createTestRequest(payload1);

    // when
    batchEmitter.add(testRequest);

    // then
    ArgumentCaptor<BulkRequest> captor = ArgumentCaptor.forClass(BulkRequest.class);
    verify(handler, times(1)).apply(captor.capture());

    assertEquals(payload1, new BulkRequestIntrospector().items(captor.getValue()).iterator().next());
}
 
Example #6
Source File: BulkProcessorObjectFactoryTest.java    From log4j2-elasticsearch with Apache License 2.0 5 votes vote down vote up
@Test
public void clientIsCalledWhenBatchItemIsAdded() {

    // given
    Builder builder = createTestObjectFactoryBuilder();
    ClientObjectFactory<TransportClient, BulkRequest> config = spy(builder.build());

    Settings settings = Settings.builder()
            .put("node.local", true)
            .build();

    TransportClient client = spy(TransportClient.builder().settings(settings).build());
    client.addTransportAddress(new LocalTransportAddress("1"));
    when(config.createClient()).thenReturn(client);

    FailoverPolicy failoverPolicy = spy(new NoopFailoverPolicy());

    BulkProcessorFactory bulkProcessorFactory = new BulkProcessorFactory();
    BatchEmitter batchEmitter = bulkProcessorFactory.createInstance(
                    1,
                    100,
                    config,
                    failoverPolicy);

    String payload1 = "test1";
    ActionRequest testRequest = createTestRequest(payload1);

    // when
    batchEmitter.add(testRequest);

    // then
    ArgumentCaptor<BulkRequest> captor = ArgumentCaptor.forClass(BulkRequest.class);
    verify(client, times(1)).bulk(captor.capture(), Mockito.any());

    assertEquals(payload1, new BulkRequestIntrospector().items(captor.getValue()).iterator().next());
}
 
Example #7
Source File: BulkProcessorObjectFactoryTest.java    From log4j2-elasticsearch with Apache License 2.0 5 votes vote down vote up
@Test
public void failoverIsExecutedAfterNonSuccessfulRequest() {

    // given
    Builder builder = createTestObjectFactoryBuilder();
    ClientObjectFactory<TransportClient, BulkRequest> config = spy(builder.build());

    FailoverPolicy failoverPolicy = spy(new NoopFailoverPolicy());
    Function handler = spy(config.createFailureHandler(failoverPolicy));
    when(config.createFailureHandler(any())).thenReturn(handler);

    Settings settings = Settings.builder().put("node.local", "true").build();
    TransportClient client = spy(TransportClient.builder().settings(settings).build());
    client.addTransportAddress(new LocalTransportAddress("1"));
    when(config.createClient()).thenReturn(client);

    BulkProcessorFactory bulkProcessorFactory = new BulkProcessorFactory();
    BatchEmitter batchEmitter = bulkProcessorFactory.createInstance(
            1,
            100,
            config,
            failoverPolicy);

    String payload1 = "test1";
    ActionRequest testRequest = createTestRequest(payload1);

    // when
    batchEmitter.add(testRequest);

    // then
    ArgumentCaptor<BulkRequest> captor = ArgumentCaptor.forClass(BulkRequest.class);
    verify(handler, times(1)).apply(captor.capture());

    assertEquals(payload1, new BulkRequestIntrospector().items(captor.getValue()).iterator().next());
}
 
Example #8
Source File: LocalTransport.java    From Elasticsearch with Apache License 2.0 4 votes vote down vote up
@Override
public TransportAddress[] addressesFromString(String address, int perAddressLimit) {
    return new TransportAddress[]{new LocalTransportAddress(address)};
}
 
Example #9
Source File: LocalTransport.java    From Elasticsearch with Apache License 2.0 4 votes vote down vote up
@Override
public boolean addressSupported(Class<? extends TransportAddress> address) {
    return LocalTransportAddress.class.equals(address);
}
 
Example #10
Source File: ClientFactory.java    From storm-trident-elasticsearch with Apache License 2.0 4 votes vote down vote up
@Override
public TransportClient makeClient(Map conf) {
    TransportClient client = new TransportClient(buildSettings());
    client.addTransportAddress(new LocalTransportAddress("1"));
    return client;
}