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

[#5228] Quota use django signals instead of irods microservice and AVUs #5461

Closed

Conversation

devincowan
Copy link
Contributor

@devincowan devincowan commented Apr 18, 2024

This PR alters are quota system to remove reliance on the iRods microservices.
More info is available in
https://github.com/hydroshare/hydroshare/blob/5228-remove-irods-quota-avus/quota-info.md

This PR attempts to "capture" all relevant file operations using Django signals.
Each signal triggers an asynchronous call to update_quota_usage

Resolves #5228 in conjunction with #5229
Relies on #5443 in order to get accurate file sizes from irods storage
Resolves #5418 by entirely removing the need for irods microservice in the dataZone
Resolves #5235 because removing the irods microservice will vastly improve performance of filesystem operations
Resolves #5441 because quota will be refreshed before sending emails and we can be confident in correct values
Resolves #5384 because we don't need a microservice anymore
Resolves #5195 because we don't need a microservice anymore
Resolves #5286 because we don't need a microservice anymore

Pull Request Checklist:

  • Positive Test Case Written by Dev
  • Automated Testing
  • Sufficient User and Developer Documentation
  • Passing Jenkins Build
  • Peer Code review and approval

Positive Test Case

  1. Suggest that you open a private window and login as admin, then open the userQuotas model in the django admin panel
  2. Login as non-admin user in the non-private window
  3. With that user, conduct the following operations
  • uploading a file to a resource
  • creating a resource
  • copying a resource
  • versioning a resource
  • transferring ownership of a resource to "user"
  • ingesting a bag from the userZone
  • zipping a file without removing the original
  • unzipping a file
  • creating aggregations
  • moving files into subdirectories
  1. In all cases, verify that the user's quota (viewed in the private browser, admin panel) adjusts in the expected way, either increasing, decreasing, or remaining the same.

@devincowan devincowan mentioned this pull request Apr 18, 2024
5 tasks
@devincowan devincowan changed the title [#5228] send signal on system_metadata instead of post add file [#5228] Quota use django signals instead of irods microservice and AVUs Apr 18, 2024
if not quota_user == user:
continue
aggregate_size += res.size
return aggregate_size


def update_quota_usage(username):
Copy link
Contributor Author

Choose a reason for hiding this comment

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

moved this to hs_core.tasks

operations = [
migrations.AddField(
model_name='baseresource',
name='quota_holder',
Copy link
Contributor Author

Choose a reason for hiding this comment

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

store the quota_holder on the resource model (was previously stored in AVU)

@receiver(post_copy_resource)
@receiver(post_version_resource)
@receiver(post_publish_resource)
def hs_update_quota(sender, **kwargs):
Copy link
Contributor Author

Choose a reason for hiding this comment

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

use signals to asyc update the stored quota sizes



class Command(BaseCommand):
help = "Migrate quota_holder info from irods AVU into Django UserQuota model."
Copy link
Contributor Author

Choose a reason for hiding this comment

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

command to migrate the quota_holder metadata from irods AVU into django resource model

@devincowan
Copy link
Contributor Author

devincowan commented Apr 19, 2024

Looks like I have a test failing
http://ci.hydroshare.org:8080/job/hydroshare-pull-requests/7502/testReport/junit/hs_core.tests.api.native.test_irods_user_zone_federation/TestUserZoneIRODSFederation/test_resource_operations_in_user_zone/

Traceback (most recent call last):
  File "/usr/local/lib/python3.9/unittest/case.py", line 59, in testPartExecutor
    yield
  File "/usr/local/lib/python3.9/unittest/case.py", line 592, in run
    self._callTestMethod(testMethod)
  File "/usr/local/lib/python3.9/unittest/case.py", line 550, in _callTestMethod
    method()
  File "/hydroshare/hs_core/tests/api/native/test_irods_user_zone_federation.py", line 118, in test_resource_operations_in_user_zone
    self.assertEqual(BaseResource.objects.all().count(), 0,
  File "/usr/local/lib/python3.9/unittest/case.py", line 837, in assertEqual
    assertion_func(first, second, msg=msg)
  File "/usr/local/lib/python3.9/unittest/case.py", line 830, in _baseAssertEqual
    raise self.failureException(msg)
AssertionError: 1 != 0 : Number of resources not equal to 0

I'm guessing it has to do with a race condition because the test passes when run locally.
Perhaps something about the post_delete_resource signal...?
https://github.com/hydroshare/hydroshare/blob/5228-remove-irods-quota-avus/hs_core/tasks.py#L1123-L1125

Testing that theory here:
#5463
and here
#5464

@devincowan devincowan linked an issue Apr 22, 2024 that may be closed by this pull request
38 tasks
@devincowan
Copy link
Contributor Author

I believe this django signals work will be replaced by #5469

@devincowan
Copy link
Contributor Author

closing in favor of #5469

@devincowan devincowan closed this May 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment