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

Make storage backends pluginnable and dynamically loaded through entry points #5501

Merged

Conversation

sphuber
Copy link
Contributor

@sphuber sphuber commented Apr 27, 2022

Fixes #5495
This PR makes storage backends for profiles pluginnable. It achieves it by creating a new entry point group aiida.storage which will allow the registering of implementations of aiida.orm.implementation.storage_backend.StorageBackend. It adds the PsqlDosStorageBackend and SqliteZipStorageBackend under the core.psql_dos and core.sql_zip entry points, respectively, that ship already with aiida-core. Instead of hard-coding the conversion of the storage.backend key from a Profile to these classes, the aiida.manage.configuration.profile.Profile.storage_cls method will now use the new aiida.plugins.factories.StorageFactory to load the class associated with the entry point. This new feature will allow plugins to provide alternative storage backends, as for example aiida-s3 which provides a storage backend using AWS S3 for the file repository as opposed to the local file system.

@sphuber sphuber force-pushed the feature/5495/storage-backend-entry-points branch 5 times, most recently from 2d1ce6e to 1e3e230 Compare May 13, 2022 13:21
Copy link
Member

@ramirezfranciscof ramirezfranciscof left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, looks very good in general! I just have a test request and some discussion regarding the logic of the config migration.

BTW: do we have in the docs or the wiki some section on what are the steps to make a class pluginable in AiiDA?

Comment on lines 370 to 371
def downgrade(self, config: ConfigType) -> None:
for profile in config.get('profiles', {}).values():
backend = profile.get('storage', {}).get('backend', None)
if backend is not None and backend.startswith('core.'):
profile.setdefault('storage', {})['backend'] = backend[5:]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mmm I'm not sure this is the way we want to do the downgrade. I'm thinking of the case that I have a v9-config with storage['backend'] = core.new_backend, and I downgrade to a version with v8-config to check something and come back. The downgrade will take away the core, but when upgrading it will not recognize the new_backend and just leave it as storage['backend'] = new_backend, which is now broken.

The generic recognition you are doing is good in general, but I think here we need to specifically only take out the core from 'psql_dos' and 'sqlite_zip' like in the upgrade.

It would also be nice to have a warning here too if the profile is neither of those two saying something like "downgrading to an older version of config where storage backends were not pluginable, your current storage won't work here" or something like that.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair, I have made the downgrade only explicit for the known storage backends at this point. I have also added sqlite_temp which was missing.

@@ -248,6 +248,29 @@ def SchedulerFactory(entry_point_name: str, load: bool = True) -> Optional[Union
raise_invalid_type_error(entry_point_name, entry_point_group, valid_classes)


def StorageFactory(entry_point_name: str, load: bool = True) -> Optional[Union[EntryPoint, 'StorageBackend']]:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to add some tests for this in the tests.plugins.test_factories.py, right?

(btw I just noticed there are no tests for the GroupFactory either. Not saying to add them in this PR though, hehe, just mentioning)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added the tests for the StorageFactory

@chrisjsewell
Copy link
Member

yep, apart from the comments by @ramirezfranciscof, basically good cheers 👍

sphuber added 3 commits May 16, 2022 12:51
This will allow plugins to dynamically provide custom storage backend
implementations. Each profile already defines the class to be used in
the `storage.backend` key, however, so far the conversion of that string
identifier to the corresponding class was hard coded.

Here we add the `aiida.storage` entry point group that registers the two
storage backend implementations currently provided by `aiida-core`,
namely, `psql_dos` and `sqlite_zip`. The `Profile.storage_cls` property
now treats the `storage.backend` key as an entry point and tries to load
the corresponding class using the `aiida.plugins.StorageFactory`.
Existing profiles should have the key `storage.backend` be prefixed with
`core.` to indicate that those entry points ship with `aiida-core`.
@sphuber sphuber force-pushed the feature/5495/storage-backend-entry-points branch from 1e3e230 to fa87187 Compare May 16, 2022 11:02
@sphuber sphuber requested a review from ramirezfranciscof May 16, 2022 11:34
Copy link
Member

@ramirezfranciscof ramirezfranciscof left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Go forth and let the s3 repo be pluggined

@sphuber sphuber merged commit 25309f7 into aiidateam:main May 16, 2022
@sphuber sphuber deleted the feature/5495/storage-backend-entry-points branch May 16, 2022 12:54
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.

Allow the storage backend implementation to be configurable
3 participants