Skip to content

Commit 0bec8e7

Browse files
authored
Odsc 41744/move incorrect opctl information (#236)
2 parents fb3ed9e + e7ee28c commit 0bec8e7

File tree

7 files changed

+84
-29
lines changed

7 files changed

+84
-29
lines changed

ads/opctl/backend/ads_dataflow.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,9 +189,10 @@ def watch(self):
189189
Watch DataFlow Run from OCID.
190190
"""
191191
run_id = self.config["execution"]["run_id"]
192+
interval = self.config["execution"].get("interval")
192193
with AuthContext(auth=self.auth_type, profile=self.profile):
193194
run = DataFlowRun.from_ocid(run_id)
194-
run.watch()
195+
run.watch(interval=interval)
195196

196197

197198
class DataFlowRuntimeFactory(RuntimeFactory):

ads/opctl/backend/ads_ml_job.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -227,10 +227,11 @@ def watch(self):
227227
Watch Job Run from OCID.
228228
"""
229229
run_id = self.config["execution"]["run_id"]
230-
230+
interval = self.config["execution"].get("interval")
231+
wait = self.config["execution"].get("wait")
231232
with AuthContext(auth=self.auth_type, profile=self.profile):
232233
run = DataScienceJobRun.from_ocid(run_id)
233-
run.watch()
234+
run.watch(interval=interval, wait=wait)
234235

235236
def _jinja_write(self, operator_slug, operator_folder):
236237
# TODO AH: fill in templates with relevant details

ads/opctl/backend/ads_ml_pipeline.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,12 @@ def watch(self) -> None:
9191
"""
9292
run_id = self.config["execution"]["run_id"]
9393
log_type = self.config["execution"].get("log_type")
94+
interval = self.config["execution"].get("interval")
9495
with AuthContext(auth=self.auth_type, profile=self.profile):
95-
PipelineRun.from_ocid(run_id).watch(log_type=log_type)
96+
PipelineRun.from_ocid(run_id).watch(
97+
interval=interval,
98+
log_type=log_type
99+
)
96100

97101
def init(
98102
self,

ads/opctl/cli.py

Lines changed: 36 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -233,42 +233,29 @@ def init_vscode(**kwargs):
233233
type=click.Choice(["api_key", "resource_principal"]),
234234
default=None,
235235
),
236+
]
237+
238+
_model_deployment_options = [
236239
click.option(
237240
"--wait-for-completion",
238-
help="either to wait for process to complete or not",
241+
help="either to wait for process to complete or not for model deployment",
239242
is_flag=True,
240243
required=False,
241244
),
242245
click.option(
243246
"--max-wait-time",
244-
help="maximum wait time in seconds for progress to complete",
247+
help="maximum wait time in seconds for progress to complete for model deployment",
245248
type=int,
246249
required=False,
247250
default=1200,
248251
),
249252
click.option(
250253
"--poll-interval",
251-
help="poll interval in seconds",
254+
help="poll interval in seconds for model deployment",
252255
type=int,
253256
required=False,
254257
default=10,
255258
),
256-
click.option(
257-
"--log-type", help="the type of logging.", required=False, default=None
258-
),
259-
click.option(
260-
"--log-filter",
261-
help="expression for filtering the logs.",
262-
required=False,
263-
default=None,
264-
),
265-
click.option(
266-
"--interval",
267-
help="log interval in seconds",
268-
type=int,
269-
required=False,
270-
default=3,
271-
),
272259
]
273260

274261

@@ -464,21 +451,46 @@ def init_operator(**kwargs):
464451

465452
@commands.command()
466453
@click.argument("ocid", nargs=1)
467-
@add_options(_options)
454+
@add_options(_model_deployment_options)
468455
def delete(**kwargs):
469456
suppress_traceback(kwargs["debug"])(delete_cmd)(**kwargs)
470457

471458

472459
@commands.command()
473460
@click.argument("ocid", nargs=1)
474-
@add_options(_options)
461+
@add_options(_model_deployment_options)
475462
def cancel(**kwargs):
476463
suppress_traceback(kwargs["debug"])(cancel_cmd)(**kwargs)
477464

478465

479466
@commands.command()
480467
@click.argument("ocid", nargs=1)
481-
@add_options(_options)
468+
@click.option(
469+
"--log-type",
470+
help="the type of logging. Allowed value: `custom_log` and `service_log` for pipeline, `access` and `predict` for model deployment.",
471+
required=False,
472+
default=None
473+
)
474+
@click.option(
475+
"--log-filter",
476+
help="expression for filtering the logs for model deployment.",
477+
required=False,
478+
default=None,
479+
)
480+
@click.option(
481+
"--interval",
482+
help="log interval in seconds",
483+
type=int,
484+
required=False,
485+
default=3,
486+
)
487+
@click.option(
488+
"--wait",
489+
help="time in seconds to keep updating the logs after the job run finished for job.",
490+
type=int,
491+
required=False,
492+
default=90
493+
)
482494
def watch(**kwargs):
483495
"""
484496
``tail`` logs form a job run, dataflow run or pipeline run.
@@ -489,7 +501,7 @@ def watch(**kwargs):
489501

490502
@commands.command()
491503
@click.argument("ocid", nargs=1)
492-
@add_options(_options)
504+
@add_options(_model_deployment_options)
493505
def activate(**kwargs):
494506
"""
495507
Activates a data science service.
@@ -499,7 +511,7 @@ def activate(**kwargs):
499511

500512
@commands.command()
501513
@click.argument("ocid", nargs=1)
502-
@add_options(_options)
514+
@add_options(_model_deployment_options)
503515
def deactivate(**kwargs):
504516
"""
505517
Deactivates a data science service.

tests/unitary/with_extras/opctl/test_opctl_dataflow_backend.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
import pytest
1313
import yaml
14+
from ads.jobs.builders.infrastructure.dataflow import DataFlowRun
1415

1516
from ads.opctl.backend.ads_dataflow import DataFlowBackend
1617

@@ -87,6 +88,23 @@ def test_dataflow_run(self, file_upload, job_run, job_create):
8788
False,
8889
)
8990

