Creating a Workflow

Functions

Creates a Data+ workflow.

Request Syntax

POST /v2/workflows/{graph_name}?x-workflow-create HTTP/1.1
Host: obs.cn-north-4.myhuaweicloud.com 
Authorization: authorization
Content-Type: application/json
Content-Length: length
Date: date

policy json body

Request Parameters

Table 1 Request parameters

Parameter

Mandatory

Type

Description

Constraints

graph_name

Yes

String

Workflow name

The name must be unique, start with a letter or digit, and contain a maximum of 64 characters. Only letters, digits, underscores (_), and hyphens (-) are allowed.

Request Headers

This request uses common headers. For details, see Table 3.

Request Elements

Table 2 Parameters

Parameter

Mandatory

Type

Description

Constraints

description

No

String

Workflow description

The description contains 0 to 256 characters. Only letters, digits, commas (,), periods (.), colons (:), hyphens (-), underscores (_), and spaces are allowed.

states

No

Array of State

Workflow orchestration definition

  • The TYPE field is mandatory, which must be one of the three states, DELAY, OPERATION, or END.
  • A state name is a string of 1 to 80 characters. Only letters, digits, hyphens (-), and underscores (_) are allowed.

inputs

No

Array of Input

Parameters that can be modified in a workflow

-

Table 3 Parameters in the State common domain

Parameter

Mandatory

Type

Description

Constraints

start

No

bool

Indicates the start state. In the figure, there must be only one state whose start value is true.

There is only one state whose start value is true.

type

Yes

string

DELAY, OPERATION, END

Enumerated

payload_filter_in

No

string

Specifies whether to filter input parameters. The default value is $, indicating no filtering for input parameters.

Valid JSONPath format

NOTE:

The END state does not have the payload_filter_in attribute.

payload_filter_out

No

string

Specifies whether to filter the state output. The default value is $, indicating no filtering for state output.

Valid JSONPath format

NOTE:

The END state does not have the payload_filter_out attribute.

state_name

Yes

string

State name definition

The value contains 1 to 20 characters. Only lowercase letters, digits, and hyphens (-) are allowed.

Table 4 Parameters in the OperationState structure

Parameter

Mandatory

Type

Description

Constraints

action_mode

No

String

Specifies in which mode are actions invoked. The default value is SEQUENTIAL.

Only SEQUENTIAL is supported.

actions

Yes

Array of Action

JSON array that defines an action.

Only one action is supported.

next_state

Yes

String

Name of the next state, which is a string and must exist in the graph definition

The value must be a state name in a workflow.

Table 5 Parameters in the DelayState structure

Parameter

Mandatory

Type

Description

Constraints

time_delay

Yes

String

Waiting time, in seconds. The value is an integer.

The value is greater than 0 and up to 86400.

next_state

Yes

String

Name of the next state, which is a string and must exist in the graph definition

The value must be a state name in a workflow template.

Table 6 Parameters in the Action structure

Parameter

Mandatory

Type

Description

Constraints

action_name

Yes

String

Name of an action.

The value must be unique in a state. The action name is a string of 1 to 20 characters containing only digits, letters, hyphens (-), and underscores (_).

action_template_name

Yes

String

Action template name. For details, see Table 8.

-

action_template_category

Yes

String

Action template type. For details, see Table 8.

-

action_template_provider_name

Yes

String

Action template type. For details, see Table 8.

-

function

Yes

String

URN of a user-defined function

You can specify either function or function_template.

function_template

Yes

String

URN of the built-in function template.

You can specify either function or function_template.

invocation_mode

No

String

Invoking mode.

The value must be SYNC.

results

No

Array of ActionResult

Mechanism for retrying after an action fails.

The value is a JSON array that contains the result definition. If the results exist, the value is greater than or equal to 0.

timeout

No

Int

Timeout interval of an action, or the maximum waiting duration. The default value is 30s.

The value is an integer ranging from 0 to 300. 0 indicates that this parameter is not specified.

payload_filter

No

String

Path for filtering results. The default value is $.

Valid JSONPath format.

dynamic_source

No

Map

When a workflow is being created, a function based on the user-defined function template can be created and parameter values can be specified.

The value must be a specified parameter name. Otherwise, the parameter does not take effect.

Table 7 Parameters in the ActionResult structure

Parameter

Mandatory

Type

Description

Constraints

match

Yes

String

A matching error.

MatchAny, States.ActionFailed, States.PermissionError, States.ParameterError, States.NotFound, States.TooManyRequests, States.FunctionStageUnavailable, States.FunctionStageOtherErrors

retry_interval

No

Int

Retry interval, in seconds.

Value range: [0, 86400]

The value is an integer greater than or equal to 0.

max_retry

No

Int

Maximum number of retry times. If this parameter is not specified, the default value 3 is used. If this parameter is set to 0, no retry.

Value range: [0, 10]

The value is an integer greater than or equal to 0.

next_state

No

String

Name of the next state, which is a string and must exist in the graph definition.

The value must be a state name in a workflow template.

is_terminal

Yes

Bool

Specifies whether to interrupt an action in case of an exception. The default value is False.

True: No need to specify the next-state; False: The next-state must be specified.

Table 8 Built-in action template names

Built-in Action Template Name

Description

Category

Data Provider Name

Description

MediaTranscode

Video transcoding

MediaProcess

op_svc_obs

Video processing

