Support http remote conf

In our production practice, many Griffin jobs run on yarn in cluster mode. We upload  different conf files to the http file server and we also provide services that generate specific configurations based on different HTTP URLs.
So we supports setting HTTP URLs as conf in submitting Griffin jobs in this PR. There is no effect on JSON or File conf mode. And it works well in our production environment for a long time.

Author: yuxiaoyu <yuxiaoyu@bytedance.com>

Closes #587 from XiaoyuBD/support_http_url_conf.
diff --git a/measure/src/main/scala/org/apache/griffin/measure/configuration/dqdefinition/reader/ParamHttpReader.scala b/measure/src/main/scala/org/apache/griffin/measure/configuration/dqdefinition/reader/ParamHttpReader.scala
new file mode 100644
index 0000000..e7c19a8
--- /dev/null
+++ b/measure/src/main/scala/org/apache/griffin/measure/configuration/dqdefinition/reader/ParamHttpReader.scala
@@ -0,0 +1,42 @@
+/*
+ * 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.griffin.measure.configuration.dqdefinition.reader
+
+import scala.reflect.ClassTag
+import scala.util.Try
+
+import org.apache.griffin.measure.configuration.dqdefinition.Param
+import org.apache.griffin.measure.utils.{HttpUtil, JsonUtil}
+
+/**
+ * read params by http url
+ *
+ * @param httpUrl
+ */
+case class ParamHttpReader(httpUrl: String) extends ParamReader {
+
+  def readConfig[T <: Param](implicit m: ClassTag[T]): Try[T] = {
+    Try {
+      val params = Map[String, Object]()
+      val headers = Map[String, Object](("Content-Type", "application/json"))
+      val jsonString = HttpUtil.doHttpRequest(httpUrl, "get", params, headers, null)._2
+      val param = JsonUtil.fromJson[T](jsonString)
+      validate(param)
+    }
+  }
+}
diff --git a/measure/src/main/scala/org/apache/griffin/measure/configuration/dqdefinition/reader/ParamReaderFactory.scala b/measure/src/main/scala/org/apache/griffin/measure/configuration/dqdefinition/reader/ParamReaderFactory.scala
index 5067a9d..f4bfd28 100644
--- a/measure/src/main/scala/org/apache/griffin/measure/configuration/dqdefinition/reader/ParamReaderFactory.scala
+++ b/measure/src/main/scala/org/apache/griffin/measure/configuration/dqdefinition/reader/ParamReaderFactory.scala
@@ -23,6 +23,7 @@
 
   val json = "json"
   val file = "file"
