2024-05-31 09:42:25 +00:00
|
|
|
package resources
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2024-10-18 06:45:47 +00:00
|
|
|
"fmt"
|
|
|
|
"net/url"
|
|
|
|
"strings"
|
2024-05-31 09:42:25 +00:00
|
|
|
|
|
|
|
"github.com/databricks/cli/libs/log"
|
|
|
|
"github.com/databricks/databricks-sdk-go"
|
|
|
|
"github.com/databricks/databricks-sdk-go/marshal"
|
|
|
|
"github.com/databricks/databricks-sdk-go/service/catalog"
|
|
|
|
)
|
|
|
|
|
|
|
|
type QualityMonitor struct {
|
|
|
|
// Represents the Input Arguments for Terraform and will get
|
|
|
|
// converted to a HCL representation for CRUD
|
|
|
|
*catalog.CreateMonitor
|
|
|
|
|
|
|
|
// This represents the id which is the full name of the monitor
|
|
|
|
// (catalog_name.schema_name.table_name) that can be used
|
|
|
|
// as a reference in other resources. This value is returned by terraform.
|
|
|
|
ID string `json:"id,omitempty" bundle:"readonly"`
|
|
|
|
|
|
|
|
ModifiedStatus ModifiedStatus `json:"modified_status,omitempty" bundle:"internal"`
|
2024-10-18 06:45:47 +00:00
|
|
|
URL string `json:"url,omitempty" bundle:"internal"`
|
2024-05-31 09:42:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *QualityMonitor) UnmarshalJSON(b []byte) error {
|
|
|
|
return marshal.Unmarshal(b, s)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s QualityMonitor) MarshalJSON() ([]byte, error) {
|
|
|
|
return marshal.Marshal(s)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *QualityMonitor) Exists(ctx context.Context, w *databricks.WorkspaceClient, id string) (bool, error) {
|
|
|
|
_, err := w.QualityMonitors.Get(ctx, catalog.GetQualityMonitorRequest{
|
|
|
|
TableName: id,
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
log.Debugf(ctx, "quality monitor %s does not exist", id)
|
|
|
|
return false, err
|
|
|
|
}
|
|
|
|
return true, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *QualityMonitor) TerraformResourceName() string {
|
|
|
|
return "databricks_quality_monitor"
|
|
|
|
}
|
2024-10-18 06:45:47 +00:00
|
|
|
|
|
|
|
func (s *QualityMonitor) InitializeURL(baseURL url.URL) {
|
|
|
|
if s.TableName == "" {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
baseURL.Path = fmt.Sprintf("explore/data/%s", strings.ReplaceAll(s.TableName, ".", "/"))
|
|
|
|
s.URL = baseURL.String()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *QualityMonitor) GetName() string {
|
|
|
|
return s.TableName
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *QualityMonitor) GetURL() string {
|
|
|
|
return s.URL
|
|
|
|
}
|