Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Birectional communication of libdnf5 actions plugin with running processes - "json" mode #1642

Conversation

jrohel
Copy link
Contributor

@jrohel jrohel commented Aug 21, 2024

Closes: #1538

Introduces a "mode" option in the hook handler definition.
Option "mode" defines communication model between actions plugin and process.
Introduces 2 modes of communication: "plain" and "json".

"mode=plain" - Original and default communication model.

Parameters are passed to the process only by arguments when it starts. Arguments may contain variables that are substituted before the process is started. A process can modify libdnf5 settings (main configuration, repository configuration, variables) and plugin actions variables by writing to standard
output.

Output line format:

  • tmp.<actions_plugin_variable_name>=<value> - sets the value of action plugins variable <actions_plugin_variable_name>
    - tmp.<actions_plugin_variable_name> - removes the action plugins variable if it exists
  • conf.<option_name>=<value> - sets the value of option <option_name> in the base configuration
  • conf.<repoid_pattern>.<option_name>=<value> - sets the value of option <option_name> in the matching repositories
  • var.<variable_name>=<value> - sets value of the variable <variable_name>

"mode=json" - Newly introduced communication model.

Parameters can be passed to the process before it starts using arguments just like in "plain" mode. This mode adds bidirectional communication between the actions plugin and the process. This is request/response communication.
The process sends requests and the actions plugin sends responses. The process writes requests to the standard output and reads responses from the standard input.

Processes send requests and the actions plugin responds:

  • Request format:
    {"op":"<operation>", "domain":"<domain>", "args":{<op_domain_spec_args>}}

"domain" is ignored in the case of the "log" operation.

  • Response format:
    {"op": "reply", "requested_op":"<op_from_request>", "domain": "<domain_from_request>", "status": "OK", "return":{<data>}}

    {"op": "reply", "requested_op":"<op_from_request>", "domain": "<domain_from_request>", "status": "ERROR", "message":"<error message>"}

"return" is not included in the response to a request for a "log"
operation.

If the JSON request is unparsable - a syntax error or incomplete message, or the response cannot be written, the action plugin closes both communication pipes. The process must terminate if the communication pipes are closed.

@jrohel jrohel force-pushed the feature/libdnf_actions_plugins_json branch from 4925421 to e7c3856 Compare August 22, 2024 07:00
…tion

If the key contains a dot sign, it is a repository option.
Improved detection -> ignoring dots after equals sign.

On the other hand, value_patter is supported only for repository options.

Parsed pattern: <repoid_pattern>.<option_name>[=<value_pattern>]

Bump version to 1.1.1
Option "mode" defines communication model between actions plugin and process.
Introduces 2 modes of communication: "plain" and "json".

"mode=plain" - Original and default communication model.
Parameters are passed to the process only by arguments when it starts.
Arguments may contain variables that are substituted before the process is
started. A process can modify libdnf5 settings (main configuration, repository
configuration, variables) and plugin actions variables by writing to standard
output.
Output line format:
- tmp.<actions_plugin_variable_name>=<value> - sets the value of action plugins
    variable <actions_plugin_variable_name>
- tmp.<actions_plugin_variable_name> - removes the action plugins variable if
    it exists
- conf.<option_name>=<value> - sets the value of option <option_name> in
    the base configuration
- conf.<repoid_pattern>.<option_name>=<value> -  sets the value of option
    <option_name> in the matching repositories
- var.<variable_name>=<value> - sets value of the variable <variable_name>

"mode=json" - Newly introduced communication model.
Parameters can be passed to the process before it starts using arguments just
like in "plain" mode. This mode adds bidirectional communication between
the actions plugin and the process. This is request/response communication.
The process sends requests and the actions plugin sends responses. The process
writes requests to the standard output and reads responses from the standard
input. The communication will be implemented later and will use JSON format.
This is a preliminary commit.
libdnf5-plugins/actions/actions.cpp Outdated Show resolved Hide resolved
libdnf5-plugins/actions/actions.cpp Outdated Show resolved Hide resolved
libdnf5-plugins/actions/actions.cpp Outdated Show resolved Hide resolved
@kontura
Copy link
Contributor

kontura commented Sep 18, 2024

I believe a docs update is needed and I assume it will be done in a follow up PR.

Processes send requests and the actions plugin responds.

- Request format:
{"op":"<operation>", "domain":"<domain>", "args":{<op_domain_spec_args>}}

"domain" is ignored in the case of the "log" operation.

- Response format:
{"op": "reply", "requested_op":"<op_from_request>", "domain":
"<domain_from_request>", "status": "OK", "return":{<data>}}

{"op": "reply", "requested_op":"<op_from_request>", "domain":
"<domain_from_request>", "status": "ERROR", "message":"<error message>"}

"return" is not included in the response to a request for a "log"
operation.

If the JSON request is unparsable - a syntax error or incomplete message,
or the response cannot be written, the action plugin closes both communication
pipes. The process must terminate if the communication pipes are closed.
If an error occurs while processing a request from a process,
the location of the hook definition is added to the log message.
e.g. `Syntax error from hook in file "{}" on line {}:`
For example, the "get" operation for "trans_packages" is only allowed
for the "pre_transaction" and "post_transaction" hooks.
To ensure the release of resources after an exception.
@jrohel jrohel force-pushed the feature/libdnf_actions_plugins_json branch from 12ee2b5 to a0b976f Compare September 20, 2024 06:32
@kontura
Copy link
Contributor

kontura commented Sep 20, 2024

The failing tests are not related.
Thank you.

@kontura kontura added this pull request to the merge queue Sep 20, 2024
Merged via the queue into rpm-software-management:main with commit 877f855 Sep 20, 2024
16 of 20 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Bidirectional communication of libdnf5 actions plugin with running processes
2 participants