2023-03-20 20:28:43 +00:00
|
|
|
package resources
|
|
|
|
|
2023-09-04 09:55:01 +00:00
|
|
|
import (
|
2024-05-17 10:10:17 +00:00
|
|
|
"context"
|
2024-10-18 06:45:47 +00:00
|
|
|
"fmt"
|
|
|
|
"net/url"
|
2024-05-17 10:10:17 +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/ml"
|
|
|
|
)
|
2023-03-20 20:28:43 +00:00
|
|
|
|
|
|
|
type MlflowExperiment 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"`
|
2023-03-21 09:58:16 +00:00
|
|
|
|
2023-04-21 08:30:20 +00:00
|
|
|
*ml.Experiment
|
2023-03-20 20:28:43 +00:00
|
|
|
}
|
2023-10-16 06:56:06 +00:00
|
|
|
|
|
|
|
func (s *MlflowExperiment) UnmarshalJSON(b []byte) error {
|
|
|
|
return marshal.Unmarshal(b, s)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s MlflowExperiment) MarshalJSON() ([]byte, error) {
|
|
|
|
return marshal.Marshal(s)
|
|
|
|
}
|
2024-05-17 10:10:17 +00:00
|
|
|
|
|
|
|
func (s *MlflowExperiment) Exists(ctx context.Context, w *databricks.WorkspaceClient, id string) (bool, error) {
|
|
|
|
_, err := w.Experiments.GetExperiment(ctx, ml.GetExperimentRequest{
|
|
|
|
ExperimentId: id,
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
log.Debugf(ctx, "experiment %s does not exist", id)
|
|
|
|
return false, err
|
|
|
|
}
|
|
|
|
return true, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *MlflowExperiment) TerraformResourceName() string {
|
|
|
|
return "databricks_mlflow_experiment"
|
|
|
|
}
|
2024-10-18 06:45:47 +00:00
|
|
|
|
|
|
|
func (s *MlflowExperiment) InitializeURL(baseURL url.URL) {
|
|
|
|
if s.ID == "" {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
baseURL.Path = fmt.Sprintf("ml/experiments/%s", s.ID)
|
|
|
|
s.URL = baseURL.String()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *MlflowExperiment) GetName() string {
|
|
|
|
return s.Name
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *MlflowExperiment) GetURL() string {
|
|
|
|
return s.URL
|
|
|
|
}
|