2016-08-02 11:42:00 -07:00
|
|
|
/**
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
2016-08-09 16:18:30 -07:00
|
|
|
|
2016-08-02 11:42:00 -07:00
|
|
|
package realis
|
|
|
|
|
|
|
|
import (
|
2020-02-19 11:40:40 -08:00
|
|
|
"github.com/aurora-scheduler/gorealis/v2/gen-go/apache/aurora"
|
2016-08-02 11:42:00 -07:00
|
|
|
)
|
|
|
|
|
2016-08-09 16:18:30 -07:00
|
|
|
// Structure to collect all information pertaining to an Aurora job.
|
2016-08-24 11:59:01 -07:00
|
|
|
type AuroraJob struct {
|
2016-08-02 11:42:00 -07:00
|
|
|
jobConfig *aurora.JobConfiguration
|
2018-12-11 16:51:10 -08:00
|
|
|
task *AuroraTask
|
2016-08-02 11:42:00 -07:00
|
|
|
}
|
|
|
|
|
2018-11-07 19:09:16 -08:00
|
|
|
// Create a AuroraJob object with everything initialized.
|
|
|
|
func NewJob() *AuroraJob {
|
2016-08-02 11:42:00 -07:00
|
|
|
|
2018-11-29 17:06:45 -08:00
|
|
|
jobKey := &aurora.JobKey{}
|
2016-08-02 11:42:00 -07:00
|
|
|
|
2018-12-11 16:51:10 -08:00
|
|
|
// AuroraTask clientConfig
|
2018-12-10 18:57:16 -08:00
|
|
|
task := NewTask()
|
|
|
|
task.task.Job = jobKey
|
2018-11-29 17:06:45 -08:00
|
|
|
|
2018-12-08 08:57:15 -08:00
|
|
|
// AuroraJob clientConfig
|
2018-11-29 17:06:45 -08:00
|
|
|
jobConfig := &aurora.JobConfiguration{
|
|
|
|
Key: jobKey,
|
2018-12-10 18:57:16 -08:00
|
|
|
TaskConfig: task.TaskConfig(),
|
2018-11-29 17:06:45 -08:00
|
|
|
}
|
2016-08-02 11:42:00 -07:00
|
|
|
|
2017-12-23 10:33:42 -08:00
|
|
|
return &AuroraJob{
|
|
|
|
jobConfig: jobConfig,
|
2018-12-10 18:57:16 -08:00
|
|
|
task: task,
|
2017-12-23 10:33:42 -08:00
|
|
|
}
|
2016-08-02 11:42:00 -07:00
|
|
|
}
|
|
|
|
|
2018-12-11 16:51:10 -08:00
|
|
|
// Set AuroraJob Key environment. Explicit changes to AuroraTask's job key are not needed
|
2018-12-10 18:57:16 -08:00
|
|
|
// because they share a pointer to the same JobKey.
|
2018-11-07 19:09:16 -08:00
|
|
|
func (j *AuroraJob) Environment(env string) *AuroraJob {
|
2016-08-24 11:59:01 -07:00
|
|
|
j.jobConfig.Key.Environment = env
|
|
|
|
return j
|
2016-08-02 11:42:00 -07:00
|
|
|
}
|
|
|
|
|
2018-11-07 19:09:16 -08:00
|
|
|
// Set AuroraJob Key Role.
|
|
|
|
func (j *AuroraJob) Role(role string) *AuroraJob {
|
2016-08-24 11:59:01 -07:00
|
|
|
j.jobConfig.Key.Role = role
|
2016-08-02 11:42:00 -07:00
|
|
|
|
2018-11-29 17:06:45 -08:00
|
|
|
// Will be deprecated
|
2017-12-23 10:33:42 -08:00
|
|
|
identity := &aurora.Identity{User: role}
|
2016-08-24 11:59:01 -07:00
|
|
|
j.jobConfig.Owner = identity
|
|
|
|
j.jobConfig.TaskConfig.Owner = identity
|
2019-01-07 14:38:08 -08:00
|
|
|
|
2016-08-24 11:59:01 -07:00
|
|
|
return j
|
2016-08-02 11:42:00 -07:00
|
|
|
}
|
|
|
|
|
2018-11-07 19:09:16 -08:00
|
|
|
// Set AuroraJob Key Name.
|
|
|
|
func (j *AuroraJob) Name(name string) *AuroraJob {
|
2016-08-24 11:59:01 -07:00
|
|
|
j.jobConfig.Key.Name = name
|
|
|
|
return j
|
2016-08-02 11:42:00 -07:00
|
|
|
}
|
|
|
|
|
2018-12-10 18:57:16 -08:00
|
|
|
// How many instances of the job to run
|
|
|
|
func (j *AuroraJob) InstanceCount(instCount int32) *AuroraJob {
|
|
|
|
j.jobConfig.InstanceCount = instCount
|
2016-08-24 11:59:01 -07:00
|
|
|
return j
|
2016-08-02 11:42:00 -07:00
|
|
|
}
|
|
|
|
|
2018-12-10 18:57:16 -08:00
|
|
|
func (j *AuroraJob) CronSchedule(cron string) *AuroraJob {
|
|
|
|
j.jobConfig.CronSchedule = &cron
|
2016-08-24 11:59:01 -07:00
|
|
|
return j
|
2016-08-02 11:42:00 -07:00
|
|
|
}
|
|
|
|
|
2018-12-10 18:57:16 -08:00
|
|
|
func (j *AuroraJob) CronCollisionPolicy(policy aurora.CronCollisionPolicy) *AuroraJob {
|
|
|
|
j.jobConfig.CronCollisionPolicy = policy
|
2016-08-24 11:59:01 -07:00
|
|
|
return j
|
2016-08-02 11:42:00 -07:00
|
|
|
}
|
|
|
|
|
2018-12-10 18:57:16 -08:00
|
|
|
// How many instances of the job to run
|
|
|
|
func (j *AuroraJob) GetInstanceCount() int32 {
|
|
|
|
return j.jobConfig.InstanceCount
|
2016-08-02 11:42:00 -07:00
|
|
|
}
|
|
|
|
|
2018-12-10 18:57:16 -08:00
|
|
|
// Get the current job configurations key to use for some realis calls.
|
2018-12-12 14:01:26 -08:00
|
|
|
func (j *AuroraJob) JobKey() aurora.JobKey {
|
|
|
|
return *j.jobConfig.Key
|
2018-12-10 18:57:16 -08:00
|
|
|
}
|
2016-08-02 11:42:00 -07:00
|
|
|
|
2018-12-10 18:57:16 -08:00
|
|
|
// Get the current job configurations key to use for some realis calls.
|
|
|
|
func (j *AuroraJob) JobConfig() *aurora.JobConfiguration {
|
|
|
|
return j.jobConfig
|
2016-08-02 11:42:00 -07:00
|
|
|
}
|
|
|
|
|
2019-01-07 14:38:08 -08:00
|
|
|
// Get the current job configurations key to use for some realis calls.
|
|
|
|
func (j *AuroraJob) AuroraTask() *AuroraTask {
|
|
|
|
return j.task
|
|
|
|
}
|
|
|
|
|
2018-12-10 18:57:16 -08:00
|
|
|
/*
|
2018-12-11 16:51:10 -08:00
|
|
|
AuroraTask specific API, see task.go for further documentation.
|
2018-12-10 18:57:16 -08:00
|
|
|
These functions are provided for the convenience of chaining API calls.
|
|
|
|
*/
|
2018-12-07 16:01:23 -08:00
|
|
|
|
2018-12-10 18:57:16 -08:00
|
|
|
func (j *AuroraJob) ExecutorName(name string) *AuroraJob {
|
|
|
|
j.task.ExecutorName(name)
|
2018-12-07 16:01:23 -08:00
|
|
|
return j
|
|
|
|
}
|
|
|
|
|
2018-12-10 18:57:16 -08:00
|
|
|
func (j *AuroraJob) ExecutorData(data string) *AuroraJob {
|
|
|
|
j.task.ExecutorData(data)
|
2016-08-24 11:59:01 -07:00
|
|
|
return j
|
2016-08-02 11:42:00 -07:00
|
|
|
}
|
|
|
|
|
2018-12-10 18:57:16 -08:00
|
|
|
func (j *AuroraJob) CPU(cpus float64) *AuroraJob {
|
|
|
|
j.task.CPU(cpus)
|
2016-08-24 11:59:01 -07:00
|
|
|
return j
|
2016-08-02 11:42:00 -07:00
|
|
|
}
|
|
|
|
|
2018-12-10 18:57:16 -08:00
|
|
|
func (j *AuroraJob) RAM(ram int64) *AuroraJob {
|
|
|
|
j.task.RAM(ram)
|
2016-09-30 01:24:49 -04:00
|
|
|
return j
|
|
|
|
}
|
|
|
|
|
2018-12-10 18:57:16 -08:00
|
|
|
func (j *AuroraJob) Disk(disk int64) *AuroraJob {
|
|
|
|
j.task.Disk(disk)
|
2016-09-30 01:24:49 -04:00
|
|
|
return j
|
|
|
|
}
|
|
|
|
|
2019-09-10 15:00:13 -07:00
|
|
|
func (j *AuroraJob) GPU(gpu int64) *AuroraJob {
|
|
|
|
j.task.GPU(gpu)
|
|
|
|
return j
|
|
|
|
}
|
|
|
|
|
2018-12-10 18:57:16 -08:00
|
|
|
func (j *AuroraJob) Tier(tier string) *AuroraJob {
|
|
|
|
j.task.Tier(tier)
|
2016-08-24 11:59:01 -07:00
|
|
|
return j
|
|
|
|
}
|
|
|
|
|
2018-12-10 18:57:16 -08:00
|
|
|
func (j *AuroraJob) MaxFailure(maxFail int32) *AuroraJob {
|
|
|
|
j.task.MaxFailure(maxFail)
|
|
|
|
return j
|
2016-08-02 11:42:00 -07:00
|
|
|
}
|
|
|
|
|
2018-12-10 18:57:16 -08:00
|
|
|
func (j *AuroraJob) IsService(isService bool) *AuroraJob {
|
|
|
|
j.task.IsService(isService)
|
|
|
|
return j
|
2016-08-24 11:59:01 -07:00
|
|
|
}
|
|
|
|
|
2021-09-16 16:29:25 -07:00
|
|
|
func (j *AuroraJob) Priority(priority int32) *AuroraJob {
|
|
|
|
j.task.Priority(priority)
|
|
|
|
return j
|
|
|
|
}
|
|
|
|
|
2021-10-15 12:18:26 -07:00
|
|
|
func (j *AuroraJob) Production(production bool) *AuroraJob {
|
|
|
|
j.task.Production(production)
|
|
|
|
return j
|
|
|
|
}
|
|
|
|
|
2017-09-14 16:38:26 -07:00
|
|
|
func (j *AuroraJob) TaskConfig() *aurora.TaskConfig {
|
2018-12-10 18:57:16 -08:00
|
|
|
return j.task.TaskConfig()
|
2016-08-02 11:42:00 -07:00
|
|
|
}
|
|
|
|
|
2018-11-07 19:09:16 -08:00
|
|
|
func (j *AuroraJob) AddURIs(extract bool, cache bool, values ...string) *AuroraJob {
|
2018-12-10 18:57:16 -08:00
|
|
|
j.task.AddURIs(extract, cache, values...)
|
2016-08-24 11:59:01 -07:00
|
|
|
return j
|
2016-08-02 11:42:00 -07:00
|
|
|
}
|
|
|
|
|
2018-11-07 19:09:16 -08:00
|
|
|
func (j *AuroraJob) AddLabel(key string, value string) *AuroraJob {
|
2018-12-10 18:57:16 -08:00
|
|
|
j.task.AddLabel(key, value)
|
2016-08-24 11:59:01 -07:00
|
|
|
return j
|
2016-08-02 11:42:00 -07:00
|
|
|
}
|
|
|
|
|
2018-11-07 19:09:16 -08:00
|
|
|
func (j *AuroraJob) AddNamedPorts(names ...string) *AuroraJob {
|
2018-12-10 18:57:16 -08:00
|
|
|
j.task.AddNamedPorts(names...)
|
2016-08-24 11:59:01 -07:00
|
|
|
return j
|
2016-08-10 11:59:04 -07:00
|
|
|
}
|
|
|
|
|
2018-11-07 19:09:16 -08:00
|
|
|
func (j *AuroraJob) AddPorts(num int) *AuroraJob {
|
2018-12-10 18:57:16 -08:00
|
|
|
j.task.AddPorts(num)
|
2016-08-24 11:59:01 -07:00
|
|
|
return j
|
2016-08-02 11:42:00 -07:00
|
|
|
}
|
2018-11-07 19:09:16 -08:00
|
|
|
func (j *AuroraJob) AddValueConstraint(name string, negated bool, values ...string) *AuroraJob {
|
2018-12-10 18:57:16 -08:00
|
|
|
j.task.AddValueConstraint(name, negated, values...)
|
2016-08-24 11:59:01 -07:00
|
|
|
return j
|
2016-08-02 11:42:00 -07:00
|
|
|
}
|
|
|
|
|
2018-11-07 19:09:16 -08:00
|
|
|
func (j *AuroraJob) AddLimitConstraint(name string, limit int32) *AuroraJob {
|
2018-12-10 18:57:16 -08:00
|
|
|
j.task.AddLimitConstraint(name, limit)
|
2016-08-24 11:59:01 -07:00
|
|
|
return j
|
2016-08-02 11:42:00 -07:00
|
|
|
}
|
2016-11-01 21:24:15 -04:00
|
|
|
|
2018-11-07 19:09:16 -08:00
|
|
|
func (j *AuroraJob) AddDedicatedConstraint(role, name string) *AuroraJob {
|
2018-12-10 18:57:16 -08:00
|
|
|
j.task.AddDedicatedConstraint(role, name)
|
2018-10-11 09:43:35 -07:00
|
|
|
return j
|
|
|
|
}
|
|
|
|
|
2018-11-07 19:09:16 -08:00
|
|
|
func (j *AuroraJob) Container(container Container) *AuroraJob {
|
2018-12-10 18:57:16 -08:00
|
|
|
j.task.Container(container)
|
2016-11-01 21:24:15 -04:00
|
|
|
return j
|
|
|
|
}
|
2019-01-07 14:38:08 -08:00
|
|
|
|
|
|
|
func (j *AuroraJob) ThermosExecutor(thermos ThermosExecutor) *AuroraJob {
|
|
|
|
j.task.ThermosExecutor(thermos)
|
|
|
|
return j
|
|
|
|
}
|
|
|
|
|
|
|
|
func (j *AuroraJob) BuildThermosPayload() error {
|
|
|
|
return j.task.BuildThermosPayload()
|
|
|
|
}
|
2018-12-20 16:38:06 -06:00
|
|
|
|
|
|
|
func (j *AuroraJob) PartitionPolicy(reschedule bool, delay int64) *AuroraJob {
|
|
|
|
j.task.PartitionPolicy(aurora.PartitionPolicy{
|
|
|
|
Reschedule: reschedule,
|
|
|
|
DelaySecs: &delay,
|
|
|
|
})
|
|
|
|
return j
|
|
|
|
}
|