Skip to content

Commit c87fe40

Browse files
vdk-jupyter: fix broken server in one use case (#2170)
What: currently the server is broken in the use case when a user uses the extension with no rest_api_url set as env variable With this changes we only look for the rest_api_url in specific cases for download, create, etc and for run and local development we do not look for it Also we remove the use of rest_api_url in the handlers and move all of it to vdk_ui Why: broken server This is what the users get currently: <img width="565" alt="Screenshot 2023-05-30 at 18 23 41" src="https://github.com/vmware/versatile-data-kit/assets/87015481/496c7a00-1a44-4858-a315-6b40a4b6c6ac"> --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent 5f078fe commit c87fe40

File tree

2 files changed

+26
-42
lines changed
  • projects/vdk-plugins/vdk-jupyter/vdk-jupyterlab-extension/vdk_jupyterlab_extension

2 files changed

+26
-42
lines changed

projects/vdk-plugins/vdk-jupyter/vdk-jupyterlab-extension/vdk_jupyterlab_extension/handlers.py

+1-24
Original file line numberDiff line numberDiff line change
@@ -12,24 +12,6 @@
1212
from .vdk_ui import VdkUI
1313

1414

15-
class HandlerConfiguration:
16-
def __init__(self):
17-
self._rest_api_url = os.environ["REST_API_URL"]
18-
if not self._rest_api_url:
19-
raise ValueError(
20-
"What happened: Missing environment variable REST_API_URL.\n"
21-
"Why it happened: This is probably caused by a corrupt environment.\n"
22-
"Consequences: The current environment cannot work as it cannot connect to the VDK Control Service.\n"
23-
"Countermeasures: Please alert your support team; alternatively, try restarting your environment."
24-
)
25-
26-
def get_rest_api_url(self):
27-
return self._rest_api_url
28-
29-
30-
handler_config = HandlerConfiguration()
31-
32-
3315
class LoadJobDataHandler(APIHandler):
3416
"""
3517
Class responsible for handling POST request for retrieving data(full path, job's name and team)
@@ -83,9 +65,7 @@ def post(self):
8365
input_data = self.get_json_body()
8466
try:
8567
status = VdkUI.delete_job(
86-
input_data[VdkOption.NAME.value],
87-
input_data[VdkOption.TEAM.value],
88-
handler_config.get_rest_api_url(),
68+
input_data[VdkOption.NAME.value], input_data[VdkOption.TEAM.value]
8969
)
9070
self.finish(json.dumps({"message": f"{status}", "error": ""}))
9171
except Exception as e:
@@ -108,7 +88,6 @@ def post(self):
10888
status = VdkUI.download_job(
10989
input_data[VdkOption.NAME.value],
11090
input_data[VdkOption.TEAM.value],
111-
handler_config.get_rest_api_url(),
11291
input_data[VdkOption.PATH.value],
11392
)
11493
self.finish(json.dumps({"message": f"{status}", "error": ""}))
@@ -133,7 +112,6 @@ def post(self):
133112
status = VdkUI.create_job(
134113
input_data[VdkOption.NAME.value],
135114
input_data[VdkOption.TEAM.value],
136-
handler_config.get_rest_api_url(),
137115
input_data[VdkOption.PATH.value],
138116
bool(input_data[VdkOption.LOCAL.value]),
139117
bool(input_data[VdkOption.CLOUD.value]),
@@ -159,7 +137,6 @@ def post(self):
159137
status = VdkUI.create_deployment(
160138
input_data[VdkOption.NAME.value],
161139
input_data[VdkOption.TEAM.value],
162-
handler_config.get_rest_api_url(),
163140
input_data[VdkOption.PATH.value],
164141
input_data[VdkOption.DEPLOYMENT_REASON.value],
165142
input_data[VdkOption.DEPLOY_ENABLE.value],

projects/vdk-plugins/vdk-jupyter/vdk-jupyterlab-extension/vdk_jupyterlab_extension/vdk_ui.py

+25-18
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,21 @@
1515
from vdk.internal.control.utils.cli_utils import get_or_prompt
1616

1717

18+
class RestApiUrlConfiguration:
19+
@staticmethod
20+
def get_rest_api_url():
21+
try:
22+
rest_api_url = os.environ["REST_API_URL"]
23+
except Exception as e:
24+
raise ValueError(
25+
"What happened: Missing environment variable REST_API_URL.\n"
26+
"Why it happened: This is probably caused by a corrupt environment.\n"
27+
"Consequences: The current environment cannot work as it cannot connect to the VDK Control Service.\n"
28+
"Countermeasures: Please alert your support team; alternatively, try restarting your environment."
29+
)
30+
return rest_api_url
31+
32+
1833
class VdkUI:
1934
"""
2035
A single parent class containing all the individual VDK methods in it.
@@ -76,50 +91,45 @@ def run_job(path, arguments=None):
7691
return {"message": process.returncode}
7792

7893
@staticmethod
79-
def delete_job(name: str, team: str, rest_api_url: str):
94+
def delete_job(name: str, team: str):
8095
"""
8196
Execute `delete job`.
8297
:param name: the name of the data job that will be deleted
8398
:param team: the team of the data job that will be deleted
84-
:param rest_api_url: The base REST API URL.
8599
:return: message that the job is deleted
86100
"""
87-
cmd = JobDelete(rest_api_url)
101+
cmd = JobDelete(RestApiUrlConfiguration.get_rest_api_url())
88102
cmd.delete_job(name, team)
89103
return f"Deleted the job with name {name} from {team} team. "
90104

91105
@staticmethod
92-
def download_job(name: str, team: str, rest_api_url: str, path: str):
106+
def download_job(name: str, team: str, path: str):
93107
"""
94108
Execute `download job`.
95109
:param name: the name of the data job that will be downloaded
96110
:param team: the team of the data job that will be downloaded
97-
:param rest_api_url: The base REST API URL
98111
:param path: the path to the directory where the job will be downloaded
99112
:return: message that the job is downloaded
100113
"""
101-
cmd = JobDownloadSource(rest_api_url)
114+
cmd = JobDownloadSource(RestApiUrlConfiguration.get_rest_api_url())
102115
cmd.download(team, name, path)
103116
return f"Downloaded the job with name {name} to {path}. "
104117

105118
# TODO: make it work with notebook jobs
106119
@staticmethod
107-
def create_job(
108-
name: str, team: str, rest_api_url: str, path: str, local: bool, cloud: bool
109-
):
120+
def create_job(name: str, team: str, path: str, local: bool, cloud: bool):
110121
"""
111122
Execute `create job`.
112123
:param name: the name of the data job that will be created
113124
:param team: the team of the data job that will be created
114-
:param rest_api_url: The base REST API URL
115125
:param path: the path to the directory where the job will be created
116126
:param local: create sample job on local file system
117127
:param cloud: create job in the cloud
118128
:return: message that the job is created
119129
"""
120-
cmd = JobCreate(rest_api_url)
130+
cmd = JobCreate(RestApiUrlConfiguration.get_rest_api_url())
121131
if cloud:
122-
cli_utils.check_rest_api_url(rest_api_url)
132+
cli_utils.check_rest_api_url(RestApiUrlConfiguration.get_rest_api_url())
123133

124134
if local:
125135
cmd.validate_job_path(path, name)
@@ -128,21 +138,18 @@ def create_job(
128138
return f"Job with name {name} was created."
129139

130140
@staticmethod
131-
def create_deployment(
132-
name: str, team: str, rest_api_url: str, path: str, reason: str, enabled: bool
133-
):
141+
def create_deployment(name: str, team: str, path: str, reason: str, enabled: bool):
134142
"""
135143
Execute `Deploy job`.
136144
:param name: the name of the data job that will be deployed
137-
:param team: the team of the data job that will be depployed
138-
:param rest_api_url: The base REST API URL
145+
:param team: the team of the data job that will be deployed
139146
:param path: the path to the job's directory
140147
:param reason: the reason of deployment
141148
:param enabled: flag whether the job is enabled (that will basically un-pause the job)
142149
:return: output string of the operation
143150
"""
144151
output = ""
145-
cmd = JobDeploy(rest_api_url, output)
152+
cmd = JobDeploy(RestApiUrlConfiguration.get_rest_api_url(), output)
146153
path = get_or_prompt("Job Path", path)
147154
default_name = os.path.basename(path)
148155
name = get_or_prompt("Job Name", name, default_name)

0 commit comments

Comments
 (0)