I am trying to submit a spark job through livy. In the job , I need to post a json data in the args parameter while invoking livy.This is what I have done
String payload = "{\"name\": \"myname\", \"id\": \"101\"}";
String data="{ \"file\":\"hdfs://some.jar\" ,\"className\":\"someclass\",\"args\":["+"\""+payload+"\""+"], \"proxyUser\":\"clsadmin\"}";
String[] command = {"curl", "-v","-g", "-u" ,"id:pwd", "-H", "Content-Type:application/json" , "-H", "X-Requested-By:livy" , url ,"--data", data};
It does not work. Now if I change my payload to this.It works.
String payload = "{\\\"name\\\": \\\"myname\\\", \\\"id\\\": \\\"101\\\"}";
How can I avoid using 3 backslashes in the payload ? Is there a better way to do it. I am using curl to call the livy url.
Process p = process.start();
BufferedReader reader = new BufferedReader(new InputStreamReader(p.getInputStream()));
StringBuilder builder = new StringBuilder();
String line = null;
while ( (line = reader.readLine()) != null)
{
builder.append(line);
builder.append(System.getProperty("line.separator"));
}