vinson0526 commented on a change in pull request #2228: add 
spark-doris-connector extension
URL: https://github.com/apache/incubator-doris/pull/2228#discussion_r348337597
 
 

 ##########
 File path: 
extension/spark-doris-connector/src/main/java/org/apache/doris/spark/rest/RestService.java
 ##########
 @@ -0,0 +1,464 @@
+// 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.doris.spark.rest;
+
+import static org.apache.doris.spark.cfg.ConfigurationOptions.DORIS_FENODES;
+import static 
org.apache.doris.spark.cfg.ConfigurationOptions.DORIS_FILTER_QUERY;
+import static org.apache.doris.spark.cfg.ConfigurationOptions.DORIS_READ_FIELD;
+import static 
org.apache.doris.spark.cfg.ConfigurationOptions.DORIS_REQUEST_AUTH_PASSWORD;
+import static 
org.apache.doris.spark.cfg.ConfigurationOptions.DORIS_REQUEST_AUTH_USER;
+import static 
org.apache.doris.spark.cfg.ConfigurationOptions.DORIS_TABLET_SIZE;
+import static 
org.apache.doris.spark.cfg.ConfigurationOptions.DORIS_TABLET_SIZE_DEFAULT;
+import static 
org.apache.doris.spark.cfg.ConfigurationOptions.DORIS_TABLET_SIZE_MIN;
+import static 
org.apache.doris.spark.cfg.ConfigurationOptions.DORIS_TABLE_IDENTIFIER;
+import static org.apache.doris.spark.util.ErrorMessages.CONNECT_FAILED_MESSAGE;
+import static 
org.apache.doris.spark.util.ErrorMessages.ILLEGAL_ARGUMENT_MESSAGE;
+import static 
org.apache.doris.spark.util.ErrorMessages.PARSE_NUMBER_FAILED_MESSAGE;
+import static 
org.apache.doris.spark.util.ErrorMessages.SHOULD_NOT_HAPPEN_MESSAGE;
+
+import java.io.IOException;
+import java.io.Serializable;
+import java.nio.charset.StandardCharsets;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.commons.lang3.StringUtils;
+import org.apache.doris.spark.cfg.ConfigurationOptions;
+import org.apache.doris.spark.cfg.Settings;
+import org.apache.doris.spark.exception.ConnectedFailedException;
+import org.apache.doris.spark.exception.DorisException;
+import org.apache.doris.spark.exception.IllegalArgumentException;
+import org.apache.doris.spark.exception.ShouldNeverHappenException;
+import org.apache.doris.spark.rest.models.QueryPlan;
+import org.apache.doris.spark.rest.models.Schema;
+import org.apache.doris.spark.rest.models.Tablet;
+import org.apache.doris.spark.util.ErrorMessages;
+import org.apache.http.HttpStatus;
+import org.apache.http.auth.AuthScope;
+import org.apache.http.auth.UsernamePasswordCredentials;
+import org.apache.http.client.CredentialsProvider;
+import org.apache.http.client.config.RequestConfig;
+import org.apache.http.client.methods.CloseableHttpResponse;
+import org.apache.http.client.methods.HttpGet;
+import org.apache.http.client.methods.HttpPost;
+import org.apache.http.client.methods.HttpRequestBase;
+import org.apache.http.client.protocol.HttpClientContext;
+import org.apache.http.entity.StringEntity;
+import org.apache.http.impl.client.BasicCredentialsProvider;
+import org.apache.http.impl.client.CloseableHttpClient;
+import org.apache.http.impl.client.HttpClients;
+import org.apache.http.util.EntityUtils;
+import org.codehaus.jackson.JsonParseException;
+import org.codehaus.jackson.map.JsonMappingException;
+import org.codehaus.jackson.map.ObjectMapper;
+import org.slf4j.Logger;
+
+import com.google.common.annotations.VisibleForTesting;
+
+/**
+ * Service for communicate with Doris FE.
+ */
+public class RestService implements Serializable {
+    public final static int REST_RESPONSE_STATUS_OK = 200;
+    private static final String API_PREFIX = "/api";
+    private static final String SCHEMA = "_schema";
+    private static final String QUERY_PLAN = "_query_plan";
+
+    /**
+     * send request to Doris FE and get response json string.
+     * @param cfg configuration of request
+     * @param request {@link HttpRequestBase} real request
+     * @param logger {@link Logger}
+     * @return Doris FE response in json string
+     * @throws ConnectedFailedException throw when cannot connect to Doris FE
+     */
+    private static String send(Settings cfg, HttpRequestBase request, Logger 
logger) throws
+            ConnectedFailedException {
+        int connectTimeout = 
cfg.getIntegerProperty(ConfigurationOptions.DORIS_REQUEST_CONNECT_TIMEOUT_MS,
+                ConfigurationOptions.DORIS_REQUEST_CONNECT_TIMEOUT_DEFAULT);
+        int socketTimeout = 
cfg.getIntegerProperty(ConfigurationOptions.DORIS_REQUEST_READ_TIMEOUT_MS,
+                ConfigurationOptions.DORIS_REQUEST_READ_TIMEOUT_DEFAULT);
+        int retries = 
cfg.getIntegerProperty(ConfigurationOptions.DORIS_REQUEST_RETRIES,
+                ConfigurationOptions.DORIS_REQUEST_RETRIES_DEFAULT);
+        logger.trace("connect timeout set to '{}'.", connectTimeout);
+        logger.trace("socket timeout set to '{}'.", socketTimeout);
+        logger.trace("retries set to '{}'.", retries);
 
 Review comment:
   done

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to