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

Add support for Ansys Lab Proxy connection #308

Merged
merged 24 commits into from
Sep 27, 2023
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
1cf0367
mods from Jerome for initial Ansys Lab suppor
mfkrogh Aug 2, 2023
49f762e
Jerome's other mods for Ansys Lab
mfkrogh Aug 2, 2023
602e2e8
wip
mfkrogh Sep 12, 2023
c23a958
Merge branch 'main' into feat/add_ansys_lab_proxy
mfkrogh Sep 12, 2023
de7c90b
wip; not working
mfkrogh Sep 12, 2023
feb6b9e
cleaned up and mostly working with the refactoring. proxy server is r…
mfkrogh Sep 13, 2023
9d55ee9
mostly working with the proxy server
mfkrogh Sep 13, 2023
9067a60
clean up so it works locally as before and so it works mostly with an…
mfkrogh Sep 14, 2023
153d915
fix REST connection
mfkrogh Sep 14, 2023
a863ed7
more mods for Ansys Lab.
mfkrogh Sep 19, 2023
e7fa0d3
Merge branch 'main' into feat/add_ansys_lab_proxy
mfkrogh Sep 20, 2023
dfe7e86
more mods for Ansys Lab; still debugging
mfkrogh Sep 23, 2023
8a78292
use proper variable to check if we're running under pim
mfkrogh Sep 23, 2023
96b6de8
fix session.show('remote_scene') for local installs. It probably can'…
mfkrogh Sep 23, 2023
edc83f2
Merge branch 'main' into feat/add_ansys_lab_proxy
mfkrogh Sep 23, 2023
0423cef
Pass the necessary environment variables to EnShell if they weren't s…
mfkrogh Sep 25, 2023
0bdead2
Merge branch 'feat/add_ansys_lab_proxy' of https://github.com/pyansys…
mfkrogh Sep 25, 2023
48d170d
session.show("remote_scene") working correctly with a local install o…
mfkrogh Sep 25, 2023
04ac619
Merge branch 'main' into feat/add_ansys_lab_proxy
mfkrogh Sep 26, 2023
3047c63
start_other method needs now two arguments also in the mocked version
mariostieriansys Sep 26, 2023
979acae
Merge branch 'feat/add_ansys_lab_proxy' of https://github.com/pyansys…
mariostieriansys Sep 26, 2023
ed4e1d1
Update src/ansys/pyensight/core/dockerlauncher.py
mfkrogh Sep 27, 2023
c6fb2a5
Update src/ansys/pyensight/core/dockerlauncher.py
mfkrogh Sep 27, 2023
fc17d07
black mods
mfkrogh Sep 27, 2023
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
10 changes: 5 additions & 5 deletions src/ansys/pyensight/core/deep_pixel_view.html
mfkrogh marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<!DOCTYPE html>
<html lang="en">
<head>
<link rel="stylesheet" type="text/css" href="/bootstrap.min.css"/>
<link rel="stylesheet" type="text/css" href="/bootstrap.min.cssOPTIONAL_QUERY"/>

<script src='/jquery-3.4.1.min.js'></script>
<script src='/geotiff.js'></script>
<script src='/geotiff_nexus.js'></script>
<script src="/bootstrap.min.js"></script>
<script src='/jquery-3.4.1.min.jsOPTIONAL_QUERY'></script>
<script src='/geotiff.jsOPTIONAL_QUERY'></script>
<script src='/geotiff_nexus.jsOPTIONAL_QUERY'></script>
<script src="/bootstrap.min.jsOPTIONAL_QUERY"></script>

