Skip to content

Commit

Permalink
refactor landing_zone_move flow (#1846)
Browse files Browse the repository at this point in the history
  • Loading branch information
mikkonie committed Sep 30, 2024
1 parent 3176882 commit 3a52413
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 119 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ Changed
- **Taskflowbackend**
- Refactor task tests (#2002)
- Unify user name parameter naming in flows (#1653)
- Refactor ``landing_zone_move`` flow (#1846)

Fixed
-----
Expand Down
180 changes: 61 additions & 119 deletions taskflowbackend/flows/landing_zone_move.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,152 +99,71 @@ def build(self, force_fail=False):
)
)

# VALIDATE_ONLY
# If "validate_only" is set, return without moving and set status
if validate_only:
self.add_task(
lz_tasks.SetLandingZoneStatusTask(
name='Set landing zone status to VALIDATING (calculate)',
project=self.project,
inject={
'landing_zone': zone,
'status': ZONE_STATUS_VALIDATING,
'status_info': ZONE_INFO_CALC,
'flow_name': self.flow_name,
},
)
)
if not validate_only:
self.add_task(
irods_tasks.BatchCalculateChecksumTask(
name='Batch calculate missing checksums in iRODS',
irods_tasks.SetInheritanceTask(
name='Set inheritance for landing zone collection '
'{}'.format(zone_path),
irods=self.irods,
inject={
'file_paths': zone_objects_nomd5,
'force': False,
},
)
)
self.add_task(
lz_tasks.SetLandingZoneStatusTask(
name='Set landing zone status to VALIDATING (compare)',
project=self.project,
inject={
'landing_zone': zone,
'status': ZONE_STATUS_VALIDATING,
'status_info': ZONE_INFO_VALIDATE.format(
count=file_count, plural=file_count_msg_plural
),
'flow_name': self.flow_name,
},
)
)
self.add_task(
irods_tasks.BatchCheckFilesTask(
name='Batch check file and MD5 checksum file existence for '
'zone data objects',
irods=self.irods,
inject={
'file_paths': zone_objects_nomd5,
'md5_paths': zone_objects_md5,
'zone_path': zone_path,
},
inject={'path': zone_path, 'inherit': True},
)
)
self.add_task(
irods_tasks.BatchValidateChecksumsTask(
name='Batch validate MD5 checksums of {} data '
'objects'.format(file_count),
irods_tasks.SetAccessTask(
name='Set admin "{}" owner access for zone coll {}'.format(
admin_name, zone_path
),
irods=self.irods,
inject={
'paths': zone_objects_nomd5,
'zone_path': zone_path,
'access_name': 'own',
'path': zone_path,
'user_name': admin_name,
'access_lookup': access_lookup,
'irods_backend': self.irods_backend,
},
)
)
self.add_task(
lz_tasks.SetLandingZoneStatusTask(
name='Set landing zone status to ACTIVE',
project=self.project,
inject={
'landing_zone': zone,
'status': ZONE_STATUS_ACTIVE,
'status_info': 'Successfully validated '
'{} file{}'.format(
file_count,
's' if file_count != 1 else '',
),
'flow_name': self.flow_name,
'extra_data': {'validate_only': int(validate_only)},
},
)
)
return

# Else continue with moving
self.add_task(
irods_tasks.SetInheritanceTask(
name='Set inheritance for landing zone collection {}'.format(
zone_path
),
irods=self.irods,
inject={'path': zone_path, 'inherit': True},
)
)
self.add_task(
irods_tasks.SetAccessTask(
name='Set admin "{}" owner access for zone coll {}'.format(
admin_name, zone_path
),
irods=self.irods,
inject={
'access_name': 'own',
'path': zone_path,
'user_name': admin_name,
'access_lookup': access_lookup,
'irods_backend': self.irods_backend,
},
)
)
self.add_task(
irods_tasks.SetAccessTask(
name='Set user "{}" read access for zone collection {}'.format(
zone.user.username, zone_path
),
irods=self.irods,
inject={
'access_name': 'read',
'path': zone_path,
'user_name': zone.user.username,
'access_lookup': access_lookup,
'irods_backend': self.irods_backend,
},
)
)
# Workaround for sodar#297
# If script user is set, set read access
if self.flow_data.get('script_user'):
self.add_task(
irods_tasks.SetAccessTask(
name='Set script user "{}" read access to landing '
'zone'.format(self.flow_data['script_user']),
name='Set user "{}" read access for zone collection '
'{}'.format(zone.user.username, zone_path),
irods=self.irods,
inject={
'access_name': 'read',
'path': zone_path,
'user_name': self.flow_data['script_user'],
'user_name': zone.user.username,
'access_lookup': access_lookup,
'irods_backend': self.irods_backend,
},
)
)
# Workaround for sodar#297
# If script user is set, set read access
if self.flow_data.get('script_user'):
self.add_task(
irods_tasks.SetAccessTask(
name='Set script user "{}" read access to landing '
'zone'.format(self.flow_data['script_user']),
irods=self.irods,
inject={
'access_name': 'read',
'path': zone_path,
'user_name': self.flow_data['script_user'],
'access_lookup': access_lookup,
'irods_backend': self.irods_backend,
},
)
)

self.add_task(
lz_tasks.SetLandingZoneStatusTask(
name='Set landing zone status to VALIDATING (calculate)',
project=self.project,
inject={
'landing_zone': zone,
'status': ZONE_STATUS_VALIDATING,
'status_info': ZONE_INFO_CALC + ZONE_INFO_READ_ONLY,
'status_info': ZONE_INFO_CALC
+ (ZONE_INFO_READ_ONLY if not validate_only else ''),
'flow_name': self.flow_name,
},
)
Expand All @@ -269,11 +188,12 @@ def build(self, force_fail=False):
'status_info': ZONE_INFO_VALIDATE.format(
count=file_count, plural=file_count_msg_plural
)
+ ZONE_INFO_READ_ONLY,
+ (ZONE_INFO_READ_ONLY if not validate_only else ''),
'flow_name': self.flow_name,
},
)
)

self.add_task(
irods_tasks.BatchCheckFilesTask(
name='Batch check file and MD5 checksum file existence for '
Expand All @@ -295,6 +215,28 @@ def build(self, force_fail=False):
inject={'paths': zone_objects_nomd5, 'zone_path': zone_path},
)
)

# Return at this point if validate_only
if validate_only:
self.add_task(
lz_tasks.SetLandingZoneStatusTask(
name='Set landing zone status to ACTIVE',
project=self.project,
inject={
'landing_zone': zone,
'status': ZONE_STATUS_ACTIVE,
'status_info': 'Successfully validated '
'{} file{}'.format(
file_count,
's' if file_count != 1 else '',
),
'flow_name': self.flow_name,
'extra_data': {'validate_only': int(validate_only)},
},
)
)
return

self.add_task(
lz_tasks.SetLandingZoneStatusTask(
name='Set landing zone status to MOVING',
Expand Down

0 comments on commit 3a52413

Please sign in to comment.