Skip to content

Commit 91c737c

Browse files
authored
#52: Added CLI options for specifying the timeout for the ExtractValidator (#57)
* Added CLI options for specifying the timeout for the ExtractValidator
1 parent 686629a commit 91c737c

File tree

6 files changed

+47
-23
lines changed

6 files changed

+47
-23
lines changed

doc/changes/unreleased.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@
22

33
## Features
44

5-
* #79 Added function get_cli_arg that makes a string CLI argument from an option and its value.
6-
Also allowed passing an option name instead of the StdParams in the following two functions:
7-
create_std_option, check_params.
5+
* #52: Added timeout options for SLC deployer to CLI
6+
* #79 Added function `get_cli_arg` that makes a string CLI argument from an option and its value.
7+
Also allowed passing an option name instead of the `StdParams` in the following two functions:
8+
`create_std_option`, `check_params`.
89

910
## Bug fixing
1011

11-
* #78 Missing default value in the definition of StdParams.path_in_bucket.
12+
* #78 Missing default value in the definition of `StdParams.path_in_bucket`.

exasol/python_extension_common/cli/std_options.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,8 @@ class StdParams(Enum):
113113
alter_system = (StdTags.SLC, auto())
114114
allow_override = (StdTags.SLC, auto())
115115
wait_for_completion = (StdTags.SLC, auto())
116+
deploy_timeout_minutes = (StdTags.SLC, auto())
117+
display_progress = (StdTags.SLC, auto())
116118

117119
def __init__(self, tags: StdTags, value):
118120
self.tags = tags
@@ -157,7 +159,9 @@ def _get_param_name(std_param: StdParamOrName) -> str:
157159
StdParams.upload_container: {'type': bool, 'default': True},
158160
StdParams.alter_system: {'type': bool, 'default': True},
159161
StdParams.allow_override: {'type': bool, 'default': False},
160-
StdParams.wait_for_completion: {'type': bool, 'default': True}
162+
StdParams.wait_for_completion: {'type': bool, 'default': True},
163+
StdParams.deploy_timeout_minutes: {'type': int, 'default': 10},
164+
StdParams.display_progress: {'type': bool, 'default': True},
161165
}
162166

163167

exasol/python_extension_common/deployment/extract_validator.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ class ExtractValidator:
4545
def __init__(self,
4646
pyexasol_connection: pyexasol.ExaConnection,
4747
timeout: timedelta,
48-
interval: timedelta = timedelta(seconds=10),
48+
interval: timedelta = timedelta(seconds=30),
4949
callback: Callable[[int, List[int]], None] | None = None,
5050
) -> None:
5151
self._pyexasol_conn = pyexasol_connection

exasol/python_extension_common/deployment/language_container_deployer.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,10 @@ def get_udf_path(bucket_base_path: bfs.path.PathLike, bucket_file: str) -> PureP
8888
return PurePosixPath(file_path.as_udf_path())
8989

9090

91+
def display_extract_progress(n: int, pending: List[int]):
92+
logger.info(f"Verify extraction: {len(pending)} of {n} nodes pending, IDs: {pending}")
93+
94+
9195
class LanguageContainerDeployer:
9296