<script>
function updatepick_ITEMID(e) {
Expand Down
36 changes: 30 additions & 6 deletions src/ansys/pyensight/core/dockerlauncher.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"""
import logging
import os.path
import re
import subprocess
import time
from typing import Any, Dict, Optional
Expand Down Expand Up @@ -160,6 +161,11 @@ def __init__(
self._service_host_port["grpc"] = ("127.0.0.1", -1)
# attach to the file service if available
self._get_file_service()
# if using PIM, we have a query parameter to append to http requests
if self._pim_instance is not None:
d = {"instance_name": self._pim_instance.name}
self._add_query_parameters(d)
#
return

# EnShell gRPC port, EnSight gRPC port, HTTP port, WSS port
Expand Down Expand Up @@ -481,20 +487,28 @@ def connect(self):
# Run websocketserver
wss_cmd = "cpython /ansys_inc/v" + self._ansys_version + "/CEI/nexus"
wss_cmd += self._ansys_version + "/nexus_launcher/websocketserver.py"
# websocket port - this needs to come first since we now have
# --add_header as a optional arg that can take an arbitrary
# number of optional headers.
wss_cmd += " " + str(self._service_host_port["ws"][1])
#
wss_cmd += " --http_directory " + self._session_directory
# http port
wss_cmd += " --http_port " + str(self._service_host_port["http"][1])
# vnc port
wss_cmd += " --client_port 1999"

# optional PIM instance header
if self._pim_instance is not None:
# Add the PIM instance header. wss needs to return this optional
# header in each http response. It's how the Ansys Lab proxy
# knows how to map back to this particular container's IP and port.
wss_cmd += " --add_header instance_name=" + self._pim_instance.name
# EnSight REST API
if self._enable_rest_api:
# grpc port
wss_cmd += " --grpc_port " + str(self._service_host_port["grpc_private"][1])

# EnVision sessions
wss_cmd += " --local_session envision 5"
# websocket port
wss_cmd += " " + str(self._service_host_port["ws"][1])

logging.debug(f"Starting WSS: {wss_cmd}\n")
ret = self._enshell.start_other(wss_cmd)
Expand All @@ -511,11 +525,16 @@ def connect(self):
use_sos = False
if self._use_sos:
use_sos = True
if self._pim_instance is None:
ws_port = self._service_host_port["ws"][1]
else:
ws_port = self._service_host_port["http"][1]
session = ansys.pyensight.core.session.Session(
host=self._service_host_port["grpc_private"][0],
grpc_port=self._service_host_port["grpc_private"][1],
html_hostname=self._service_host_port["http"][0],
html_port=self._service_host_port["http"][1],
ws_port=self._service_host_port["ws"][1],
ws_port=ws_port,
install_path=None,
secret_key=self._secret_key,
timeout=self._timeout,
Expand Down Expand Up @@ -578,7 +597,12 @@ def file_service(self) -> Optional[Any]:

def _get_host_port(self, uri: str) -> tuple:
parse_results = urllib3.util.parse_url(uri)
return (parse_results.host, parse_results.port)
port = (
parse_results.port
if parse_results.port
else (443 if re.search("^https|wss$", parse_results.scheme) else None)
)
return (parse_results.host, port)

def _is_system_egl_capable(self) -> bool:
"""Check if the system is EGL capable.
Expand Down
45 changes: 44 additions & 1 deletion src/ansys/pyensight/core/launcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class implement specific launching paradigms.
import os.path
import platform
import socket
from typing import TYPE_CHECKING, List, Optional
from typing import TYPE_CHECKING, Dict, List, Optional
import warnings

import requests
Expand Down Expand Up @@ -82,6 +82,8 @@ def __init__(
self._egl_env_val = True
else:
self._egl_env_val = False
# a dict of any optional launcher specific query parameters for URLs
self._query_parameters: Dict[str, str] = {}

@property
def session_directory(self) -> str:
Expand Down Expand Up @@ -266,3 +268,44 @@ def _is_windows(self) -> bool:

"""
return platform.system() == "Windows"

def _get_query_parameters(self) -> Dict[str, str]:
"""Return optional http query parameters as a dict.
It may be empty if there are None.
If query parameters exist, they should be added to any
http/https URL intended for the WSS web server.
This is used by things such as Ansys Lab.

Returns
-------
dict
query parameters that should be appended to any queries
"""
return self._query_parameters

def _add_query_parameters(self, params: Dict[str, str]) -> None:
"""Add query parameters supplied by params to the
overall dict of query parameters.

Parameters
----------
params: dict :
query parameters to add to overall dict
"""
for item, value in params.items():
self._query_parameters[item] = value

def _delete_query_parameters(self, params: List[str]) -> None:
"""Delete query parameters supplied by params from the
overall dict of query parameters.

Parameters
----------
params: list :
query parameters to delete from the overall dict
"""
for item in params:
try:
del self._query_parameters[item]
except Exception:
pass
Loading
Loading