Skip to content

Commit 926eda6

Browse files
authored
Merge pull request #221 from dataiku/feature/dss110-sc-80078-mlflow-dont-auto-create-managed-folder
Dont auto create managed folder in setup_mlflow
2 parents ae5e512 + 2f8f749 commit 926eda6

File tree

2 files changed

+25
-28
lines changed

2 files changed

+25
-28
lines changed

dataikuapi/dss/project.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import time, warnings, sys, os.path as osp
1+
import warnings, os.path as osp
22

33
from ..dss_plugin_mlflow import MLflowHandle
44

@@ -1608,14 +1608,14 @@ def get_app_manifest(self):
16081608

16091609
# MLflow experiment tracking
16101610
########################################################
1611-
def setup_mlflow(self, managed_folder_name="mlflow_artifacts", host=None):
1611+
def setup_mlflow(self, managed_folder, host=None):
16121612
"""
16131613
Setup the dss-plugin for MLflow
16141614
1615-
:param str managed_folder_name: name of the managed folder where artifacts should be stored
1615+
:param object managed_folder: a :class:`dataikuapi.dss.DSSManagedFolder` where MLflow artifacts should be stored.
16161616
:param str host: setup a custom host if the backend used is not DSS
16171617
"""
1618-
return MLflowHandle(client=self.client, project_key=self.project_key, managed_folder_name=managed_folder_name, host=host)
1618+
return MLflowHandle(client=self.client, project=self, managed_folder=managed_folder, host=host)
16191619

16201620
def get_mlflow_extension(self):
16211621
"""

dataikuapi/dss_plugin_mlflow/utils.py

Lines changed: 21 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
from ..utils import DataikuException
2+
from ..dss.managedfolder import DSSManagedFolder
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,25 @@ 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)
65+
if not isinstance(managed_folder, DSSManagedFolder):
66+
raise TypeError('managed_folder must a DSSManagedFolder.')
7867

68+
mf_project = managed_folder.project.project_key
69+
mf_id = managed_folder.id
70+
try:
71+
client.get_project(mf_project).get_managed_folder(mf_id).get_definition()
72+
except DataikuException as e:
73+
if "NotFoundException" in str(e):
74+
logging.error('The managed folder "%s" does not exist, please create it in your project flow before running this command.' % (mf_id))
75+
raise
7976

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.
77+
# Set host, tracking URI, project key and managed_folder_id
8478
self.mlflow_env.update({
85-
"DSS_MLFLOW_MANAGED_FOLDER_ID": managed_folder.id
79+
"DSS_MLFLOW_PROJECTKEY": self.project_key,
80+
"MLFLOW_TRACKING_URI": self.client.host + "/dip/publicapi" if host is None else host,
81+
"DSS_MLFLOW_HOST": self.client.host,
82+
"DSS_MLFLOW_MANAGED_FOLDER_ID": mf_project + "." + mf_id
8683
})
8784

8885
os.environ.update(self.mlflow_env)

0 commit comments

Comments
 (0)