我正在管理一个zeppelin服务器,我正在尝试使用REST api调用重新启动zeppelin解释器。我已经开启了身份验证。因此,我试图首先使用login api获取sessionID,然后将其传递给下一个PUT请求以重新启动解释器。
以下是我要遵循的步骤。
获取会话ID:
curl -i --data 'userName=admin&password=admin123' -X POST http://zeppelin-server.com:8055/api/login
响应:
HTTP/1.1 200 OK
Date: Tue, 08 Aug 2017 15:09:14 GMT
Access-Control-Allow-Credentials: true
Access-Control-Allow-Headers: authorization,Content-Type
Access-Control-Allow-Methods: POST, GET, OPTIONS, PUT, HEAD, DELETE
Date: Tuesday, August 8, 2017 11:09:14 AM EDT
Set-Cookie: rememberMe=deleteMe; Path=/; Max-Age=0; Expires=Mon, 07-Aug-2017 15:09:14 GMT
Set-Cookie: JSESSIONID=438b05e7-1a9a-4cbe-aa06-1c3dfv454976; Path=/; HttpOnly
Set-Cookie: JSESSIONID=deleteMe; Path=/; Max-Age=0; Expires=Mon, 07-Aug-2017 15:09:14 GMT
Set-Cookie: JSESSIONID=f404ad12-a21b-4c6c-bcde-d4f8b59c076a; Path=/; HttpOnly
Set-Cookie: rememberMe=deleteMe; Path=/; Max-Age=0; Expires=Mon, 07-Aug-2017 15:09:14 GMT
Content-Type: application/json
Date: Tue, 08 Aug 2017 15:09:14 GMT
Content-Length: 123
Server: Jetty(9.2.15.v20160210)
{"status":"OK","message":"","body":{"principal":"admin","ticket":"f329g1cc-d488-4aef-9b89-6b206ee71496","roles":"[admin]"}}
接下来,我将JSESSIONID传递给PUT请求以重新启动解释器
curl -v -i -b 'JSESSIONID=438b05e7-1a9a-4cbe-aa06-1c3dfv454976; Path=/; HttpOnly' -X PUT http://zeppelin-server.com:8055/api/interpreter/setting/restart/2CGBW7NIF
响应:
HTTP/1.1 302 Found
当我关闭身份验证时,我没有得到json响应状态。
有人能指出我在这里做错了什么。我按照这里的说明。
https://community.hortonworks.com/questions/52840/authentication-with-the-zeppelin-rest-api.html
答案 0 :(得分:2)
嘿,你之所以得到302 Found Code,是因为你刚刚提供了半Cookie。在你的例子中,curl应该是:
curl -v -i -b 'JSESSIONID=f404ad12-a21b-4c6c-bcde-d4f8b59c076a; Path=/; HttpOnly; rememberMe=deleteMe; Path=/; Max-Age=0; Expires=Mon, 07-Aug-2017 15:09:14 GMT' -X PUT http://zeppelin-server.com:8055/api/interpreter/setting/restart/2CGBW7NIF
这对我有用。希望这对你也有帮助!
答案 1 :(得分:1)
我通过使用-c参数(存储cookie)和-b(恢复和发送)解决了这个问题。
请附上我的示例代码:
#Get credentials
curl --data 'userName=user1&password=user1' -c cookies.txt -XPOST http://$IP:8080/api/login
...
#Use credential to get list of notebooks
curl -b cookies.txt -XGET http://<server>:8080/api/notebook
我希望这会对你有所帮助。
问候!