How to create connection in storage plugin of Apache Drill Programmatically in c#

痴心易碎 提交于 2019-12-18 09:27:45

问题


I want to add new connections in storage plugins through my code. Would you please tell how to add or configure connections in storage plugin programmatically in c#.

Is it possible to configure storage plugin connection through command prompt? If yes, how?


回答1:


I found out some solution for that:

           var request = (HttpWebRequest)WebRequest.Create(url);
           var postData = "name=" + name + "&config=" + config;
           var data = Encoding.ASCII.GetBytes(postData);
           request.Method = "POST";
           request.ContentType = "application/x-www-form-urlencoded";
           request.ContentLength = data.Length;
           using (var stream = request.GetRequestStream())
           {
               stream.Write(data, 0, data.Length);
           }
           var response = (HttpWebResponse)request.GetResponse();
           var responseString = new StreamReader(response.GetResponseStream()).ReadToEnd();
           if (responseString != null)
           {
               var jsonObject = Newtonsoft.Json.JsonConvert.DeserializeObject<dynamic>(responseString);
               return jsonObject.result == "success";
           }



回答2:


As per the drill's docs, you can add plugin:

  • Using the Drill Web Console
  • Storage Plugin REST API
  • Bootstrapping a Storage Plugin (for distributed environment)

Using WEB UI

As per docs,

Go to: http://localhost:8047/storage (replace localhost bt IP/hostname if drill is running on remote machine)

Add New Storage Plugin (say name sql) & click create.

Put config there:

{
  type: "jdbc",
  enabled: true,
  driver: "com.microsoft.sqlserver.jdbc.SQLServerDriver",
  url:"jdbc:sqlserver://1.2.3.4:1433;databaseName=mydatabase",
  username:"user",
  password:"password"
}

It will return success if your credentials are right.

Check docs for sql-server plugin.

Note: Make sure you added sqljdbc41.4.2.6420.100.jar in <drill-directory>/jars/3rdparty

Using REST API

As per docs,

curl -X POST -H "Content-Type: application/json" -d '{"name":"sql","config": { type: "jdbc", enabled: true, driver: "com.microsoft.sqlserver.jdbc.SQLServerDriver",url:"jdbc:sqlserver://1.2.3.4:1433;databaseName=mydatabase",username:"user", password:"password"}' http://localhost:8047/storage/sql.json

I guess there is no direct way to add plugin via C++ client. You can write code for POST request using C++.



来源:https://stackoverflow.com/questions/35308055/how-to-create-connection-in-storage-plugin-of-apache-drill-programmatically-in-c

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!