yfsn666 commented on code in PR #10837: URL: https://github.com/apache/inlong/pull/10837#discussion_r1725053330
########## inlong-sort-standalone/sort-standalone-source/src/main/java/org/apache/inlong/sort/standalone/sink/http/HttpSink.java: ########## @@ -0,0 +1,90 @@ +/* + * 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.inlong.sort.standalone.sink.http; + +import org.apache.inlong.sort.standalone.sink.SinkContext; +import org.apache.inlong.sort.standalone.utils.BufferQueue; + +import org.apache.flume.Context; +import org.apache.flume.EventDeliveryException; +import org.apache.flume.conf.Configurable; +import org.apache.flume.sink.AbstractSink; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.ArrayList; +import java.util.List; + +public class HttpSink extends AbstractSink implements Configurable { + + public static final Logger LOG = LoggerFactory.getLogger(HttpSink.class); + + private Context parentContext; + private BufferQueue<HttpRequest> dispatchQueue; + private HttpSinkContext context; + // workers + private List<HttpChannelWorker> workers = new ArrayList<>(); + // output + private HttpOutputChannel outputChannel; + + @Override + public void start() { + super.start(); + try { + this.dispatchQueue = SinkContext.createBufferQueue(); + this.context = new HttpSinkContext(getName(), parentContext, getChannel(), dispatchQueue); + this.context.start(); + for (int i = 0; i < context.getMaxThreads(); i++) { + HttpChannelWorker worker = new HttpChannelWorker(context, i); + this.workers.add(worker); + worker.start(); + } + this.outputChannel = HttpSinkFactory.createHttpOutputChannel(context); + this.outputChannel.init(); + this.outputChannel.start(); + } catch (Exception e) { + LOG.error(e.getMessage(), e); + } + } + + @Override + public void stop() { + super.stop(); + try { + this.context.close(); + for (HttpChannelWorker worker : this.workers) { + worker.close(); + } + this.workers.clear(); + this.outputChannel.close(); + } catch (Exception e) { + LOG.error(e.getMessage(), e); + } + } + + @Override + public void configure(Context context) { + LOG.info("start to configure:{}, context:{}.", this.getName(), context.toString()); Review Comment: fixed. ########## inlong-sort-standalone/sort-standalone-source/src/main/java/org/apache/inlong/sort/standalone/sink/http/HttpSinkContext.java: ########## @@ -0,0 +1,405 @@ +/* + * 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.inlong.sort.standalone.sink.http; + +import org.apache.inlong.common.pojo.sort.ClusterTagConfig; +import org.apache.inlong.common.pojo.sort.TaskConfig; +import org.apache.inlong.common.pojo.sort.node.HttpNodeConfig; +import org.apache.inlong.common.pojo.sortstandalone.SortTaskConfig; +import org.apache.inlong.sort.standalone.channel.ProfileEvent; +import org.apache.inlong.sort.standalone.config.holder.CommonPropertiesHolder; +import org.apache.inlong.sort.standalone.config.holder.SortClusterConfigHolder; +import org.apache.inlong.sort.standalone.config.holder.v2.SortConfigHolder; +import org.apache.inlong.sort.standalone.config.pojo.InlongId; +import org.apache.inlong.sort.standalone.metrics.SortConfigMetricReporter; +import org.apache.inlong.sort.standalone.metrics.SortMetricItem; +import org.apache.inlong.sort.standalone.metrics.audit.AuditUtils; +import org.apache.inlong.sort.standalone.sink.SinkContext; +import org.apache.inlong.sort.standalone.utils.BufferQueue; +import org.apache.inlong.sort.standalone.utils.Constants; +import org.apache.inlong.sort.standalone.utils.InlongLoggerFactory; + +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.DeserializationFeature; +import com.fasterxml.jackson.databind.ObjectMapper; +import org.apache.commons.lang3.ClassUtils; +import org.apache.flume.Channel; +import org.apache.flume.Context; +import org.slf4j.Logger; + +import java.util.Collection; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.atomic.AtomicLong; +import java.util.stream.Collectors; + +public class HttpSinkContext extends SinkContext { + + public static final Logger LOG = InlongLoggerFactory.getLogger(HttpSinkContext.class); + public static final String KEY_NODE_ID = "nodeId"; + public static final String KEY_BASE_URL = "baseUrl"; + public static final String KEY_ENABLE_CREDENTIAL = "enableCredential"; + public static final String KEY_USERNAME = "username"; + public static final String KEY_PASSWORD = "password"; + public static final String KEY_MAX_CONNECT_TOTAL = "maxConnect"; + public static final String KEY_MAX_CONNECT_PER_ROUTE = "maxConnectPerRoute"; + public static final String KEY_CONNECTION_REQUEST_TIMEOUT = "connectionRequestTimeout"; + public static final String KEY_SOCKET_TIMEOUT = "socketTimeout"; + public static final String KEY_MAX_REDIRECTS = "maxRedirects"; + public static final String KEY_LOG_MAX_LENGTH = "logMaxLength"; + public static final String KEY_EVENT_HTTPREQUEST_HANDLER = "httpRequestHandler"; Review Comment: fixed. -- 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: commits-unsubscr...@inlong.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org