Support Questions

Find answers, ask questions, and share your expertise

Apache livy and Ajax

avatar

Good morning every one,

can someone help me with how to send a post request by ajax to the apache livy server? I tried my best but I don't see how to do that. I have a textarea in which user can put his spark code. I want to send that code to the apache livy by ajax and get the result. I don't if my question is clear. Thank you.

1 ACCEPTED SOLUTION

avatar

@Melchicédec NDUWAYO

You could use the following java script client package or similar:

https://www.npmjs.com/package/livy-client

Or you could code your own using javascript jquery or similar.

Overall steps you should consider:

1. Create a livy session to be able to submit code

2. Reference the session id when running the code

Also keep the livy api link handy when working with livy 🙂

https://livy.incubator.apache.org/docs/latest/rest-api.html

HTH

*** If you found this answer addressed your question, please take a moment to login and click the "accept" link on the answer.

View solution in original post

4 REPLIES 4

avatar

@Melchicédec NDUWAYO

You could use the following java script client package or similar:

https://www.npmjs.com/package/livy-client

Or you could code your own using javascript jquery or similar.

Overall steps you should consider:

1. Create a livy session to be able to submit code

2. Reference the session id when running the code

Also keep the livy api link handy when working with livy 🙂

https://livy.incubator.apache.org/docs/latest/rest-api.html

HTH

*** If you found this answer addressed your question, please take a moment to login and click the "accept" link on the answer.

avatar

@Melchicédec NDUWAYO If the above answer has helped please login and mark the answer as "Accepted"

avatar

@Felix Albani I don't see exactly how to create that livy session with javascript or jquery. Can you help me please? Is there any documentation about that? Using the livy client package will not be easy for me also because I must use nodejs to get the package and me I created my webapp using java ee with maven. I am weak in javascript programming. Please, help me.

Thank you.

This is how, normally I send posts to the server using ajax:

$.ajax({
                type: 'POST',
                url: 'TraitementsServletPartialAgre',
                data: {drag: drag},
                success: function (resultat) {
                    var myTrees = resultat.split("|");
                    for (var myTree in myTrees) {
                        var myTree = JSON.parse(myTrees[myTree]);
                        new Treant(myTree);
                    }
                }
            });

And this is what I tried with apache livy:

$.ajax({
            type: 'POST',
            dataType:'json',
            url: 'http://localhost:8998/',
            data: {kind: 'spark',
                   code: CodeMirrorString},
            success: function (resultat) {
                document.getElementById(response).innerHTML = resultat;
            }
        });

avatar

Thank you very much for your answer. I will see that deeply. It seems that it can help me.

Thank you again.