|
| 1 | +import argparse |
| 2 | +import rohub |
| 3 | +import time |
| 4 | + |
| 5 | + |
| 6 | +def parse_args(): |
| 7 | + parser = argparse.ArgumentParser( |
| 8 | + description="Process ro-crate-metadata.json artifacts and display simulation results." |
| 9 | + ) |
| 10 | + parser.add_argument( |
| 11 | + "--provenance_folderpath", |
| 12 | + type=str, |
| 13 | + required=True, |
| 14 | + help="Path to the folder containing provenance data", |
| 15 | + ) |
| 16 | + parser.add_argument( |
| 17 | + "--username", |
| 18 | + type=str, |
| 19 | + required=True, |
| 20 | + help="Username for RoHub", |
| 21 | + ) |
| 22 | + parser.add_argument( |
| 23 | + "--password", |
| 24 | + type=str, |
| 25 | + required=True, |
| 26 | + help="Password for RoHub", |
| 27 | + ) |
| 28 | + return parser.parse_args() |
| 29 | + |
| 30 | + |
| 31 | +def run(args): |
| 32 | + rohub.settings.SLEEP_TIME = 10 |
| 33 | + |
| 34 | + USE_DEVELOPMENT_VERSION = True |
| 35 | + if USE_DEVELOPMENT_VERSION: |
| 36 | + rohub.settings.API_URL = "https://rohub2020-rohub.apps.paas-dev.psnc.pl/api/" |
| 37 | + rohub.settings.KEYCLOAK_CLIENT_ID = "rohub2020-cli" |
| 38 | + rohub.settings.KEYCLOAK_CLIENT_SECRET = "714617a7-87bc-4a88-8682-5f9c2f60337d" |
| 39 | + rohub.settings.KEYCLOAK_URL = "https://keycloak-dev.apps.paas-dev.psnc.pl/auth/realms/rohub/protocol/openid-connect/token" |
| 40 | + rohub.settings.SPARQL_ENDPOINT = ( |
| 41 | + "https://rohub2020-api-virtuoso-route-rohub.apps.paas-dev.psnc.pl/sparql/" |
| 42 | + ) |
| 43 | + |
| 44 | + rohub.login(args.username, args.password) |
| 45 | + |
| 46 | + my_ros = rohub.list_my_ros() |
| 47 | + |
| 48 | + try: |
| 49 | + for _, row in my_ros.iterrows(): |
| 50 | + rohub.ros_delete(row["identifier"]) |
| 51 | + except Exception as error: |
| 52 | + print(f"Error on Deleteing RoHub: {error}") |
| 53 | + |
| 54 | + identifier = "" |
| 55 | + uuid = "" |
| 56 | + try: |
| 57 | + upload_result = rohub.ros_upload(path_to_zip=args.provenance_folderpath) |
| 58 | + identifier = upload_result["identifier"] |
| 59 | + uuid = upload_result["results"].rstrip("/").split("/")[-1] |
| 60 | + except Exception as error: |
| 61 | + print(f"Error on Upload RoHub: {error}") |
| 62 | + |
| 63 | + timeout_seconds = 5 * 60 |
| 64 | + poll_interval = 10 |
| 65 | + start_time = time.time() |
| 66 | + |
| 67 | + while True: |
| 68 | + success_result = rohub.is_job_success(job_id=identifier) |
| 69 | + status = success_result.get("status", "UNKNOWN") |
| 70 | + |
| 71 | + if status == "SUCCESS": |
| 72 | + print(f"Upload successful: {success_result}") |
| 73 | + break |
| 74 | + elif time.time() - start_time > timeout_seconds: |
| 75 | + print(f"Upload did not succeed within 5 minutes. Last status: {status}") |
| 76 | + break |
| 77 | + else: |
| 78 | + print(f"Current status: {status}, waiting {poll_interval}s...") |
| 79 | + time.sleep(poll_interval) |
| 80 | + |
| 81 | + ANNOTATION_PREDICATE = "http://w3id.org/nfdi4ing/metadata4ing#investigates" |
| 82 | + ANNOTATION_OBJECT = "https://github.com/BAMresearch/NFDI4IngModelValidationPlatform/tree/main/benchmarks/linear-elastic-plate-with-hole" |
| 83 | + |
| 84 | + if (uuid != ""): |
| 85 | + _RO = rohub.ros_load(uuid) |
| 86 | + annotation_json = [{"property": ANNOTATION_PREDICATE, "value": ANNOTATION_OBJECT}] |
| 87 | + add_annotations_result = _RO.add_annotations( |
| 88 | + body_specification_json=annotation_json |
| 89 | + ) |
| 90 | + print(add_annotations_result) |
| 91 | + |
| 92 | +def main(): |
| 93 | + args = parse_args() |
| 94 | + run(args) |
| 95 | + |
| 96 | + |
| 97 | +if __name__ == "__main__": |
| 98 | + main() |
0 commit comments