91+
@patch(
92+
"ads.opctl.backend.ads_dataflow.DataFlowRun.watch",
93+
return_value=DataFlowRun(),
94+
)
95+
@patch(
96+
"ads.opctl.backend.ads_dataflow.DataFlowRun.from_ocid",
97+
return_value=DataFlowRun(),
98+
)
99+
def test_watch(self, mock_from_ocid, mock_watch):
100+
config = self.config
101+
config["execution"]["run_id"] = "test_dataflow_run_id"
102+
config["execution"]["interval"] = 10
103+
backend = DataFlowBackend(config)
104+
backend.watch()
105+
mock_from_ocid.assert_called_with("test_dataflow_run_id")
106+
mock_watch.assert_called_with(interval=10)
107+
90108
@pytest.mark.parametrize(
91109
"runtime_type",
92110
["dataFlow", "dataFlowNotebook"],

tests/unitary/with_extras/opctl/test_opctl_ml_job_backend.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,24 @@ def test_run_with_image(self, rt, job_run, job_create):
109109
job_create.assert_called()
110110
job_run.assert_called()
111111

112+
@patch(
113+
"ads.opctl.backend.ads_ml_job.DataScienceJobRun.watch",
114+
return_value=DataScienceJobRun(),
115+
)
116+
@patch(
117+
"ads.opctl.backend.ads_ml_job.DataScienceJobRun.from_ocid",
118+
return_value=DataScienceJobRun(),
119+
)
120+
def test_watch(self, mock_from_ocid, mock_watch):
121+
config = self.config
122+
config["execution"]["run_id"] = "test_job_run_id"
123+
config["execution"]["interval"] = 10
124+
config["execution"]["wait"] = 15
125+
backend = MLJobBackend(config)
126+
backend.watch()
127+
mock_from_ocid.assert_called_with("test_job_run_id")
128+
mock_watch.assert_called_with(interval=10, wait=15)
129+
112130
@pytest.mark.parametrize(
113131
"runtime_type",
114132
["container", "script", "python", "notebook", "gitPython"],

tests/unitary/with_extras/opctl/test_opctl_ml_pipeline_backend.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,10 +129,11 @@ def test_watch(self, mock_from_ocid, mock_watch):
129129
config = self.config
130130
config["execution"]["run_id"] = "test_pipeline_run_id"
131131
config["execution"]["log_type"] = "custom_log"
132+
config["execution"]["interval"] = 10
132133
backend = PipelineBackend(config)
133134
backend.watch()
134135
mock_from_ocid.assert_called_with("test_pipeline_run_id")
135-
mock_watch.assert_called_with(log_type="custom_log")
136+
mock_watch.assert_called_with(interval=10, log_type="custom_log")
136137

137138
@pytest.mark.parametrize(
138139
"runtime_type",

0 commit comments

Comments
 (0)