WebSocket

Linkis provides access to WebSocket, and the frontend can interact with Link’s WebSocket only in real time and does not need to be queried through Restful.

1 Linkis interface specification

Linkis defines a set of its own interface norms when interacting at the back and back end.

If you are interested in interface specifications, please click hereto view interface norms

2 WebSocket Interface Summary

We provide the following interfaces to facilitate rapid user submission of Jobs for implementation.

  • Create WebSocket Connection
  • Submit for Implementation
  • Service active return status, logs, and progress

3 Interface Details

3.1 Establishing a connection

This interface is intended to create a WebSocket connection with Linkis.

  • /api/res_j/entrance/connect

  • Request Method GET

  • Response status code 101

3.2 Submission of implementation

Requested task is to submit user’s assignment to Linkis for execution interface

  • Interface /api/res_j/entrance/execution

  • Submit Method POST

  • Request JSON Example

  1. {
  2. "method":"/api/rest_j/v1/entrance/execute",
  3. "data":{
  4. "params": {
  5. "variable":{
  6. "k1":"v1"
  7. },
  8. "configuration":{
  9. "special":{
  10. "k2":"v2"
  11. },
  12. "runtime":{
  13. "k3":"v3"
  14. },
  15. "startup":{
  16. "k4":"v4"
  17. }
  18. }
  19. },
  20. "executeApplicationName":"spark",
  21. "executionCode":"show tables",
  22. "runType":"sql",
  23. "source":{
  24. "scriptPath": "/home/Linkis/Linkis.sql"
  25. },
  26. "websocketTag":"37fcbd8b762d465a0c870684a0261c6e"
  27. }
  28. }
  • The parameters in the requested body data are described below.
Parameter NameDefinition of parametersTypeRemarks
executeApplicationNameEngine services such as Spark, hive, etc. the user expects to useStringmust not be empty
requestApplicationNameName of system to launch the requestStringis empty
paramsUser-specified parameters for running the service programMapRequired, the value inside is empty
Execution CodeExecution code submitted by userStringmust not be empty
runTypeWhen users perform such services as spark, they can select python, R, SQL, etc.Stringmust not be empty
scriptPathPath to store for user submitted code scriptsStringIf IDE, it cannot be empty with execution code
  • Return Example
  1. {
  2. "method": "/api/rest_j/v1/entrance/execute",
  3. "status": 0,
  4. "message": "The request was executed successfully",
  5. "data": {
  6. "execID": "030418IDEhivebdpdwc010004:10087IDE_johnnwang_21",
  7. "taskID": "123"
  8. }
  9. }
  • The execID is the unique execution ID generated for the task after the user task has been submitted to UJES, the String type that is useful only when the task is running, similar to the PID concept.ExecID is designed (requestApplicationName length) (executeAppName length1) (Instalment 2)${requestApplicationName}${executeApplicationName}${entranceInstanceip+port}${requestApplicationName}${umUser}${index}
  • taskID is the unique ID that represents the user submission of tasks. This ID is generated by database auto-adding, long type

3.3 Task Status, Logs, Progress Proactive Push

Once executed, the server will take the initiative to push information about the status, logs, progress, etc. You can also use WebSocket to ask for status, logs, and progress.

Server has initiated the following content:

  • Logs
  1. {
  2. "method": "/api/rest_j/v1/entrance/${execID}/log",
  3. "status": 0,
  4. "message": "Return log information",
  5. "data": {
  6. "execID": "${execID}",
  7. "log": ["error","warn","info", "all"],
  8. "taskID":28594,
  9. "fromLine": 56
  10. },
  11. "websocketTag":"37fcbd8b762d465a0c870684a0261c6e"
  12. }
  • Status
  1. LOD
  2. "method": "/api/res_j/v1/entrance/${execID}/status",
  3. "status": 0,
  4. "message": "Return status information",
  5. "data": {
  6. "execID": "${execID}",
  7. "taskID":28594,
  8. "status": "Running",
  9. },
  10. "websocketTag": "37fcbd8b762d465a0c860684a0261c6e"
  11. }
  • Progress
  1. {
  2. "method": "/api/rest_j/v1/entrance/${execID}/log",
  3. "status": 0,
  4. "message": "Return progress information",
  5. "data": {
  6. "execID": "${execID}",
  7. "taskID":28594,
  8. "progress": 0.2,
  9. "progressInfo": [
  10. {
  11. "id": "job-1",
  12. "succeedTasks": 2,
  13. "failedTasks": 0,
  14. "runningTasks": 5,
  15. "totalTasks": 10
  16. },
  17. {
  18. "id": "job-2",
  19. "succeedTasks": 5,
  20. "failedTasks": 0,
  21. "runningTasks": 5,
  22. "totalTasks": 10
  23. }
  24. ]
  25. },
  26. "websocketTag":"37fcbd8b762d465a0c870684a0261c6e"
  27. }