snuyanzin commented on code in PR #56: URL: https://github.com/apache/flink-connector-opensearch/pull/56#discussion_r2810048190
########## flink-connector-opensearch3/src/main/java/org/apache/flink/connector/opensearch/sink/Opensearch3SinkBuilder.java: ########## @@ -0,0 +1,384 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.flink.connector.opensearch.sink; + +import org.apache.flink.annotation.PublicEvolving; +import org.apache.flink.connector.base.DeliveryGuarantee; +import org.apache.flink.connector.opensearch.sink.Opensearch3Writer.DefaultFailureHandler; +import org.apache.flink.connector.opensearch.sink.Opensearch3Writer.Opensearch3FailureHandler; +import org.apache.flink.util.InstantiationUtil; + +import org.apache.hc.core5.http.HttpHost; + +import java.util.Arrays; +import java.util.List; + +import static org.apache.flink.util.Preconditions.checkArgument; +import static org.apache.flink.util.Preconditions.checkNotNull; +import static org.apache.flink.util.Preconditions.checkState; + +/** + * Builder to construct an OpenSearch 3.x compatible {@link Opensearch3Sink}. + * + * <p>The following example shows the minimal setup to create an Opensearch3Sink that submits + * actions on checkpoint or the default number of actions was buffered (1000). + * + * <pre>{@code + * Opensearch3Sink<String> sink = new Opensearch3SinkBuilder<String>() + * .setHosts(new HttpHost("localhost", 9200, "https")) + * .setEmitter((element, context, indexer) -> { + * Map<String, Object> doc = new HashMap<>(); + * doc.put("data", element); + * indexer.addIndexRequest("my-index", element.hashCode() + "", doc); + * }) + * .setDeliveryGuarantee(DeliveryGuarantee.AT_LEAST_ONCE) + * .build(); + * }</pre> + * + * @param <IN> type of the records converted to OpenSearch actions + */ +@PublicEvolving +public class Opensearch3SinkBuilder<IN> { + + private int bulkFlushMaxActions = 1000; + private int bulkFlushMaxMb = -1; + private long bulkFlushInterval = -1; + private FlushBackoffType bulkFlushBackoffType = FlushBackoffType.NONE; + private int bulkFlushBackoffRetries = -1; + private long bulkFlushBackOffDelay = -1; + private DeliveryGuarantee deliveryGuarantee = DeliveryGuarantee.AT_LEAST_ONCE; + private List<HttpHost> hosts; + protected Opensearch3Emitter<? super IN> emitter; + private String username; + private String password; + private String connectionPathPrefix; + private Integer connectionTimeout; + private Integer connectionRequestTimeout; + private Integer socketTimeout; + private Boolean allowInsecure; + private Opensearch3FailureHandler failureHandler = new DefaultFailureHandler(); Review Comment: idea for follow up PR: I wonder if there should be a possibility to set these params via config options -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
