databricks-cli/cmd/workspace/metastores/metastores.go

560 lines
17 KiB
Go
Executable File

// Code generated from OpenAPI specs by Databricks SDK Generator. DO NOT EDIT.
package metastores
import (
"fmt"
"github.com/databricks/cli/cmd/root"
"github.com/databricks/cli/libs/cmdio"
"github.com/databricks/cli/libs/flags"
"github.com/databricks/databricks-sdk-go/service/catalog"
"github.com/spf13/cobra"
)
var Cmd = &cobra.Command{
Use: "metastores",
Short: `A metastore is the top-level container of objects in Unity Catalog.`,
Long: `A metastore is the top-level container of objects in Unity Catalog. It stores
data assets (tables and views) and the permissions that govern access to them.
Databricks account admins can create metastores and assign them to Databricks
workspaces to control which workloads use each metastore. For a workspace to
use Unity Catalog, it must have a Unity Catalog metastore attached.
Each metastore is configured with a root storage location in a cloud storage
account. This storage location is used for metadata and managed tables data.
NOTE: This metastore is distinct from the metastore included in Databricks
workspaces created before Unity Catalog was released. If your workspace
includes a legacy Hive metastore, the data in that metastore is available in a
catalog named hive_metastore.`,
Annotations: map[string]string{
"package": "catalog",
},
}
// start assign command
var assignReq catalog.CreateMetastoreAssignment
func init() {
Cmd.AddCommand(assignCmd)
// TODO: short flags
}
var assignCmd = &cobra.Command{
Use: "assign METASTORE_ID DEFAULT_CATALOG_NAME WORKSPACE_ID",
Short: `Create an assignment.`,
Long: `Create an assignment.
Creates a new metastore assignment. If an assignment for the same
__workspace_id__ exists, it will be overwritten by the new __metastore_id__
and __default_catalog_name__. The caller must be an account admin.`,
Annotations: map[string]string{},
Args: func(cmd *cobra.Command, args []string) error {
check := cobra.ExactArgs(3)
return check(cmd, args)
},
PreRunE: root.MustWorkspaceClient,
RunE: func(cmd *cobra.Command, args []string) (err error) {
ctx := cmd.Context()
w := root.WorkspaceClient(ctx)
assignReq.MetastoreId = args[0]
assignReq.DefaultCatalogName = args[1]
_, err = fmt.Sscan(args[2], &assignReq.WorkspaceId)
if err != nil {
return fmt.Errorf("invalid WORKSPACE_ID: %s", args[2])
}
err = w.Metastores.Assign(ctx, assignReq)
if err != nil {
return err
}
return nil
},
// Disable completions since they are not applicable.
// Can be overridden by manual implementation in `override.go`.
ValidArgsFunction: cobra.NoFileCompletions,
}
// start create command
var createReq catalog.CreateMetastore
var createJson flags.JsonFlag
func init() {
Cmd.AddCommand(createCmd)
// TODO: short flags
createCmd.Flags().Var(&createJson, "json", `either inline JSON string or @path/to/file.json with request body`)
createCmd.Flags().StringVar(&createReq.Region, "region", createReq.Region, `Cloud region which the metastore serves (e.g., us-west-2, westus).`)
}
var createCmd = &cobra.Command{
Use: "create NAME STORAGE_ROOT",
Short: `Create a metastore.`,
Long: `Create a metastore.
Creates a new metastore based on a provided name and storage root path.`,
Annotations: map[string]string{},
Args: func(cmd *cobra.Command, args []string) error {
check := cobra.ExactArgs(2)
if cmd.Flags().Changed("json") {
check = cobra.ExactArgs(0)
}
return check(cmd, args)
},
PreRunE: root.MustWorkspaceClient,
RunE: func(cmd *cobra.Command, args []string) (err error) {
ctx := cmd.Context()
w := root.WorkspaceClient(ctx)
if cmd.Flags().Changed("json") {
err = createJson.Unmarshal(&createReq)
if err != nil {
return err
}
} else {
createReq.Name = args[0]
createReq.StorageRoot = args[1]
}
response, err := w.Metastores.Create(ctx, createReq)
if err != nil {
return err
}
return cmdio.Render(ctx, response)
},
// Disable completions since they are not applicable.
// Can be overridden by manual implementation in `override.go`.
ValidArgsFunction: cobra.NoFileCompletions,
}
// start current command
func init() {
Cmd.AddCommand(currentCmd)
}
var currentCmd = &cobra.Command{
Use: "current",
Short: `Get metastore assignment for workspace.`,
Long: `Get metastore assignment for workspace.
Gets the metastore assignment for the workspace being accessed.`,
Annotations: map[string]string{},
PreRunE: root.MustWorkspaceClient,
RunE: func(cmd *cobra.Command, args []string) (err error) {
ctx := cmd.Context()
w := root.WorkspaceClient(ctx)
response, err := w.Metastores.Current(ctx)
if err != nil {
return err
}
return cmdio.Render(ctx, response)
},
// Disable completions since they are not applicable.
// Can be overridden by manual implementation in `override.go`.
ValidArgsFunction: cobra.NoFileCompletions,
}
// start delete command
var deleteReq catalog.DeleteMetastoreRequest
func init() {
Cmd.AddCommand(deleteCmd)
// TODO: short flags
deleteCmd.Flags().BoolVar(&deleteReq.Force, "force", deleteReq.Force, `Force deletion even if the metastore is not empty.`)
}
var deleteCmd = &cobra.Command{
Use: "delete ID",
Short: `Delete a metastore.`,
Long: `Delete a metastore.
Deletes a metastore. The caller must be a metastore admin.`,
Annotations: map[string]string{},
PreRunE: root.MustWorkspaceClient,
RunE: func(cmd *cobra.Command, args []string) (err error) {
ctx := cmd.Context()
w := root.WorkspaceClient(ctx)
if len(args) == 0 {
promptSpinner := cmdio.Spinner(ctx)
promptSpinner <- "No ID argument specified. Loading names for Metastores drop-down."
names, err := w.Metastores.MetastoreInfoNameToMetastoreIdMap(ctx)
close(promptSpinner)
if err != nil {
return fmt.Errorf("failed to load names for Metastores drop-down. Please manually specify required arguments. Original error: %w", err)
}
id, err := cmdio.Select(ctx, names, "Unique ID of the metastore")
if err != nil {
return err
}
args = append(args, id)
}
if len(args) != 1 {
return fmt.Errorf("expected to have unique id of the metastore")
}
deleteReq.Id = args[0]
err = w.Metastores.Delete(ctx, deleteReq)
if err != nil {
return err
}
return nil
},
// Disable completions since they are not applicable.
// Can be overridden by manual implementation in `override.go`.
ValidArgsFunction: cobra.NoFileCompletions,
}
// start enable-optimization command
var enableOptimizationReq catalog.UpdatePredictiveOptimization
var enableOptimizationJson flags.JsonFlag
func init() {
Cmd.AddCommand(enableOptimizationCmd)
// TODO: short flags
enableOptimizationCmd.Flags().Var(&enableOptimizationJson, "json", `either inline JSON string or @path/to/file.json with request body`)
}
var enableOptimizationCmd = &cobra.Command{
Use: "enable-optimization METASTORE_ID ENABLE",
Short: `Toggle predictive optimization on the metastore.`,
Long: `Toggle predictive optimization on the metastore.
Enables or disables predictive optimization on the metastore.`,
// This command is being previewed; hide from help output.
Hidden: true,
Annotations: map[string]string{},
Args: func(cmd *cobra.Command, args []string) error {
check := cobra.ExactArgs(2)
if cmd.Flags().Changed("json") {
check = cobra.ExactArgs(0)
}
return check(cmd, args)
},
PreRunE: root.MustWorkspaceClient,
RunE: func(cmd *cobra.Command, args []string) (err error) {
ctx := cmd.Context()
w := root.WorkspaceClient(ctx)
if cmd.Flags().Changed("json") {
err = enableOptimizationJson.Unmarshal(&enableOptimizationReq)
if err != nil {
return err
}
} else {
enableOptimizationReq.MetastoreId = args[0]
_, err = fmt.Sscan(args[1], &enableOptimizationReq.Enable)
if err != nil {
return fmt.Errorf("invalid ENABLE: %s", args[1])
}
}
response, err := w.Metastores.EnableOptimization(ctx, enableOptimizationReq)
if err != nil {
return err
}
return cmdio.Render(ctx, response)
},
// Disable completions since they are not applicable.
// Can be overridden by manual implementation in `override.go`.
ValidArgsFunction: cobra.NoFileCompletions,
}
// start get command
var getReq catalog.GetMetastoreRequest
func init() {
Cmd.AddCommand(getCmd)
// TODO: short flags
}
var getCmd = &cobra.Command{
Use: "get ID",
Short: `Get a metastore.`,
Long: `Get a metastore.
Gets a metastore that matches the supplied ID. The caller must be a metastore
admin to retrieve this info.`,
Annotations: map[string]string{},
PreRunE: root.MustWorkspaceClient,
RunE: func(cmd *cobra.Command, args []string) (err error) {
ctx := cmd.Context()
w := root.WorkspaceClient(ctx)
if len(args) == 0 {
promptSpinner := cmdio.Spinner(ctx)
promptSpinner <- "No ID argument specified. Loading names for Metastores drop-down."
names, err := w.Metastores.MetastoreInfoNameToMetastoreIdMap(ctx)
close(promptSpinner)
if err != nil {
return fmt.Errorf("failed to load names for Metastores drop-down. Please manually specify required arguments. Original error: %w", err)
}
id, err := cmdio.Select(ctx, names, "Unique ID of the metastore")
if err != nil {
return err
}
args = append(args, id)
}
if len(args) != 1 {
return fmt.Errorf("expected to have unique id of the metastore")
}
getReq.Id = args[0]
response, err := w.Metastores.Get(ctx, getReq)
if err != nil {
return err
}
return cmdio.Render(ctx, response)
},
// Disable completions since they are not applicable.
// Can be overridden by manual implementation in `override.go`.
ValidArgsFunction: cobra.NoFileCompletions,
}
// start list command
func init() {
Cmd.AddCommand(listCmd)
}
var listCmd = &cobra.Command{
Use: "list",
Short: `List metastores.`,
Long: `List metastores.
Gets an array of the available metastores (as __MetastoreInfo__ objects). The
caller must be an admin to retrieve this info. There is no guarantee of a
specific ordering of the elements in the array.`,
Annotations: map[string]string{},
PreRunE: root.MustWorkspaceClient,
RunE: func(cmd *cobra.Command, args []string) (err error) {
ctx := cmd.Context()
w := root.WorkspaceClient(ctx)
response, err := w.Metastores.ListAll(ctx)
if err != nil {
return err
}
return cmdio.Render(ctx, response)
},
// Disable completions since they are not applicable.
// Can be overridden by manual implementation in `override.go`.
ValidArgsFunction: cobra.NoFileCompletions,
}
// start summary command
func init() {
Cmd.AddCommand(summaryCmd)
}
var summaryCmd = &cobra.Command{
Use: "summary",
Short: `Get a metastore summary.`,
Long: `Get a metastore summary.
Gets information about a metastore. This summary includes the storage
credential, the cloud vendor, the cloud region, and the global metastore ID.`,
Annotations: map[string]string{},
PreRunE: root.MustWorkspaceClient,
RunE: func(cmd *cobra.Command, args []string) (err error) {
ctx := cmd.Context()
w := root.WorkspaceClient(ctx)
response, err := w.Metastores.Summary(ctx)
if err != nil {
return err
}
return cmdio.Render(ctx, response)
},
// Disable completions since they are not applicable.
// Can be overridden by manual implementation in `override.go`.
ValidArgsFunction: cobra.NoFileCompletions,
}
// start unassign command
var unassignReq catalog.UnassignRequest
func init() {
Cmd.AddCommand(unassignCmd)
// TODO: short flags
}
var unassignCmd = &cobra.Command{
Use: "unassign WORKSPACE_ID METASTORE_ID",
Short: `Delete an assignment.`,
Long: `Delete an assignment.
Deletes a metastore assignment. The caller must be an account administrator.`,
Annotations: map[string]string{},
Args: func(cmd *cobra.Command, args []string) error {
check := cobra.ExactArgs(2)
return check(cmd, args)
},
PreRunE: root.MustWorkspaceClient,
RunE: func(cmd *cobra.Command, args []string) (err error) {
ctx := cmd.Context()
w := root.WorkspaceClient(ctx)
_, err = fmt.Sscan(args[0], &unassignReq.WorkspaceId)
if err != nil {
return fmt.Errorf("invalid WORKSPACE_ID: %s", args[0])
}
unassignReq.MetastoreId = args[1]
err = w.Metastores.Unassign(ctx, unassignReq)
if err != nil {
return err
}
return nil
},
// Disable completions since they are not applicable.
// Can be overridden by manual implementation in `override.go`.
ValidArgsFunction: cobra.NoFileCompletions,
}
// start update command
var updateReq catalog.UpdateMetastore
func init() {
Cmd.AddCommand(updateCmd)
// TODO: short flags
updateCmd.Flags().StringVar(&updateReq.DeltaSharingOrganizationName, "delta-sharing-organization-name", updateReq.DeltaSharingOrganizationName, `The organization name of a Delta Sharing entity, to be used in Databricks-to-Databricks Delta Sharing as the official name.`)
updateCmd.Flags().Int64Var(&updateReq.DeltaSharingRecipientTokenLifetimeInSeconds, "delta-sharing-recipient-token-lifetime-in-seconds", updateReq.DeltaSharingRecipientTokenLifetimeInSeconds, `The lifetime of delta sharing recipient token in seconds.`)
updateCmd.Flags().Var(&updateReq.DeltaSharingScope, "delta-sharing-scope", `The scope of Delta Sharing enabled for the metastore.`)
updateCmd.Flags().StringVar(&updateReq.Name, "name", updateReq.Name, `The user-specified name of the metastore.`)
updateCmd.Flags().StringVar(&updateReq.Owner, "owner", updateReq.Owner, `The owner of the metastore.`)
updateCmd.Flags().StringVar(&updateReq.PrivilegeModelVersion, "privilege-model-version", updateReq.PrivilegeModelVersion, `Privilege model version of the metastore, of the form major.minor (e.g., 1.0).`)
updateCmd.Flags().StringVar(&updateReq.StorageRootCredentialId, "storage-root-credential-id", updateReq.StorageRootCredentialId, `UUID of storage credential to access the metastore storage_root.`)
}
var updateCmd = &cobra.Command{
Use: "update ID",
Short: `Update a metastore.`,
Long: `Update a metastore.
Updates information for a specific metastore. The caller must be a metastore
admin.`,
Annotations: map[string]string{},
PreRunE: root.MustWorkspaceClient,
RunE: func(cmd *cobra.Command, args []string) (err error) {
ctx := cmd.Context()
w := root.WorkspaceClient(ctx)
if len(args) == 0 {
promptSpinner := cmdio.Spinner(ctx)
promptSpinner <- "No ID argument specified. Loading names for Metastores drop-down."
names, err := w.Metastores.MetastoreInfoNameToMetastoreIdMap(ctx)
close(promptSpinner)
if err != nil {
return fmt.Errorf("failed to load names for Metastores drop-down. Please manually specify required arguments. Original error: %w", err)
}
id, err := cmdio.Select(ctx, names, "Unique ID of the metastore")
if err != nil {
return err
}
args = append(args, id)
}
if len(args) != 1 {
return fmt.Errorf("expected to have unique id of the metastore")
}
updateReq.Id = args[0]
response, err := w.Metastores.Update(ctx, updateReq)
if err != nil {
return err
}
return cmdio.Render(ctx, response)
},
// Disable completions since they are not applicable.
// Can be overridden by manual implementation in `override.go`.
ValidArgsFunction: cobra.NoFileCompletions,
}
// start update-assignment command
var updateAssignmentReq catalog.UpdateMetastoreAssignment
func init() {
Cmd.AddCommand(updateAssignmentCmd)
// TODO: short flags
updateAssignmentCmd.Flags().StringVar(&updateAssignmentReq.DefaultCatalogName, "default-catalog-name", updateAssignmentReq.DefaultCatalogName, `The name of the default catalog for the metastore.`)
updateAssignmentCmd.Flags().StringVar(&updateAssignmentReq.MetastoreId, "metastore-id", updateAssignmentReq.MetastoreId, `The unique ID of the metastore.`)
}
var updateAssignmentCmd = &cobra.Command{
Use: "update-assignment WORKSPACE_ID",
Short: `Update an assignment.`,
Long: `Update an assignment.
Updates a metastore assignment. This operation can be used to update
__metastore_id__ or __default_catalog_name__ for a specified Workspace, if the
Workspace is already assigned a metastore. The caller must be an account admin
to update __metastore_id__; otherwise, the caller can be a Workspace admin.`,
Annotations: map[string]string{},
PreRunE: root.MustWorkspaceClient,
RunE: func(cmd *cobra.Command, args []string) (err error) {
ctx := cmd.Context()
w := root.WorkspaceClient(ctx)
if len(args) == 0 {
promptSpinner := cmdio.Spinner(ctx)
promptSpinner <- "No WORKSPACE_ID argument specified. Loading names for Metastores drop-down."
names, err := w.Metastores.MetastoreInfoNameToMetastoreIdMap(ctx)
close(promptSpinner)
if err != nil {
return fmt.Errorf("failed to load names for Metastores drop-down. Please manually specify required arguments. Original error: %w", err)
}
id, err := cmdio.Select(ctx, names, "A workspace ID")
if err != nil {
return err
}
args = append(args, id)
}
if len(args) != 1 {
return fmt.Errorf("expected to have a workspace id")
}
_, err = fmt.Sscan(args[0], &updateAssignmentReq.WorkspaceId)
if err != nil {
return fmt.Errorf("invalid WORKSPACE_ID: %s", args[0])
}
err = w.Metastores.UpdateAssignment(ctx, updateAssignmentReq)
if err != nil {
return err
}
return nil
},
// Disable completions since they are not applicable.
// Can be overridden by manual implementation in `override.go`.
ValidArgsFunction: cobra.NoFileCompletions,
}
// end service Metastores