Skip to content
Draft
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
47 changes: 47 additions & 0 deletions examples/re_upload_files/upload_fail.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
{
"project_id": "032giRgQ1EGK0UCx9zKXwF",
"task_id": "032giS16ofqdXqh6sgTR9P",
"task_directory": "C:\\AnsysDev\\rep-evaluator\\test_run\\upload_fail_test\\test_upload_fail\\eval_aapqttqyh0qxrsg-upload_fail_test-test_upload_fail\\work_dir\\tasks\\032giRgQ1EGK0UCx9zKXwF\\task_032giS16ofqdXqh6sgTR9P",
"files": [
{
"access_mode": "transfer",
"collect": true,
"collect_interval": null,
"created_by": "8f9758f7-8167-46f9-b099-7c5acc152fe2",
"creation_time": "2026-03-12T15:01:32.919202+00:00",
"evaluation_path": "ps0_out.txt",
"expiry_time": null,
"format": null,
"hash": null,
"id": "032giSTY6wKeDuSfcTJ8dW",
"modification_time": "2026-03-12T15:01:32.919202+00:00",
"modified_by": "8f9758f7-8167-46f9-b099-7c5acc152fe2",
"monitor": true,
"name": "ps0_out",
"reference_id": "032giRvTNjwtBjumAGX0op",
"size": null,
"storage_id": "032giSTY6wKeDuSfcTJ8dW_ps0_out",
"type": "text/plain"
},
{
"access_mode": "transfer",
"collect": true,
"collect_interval": null,
"created_by": "8f9758f7-8167-46f9-b099-7c5acc152fe2",
"creation_time": "2026-03-12T15:01:32.919203+00:00",
"evaluation_path": "console_output.txt",
"expiry_time": null,
"format": null,
"hash": null,
"id": "032giSTY7a290fDOn2qepA",
"modification_time": "2026-03-12T15:01:32.919203+00:00",
"modified_by": "8f9758f7-8167-46f9-b099-7c5acc152fe2",
"monitor": true,
"name": "console_output",
"reference_id": "032giRwC13uwPuwqG05O0z",
"size": null,
"storage_id": "032giSTY7a290fDOn2qepA_console_output",
"type": "text/plain"
}
]
}
96 changes: 96 additions & 0 deletions examples/re_upload_files/upload_files.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
# Copyright (C) 2022 - 2026 ANSYS, Inc. and/or its affiliates.
# SPDX-License-Identifier: MIT
#
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

"""Example to retry upload of failed Evaluator upload."""

import argparse
import json
import logging
import os

from ansys.hps.client import Client, HPSError
from ansys.hps.client.jms import File, JmsApi, ProjectApi, Task

log = logging.getLogger(__name__)


def upload_files(client, file_path):
"""Upload files example."""

if not os.path.isabs(file_path):
file_path = os.path.join(os.getcwd(), file_path)
file_path = os.path.abspath(file_path)

with open(file_path, encoding="utf-8") as f:
data = json.load(f)

files = [File(**d) for d in data["files"]]
for f in files:
f.src = os.path.join(data["task_directory"], f.evaluation_path)

jms_api = JmsApi(client)
project = jms_api.get_project(id=data["project_id"])

log.info(f"Project id: {project.id}")
project_api = ProjectApi(client, project.id)

log.info("=== Example: Uploading output files using ProjectApi.update_files()")
project_api.update_files(files)

task_updates: list[Task] = []
task_updates.append(Task(id=data["task_id"], eval_status="evaluated"))

tasks = project_api.update_tasks(task_updates)

if tasks[0].eval_status == "evaluated":
log.info(f"Files uploaded and Task eval status updated to {tasks[0].eval_status}")
else:
log.info("Files uploaded but Task eval status NOT updated")


if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument("-f", "--file", type=str, default="")
parser.add_argument("-U", "--url", default="https://127.0.0.1:8443/hps")
parser.add_argument("-u", "--username", default="repadmin")
parser.add_argument("-p", "--password", default="repadmin")
parser.add_argument("-t", "--token", default="")
parser.add_argument("-a", "--account", default="onprem_account")
args = parser.parse_args()

logger = logging.getLogger()
logging.basicConfig(format="%(message)s", level=logging.DEBUG)

try:
log.info("Connect to HPC Platform Services")

if args.token:
client = Client(url=args.url, access_token=args.token)
client.session.headers.update({"accountid": args.account})
else:
client = Client(url=args.url, username=args.username, password=args.password)
log.info(f"HPS URL: {client.url}")

upload_files(client=client, file_path=args.file)

except HPSError as e:
log.error(str(e))
Loading