Skip to content
Draft
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
2 changes: 2 additions & 0 deletions acceptance/bundle/help/bundle-deployment/output.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ Usage:

Available Commands:
bind Bind bundle-defined resources to existing resources
get Get a deployment.
list List deployments.
migrate Migrate from Terraform to Direct deployment engine
unbind Unbind bundle-defined resources from its managed remote resource

Expand Down
3 changes: 3 additions & 0 deletions acceptance/bundle/help/bundle/output.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,15 @@ Available Commands:
generate Generate bundle configuration
init Initialize using a bundle template
open Open a resource in the browser
operation Read operation records in the bundle metadata service.
plan Show deployment plan
resource Read resource records from the bundle metadata service.
run Run a job, pipeline update or app
schema Generate JSON Schema for bundle configuration
summary Summarize resources deployed by this bundle
sync Synchronize bundle tree to the workspace
validate Validate configuration
version Read version records in the bundle metadata service.

Flags:
-h, --help help for bundle
Expand Down
3 changes: 3 additions & 0 deletions acceptance/cmd/bundle/dms-read-only/out.test.toml

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

81 changes: 81 additions & 0 deletions acceptance/cmd/bundle/dms-read-only/output.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@

>>> [CLI] bundle deployment list
[
{
"display_name": "first deployment",
"name": "deployments/abc",
"status": "DEPLOYMENT_STATUS_ACTIVE",
"target_name": "dev"
},
{
"display_name": "second deployment",
"name": "deployments/def",
"status": "DEPLOYMENT_STATUS_ACTIVE",
"target_name": "prod"
}
]

>>> [CLI] bundle deployment get deployments/abc
{
"display_name": "first deployment",
"last_version_id": "v1",
"name": "deployments/abc",
"status": "DEPLOYMENT_STATUS_ACTIVE",
"target_name": "dev"
}

>>> [CLI] bundle version list deployments/abc
[
{
"cli_version": "[DEV_VERSION]",
"name": "deployments/abc/versions/v1",
"status": "VERSION_STATUS_COMPLETED",
"version_type": ""
}
]

>>> [CLI] bundle version get deployments/abc/versions/v1
{
"cli_version": "[DEV_VERSION]",
"name": "deployments/abc/versions/v1",
"status": "VERSION_STATUS_COMPLETED",
"version_type": ""
}

>>> [CLI] bundle resource list deployments/abc
[
{
"last_action_type": "OPERATION_ACTION_TYPE_CREATE",
"last_version_id": "v1",
"name": "deployments/abc/resources/my_job",
"resource_id": "12345",
"resource_type": "DEPLOYMENT_RESOURCE_TYPE_JOB"
}
]

>>> [CLI] bundle resource get deployments/abc/resources/my_job
{
"last_action_type": "OPERATION_ACTION_TYPE_CREATE",
"last_version_id": "v1",
"name": "deployments/abc/resources/my_job",
"resource_id": "12345",
"resource_type": "DEPLOYMENT_RESOURCE_TYPE_JOB"
}

>>> [CLI] bundle operation list deployments/abc/versions/v1
[
{
"action_type": "OPERATION_ACTION_TYPE_CREATE",
"name": "deployments/abc/versions/v1/operations/my_job",
"resource_id": "12345",
"status": "OPERATION_STATUS_SUCCEEDED"
}
]

>>> [CLI] bundle operation get deployments/abc/versions/v1/operations/my_job
{
"action_type": "OPERATION_ACTION_TYPE_CREATE",
"name": "deployments/abc/versions/v1/operations/my_job",
"resource_id": "12345",
"status": "OPERATION_STATUS_SUCCEEDED"
}
8 changes: 8 additions & 0 deletions acceptance/cmd/bundle/dms-read-only/script
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
trace $CLI bundle deployment list
trace $CLI bundle deployment get deployments/abc
trace $CLI bundle version list deployments/abc
trace $CLI bundle version get deployments/abc/versions/v1
trace $CLI bundle resource list deployments/abc
trace $CLI bundle resource get deployments/abc/resources/my_job
trace $CLI bundle operation list deployments/abc/versions/v1
trace $CLI bundle operation get deployments/abc/versions/v1/operations/my_job
117 changes: 117 additions & 0 deletions acceptance/cmd/bundle/dms-read-only/test.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
# Local-only acceptance test for the read-only DMS commands under
# `databricks bundle {deployment,version,resource,operation}`. The DMS APIs
# aren't on test workspaces yet, so we stub the eight read endpoints with
# fixed response bodies and assert the CLI renders them as expected.
Local = true
Cloud = false

[[Server]]
Pattern = "GET /api/2.0/bundle/deployments"
Response.Body = '''
{
"deployments": [
{
"name": "deployments/abc",
"display_name": "first deployment",
"target_name": "dev",
"status": "DEPLOYMENT_STATUS_ACTIVE"
},
{
"name": "deployments/def",
"display_name": "second deployment",
"target_name": "prod",
"status": "DEPLOYMENT_STATUS_ACTIVE"
}
]
}
'''

[[Server]]
Pattern = "GET /api/2.0/bundle/deployments/abc"
Response.Body = '''
{
"name": "deployments/abc",
"display_name": "first deployment",
"target_name": "dev",
"status": "DEPLOYMENT_STATUS_ACTIVE",
"last_version_id": "v1"
}
'''

[[Server]]
Pattern = "GET /api/2.0/bundle/deployments/abc/versions"
Response.Body = '''
{
"versions": [
{
"name": "deployments/abc/versions/v1",
"cli_version": "0.0.0-dev",
"status": "VERSION_STATUS_COMPLETED"
}
]
}
'''

[[Server]]
Pattern = "GET /api/2.0/bundle/deployments/abc/versions/v1"
Response.Body = '''
{
"name": "deployments/abc/versions/v1",
"cli_version": "0.0.0-dev",
"status": "VERSION_STATUS_COMPLETED"
}
'''

[[Server]]
Pattern = "GET /api/2.0/bundle/deployments/abc/resources"
Response.Body = '''
{
"resources": [
{
"name": "deployments/abc/resources/my_job",
"resource_id": "12345",
"resource_type": "DEPLOYMENT_RESOURCE_TYPE_JOB",
"last_version_id": "v1",
"last_action_type": "OPERATION_ACTION_TYPE_CREATE"
}
]
}
'''

[[Server]]
Pattern = "GET /api/2.0/bundle/deployments/abc/resources/my_job"
Response.Body = '''
{
"name": "deployments/abc/resources/my_job",
"resource_id": "12345",
"resource_type": "DEPLOYMENT_RESOURCE_TYPE_JOB",
"last_version_id": "v1",
"last_action_type": "OPERATION_ACTION_TYPE_CREATE"
}
'''

[[Server]]
Pattern = "GET /api/2.0/bundle/deployments/abc/versions/v1/operations"
Response.Body = '''
{
"operations": [
{
"name": "deployments/abc/versions/v1/operations/my_job",
"action_type": "OPERATION_ACTION_TYPE_CREATE",
"resource_id": "12345",
"status": "OPERATION_STATUS_SUCCEEDED"
}
]
}
'''

[[Server]]
Pattern = "GET /api/2.0/bundle/deployments/abc/versions/v1/operations/my_job"
Response.Body = '''
{
"name": "deployments/abc/versions/v1/operations/my_job",
"action_type": "OPERATION_ACTION_TYPE_CREATE",
"resource_id": "12345",
"status": "OPERATION_STATUS_SUCCEEDED"
}
'''
40 changes: 39 additions & 1 deletion cmd/bundle/bundle.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,47 @@ Online documentation: https://docs.databricks.com/en/dev-tools/bundles/index.htm
cmd.AddCommand(newSummaryCommand())
cmd.AddCommand(newGenerateCommand())
cmd.AddCommand(newDebugCommand())
cmd.AddCommand(deployment.NewDeploymentCommand())
cmd.AddCommand(newOpenCommand())
cmd.AddCommand(newPlanCommand())
cmd.AddCommand(newConfigRemoteSyncCommand())

// Bundle Metadata Service (DMS) read-only command groups. Only `get`
// and `list` are surfaced here; mutating verbs (create/delete/heartbeat/
// complete) are not user-facing yet and stay in the auto-generated
// `cmd/workspace/bundle` tree (which is filtered out of top-level
// registration in cmd/cmd.go).
dms := metadataServiceCommands()

// The DAB `deployment` group already exists for bind/unbind/migrate.
// Augment it additively with the DMS read-side verbs.
deploymentCmd := deployment.NewDeploymentCommand()
deploymentCmd.AddCommand(renameTo(dms["get-deployment"], "get"))
deploymentCmd.AddCommand(renameTo(dms["list-deployments"], "list"))
cmd.AddCommand(deploymentCmd)

versionCmd := &cobra.Command{
Use: "version",
Short: "Read version records in the bundle metadata service.",
}
versionCmd.AddCommand(renameTo(dms["get-version"], "get"))
versionCmd.AddCommand(renameTo(dms["list-versions"], "list"))
cmd.AddCommand(versionCmd)

resourceCmd := &cobra.Command{
Use: "resource",
Short: "Read resource records from the bundle metadata service.",
}
resourceCmd.AddCommand(renameTo(dms["get-resource"], "get"))
resourceCmd.AddCommand(renameTo(dms["list-resources"], "list"))
cmd.AddCommand(resourceCmd)

operationCmd := &cobra.Command{
Use: "operation",
Short: "Read operation records in the bundle metadata service.",
}
operationCmd.AddCommand(renameTo(dms["get-operation"], "get"))
operationCmd.AddCommand(renameTo(dms["list-operations"], "list"))
cmd.AddCommand(operationCmd)

return cmd
}
42 changes: 42 additions & 0 deletions cmd/bundle/metadata_service.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package bundle

import (
"strings"

workspacebundle "github.com/databricks/cli/cmd/workspace/bundle"
"github.com/spf13/cobra"
)

// metadataServiceCommands returns the auto-generated workspace bundle service
// commands keyed by their original cobra Name (e.g. "get-deployment").
//
// The auto-generated `databricks bundle <verb>` namespace collides with the
// DAB `bundle` command tree; cmd/cmd.go filters the workspace bundle root out
// of top-level registration. Here we call into the workspace package once,
// detach each subcommand from its (discarded) parent, and let the DAB bundle
// re-attach them under proper sub-groups with shorter names.
func metadataServiceCommands() map[string]*cobra.Command {
ws := workspacebundle.New()
subs := ws.Commands()
out := make(map[string]*cobra.Command, len(subs))
for _, sub := range subs {
ws.RemoveCommand(sub)
// These ride under the DAB bundle now, which is visible.
sub.Hidden = false
out[sub.Name()] = sub
}
return out
}

// renameTo replaces the first whitespace-separated token of cobra's Use field
// with newName, preserving the trailing positional-arg syntax that cobra renders
// in usage strings (e.g. "get-deployment NAME" -> "get NAME"). Returns the
// command for inline chaining.
func renameTo(c *cobra.Command, newName string) *cobra.Command {
rest := ""
if i := strings.IndexByte(c.Use, ' '); i >= 0 {
rest = c.Use[i:]
}
c.Use = newName + rest
return c
}
Loading