Skip to content

Commit 8f1e93a

Browse files
committed
Merge branch 'release/9.0'
2 parents cc11956 + b14c390 commit 8f1e93a

File tree

4 files changed

+91
-51
lines changed

4 files changed

+91
-51
lines changed

dataikuapi/dss/admin.py

Lines changed: 59 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -710,7 +710,19 @@ def set_definition(self, env):
710710
"""
711711
return self.client._perform_json(
712712
"PUT", "/admin/code-envs/%s/%s" % (self.env_lang, self.env_name), body=env)
713-
713+
714+
def get_version_for_project(self, project_key):
715+
"""
716+
Resolve the code env version for a given project
717+
718+
Note: version will only be non-empty for versioned code envs actually used by the project
719+
720+
:returns: the code env reference, with a version field
721+
"""
722+
return self.client._perform_json(
723+
"GET", "/admin/code-envs/%s/%s/%s/version" % (self.env_lang, self.env_name, project_key))
724+
725+
714726
########################################################
715727
# Code env actions
716728
########################################################
@@ -747,6 +759,52 @@ def update_packages(self, force_rebuild_env=False):
747759
raise Exception('Env update failed : %s' % (json.dumps(resp.get('messages', {}).get('messages', {}))))
748760
return resp
749761

762+
def update_images(self, env_version=None):
763+
"""
764+
Rebuild the docker image of the code env
765+
766+
Note: this call requires an API key with admin rights
767+
"""
768+
resp = self.client._perform_json(
769+
"POST", "/admin/code-envs/%s/%s/images" % (self.env_lang, self.env_name),
770+
params={"envVersion": env_version})
771+
if resp is None:
772+
raise Exception('Env image build returned no data')
773+
if resp.get('messages', {}).get('error', False):
774+
raise Exception('Env image build failed : %s' % (json.dumps(resp.get('messages', {}).get('messages', {}))))
775+
return resp
776+
777+
def list_usages(self, env_version=None):
778+
"""
779+
List usages of the code env in the instance
780+
781+
:return: a list of objects where the code env is used
782+
"""
783+
return self.client._perform_json(
784+
"GET", "/admin/code-envs/%s/%s/usages" % (self.env_lang, self.env_name), params={"envVersion": env_version})
785+
786+
def list_logs(self, env_version=None):
787+
"""
788+
List logs of the code env in the instance
789+
790+
:return: a list of log descriptions
791+
"""
792+
return self.client._perform_json(
793+
"GET", "/admin/code-envs/%s/%s/logs" % (self.env_lang, self.env_name), params={"envVersion": env_version})
794+
795+
def get_log(self, log_name):
796+
"""
797+
Get the logs of the code env
798+
799+
Args:
800+
log_name: name of the log to fetch
801+
802+
Returns:
803+
the log, as a string
804+
"""
805+
return self.client._perform_text(
806+
"GET", "/admin/code-envs/%s/%s/logs/%s" % (self.env_lang, self.env_name, log_name))
807+
750808

751809
class DSSGlobalApiKey(object):
752810
"""

dataikuapi/dss/apideployer.py

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -347,15 +347,29 @@ def start_update(self):
347347

348348
return DSSFuture(self.client, future_response.get('jobId', None), future_response)
349349

350-
def delete(self):
350+
def delete(self, disable_first=False):
351351
"""
352-
Deletes this deployment
352+
Deletes this deployment. The disable_first flag automatically disables the deployment
353+
before its deletion.
354+
355+
:param boolean disable_first: If True, automatically disables this deployment before deleting it.
356+
If False, will raise an Exception if this deployment is enabled.
353357
354-
You may only delete a deployment if it is disabled and has been updated after disabling it.
355358
"""
356-
return self.client._perform_empty(
357-
"DELETE", "/api-deployer/deployments/%s" % (self.deployment_id))
358359

360+
# Check if the deployment is disabled
361+
is_enabled = self.get_status().light_status["deploymentBasicInfo"].get("enabled")
362+
if is_enabled and not disable_first:
363+
raise Exception("Deployment {} deletion failed: deployment must be disabled first.".format(self.deployment_id))
364+
if is_enabled:
365+
settings = self.get_settings()
366+
settings.set_enabled(enabled=False)
367+
settings.save()
368+
self.client._perform_empty(
369+
"DELETE", "/api-deployer/deployments/%s" % (self.deployment_id))
370+
371+
372+
359373