MediaRemux

Video packaging

MediaProcess

op_svc_obs

Video processing

MediaMetadata

Video metadata

MediaProcess

op_svc_obs

Video processing

MediaThumbnail

Frame capturing

MediaProcess

op_svc_obs

Video processing

NotificationSMN

SMN message notice

NotificationProcess

op_svc_obs

Message notifications

Table 9 Parameters in the input structure

Parameter

Mandatory

Type

Constraints

Description

parameter_name

Yes

String

The value contains 1 to 20 characters. Only lowercase letters, digits, and hyphens (-) are allowed.

Parameter name. You can define a maximum of 60 parameter names, and each name must be unique.

type

Yes

  • String
  • Integer
  • Float
  • Boolean
  • List
  • Map

-

Type

value_type

No

  • String
  • Integer
  • Float

-

List type parameter value.

Only the atomic type is supported.

template_parameter_name

No

String

The value contains 1 to 20 characters. Only lowercase letters, digits, and hyphens (-) are allowed.

When multiple action templates are in the same workflow, fields are added for internationalization.

paramter_value

No

Parameter values passed based on the type.

Defined constraints.

Parameter value.

description

No

String

The value contains 0 to 256 characters.

Parameter description information.

default

No

String

The default value can be replaced by an external input when a workflow instance is created. If the default value is not specified, the value of this parameter must be entered.

The default value type should be consistent with the defined parameter type. If they are inconsistent, the parser automatically converts their types, leading to unexpected results.

label

No

String

String length: 0 to 64 characters

Label of a parameter. The labels defined here can be displayed by category during stack creation.

constraints

No

map

Constraints are as follows: One input parameter can define only one rule for each condition. If any of the conditions is not met, the parameter is deemed as invalid.

  • equal: The value of a parameter must be the specified value.
  • valid_values: valid values of the parameter. It means an array.
  • regex: The parameter must meet a regularity condition. Only a string-type parameter can be matched.
  • invalid_values: invalid value range of a parameter. If a parameter value is in this range, the parameter is deemed as invalid and an error is reported.

Parameter constraint, which is used to define the valid value range of an input parameter.

For example, if the input parameter is not obs, the parameter is deemed as invalid.

"constraints": {
     "equal": "obs"
}

For example, the output parameter value can be TCP or UDP.

"constraints": {
     "valid_values": ["TCP", "UDP" ]
}

For example, if an input parameter does not meet the regularity condition, the parameter is deemed as invalid.

"constraints": {
     "valid_values": ["TCP", "UDP" ]
}

For example, if the input parameter value is 1 or 12, the parameter is regarded as invalid.

"constraints": {
     "invalid_values": ["1", "12" ]
}

invisible

No

Boolean

If this parameter is set to true, the return value is ******.

Check whether the command output is displayed.

Response Syntax

HTTP/1.1 status_code 
Date: date 
Content-Length: length 
X-Request-ID: obs request id

json body

Response Headers

The response to the request uses common headers. For details, see Table 1.

Response Elements

Parameter

Type

Description

graph_name

String

Workflow name

graph_urn

String

Workflow URN

created_at

String

Creation time of a workflow

Error Responses

No special error responses are returned. For details about error responses, see Table 2.

Sample Request

POST /v2/workflows/{graph_name}?x-workflow-create HTTP/1.1
Host: obs.cn-north-4.myhuaweicloud.com 
Date: Thu, 27 Aug 2020 12:38:10 GMT
Authorization: OBS H4IPJX0TQTHTHEBQQCEC:sc2PM13Wlfcoc/YZLK0MwsI2Zpo=
Content-Type: application/json
Content-Length: 100

{
    "description": "a demo of graph",
    "inputs": [{
        "parameter_name": "param1",
        "default": "TCP",
        "parameter_value": "TCP",
        "template_parameter_name": "param",
        "type": "string",
        "label": "action1",
        "constraints": {
            "valid_values": ["TCP", "UDP"]
        },
        "invisible": true,
        "description": "description param1"
    }],
    "states": [{
        "start": true,
        "state_name": "operation",
        "payload_filter_in": "$",
        "payload_filter_out": "$",
        "type": "OPERATION",
        "action_mode": "SEQUENTIAL",
        "actions": [{
            "action_name": "action1",
            "action_template_name": "<Action Template name>",
            "action_template_category": "<Action Template category>",
            "action_template_provider_name": "<Action Template provider name>",
            "function_template": "urn:fss:cn-north-5:3f1e6caf808246c68457e660e4bfeb2f:function:default:test",
            "invocation_mode": "SYNC",
            "timeout": 0,
            "payload_filter": "$",
            "dynamic_source": {
                "param1": {
                    "get_input": "$.inputs.param1"
                },
                "param2": {
                    "get_input": "$.inputs.param2"
                }
            }
        }],
        "next_state": "end"
    }, {
        "state_name": "end",
        "type": "END"
    }]
}

Sample Response

HTTP/1.1 201 Created
Server: OBS
Date: Thu, 27 Aug 2020 12:38:10 GMT
Content-Length: 100
X-Request-ID: 000001742FE8FB3CCA20173B00807C43

{
    "graph_name": "test-graph",
    "graph_urn": "urn:obs:cn-north-5:3f1e6caf808246c68457e660e4bfeb2f:graph:test-graph",
    "created_at": "2020-04-23T12:32:11.131Z"
}