1

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?

Cœur
  • 32,421
  • 21
  • 173
  • 232
Naveen D
  • 121
  • 2
  • 15
  • you can simply add it using Drill Web UI? – Dev Feb 10 '16 at 06:52
  • would you please give me some example..? – Naveen D Feb 10 '16 at 07:33
  • check : https://drill.apache.org/docs/plugin-configuration-basics/ Which plugin you want to add? – Dev Feb 10 '16 at 07:46
  • Hi.. I already go through this link.. but not found any code or anything for configuration throught c# code.. I want to connect sql server throught c# code (Not Through Web Console or Drill Web UI). Please help me out.. And Is it possible to configure connections throught command prompt (rather than Web Console or Drill Web UI). – Naveen D Feb 10 '16 at 08:04
  • I want to write this Configuration: { "type": "jdbc", "driver": "com.microsoft.sqlserver.jdbc.SQLServerDriver", "url": "jdbc:sqlserver://DEMO;databaseName=newdemo", "username": "sa", "password": "XXXXXX", "enabled": true } Through Programmatically.(in C#) – Naveen D Feb 10 '16 at 08:20
  • firstly, try to add this plugin from web ui so that you will be sure that it's working (try querying on some table of SQL server) – Dev Feb 10 '16 at 08:30

2 Answers2

1

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++.

Dev
  • 11,996
  • 15
  • 57
  • 138
  • Hi..Thanks for your reply..... Please tell me Is it possible to configure storage plugins through command prompt.?? – Naveen D Feb 10 '16 at 09:51
  • curl -X POST I mentioned in aswer can be fired from command prompt (I am sure about linux machines ) – Dev Feb 10 '16 at 09:53
  • you are not referring **drill shell** by command prompt. Right? – Dev Feb 10 '16 at 09:54
  • yes..i am not referring drill shell by command prompt. But wht ab the window..? And would you please give me example.. how to use curl -X POST in cmd.. – Naveen D Feb 10 '16 at 10:00
  • This may help you: http://serverfault.com/questions/483754/is-there-a-built-in-command-line-tool-under-windows-like-wget-curl – Dev Feb 10 '16 at 10:04
  • From java, I can use jars (e.g. jersey) to make REST call. I believe you can do that from C++ too. I am java developer, so mot much aware about C++. – Dev Feb 10 '16 at 10:06
  • Thanks Dev.. for giving valuable time.. :) – Naveen D Feb 10 '16 at 10:09
  • Would you please tell me when to run curl command in cmd..? [Means after: sqlline.bat -u "jdbc:drill:zk=local" or before running the drill.]..? When i type this command i am getting an error – Naveen D Feb 10 '16 at 13:39
  • you are posting your plugin details to `http://localhost:8047/storage/sql.json `. This url will be active when you start drill. So, you need to start drill (_using command you mentioned_). Then fire CURL command..:) – Dev Feb 10 '16 at 14:32
  • Are you able to connect to SQL server via JDBC using the same url, username,password you mentioned in drill plugin? – Dev Feb 10 '16 at 14:34
  • Yes.. I am able t connect sql server via JDBC.. & I have used same user and pwd.. – Naveen D Feb 11 '16 at 06:11
  • Please tell after typing sqlline.bat -u "jdbc:drill:zk=local" ... What to do for achieving storage plugin through cmd..? – Naveen D Feb 11 '16 at 06:42
  • you need to verify 2 things. 1. Drill is running or not (using `sqlline.bat -u "jdbc:drill:zk=local" ` drill shell with appear. Try `show databases` to verify its running) 2. I am assuming username, password, schema name, etc are right for sql server (you must have verified). Try to add plugin from C++ code or command prompt later. Open drill web ui `localhost:8047` & add plugin (_I mentioned in answer_). Is it returning success? – Dev Feb 11 '16 at 15:24
  • Yes drill is running successfully. and from localhost:8047, i have successfully connected from sqlserver. & it also show the databases, amd i have successfully run the query from sqlserver.The only things i want to know that how (code)can i create new storage plugin from cmd. – Naveen D Feb 12 '16 at 05:54
  • you downloaded tool for running curl command on your windows machine? – Dev Feb 12 '16 at 08:11
  • No.. Which tool I have to download..? Please tell me..? – Naveen D Feb 12 '16 at 10:34
  • I did not use windows much. This should help: http://stackoverflow.com/questions/9507353/how-do-i-install-set-up-and-use-curl-on-a-windows – Dev Feb 13 '16 at 09:44
  • Hi.. Would you please tell me why to use distribute mode and how to provide user name and password while starting the drill(For Security Purposes) – Naveen D Feb 18 '16 at 13:51
  • @NaveenD I suggest you to ask a different question as this is a different problem. Also, you will get views of different users on this concern. – Dev Feb 18 '16 at 15:36
  • I am trying to configure for Oracle DB. But showing: > Error(Not able to create and update storage.) { type: "jdbc", enabled: true, driver: "oracle.jdbc.OracleDriver", url:"jdbc:oracle:thin:system/pass@123@1@192.XXX.XXX.XXX:8047:nvn" } Please tell what i am doing wrong in this..? – Naveen D Feb 23 '16 at 11:00
  • I hope you added `ojdbc7.jar` in 3rdParty. Your jdbc url `url:"jdbc:oracle:thin:system/pass@123@1@192.XXX.XXX.XXX:8047:nvn" ` is incorrect. It should be like `"jdbc:oracle:thin:user/pass@192.168.41.67:1521:nvn"` where user & pass are username, password. – Dev Feb 23 '16 at 11:50
  • Ya I have already added ojdbc7.jar in 3rdParty. And my connection is right. system is my user name , pass@123 is my password. – Naveen D Feb 23 '16 at 12:04
  • & NVN is my workspace for oracle.. and can i used localhost instead of 192.168.41.41.67..? – Naveen D Feb 23 '16 at 12:07
  • I hope `pass@123@1` written above is by mistake..:P Are you able to connect to oracle with above mentioned credentials via JDBC client? – Dev Feb 23 '16 at 12:40
  • sorry password is pass@123 & Yes I am able to connect with this credentials – Naveen D Feb 23 '16 at 12:47
  • :- How to write code for POST request using C++ for storage plugin. Please give some example..? – Naveen D Jul 27 '16 at 07:58
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";
           }
Sanjiv
  • 440
  • 1
  • 7
  • 26