Skip to content

Manage Schedules Using REST

Manage Schedules Using REST

You can use the support-scheduler REST API to manage schedules.

To use the scheduling service you need to set up an interval and an interval action. The interval is the time at which the interval action is triggered. The interval action is the operation that occurs.

Note

Make sure to run Edge Xpert Manager with support-scheduler option to access the scheduling service:

edgexpert up support-scheduler

Viewing the Schedules

To see the default interval and interval actions in the scheduler we can also use the REST API.

Viewing the Intervals

To view all the intervals that are set in the Scheduler use the following command:

curl -X 'GET' \
  'http://localhost:59861/api/v2/interval/all?offset=0&limit=20'; \
  -H 'accept: application/json'
Viewing the Interval Actions

To view all the interval actions set in the scheduler use the command:

curl -X 'GET' \
  'http://localhost:59861/api/v2/intervalaction/all?offset=0&limit=20'; \
  -H 'accept: application/json'

Creating a Schedule

To create a schedule we need to do two things:

  • Create an Inteval. This specifies how often the Interval Action is called.
  • Create an Interval Action. This specifies the command that is called when the Interval is reached.
Creating an Interval

To create an interval use the following commmand:

Info

If Edge Xpert is running in secure mode, you will need to replace localhost in the URL with the IP address for the service. See CLI Service Ports for details.

curl -X 'POST' \
  'http://localhost:59861/api/v2/interval' \
  -H 'Content-Type: application/json' \
  -d '[
  {
    "apiVersion": "v2",
    "interval": {
      "end": "20221016T200000",
      "interval": "100m",
      "name": "test-interval",
      "start": "20211016T200000"
    }
  }
]'
  • The name is the name of the interval, in this case it is test-interval.

  • The interval is how often the interval action is called. The format of this field is to be an unsigned integer followed by a unit which may be "ns", "us" (or "µs"), "ms", "s", "m", "h" representing nanoseconds, microseconds, milliseconds, seconds, minutes or hours. Eg, "100ms", "24h"

  • The start is the start time of the interval in ISO 8601 format

  • The end is the end time of the interval in ISO 8601 format

Creating an Interval Actions

To create an interval action use the following command:

Info

If Edge Xpert is running in secure mode, you will need to replace localhost in the URL with the IP address for the service. See CLI Service Ports for details.

curl -X 'POST' \
  'http://localhost:59861/api/v2/intervalaction' \
  -H 'Content-Type: application/json' \
  -d '[
  {
    "apiVersion": "v2",
    "action": {
      "name": "string",
      "intervalName": "string",
      "address": {
        "type": "REST",
        "host": "192.168.0.102",
        "port": 8080,
        "httpMethod": "GET",
        "path": "/api/v2/ping"
      },
      "content": "string",
      "adminState": "LOCKED"
    }
  }
]'
  • name is the name of the interval action
  • intervalName is the name of the interval you want to use

The address section tells it which API method to used

  • The type is REST
  • The host is the host targetted by the action when it activates
  • Port is the port on the targetted localhost
  • httpMethod indicates which Http verb should be used for the REST endpoint
  • Path is the HTTP path at the targetted host for fulfillment of the action.

Content is the actual content to be sent as the body. The content needs to be in string format so we need to use string escaping to ensure the quotes are read correctly. You can use a string escaping tool to automatically get the string in the backslash-escaped format.