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

Integrate with data transfer worker #436

Merged
merged 65 commits into from
Sep 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
65 commits
Select commit Hold shift + click to select a range
57ed55a
Integrate with data transfer worker
RajaPiseD Aug 2, 2024
294a968
Merge branch 'main' into rajapise/dts-integration
RajaPiseD Aug 2, 2024
4d0e1df
update dependency
RajaPiseD Aug 2, 2024
59d945d
Merge branch 'rajapise/dts-integration' of github.com:ansys/pyhps int…
RajaPiseD Aug 2, 2024
198a877
updated
RajaPiseD Aug 2, 2024
6ac8620
updated file
RajaPiseD Aug 8, 2024
4879315
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Aug 8, 2024
9850c5c
Update ProjectApi.copy_default_execution_script function to use new d…
ojkoenig Aug 17, 2024
d572c73
updated code as per review observations
RajaPiseD Aug 28, 2024
c402603
updated code
RajaPiseD Aug 28, 2024
396dcfc
updated code as per review observations
RajaPiseD Aug 28, 2024
c426845
Merge branch 'main' into rajapise/dts-integration
RajaPiseD Aug 28, 2024
c046296
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Aug 28, 2024
8af823d
update secret
RajaPiseD Sep 2, 2024
3d7353d
updated file
RajaPiseD Sep 2, 2024
c34bc96
updated file
RajaPiseD Sep 2, 2024
7ecc0f3
updated file
RajaPiseD Sep 2, 2024
9b72db6
updated conftest client()
RajaPiseD Sep 2, 2024
9e3d28b
reverted change
RajaPiseD Sep 2, 2024
8215c7d
Update action.yml
RajaPiseD Sep 2, 2024
f19fd65
Update action.yml
RajaPiseD Sep 2, 2024
2aa226d
Update action.yml
RajaPiseD Sep 2, 2024
83fbde1
Update action.yml
RajaPiseD Sep 3, 2024
5773cb8
Merge branch 'main' into rajapise/dts-integration
RajaPiseD Sep 3, 2024
c02e56d
Update action.yml
RajaPiseD Sep 3, 2024
f2dba9e
Update action.yml
RajaPiseD Sep 3, 2024
10e4413
Update ci_cd.yml
RajaPiseD Sep 3, 2024
73439fa
Update action.yml
RajaPiseD Sep 3, 2024
1fa853e
Update action.yml
RajaPiseD Sep 3, 2024
1571554
Update action.yml
RajaPiseD Sep 3, 2024
202000d
Update action.yml
RajaPiseD Sep 3, 2024
af0b87d
Update action.yml
RajaPiseD Sep 3, 2024
6af25a6
Update action.yml
RajaPiseD Sep 3, 2024
70a709e
Update action.yml
RajaPiseD Sep 3, 2024
a23a0a7
Update action.yml
RajaPiseD Sep 3, 2024
f6c8453
Update action.yml
RajaPiseD Sep 3, 2024
ea2f033
Update action.yml
RajaPiseD Sep 3, 2024
20affa6
Update action.yml
RajaPiseD Sep 3, 2024
5076ce2
Update action.yml
RajaPiseD Sep 3, 2024
18248c8
Update action.yml
RajaPiseD Sep 3, 2024
bd3a08b
Update action.yml
RajaPiseD Sep 3, 2024
d0de340
Update action.yml
RajaPiseD Sep 3, 2024
f64bb46
Update action.yml
RajaPiseD Sep 3, 2024
df6ce1d
Update action.yml
RajaPiseD Sep 3, 2024
d69578d
Update action.yml
RajaPiseD Sep 3, 2024
6aa4067
updated files
RajaPiseD Sep 2, 2024
670d07a
support for archieve upload and download
RajaPiseD Sep 3, 2024
0c21fce
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Sep 3, 2024
3a703ba
handle file input as stream io
RajaPiseD Sep 4, 2024
688bd42
updated action yaml
RajaPiseD Sep 4, 2024
09e9d76
Merge branch 'main' into rajapise/dts-integration
RajaPiseD Sep 4, 2024
e5c275b
updated code as per review observations
RajaPiseD Sep 4, 2024
dab97d9
updated profile
RajaPiseD Sep 4, 2024
3357d75
Updated github actions
RajaPiseD Sep 5, 2024
ae3deb2
Update tests.yml
RajaPiseD Sep 5, 2024
f92cf18
Update tests.yml
RajaPiseD Sep 5, 2024
adb6a04
Update action.yml
RajaPiseD Sep 5, 2024
7486c70
Update ci_cd.yml
RajaPiseD Sep 5, 2024
a3ae704
Update ci_cd.yml
RajaPiseD Sep 5, 2024
4274eca
Update action.yml
RajaPiseD Sep 5, 2024
7b1b77a
Update ci_cd.yml
RajaPiseD Sep 5, 2024
fa12c61
Update ci_cd.yml
RajaPiseD Sep 5, 2024
b209cc5
adjust hps-feature defaults
FedericoNegri Sep 5, 2024
fcb023a
prep for merge
FedericoNegri Sep 5, 2024
eb3dd4b
remove compose tags
FedericoNegri Sep 5, 2024
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
27 changes: 18 additions & 9 deletions .github/actions/hps_services/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ inputs:
description: 'HPS version'
required: true

