Skip to content

Commit 2fde652

Browse files
authored
internal: Rename DoRefresh to DoRead (#3947)
## Why "Refresh" has more meaning in terraform, which is not just read but update local state with new information. We don't do that and this method is simply a wrapper for read/get. Calling it "DoRead" completes CRUD, given that we already have DoCreate, DoUpdate, DoDelete.
1 parent 071b584 commit 2fde652

25 files changed

+37
-37
lines changed

bundle/direct/apply.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ func (d *DeploymentUnit) refreshRemoteState(ctx context.Context, id string) erro
234234
if d.RemoteState != nil {
235235
return nil
236236
}
237-
remoteState, err := d.Adapter.DoRefresh(ctx, id)
237+
remoteState, err := d.Adapter.DoRead(ctx, id)
238238
if err != nil {
239239
return fmt.Errorf("failed to refresh remote state id=%s: %w", id, err)
240240
}

bundle/direct/bundle_plan.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ func (b *DeploymentBundle) CalculatePlan(ctx context.Context, client *databricks
9999
return false
100100
}
101101

102-
remoteState, err := adapter.DoRefresh(ctx, dbentry.ID)
102+
remoteState, err := adapter.DoRead(ctx, dbentry.ID)
103103
if err != nil {
104104
if isResourceGone(err) {
105105
// no such resource
@@ -150,7 +150,7 @@ func (b *DeploymentBundle) CalculatePlan(ctx context.Context, client *databricks
150150
return false
151151
}
152152

153-
remoteState, err := adapter.DoRefresh(ctx, dbentry.ID)
153+
remoteState, err := adapter.DoRead(ctx, dbentry.ID)
154154
if err != nil {
155155
if isResourceGone(err) {
156156
remoteState = nil

bundle/direct/dresources/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
- Each Create/Update/Delete method should correspond to one API call. We persist state right after, so there is minimum chance of having orphaned resources.
1010
- The logic what kind of update it is should be in FieldTriggers / ClassifyChange methods. The methods performing update should not have logic in them on what method to call.
1111
- Create/Update/Delete methods should not need to read any state. (We can implement support for passing remoteState we already to these methods if such need arises though).
12-
- Prefer “with refresh” variants of methods if resource API supports that. That avoids explicit DoRefresh() call.
12+
- Prefer “with refresh” variants of methods if resource API supports that. That avoids explicit DoRead() call.
1313

1414
Nice to have
1515
- Add link to corresponding API documentation before each method.

bundle/direct/dresources/adapter.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@ type IResource interface {
3333
// Example: func (*ResourceJob) RemapState(jobs *jobs.Job) *jobs.JobSettings
3434
RemapState(input any) any
3535

36-
// DoRefresh reads and returns remote state from the backend. The return type defines schema for remote field resolution.
37-
// Example: func (r *ResourceJob) DoRefresh(ctx context.Context, id string) (*jobs.Job, error)
38-
DoRefresh(ctx context.Context, id string) (remoteState any, e error)
36+
// DoRead reads and returns remote state from the backend. The return type defines schema for remote field resolution.
37+
// Example: func (r *ResourceJob) DoRead(ctx context.Context, id string) (*jobs.Job, error)
38+
DoRead(ctx context.Context, id string) (remoteState any, e error)
3939

4040
// DoDelete deletes the resource.
4141
// Example: func (r *ResourceJob) DoDelete(ctx context.Context, id string) error
@@ -210,7 +210,7 @@ func (a *Adapter) initMethods(resource any) error {
210210
return err
211211
}
212212

213-
a.doRefresh, err = prepareCallRequired(resource, "DoRefresh")
213+
a.doRefresh, err = prepareCallRequired(resource, "DoRead")
214214
if err != nil {
215215
return err
216216
}
@@ -431,7 +431,7 @@ func (a *Adapter) RemapState(remoteState any) (any, error) {
431431
return outs[0], nil
432432
}
433433

434-
func (a *Adapter) DoRefresh(ctx context.Context, id string) (any, error) {
434+
func (a *Adapter) DoRead(ctx context.Context, id string) (any, error) {
435435
outs, err := a.doRefresh.Call(ctx, id)
436436
if err != nil {
437437
return nil, err

bundle/direct/dresources/alert.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ func (*ResourceAlert) PrepareState(input *resources.Alert) *sql.AlertV2 {
2222
return &input.AlertV2
2323
}
2424

25-
// DoRefresh reads the alert by id.
26-
func (r *ResourceAlert) DoRefresh(ctx context.Context, id string) (*sql.AlertV2, error) {
25+
// DoRead reads the alert by id.
26+
func (r *ResourceAlert) DoRead(ctx context.Context, id string) (*sql.AlertV2, error) {
2727
return r.client.AlertsV2.GetAlertById(ctx, id)
2828
}
2929

bundle/direct/dresources/all_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -404,8 +404,8 @@ func testCRUD(t *testing.T, group string, adapter *Adapter, client *databricks.W
404404

405405
ctx := context.Background()
406406

407-
// initial DoRefresh() cannot find the resource
408-
remote, err := adapter.DoRefresh(ctx, "1234")
407+
// initial DoRead() cannot find the resource
408+
remote, err := adapter.DoRead(ctx, "1234")
409409
require.Nil(t, remote)
410410
require.Error(t, err)
411411
// TODO: if errors.Is(err, databricks.ErrResourceDoesNotExist) {... }
@@ -414,7 +414,7 @@ func testCRUD(t *testing.T, group string, adapter *Adapter, client *databricks.W
414414
require.NoError(t, err, "DoCreate failed state=%v", newState)
415415
require.NotEmpty(t, createdID, "ID returned from DoCreate was empty")
416416

417-
remote, err = adapter.DoRefresh(ctx, createdID)
417+
remote, err = adapter.DoRead(ctx, createdID)
418418
require.NoError(t, err)
419419
require.NotNil(t, remote)
420420

@@ -503,7 +503,7 @@ func testCRUD(t *testing.T, group string, adapter *Adapter, client *databricks.W
503503

504504
deleteIsNoop := strings.HasSuffix(group, "permissions") || strings.HasSuffix(group, "grants")
505505

506-
remoteAfterDelete, err := adapter.DoRefresh(ctx, createdID)
506+
remoteAfterDelete, err := adapter.DoRead(ctx, createdID)
507507
if deleteIsNoop {
508508
require.NoError(t, err)
509509
} else {

bundle/direct/dresources/app.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ func (*ResourceApp) PrepareState(input *resources.App) *apps.App {
2424
return &input.App
2525
}
2626

27-
func (r *ResourceApp) DoRefresh(ctx context.Context, id string) (*apps.App, error) {
27+
func (r *ResourceApp) DoRead(ctx context.Context, id string) (*apps.App, error) {
2828
return r.client.Apps.GetByName(ctx, id)
2929
}
3030

bundle/direct/dresources/cluster.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ func (r *ResourceCluster) RemapState(input *compute.ClusterDetails) *compute.Clu
7373
return spec
7474
}
7575

76-
func (r *ResourceCluster) DoRefresh(ctx context.Context, id string) (*compute.ClusterDetails, error) {
76+
func (r *ResourceCluster) DoRead(ctx context.Context, id string) (*compute.ClusterDetails, error) {
7777
return r.client.Clusters.GetByClusterId(ctx, id)
7878
}
7979

bundle/direct/dresources/dashboard.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ func (r *ResourceDashboard) RemapState(state *resources.DashboardConfig) *resour
8585
}
8686
}
8787

88-
func (r *ResourceDashboard) DoRefresh(ctx context.Context, id string) (*resources.DashboardConfig, error) {
88+
func (r *ResourceDashboard) DoRead(ctx context.Context, id string) (*resources.DashboardConfig, error) {
8989
var dashboard *dashboards.Dashboard
9090
var publishedDashboard *dashboards.PublishedDashboard
9191

bundle/direct/dresources/database_catalog.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ func (*ResourceDatabaseCatalog) PrepareState(input *resources.DatabaseCatalog) *
2020
return &input.DatabaseCatalog
2121
}
2222

23-
func (r *ResourceDatabaseCatalog) DoRefresh(ctx context.Context, id string) (*database.DatabaseCatalog, error) {
23+
func (r *ResourceDatabaseCatalog) DoRead(ctx context.Context, id string) (*database.DatabaseCatalog, error) {
2424
return r.client.Database.GetDatabaseCatalogByName(ctx, id)
2525
}
2626

0 commit comments

Comments
 (0)