2022-11-18 09:57:31 +00:00
|
|
|
package resources
|
|
|
|
|
2023-08-14 06:43:45 +00:00
|
|
|
import (
|
2024-02-14 18:04:45 +00:00
|
|
|
"context"
|
2024-10-18 06:45:47 +00:00
|
|
|
"fmt"
|
|
|
|
"net/url"
|
2024-02-14 18:04:45 +00:00
|
|
|
"strconv"
|
|
|
|
|
|
|
|
"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-08-14 06:43:45 +00:00
|
|
|
"github.com/databricks/databricks-sdk-go/service/jobs"
|
|
|
|
)
|
2022-11-18 10:12:24 +00:00
|
|
|
|
2022-12-01 21:39:15 +00:00
|
|
|
type Job 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
|
|
|
|
|
|
|
*jobs.JobSettings
|
2022-11-18 09:57:31 +00:00
|
|
|
}
|
2023-08-14 06:43:45 +00:00
|
|
|
|
2023-10-16 06:56:06 +00:00
|
|
|
func (s *Job) UnmarshalJSON(b []byte) error {
|
|
|
|
return marshal.Unmarshal(b, s)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s Job) MarshalJSON() ([]byte, error) {
|
|
|
|
return marshal.Marshal(s)
|
|
|
|
}
|
|
|
|
|
2024-02-14 18:04:45 +00:00
|
|
|
func (j *Job) Exists(ctx context.Context, w *databricks.WorkspaceClient, id string) (bool, error) {
|
|
|
|
jobId, err := strconv.Atoi(id)
|
|
|
|
if err != nil {
|
|
|
|
return false, err
|
|
|
|
}
|
|
|
|
_, err = w.Jobs.Get(ctx, jobs.GetJobRequest{
|
|
|
|
JobId: int64(jobId),
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
log.Debugf(ctx, "job %s does not exist", id)
|
|
|
|
return false, err
|
|
|
|
}
|
|
|
|
return true, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (j *Job) TerraformResourceName() string {
|
|
|
|
return "databricks_job"
|
|
|
|
}
|
2024-10-18 06:45:47 +00:00
|
|
|
|
|
|
|
func (j *Job) InitializeURL(baseURL url.URL) {
|
|
|
|
if j.ID == "" {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
baseURL.Path = fmt.Sprintf("jobs/%s", j.ID)
|
|
|
|
j.URL = baseURL.String()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (j *Job) GetName() string {
|
|
|
|
return j.Name
|
|
|
|
}
|
|
|
|
|
|
|
|
func (j *Job) GetURL() string {
|
|
|
|
return j.URL
|
|
|
|
}
|