databricks-cli/bundle/config/mutator/process_environment_mode.go

81 lines
2.0 KiB
Go
Raw Normal View History

package mutator
import (
"context"
"fmt"
"github.com/databricks/cli/bundle"
"github.com/databricks/cli/bundle/config"
"github.com/databricks/databricks-sdk-go/service/ml"
)
type processEnvironmentMode struct{}
const debugConcurrentRuns = 4
func ProcessEnvironmentMode() bundle.Mutator {
return &processEnvironmentMode{}
}
func (m *processEnvironmentMode) Name() string {
return "ProcessEnvironmentMode"
}
2023-07-03 14:30:42 +00:00
// Mark all resources as being for 'development' purposes, i.e.
// changing their their name, adding tags, and (in the future)
// marking them as 'hidden' in the UI.
2023-07-03 14:30:42 +00:00
func processDevelopmentMode(b *bundle.Bundle) error {
r := b.Config.Resources
for i := range r.Jobs {
2023-07-03 14:30:42 +00:00
r.Jobs[i].Name = "[dev] " + r.Jobs[i].Name
if r.Jobs[i].Tags == nil {
r.Jobs[i].Tags = make(map[string]string)
}
2023-07-03 14:30:42 +00:00
r.Jobs[i].Tags["dev"] = ""
if r.Jobs[i].MaxConcurrentRuns == 0 {
r.Jobs[i].MaxConcurrentRuns = debugConcurrentRuns
}
2023-06-20 09:21:33 +00:00
if r.Jobs[i].Schedule != nil {
r.Jobs[i].Schedule.PauseStatus = "PAUSED"
}
if r.Jobs[i].Continuous != nil {
r.Jobs[i].Continuous.PauseStatus = "PAUSED"
}
if r.Jobs[i].Trigger != nil {
r.Jobs[i].Trigger.PauseStatus = "PAUSED"
}
}
for i := range r.Pipelines {
2023-07-03 14:30:42 +00:00
r.Pipelines[i].Name = "[dev] " + r.Pipelines[i].Name
r.Pipelines[i].Development = true
// (pipelines don't yet support tags)
}
for i := range r.Models {
2023-07-03 14:30:42 +00:00
r.Models[i].Name = "[dev] " + r.Models[i].Name
r.Models[i].Tags = append(r.Models[i].Tags, ml.ModelTag{Key: "dev", Value: ""})
}
for i := range r.Experiments {
2023-07-03 14:30:42 +00:00
r.Experiments[i].Name = "[dev] " + r.Experiments[i].Name
r.Experiments[i].Tags = append(r.Experiments[i].Tags, ml.ExperimentTag{Key: "dev", Value: ""})
}
return nil
}
func (m *processEnvironmentMode) Apply(ctx context.Context, b *bundle.Bundle) error {
switch b.Config.Bundle.Mode {
2023-07-03 14:30:42 +00:00
case config.Development:
return processDevelopmentMode(b)
case "":
// No action
default:
return fmt.Errorf("unsupported value specified for 'mode': %s", b.Config.Bundle.Mode)
}
return nil
}