Skip to content

Commit 0fd015c

Browse files
committed
Do not create managed folder automatically for mlflow
1 parent 5ee8e58 commit 0fd015c

File tree

2 files changed

+30
-29
lines changed

2 files changed

+30
-29
lines changed

dataikuapi/dss/project.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1625,14 +1625,15 @@ def get_app_manifest(self):
16251625

16261626
# MLflow experiment tracking
16271627
########################################################
1628-
def setup_mlflow(self, managed_folder_name="mlflow_artifacts", host=None):
1628+
def setup_mlflow(self, managed_folder, host=None):
16291629
"""
16301630
Setup the dss-plugin for MLflow
16311631
1632-
:param str managed_folder_name: name of the managed folder where artifacts should be stored
1632+
:param managed_folder: Managed folder where artifacts should be stored.
1633+
Either a managed folder id, or an instance of :class:`dataikuapi.dss.DSSManagedFolder`.
16331634
:param str host: setup a custom host if the backend used is not DSS
16341635
"""
1635-
return MLflowHandle(client=self.client, project_key=self.project_key, managed_folder_name=managed_folder_name, host=host)
1636+
return MLflowHandle(client=self.client, project=self, managed_folder=managed_folder, host=host)
16361637

16371638
def get_mlflow_extension(self):
16381639
"""

dataikuapi/dss_plugin_mlflow/utils.py

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
from ..dss.utils import AnyLoc
2+
from ..utils import DataikuException
3+
import logging
14
import os
25
import sys
36
import tempfile
@@ -6,7 +9,7 @@
69

710

811
class MLflowHandle:
9-
def __init__(self, client, project_key, managed_folder_name, host=None):
12+
def __init__(self, client, project, managed_folder, host=None):
1013
""" Add the MLflow-plugin parts of dataikuapi to MLflow local setup.
1114
1215
This method deals with
@@ -19,7 +22,8 @@ def __init__(self, client, project_key, managed_folder_name, host=None):
1922
with DSS backend as the tracking backend and enable using DSS managed folder
2023
as artifact location.
2124
"""
22-
self.project_key = project_key
25+
self.project = project
26+
self.project_key = project.project_key
2327
self.client = client
2428
self.mlflow_env = {}
2529

@@ -57,32 +61,28 @@ def __init__(self, client, project_key, managed_folder_name, host=None):
5761
"DSS_MLFLOW_TOKEN": self.client.internal_ticket,
5862
"DSS_MLFLOW_INTERNAL_TICKET": self.client.internal_ticket
5963
})
60-
# Set host, tracking URI and project key
61-
self.mlflow_env.update({
62-
"DSS_MLFLOW_PROJECTKEY": project_key,
63-
"MLFLOW_TRACKING_URI": self.client.host + "/dip/publicapi" if host is None else host,
64-
"DSS_MLFLOW_HOST": self.client.host
65-
})
6664

67-
# Get or create managed folder with name 'managed_folder_name'
68-
project = self.client.get_project(project_key)
69-
managed_folders = [
70-
x["id"] for x in project.list_managed_folders()
71-
if x["name"] == managed_folder_name
72-
]
73-
managed_folder = None
74-
if len(managed_folders) > 0:
75-
managed_folder = project.get_managed_folder(managed_folders[0])
76-
else:
77-
managed_folder = project.create_managed_folder(managed_folder_name)
78-
79-
80-
# TODO: don't allow to pass a managed folder name, everything is already
81-
# wired in artifact_repository and in the backend for DSS_MLFLOW_MANAGED_FOLDER_ID to contain
82-
# a smart ref. So, instead of managed_folder_name, we should take a DSSManagedFolder
83-
# or a managed folder id/smart ref and set DSS_MLFLOW_MANAGED_FOLDER_ID to that (smart) id.
65+
def full_id(mf):
66+
return mf.project.project_key + "." + mf.id
67+
68+
def get_managed_folder(smart_mf_id):
69+
return client.get_project(smart_mf_id.project_key).get_managed_folder(smart_mf_id.object_id)
70+
71+
mf_id = managed_folder if isinstance(managed_folder, str) else full_id(managed_folder)
72+
smart_mf_id = AnyLoc.from_ref(self.project_key, mf_id)
73+
try:
74+
get_managed_folder(smart_mf_id).get_definition()
75+
except DataikuException as e:
76+
if "NotFoundException" in str(e):
77+
logging.error('The managed folder "%s" does not exist, please create it in your project flow before running this command.' % (mf_id))
78+
raise
79+
80+
# Set host, tracking URI, project key and managed_folder_id
8481
self.mlflow_env.update({
85-
"DSS_MLFLOW_MANAGED_FOLDER_ID": managed_folder.id
82+
"DSS_MLFLOW_PROJECTKEY": self.project_key,
83+
"MLFLOW_TRACKING_URI": self.client.host + "/dip/publicapi" if host is None else host,
84+
"DSS_MLFLOW_HOST": self.client.host,
85+
"DSS_MLFLOW_MANAGED_FOLDER_ID": mf_id
8686
})
8787

8888
os.environ.update(self.mlflow_env)

0 commit comments

Comments
 (0)