diff --git a/acceptance/acceptance_test.go b/acceptance/acceptance_test.go index edcacfc3f..1958a5662 100644 --- a/acceptance/acceptance_test.go +++ b/acceptance/acceptance_test.go @@ -414,6 +414,7 @@ func runTest(t *testing.T, dir, coverDir string, repls testdiff.ReplacementsCont require.NoError(t, err) cmd.Env = append(cmd.Env, "TESTDIR="+absDir) cmd.Env = append(cmd.Env, "CLOUD_ENV="+cloudEnv) + cmd.Env = append(cmd.Env, "CURRENT_USER_NAME="+user.UserName) cmd.Dir = tmpDir outputPath := filepath.Join(tmpDir, "output.txt") diff --git a/acceptance/bundle/deployment/bind/experiment/databricks.yml b/acceptance/bundle/deployment/bind/experiment/databricks.yml new file mode 100644 index 000000000..c77da2d88 --- /dev/null +++ b/acceptance/bundle/deployment/bind/experiment/databricks.yml @@ -0,0 +1,8 @@ +bundle: + name: bind-ml-experiment-test-$BUNDLE_NAME_SUFFIX + +resources: + experiments: + experiment1: + name: $EXPERIMENT_NAME + diff --git a/acceptance/bundle/deployment/bind/experiment/output.txt b/acceptance/bundle/deployment/bind/experiment/output.txt new file mode 100644 index 000000000..e9c96a198 --- /dev/null +++ b/acceptance/bundle/deployment/bind/experiment/output.txt @@ -0,0 +1,31 @@ + +=== Bind experiment test: +=== Substitute variables in the template +=== Create a pre-defined experiment +=== Bind experiment: Updating deployment state... +Successfully bound databricks_mlflow_experiment with an id '[NUMID]'. Run 'bundle deploy' to deploy changes to your workspace + +=== Deploy bundle: Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/bind-ml-experiment-test-[UUID]/default/files... +Deploying resources... +Updating deployment state... +Deployment complete! + +=== Read the pre-defined experiment: { + "name": "/Users/[USERNAME]/test-experiment[UUID]", + "lifecycle_stage": "active" +} + +=== Unbind the experiment: Updating deployment state... + +=== Destroy the bundle: All files and directories at the following location will be deleted: /Workspace/Users/[USERNAME]/.bundle/bind-ml-experiment-test-[UUID]/default + +Deleting files... +Destroy complete! + +=== Read the pre-defined experiment again (expecting it still exists and is not deleted): { + "name": "/Users/[USERNAME]/test-experiment[UUID]", + "lifecycle_stage": "active" +} + +=== Test cleanup: +=== Delete the pre-defined experiment: 0 diff --git a/acceptance/bundle/deployment/bind/experiment/script b/acceptance/bundle/deployment/bind/experiment/script new file mode 100644 index 000000000..46a631aea --- /dev/null +++ b/acceptance/bundle/deployment/bind/experiment/script @@ -0,0 +1,42 @@ +title "Bind experiment test: " + +title "Substitute variables in the template" +BUNDLE_NAME_SUFFIX=$(uuid) +export BUNDLE_NAME_SUFFIX + +# double slash at the start prevents Windows to apply replacements to the path +EXPERIMENT_NAME="//Workspace/Users/${CURRENT_USER_NAME}/test-experiment$(uuid)" +if [ -z "$CLOUD_ENV" ]; then + EXPERIMENT_NAME="//Workspace/Users/${CURRENT_USER_NAME}/test-experiment6260d50f-e8ff-4905-8f28-812345678903" # use hard-coded uuid when running locally +fi +export EXPERIMENT_NAME +envsubst < databricks.yml > out.yml && mv out.yml databricks.yml + +title "Create a pre-defined experiment" +EXPERIMENT_ID=$($CLI experiments create-experiment "${EXPERIMENT_NAME}" | jq -r '.experiment_id') + +cleanupRemoveExperiment() { + title "Test cleanup: " + title "Delete the pre-defined experiment: " + $CLI experiments delete-experiment ${EXPERIMENT_ID} + echo $? +} +trap cleanupRemoveExperiment EXIT + +title "Bind experiment: " +$CLI bundle deployment bind experiment1 ${EXPERIMENT_ID} --auto-approve + +title "Deploy bundle: " +$CLI bundle deploy --force-lock --auto-approve + +title "Read the pre-defined experiment: " +$CLI experiments get-experiment ${EXPERIMENT_ID} | jq '{name: .experiment.name, lifecycle_stage: .experiment.lifecycle_stage}' + +title "Unbind the experiment: " +$CLI bundle deployment unbind experiment1 + +title "Destroy the bundle: " +$CLI bundle destroy --auto-approve + +title "Read the pre-defined experiment again (expecting it still exists and is not deleted): " +$CLI experiments get-experiment ${EXPERIMENT_ID} | jq '{name: .experiment.name, lifecycle_stage: .experiment.lifecycle_stage}' diff --git a/acceptance/bundle/deployment/bind/experiment/test.toml b/acceptance/bundle/deployment/bind/experiment/test.toml new file mode 100644 index 000000000..726c4c55d --- /dev/null +++ b/acceptance/bundle/deployment/bind/experiment/test.toml @@ -0,0 +1,6 @@ +Local = false +Cloud = true + +[[Repls]] +Old = "[0-9]{3,}" +New = "[NUMID]" \ No newline at end of file diff --git a/bundle/config/resources.go b/bundle/config/resources.go index 866bd7641..ab5c8f27f 100644 --- a/bundle/config/resources.go +++ b/bundle/config/resources.go @@ -118,6 +118,12 @@ func (r *Resources) FindResourceByConfigKey(key string) (ConfigResource, error) } } + for k := range r.Experiments { + if k == key { + found = append(found, r.Experiments[k]) + } + } + if len(found) == 0 { return nil, fmt.Errorf("no such resource: %s", key) }