--- sidebar_position: 5 --- # REST API Job Lifecycle Cookbook ## Overview This guide supplements the [REST API v2 reference](rest-api-v2.md) with practical recipes for managing the complete job lifecycle: submission, monitoring, stopping, cancelling, savepoint, and recovery. It also covers authentication, performance considerations, and common errors. --- ## 1. Prerequisites Enable the REST API in `seatunnel.yaml`: ```yaml seatunnel: engine: http: enable-http: true port: 8080 enable-dynamic-port: true port-range: 100 ``` All examples below use `http://:8080`. Replace with your actual master host and port. --- ## 2. Job Submission ### 2.1 Submit a job from a config file (JSON body) ```bash curl -X POST http://:8080/submit-job \ -H "Content-Type: application/json" \ -d @job.json ``` Minimal `job.json` structure: ```json { "env": { "job.name": "my-cdc-job", "job.mode": "STREAMING", "checkpoint.interval": 30000 }, "source": [ { "plugin_name": "MySQL-CDC", "plugin_output": "mysql_cdc_result", "base-url": "jdbc:mysql://localhost:3306/mydb", "username": "cdc_user", "password": "password", "database-names": ["mydb"], "table-names": ["mydb.orders"], "startup.mode": "initial", "server-id": "5400-5404" } ], "transform": [], "sink": [ { "plugin_name": "Console", "plugin_input": ["mysql_cdc_result"] } ] } ``` ### 2.2 Submit a job with multiple transforms (JSON format) ```json { "env": { "job.name": "etl-with-transforms", "job.mode": "BATCH" }, "source": [ { "plugin_name": "FakeSource", "plugin_output": "fake", "row.num": 100, "schema": { "fields": { "id": "int", "name": "string", "amount": "double" } } } ], "transform": [ { "plugin_name": "FieldMapper", "plugin_input": ["fake"], "plugin_output": "after_field_map", "field_mapper": { "id": "user_id", "name": "user_name" } }, { "plugin_name": "Filter", "plugin_input": ["after_field_map"], "plugin_output": "filtered", "fields": ["user_id", "user_name", "amount"] } ], "sink": [ { "plugin_name": "Console", "plugin_input": ["filtered"] } ] } ``` ### 2.3 Submission response A successful submission returns: ```json { "jobId": "733584788375093248", "jobName": "my-cdc-job" } ``` Save the `jobId` for all subsequent lifecycle operations. --- ## 3. Job Status Query ### 3.1 Query a single running job ```bash curl http://:8080/job-info/ ``` Response fields: | Field | Description | |---|---| | `jobId` | Unique job identifier | | `jobName` | Human-readable job name | | `jobStatus` | `RUNNING`, `FINISHED`, `FAILED`, `CANCELED` | | `envOptions` | Env configuration applied | | `createTime` | Job creation timestamp | | `jobDag` | DAG structure | | `metrics` | Source/sink throughput counters | ### 3.2 Query all running jobs ```bash curl "http://:8080/running-jobs?page=1&rows=10" ``` ### 3.3 Query finished jobs ```bash curl "http://:8080/finished-jobs/FINISHED?page=1&rows=10" ``` Use the `state` path parameter to filter finished jobs, for example `FINISHED`, `FAILED`, `CANCELED`, or `SAVEPOINT_DONE`. ### 3.4 Query job metrics only ```bash curl http://:8080/job-info/ ``` Key metric fields: | Metric | Meaning | |---|---| | `SourceReceivedCount` | Total rows read from source | | `SinkWriteCount` | Total rows written to sink | | `SourceReceivedQPS` | Current read throughput (rows/sec) | | `SinkWriteQPS` | Current write throughput (rows/sec) | Counters are reported by the current attempt of each pipeline. When a pipeline is restored after a failover (or retried after a failure), the new attempt starts counting from zero instead of accumulating the values left behind by the failed attempt, for both batch and streaming jobs. A worker report that was in flight during the restore can still carry a stale value for at most a millisecond-scale window. --- ## 4. Querying Job Logs ```bash # List the log files matching this jobId on all nodes (returns node/logName/logLink entries); # fetch the file content via the returned logLink curl "http://:8080/logs/" ``` For large deployments where log files are on individual workers, use the worker's REST port directly, or configure centralized logging (see [Logging](logging.md)). --- ## 5. Stop, Cancel, and Savepoint Semantics ### Semantics comparison | Operation | What happens | State preserved | Can resume | |---|---|---|---| | `stop` (graceful) | Waits for in-flight data to flush | Checkpoint at stop point | Yes, via `--restore` | | `stop-with-savepoint` | Graceful stop + explicit savepoint written | Full savepoint | Yes, via `--restore` | | `cancel` (force kill) | Immediate termination | No new state written | Only from last checkpoint | ### 5.1 Graceful stop (no savepoint) ```bash curl -X POST "http://:8080/stop-job" \ -H "Content-Type: application/json" \ -d '{"jobId": "733584788375093248", "isStopWithSavePoint": false}' ``` ### 5.2 Stop with savepoint ```bash curl -X POST "http://:8080/stop-job" \ -H "Content-Type: application/json" \ -d '{"jobId": "733584788375093248", "isStopWithSavePoint": true}' ``` The savepoint is written to the configured checkpoint storage (see the checkpoint storage settings of your cluster). The `/job-info/:jobId` response has no `savepointPath` field; to resume later, resubmit with `restoreMode=SAVEPOINT` (and `restoreSourceJobId`), which picks up the latest savepoint of that job. For the full request example, see section 6.2. ### 5.3 Cancel (force) ```bash curl -X POST "http://:8080/stop-job" \ -H "Content-Type: application/json" \ -d '{"jobId": "733584788375093248", "isStopWithSavePoint": false, "force": true}' ``` --- ## 6. Job Recovery and Restart ### 6.1 Restart from the latest checkpoint Submit the job again with `restoreMode=CHECKPOINT`, and use `restoreSourceJobId` to specify the job ID to restore from. ```bash curl -X POST "http://:8080/submit-job?restoreMode=CHECKPOINT&restoreSourceJobId=733584788375093248" \ -H "Content-Type: application/json" \ -d '{ "env": { "job.name": "my-cdc-job-restored", "job.mode": "STREAMING", "checkpoint.interval": 30000, "checkpoint.retain-after-job-cancelled": true }, "source": [ ... ], "sink": [ ... ] }' ``` The same `restoreMode` and `restoreSourceJobId` query parameters work with the [upload endpoint](rest-api-v2.md#submit-a-job-by-upload-config-file) when submitting a config file instead of a JSON body -- both endpoints share the same restore handling: ```bash curl --location 'http://:8080/submit-job/upload?restoreMode=CHECKPOINT&restoreSourceJobId=733584788375093248' \ --form 'config_file=@"/temp/my-cdc-job.conf"' ``` If the checkpoint data for `restoreSourceJobId` is missing, already cleaned up, or incompatible, the submission fails fast. If you want a canceled job to remain resumable from checkpoint, retain the checkpoint data generated during job execution in one of the following ways before the job is canceled. 1. Configure the cluster default in `seatunnel.yaml`. This is a global setting and applies to all jobs: ```yaml seatunnel: engine: checkpoint: retain-after-job-cancelled: true ``` 2. Configure a job-level `env` override in the REST request body. This applies only to the current job: ```json { "env": { "job.name": "my-cdc-job-restored", "job.mode": "STREAMING", "checkpoint.interval": 30000, "checkpoint.retain-after-job-cancelled": true }, "source": [ ... ], "sink": [ ... ] } ``` The default value is `false`. If neither the cluster config nor the job `env` enables this option, canceled jobs still clean up checkpoint data by default. When both are present, the job-level `env` setting takes precedence. ### 6.2 Restart from the latest savepoint ```bash curl -X POST "http://:8080/submit-job?restoreMode=SAVEPOINT&restoreSourceJobId=733584788375093248" \ -H "Content-Type: application/json" \ -d '{ "env": { "job.name": "my-cdc-job-restored", "job.mode": "STREAMING", "checkpoint.interval": 30000 }, "source": [ ... ], "sink": [ ... ] }' ``` ### 6.3 Restoring from an explicit savepoint path The REST API does not support pointing at a specific savepoint path. There are no env options such as `restore.mode` or `savepoint.path`; restore is driven only by the `restoreMode` and `restoreSourceJobId` request parameters, and `restoreMode=SAVEPOINT` always picks up the **latest** savepoint of the referenced job (per pipeline, the one with the highest checkpoint id). There is no supported way to select an older savepoint through the REST API. --- ## 7. Authentication and Authorization When basic authentication is enabled (see [Security](security.md)), all REST API calls must include the configured username and password. ### Basic auth example ```bash curl -u admin:password "http://:8080/running-jobs?page=1&rows=10" ``` --- ## 8. REST API Performance Considerations ### `job-info` slowness with many finished jobs When `finished-job-state` IMap grows large (thousands of entries), the `/running-jobs` and `/finished-jobs/:state` endpoints may become slow because they scan all entries. **Mitigations:** 1. Reduce `history-job-expire-minutes` to shorten the retention window 2. Avoid polling finished-jobs endpoints at high frequency; cache the result in your monitoring layer 3. For dashboards, query specific `jobId` directly instead of listing all jobs ### Concurrent submission rate The REST API processes submissions synchronously in the Hazelcast executor pool. For bulk submission scenarios (importing hundreds of jobs), throttle submissions to 10–20 per second to avoid overwhelming the master node. ### Dynamic port allocation If `enable-dynamic-port: true`, different master nodes may use different ports. Use the REST API overview endpoint to inspect the active cluster state from a reachable master: ```bash # Inspect the cluster state from a reachable master curl http://:8080/overview | \ python3 -c "import sys,json; print(json.load(sys.stdin))" ``` --- ## 9. Common Errors and Troubleshooting | Error | Cause | Fix | |---|---|---| | `HTTP 404` on any endpoint | REST API not enabled or wrong port | Set `enable-http: true` and check port | | `Connection refused` | Master not started or firewall blocking port | Verify master process is running; check firewall | | `found: false` (or a status-less 200) in `job-info` | The id is unknown, or the job has expired from finished-job history | Query `/finished-jobs/:state` with the expected final state | | Submit returns `400 Bad Request` | Malformed JSON or missing required fields | Validate JSON; check `plugin_name` spelling | | `The job id ... has already been submitted and is not starting with a savepoint` | Resubmitting a job with a fixed `job.id` while history for that ID is still retained (cancelling does not clear it) | Submit a fresh job with a new `job.id`, or restore intentionally via the documented savepoint/restore flow | | `Unauthorized 401` | Basic authentication is enabled but no credentials were provided | Include `-u user:pass` | | Restoration fails with missing or incompatible checkpoint data | Checkpoint data for `restoreSourceJobId` was cleaned up or is incompatible | Verify checkpoint storage contents and `history-job-expire-minutes` retention; the REST API cannot point to a custom savepoint path | --- ## See Also - [REST API v2 Reference](rest-api-v2.md) - [REST API v1 Reference](rest-api-v1.md) - [Security Configuration](security.md) - [Checkpoint Storage](checkpoint-storage.md) - [CDC Pipeline Architecture](../../architecture/cdc-pipeline-architecture.md)