Skip to content

Add workspace import_dir command to the CLI#418

Closed
shreyas-goenka wants to merge 31 commits intomainfrom
import_dir
Closed

Add workspace import_dir command to the CLI#418
shreyas-goenka wants to merge 31 commits intomainfrom
import_dir

Conversation

@shreyas-goenka
Copy link
Copy Markdown
Contributor

@shreyas-goenka shreyas-goenka commented Jun 1, 2023

TODO: add integration tests for functionality and progress events

@shreyas-goenka
Copy link
Copy Markdown
Contributor Author

outputs:

shreyas.goenka@THW32HFW6T vandaley-industries % cli workspace import_dir . /Users/shreyas.goenka@databricks.com/new-vandaley
Import started
Error: Request failed for POST /Users/shreyas.goenka@databricks.com/new-vandaley/exported/foo/c.py: Path (/Users/shreyas.goenka@databricks.com/new-vandaley/exported/foo/c) already exists.
shreyas.goenka@THW32HFW6T vandaley-industries % cli workspace import_dir . /Users/shreyas.goenka@databricks.com/new-vandaley --overwrite
Import started
Uploaded foo/c.py -> /Users/shreyas.goenka@databricks.com/new-vandaley/foo/c
Uploaded foo/b.py -> /Users/shreyas.goenka@databricks.com/new-vandaley/foo/b
Uploaded exported/foo/b.py -> /Users/shreyas.goenka@databricks.com/new-vandaley/exported/foo/b
Uploaded exported/foo/c.py -> /Users/shreyas.goenka@databricks.com/new-vandaley/exported/foo/c
Uploaded myDir/b.txt -> /Users/shreyas.goenka@databricks.com/new-vandaley/myDir/b.txt
Uploaded exported/my-notebook.py.py -> /Users/shreyas.goenka@databricks.com/new-vandaley/exported/my-notebook.py
Uploaded .gitignore -> /Users/shreyas.goenka@databricks.com/new-vandaley/.gitignore
Uploaded myDir/a.txt -> /Users/shreyas.goenka@databricks.com/new-vandaley/myDir/a.txt
Import completed
shreyas.goenka@THW32HFW6T vandaley-industries % cli workspace import_dir . /Users/shreyas.goenka@databricks.com/new-vandaley --overwrite --output json
{
  "source_path":".",
  "target_path":"/Users/shreyas.goenka@databricks.com/new-vandaley",
  "type":"IMPORT_STARTED"
}
{
  "source_path":"foo/b.py",
  "target_path":"/Users/shreyas.goenka@databricks.com/new-vandaley/foo/b",
  "type":"UPLOAD_COMPLETE"
}
{
  "source_path":"exported/my-notebook.py.py",
  "target_path":"/Users/shreyas.goenka@databricks.com/new-vandaley/exported/my-notebook.py",
  "type":"UPLOAD_COMPLETE"
}
{
  "source_path":"exported/foo/c.py",
  "target_path":"/Users/shreyas.goenka@databricks.com/new-vandaley/exported/foo/c",
  "type":"UPLOAD_COMPLETE"
}
{
  "source_path":"exported/foo/b.py",
  "target_path":"/Users/shreyas.goenka@databricks.com/new-vandaley/exported/foo/b",
  "type":"UPLOAD_COMPLETE"
}
{
  "source_path":"myDir/b.txt",
  "target_path":"/Users/shreyas.goenka@databricks.com/new-vandaley/myDir/b.txt",
  "type":"UPLOAD_COMPLETE"
}
{
  "source_path":"sync-snapshots/0bf79f861fa32456.json",
  "target_path":"/Users/shreyas.goenka@databricks.com/new-vandaley/sync-snapshots/0bf79f861fa32456.json",
  "type":"UPLOAD_COMPLETE"
}
{
  "source_path":".gitignore",
  "target_path":"/Users/shreyas.goenka@databricks.com/new-vandaley/.gitignore",
  "type":"UPLOAD_COMPLETE"
}
{
  "source_path":"foo/c.py",
  "target_path":"/Users/shreyas.goenka@databricks.com/new-vandaley/foo/c",
  "type":"UPLOAD_COMPLETE"
}
{
  "source_path":"myDir/a.txt",
  "target_path":"/Users/shreyas.goenka@databricks.com/new-vandaley/myDir/a.txt",
  "type":"UPLOAD_COMPLETE"
}
{
  "type":"IMPORT_COMPLETE"
}


// Initialize error wait group, and spawn the progress event emitter inside
// the error wait group
group, ctx := errgroup.WithContext(ctx)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the behavior of the returned context?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The returned context is cancelled if there's an error in any of the subroutines. see: https://pkg.go.dev/golang.org/x/sync/errgroup#WithContext

if err != nil {
return err
}
_, err = w.Write([]byte("\n"))
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you split this into a separate PR? Might affect other functionality.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in this PR: #443

return "", fmt.Errorf("could not find remote path for %s", localPath)
}
return s.repoFiles.RemotePath(relativePath)
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a comment here why this is a public function? Also this needs a mutex because the snapshot code is accessing it from a separate goroutine.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A better approach is to include the remote name in the events, then you don't need this function or the mutex.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, having this in the events is then you have to use reflection to read the remote name values, which is OK maybe

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The type switch is there already right?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah right, using type assertions should be enough here

@shreyas-goenka
Copy link
Copy Markdown
Contributor Author

Closing because we decided to move forward with just a simple walk dir

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants