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

Fix/validation timeout #127

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ repos:
- id: no-commit-to-branch
args: [--branch, develop, --branch, master, --pattern, release/.*]
- repo: https://github.com/psf/black
rev: 20.8b1
rev: 22.3.0
hooks:
- id: black
35 changes: 27 additions & 8 deletions scripts/validate.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
import json
import math

import boto3
import botocore
from cdislogging import get_logger

from urllib.parse import urlparse

from indexclient.client import IndexClient
from cdislogging import get_logger

# from scripts import file_utils

from scripts import utils
from scripts.errors import UserError
Expand All @@ -19,6 +23,15 @@ def resume_logger(filename=None):
logger = get_logger("Validation", filename)


def log_file_progress(manifest_idx, current_file, total_files):
progress = (current_file / total_files) * 100
progress = math.floor(progress / 10) * 10 # Round down to nearest 10
if progress % 10 == 0:
logger.info(
f"Manifest #: {manifest_idx} - Processing {current_file}/{total_files} files ({progress}% complete)"
)


def run(global_config):
"""
Given manifests run validation process to check if all the objects exist and are indexed correctly
Expand Down Expand Up @@ -70,7 +83,7 @@ def run(global_config):
"number of output manifests and number of manifest_files are not the same"
)

if not _pass_preliminary_check(FORCE_CREATE_MANIFEST, manifest_files):
if not _pass_preliminary_check(manifest_files, FORCE_CREATE_MANIFEST):
raise UserError("The input does not pass the preliminary check")

logger.info("scan all copied objects")
Expand Down Expand Up @@ -115,7 +128,7 @@ def run(global_config):
manifest_file = manifest_file.strip()
files = utils.get_fileinfo_list_from_s3_manifest(manifest_file)
fail_list = []
for fi in files:
for i, fi in enumerate(files):
del fi["url"]
fi["aws_url"], fi["gs_url"], fi["indexd_url"] = None, None, None

Expand All @@ -127,6 +140,7 @@ def run(global_config):
logger.error("There is no indexd record for {}".format(fi["id"]))

# validate aws
# TO NOTE: doing extra checks here because of logic of open prod accounts for buckets
aws_bucket = utils.get_aws_bucket_name(fi, PROJECT_ACL)
object_path = "{}/{}/{}".format(aws_bucket, fi["id"], fi["file_name"])
object_path_2 = "{}/{}/{}".format(
Expand Down Expand Up @@ -181,6 +195,7 @@ def run(global_config):
fi["id"], fi["gs_url"], fi["indexd_url"]
)
)
log_file_progress(idx, i, len(files))

if total_gs_index_failures + total_gs_copy_failures == 0:
logger.info(
Expand Down Expand Up @@ -291,22 +306,26 @@ def run(global_config):
return pass_validation


def _pass_preliminary_check(FORCE_CREATE_MANIFEST, manifest_files):
def _pass_preliminary_check(manifest_files: str, FORCE_CREATE_MANIFEST=False):
"""
Check if manifests are in the manifest bucket

'FORCE_CREATE_MANIFEST': True, False command arg parameter
'manifest_files': 's3://input/active_manifest.tsv, s3://input/legacy_manifest.tsv'
Args:
manifest_files(str):
Expression to match (for example: >5, ==3, ==this_guid)
Returns:
None
"""

session = boto3.session.Session()
s3 = session.resource("s3")

for url in manifest_files:
try:
logger.info(f"{manifest_files}, {url}")
parsed = urlparse(url)
bucket_name = parsed.netloc
key = parsed.path.strip("/")
logger.info(f"Bucket name: {bucket_name}")
s3.meta.client.head_object(Bucket=bucket_name, Key=key)
except botocore.exceptions.ClientError as e:
error_code = int(e.response["Error"]["Code"])
Expand Down