feature:
description: 'HPS feature (only for latest-dev version)'
required: false

token:
description: 'Token'
required: true
Expand Down Expand Up @@ -44,14 +48,17 @@ runs:
token: ${{ inputs.token }}

- if: ${{ inputs.version == 'latest-dev' }}
uses: dsaltares/fetch-gh-release-asset@master
uses: dawidd6/action-download-artifact@v3
name: Download Internal Services Artifact
with:
file: 'docker-compose-internal.tar.gz'
target: 'docker-compose-artifact/docker-compose-internal.tar.gz'
workflow: main.yaml
name: docker-compose-internal
branch: ${{ inputs.feature || 'main'}}
repo: ansys-internal/rep-deployments
version: tags/latest-dev
token: ${{ inputs.token }}
workflow_conclusion: success
search_artifacts: false
path: ./docker-compose-artifact
github_token: ${{ inputs.token }}

- uses: KengoTODA/actions-setup-docker-compose@main
env:
Expand Down Expand Up @@ -80,17 +87,19 @@ runs:
if: ${{ inputs.version == 'latest-dev' }}
shell: bash
run: |
echo "$(pwd)"
pwd
ls -la
tar -xvzf docker-compose-internal.tar.gz
cd docker-compose
FSGATEWAY_TAG=latest-dev JMS_TAG=latest-dev docker-compose pull
FSGATEWAY_TAG=latest-dev JMS_TAG=latest-dev docker-compose up -d
docker-compose pull
docker-compose up -d
working-directory: ./docker-compose-artifact

- name: Wait for services
shell: bash
run: |
curl -k --head -X GET --retry 30 --retry-connrefused --retry-delay 1 https://localhost:8443/hps/jms/api/v1
curl -k --head -X GET --retry 30 --retry-connrefused --retry-delay 5 https://localhost:8443/hps/jms/api/v1
curl -k --head -X GET --retry 30 --retry-connrefused --retry-delay 1 https://localhost:8443/hps/fs/api/v1
curl -k --head -X GET --retry 30 --retry-connrefused --retry-delay 1 https://localhost:8443/hps/rms/api/v1

Expand All @@ -100,4 +109,4 @@ runs:
run: |
echo "url=https://localhost:8443/hps" >> $GITHUB_OUTPUT
echo "path=$(pwd)" >> $GITHUB_OUTPUT
working-directory: ./docker-compose-artifact/docker-compose
working-directory: ./docker-compose-artifact/docker-compose
23 changes: 23 additions & 0 deletions .github/workflows/ci_cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ on:
- 'v1.0.2'
- 'v1.0.3'
- 'latest-dev'
hps-feature:
description: HPS feature to test against
type: 'string'
default: 'main'

pull_request:
push:
Expand Down Expand Up @@ -57,6 +61,7 @@ jobs:
toxenv: ${{ matrix.cfg.toxenv }}
runner: ${{ matrix.os }}
hps-version: ${{ inputs.hps-version || 'latest-dev' }}
hps-feature: ${{ inputs.hps-feature || 'main' }}

docs:
name: Documentation
Expand All @@ -69,6 +74,12 @@ jobs:
uses: actions/setup-python@v5
with:
python-version: ${{ env.MAIN_PYTHON_VERSION }}

- uses: extractions/netrc@v2
with:
machine: github.com
username: pyansys-ci-bot
password: ${{ secrets.PYANSYS_CI_BOT_PACKAGE_TOKEN }}

- name: Install dependencies
run: |
Expand Down Expand Up @@ -120,6 +131,12 @@ jobs:
python-version: '3.12'

steps:
- uses: extractions/netrc@v2
with:
machine: github.com
username: pyansys-ci-bot
password: ${{ secrets.PYANSYS_CI_BOT_PACKAGE_TOKEN }}

- name: Build wheelhouse and perform smoke test
uses: ansys/actions/build-wheelhouse@v7
RajaPiseD marked this conversation as resolved.
Show resolved Hide resolved
with:
Expand All @@ -146,6 +163,12 @@ jobs:
steps:
- name: "Install Git and clone project"
uses: actions/checkout@v4

- uses: extractions/netrc@v2
with:
machine: github.com
username: pyansys-ci-bot
password: ${{ secrets.PYANSYS_CI_BOT_PACKAGE_TOKEN }}

- name: "Set up Python ${{ env.MAIN_PYTHON_VERSION }}"
uses: ansys/actions/_setup-python@main
Expand Down
13 changes: 12 additions & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ on:
description: HPS version to test against
type: string
default: 'latest-dev'
hps-feature:
description: HPS Feature to test against (only for latest-dev version)
type: string
default: 'main'

jobs:

Expand All @@ -31,6 +35,12 @@ jobs:
uses: actions/setup-python@v5
with:
python-version: ${{ inputs.python-version }}

