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
12 changes: 8 additions & 4 deletions bundle/bundle.go
Original file line numberDiff line numberDiff line change
Expand Up@@ -7,7 +7,7 @@ import (

"github.com/databricks/bricks/bundle/config"
"github.com/databricks/bricks/bundle/config/mutator"
"github.com/databricks/databricks-sdk-go/workspaces"
"github.com/databricks/databricks-sdk-go"
)

type Bundle struct {
Expand All@@ -16,7 +16,7 @@ type Bundle struct {
// Store a pointer to the workspace client.
// It can be initialized on demand after loading the configuration.
clientOnce sync.Once
client *workspaces.WorkspacesClient
client *databricks.WorkspaceClient
}

func (b *Bundle) MutateForEnvironment(env string) error {
Expand DownExpand Up@@ -59,9 +59,13 @@ func ConfigureForEnvironment(ctx context.Context, env string) (context.Context,
return Context(ctx, b), nil
}

func (b *Bundle) WorkspaceClient() *workspaces.WorkspacesClient {
func (b *Bundle) WorkspaceClient() *databricks.WorkspaceClient {
b.clientOnce.Do(func() {
b.client = b.Config.Workspace.Client()
var err error
b.client, err = b.Config.Workspace.Client()
if err != nil {
panic(err)
}
})
return b.client
}
7 changes: 3 additions & 4 deletions bundle/config/workspace.go
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
package config

import (
"github.com/databricks/databricks-sdk-go/databricks"
"github.com/databricks/databricks-sdk-go/workspaces"
"github.com/databricks/databricks-sdk-go"
)

// Workspace defines configurables at the workspace level.
Expand DownExpand Up@@ -31,7 +30,7 @@ type Workspace struct {
AzureLoginAppID string `json:"azure_login_app_id,omitempty"`
}

func (w *Workspace) Client() *workspaces.WorkspacesClient {
func (w *Workspace) Client() (*databricks.WorkspaceClient, error) {
config := databricks.Config{
// Generic
Host: w.Host,
Expand All@@ -49,5 +48,5 @@ func (w *Workspace) Client() *workspaces.WorkspacesClient {
AzureLoginAppID: w.AzureLoginAppID,
}

return workspaces.New(&config)
return databricks.NewWorkspaceClient(&config)
}
6 changes: 3 additions & 3 deletions cmd/api/api.go
Original file line numberDiff line numberDiff line change
Expand Up@@ -8,8 +8,8 @@ import (
"strings"

"github.com/databricks/bricks/cmd/root"
"github.com/databricks/databricks-sdk-go/databricks"
"github.com/databricks/databricks-sdk-go/databricks/client"
"github.com/databricks/databricks-sdk-go/client"
"github.com/databricks/databricks-sdk-go/config"
"github.com/spf13/cobra"
)

Expand DownExpand Up@@ -52,7 +52,7 @@ func makeCommand(method string) *cobra.Command {
return err
}

api, err := client.New(&databricks.Config{})
api, err := client.New(&config.Config{})
if err != nil {
return err
}
Expand Down
17 changes: 9 additions & 8 deletions cmd/sync/watchdog.go
Original file line numberDiff line numberDiff line change
Expand Up@@ -5,6 +5,7 @@ import (
"fmt"
"io"
"log"
"net/http"
"os"
"path"
"path/filepath"
Expand All@@ -13,10 +14,10 @@ import (
"time"

"github.com/databricks/bricks/project"
"github.com/databricks/databricks-sdk-go/databricks/apierr"
"github.com/databricks/databricks-sdk-go/databricks/client"
"github.com/databricks/databricks-sdk-go"
"github.com/databricks/databricks-sdk-go/apierr"
"github.com/databricks/databricks-sdk-go/client"
"github.com/databricks/databricks-sdk-go/service/workspace"
"github.com/databricks/databricks-sdk-go/workspaces"
"golang.org/x/sync/errgroup"
)

Expand DownExpand Up@@ -57,12 +58,12 @@ func putFile(ctx context.Context, path string, content io.Reader) error {
apiPath := fmt.Sprintf(
"/api/2.0/workspace-files/import-file/%s?overwrite=true",
strings.TrimLeft(path, "/"))
return apiClient.Post(ctx, apiPath, content, nil)
return apiClient.Do(ctx, http.MethodPost, apiPath, content, nil)
}

// path: The remote path of the file in the workspace
func deleteFile(ctx context.Context, path string, wsc *workspaces.WorkspacesClient) error {
err := wsc.Workspace.Delete(ctx,
func deleteFile(ctx context.Context, path string, w *databricks.WorkspaceClient) error {
err := w.Workspace.Delete(ctx,
workspace.Delete{
Path: path,
Recursive: true,
Expand All@@ -78,7 +79,7 @@ func deleteFile(ctx context.Context, path string, wsc *workspaces.WorkspacesClie
return err
}

func getRemoteSyncCallback(ctx context.Context, root, remoteDir string, wsc *workspaces.WorkspacesClient) func(localDiff diff) error {
func getRemoteSyncCallback(ctx context.Context, root, remoteDir string, w *databricks.WorkspaceClient) func(localDiff diff) error {
return func(d diff) error {

// Abstraction over wait groups which allows you to get the errors
Expand All@@ -95,7 +96,7 @@ func getRemoteSyncCallback(ctx context.Context, root, remoteDir string, wsc *wor
// is evaluated
remoteNameCopy := remoteName
g.Go(func() error {
err := deleteFile(ctx, path.Join(remoteDir, remoteNameCopy), wsc)
err := deleteFile(ctx, path.Join(remoteDir, remoteNameCopy), w)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion ext/databricks-sdk-go
Submodule databricks-sdk-go updated 188 files
8 changes: 4 additions & 4 deletions git/git.go
Original file line numberDiff line numberDiff line change
Expand Up@@ -9,8 +9,8 @@ import (
"strings"

"github.com/databricks/bricks/folders"
"github.com/databricks/bricks/utilities"
"github.com/databricks/databricks-sdk-go/workspaces"
"github.com/databricks/databricks-sdk-go"
"github.com/databricks/databricks-sdk-go/service/repos"
giturls "github.com/whilp/git-urls"
"gopkg.in/ini.v1"
)
Expand DownExpand Up@@ -82,8 +82,8 @@ func RepositoryName() (string, error) {
return strings.TrimSuffix(base, ".git"), nil
}

func RepoExists(remotePath string, ctx context.Context, wsc *workspaces.WorkspacesClient) (bool, error) {
repos, err := utilities.GetAllRepos(ctx, wsc, remotePath)
func RepoExists(remotePath string, ctx context.Context, w *databricks.WorkspaceClient) (bool, error) {
repos, err := w.Repos.ListAll(ctx, repos.ListRequest{})
if err != nil {
return false, fmt.Errorf("could not get repos: %s", err)
}
Expand Down
54 changes: 27 additions & 27 deletions internal/sync_test.go
Original file line numberDiff line numberDiff line change
Expand Up@@ -15,9 +15,9 @@ import (

"github.com/databricks/bricks/cmd/sync"
"github.com/databricks/bricks/folders"
"github.com/databricks/databricks-sdk-go"
"github.com/databricks/databricks-sdk-go/service/repos"
"github.com/databricks/databricks-sdk-go/service/workspace"
"github.com/databricks/databricks-sdk-go/workspaces"
"github.com/stretchr/testify/assert"
)

Expand All@@ -39,7 +39,7 @@ func TestAccFullSync(t *testing.T) {
t.Log("bricks repo location: : ", bricksRepo)
assert.Equal(t, "bricks", filepath.Base(bricksRepo))

wsc := workspaces.New()
wsc := databricks.Must(databricks.NewWorkspaceClient())
ctx := context.Background()
me, err := wsc.CurrentUser.Me(ctx)
assert.NoError(t, err)
Expand DownExpand Up@@ -104,18 +104,18 @@ func TestAccFullSync(t *testing.T) {

// First upload assertion
assert.Eventually(t, func() bool {
repoContent, err := wsc.Workspace.List(ctx, workspace.ListRequest{
objects, err := wsc.Workspace.ListAll(ctx, workspace.ListRequest{
Path: repoPath,
})
assert.NoError(t, err)
return len(repoContent.Objects) == 3
return len(objects) == 3
}, 30*time.Second, 5*time.Second)
repoContent, err := wsc.Workspace.List(ctx, workspace.ListRequest{
objects, err := wsc.Workspace.ListAll(ctx, workspace.ListRequest{
Path: repoPath,
})
assert.NoError(t, err)
var files1 []string
for _, v := range repoContent.Objects {
for _, v := range objects {
files1 = append(files1, filepath.Base(v.Path))
}
assert.Len(t, files1, 3)
Expand All@@ -127,18 +127,18 @@ func TestAccFullSync(t *testing.T) {
os.Create(filepath.Join(projectDir, "hello.txt"))
os.Create(filepath.Join(projectDir, "world.txt"))
assert.Eventually(t, func() bool {
repoContent, err := wsc.Workspace.List(ctx, workspace.ListRequest{
objects, err := wsc.Workspace.ListAll(ctx, workspace.ListRequest{
Path: repoPath,
})
assert.NoError(t, err)
return len(repoContent.Objects) == 5
return len(objects) == 5
}, 30*time.Second, 5*time.Second)
repoContent, err = wsc.Workspace.List(ctx, workspace.ListRequest{
objects, err = wsc.Workspace.ListAll(ctx, workspace.ListRequest{
Path: repoPath,
})
assert.NoError(t, err)
var files2 []string
for _, v := range repoContent.Objects {
for _, v := range objects {
files2 = append(files2, filepath.Base(v.Path))
}
assert.Len(t, files2, 5)
Expand All@@ -151,18 +151,18 @@ func TestAccFullSync(t *testing.T) {
// delete a file and assert
os.Remove(filepath.Join(projectDir, "hello.txt"))
assert.Eventually(t, func() bool {
repoContent, err := wsc.Workspace.List(ctx, workspace.ListRequest{
objects, err := wsc.Workspace.ListAll(ctx, workspace.ListRequest{
Path: repoPath,
})
assert.NoError(t, err)
return len(repoContent.Objects) == 4
return len(objects) == 4
}, 30*time.Second, 5*time.Second)
repoContent, err = wsc.Workspace.List(ctx, workspace.ListRequest{
objects, err = wsc.Workspace.ListAll(ctx, workspace.ListRequest{
Path: repoPath,
})
assert.NoError(t, err)
var files3 []string
for _, v := range repoContent.Objects {
for _, v := range objects {
files3 = append(files3, filepath.Base(v.Path))
}
assert.Len(t, files3, 4)
Expand DownExpand Up@@ -211,7 +211,7 @@ func TestAccIncrementalSync(t *testing.T) {
t.Log("bricks repo location: : ", bricksRepo)
assert.Equal(t, "bricks", filepath.Base(bricksRepo))

wsc := workspaces.New()
wsc := databricks.Must(databricks.NewWorkspaceClient())
ctx := context.Background()
me, err := wsc.CurrentUser.Me(ctx)
assert.NoError(t, err)
Expand DownExpand Up@@ -281,18 +281,18 @@ func TestAccIncrementalSync(t *testing.T) {

// First upload assertion
assert.Eventually(t, func() bool {
repoContent, err := wsc.Workspace.List(ctx, workspace.ListRequest{
objects, err := wsc.Workspace.ListAll(ctx, workspace.ListRequest{
Path: repoPath,
})
assert.NoError(t, err)
return len(repoContent.Objects) == 2
return len(objects) == 2
}, 30*time.Second, 5*time.Second)
repoContent, err := wsc.Workspace.List(ctx, workspace.ListRequest{
objects, err := wsc.Workspace.ListAll(ctx, workspace.ListRequest{
Path: repoPath,
})
assert.NoError(t, err)
var files1 []string
for _, v := range repoContent.Objects {
for _, v := range objects {
files1 = append(files1, filepath.Base(v.Path))
}
assert.Len(t, files1, 2)
Expand All@@ -307,18 +307,18 @@ func TestAccIncrementalSync(t *testing.T) {

// new file upload assertion
assert.Eventually(t, func() bool {
repoContent, err := wsc.Workspace.List(ctx, workspace.ListRequest{
objects, err := wsc.Workspace.ListAll(ctx, workspace.ListRequest{
Path: repoPath,
})
assert.NoError(t, err)
return len(repoContent.Objects) == 3
return len(objects) == 3
}, 30*time.Second, 5*time.Second)
repoContent, err = wsc.Workspace.List(ctx, workspace.ListRequest{
objects, err = wsc.Workspace.ListAll(ctx, workspace.ListRequest{
Path: repoPath,
})
assert.NoError(t, err)
var files2 []string
for _, v := range repoContent.Objects {
for _, v := range objects {
files2 = append(files2, filepath.Base(v.Path))
}
assert.Len(t, files2, 3)
Expand All@@ -330,18 +330,18 @@ func TestAccIncrementalSync(t *testing.T) {
// delete a file and assert
os.Remove(filepath.Join(projectDir, ".gitkeep"))
assert.Eventually(t, func() bool {
repoContent, err := wsc.Workspace.List(ctx, workspace.ListRequest{
objects, err := wsc.Workspace.ListAll(ctx, workspace.ListRequest{
Path: repoPath,
})
assert.NoError(t, err)
return len(repoContent.Objects) == 2
return len(objects) == 2
}, 30*time.Second, 5*time.Second)
repoContent, err = wsc.Workspace.List(ctx, workspace.ListRequest{
objects, err = wsc.Workspace.ListAll(ctx, workspace.ListRequest{
Path: repoPath,
})
assert.NoError(t, err)
var files3 []string
for _, v := range repoContent.Objects {
for _, v := range objects {
files3 = append(files3, filepath.Base(v.Path))
}
assert.Len(t, files3, 2)
Expand Down
26 changes: 8 additions & 18 deletions project/project.go
Original file line numberDiff line numberDiff line change
Expand Up@@ -8,11 +8,9 @@ import (
"sync"

"github.com/databricks/bricks/git"
"github.com/databricks/databricks-sdk-go/databricks"
"github.com/databricks/databricks-sdk-go/service/clusters"
"github.com/databricks/databricks-sdk-go"
"github.com/databricks/databricks-sdk-go/service/commands"
"github.com/databricks/databricks-sdk-go/service/scim"
"github.com/databricks/databricks-sdk-go/workspaces"
"github.com/spf13/cobra"
)

Expand All@@ -26,7 +24,7 @@ type project struct {

config *Config
environment *Environment
wsc *workspaces.WorkspacesClient
wsc *databricks.WorkspaceClient
me *scim.User
fileSet *git.FileSet
}
Expand DownExpand Up@@ -96,7 +94,7 @@ func (p *project) initializeWorkspacesClient(ctx context.Context) {
config.Profile = p.environment.Workspace.Profile
}

p.wsc = workspaces.New(&config)
p.wsc = databricks.Must(databricks.NewWorkspaceClient(&config))
}

// Get returns the project as configured on the context.
Expand All@@ -110,7 +108,7 @@ func Get(ctx context.Context) *project {
}

// Make sure to initialize the workspaces client on project init
func (p *project) WorkspacesClient() *workspaces.WorkspacesClient {
func (p *project) WorkspacesClient() *databricks.WorkspaceClient {
return p.wsc
}

Expand DownExpand Up@@ -183,22 +181,14 @@ func (p *project) DeploymentIsolationPrefix() string {
}

func getClusterIdFromClusterName(ctx context.Context,
wsc *workspaces.WorkspacesClient,
wsc *databricks.WorkspaceClient,
clusterName string,
) (clusterId string, err error) {
clusterId = ""
clustersList, err := wsc.Clusters.List(ctx, clusters.ListRequest{})
clusterInfo, err := wsc.Clusters.GetClusterInfoByClusterName(ctx, clusterName)
if err != nil {
return
}
for _, cluster := range clustersList.Clusters {
if cluster.ClusterName == clusterName {
clusterId = cluster.ClusterId
return
}
return "", err
}
err = fmt.Errorf("could not find cluster with name: %s", clusterName)
return
return clusterInfo.ClusterId, nil
}

// Old version of getting development cluster details with isolation implemented.
Expand Down
Loading