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

Add support for remote barman config-update execution #89

Merged
merged 7 commits into from
Jan 18, 2024

Conversation

barthisrael
Copy link
Contributor

@barthisrael barthisrael commented Jan 9, 2024

So far we had only operations related with Barman servers in the API:

  • RecoveryOperation: to perform a barman recover of a Barman server
  • ConfigSwitchOperation: to perform a barman config-switch to a Barman server

However, we needed to add an operation to the API which is performed at the Barman instance level (global), not to a specific Barman server: the ConfigUpdateOperation.

With that in mind this PR changes the classes below so we will be able to create Barman instance operations:

  • OperationServer: turn server_name argument optional. When it is None, that is considered an instance operation. Thus, the job and output files will be written under the Barman home in that case instead of under a Barman server directory
  • Operation: turn server_name argument optional, so it creates OperationServer accordingly

We also added a couple new endpoints to the API, so we can handle instance operations:

  • /operations/<operation_id>: used to get the status of an instance operation -- similar to what we have for server operations through /servers/<server_name>/operations/<operation_id>;
  • /operations: used to get a list of or instance operations, or to create a new instance operation -- similar to what we have for server operations through /servers/<server_name>/operations.

The BarmanConfigUpdate operation has been created and uses the above API endpoints.

Unit tests changed accordingly, so we check both server and instance operations, including the introduced operation.

References: BAR-126.

So far we had only operations related with Barman servers in the
API:

* `RecoveryOperation`: to perform a `barman recover` of a Barman
  server
* `ConfigSwitchOperation`: to perform a `barman config-switch` to
  a Barman server

However, we intend to add an operation to the API which is performed
at the Barman instance level (global), not to a specific Barman
server: the `ConfigModelOperation`.

With that in mind this initial commit changes the classes below so
we will be able to create Barman instance operations:

* `OperationServer`: turn `server_name` argument optional. When it
  is `None`, that is considered an instance operation. Thus, the
  `job` and `output` files will be written under the Barman home
  in that case instead of under a Barman server directory
* `Operation`: turn `server_name` argument optional, so it creates
  `OperationServer` accrodingly

Unit tests changed accordingly, so we check both server and instance
operations.

Follow-up commits to come, which will implement new endpoints to the
API and the `ConfigModelOperation`.

References: BAR-126.

Signed-off-by: Israel Barth Rubio <israel.barth@enterprisedb.com>
@barthisrael barthisrael self-assigned this Jan 9, 2024
@barthisrael barthisrael marked this pull request as draft January 9, 2024 20:14
This commit fixes the following couple issues reported by `pyright`:

```
pg_backup_api/pg_backup_api/server_operation.py
  pg_backup_api/pg_backup_api/server_operation.py:634:13 - error: Expression of type "list[str | None]" cannot be assigned to return type "List[str]"
    Type "str | None" cannot be assigned to type "str"
      "None" is incompatible with "str" (reportGeneralTypeIssues)
  pg_backup_api/pg_backup_api/server_operation.py:754:16 - error: Expression of type "list[str | None]" cannot be assigned to return type "List[str]"
    "list[str | None]" is incompatible with "List[str]"
      Type parameter "_T@list" is invariant, but "str | None" is not the same as "str"
      Consider switching from "list" to "Sequence" which is covariant (reportGeneralTypeIssues)
```

References: BAR-126.

Signed-off-by: Israel Barth Rubio <israel.barth@enterprisedb.com>
So far we had only endpoints for handling Barman server operations. This
commit is a preparation step before implementing the first instance operation.

As part of the work we added a couple new endpoints to the API:

* `/operations/<operation_id>`: used to get the status of an instance
  operation -- similar to what we have for server operations through
  `/servers/<server_name>/operations/<operation_id>`;
* `/operations`: used to get a list of or instance operations, or to create
  a new instance operation -- similar to what we have for server operations
  through `/servers/<server_name>/operations`.

The handling of `POST` requests to `/operations` is only returning a dummy
message for now, as we still need to implement the first instance operation.

Unit tests were modified accordingly.

References: BAR-126.

Signed-off-by: Israel Barth Rubio <israel.barth@enterprisedb.com>
This commit adds the class `ConfigModelOperation` and the command
`pg-backup-api config-model`.

We still need to define the final implementation of the command
in Barman (`barman config-model`), so we can back here and update
this branch with changes in the code and unit tests.

References: BAR-126.

Signed-off-by: Israel Barth Rubio <israel.barth@enterprisedb.com>
We initially designed a command in Barman called `barman config model`
to create and update models.

However, as part of BAR-128 we ended up implementing `barman config-update`
which is able to handle both server and models.

This commit reflects that change in the name of the command, and also
implements the actual logic for listening on the pg-backup-api endpoint
and properly calling the Barman command.

References: BAR-126.

Signed-off-by: Israel Barth Rubio <israel.barth@enterprisedb.com>
@barthisrael barthisrael changed the title Add support for Barman instance operations Add support for Barman instance operations and implement config update Jan 18, 2024
@barthisrael barthisrael changed the title Add support for Barman instance operations and implement config update Add endpoint for remote barman config-update execution Jan 18, 2024
@barthisrael barthisrael changed the title Add endpoint for remote barman config-update execution Add support for remote barman config-update execution Jan 18, 2024
References: BAR-126.

Signed-off-by: Israel Barth Rubio <israel.barth@enterprisedb.com>
Signed-off-by: Israel Barth Rubio <israel.barth@enterprisedb.com>
@barthisrael barthisrael marked this pull request as ready for review January 18, 2024 11:51
@barthisrael barthisrael requested a review from gcalacoci January 18, 2024 11:51
@barthisrael barthisrael merged commit 510a2d7 into main Jan 18, 2024
14 checks passed
@barthisrael barthisrael deleted the dev/BAR-126-config-model-endpoint branch January 18, 2024 12:19
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.

2 participants