2023-06-18 14:47:01 +00:00
|
|
|
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{}
|
|
|
|
|
2023-06-18 15:40:30 +00:00
|
|
|
const debugConcurrentRuns = 4
|
|
|
|
|
2023-06-18 14:47:01 +00:00
|
|
|
func ProcessEnvironmentMode() bundle.Mutator {
|
|
|
|
return &processEnvironmentMode{}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *processEnvironmentMode) Name() string {
|
|
|
|
return "ProcessEnvironmentMode"
|
|
|
|
}
|
|
|
|
|
|
|
|
// Mark all resources as being for 'debug' purposes, i.e.
|
|
|
|
// changing their their name, adding tags, and (in the future)
|
|
|
|
// marking them as 'hidden' in the UI.
|
|
|
|
func processDebugMode(b *bundle.Bundle) error {
|
|
|
|
r := b.Config.Resources
|
|
|
|
|
|
|
|
for i := range r.Jobs {
|
|
|
|
r.Jobs[i].Name = "[debug] " + r.Jobs[i].Name
|
|
|
|
if r.Jobs[i].Tags == nil {
|
|
|
|
r.Jobs[i].Tags = make(map[string]string)
|
|
|
|
}
|
|
|
|
r.Jobs[i].Tags["debug"] = ""
|
2023-06-18 15:40:30 +00:00
|
|
|
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"
|
|
|
|
}
|
2023-06-18 14:47:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for i := range r.Pipelines {
|
|
|
|
r.Pipelines[i].Name = "[debug] " + r.Pipelines[i].Name
|
|
|
|
r.Pipelines[i].Development = true
|
2023-06-18 15:40:30 +00:00
|
|
|
// (pipelines don't yet support tags)
|
2023-06-18 14:47:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for i := range r.Models {
|
|
|
|
r.Models[i].Name = "[debug] " + r.Models[i].Name
|
|
|
|
r.Models[i].Tags = append(r.Models[i].Tags, ml.ModelTag{Key: "debug", Value: ""})
|
|
|
|
}
|
|
|
|
|
|
|
|
for i := range r.Experiments {
|
|
|
|
r.Experiments[i].Name = "[debug] " + r.Experiments[i].Name
|
|
|
|
r.Experiments[i].Tags = append(r.Experiments[i].Tags, ml.ExperimentTag{Key: "debug", Value: ""})
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *processEnvironmentMode) Apply(ctx context.Context, b *bundle.Bundle) error {
|
|
|
|
switch b.Config.Bundle.Mode {
|
|
|
|
case config.Debug:
|
|
|
|
return processDebugMode(b)
|
|
|
|
case config.Default, "":
|
|
|
|
// No action
|
|
|
|
case config.PullRequest:
|
|
|
|
return fmt.Errorf("not implemented")
|
|
|
|
default:
|
|
|
|
return fmt.Errorf("unsupported value specified for 'mode': %s", b.Config.Bundle.Mode)
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|