Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .nextchanges/bundles/cluster-libraries.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* Add libraries field to clusters. ([#6831](https://github.com/databricks/cli/pull/6831))
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
bundle:
name: wheel-task-declared-libs

workspace:
root_path: "~/.bundle/$UNIQUE_NAME"

resources:
clusters:
test_cluster:
cluster_name: "test-cluster-$UNIQUE_NAME"
spark_version: "$DEFAULT_SPARK_VERSION"
node_type_id: "$NODE_TYPE_ID"
num_workers: 1
data_security_mode: $DATA_SECURITY_MODE
libraries:
- pypi:
package: requests
- pypi:
package: urllib3

jobs:
some_other_job:
name: "[${bundle.target}] Test Wheel Job $UNIQUE_NAME"
tasks:
- task_key: TestTask
existing_cluster_id: "${resources.clusters.test_cluster.cluster_id}"
python_wheel_task:
package_name: my_test_code
entry_point: run
parameters:
- "one"
- "two"
libraries:
- whl: ./dist/*.whl
- pypi:
package: six
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
__version__ = "0.0.1"
__author__ = "Databricks"
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
"""
The entry point of the Python Wheel
"""

import sys


def main():
# This method will print the provided arguments
print("Hello from my func")
print("Got arguments:")
print(sys.argv)


if __name__ == "__main__":
main()

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@

=== Deploy the cluster (declares requests and urllib3) and the wheel job that targets it
OK: deployed

=== Run the job: its task installs the wheel and pypi 'six' on the shared cluster, out of band
OK: job ran

=== Plan: the job's out-of-band 'six' shows as a removal, the declared libraries are unchanged
>>> plan_pypi_libs
{
"libraries[pypi='six;']": {
"action": "update",
"remote": {
"pypi": {
"package": "six"
}
}
}
}

=== Remove the declared 'urllib3' and redeploy: uninstalls urllib3 and the job's libraries, keeps requests
>>> plan_pypi_libs
{
"libraries[pypi='six;']": {
"action": "update",
"remote": {
"pypi": {
"package": "six"
}
}
},
"libraries[pypi='urllib3;']": {
"action": "update",
"old": {
"pypi": {
"package": "urllib3"
}
},
"remote": {
"pypi": {
"package": "urllib3"
}
}
}
}

OK: redeployed

>>> print_requests.py //libraries/uninstall //libraries/install
{
"method": "POST",
"path": "/api/2.0/libraries/uninstall",
"body": {
"cluster_id": "[TEST_CLUSTER_ID]",
"libraries": [
{
"pypi": {
"package": "urllib3"
}
},
{
"whl": "/Workspace/Users/[USERNAME]/.bundle/[UNIQUE_NAME]/artifacts/.internal/my_test_code-0.0.1-py3-none-any.whl"
},
{
"pypi": {
"package": "six"
}
}
]
}
}
{
"method": "POST",
"path": "/api/2.0/libraries/install",
"body": {
"cluster_id": "[TEST_CLUSTER_ID]",
"libraries": [
{
"pypi": {
"package": "requests"
}
}
]
}
}

>>> [CLI] bundle destroy --auto-approve
The following resources will be deleted:
delete resources.clusters.test_cluster
delete resources.jobs.some_other_job

All files and directories at the following location will be deleted: /Workspace/Users/[USERNAME]/.bundle/[UNIQUE_NAME]

Destroy: 2 deleted
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
export DATA_SECURITY_MODE=USER_ISOLATION
envsubst < databricks.yml.tmpl > databricks.yml
trap "errcode trace '$CLI' bundle destroy --auto-approve" EXIT

# Show the cluster's pypi library plan entries; build/plan noise and the noisy wheel path go to LOG.
plan_pypi_libs() {
$CLI bundle plan -o json 2>>LOG.plan | jq '.plan["resources.clusters.test_cluster"].changes | with_entries(select(.key | startswith("libraries[pypi")))'
}

title "Deploy the cluster (declares requests and urllib3) and the wheel job that targets it"
$CLI bundle deploy &> LOG.deploy
cat LOG.deploy | contains.py "clusters.test_cluster" > /dev/null
printf '\n%s\n' "OK: deployed"

# Normalize server-generated resource IDs before we read requests/plans.
replace_ids.py

title "Run the job: its task installs the wheel and pypi 'six' on the shared cluster, out of band"
$CLI bundle run some_other_job &> LOG.run
printf '\n%s\n' "OK: job ran"
# Flush the install requests the run recorded so they do not leak into the redeploy assertions.
print_requests.py //libraries/install > /dev/null

title "Plan: the job's out-of-band 'six' shows as a removal, the declared libraries are unchanged"
trace plan_pypi_libs

title "Remove the declared 'urllib3' and redeploy: uninstalls urllib3 and the job's libraries, keeps requests"
update_file.py databricks.yml "
- pypi:
package: urllib3" ""
trace plan_pypi_libs
$CLI bundle deploy &> LOG.deploy2
cat LOG.deploy2 | contains.py "Updated clusters.test_cluster" > /dev/null
printf '\n%s\n' "OK: redeployed"
trace print_requests.py //libraries/uninstall //libraries/install
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from setuptools import setup, find_packages

import my_test_code

setup(
name="my_test_code",
version=my_test_code.__version__,
author=my_test_code.__author__,
url="https://databricks.com",
author_email="john.doe@databricks.com",
description="my example wheel",
packages=find_packages(include=["my_test_code"]),
entry_points={"group1": "run=my_test_code.__main__:main"},
install_requires=["setuptools"],
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# The cluster declares `requests` and `urllib3`; the wheel job's task targets the same cluster via
# existing_cluster_id and installs the wheel and pypi `six` on it. So the cluster reads back
# libraries it never declared and treats them as drift: removing `urllib3` uninstalls it and the
# job's libraries (marked UNINSTALL_ON_RESTART on cloud). Cloud + CloudSlow and the venv/wheel harness are inherited from the parent.
# Direct engine only (cluster libraries are a direct-engine feature).
RecordRequests = true

EnvMatrix.DATABRICKS_BUNDLE_ENGINE = ["direct"]
14 changes: 14 additions & 0 deletions acceptance/bundle/invariant/configs/cluster_libraries.yml.tmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
bundle:
name: test-bundle-$UNIQUE_NAME

resources:
clusters:
foo:
cluster_name: test-cluster-$UNIQUE_NAME
spark_version: 13.3.x-scala2.12
node_type_id: $NODE_TYPE_ID
instance_pool_id: $TEST_INSTANCE_POOL_ID
num_workers: 1
libraries:
- pypi:
package: requests
3 changes: 3 additions & 0 deletions acceptance/bundle/invariant/continue_293/test.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ EnvMatrixExclude.no_instance_pool = ["INPUT_CONFIG=instance_pool.yml.tmpl"]
# cluster_policies resource is not supported on v0.293.0
EnvMatrixExclude.no_cluster_policy = ["INPUT_CONFIG=cluster_policy.yml.tmpl"]

# cluster libraries (clusters.libraries) are not supported on v0.293.0
EnvMatrixExclude.no_cluster_libraries = ["INPUT_CONFIG=cluster_libraries.yml.tmpl"]

# job_runs resource is not supported on v0.293.0
EnvMatrixExclude.no_job_run = ["INPUT_CONFIG=job_run.yml.tmpl"]

Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions acceptance/bundle/invariant/migrate/test.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ EnvMatrixExclude.no_genie_space = ["INPUT_CONFIG=genie_space.yml.tmpl"]
EnvMatrixExclude.no_instance_pool = ["INPUT_CONFIG=instance_pool.yml.tmpl"]
# Cluster policies are direct-only; the terraform deploy that seeds the migration fails for them.
EnvMatrixExclude.no_cluster_policy = ["INPUT_CONFIG=cluster_policy.yml.tmpl"]
# Cluster libraries are direct-only; the terraform deploy that seeds the migration fails for them.
EnvMatrixExclude.no_cluster_libraries = ["INPUT_CONFIG=cluster_libraries.yml.tmpl"]
# AI Gateway securables are direct-only; the terraform deploy that seeds the migration fails for them.
EnvMatrixExclude.no_model_service = ["INPUT_CONFIG=model_service.yml.tmpl"]

Expand Down
1 change: 1 addition & 0 deletions acceptance/bundle/invariant/no_drift/out.test.toml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions acceptance/bundle/invariant/test.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ EnvMatrix.INPUT_CONFIG = [
"catalog_optional_fields.yml.tmpl",
"cluster.yml.tmpl",
"cluster_apply_policy_default_values.yml.tmpl",
"cluster_libraries.yml.tmpl",
"cluster_policy.yml.tmpl",
"dashboard.yml.tmpl",
"job_apply_policy_default_values_job_cluster.yml.tmpl",
Expand Down
17 changes: 17 additions & 0 deletions acceptance/bundle/refschema/out.fields.txt
Original file line number Diff line number Diff line change
Expand Up @@ -461,6 +461,23 @@ resources.clusters.*.jdbc_port int REMOTE
resources.clusters.*.kind compute.Kind ALL
resources.clusters.*.last_restarted_time int64 REMOTE
resources.clusters.*.last_state_loss_time int64 REMOTE
resources.clusters.*.libraries []compute.Library ALL
resources.clusters.*.libraries[*] compute.Library ALL
resources.clusters.*.libraries[*].cran *compute.RCranLibrary ALL
resources.clusters.*.libraries[*].cran.package string ALL
resources.clusters.*.libraries[*].cran.repo string ALL
resources.clusters.*.libraries[*].egg string ALL
resources.clusters.*.libraries[*].jar string ALL
resources.clusters.*.libraries[*].maven *compute.MavenLibrary ALL
resources.clusters.*.libraries[*].maven.coordinates string ALL
resources.clusters.*.libraries[*].maven.exclusions []string ALL
resources.clusters.*.libraries[*].maven.exclusions[*] string ALL
resources.clusters.*.libraries[*].maven.repo string ALL
resources.clusters.*.libraries[*].pypi *compute.PythonPyPiLibrary ALL
resources.clusters.*.libraries[*].pypi.package string ALL
resources.clusters.*.libraries[*].pypi.repo string ALL
resources.clusters.*.libraries[*].requirements string ALL
resources.clusters.*.libraries[*].whl string ALL
resources.clusters.*.lifecycle *dresources.StateLifecycle REMOTE STATE
resources.clusters.*.lifecycle *resources.LifecycleWithStarted INPUT
resources.clusters.*.lifecycle resources.Lifecycle INPUT
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
bundle:
name: cluster-libraries-$UNIQUE_NAME

workspace:
root_path: ~/.bundle/$UNIQUE_NAME

artifacts:
my_test_code:
type: whl
path: .
# Use 'python' because 'python3' does not exist in Windows virtualenvs.
build: python setup.py bdist_wheel

resources:
clusters:
mycluster:
cluster_name: mycluster-$UNIQUE_NAME
spark_version: $DEFAULT_SPARK_VERSION
node_type_id: $NODE_TYPE_ID
num_workers: 1
data_security_mode: $DATA_SECURITY_MODE
libraries:
- whl: ./dist/*.whl
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
__version__ = "0.0.1"
__author__ = "Databricks"
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
"""
The entry point of the Python Wheel
"""

import sys


def main():
# This method will print the provided arguments
print("Hello from my func")
print("Got arguments:")
print(sys.argv)


if __name__ == "__main__":
main()

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@

=== Deploy a cluster with a local wheel library
OK: cluster created with wheel

>>> print_requests.py //libraries/install
{
"method": "POST",
"path": "/api/2.0/libraries/install",
"body": {
"cluster_id": "[UUID]",
"libraries": [
{
"whl": "/Workspace/Users/[USERNAME]/.bundle/[UNIQUE_NAME]/artifacts/.internal/my_test_code-0.0.1-py3-none-any.whl"
}
]
}
}

=== Badness: wheel code changes but version does not, so redeploy does not reinstall it
>>> jq .plan["resources.clusters.mycluster"].action tmp.plan.json
"skip"

OK: redeployed without reinstalling the changed wheel (known limitation)

>>> print_requests.py //libraries/install

>>> [CLI] bundle destroy --auto-approve
The following resources will be deleted:
delete resources.clusters.mycluster

All files and directories at the following location will be deleted: /Workspace/Users/[USERNAME]/.bundle/[UNIQUE_NAME]

Destroy: 1 deleted
Loading
Loading