2023-09-07 21:54:31 +00:00
|
|
|
package resources
|
|
|
|
|
|
|
|
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-07 21:54:31 +00:00
|
|
|
"github.com/databricks/databricks-sdk-go/service/serving"
|
|
|
|
)
|
|
|
|
|
|
|
|
type ModelServingEndpoint struct {
|
|
|
|
// This represents the input args for terraform, and will get converted
|
|
|
|
// to a HCL representation for CRUD
|
|
|
|
*serving.CreateServingEndpoint
|
|
|
|
|
|
|
|
// This represents the id (ie serving_endpoint_id) that can be used
|
|
|
|
// as a reference in other resources. This value is returned by terraform.
|
2024-01-25 11:32:47 +00:00
|
|
|
ID string `json:"id,omitempty" bundle:"readonly"`
|
2023-09-07 21:54:31 +00:00
|
|
|
|
|
|
|
// This is a resource agnostic implementation of permissions for ACLs.
|
|
|
|
// Implementation could be different based on the resource type.
|
|
|
|
Permissions []Permission `json:"permissions,omitempty"`
|
2024-01-25 11:32:47 +00:00
|
|
|
|
|
|
|
ModifiedStatus ModifiedStatus `json:"modified_status,omitempty" bundle:"internal"`
|
2024-10-18 06:45:47 +00:00
|
|
|
URL string `json:"url,omitempty" bundle:"internal"`
|
2023-09-07 21:54:31 +00:00
|
|
|
}
|
2023-10-16 06:56:06 +00:00
|
|
|
|
|
|
|
func (s *ModelServingEndpoint) UnmarshalJSON(b []byte) error {
|
|
|
|
return marshal.Unmarshal(b, s)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s ModelServingEndpoint) MarshalJSON() ([]byte, error) {
|
|
|
|
return marshal.Marshal(s)
|
|
|
|
}
|
2024-05-17 10:10:17 +00:00
|
|
|
|
|
|
|
func (s *ModelServingEndpoint) Exists(ctx context.Context, w *databricks.WorkspaceClient, id string) (bool, error) {
|
|
|
|
_, err := w.ServingEndpoints.Get(ctx, serving.GetServingEndpointRequest{
|
|
|
|
Name: id,
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
log.Debugf(ctx, "serving endpoint %s does not exist", id)
|
|
|
|
return false, err
|
|
|
|
}
|
|
|
|
return true, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *ModelServingEndpoint) TerraformResourceName() string {
|
|
|
|
return "databricks_model_serving"
|
|
|
|
}
|
2024-10-18 06:45:47 +00:00
|
|
|
|
|
|
|
func (s *ModelServingEndpoint) InitializeURL(baseURL url.URL) {
|
|
|
|
if s.ID == "" {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
baseURL.Path = fmt.Sprintf("ml/endpoints/%s", s.ID)
|
|
|
|
s.URL = baseURL.String()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *ModelServingEndpoint) GetName() string {
|
|
|
|
return s.Name
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *ModelServingEndpoint) GetURL() string {
|
|
|
|
return s.URL
|
|
|
|
}
|