java api 在 apache drill 中添加存储插件

java api to add storage plugin in apache drill

我想使用 java 代码添加一个新的存储插件。目前我正在创建一个 json 文件并将其上传到 drill web ui。但它失败了。这是我的代码

def creatplugin() {
   val httpclient = new DefaultHttpClient()
    val httpPost = new HttpPost("http://ip:port/storage/hdfs1.json")
    val uploadFilePart = new FileBody(new File("D:/plugin.json"))
    val reqEntity = new MultipartEntity()
    reqEntity.addPart("hdfs1.json", uploadFilePart)
    httpPost.setEntity(reqEntity)
    httpPost.setHeader("Content-type", "application/json")
    val response = httpclient.execute(httpPost)
    println(response.getStatusLine().getStatusCode())
  }

在这种情况下,响应代码为 400,请求错误。

任何建议,出了什么问题?有没有其他方法可以使用 java 代码而不是 rest api 动态添加插件?

谢谢

我认为它可能是多部分条目。我只是 post json 数据作为 post 消息正文的一部分。这是一个 works.Use StringEntity 代替的 curl 示例。

curl -X POST -H "Authorization: Basic bWFwcjpyb290NG1hcHI=" -H "Content-Type: application/json" -d '{"name":"nfl","config":{ "type":"file","enabled":true,"connection":"maprfs:///","workspaces":{"views":{"location":"/mapr/demo.mapr.com/data/views","writable":true,"defaultInputFormat":null},"json":{"location":" =66=].mapr.com/data/nfl/json","writable":false,"defaultInputFormat":"json"},"csv":{"location":" =66=].mapr.com/data/nfl/csv","writable":false,"defaultInputFormat":"csv"},"tab":{"location":" =66=].mapr.com/data/nfl/txt","writable":false,"defaultInputFormat":"tsv"},"xml":{"location":" =66=].mapr.com/data/nfl/xml","writable":false,"defaultInputFormat":null}},"formats":{"csv":{"type":"text","extensions":["csv"],"delimiter":","},"tsv":{"type":"text","extensions":["tsv","txt"],"delimiter":"\t"},"json":{"type":"json"}}}}' http://maprdemo:8047/storage/nfl.json

正如 Jim 指出的那样,问题是多部分实体。这是工作代码

def creatplugin() {
    val source = scala.io.Source.fromFile("D:/plugin.json").mkString
    val httpclient = new DefaultHttpClient()
    val httpPost = new HttpPost("http://ip:port/storage/hdfs1.json")
    val reqEntity = new StringEntity(source)
    httpPost.setEntity(reqEntity)
    httpPost.setHeader("content-type", "application/json")
    httpPost.setHeader("Accept", "application/json")
    val response = httpclient.execute(httpPost)
    println(response.getStatusLine().getStatusCode())
  }