+  val httpRegex = "^http[s]?://.*"
 
   /**
    * parse string content to get param reader
@@ -30,9 +31,13 @@
    * @return
    */
   def getParamReader(pathOrJson: String): ParamReader = {
-    val strType = paramStrType(pathOrJson)
-    if (json.equals(strType)) ParamJsonReader(pathOrJson)
-    else ParamFileReader(pathOrJson)
+    if (pathOrJson.matches(httpRegex)) {
+      ParamHttpReader(pathOrJson)
+    } else {
+      val strType = paramStrType(pathOrJson)
+      if (json.equals(strType)) ParamJsonReader(pathOrJson)
+      else ParamFileReader(pathOrJson)
+    }
   }
 
   private def paramStrType(str: String): String = {
diff --git a/measure/src/main/scala/org/apache/griffin/measure/sink/ElasticSearchSink.scala b/measure/src/main/scala/org/apache/griffin/measure/sink/ElasticSearchSink.scala
index d8cce41..3134b44 100644
--- a/measure/src/main/scala/org/apache/griffin/measure/sink/ElasticSearchSink.scala
+++ b/measure/src/main/scala/org/apache/griffin/measure/sink/ElasticSearchSink.scala
@@ -63,7 +63,8 @@
 
       def func(): (Long, Future[Boolean]) = {
         import scala.concurrent.ExecutionContext.Implicits.global
-        (timeStamp, Future(HttpUtil.doHttpRequest(api, method, params, header, data)))
+        val code = HttpUtil.doHttpRequest(api, method, params, header, data)._1
+        (timeStamp, Future(code >= 200 && code < 300))
       }
       if (block) SinkTaskRunner.addBlockTask(func _, retry, connectionTimeout)
       else SinkTaskRunner.addNonBlockTask(func _, retry)
diff --git a/measure/src/main/scala/org/apache/griffin/measure/utils/HttpUtil.scala b/measure/src/main/scala/org/apache/griffin/measure/utils/HttpUtil.scala
index 66648d0..652bbf7 100644
--- a/measure/src/main/scala/org/apache/griffin/measure/utils/HttpUtil.scala
+++ b/measure/src/main/scala/org/apache/griffin/measure/utils/HttpUtil.scala
@@ -19,10 +19,10 @@
 
 import scala.util.matching.Regex
 
-import org.apache.http.client.methods.{HttpGet, HttpPost}
+import org.apache.http.client.methods.{HttpDelete, HttpGet, HttpPost, HttpPut}
+import org.apache.http.client.utils.URIBuilder
 import org.apache.http.entity.{ContentType, StringEntity}
-import org.apache.http.impl.client.HttpClientBuilder
-import scalaj.http._
+import org.apache.http.impl.client.{BasicResponseHandler, HttpClientBuilder}
 
 object HttpUtil {
 
@@ -31,65 +31,34 @@
   val PUT_REGEX: Regex = """^(?i)put$""".r
   val DELETE_REGEX: Regex = """^(?i)delete$""".r
 
-  def postData(
-      url: String,
-      params: Map[String, Object],
-      headers: Map[String, Object],
-      data: String): Boolean = {
-    val response = Http(url)
-      .params(convertObjMap2StrMap(params))
-      .headers(convertObjMap2StrMap(headers))
-      .postData(data)
-      .asString
-
-    response.isSuccess
-  }
-
   def doHttpRequest(
       url: String,
       method: String,
       params: Map[String, Object],
       headers: Map[String, Object],
-      data: String): Boolean = {
+      data: String): (Integer, String) = {
     val client = HttpClientBuilder.create.build
-    method match {
+    val uriBuilder = new URIBuilder(url)
+    convertObjMap2StrMap(params) foreach (param => uriBuilder.setParameter(param._1, param._2))
+    val handler = new BasicResponseHandler()
+    val request = method match {
       case POST_REGEX() =>
-        val post = new HttpPost(url)
-        convertObjMap2StrMap(headers) foreach (header => post.addHeader(header._1, header._2))
+        val post = new HttpPost(uriBuilder.build())
         post.setEntity(new StringEntity(data, ContentType.APPLICATION_JSON))
-
-        // send the post request
-        val response = client.execute(post)
-        val code = response.getStatusLine.getStatusCode
-        code >= 200 && code < 300
+        post
       case PUT_REGEX() =>
-        val get = new HttpGet(url)
-        convertObjMap2StrMap(headers) foreach (header => get.addHeader(header._1, header._2))
-        val response = client.execute(get)
-        val code = response.getStatusLine.getStatusCode
-        code >= 200 && code < 300
-      case _ => false
+        val put = new HttpPut(uriBuilder.build())
+        put.setEntity(new StringEntity(data, ContentType.APPLICATION_JSON))
+        put
+      case GET_REGEX() =>
+        new HttpGet(uriBuilder.build())
+      case DELETE_REGEX() =>
+        new HttpDelete(uriBuilder.build())
+      case _ => throw new UnsupportedOperationException("Unsupported http method error!")
     }
-  }
-
-  def httpRequest(
-      url: String,
-      method: String,
-      params: Map[String, Object],
-      headers: Map[String, Object],
-      data: String): Boolean = {
-    val httpReq = Http(url)
-      .params(convertObjMap2StrMap(params))
-      .headers(convertObjMap2StrMap(headers))
-    method match {
-      case POST_REGEX() =>
-        val res = httpReq.postData(data).asString
-        res.isSuccess
-      case PUT_REGEX() =>
-        val res = httpReq.put(data).asString
-        res.isSuccess
-      case _ => false
-    }
+    convertObjMap2StrMap(headers) foreach (header => request.addHeader(header._1, header._2))
+    val response = client.execute(request)
+    (response.getStatusLine.getStatusCode, handler.handleResponse(response).trim)
   }
 
   private def convertObjMap2StrMap(map: Map[String, Object]): Map[String, String] = {