- uses: extractions/netrc@v2
with:
machine: github.com
username: pyansys-ci-bot
password: ${{ secrets.PYANSYS_CI_BOT_PACKAGE_TOKEN }}

- name: Install dependencies
run: |
Expand All @@ -45,7 +55,8 @@ jobs:
ghcr-username: ${{ secrets.PYANSYS_CI_BOT_USERNAME }}
ghcr-token: ${{ secrets.PYANSYS_CI_BOT_PACKAGE_TOKEN }}
version: ${{ inputs.hps-version }}

feature: ${{ inputs.hps-feature }}

- name: Test with tox
run: tox -e ${{ inputs.toxenv }}-coverage
env:
Expand Down
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ dependencies = [
"marshmallow_oneofschema>=2.0.1",
"backoff>=2.0.0",
"pydantic>=1.10.0",
"PyJWT>=2.8.0"
"PyJWT>=2.8.0",
"ansys-hps-data-transfer-client@git+https://github.com/ansys-internal/hps-data-transfer-client.git@main#egg=ansys-hps-data-transfer-client"
Copy link
Member

Choose a reason for hiding this comment

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

@FedericoNegri @RajaPiseD I want to bring to your attention that adding dependencies using the git specifier is not valid when uploading packages to PyPI. The Python Package Index will reject any uploads containing dependencies specified like this.

Copy link
Contributor

Choose a reason for hiding this comment

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

@jorgepiloto we're aware, that's currently an internal dependency which is meant to either be incorporated in pyhps directly or become an open source pyansys package on its own. Either way, it's a prerequisite for the next pyhps release.

]

[project.optional-dependencies]
Expand Down
73 changes: 73 additions & 0 deletions src/ansys/hps/client/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,18 @@
# 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.

"""Module providing the Python client to the HPS APIs."""

import atexit
import logging
import os
import platform
from typing import Union
import warnings

from ansys.hps.data_transfer.client import Client as DTClient
from ansys.hps.data_transfer.client import DataTransferApi
import jwt
import requests

Expand Down Expand Up @@ -156,6 +162,8 @@ def __init__(
self.client_id = client_id
self.client_secret = client_secret
self.verify = verify
self.data_transfer_url = url + f"/dt/api/v1"
self.dt_client = None

if self.verify is None:
self.verify = False
Expand Down Expand Up @@ -256,6 +264,13 @@ def __init__(
self._unauthorized_num_retry = 0
self._unauthorized_max_retry = 1

def exit_handler():
if self.dt_client is not None:
log.info("Stopping the data transfer client gracefully.")
self.dt_client.stop()

atexit.register(exit_handler)

def _get_username(self, decoded_token):
parsed_username = decoded_token.get("preferred_username", None)
if not parsed_username:
Expand All @@ -280,6 +295,62 @@ def rep_url(self) -> str:
log.warning(msg)
return self.url

def _start_dt_worker(self):

if self.dt_client is None:
try:
log.info("Starting Data Transfer client.")
# start Data transfer client
self.dt_client = DTClient(download_dir=self._get_download_dir("Ansys"))

self.dt_client.binary_config.update(
verbosity=3,
debug=False,
insecure=True,
token=self.access_token,
data_transfer_url=self.data_transfer_url,
)
self.dt_client.start()

self.dt_api = DataTransferApi(self.dt_client)
self.dt_api.status(wait=True)
except Exception as ex:
log.debug(ex)
raise HPSError("Error occurred when starting Data Transfer client.")

def _get_download_dir(self, company=None):
RajaPiseD marked this conversation as resolved.
Show resolved Hide resolved
"""
Returns download directory platform dependent

:Parameters:
-`company`: Company name of the software provider

Resulting paths:
`Linux`: /home/user/.ansys/binaries
`Windows`: C:\\Users\\user\\AppData\\Local\\Ansys\\binaries

Note that on Windows we use AppData\Local for this,
not AppData\Roaming, as the data stored for an application should typically be kept local.

"""

environment_variable = "HOME"
if platform.uname()[0].lower() == "windows":
environment_variable = "LOCALAPPDATA"
path = os.environ.get(environment_variable, None)

app_dir = ""
if company:
app_dir = os.path.join(app_dir, company)
if app_dir:
if platform.uname()[0].lower() != "windows":
app_dir = "." + app_dir.lower()
path = os.path.join(path, app_dir)

path = os.path.join(path, "binaries")

return path

@property
def auth_api_url(self) -> str:
msg = f"The client 'auth_api_url' property is deprecated. \
Expand All @@ -306,6 +377,8 @@ def _auto_refresh_token(self, response, *args, **kwargs):
response.request.headers.update(
{"Authorization": self.session.headers["Authorization"]}
)
if self.dt_client is not None:
self.dt_client.binary_config.update(token=self.access_token)
RajaPiseD marked this conversation as resolved.
Show resolved Hide resolved
log.debug(f"Retrying request with updated access token.")
return self.session.send(response.request)

Expand Down
Loading
Loading