|
| 1 | +/* |
| 2 | +Copyright 2019 microsoft. |
| 3 | +
|
| 4 | +Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | +you may not use this file except in compliance with the License. |
| 6 | +You may obtain a copy of the License at |
| 7 | +
|
| 8 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +
|
| 10 | +Unless required by applicable law or agreed to in writing, software |
| 11 | +distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | +See the License for the specific language governing permissions and |
| 14 | +limitations under the License. |
| 15 | +*/ |
| 16 | + |
| 17 | +package v1alpha1 |
| 18 | + |
| 19 | +import ( |
| 20 | + dbmodels "github.com/xinsnake/databricks-sdk-golang/azure/models" |
| 21 | +) |
| 22 | + |
| 23 | +// JobSettings is similar to dbmodels.JobSettings, the reason it |
| 24 | +// exists is because dbmodels.JobSettings doesn't support ExistingClusterName |
| 25 | +// ExistingClusterName allows discovering databricks clusters by it's kubernetese object name |
| 26 | +type JobSettings struct { |
| 27 | + ExistingClusterID string `json:"existing_cluster_id,omitempty" url:"existing_cluster_id,omitempty"` |
| 28 | + ExistingClusterName string `json:"existing_cluster_name,omitempty" url:"existing_cluster_name,omitempty"` |
| 29 | + NewCluster *dbmodels.NewCluster `json:"new_cluster,omitempty" url:"new_cluster,omitempty"` |
| 30 | + NotebookTask *dbmodels.NotebookTask `json:"notebook_task,omitempty" url:"notebook_task,omitempty"` |
| 31 | + SparkJarTask *dbmodels.SparkJarTask `json:"spark_jar_task,omitempty" url:"spark_jar_task,omitempty"` |
| 32 | + SparkPythonTask *dbmodels.SparkPythonTask `json:"spark_python_task,omitempty" url:"spark_python_task,omitempty"` |
| 33 | + SparkSubmitTask *dbmodels.SparkSubmitTask `json:"spark_submit_task,omitempty" url:"spark_submit_task,omitempty"` |
| 34 | + Name string `json:"name,omitempty" url:"name,omitempty"` |
| 35 | + Libraries []dbmodels.Library `json:"libraries,omitempty" url:"libraries,omitempty"` |
| 36 | + EmailNotifications *dbmodels.JobEmailNotifications `json:"email_notifications,omitempty" url:"email_notifications,omitempty"` |
| 37 | + TimeoutSeconds int32 `json:"timeout_seconds,omitempty" url:"timeout_seconds,omitempty"` |
| 38 | + MaxRetries int32 `json:"max_retries,omitempty" url:"max_retries,omitempty"` |
| 39 | + MinRetryIntervalMillis int32 `json:"min_retry_interval_millis,omitempty" url:"min_retry_interval_millis,omitempty"` |
| 40 | + RetryOnTimeout bool `json:"retry_on_timeout,omitempty" url:"retry_on_timeout,omitempty"` |
| 41 | + Schedule *dbmodels.CronSchedule `json:"schedule,omitempty" url:"schedule,omitempty"` |
| 42 | + MaxConcurrentRuns int32 `json:"max_concurrent_runs,omitempty" url:"max_concurrent_runs,omitempty"` |
| 43 | +} |
| 44 | + |
| 45 | +// ToK8sJobSettings converts a databricks JobSettings object to k8s JobSettings object. |
| 46 | +// It is needed to add ExistingClusterName and follow k8s camleCase naming convention |
| 47 | +func ToK8sJobSettings(dbjs *dbmodels.JobSettings) JobSettings { |
| 48 | + var k8sjs JobSettings |
| 49 | + k8sjs.ExistingClusterID = dbjs.ExistingClusterID |
| 50 | + k8sjs.NewCluster = dbjs.NewCluster |
| 51 | + k8sjs.NotebookTask = dbjs.NotebookTask |
| 52 | + k8sjs.SparkJarTask = dbjs.SparkJarTask |
| 53 | + k8sjs.SparkPythonTask = dbjs.SparkPythonTask |
| 54 | + k8sjs.SparkSubmitTask = dbjs.SparkSubmitTask |
| 55 | + k8sjs.Name = dbjs.Name |
| 56 | + k8sjs.Libraries = dbjs.Libraries |
| 57 | + k8sjs.EmailNotifications = dbjs.EmailNotifications |
| 58 | + k8sjs.TimeoutSeconds = dbjs.TimeoutSeconds |
| 59 | + k8sjs.MaxRetries = dbjs.MaxRetries |
| 60 | + k8sjs.MinRetryIntervalMillis = dbjs.MinRetryIntervalMillis |
| 61 | + k8sjs.RetryOnTimeout = dbjs.RetryOnTimeout |
| 62 | + k8sjs.Schedule = dbjs.Schedule |
| 63 | + k8sjs.MaxConcurrentRuns = dbjs.MaxConcurrentRuns |
| 64 | + return k8sjs |
| 65 | +} |
| 66 | + |
| 67 | +// ToDatabricksJobSettings converts a k8s JobSettings object to a DataBricks JobSettings object. |
| 68 | +// It is needed to add ExistingClusterName and follow k8s camleCase naming convention |
| 69 | +func ToDatabricksJobSettings(k8sjs *JobSettings) dbmodels.JobSettings { |
| 70 | + |
| 71 | + var dbjs dbmodels.JobSettings |
| 72 | + dbjs.ExistingClusterID = k8sjs.ExistingClusterID |
| 73 | + dbjs.NewCluster = k8sjs.NewCluster |
| 74 | + dbjs.NotebookTask = k8sjs.NotebookTask |
| 75 | + dbjs.SparkJarTask = k8sjs.SparkJarTask |
| 76 | + dbjs.SparkPythonTask = k8sjs.SparkPythonTask |
| 77 | + dbjs.SparkSubmitTask = k8sjs.SparkSubmitTask |
| 78 | + dbjs.Name = k8sjs.Name |
| 79 | + dbjs.Libraries = k8sjs.Libraries |
| 80 | + dbjs.EmailNotifications = k8sjs.EmailNotifications |
| 81 | + dbjs.TimeoutSeconds = k8sjs.TimeoutSeconds |
| 82 | + dbjs.MaxRetries = k8sjs.MaxRetries |
| 83 | + dbjs.MinRetryIntervalMillis = k8sjs.MinRetryIntervalMillis |
| 84 | + dbjs.RetryOnTimeout = k8sjs.RetryOnTimeout |
| 85 | + dbjs.Schedule = k8sjs.Schedule |
| 86 | + dbjs.MaxConcurrentRuns = k8sjs.MaxConcurrentRuns |
| 87 | + return dbjs |
| 88 | +} |
0 commit comments