-
Notifications
You must be signed in to change notification settings - Fork 25
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 ServerContext #606
Add ServerContext #606
Changes from 18 commits
a60222d
a0f1f64
c601a46
65c4ce0
ea12ed2
7db57ac
dd40efd
ad40ad3
5a657fd
91786fb
343eb96
0e5a6e7
384f6e2
59568ed
f52f90b
0705748
8853323
3447007
006c6ad
0b61219
2e1ba74
2e07195
cac44ab
79ab562
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
""" | ||
ServerContext | ||
============= | ||
|
||
Gives the ability to choose the context with which the server should be started. | ||
The context allows to choose which capabilities are available. | ||
""" | ||
from enum import Enum | ||
|
||
|
||
class EContextType(Enum): | ||
pre_defined_environment = 0 | ||
"""DataProcessingCore.xml that is next to DataProcessingCore.dll/libDataProcessingCore.so will | ||
be taken""" | ||
premium = 1 | ||
"""Gets the Specific premium DataProcessingCore.xml.""" | ||
user_defined = 2 | ||
"""Load a user defined xml using its path.""" | ||
custom_defined = 3 | ||
"""Loads the xml named "DpfCustomDefined.xml" that the user can modify.""" | ||
entry = 4 | ||
"""Loads the minimum number of plugins for a basic usage.""" | ||
|
||
|
||
class ServerContext: | ||
"""The context allows to choose which capabilities are available server side. | ||
|
||
Parameters | ||
---------- | ||
context_type : EContextType | ||
Type of context. | ||
xml_path : str, optional | ||
Path to the xml to load. | ||
""" | ||
def __init__(self, context_type=EContextType.user_defined, xml_path=""): | ||
self._context_type = context_type | ||
self._xml_path = xml_path | ||
|
||
@property | ||
def context_type(self): | ||
return self._context_type | ||
|
||
@property | ||
def xml_path(self): | ||
return self._xml_path | ||
|
||
def __str__(self): | ||
return f"Server Context of type {self.context_type}" \ | ||
f" with {'no' if len(self.xml_path)==0 else ''} xml path" \ | ||
f"{'' if len(self.xml_path)==0 else ': ' + self.xml_path}" | ||
|
||
|
||
class AvailableServerContexts: | ||
pre_defined_environment = ServerContext(EContextType.pre_defined_environment) | ||
"""DataProcessingCore.xml that is next to DataProcessingCore.dll/libDataProcessingCore.so will | ||
be taken""" | ||
premium = ServerContext(EContextType.premium) | ||
"""Gets the Specific premium DataProcessingCore.xml to load most plugins with their | ||
environments.""" | ||
custom_defined = ServerContext(EContextType.custom_defined) | ||
"""Loads the xml named "DpfCustomDefined.xml" that the user can modify.""" | ||
entry = ServerContext(EContextType.entry) | ||
"""Loads the minimum number of plugins for a basic usage. Is the default.""" | ||
|
||
|
||
SERVER_CONTEXT = AvailableServerContexts.entry | ||
|
||
|
||
def apply_server_context(context=AvailableServerContexts.entry, server=None) -> None: | ||
"""Allows to apply a context globally (if no server is specified) or to a | ||
given server. | ||
When called before any server is started, the context will be applied by default to any | ||
new server. | ||
|
||
The context allows to choose which capabilities are available server side. | ||
|
||
Parameters | ||
---------- | ||
context : ServerContext | ||
Context to apply to the given server or to the newly started servers (when no server | ||
is given). | ||
server : server.DPFServer, optional | ||
Server with channel connected to the remote or local instance. When | ||
``None``, attempts to use the global server. | ||
|
||
Notes | ||
----- | ||
Available with server's version starting at 6.0 (Ansys 2023R2). | ||
""" | ||
from ansys.dpf.core import SERVER | ||
if server is None: | ||
server = SERVER | ||
global SERVER_CONTEXT | ||
SERVER_CONTEXT = context | ||
if server is not None: | ||
from ansys.dpf.core.core import BaseService | ||
base = BaseService(server, load_operators=False) | ||
base.apply_context(context) |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,6 +25,7 @@ | |
server_to_ansys_version | ||
) | ||
from ansys.dpf.core.misc import __ansys_version__ | ||
from ansys.dpf.core import server_context | ||
from ansys.dpf.gate import load_api, data_processing_grpcapi | ||
|
||
import logging | ||
|
@@ -613,6 +614,10 @@ def __init__(self, | |
self._create_shutdown_funcs() | ||
self._check_first_call(num_connection_tryouts) | ||
self.set_as_global(as_global=as_global) | ||
try: | ||
self._base_service.initialize_with_context(server_context.SERVER_CONTEXT) | ||
except errors.DpfVersionNotSupported: | ||
pass | ||
|
||
def _check_first_call(self, num_connection_tryouts): | ||
for i in range(num_connection_tryouts): | ||
|
@@ -763,7 +768,6 @@ def __init__(self, | |
super().__init__(ansys_path=ansys_path, load_operators=load_operators) | ||
# Load DataProcessingCore | ||
from ansys.dpf.gate.utils import data_processing_core_load_api | ||
from ansys.dpf.gate import data_processing_capi | ||
name = "DataProcessingCore" | ||
path = _get_dll_path(name, ansys_path) | ||
try: | ||
|
@@ -774,8 +778,14 @@ def __init__(self, | |
f"DPF directory not found at {os.path.dirname(path)}" | ||
f"Unable to locate the following file: {path}") | ||
raise e | ||
data_processing_capi.DataProcessingCAPI.data_processing_initialize_with_context(1, None) | ||
self.set_as_global(as_global=as_global) | ||
try: | ||
self._base_service.apply_context(server_context.SERVER_CONTEXT) | ||
except errors.DpfVersionNotSupported: | ||
self._base_service.initialize_with_context( | ||
server_context.AvailableServerContexts.premium | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @cbellot000 Why premium in this case? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @PProfizi premium was the old default (equivalent to standalone) |
||
) | ||
pass | ||
|
||
@property | ||
def version(self): | ||
|
@@ -915,6 +925,10 @@ def __init__( | |
|
||
check_ansys_grpc_dpf_version(self, timeout) | ||
self.set_as_global(as_global=as_global) | ||
try: | ||
self._base_service.initialize_with_context(server_context.SERVER_CONTEXT) | ||
except errors.DpfVersionNotSupported: | ||
pass | ||
|
||
def _create_shutdown_funcs(self): | ||
self._core_api = data_processing_grpcapi.DataProcessingGRPCAPI | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
pytest==7.2.0 | ||
pytest-cov==4.0.0 | ||
pytest-rerunfailures==10.2 | ||
pytest-order==1.0.1 | ||
pyvista==0.36.1 | ||
ansys-platform-instancemanagement==1.0.2 | ||
coverage==6.5.0 | ||
coverage==6.5.0 |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -189,6 +189,9 @@ def cyclic_multistage(): | |
return core.examples.download_multi_stage_cyclic_result() | ||
|
||
|
||
SERVERS_VERSION_GREATER_THAN_OR_EQUAL_TO_6_0 = meets_version( | ||
get_server_version(core._global_server()), "6.0" | ||
) | ||
SERVERS_VERSION_GREATER_THAN_OR_EQUAL_TO_5_0 = meets_version( | ||
get_server_version(core._global_server()), "5.0" | ||
) | ||
|
@@ -198,6 +201,10 @@ def cyclic_multistage(): | |
SERVERS_VERSION_GREATER_THAN_OR_EQUAL_TO_3_0 = meets_version( | ||
get_server_version(core._global_server()), "3.0" | ||
) | ||
SERVERS_VERSION_GREATER_THAN_OR_EQUAL_TO_2_0 = meets_version( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @cbellot000 Is the minimum server version required 2.0 or 2.1? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's how it was used before |
||
get_server_version(core._global_server()), "2.1" | ||
) | ||
|
||
|
||
IS_USING_GATEBIN = _try_use_gatebin() | ||
|
||
|
@@ -210,7 +217,10 @@ def raises_for_servers_version_under(version): | |
|
||
def decorator(func): | ||
@pytest.mark.xfail( | ||
not meets_version(get_server_version(core._global_server()), version), | ||
not SERVERS_VERSION_GREATER_THAN_OR_EQUAL_TO_3_0 if version == "3.0" else | ||
not SERVERS_VERSION_GREATER_THAN_OR_EQUAL_TO_4_0 if version == "4.0" else | ||
not SERVERS_VERSION_GREATER_THAN_OR_EQUAL_TO_5_0 if version == "5.0" else | ||
not SERVERS_VERSION_GREATER_THAN_OR_EQUAL_TO_6_0 if version == "6.0" else True, | ||
reason=f"Requires server version greater than or equal to {version}", | ||
raises=core.errors.DpfVersionNotSupported, | ||
) | ||
|
@@ -294,6 +304,15 @@ def remote_config_server_type(request): | |
return request.param | ||
|
||
|
||
@pytest.fixture( | ||
scope="package", | ||
params=configsserver_type, | ||
ids=config_namesserver_type, | ||
) | ||
def config_server_type(request): | ||
return request.param | ||
|
||
|
||
configs_server_type_legacy_grpc, config_names_server_type_legacy_grpc = \ | ||
remove_none_available_config( | ||
[ | ||
|
@@ -421,3 +440,11 @@ def count_servers(): | |
# assert num_dpf_exe == 1 | ||
|
||
request.addfinalizer(count_servers) | ||
|
||
|
||
# to call at the end | ||
core.server.shutdown_all_session_servers() | ||
try: | ||
core.apply_server_context(core.AvailableServerContexts.premium) | ||
except core.errors.DpfVersionNotSupported: | ||
pass |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@cbellot000 Why is the user_defined context the default one? I think this makes the xml_path non-optional in a way.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@PProfizi it's the default of this constructor (because you would only need to use the constructor directly when you want to speicify an xml), it doesn't make user defined the default context (which is SERVER_CONTEXT = AvailableServerContexts.entry)