Created
April 20, 2018 17:30
-
-
Save alexcombessie/cf02d2a3cbae7dbbda4958505486931c to your computer and use it in GitHub Desktop.
Deploying training projects on Dataiku DSS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Parameters | |
number_of_groups = 5 | |
number_of_users_per_group = 3 | |
generic_password = "password4Training!!" | |
analysis_id, mltask_id = u'bOkH96fi', u'E7bXC2fR' | |
saved_model_id="sXGr0kU2" | |
# Group creation | |
import dataiku | |
client = dataiku.api_client() | |
group_name_list = [i["name"] for i in client.list_groups()] | |
target_group_definition = { | |
u'admin': False, | |
u'mayCreateAuthenticatedConnections': True, | |
u'mayCreateCodeEnvs': True, | |
u'mayCreateProjects': True, | |
u'mayDevelopPlugins': True, | |
u'mayEditLibFolders': True, | |
u'mayManageCodeEnvs': True, | |
u'mayManageUDM': False, | |
u'mayViewIndexedHiveConnections': True, | |
u'mayWriteSafeCode': True, | |
u'mayWriteUnsafeCode': True, | |
} | |
for i in range(number_of_groups): | |
group_name = "group"+str(i+1) | |
group = client.get_group(group_name) | |
if group_name in group_name_list: | |
group.delete() | |
client.create_group(group_name, description="Training "+group_name, source_type='LOCAL') | |
group_definition = group.get_definition() | |
for k,v in target_group_definition.items(): | |
group_definition[k] = v | |
group.set_definition(group_definition) | |
# User group assignment | |
list_user_login = [i["login"] for i in client.list_users()] | |
for i in range(number_of_groups*number_of_users_per_group): | |
user_login = "user"+str(i+1) | |
user = client.get_user(user_login) | |
group_assignment = "group"+str((i // number_of_users_per_group) + 1) | |
if user_login in list_user_login: | |
user.delete() | |
client.create_user(user_login, | |
generic_password, | |
display_name=user_login, | |
source_type='LOCAL', | |
groups=[group_assignment], | |
profile='DATA_SCIENTIST') | |
# Project cloning | |
print(client.list_project_keys()) | |
current_project_key = dataiku.default_project_key() | |
current_project = client.get_project(current_project_key) | |
for i in range(number_of_groups): | |
project_key = current_project_key+"_"+str(i+1) | |
project = client.get_project(project_key) | |
group_name = "group"+str(i+1) | |
if project_key in client.list_project_keys(): | |
project.delete() | |
export_stream = current_project.get_export_stream(options={ | |
"exportAllDatasets": True, | |
"exportSavedModels" : True | |
}) | |
with export_stream as s: | |
client.prepare_project_import(s).execute(settings={"targetProjectKey":project_key}) | |
target_permissions = { | |
u'owner': u'dataiku', | |
u'permissions': [ | |
{ | |
u'admin': False, | |
u'exportDatasetsData': True, | |
u'group': group_name, | |
u'manageAdditionalDashboardUsers': True, | |
u'manageDashboardAuthorizations': True, | |
u'manageExposedElements': True, | |
u'moderateDashboards': True, | |
u'readDashboards': True, | |
u'readProjectContent': True, | |
u'runScenarios': False, | |
u'writeDashboards': True, | |
u'writeProjectContent': True | |
} | |
] | |
} | |
project.set_permissions(target_permissions) | |
# Model redeployment | |
print(current_project.list_ml_tasks()) | |
for i in range(number_of_groups): | |
project_key = current_project_key+"_"+str(i+1) | |
project = client.get_project(project_key) | |
mltask = project.get_ml_task(analysis_id, mltask_id) | |
mltask.start_train() | |
mltask.wait_train_complete() | |
print(mltask.get_trained_models_ids()) | |
model_id = mltask.get_trained_models_ids()[0] | |
mltask.redeploy_to_flow(model_id, saved_model_id=saved_model_id) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment