44 "context"
55 "errors"
66 "fmt"
7- "path"
87 "path/filepath"
98 "strconv"
109 "time"
@@ -18,7 +17,6 @@ import (
1817 "github.com/databricks/cli/bundle/deployplan"
1918 "github.com/databricks/cli/bundle/direct"
2019 "github.com/databricks/cli/bundle/direct/dstate"
21- bundleenv "github.com/databricks/cli/bundle/env"
2220 "github.com/databricks/cli/bundle/phases"
2321 "github.com/databricks/cli/bundle/scripts"
2422 "github.com/databricks/cli/bundle/statemgmt"
@@ -35,7 +33,6 @@ import (
3533 "github.com/databricks/cli/libs/telemetry"
3634 "github.com/databricks/cli/libs/telemetry/protos"
3735 "github.com/databricks/databricks-sdk-go"
38- "github.com/databricks/databricks-sdk-go/apierr"
3936 "github.com/databricks/databricks-sdk-go/service/bundledeployments"
4037 "github.com/databricks/databricks-sdk-go/useragent"
4138 "github.com/spf13/cobra"
@@ -372,7 +369,7 @@ func ProcessBundleRet(cmd *cobra.Command, opts ProcessOptions) (b *bundle.Bundle
372369
373370 if needDirectState && stateDesc .IsDMS () {
374371 var err error
375- dmsDeploymentID , dmsDeployment , err = fetchDeploymentFromStatePath (ctx , b .WorkspaceClient (ctx ), b .Config .Workspace .StatePath )
372+ dmsDeploymentID , dmsDeployment , err = fetchDeploymentFromStatePath (ctx , b .WorkspaceClient (ctx ), b .Config .Workspace .StatePath , stateDesc )
376373 if err != nil {
377374 logdiag .LogError (ctx , err )
378375 return b , stateDesc , root .ErrAlreadyPrinted
@@ -586,6 +583,8 @@ func ValidateEngineSetting(ctx context.Context, b *bundle.Bundle) error {
586583
587584// Lookup and return the deployment object from ${workspace.state_path}/resources.deployment.json
588585//
586+ // The id comes from stateDesc.Deployment when the state pull already looked it up.
587+ //
589588// TODO: a deployment is only usable when both the node and the service's record exist, and a
590589// half-created one - node present, record missing - blocks the bundle here even though
591590// CreateDeployment already recovers from it. Move this behind a dms.ReadDeployment(ctx, statePath)
@@ -594,17 +593,17 @@ func ValidateEngineSetting(ctx context.Context, b *bundle.Bundle) error {
594593//
595594// TODO: ask the service for a lookup by state path, so this is one round trip rather than two - a
596595// workspace lookup to turn the node into an id, then a get by that id.
597- func fetchDeploymentFromStatePath (ctx context.Context , w * databricks.WorkspaceClient , statePath string ) (string , * bundledeployments.Deployment , error ) {
598- nodePath := path .Join (statePath , dms .DeploymentNodeName )
599-
600- obj , err := w .Workspace .GetStatusByPath (ctx , nodePath )
601- if errors .Is (err , apierr .ErrNotFound ) || errors .Is (err , apierr .ErrResourceDoesNotExist ) {
602- return "" , nil , nil
596+ func fetchDeploymentFromStatePath (ctx context.Context , w * databricks.WorkspaceClient , statePath string , stateDesc * statemgmt.StateDesc ) (string , * bundledeployments.Deployment , error ) {
597+ var deploymentID string
598+ var err error
599+ if stateDesc .Deployment != nil {
600+ deploymentID , err = stateDesc .Deployment .ID , stateDesc .Deployment .Err
601+ } else {
602+ deploymentID , err = dms .LookupDeploymentID (ctx , w , statePath )
603603 }
604- if err != nil {
605- return "" , nil , fmt . Errorf ( "looking up deployment at %s: %w" , nodePath , err )
604+ if err != nil || deploymentID == "" {
605+ return "" , nil , err
606606 }
607- deploymentID := strconv .FormatInt (obj .ObjectId , 10 )
608607 deployment , err := w .BundleDeployments .GetDeployment (ctx , bundledeployments.GetDeploymentRequest {
609608 Name : dms .DeploymentName (deploymentID ),
610609 })
@@ -639,7 +638,7 @@ func OpenDirectStateForRead(ctx context.Context, b *bundle.Bundle, stateDesc *st
639638 return enforceDeploymentHistorySetting (ctx , b , stateDesc , false )
640639 }
641640
642- dmsDeploymentID , dmsDeployment , err := fetchDeploymentFromStatePath (ctx , b .WorkspaceClient (ctx ), b .Config .Workspace .StatePath )
641+ dmsDeploymentID , dmsDeployment , err := fetchDeploymentFromStatePath (ctx , b .WorkspaceClient (ctx ), b .Config .Workspace .StatePath , stateDesc )
643642 if err != nil {
644643 return err
645644 }
@@ -658,7 +657,7 @@ func OpenDirectStateForRead(ctx context.Context, b *bundle.Bundle, stateDesc *st
658657}
659658
660659func resolveDeploymentHistory (ctx context.Context , b * bundle.Bundle , stateDesc * statemgmt.StateDesc ) bool {
661- configured := configuresDeploymentHistory (ctx , b )
660+ configured := statemgmt . ConfiguresDeploymentHistory (ctx , b )
662661 if stateDesc .SourcePath == "" {
663662 if configured {
664663 stateDesc .Features = map [string ]struct {}{dstate .FeatureDeploymentHistory : {}}
@@ -673,7 +672,7 @@ func enforceDeploymentHistorySetting(ctx context.Context, b *bundle.Bundle, stat
673672 if stateDesc .SourcePath == "" {
674673 return nil
675674 }
676- configured := configuresDeploymentHistory (ctx , b )
675+ configured := statemgmt . ConfiguresDeploymentHistory (ctx , b )
677676 recorded := stateDesc .IsDMS ()
678677 if configured == recorded {
679678 return nil
@@ -692,14 +691,6 @@ Run "databricks bundle destroy" first, then deploy again with deployment history
692691 return nil
693692}
694693
695- func configuresDeploymentHistory (ctx context.Context , b * bundle.Bundle ) bool {
696- var configured * bool
697- if b .Config .Experimental != nil {
698- configured = b .Config .Experimental .DeploymentHistory
699- }
700- return bundleenv .RecordsDeploymentHistory (ctx , configured )
701- }
702-
703694// isNewerVersion reports whether the state's recorded CLI version is strictly
704695// newer than the running build. Both are bare versions without a leading "v".
705696// An empty stateVersion (state not written by any CLI yet) or an unparseable
0 commit comments