Rules management

The eKuiper REST api for rules allows you to manage rules, such as create, show, drop, describe, start, stop and restart rules.

create a rule

The API accepts a JSON content and create and start a rule.

  1. POST http://localhost:9081/rules

Request Sample

  1. {
  2. "id": "rule1",
  3. "sql": "SELECT * FROM demo",
  4. "actions": [{
  5. "log": {}
  6. }]
  7. }

show rules

The API is used for displaying all of rules defined in the server with a brief status.

  1. GET http://localhost:9081/rules

Response Sample:

  1. [
  2. {
  3. "id": "rule1",
  4. "status": "Running"
  5. },
  6. {
  7. "id": "rule2",
  8. "status": "Stopped: canceled by error."
  9. }
  10. ]

describe a rule

The API is used for print the detailed definition of rule.

  1. GET http://localhost:9081/rules/{id}

Path parameter id is the id or name of the rule.

Response Sample:

  1. {
  2. "sql": "SELECT * from demo",
  3. "actions": [
  4. {
  5. "log": {}
  6. },
  7. {
  8. "mqtt": {
  9. "server": "tcp://127.0.0.1:1883",
  10. "topic": "demoSink"
  11. }
  12. }
  13. ]
  14. }

update a rule

The API accepts a JSON content and update a rule.

  1. PUT http://localhost:9081/rules/{id}

Path parameter id is the id or name of the old rule.

Request Sample

  1. {
  2. "id": "rule1",
  3. "sql": "SELECT * FROM demo",
  4. "actions": [{
  5. "log": {}
  6. }]
  7. }

drop a rule

The API is used for drop the rule.

  1. DELETE http://localhost:9081/rules/{id}

start a rule

The API is used to start running the rule.

  1. POST http://localhost:9081/rules/{id}/start

stop a rule

The API is used to stop running the rule.

  1. POST http://localhost:9081/rules/{id}/stop

restart a rule

The API is used to restart the rule.

  1. POST http://localhost:9081/rules/{id}/restart

get the status of a rule

The command is used to get the status of the rule. If the rule is running, the metrics will be retrieved realtime. The status can be

  • $metrics
  • stopped: $reason
  1. GET http://localhost:9081/rules/{id}/status

Response Sample:

  1. {
  2. "source_demo_0_records_in_total":5,
  3. "source_demo_0_records_out_total":5,
  4. "source_demo_0_exceptions_total":0,
  5. "source_demo_0_process_latency_ms":0,
  6. "source_demo_0_buffer_length":0,
  7. "source_demo_0_last_invocation":"2020-01-02T11:28:33.054821",
  8. ...
  9. "op_filter_0_records_in_total":5,
  10. "op_filter_0_records_out_total":2,
  11. "op_filter_0_exceptions_total":0,
  12. "op_filter_0_process_latency_ms":0,
  13. "op_filter_0_buffer_length":0,
  14. "op_filter_0_last_invocation":"2020-01-02T11:28:33.054821",
  15. ...
  16. }

get the topology structure of a rule

The command is used to get the status of the rule represented as a json string. In the json string, there are 2 fields:

  • sources: it is a string array of the names of all source nodes. They are the entry of the topology.
  • edges: it is a hash map of all edges categorized by nodes. The keys are the starting point of an edge. And the value is a collection of ending point.
  1. GET http://localhost:9081/rules/{id}/topo

Response Sample:

  1. {
  2. "sources": [
  3. "source_stream"
  4. ],
  5. "edges": {
  6. "op_project": [
  7. "sink_log"
  8. ],
  9. "source_stream": [
  10. "op_project"
  11. ]
  12. }
  13. }