360374
class DSSAPIDeployerDeploymentSettings(object):
361375
"""
@@ -534,7 +548,7 @@ def delete(self):
534548
535549
You may only delete a service if it has no deployments on it anymore.
536550
"""
537-
return self.client._perform_empty(
551+
self.client._perform_empty(
538552
"DELETE", "/api-deployer/services/%s" % (self.service_id))
539553

540554

dataikuapi/dss/recipe.py

Lines changed: 0 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1406,44 +1406,3 @@ def __init__(self, name, project):
14061406
def with_input_model(self, model_id):
14071407
"""Sets the input model"""
14081408
return self._with_input(model_id, self.project.project_key, "model")
1409-
1410-
1411-
class DownloadRecipeCreator(SingleOutputRecipeCreator):
1412-
"""
1413-
Create a Download recipe
1414-
"""
1415-
def __init__(self, name, project):
1416-
SingleOutputRecipeCreator.__init__(self, 'download', name, project)
1417-
1418-
1419-
class RequiredSchemaUpdates(object):
1420-
"""
1421-
Representation of the updates required to the schema of the outputs of a recipe.
1422-
Do not create this class directly, use :meth:`DSSRecipe.compute_schema_updates`
1423-
"""
1424-
1425-
def __init__(self, recipe, data):
1426-
self.recipe = recipe
1427-
self.data = data
1428-
self.drop_and_recreate = True
1429-
self.synchronize_metastore = True
1430-
1431-
def any_action_required(self):
1432-
return self.data["totalIncompatibilities"] > 0
1433-
1434-
def apply(self):
1435-
results = []
1436-
for computable in self.data["computables"]:
1437-
osu = {
1438-
"computableType": computable["type"],
1439-
# dirty
1440-
"computableId": computable["type"] == "DATASET" and computable["datasetName"] or computable["id"],
1441-
"newSchema": computable["newSchema"],
1442-
"dropAndRecreate": self.drop_and_recreate,
1443-
"synchronizeMetastore" : self.synchronize_metastore
1444-
}
1445-
1446-
results.append(self.recipe.client._perform_json("POST",
1447-
"/projects/%s/recipes/%s/actions/updateOutputSchema" % (self.recipe.project_key, self.recipe.recipe_name),
1448-
body=osu))
1449-
return results

dataikuapi/dssclient.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ def get_root_project_folder(self):
114114
"""
115115
Get a handle to interact with the root project folder.
116116
117-
:returns: A :class:`dataikuapi.dss.projectfolder.DSSProjectFolder`to interact with this project folder
117+
:returns: A :class:`dataikuapi.dss.projectfolder.DSSProjectFolder` to interact with this project folder
118118
"""
119119
return self.get_project_folder("ROOT")
120120

@@ -123,7 +123,7 @@ def get_project_folder(self, project_folder_id):
123123
Get a handle to interact with a project folder.
124124
125125
:param str project_folder_id: the project folder ID of the desired project folder
126-
:returns: A :class:`dataikuapi.dss.projectfolder.DSSProjectFolder`to interact with this project folder
126+
:returns: A :class:`dataikuapi.dss.projectfolder.DSSProjectFolder` to interact with this project folder
127127
"""
128128
data = self._perform_json("GET", "/project-folders/%s" % project_folder_id)
129129
return DSSProjectFolder(self, data)
@@ -179,7 +179,7 @@ def create_project(self, project_key, name, owner, description=None, settings=No
179179
:param dict settings: Initial settings for the project (can be modified later). The exact possible settings are not documented.
180180
:param str project_folder_id: the project folder ID in which the project will be created (root project folder if not specified)
181181
182-
:returns: A class:`dataikuapi.dss.project.DSSProject` project handle to interact with this project
182+
:returns: A :class:`dataikuapi.dss.project.DSSProject` project handle to interact with this project
183183
"""
184184
params = {}
185185
if project_folder_id is not None:
@@ -528,6 +528,15 @@ def create_code_env(self, env_lang, env_name, deployment_mode, params=None):
528528
raise Exception('Env creation failed : %s' % (json.dumps(resp.get('messages', {}).get('messages', {}))))
529529
return DSSCodeEnv(self, env_lang, env_name)
530530

531+
def list_code_env_usages(self):
532+
"""
533+
List all usages of a code env in the instance
534+
535+
:return: a list of objects where the code env is used
536+
"""
537+
return self._perform_json("GET", "/admin/code-envs/usages")
538+
539+
531540
########################################################
532541
# Clusters
533542
########################################################

0 commit comments

Comments
 (0)