Communication with an external application¶
The communication with an external application is based on JSON-RPC messages.
Pipeline Manager supports two ways of defining external application:
Communication protocol¶
The application layer protocol specifies two blocks:
size- four first bytes form an unsigned integer and tell the size of the content of the message in bytes.content- the rest of the message holding additional data in JSON-RPC format described in API Specification.
The size and content are stored in big-endian.
External Backend Application¶
This is a core concept of server-app Pipeline Manager mode.
Pipeline Manager implements a TCP server that is listening on a specified port and waiting for the client to connect. Pipeline Manager frontend sends JSON-RPC requests to this server through SocketIO, which redirects messages to connected client for specific actions described in this chapter. External application can also request actions from Pipeline Manager in similar manner.
Frontend / Backend / External application¶
By default, Pipeline Manager will wait for an external application to connect and then request the specification. If the connection is established successfully, Pipeline Manager frontend will check if external application is still connected every 0.5 second. Apart from that, both Pipeline Manager frontend and external application can send requests which pass through Pipeline Manager backend.
sequenceDiagram
Note over Frontend,Backend: Pipeline Manager (SocketIO)
Note over External App: Pipeline Manager Backend Communication
Frontend->>Backend: status_get
Backend->>Frontend: status
Frontend->>+Backend: external_app_connect
Note over Backend,External App: BSD socket
External App->>Backend: connect_socket
Backend->>-Frontend: MessageType.OK
Frontend->>+Backend: specification_get
Backend->>External App: specification_get
External App->>Backend: specification
Backend->>-Frontend: MessageType.OK + specification
loop Every 0.5s
Frontend->>Backend: status_get
Backend->>Frontend: status
end
par External App API
Frontend->>+Backend: request
Backend->>+External App: redirected request
External App->>-Backend: response
Backend->>-Frontend: redirected response
and Frontend API
External App->>+Backend: request
Backend->>+Frontend: redirected request
Frontend->>-Backend: response
Backend->>-External App: redirected response
endAs Pipeline Manager part of communication is done with SocketIO, it is based on events, which are precisely defined for both sides and can trigger different actions.
Frontend listens to:
api – received messages are JSON-RPC requests, they are validated with specification, executed and generated responds are resend,
api-response – received messages are JSON-RPC responses, they are also validated and returned as result of previous request.
Backend implements the following events:
backend-api – receives all JSON-RPC requests, runs methods and responds,
external-api – redirects messages to external application through BSD socket.
On the other hand, communication between backend and external application is done through BSD socket. To manage this, both sides run socket listener as separate coroutine task, which waits for messages and responds or redirects them.
External Frontend / Pipeline Manager¶
If the Pipeline Manager is wrapped with another frontend (see Frontend Features for details), the communication can be established with POST requests.
sequenceDiagram
Note over External Frontend,Frontend: postMessage
par Frontend API
External Frontend->>Frontend: request
Frontend->>External Frontend: response
and Backend/External API
External Frontend->>+Frontend: request
Note over Frontend,Backend & External App: Pipeline Manager (SocketIO)
Frontend->>+Backend & External App: redirected request
Backend & External App->>-Frontend: response
Frontend->>-External Frontend: redirected response
endRequest structure¶
Following communication structure diagram below, we have:
blue lines describing Backend API request from frontend,
red lines describing External App API request from frontend,
purple lines describing Frontend API request from external application.
C4Deployment
Deployment_Node(cf, "External Frontend", "") {
Container(external-post-message, "postMessage")
}
Deployment_Node(pm, "Pipeline Manager", "") {
Deployment_Node(front, "Frontend", "") {
Container(front-post-message, "postMessage")
Deployment_Node(socketio, "SocketIO", "") {
Container(front-socket, "SocketIO")
Deployment_Node(front-event, "Events", "") {
Container(front-api, "api")
Container(front-response-api, "api-response")
}
}
}
Deployment_Node(back, "Backend", "") {
Deployment_Node(flask, "Python-SocketIO events", "") {
Container(flask-backend-api, "backend-api")
Container(flask-external-api, "external-api")
}
Deployment_Node(flask-task, "Coroutine task", "") {
Container(back-socket, "BSD socket listener")
}
}
}
Deployment_Node(pmbc, "Pipeline Manager Backend Communication", "") {
Deployment_Node(pmbc-socket, "Socket", "") {
Container(pmbc-socket, "BSD socket")
Deployment_Node(pmbc-task, "Coroutine task", "") {
Container(pmbc-listener, "BSD socket listener")
}
}
}
%% frontend to frontend
BiRel(external-post-message, front-post-message, "JSON-RPC requests and frontend responses")
Rel(front-post-message, front-socket, "Redirected requests")
Rel(front-response-api, external-post-message, "Redirected responses")
UpdateRelStyle(external-post-message, front-post-message, $offsetX="-55", $offsetY="-30")
UpdateRelStyle(front-post-message, front-socket, front-post-message, $offsetX="-55", $offsetY="-30")
%% frontend to backend request
Rel(front-socket, flask-backend-api, "JSON-RPC request")
Rel(flask-backend-api, front-response-api, "JSON-RPC response")
UpdateRelStyle(front-socket, flask-backend-api, $lineColor="var(--md-code-hl-keyword-color)", $textColor="var(--md-code-hl-keyword-color)", $offsetY="-15")
UpdateRelStyle(flask-backend-api, front-response-api, $lineColor="var(--md-code-hl-keyword-color)", $textColor="var(--md-code-hl-keyword-color)", $offsetX="-50", $offsetY="55")
%% frontend to external app request
Rel(front-socket, flask-external-api, "JSON-RPC request")
Rel(flask-external-api, pmbc-listener, "Redirected requests and responses")
Rel(pmbc-listener, back-socket, "JSON-RPC response")
Rel(back-socket, front-response-api, "Redirected response")
UpdateRelStyle(front-socket, flask-external-api, $lineColor="var(--md-code-hl-number-color)", $textColor="var(--md-code-hl-number-color)")
UpdateRelStyle(flask-external-api, pmbc-listener, $lineColor="var(--md-code-hl-name-color)", $textColor="var(--md-code-hl-name-color)", $offsetX="-10", $offsetY="-10")
UpdateRelStyle(pmbc-listener, back-socket, $lineColor="var(--md-code-hl-number-color)", $textColor="var(--md-code-hl-number-color)", $offsetX="25", $offsetY="-25")
UpdateRelStyle(back-socket, front-response-api, $lineColor="var(--md-code-hl-number-color)", $textColor="var(--md-code-hl-number-color)", $offsetX="-10", $offsetY="20")
%% external app to frontend request
Rel(pmbc-socket, back-socket, "JSON-RPC request")
Rel(back-socket, front-api, "Redirected request")
Rel(front-api, flask-external-api, "JSON-RPC response")
Rel(pmbc-listener, pmbc-socket, "Received response")
UpdateRelStyle(pmbc-socket, back-socket, $textColor="var(--md-code-hl-function-color)", $lineColor="var(--md-code-hl-function-color)", $offsetX="-10", $offsetY="15")
UpdateRelStyle(back-socket, front-api, $textColor="var(--md-code-hl-function-color)", $lineColor="var(--md-code-hl-function-color)", $offsetX="45")
UpdateRelStyle(front-api, flask-external-api, $textColor="var(--md-code-hl-function-color)", $lineColor="var(--md-code-hl-function-color)", $offsetX="-65", $offsetY="-30")
UpdateRelStyle(pmbc-listener, pmbc-socket, $textColor="var(--md-code-hl-function-color)", $lineColor="var(--md-code-hl-function-color)", $offsetX="5", $offsetY="-30")
UpdateLayoutConfig($c4ShapeInRow="1", $c4BoundaryInRow="3")External Frontend Application¶
If the Pipeline Manager is used as an iframe, a website that wraps it can implement an External Application.
Similartly to External Frontend Communication, data transfer relies on POST requests: both requests and responses use MessageEvent (see Frontend Features for details).
This application type can be enabled dynamically via dedicated register_external_frontend Frontend API request. This is possible for both static-html and server-app modes.
Currently, in the latter case, external backend application will be overridden with the frontend one.
Request structure¶
sequenceDiagram
Note over External Frontend,Pipeline Manager Frontend: postMessage
par Frontend API
External Frontend->>Pipeline Manager Frontend: request
Pipeline Manager Frontend->>External Frontend: response
and External API
Pipeline Manager Frontend->>External Frontend: request
External Frontend->>Pipeline Manager Frontend: response
endResponse messages types - sent by the external application¶
OK¶
Message of type OK (0) is used to indicate a success and optionally includes an answer to a previous request.
Its content may vary depending on the request type.
ERROR¶
Message of type ERROR (1) is used to indicate a failure and optionally includes an answer to a previous request.
Its content may vary depending on the answered request.
PROGRESS¶
Message of optional type PROGRESS (2) is used to inform Pipeline Manager about the status of a running dataflow.
The PROGRESS message type can only be used once a message of type RUN is received and can be sent multiple times before sending a final response message of type either ERROR or OK that indicates the end of the run.
The progress information is conveyed in content using a number ranging 0 - 100 encoded in UTF-8 that signals the percentage of completion of the run.
See RUN for more information.
WARNING¶
Message of type WARNING (3) is used to indicate a success but also alerts of a condition that might cause a problem in the future.
It optionally includes an answer to a previous request.
Its content may vary depending on the answered request.
API Specification¶
Frontend API¶
frontend_status_get¶
Returns status of the frontend
params: Refer to null_or_empty.result(object): Description of frontend status. Cannot contain additional properties.
frontend_specification_get¶
Returns specification used by frontend
params(object): Parameters for specification request. Cannot contain additional properties.result: Refer to specification_object.
dialog_template_add¶
Request to register user dialog box or override existing one.
-
-
One of
: Refer to dialog_box.
: Refer to empty.
dialog_open¶
Request opening dialog box by frontend.
result: Refer to dialog_box_output.
graph_get¶
Returns dataflow used by frontend
params([object, null]): Serialization options. Cannot contain additional properties.readonly(boolean): Specifies whether the returned dataflow should be marked as read only. Default:false.hideHud(boolean): Specifies whether the returned dataflow should have the HUD disabled. Default:false.position(boolean): Specifies whether the current view location should be included. Default:false.hideLayers(boolean): Specifies whether information about hidden layers should be included. Default:false.
result: Refer to dataflow_object.
node_get¶
Procedure to read node state
-
All of
: Refer to node_object.
properties_get¶
Procedure to alter values of a node
params(object): Cannot contain unevaluated properties.All of
: Refer to node_object.
properties([array, null]): Properties which values are going to be read specified by either a name of id. If undefined then all properties are returned.
properties_change¶
Procedure to alter properties of a node
params: Refer to properties_diff.result: Refer to null_or_empty.
interfaces_change¶
Procedure to alter interfaces of a node
params: Refer to interfaces_diff.result: Refer to null_or_empty.
name_change¶
Procedure to alter the name of the node.
params: Refer to name_diff.result: Refer to null_or_empty.
position_change¶
Procedure to alter position of a node
params: Refer to position_diff.result: Refer to null_or_empty.
nodes_change¶
Procedure to add and delete nodes
params: Refer to nodes_diff.result: Refer to null_or_empty.
connections_change¶
Procedure to add and delete connections
params: Refer to connections_diff.result: Refer to null_or_empty.
graph_change¶
Procedure to add and delete nodes
params(object): Cannot contain additional properties.dataflow: Refer to dataflow_or_url.loadingScreen: Refer to loadingScreen.
result: Refer to null_or_empty.
progress_change¶
Notification with progress of job ran by external application
metadata_change¶
Updates the editor’s metadata
params: Refer to metadata.
viewport_center¶
Center the editor
params: Refer to null_or_empty.
terminal_add¶
Create new terminal instance
result: Refer to null_or_empty.
terminal_remove¶
Create new terminal instance
result: Refer to null_or_empty.
terminal_write¶
Writes a message line to a terminal instance. Allows to send both text and hterm’s control sequences. For more details on available control sequences check hterm Control Sequences.
Warning
Since data is sent in JSON format, the hexadecimal values need to be escaped with \u, not \x, e.g. \u001b[38:2:238:178:17mexample.
result: Refer to null_or_empty.
terminal_clear¶
Clears a terminal with a given name
result: Refer to null_or_empty.
terminal_hide¶
Hides a terminal panel
params: Refer to null_or_empty.result: Refer to null_or_empty.
terminal_show¶
result: Refer to null_or_empty.
terminal_view¶
Configures the layout of the terminal panel
result: Refer to null_or_empty.
terminal_get_instances¶
Configures the layout of the terminal panel
params: Refer to null_or_empty.
notification_send¶
Sends a notification to the frontend. It will display the message both in the notifications and in the default terminal
params(object): Parameters for notification.type: Type of the notification. Must be one of:["error", "warning", "info"].title(string, required): Title of the notification, appearing both in the terminal and notification.details(string, required): Details of the notification, displayed only in the terminal.timestamp(string): Notification timestamp, if not provided, timestamp will be automatically generated (pass non-null falsy value to disable).
result: Refer to null_or_empty.
specification_change¶
Procedure to update specification
-
specification: Refer to specification_or_url.urloverrides: Refer to urloverrides.loadingScreen: Refer to loadingScreen.tryMinify: Refer to tryMinify.
result: Refer to null_or_empty.
specification_graph_change¶
Procedure to update specification and dataflow
params(object): Cannot contain additional properties.specification: Refer to specification_or_url.dataflow: Refer to dataflow_or_url.urloverrides: Refer to urloverrides.loadingScreen: Refer to loadingScreen.tryMinify: Refer to tryMinify.
result: Refer to null_or_empty.
specification_preprocess¶
Handles preprocessor specification directives
-
specification: Refer to specification.unmarkNewNodes(boolean): Decides whether to remove built-in style of new nodes from specification.urloverrides: Refer to urloverrides.tryMinify: Refer to tryMinify.
-
Any of
: Refer to specification_object.
: Refer to null_or_empty.
specification_expand¶
-
specification: Refer to specification.
result: Refer to specification_object.
nodes_highlight¶
Procedure to highlight specified nodes in the editor
params: Refer to highlight_diff.result: Refer to null_or_empty.
register_external_frontend¶
Register external frontend in the Pipeline Manager frontend, available only through ‘postMessage’ interface
params: Refer to null_or_empty.result: Refer to null_or_empty.
return_from_subgraph¶
Returns from subgraph if currently in one
params: Refer to null_or_empty.result(object): Specifies whether the editor was in subgraph and returned. Cannot contain additional properties.
notifications_get_verbosity¶
Obtains current notifications verbosity level or all possible values
notifications_set_verbosity¶
Sets notifications verbosity level
connections_get_style¶
Obtains current connections style, or a list of all possible values
connections_set_style¶
Sets connections style
background_get_grid_size¶
Obtains current background grid size
params: Refer to null_or_empty.
background_set_grid_size¶
Sets background grid size
autolayout_apply¶
Apply autolayout algorithm
params: Refer to null_or_empty.result: Refer to null_or_empty.
interfaces_swap¶
Swap interfaces
params: Refer to null_or_empty.result: Refer to null_or_empty.
interfaces_hide_unconnected¶
Hides unconnected interfaces
params: Refer to null_or_empty.result: Refer to null_or_empty.
interfaces_show_hidden¶
Shows previously hidden interfaces
params: Refer to null_or_empty.result: Refer to null_or_empty.
editor_clear¶
Clears editor
params: Refer to null_or_empty.result: Refer to null_or_empty.
layers_get_list¶
Obtains list of available layers
params: Refer to null_or_empty.
layer_get_hidden¶
Obtains layer state
layer_set_hidden¶
Sets layer state
panel_toggle¶
Toggle navbar panels
fullscreen_toggle¶
Toggle editor fullscreen mode
params: Refer to null_or_empty.result: Refer to null_or_empty.
search_get_query¶
Obtains the current search query
params: Refer to null_or_empty.
search_set_query¶
Sets the current search query
result: Refer to null_or_empty.
graph_add¶
Adds a new empty graph to the editor
params([object, null]): Parameters for request. Cannot contain additional properties.result(object): Information about the created graph. Cannot contain additional properties.
graph_set_name¶
Renames a graph
params(object): Parameters for request. Cannot contain additional properties.result: Refer to null_or_empty.
graph_export_image¶
Renders the currently displayed graph to an image
params(object): Parameters for request. Cannot contain additional properties.result(object): Rendered image. Cannot contain additional properties.
layout_get¶
Returns the layout of a graph.
params([object, null]): Parameters for request. Cannot contain additional properties.result: Refer to graph_layout.
layout_set¶
Applies a layout to a graph.
params: Refer to graph_layout.result(object): Result of applying the layout. Cannot contain additional properties.
Backend API¶
status_get¶
Returns status of connection with external application
params: Refer to null_or_empty.result(object): Description of backend status. Cannot contain additional properties.
external_app_connect¶
Request to wait till connection with external application is established
params: Refer to null_or_empty.result: Refer to empty.
connected_frontends_get¶
Request the number of connected fronteds
params: Refer to null_or_empty.
External App API¶
specification_get¶
Request specification used by external application
params: Refer to null_or_empty.result: Refer to external_endpoint_return_type.
app_capabilities_get¶
Request external application capabilities
params: Refer to null_or_empty.result: Refer to navbar_items.
dialog_boxes_get¶
Request external application dialog boxes
params: Refer to null_or_empty.result: Refer to dialog_boxes.
dataflow_import¶
Request to convert dataflow in external app to Pipeline Manager format and import it
params(object): Parameters for request. Cannot contain additional properties.external_application_dataflow(string, required): Dataflow in external application format. If loaded file cannot be represented as text, it will be sent as base64 string. To make sure received data are in readable formatconvert_message_to_stringfrompipeline_manager_backend_communication.utilscan be used. Optionally, for conversion to bytesconvert_message_to_bytesfunction is available.base64(boolean, required): Specifies whetherexternal_application_dataflowis in byte64 format.
result: Refer to external_endpoint_return_type.
dataflow_validate¶
Request external application to validate dataflow
params: Refer to dataflow_object.result: Refer to external_endpoint_return_type.
dataflow_run¶
Request external application to run dataflow
params: Refer to dataflow_object.result: Refer to external_endpoint_return_type.
dataflow_stop¶
Request external application to run dataflow
params(object): Parameters for stopping dataflow. Cannot contain additional properties.result: Refer to external_endpoint_return_type.
dataflow_export¶
Request external application to export dataflow
params: Refer to dataflow_object.result(object): Common type returned by external app. Cannot contain additional properties.type(number, required): MessageType specifying success or error.content([object, string]): Exported dataflow, which is then saved by the frontend user. Should be either a json object, or a base64 encoded string. If any error occurred then it should contain a proper message.filename(string): Suggested filename used to save the file.
frontend_on_connect¶
Request sent when Pipeline Manager frontend connects to backend and notifyWhenChanged option is enabled in the metadata section of specification.
params: Refer to null_or_empty.result: Refer to null_or_empty.
properties_on_change¶
Request sent when properties of any node change and notifyWhenChanged option is enabled in the metadata section of specification.
params: Refer to properties_diff.result: Refer to null_or_empty.
interfaces_on_change¶
Request sent when interface of any node changes and notifyWhenChanged option is enabled in the metadata section of specification.
params: Refer to interfaces_diff.result: Refer to null_or_empty.
name_on_change¶
Request sent when node name was changed and notifyWhenChanged option is enabled in the metadata section of specification.
params: Refer to name_diff.result: Refer to null_or_empty.
position_on_change¶
Request sent when position of any node changes and notifyWhenChanged option is enabled in the metadata section of specification.
params: Refer to position_diff.result: Refer to null_or_empty.
nodes_on_change¶
Request sent when node was added or deleted and notifyWhenChanged option is enabled in the metadata section of specification.
params: Refer to nodes_diff.result: Refer to null_or_empty.
connections_on_change¶
Request sent when connection was added or deleted and notifyWhenChanged option is enabled in the metadata section of specification.
params: Refer to connections_diff.result: Refer to null_or_empty.
graph_on_change¶
Request sent when whole dataflow changed, e.g. when dataflow is loaded, and notifyWhenChanged option is enabled in the metadata section of specification.
params: Refer to dataflow_object.result: Refer to null_or_empty.
specification_on_change¶
Request sent when whole specification changed, e.g. when node type is modified, and notifyWhenChanged option is enabled in the metadata section of specification.
params: Refer to specification_object.result: Refer to null_or_empty.
metadata_on_change¶
Request sent when metadata was changed, and notifyWhenChanged option is enabled in the metadata section of specification.
params: Refer to metadata.result: Refer to null_or_empty.
viewport_on_center¶
Request sent when editor was centered and notifyWhenChanged option is enabled in the metadata section of specification.
params: Refer to null_or_empty.result: Refer to null_or_empty.
dialog_on_submit¶
Request sent by the frontend when custom user dialog is closed
params: Refer to dialog_box_output.result: Refer to null_or_empty.
terminal_read¶
Request sent by the frontend when terminal received an input
result: Refer to null_or_empty.
nodes_on_highlight¶
Request sent when node was either selected or unselected and notifyWhenChanged option is enabled in the metadata section of specification.
params: Refer to highlight_diff.result: Refer to null_or_empty.
button_click¶
Request send when button node property was pressed
result: Refer to null_or_empty.
Common Types¶
empty¶
null_or_empty¶
unnested_dialog_box_template¶
dialog_box_template¶
: A template that defines dialog box inputs.
All of
: Refer to unnested_dialog_box_template.
-
template(object): A generic dialog box template used with dynamic and nested type. Can contain additional properties.Additional properties: Refer to unnested_dialog_box_template.
dialog_box¶
object: Schema that defines dialog box template.
template(object): A template of the dialog box. Can contain additional properties.Additional properties: Refer to dialog_box_template.
dialog_boxes¶
object: Schema that defines dialog boxes template. Can contain additional properties.
Additional properties: Refer to dialog_box.
dialog_box_output¶
node_object¶
urloverrides¶
loadingScreen¶
tryMinify¶
dataflow_or_url¶
dataflow_object¶
specification¶
specification_or_url¶
specification_object¶
object: Definition containing
specificationobject. Cannot contain additional properties.specification: Refer to specification.
properties_diff¶
object: Schema that represents differences in properties of the node. Cannot contain unevaluated properties.
All of
: Refer to node_object.
properties(array, required): Properties to change specified by either a name or id.
interfaces_diff¶
object: Schema that represents differences in interfaces of the node. Cannot contain unevaluated properties.
All of
: Refer to node_object.
interfaces(array, required): Interfaces to change specified by either a name or id.-
One of
-
name_diff¶
object: Schema that represent differences in title change. Cannot contain unevaluated properties.
All of
: Refer to node_object.
position_diff¶
object: Schema that represent differences in position of the node. Cannot contain unevaluated properties.
All of
: Refer to node_object.
position(object, required): Position to change specified by either a name or id.
nodes_diff¶
object: Schema that represents nodes’ differences in a graph.
connections_diff¶
highlight_diff¶
metadata¶
external_endpoint_return_type¶
object: Common type returned by external app. Cannot contain additional properties.
type(number, required): MessageType specifying success, error or progress.content([object, string]): Additional information, either message or dataflow.
navbar_items¶
array: List of buttons displayed in the application navbar. Default:
[].Items (object): Description of a single button. Cannot contain additional properties.
Any of
stopName(string): Name displayed in the tooltip when the corresponding procedure is running and is stoppable. If not specified simply Stop is added as a prefix to the name.iconName(string, required): Name of the icon displayed in the navbar. Name should correspond to a file in the asset directory or to an icon infrontend/src/icons.procedureName(string): Name of the procedure used when button is pressed. The currently displayed graph is used as an argument.allowToRunInParallelWith(array): List of procedures which can be run when thisnavbarItemis still running. Default:[].requireResponse(boolean): Flag determining whether response from external application should be awaited when running the procedure. Default:true.openUrl(string): URL opened in a new tab when the button starts its procedure, e.g. a page following its progress. Opened on the click itself, so that browsers do not block it as a popup.
graph_layout¶
object: Layout of a graph. Cannot contain additional properties.
graph_id(string): ID of the graph the layout belongs to, defaults to the currently displayed graph.layout(object, required): Mapping from node IDs to their layout. Can contain additional properties.
Custom procedures¶
Navbar¶
External application can define new remote procedures, which will be called by custom Navbar button.
To use it, procedure’s name has to start with custom_ prefix, e.g. custom_simulate_design.
Such remote procedures can be called from the frontend using custom Navbar buttons defined in the metadata’s navbarItems field, e.g.:
{
"name": "Simulate design",
"stopName": "Stop simulation",
"iconName": "Run",
"procedureName": "custom_simulate_design"
}
Custom procedure has the same parameters and return type as dataflow_run method.
Context menus¶
An external application can also define custom remote procedures to be called in the context menu of node.
There are three scopes for such an action: all nodes, subgraph nodes and a given node type.
They are specified by including a Context menu item in, respectively,
customMenuActions or subgraphCustomMenuActions fields of metadata or in the contextMenuActions
field of a given node.
Context menu procedures have only one parameter: node_id, which is the id of the clicked node.
The expected return type is dataflow_export for procedures with
the custom_download prefix in their name, and dataflow_run for all other procedures.
Custom dialog box¶
Custom dialog box definition¶
An external application can also define custom dialog boxes for various use cases. When connection with Pipeline Manager server is established it sends dialog_boxes_get request to get user credentials with all custom dialog boxes used by the application. Example dictionary defining simple form:
{
"optimizationTask": {
"title": "Optimization task",
"confirmText": "Ok",
"template": {
"taskName": {
"name": "task",
"type": "text",
"default": "Foo"
},
"numberOfIterations": {
"name": "iterations",
"type": "int",
"default": 10
},
"earlyStopping": {
"name": "early stopping",
"type": "bool",
"default": false
},
"algorithmsSelect": {
"name": "algorithms",
"type": "select",
"items": {
"CG": "cg",
"BFGS": "bfgs",
"Newton-CG": "newton"
},
"default": "newton"
},
"portDynamic": {
"name": "dynamo",
"type": "dynamic",
"template": {
"intPort": {"name": "port", "type": "int"}
}
},
"attrNested": {
"name": "Additional attributes",
"type": "nested",
"template": {
"attrName": {"name": "name", "type": "text"},
"attrId": {"name": "id", "type": "int"}
}
}
}
}
}
Every entry in the dictionary defines an object with the name later used to open a dialog box, in this case it is the dialog box with name optimizationTask.
Each dialog definition consists of:
title- a name of the dialog box’s windowconfirmText- a title of the dialog box’s confirm buttontemplate- a definition for every input in the dialog box.
The user dialog box template allows for defining input’s name and its type.
Object name represents internal name of the input in which it will be returned, see Read data from custom dialog box.
Nested name property represents a name of the input it will be shown in a dialog box’s form and type represents type of the input, supported types:
text- a standard text inputnumber- a numerical inputint- an integer inputbool- a checkbox with two states true or falseselect- a dropdown selection inputnested- a nested formdynamic- a dynamic form
default properties in the template allows for setting an initial value in user data form.
The resulting specification gives us the dialog box that looks like that:

In case of an error with the provided template, an error message will be sent through requestTerminalRead on dialogErrors terminal, it can be handy for debugging purposes.
Custom dialog input types description¶
text- Represents a standard input that accepts text data.number- Represents a numerical input that supports float numbers and allows for settings maximum and minimum value through optionalmaxandminparameters.int- Represents a numerical input that supports integer based data and allows for settings maximum and minimum value through optionalmaxandminparameters.bool- Represents an input that accepts only two statestrueandfalseand is displayed as a checkbox in the dialog box.select- Represents an input as a dropdown selection list with options defined initemsoption. Defined as a simple dictionary in which the key represents a name of the entry, visible by user, and item’s value is an internal value used by the application.nested- Represents a nested form input, which allows defining form inside other form, usingtemplateproperty which accepts the same generic template format like normal custom dialog’s form.defaultparameter allows setting default values for each form in the nested form.dynamic- Represents a dynamic form, which allows defining virtually infinite number of forms defined intemplateproperty, which accepts standard generic template format for custom dialog’s form. The number of forms is defined with additional integer input in the form. For dynamic form,defaultparameter have two functions:when an integer value higher than 0 is set as default value, it is used to define initial amount of dynamic inputs.
when the default value is an array, it creates dynamic inputs based on values defined in the array. It allows for setting default value for each element in form.
Example usage of a default value in the dynamic input, based on a dialog box template presented below:
{
"optimizationTask": {
"title": "Power simulation",
"confirmText": "OK",
"template": {
"parameters": {
"name": "Parameters",
"type": "dynamic",
"default": [
{
"paramName": "Voltage",
"paramVal": "1800mV"
},
{
"paramName": "Current",
"paramVal": "500mA"
}
],
"template": {
"paramName": {
"name": "Name",
"type": "text"
},
"paramVal": {
"name": "Value",
"type": "text"
}
}
}
}
}
}
This template will create the dialog box with two dynamic inputs with default values:

It is also possible to add, overwrite or remove the dialog box during application execution, using dialog_template_add requests. Example input data used with request:
{
"name": "optimizationTask",
"box": {
"title": "Task form",
"confirmText": "Send",
"template": {
"taskName": {
"name": "task",
"type": "text",
"default": "Foo"
}
}
}
}
name- a name of dialog box we wish to add or modifybox- a template used to define custom dialog box
In this case it will create a dialog box with a single text input.
If optimizationTask is already registered, its template will be overridden with a new one.
When optimizationTask is registered but the provided template or a box parameter is empty, optimizationTask will be removed.
As a response dialog_template_add returns arrays with showing added, removed or overridden dialog boxes:
{
"added": [ "optimizationTask" ],
"removed": [],
"overridden": []
}
Open custom dialog box¶
To open this dialog box, external application sends dialog_open request with a payload:
{
"name": "optimizationTask"
}
In which name parameter is a name of the dialog box to open.
Read data from custom dialog box¶
When confirm button, OK button in this case, is pressed, Pipeline Manager sends dialog_on_submit request with data read from the dialog box in a form of simple json-like format:
{
"taskName": "Foo"
}
In which taskName corresponds to input_name defined in template section of the dialog box.
Example usage of the custom dialog box is defined in a script tester_client.
You can also test the custom dialog box using Custom dialog box demo which uses Pipeline Manager embedded into HTML page.
Implementing a Python-based client for Pipeline Manager¶
The communication described above is necessary to integrate an application with Pipeline Manager. The client needs to be able to read requests coming from Pipeline Manager and send proper responses.
For applications written in Python, you can use the pipeline-manager-backend-communication library. It implements an easy-to-use interface that is able to communicate with Pipeline Manager along with helper structures and enumerations.
The main structures provided by the pipeline-manager-backend-communication library are:
CommunicationBackend- class that implements the functionality for receiving and sending messages.MessageType- enum used to easily distinguish message types.Status- enum that describes the current state of the client.
The following code is an example of how to receive requests and send responses to Pipeline Manager: As Pipeline Manager communication is based on JSON-RPC, application should implement method that can be requested. They are described in Backend API.
# Class containing all implemented methods
class RPCMethods:
def specification_get(self) -> Dict:
# ...
return {'type': MessageType.OK.value, 'content': specification}
# ...
Defined methods have to have appropriate (matching with specification) name, input and output.
# Function name matches with the dataflow_import endpoint from External App API
def dataflow_import(self, external_application_dataflow: str, mime: str, base64: bool) -> Dict:
# Function will receive one parameter, it's name has to be the same
# as the one from API specification `params`.
# Optional, but you can convert the received file to string format
# with `convert_message_to_string`
# from pipeline_manager_backend_communication.utils import (
# convert_message_to_string
# )
data_as_string = convert_message_to_string(
external_application_dataflow,
base64,
mime
)
# ...
# pipeline_manager_dataflow here is the converted input file to the
# Pipeline Manager's graph representation
return {
'type': MessageType.OK.value,
'content': pipeline_manager_dataflow
}
def dataflow_validate(self, dataflow: Dict) -> Dict:
# ...
# Returned object has to match API specification `returns`
return {'type': MessageType.OK.value}
def dataflow_run(self, **kwargs: Dict) -> Dict:
# All params can also be retrieved as one dictionary
print(kwargs['dataflow'])
# ...
return {'type': MessageType.OK.value}
# Custom procedure example
def custom_build(self, dataflow: Dict) -> Dict:
# ...
return {'type': MessageType.OK.value}
Moreover, every uncaught exception will be classified as error.
def dataflow_export(self, dataflow: Dict) -> Dict:
# ...
raise Exception('Something went very, very bad...')
RPC methods can also be asynchronous. It is automatically detected by server and awaited.
async def dataflow_stop(self) -> Dict:
# ...
return {'type': MessageType.OK.value}
Therefore, the following JSON-RPC error message will be returned to frontend application.
{
"id": 1,
"jsonrpc": "2.0",
"error": {
"code": -3,
"message": "Something went very, very bad...",
"data": {}
}
}
TCP client, that connects to Pipeline Manager using host and port parameters provided has to be created.
It has to be initialized with object containing JSON-RPC methods.
host = '127.0.0.1'
port = 5000
# Creating a client instance with host and port specified
client = CommunicationBackend(host, port)
# Registering implemented methods and
# connecting to Pipeline Manager
await client.initialize_client(RPCMethods())
Once the connection is established, the application can start listening for the incoming requests.
await client.start_json_rpc_client()
These methods can be wrapped into the async function and run with asyncio.run function.
Sending JSON-RPC requests to Pipeline Manager¶
Sending requests is defined as coroutine which has to be awaited.
response = await client.request('graph_get')
This method sends graph-get request to frontend application and receive following response:
{
"id": 1,
"jsonrpc": "2.0",
"result": {
"dataflow": {
// ...
}
}
}