9397
def __init__(self,
@@ -105,8 +109,8 @@ def __init__(self,
105109
else:
106110
self._extract_validator = ExtractValidator(
107111
pyexasol_connection,
108-
timeout=timedelta(minutes=5),
109-
interval=timedelta(seconds=10),
112+
timeout=timedelta(minutes=10),
113+
interval=timedelta(seconds=30),
110114
)
111115
logger.debug("Init %s", LanguageContainerDeployer.__name__)
112116

@@ -330,7 +334,10 @@ def create(cls,
330334
path_in_bucket: str = '',
331335
use_ssl_cert_validation: bool = True, ssl_trusted_ca: Optional[str] = None,
332336
ssl_client_certificate: Optional[str] = None,
333-
ssl_private_key: Optional[str] = None) -> "LanguageContainerDeployer":
337+
ssl_private_key: Optional[str] = None,
338+
deploy_timeout: timedelta = timedelta(minutes=10),
339+
display_progress: bool = False,
340+
) -> "LanguageContainerDeployer":
334341
warnings.warn(
335342
"create() function is deprecated and will be removed in a future version. "
336343
"For CLI use the LanguageContainerDeployerCli class instead.",
@@ -389,4 +396,6 @@ def create(cls,
389396
encryption=True,
390397
websocket_sslopt=websocket_sslopt)
391398

392-
return cls(pyexasol_conn, language_alias, bucketfs_path)
399+
callback = display_extract_progress if display_progress else None
400+
extract_validator = ExtractValidator(pyexasol_conn, deploy_timeout, callback=callback)
401+
return cls(pyexasol_conn, language_alias, bucketfs_path, extract_validator)

exasol/python_extension_common/deployment/language_container_deployer_cli.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import click
77
import warnings
88
from exasol.python_extension_common.deployment.language_container_deployer import LanguageContainerDeployer
9+
from datetime import timedelta
910

1011

1112
class CustomizableParameters(Enum):
@@ -154,6 +155,8 @@ def secret_callback(ctx: click.Context, param: click.Option, value: Any):
154155
@click.option('--alter-system/--no-alter-system', type=bool, default=True)
155156
@click.option('--allow-override/--disallow-override', type=bool, default=False)
156157
@click.option('--wait_for_completion/--no-wait_for_completion', type=bool, default=True)
158+
@click.option('--deploy-timeout-minutes', type=int, default=10)
159+
@click.option('--display-progress/--no-display-progress', type=bool, default=True)
157160
def language_container_deployer_main(
158161
bucketfs_name: str,
159162
bucketfs_host: str,
@@ -182,6 +185,8 @@ def language_container_deployer_main(
182185
alter_system: bool,
183186
allow_override: bool,
184187
wait_for_completion: bool,
188+
deploy_timeout_minutes: int,
189+
display_progress: bool,
185190
container_url: Optional[str] = None,
186191
container_name: Optional[str] = None):
187192
warnings.warn(
@@ -213,7 +218,10 @@ def language_container_deployer_main(
213218
ssl_trusted_ca=ssl_cert_path,
214219
ssl_client_certificate=ssl_client_cert_path,
215220
ssl_private_key=ssl_client_private_key,
216-
use_ssl_cert_validation=use_ssl_cert_validation)
221+
use_ssl_cert_validation=use_ssl_cert_validation,
222+
deploy_timeout=timedelta(minutes=deploy_timeout_minutes),
223+
display_progress=display_progress,
224+
)
217225

218226
if not upload_container:
219227
deployer.run(alter_system=alter_system, allow_override=allow_override,

test/unit/deployment/test_cli.py

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
SecretParams,
1414
)
1515
from exasol.python_extension_common.deployment.language_container_deployer import LanguageContainerDeployer
16+
from datetime import timedelta
1617

1718

1819
class CliRunner:
@@ -62,13 +63,15 @@ def __init__(
6263
self,
6364
api: str,
6465
value: any = None,
66+
cli_value: any = None,
6567
cli: str = None,
6668
env: str = None,
6769
prompt: str = None,
6870
):
6971
self.api_kwarg = api
7072
self.value = f"om_value_{api}" if value is None else value
7173
self.cli = cli or "--" + api.replace("_", "-")
74+
self.cli_value = self.value if cli_value is None else cli_value
7275
self.env = env
7376
self.prompt = prompt
7477

@@ -144,6 +147,9 @@ def test_default_values(container_file):
144147
OptionMapper("ssl_client_certificate", "", cli="--ssl-client-cert-path"),
145148
OptionMapper("ssl_private_key", "", cli="--ssl-client-private-key"),
146149
OptionMapper("use_ssl_cert_validation", True),
150+
OptionMapper("deploy_timeout", cli="--deploy-timeout-minutes",
151+
cli_value=5, value=timedelta(minutes=10)),
152+
OptionMapper("display_progress", True),
147153
]
148154
deployer = create_autospec(LanguageContainerDeployer)
149155
with CliRunner(deployer) as runner:
@@ -187,19 +193,17 @@ def test_cli_options_passed_to_create(container_file):
187193
OptionMapper("ssl_client_certificate", cli="--ssl-client-cert-path"),
188194
OptionMapper("ssl_private_key", cli="--ssl-client-private-key"),
189195
OptionMapper("use_ssl_cert_validation", False),
190-
# For the following two arguments to
191-
# LanguageContainerDeployer.create() there are no corresponding CLI
192-
# options defined:
193-
# - container_url: Optional[str] = None,
194-
# - container_name: Optional[str] = None):
196+
OptionMapper("deploy_timeout", cli="--deploy-timeout-minutes",
197+
cli_value=6, value=timedelta(minutes=6)),
198+
OptionMapper("display_progress", False),
195199
]
196200
def keys_and_values():
197201
for o in options:
198202
if o.value == False:
199203
yield "--no-" + o.cli[2:]
200204
continue
201205
yield o.cli
202-
yield str(o.value)
206+
yield str(o.cli_value)
203207

204208
cli_options = list(keys_and_values())
205209
deployer = create_autospec(LanguageContainerDeployer)
@@ -250,17 +254,15 @@ def test_container_file():
250254
"Covered by test_default_values()"
251255

252256

253-
@pytest.mark.skip(reason="Not implemented, yet")
257+
@pytest.mark.skip(reason="Test case to be implemented in derived applications")
254258
def test_container_url():
255259
"""
256260
For the following two arguments to LanguageContainerDeployer.create()
257-
there are no corresponding CLI options defined:
261+
the corresponding CLI options need to defined in actual CLI applications
262+
using ``language_container_deployer_main()``
258263
259264
- container_url: Optional[str] = None,
260265
- container_name: Optional[str] = None):
261266
262-
Hence this test case currently cannot be run.
267+
Hence there is no related test case in the current file.
263268
"""
264-
265-
# Additionally there seems to be a file main.py missing that is wrapping the
266-
# command line.

0 commit comments

Comments
 (0)