1515
1616package io .confluent .connect .elasticsearch ;
1717
18- import io .confluent .connect .elasticsearch .bulk .BulkProcessor ;
1918import io .confluent .connect .elasticsearch .jest .JestElasticsearchClient ;
2019import org .apache .kafka .clients .consumer .OffsetAndMetadata ;
2120import org .apache .kafka .common .TopicPartition ;
2726import org .slf4j .LoggerFactory ;
2827
2928import java .util .Collection ;
30- import java .util .HashMap ;
3129import java .util .HashSet ;
32- import java .util .List ;
3330import java .util .Map ;
3431import java .util .Set ;
3532import java .util .concurrent .TimeUnit ;
@@ -58,61 +55,16 @@ public void start(Map<String, String> props, ElasticsearchClient client) {
5855 log .info ("Starting ElasticsearchSinkTask." );
5956
6057 ElasticsearchSinkConnectorConfig config = new ElasticsearchSinkConnectorConfig (props );
61- String type = config .getString (ElasticsearchSinkConnectorConfig .TYPE_NAME_CONFIG );
62- boolean ignoreKey =
63- config .getBoolean (ElasticsearchSinkConnectorConfig .KEY_IGNORE_CONFIG );
64- boolean ignoreSchema =
65- config .getBoolean (ElasticsearchSinkConnectorConfig .SCHEMA_IGNORE_CONFIG );
66- boolean useCompactMapEntries =
67- config .getBoolean (ElasticsearchSinkConnectorConfig .COMPACT_MAP_ENTRIES_CONFIG );
68-
69-
70- Map <String , String > topicToIndexMap =
71- parseMapConfig (config .getList (ElasticsearchSinkConnectorConfig .TOPIC_INDEX_MAP_CONFIG ));
72- Set <String > topicIgnoreKey =
73- new HashSet <>(config .getList (ElasticsearchSinkConnectorConfig .TOPIC_KEY_IGNORE_CONFIG ));
74- Set <String > topicIgnoreSchema = new HashSet <>(
75- config .getList (ElasticsearchSinkConnectorConfig .TOPIC_SCHEMA_IGNORE_CONFIG )
76- );
77-
78- long flushTimeoutMs =
79- config .getLong (ElasticsearchSinkConnectorConfig .FLUSH_TIMEOUT_MS_CONFIG );
80- int maxBufferedRecords =
81- config .getInt (ElasticsearchSinkConnectorConfig .MAX_BUFFERED_RECORDS_CONFIG );
82- int batchSize =
83- config .getInt (ElasticsearchSinkConnectorConfig .BATCH_SIZE_CONFIG );
84- long lingerMs =
85- config .getLong (ElasticsearchSinkConnectorConfig .LINGER_MS_CONFIG );
86- int maxInFlightRequests =
87- config .getInt (ElasticsearchSinkConnectorConfig .MAX_IN_FLIGHT_REQUESTS_CONFIG );
88- long retryBackoffMs =
89- config .getLong (ElasticsearchSinkConnectorConfig .RETRY_BACKOFF_MS_CONFIG );
90- int maxRetry =
91- config .getInt (ElasticsearchSinkConnectorConfig .MAX_RETRIES_CONFIG );
92- boolean dropInvalidMessage =
93- config .getBoolean (ElasticsearchSinkConnectorConfig .DROP_INVALID_MESSAGE_CONFIG );
94- boolean createIndicesAtStartTime =
95- config .getBoolean (ElasticsearchSinkConnectorConfig .AUTO_CREATE_INDICES_AT_START_CONFIG );
96-
97- DataConverter .BehaviorOnNullValues behaviorOnNullValues =
98- DataConverter .BehaviorOnNullValues .forValue (
99- config .getString (ElasticsearchSinkConnectorConfig .BEHAVIOR_ON_NULL_VALUES_CONFIG )
100- );
101-
102- BulkProcessor .BehaviorOnMalformedDoc behaviorOnMalformedDoc =
103- BulkProcessor .BehaviorOnMalformedDoc .forValue (
104- config .getString (ElasticsearchSinkConnectorConfig .BEHAVIOR_ON_MALFORMED_DOCS_CONFIG )
105- );
10658
10759 // Calculate the maximum possible backoff time ...
10860 long maxRetryBackoffMs =
109- RetryUtil .computeRetryWaitTimeInMillis (maxRetry , retryBackoffMs );
61+ RetryUtil .computeRetryWaitTimeInMillis (config . maxRetries (), config . retryBackoffMs () );
11062 if (maxRetryBackoffMs > RetryUtil .MAX_RETRY_TIME_MS ) {
11163 log .warn ("This connector uses exponential backoff with jitter for retries, "
11264 + "and using '{}={}' and '{}={}' results in an impractical but possible maximum "
11365 + "backoff time greater than {} hours." ,
114- ElasticsearchSinkConnectorConfig .MAX_RETRIES_CONFIG , maxRetry ,
115- ElasticsearchSinkConnectorConfig .RETRY_BACKOFF_MS_CONFIG , retryBackoffMs ,
66+ ElasticsearchSinkConnectorConfig .MAX_RETRIES_CONFIG , config . maxRetries () ,
67+ ElasticsearchSinkConnectorConfig .RETRY_BACKOFF_MS_CONFIG , config . retryBackoffMs () ,
11668 TimeUnit .MILLISECONDS .toHours (maxRetryBackoffMs ));
11769 }
11870
@@ -123,23 +75,23 @@ public void start(Map<String, String> props, ElasticsearchClient client) {
12375 }
12476
12577 ElasticsearchWriter .Builder builder = new ElasticsearchWriter .Builder (this .client )
126- .setType (type )
127- .setIgnoreKey (ignoreKey , topicIgnoreKey )
128- .setIgnoreSchema (ignoreSchema , topicIgnoreSchema )
129- .setCompactMapEntries (useCompactMapEntries )
130- .setTopicToIndexMap (topicToIndexMap )
131- .setFlushTimoutMs (flushTimeoutMs )
132- .setMaxBufferedRecords (maxBufferedRecords )
133- .setMaxInFlightRequests (maxInFlightRequests )
134- .setBatchSize (batchSize )
135- .setLingerMs (lingerMs )
136- .setRetryBackoffMs (retryBackoffMs )
137- .setMaxRetry (maxRetry )
138- .setDropInvalidMessage (dropInvalidMessage )
139- .setBehaviorOnNullValues (behaviorOnNullValues )
140- .setBehaviorOnMalformedDoc (behaviorOnMalformedDoc );
141-
142- this .createIndicesAtStartTime = createIndicesAtStartTime ;
78+ .setType (config . type () )
79+ .setIgnoreKey (config . ignoreKey (), config . ignoreKeyTopics () )
80+ .setIgnoreSchema (config . ignoreSchema (), config . ignoreSchemaTopics () )
81+ .setCompactMapEntries (config . useCompactMapEntries () )
82+ .setTopicToIndexMap (config . topicToIndexMap () )
83+ .setFlushTimoutMs (config . flushTimeoutMs () )
84+ .setMaxBufferedRecords (config . maxBufferedRecords () )
85+ .setMaxInFlightRequests (config . maxInFlightRequests () )
86+ .setBatchSize (config . batchSize () )
87+ .setLingerMs (config . lingerMs () )
88+ .setRetryBackoffMs (config . retryBackoffMs () )
89+ .setMaxRetry (config . maxRetries () )
90+ .setDropInvalidMessage (config . dropInvalidMessage () )
91+ .setBehaviorOnNullValues (config . behaviorOnNullValues () )
92+ .setBehaviorOnMalformedDoc (config . behaviorOnMalformedDoc () );
93+
94+ this .createIndicesAtStartTime = config . createIndicesAtStart () ;
14395
14496 writer = builder .build ();
14597 writer .start ();
@@ -190,16 +142,4 @@ public void stop() throws ConnectException {
190142 client .close ();
191143 }
192144 }
193-
194- private Map <String , String > parseMapConfig (List <String > values ) {
195- Map <String , String > map = new HashMap <>();
196- for (String value : values ) {
197- String [] parts = value .split (":" );
198- String topic = parts [0 ];
199- String type = parts [1 ];
200- map .put (topic , type );
201- }
202- return map ;
203- }
204-
205145}
0 commit comments