1 # ==================================================================================
3 # Copyright (c) 2022 Samsung Electronics Co., Ltd. All Rights Reserved.
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
9 # http://www.apache.org/licenses/LICENSE-2.0
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
17 # ==================================================================================
20 from kfp_server_api.models.api_run import ApiRun
21 from kfp_server_api.models.api_list_runs_response import ApiListRunsResponse
23 from kfp_server_api.models.api_experiment import ApiExperiment
24 from kfp_server_api.models.api_list_pipelines_response import ApiListPipelinesResponse
25 from kfp_server_api.models.api_pipeline import ApiPipeline
26 from kfp_server_api.models.api_parameter import ApiParameter
27 from kfp_server_api.models.api_resource_reference import ApiResourceReference
28 from kfp_server_api.models.api_resource_key import ApiResourceKey
29 from kfp_server_api.models.api_pipeline_version import ApiPipelineVersion
34 print("Initialized Fake KfConnect")
36 def get_kf_list_experiments(self, nspace):
37 explist = kfp_server_api.ApiListExperimentsResponse()
39 exp = kfp_server_api.ApiExperiment()
42 explist.experiments = [exp]
45 def get_pl_versions_by_pl_name(self, pipeline_name):
47 version_list.append("2.0.0")
50 def run_kf_pipeline(self,exp_id,arguments,
53 pipeline_package_path: Optional[str] = None,
54 params: Optional[dict] = None,
55 pipeline_id: Optional[str] = None,
56 version_id: Optional[str] = None,
57 pipeline_root: Optional[str] = None,
58 enable_caching: Optional[str] = None,
59 service_account: Optional[str] = None,):
64 rr0 = ApiResourceReference()
66 key0 = ApiResourceKey()
69 rr1 = ApiResourceReference()
71 key1 = ApiResourceKey()
74 run.status = "Running"
75 run.resource_references = [rr0, rr1]
79 def delete_kf_pipeline(self, pipeline_id):
82 def get_kf_pipeline_version_id( self,pipeline_version_name,
90 def get_kf_list_runs(self,
96 listrun = ApiListRunsResponse()
99 run1.description = "description"
100 run1.status = "status"
102 rr0 = ApiResourceReference()
104 key0 = ApiResourceKey()
108 rr1 = ApiResourceReference()
110 key1 = ApiResourceKey()
114 run1.resource_references = [rr0, rr1]
118 run2.description = "description"
119 run2.status = "status"
121 rr2 = ApiResourceReference()
123 key2 = ApiResourceKey()
127 rr3 = ApiResourceReference()
129 key3 = ApiResourceKey()
133 run2.resource_references = [rr2, rr3]
136 listrun.runs = [run1, run2]
140 def get_kf_pipeline_desc(self, pipeline_id: str):
141 pipeline_info = ApiPipeline()
143 param1 = ApiParameter()
144 param1.name = "param1"
145 param1.value = "value1"
146 param2 = ApiParameter()
147 param2.name = "param2"
148 param2.value = "value2"
149 pipeline_info.parameters = [param1, param2]
150 pipeline_info.description = 'description'
151 pipeline_info.id = "id"
152 pipeline_info.name = "name"
154 param3 = ApiParameter()
155 param3.name = "param3"
156 param3.value = "value3"
157 param4 = ApiParameter()
158 param4.name = "param4"
159 param4.value = "value4"
161 default_version = ApiPipelineVersion()
162 default_version.parameters = [param3, param4]
164 pipeline_info.default_version = default_version
167 def get_kf_run(self, run_id: str):
169 run.name = "run_name"
170 run.status = "Running"
174 def get_kf_experiment_details(self, ex_name, nspace):
175 experiment = ApiExperiment()
176 experiment.name = "exp_name"
177 experiment.id = "exp_id"
180 def get_kf_pipeline_id(self, pipeline_name):
183 def upload_pipeline_with_versions(self, pipeline_name, file, desc):
184 pipeline_info = kfp_server_api.ApiPipelineVersion()
185 pipeline_info.id("pipeline_id")
189 def get_kf_list_pipelines(self):
190 pipeline_list = ApiListPipelinesResponse()
191 pipeline = ApiPipeline()
192 pipeline.id = "pipeline_id"
193 pipeline.description = "pipeline_description"
194 parameter = ApiParameter()
195 parameter.name = "param1"
196 parameter.value = "value1"
197 pipeline.parameters = [parameter]
198 pipeline_list.pipelines = [pipeline]
202 class NegativeFakeKfConnect:
204 print("Initialized Negative Fake KfConnect")
206 def get_kf_pipeline_id(self, pipeline_name):
209 def get_kf_experiment_details(self, ex_name, nspace):
212 def get_pl_versions_by_pl_name(self, pipeline_name):
213 raise kfp_server_api.exceptions.ApiException
215 def get_kf_run(self, run_id):
219 run.name = 'run_name'
220 run.status = 'Running'
223 raise Exception('erro')
225 def get_kf_list_runs(self, nspace):
228 run.name = "run_name"
229 run.status = "Running"
231 run.description = "descrption"
232 rr0 = ApiResourceReference()
234 key0 = ApiResourceKey()
236 run.resource_references = [rr0]
238 runs = ApiListRunsResponse()
243 def get_kf_list_pipelines(self,
247 raise Exception('error')
250 def get_kf_pipeline_desc(self, pipeline_id):
251 raise kfp_server_api.exceptions.ApiException
253 class NegativeFakeAdditionalKfConnect:
255 def get_kf_experiment_details(self, ex_name, nspace):
256 raise Exception('error')
258 def get_kf_pipeline_id(self, pipeline_name):
259 raise kfp_server_api.exceptions.ApiException('error')
261 def get_pl_versions_by_pl_namee(self, pipeline_name):
262 raise Exception('error')
265 def get_kf_pipeline_version_id(self, pipeline_id, pipeline_version_name):
266 raise Exception('error')
268 def get_kf_list_experiments(self, nspace):
269 raise Exception('error')
271 def get_kf_pipeline_desc(self, pipeline_id: str):
272 raise kfp_server_api.exceptions.ApiException('error')
274 class NegativeFakeNoneKfConnect:
276 def get_kf_experiment_details(self, ex_name, nspace):
277 experiment = ApiExperiment()
278 experiment.name = "exp_name"
279 experiment.id = "exp_id"
282 def get_kf_pipeline_id(self, pipeline_name):