2022-11-18 09:57:31 +00:00
|
|
|
package resources
|
|
|
|
|
2023-09-04 09:55:01 +00:00
|
|
|
import (
|
2024-02-14 18:04:45 +00:00
|
|
|
"context"
|
2024-10-18 06:45:47 +00:00
|
|
|
"fmt"
|
|
|
|
"net/url"
|
2023-09-21 19:21:20 +00:00
|
|
|
|
2024-02-14 18:04:45 +00:00
|
|
|
"github.com/databricks/cli/libs/log"
|
|
|
|
"github.com/databricks/databricks-sdk-go"
|
2023-10-16 06:56:06 +00:00
|
|
|
"github.com/databricks/databricks-sdk-go/marshal"
|
2023-09-04 09:55:01 +00:00
|
|
|
"github.com/databricks/databricks-sdk-go/service/pipelines"
|
|
|
|
)
|
2022-11-18 10:12:24 +00:00
|
|
|
|
2022-11-18 09:57:31 +00:00
|
|
|
type Pipeline struct {
|
2024-01-25 11:32:47 +00:00
|
|
|
ID string `json:"id,omitempty" bundle:"readonly"`
|
|
|
|
Permissions []Permission `json:"permissions,omitempty"`
|
|
|
|
ModifiedStatus ModifiedStatus `json:"modified_status,omitempty" bundle:"internal"`
|
2024-10-18 06:45:47 +00:00
|
|
|
URL string `json:"url,omitempty" bundle:"internal"`
|
2022-11-18 10:12:24 +00:00
|
|
|
|
|
|
|
*pipelines.PipelineSpec
|
2022-11-18 09:57:31 +00:00
|
|
|
}
|
2023-09-21 19:21:20 +00:00
|
|
|
|
2023-10-16 06:56:06 +00:00
|
|
|
func (s *Pipeline) UnmarshalJSON(b []byte) error {
|
|
|
|
return marshal.Unmarshal(b, s)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s Pipeline) MarshalJSON() ([]byte, error) {
|
|
|
|
return marshal.Marshal(s)
|
|
|
|
}
|
|
|
|
|
2024-02-14 18:04:45 +00:00
|
|
|
func (p *Pipeline) Exists(ctx context.Context, w *databricks.WorkspaceClient, id string) (bool, error) {
|
|
|
|
_, err := w.Pipelines.Get(ctx, pipelines.GetPipelineRequest{
|
|
|
|
PipelineId: id,
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
log.Debugf(ctx, "pipeline %s does not exist", id)
|
|
|
|
return false, err
|
|
|
|
}
|
|
|
|
return true, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p *Pipeline) TerraformResourceName() string {
|
|
|
|
return "databricks_pipeline"
|
|
|
|
}
|
2024-10-18 06:45:47 +00:00
|
|
|
|
|
|
|
func (p *Pipeline) InitializeURL(baseURL url.URL) {
|
|
|
|
if p.ID == "" {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
baseURL.Path = fmt.Sprintf("pipelines/%s", p.ID)
|
|
|
|
p.URL = baseURL.String()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p *Pipeline) GetName() string {
|
|
|
|
return p.Name
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *Pipeline) GetURL() string {
|
|
|
|
return s.URL
|
|
|
|
}
|
2024-11-28 12:27:24 +00:00
|
|
|
|
|
|
|
func (s *Pipeline) IsNil() bool {
|
|
|
|
return s.PipelineSpec == nil
|
|
|
|
}
|