15
15
from vdk .internal .control .utils .cli_utils import get_or_prompt
16
16
17
17
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
+
18
33
class VdkUI :
19
34
"""
20
35
A single parent class containing all the individual VDK methods in it.
@@ -76,50 +91,45 @@ def run_job(path, arguments=None):
76
91
return {"message" : process .returncode }
77
92
78
93
@staticmethod
79
- def delete_job (name : str , team : str , rest_api_url : str ):
94
+ def delete_job (name : str , team : str ):
80
95
"""
81
96
Execute `delete job`.
82
97
:param name: the name of the data job that will be deleted
83
98
:param team: the team of the data job that will be deleted
84
- :param rest_api_url: The base REST API URL.
85
99
:return: message that the job is deleted
86
100
"""
87
- cmd = JobDelete (rest_api_url )
101
+ cmd = JobDelete (RestApiUrlConfiguration . get_rest_api_url () )
88
102
cmd .delete_job (name , team )
89
103
return f"Deleted the job with name { name } from { team } team. "
90
104
91
105
@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 ):
93
107
"""
94
108
Execute `download job`.
95
109
:param name: the name of the data job that will be downloaded
96
110
:param team: the team of the data job that will be downloaded
97
- :param rest_api_url: The base REST API URL
98
111
:param path: the path to the directory where the job will be downloaded
99
112
:return: message that the job is downloaded
100
113
"""
101
- cmd = JobDownloadSource (rest_api_url )
114
+ cmd = JobDownloadSource (RestApiUrlConfiguration . get_rest_api_url () )
102
115
cmd .download (team , name , path )
103
116
return f"Downloaded the job with name { name } to { path } . "
104
117
105
118
# TODO: make it work with notebook jobs
106
119
@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 ):
110
121
"""
111
122
Execute `create job`.
112
123
:param name: the name of the data job that will be created
113
124
:param team: the team of the data job that will be created
114
- :param rest_api_url: The base REST API URL
115
125
:param path: the path to the directory where the job will be created
116
126
:param local: create sample job on local file system
117
127
:param cloud: create job in the cloud
118
128
:return: message that the job is created
119
129
"""
120
- cmd = JobCreate (rest_api_url )
130
+ cmd = JobCreate (RestApiUrlConfiguration . get_rest_api_url () )
121
131
if cloud :
122
- cli_utils .check_rest_api_url (rest_api_url )
132
+ cli_utils .check_rest_api_url (RestApiUrlConfiguration . get_rest_api_url () )
123
133
124
134
if local :
125
135
cmd .validate_job_path (path , name )
@@ -128,21 +138,18 @@ def create_job(
128
138
return f"Job with name { name } was created."
129
139
130
140
@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 ):
134
142
"""
135
143
Execute `Deploy job`.
136
144
: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
139
146
:param path: the path to the job's directory
140
147
:param reason: the reason of deployment
141
148
:param enabled: flag whether the job is enabled (that will basically un-pause the job)
142
149
:return: output string of the operation
143
150
"""
144
151
output = ""
145
- cmd = JobDeploy (rest_api_url , output )
152
+ cmd = JobDeploy (RestApiUrlConfiguration . get_rest_api_url () , output )
146
153
path = get_or_prompt ("Job Path" , path )
147
154
default_name = os .path .basename (path )
148
155
name = get_or_prompt ("Job Name" , name , default_name )
0 commit comments