I installed apache spark and apache Livy in my system. When I am running a python code, it's giving error
'u'java.lang.IllegalStateException: Session is in state starting''
By default Apchy Livy run on port number 8998. My python code is
import json, pprint, requests, textwrap
host = 'http://localhost:8998'
data = {'kind': 'pyspark'}
headers = {'Content-Type': 'application/json'}
r = requests.post(host + '/sessions', data=json.dumps(data),
headers=headers)
session_url = host + r.headers['location']
statements_url = session_url + '/statements'
data = {
'code': textwrap.dedent("""
import random
NUM_SAMPLES = 100000
def sample(p):
x, y = random.random(), random.random()
return 1 if x*x + y*y < 1 else 0
count = sc.parallelize(xrange(0,
NUM_SAMPLES)).map(sample).reduce(lambda a, b: a +b)
print "Pi is roughly %f" % (4.0 * count / NUM_SAMPLES)
""")
}
r = requests.post(statements_url, data=json.dumps(data),
headers=headers)
pprint.pprint(r.json())
{u'id': 12,
u'output': {u'data': {u'text/plain': u'Pi is roughly 3.136000'},
u'execution_count': 12,
u'status': u'ok'},
u'state': u'running'}
How I can resolve this error?
Whenever you create a new spark session in Livy it takes time for it to get into Idle state. As after creating the session you are directly posting up your code to that particular spark session which is still in starting state due to which exception in thrown.
Try doing something like this -:
once you get the url location from headers follow this