Skip to content

Commit 92998aa

Browse files
andrewnesterTanishqDatabricks
authored andcommitted
direct: Pass id to WaitAfterXXX methods (databricks#5258)
## Changes Pass id to WaitAfterXXX methods ## Why Follow up from here databricks#5150 (comment) ## Tests Tests pas <!-- If your PR needs to be included in the release notes for next release, add a separate entry in NEXT_CHANGELOG.md as part of your PR. -->
1 parent dfb47f6 commit 92998aa

7 files changed

Lines changed: 18 additions & 18 deletions

File tree

bundle/direct/apply.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ func (d *DeploymentUnit) Create(ctx context.Context, db *dstate.DeploymentState,
6666
return fmt.Errorf("saving state after creating id=%s: %w", newID, err)
6767
}
6868

69-
waitRemoteState, err := d.Adapter.WaitAfterCreate(ctx, newState)
69+
waitRemoteState, err := d.Adapter.WaitAfterCreate(ctx, newID, newState)
7070
if err != nil {
7171
return fmt.Errorf("waiting after creating id=%s: %w", newID, err)
7272
}
@@ -116,7 +116,7 @@ func (d *DeploymentUnit) Update(ctx context.Context, db *dstate.DeploymentState,
116116
return fmt.Errorf("saving state id=%s: %w", id, err)
117117
}
118118

119-
waitRemoteState, err := d.Adapter.WaitAfterUpdate(ctx, newState)
119+
waitRemoteState, err := d.Adapter.WaitAfterUpdate(ctx, id, newState)
120120
if err != nil {
121121
return fmt.Errorf("waiting after updating id=%s: %w", id, err)
122122
}
@@ -152,7 +152,7 @@ func (d *DeploymentUnit) UpdateWithID(ctx context.Context, db *dstate.Deployment
152152
return fmt.Errorf("saving state id=%s: %w", oldID, err)
153153
}
154154

155-
waitRemoteState, err := d.Adapter.WaitAfterUpdate(ctx, newState)
155+
waitRemoteState, err := d.Adapter.WaitAfterUpdate(ctx, newID, newState)
156156
if err != nil {
157157
return fmt.Errorf("waiting after updating id=%s: %w", newID, err)
158158
}

bundle/direct/dresources/adapter.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,10 @@ type IResource interface {
6767

6868
// [Optional] WaitAfterCreate waits for the resource to become ready after creation. Returns optionally updated remote state.
6969
// TODO: wait status should be persisted in the state.
70-
WaitAfterCreate(ctx context.Context, newState any) (remoteState any, e error)
70+
WaitAfterCreate(ctx context.Context, id string, newState any) (remoteState any, e error)
7171

7272
// [Optional] WaitAfterUpdate waits for the resource to become ready after update. Returns optionally updated remote state.
73-
WaitAfterUpdate(ctx context.Context, newState any) (remoteState any, e error)
73+
WaitAfterUpdate(ctx context.Context, id string, newState any) (remoteState any, e error)
7474

7575
// [Optional] KeyedSlices returns a map from path patterns to KeyFunc for comparing slices by key instead of by index.
7676
// Example: func (*ResourcePermissions) KeyedSlices(state *PermissionsState) map[string]any
@@ -306,7 +306,7 @@ func (a *Adapter) validate() error {
306306
}
307307

308308
if a.waitAfterCreate != nil {
309-
validations = append(validations, "WaitAfterCreate newState", a.waitAfterCreate.InTypes[1], stateType)
309+
validations = append(validations, "WaitAfterCreate newState", a.waitAfterCreate.InTypes[2], stateType)
310310
// WaitAfterCreate must return (remoteType, error)
311311
if len(a.waitAfterCreate.OutTypes) != 2 {
312312
return fmt.Errorf("WaitAfterCreate must return (remoteType, error), got %d return values", len(a.waitAfterCreate.OutTypes))
@@ -315,7 +315,7 @@ func (a *Adapter) validate() error {
315315
}
316316

317317
if a.waitAfterUpdate != nil {
318-
validations = append(validations, "WaitAfterUpdate newState", a.waitAfterUpdate.InTypes[1], stateType)
318+
validations = append(validations, "WaitAfterUpdate newState", a.waitAfterUpdate.InTypes[2], stateType)
319319
// WaitAfterUpdate must return (remoteType, error)
320320
if len(a.waitAfterUpdate.OutTypes) != 2 {
321321
return fmt.Errorf("WaitAfterUpdate must return (remoteType, error), got %d return values", len(a.waitAfterUpdate.OutTypes))
@@ -485,12 +485,12 @@ func (a *Adapter) DoResize(ctx context.Context, id string, newState any) error {
485485
// WaitAfterCreate waits for the resource to become ready after creation.
486486
// If the resource doesn't implement this method, this is a no-op.
487487
// Returns the updated remoteState if available, otherwise returns nil
488-
func (a *Adapter) WaitAfterCreate(ctx context.Context, newState any) (any, error) {
488+
func (a *Adapter) WaitAfterCreate(ctx context.Context, id string, newState any) (any, error) {
489489
if a.waitAfterCreate == nil {
490490
return nil, nil // no-op if not implemented
491491
}
492492

493-
outs, err := a.waitAfterCreate.Call(ctx, newState)
493+
outs, err := a.waitAfterCreate.Call(ctx, id, newState)
494494
if err != nil {
495495
return nil, err
496496
}
@@ -502,12 +502,12 @@ func (a *Adapter) WaitAfterCreate(ctx context.Context, newState any) (any, error
502502
// WaitAfterUpdate waits for the resource to become ready after update.
503503
// If the resource doesn't implement this method, this is a no-op.
504504
// Returns the updated remoteState if available, otherwise returns nil.
505-
func (a *Adapter) WaitAfterUpdate(ctx context.Context, newState any) (any, error) {
505+
func (a *Adapter) WaitAfterUpdate(ctx context.Context, id string, newState any) (any, error) {
506506
if a.waitAfterUpdate == nil {
507507
return nil, nil // no-op if not implemented
508508
}
509509

510-
outs, err := a.waitAfterUpdate.Call(ctx, newState)
510+
outs, err := a.waitAfterUpdate.Call(ctx, id, newState)
511511
if err != nil {
512512
return nil, err
513513
}

bundle/direct/dresources/all_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -798,7 +798,7 @@ func testCRUD(t *testing.T, group string, adapter *Adapter, client *databricks.W
798798
"unexpected differences between remappedState and remappedRemoteStateFromCreate")
799799
}
800800

801-
remoteStateFromWaitCreate, err := adapter.WaitAfterCreate(ctx, newState)
801+
remoteStateFromWaitCreate, err := adapter.WaitAfterCreate(ctx, createdID, newState)
802802
require.NoError(t, err)
803803
if remoteStateFromWaitCreate != nil {
804804
require.Equal(t, remote, remoteStateFromWaitCreate)
@@ -814,7 +814,7 @@ func testCRUD(t *testing.T, group string, adapter *Adapter, client *databricks.W
814814
"unexpected differences between remappedState and remappedStateFromUpdate")
815815
}
816816

817-
remoteStateFromWaitUpdate, err := adapter.WaitAfterUpdate(ctx, newState)
817+
remoteStateFromWaitUpdate, err := adapter.WaitAfterUpdate(ctx, createdID, newState)
818818
require.NoError(t, err)
819819
if remoteStateFromWaitUpdate != nil {
820820
remappedStateFromWaitUpdate, err := adapter.RemapState(remoteStateFromWaitUpdate)

bundle/direct/dresources/app.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ func (r *ResourceApp) DoDelete(ctx context.Context, id string) error {
321321
return err
322322
}
323323

324-
func (r *ResourceApp) WaitAfterCreate(ctx context.Context, config *AppState) (*AppRemote, error) {
324+
func (r *ResourceApp) WaitAfterCreate(ctx context.Context, id string, config *AppState) (*AppRemote, error) {
325325
remote, err := r.waitForApp(ctx, r.client, config.Name)
326326
if err != nil {
327327
return nil, err

bundle/direct/dresources/database_instance.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ func (d *ResourceDatabaseInstance) DoUpdate(ctx context.Context, id string, conf
4646
return nil, err
4747
}
4848

49-
func (d *ResourceDatabaseInstance) WaitAfterCreate(ctx context.Context, config *database.DatabaseInstance) (*database.DatabaseInstance, error) {
49+
func (d *ResourceDatabaseInstance) WaitAfterCreate(ctx context.Context, id string, config *database.DatabaseInstance) (*database.DatabaseInstance, error) {
5050
waiter := &database.WaitGetDatabaseInstanceDatabaseAvailable[database.DatabaseInstance]{
5151
Response: config,
5252
Name: config.Name,

bundle/direct/dresources/model_serving_endpoint.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,11 +150,11 @@ func (r *ResourceModelServingEndpoint) waitForEndpointReady(ctx context.Context,
150150
}, nil
151151
}
152152

153-
func (r *ResourceModelServingEndpoint) WaitAfterCreate(ctx context.Context, config *serving.CreateServingEndpoint) (*ModelServingEndpointRemote, error) {
153+
func (r *ResourceModelServingEndpoint) WaitAfterCreate(ctx context.Context, id string, config *serving.CreateServingEndpoint) (*ModelServingEndpointRemote, error) {
154154
return r.waitForEndpointReady(ctx, config.Name)
155155
}
156156

157-
func (r *ResourceModelServingEndpoint) WaitAfterUpdate(ctx context.Context, config *serving.CreateServingEndpoint) (*ModelServingEndpointRemote, error) {
157+
func (r *ResourceModelServingEndpoint) WaitAfterUpdate(ctx context.Context, id string, config *serving.CreateServingEndpoint) (*ModelServingEndpointRemote, error) {
158158
return r.waitForEndpointReady(ctx, config.Name)
159159
}
160160

bundle/direct/dresources/vector_search_endpoint.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ func (r *ResourceVectorSearchEndpoint) DoCreate(ctx context.Context, config *vec
7777
return id, newVectorSearchEndpointRemote(waiter.Response), nil
7878
}
7979

80-
func (r *ResourceVectorSearchEndpoint) WaitAfterCreate(ctx context.Context, config *vectorsearch.CreateEndpoint) (*VectorSearchEndpointRemote, error) {
80+
func (r *ResourceVectorSearchEndpoint) WaitAfterCreate(ctx context.Context, id string, config *vectorsearch.CreateEndpoint) (*VectorSearchEndpointRemote, error) {
8181
info, err := r.client.VectorSearchEndpoints.WaitGetEndpointVectorSearchEndpointOnline(ctx, config.Name, 60*time.Minute, nil)
8282
if err != nil {
8383
return nil, err

0 commit comments

Comments
 (0)