jkawamoto/roadie

View on GitHub
cloud/azure/batch/models/job_specification.go

Summary

Maintainability
B
5 hrs
Test Coverage
package models

// This file was generated by the swagger tool.
// Editing this file might prove futile when you re-run the swagger generate command

import (
    "encoding/json"

    strfmt "github.com/go-openapi/strfmt"
    "github.com/go-openapi/swag"

    "github.com/go-openapi/errors"
    "github.com/go-openapi/validate"
)

// JobSpecification Specifies details of the jobs to be created on a schedule.
// swagger:model JobSpecification
type JobSpecification struct {

    // A list of common environment variable settings. These environment variables are set for all tasks in jobs created under this schedule (including the Job Manager, Job Preparation and Job Release tasks).
    //
    // Individual tasks can override an environment setting specified here by specifying the same setting name with a different value.
    CommonEnvironmentSettings []*EnvironmentSetting `json:"commonEnvironmentSettings"`

    // The execution constraints for jobs created under this schedule.
    Constraints *JobConstraints `json:"constraints,omitempty"`

    // The display name for jobs created under this schedule.
    //
    // The name need not be unique and can contain any Unicode characters up to a maximum length of 1024.
    DisplayName string `json:"displayName,omitempty"`

    // The details of a Job Manager task to be launched when a job is started under this schedule.
    //
    // If the job does not specify a Job Manager task, the user must explicitly add tasks to the job using the Task API. If the job does specify a Job Manager task, the Batch service creates the Job Manager task when the job is created, and will try to schedule the Job Manager task before scheduling other tasks in the job.
    JobManagerTask *JobManagerTask `json:"jobManagerTask,omitempty"`

    // The Job Preparation task for jobs created under this schedule.
    //
    // If a job has a Job Preparation task, the Batch service will run the Job Preparation task on a compute node before starting any tasks of that job on that compute node.
    JobPreparationTask *JobPreparationTask `json:"jobPreparationTask,omitempty"`

    // The Job Release task for jobs created under this schedule.
    //
    // The primary purpose of the Job Release task is to undo changes to compute nodes made by the Job Preparation task. Example activities include deleting local files, or shutting down services that were started as part of job preparation. A Job Release task cannot be specified without also specifying a Job Preparation task for the job. The Batch service runs the Job Release task on the compute nodes that have run the Job Preparation task.
    JobReleaseTask *JobReleaseTask `json:"jobReleaseTask,omitempty"`

    // A list of name-value pairs associated with each job created under this schedule as metadata.
    //
    // The Batch service does not assign any meaning to metadata; it is solely for the use of user code.
    Metadata []*MetadataItem `json:"metadata"`

    // The action the Batch service should take when all tasks in a job created under this schedule are in the completed state.
    //
    // Note that if a job contains no tasks, then all tasks are considered complete. This option is therefore most commonly used with a job manager task; if you want to use automatic job termination without a job manager, you should initially set onAllTasksComplete to noaction and update the job properties to set onAllTasksComplete to terminatejob once you have finished adding tasks. The default is noaction.
    OnAllTasksComplete string `json:"onAllTasksComplete,omitempty"`

    // The action the Batch service should take when any task fails in a job created under this schedule. A task is considered to have failed if it completes with a non-zero exit code and has exhausted its retry count, or if it had a scheduling error.
    //
    // The default is noaction.
    OnTaskFailure string `json:"onTaskFailure,omitempty"`

    // The pool on which the Batch service runs the tasks of jobs created under this schedule.
    // Required: true
    PoolInfo *PoolInformation `json:"poolInfo"`

    // The priority of jobs created under this schedule.
    //
    // Priority values can range from -1000 to 1000, with -1000 being the lowest priority and 1000 being the highest priority. The default value is 0. This priority is used as the default for all jobs under the job schedule. You can update a job's priority after it has been created using by using the update job API.
    Priority int32 `json:"priority,omitempty"`

    // The flag that determines if this job will use tasks with dependencies.
    UsesTaskDependencies bool `json:"usesTaskDependencies,omitempty"`
}

// Validate validates this job specification
func (m *JobSpecification) Validate(formats strfmt.Registry) error {
    var res []error

    if err := m.validateCommonEnvironmentSettings(formats); err != nil {
        // prop
        res = append(res, err)
    }

    if err := m.validateConstraints(formats); err != nil {
        // prop
        res = append(res, err)
    }

    if err := m.validateJobManagerTask(formats); err != nil {
        // prop
        res = append(res, err)
    }

    if err := m.validateJobPreparationTask(formats); err != nil {
        // prop
        res = append(res, err)
    }

    if err := m.validateJobReleaseTask(formats); err != nil {
        // prop
        res = append(res, err)
    }

    if err := m.validateMetadata(formats); err != nil {
        // prop
        res = append(res, err)
    }

    if err := m.validateOnAllTasksComplete(formats); err != nil {
        // prop
        res = append(res, err)
    }

    if err := m.validateOnTaskFailure(formats); err != nil {
        // prop
        res = append(res, err)
    }

    if err := m.validatePoolInfo(formats); err != nil {
        // prop
        res = append(res, err)
    }

    if len(res) > 0 {
        return errors.CompositeValidationError(res...)
    }
    return nil
}

func (m *JobSpecification) validateCommonEnvironmentSettings(formats strfmt.Registry) error {

    if swag.IsZero(m.CommonEnvironmentSettings) { // not required
        return nil
    }

    for i := 0; i < len(m.CommonEnvironmentSettings); i++ {

        if swag.IsZero(m.CommonEnvironmentSettings[i]) { // not required
            continue
        }

        if m.CommonEnvironmentSettings[i] != nil {

            if err := m.CommonEnvironmentSettings[i].Validate(formats); err != nil {
                return err
            }
        }

    }

    return nil
}

func (m *JobSpecification) validateConstraints(formats strfmt.Registry) error {

    if swag.IsZero(m.Constraints) { // not required
        return nil
    }

    if m.Constraints != nil {

        if err := m.Constraints.Validate(formats); err != nil {
            return err
        }
    }

    return nil
}

func (m *JobSpecification) validateJobManagerTask(formats strfmt.Registry) error {

    if swag.IsZero(m.JobManagerTask) { // not required
        return nil
    }

    if m.JobManagerTask != nil {

        if err := m.JobManagerTask.Validate(formats); err != nil {
            return err
        }
    }

    return nil
}

func (m *JobSpecification) validateJobPreparationTask(formats strfmt.Registry) error {

    if swag.IsZero(m.JobPreparationTask) { // not required
        return nil
    }

    if m.JobPreparationTask != nil {

        if err := m.JobPreparationTask.Validate(formats); err != nil {
            return err
        }
    }

    return nil
}

func (m *JobSpecification) validateJobReleaseTask(formats strfmt.Registry) error {

    if swag.IsZero(m.JobReleaseTask) { // not required
        return nil
    }

    if m.JobReleaseTask != nil {

        if err := m.JobReleaseTask.Validate(formats); err != nil {
            return err
        }
    }

    return nil
}

func (m *JobSpecification) validateMetadata(formats strfmt.Registry) error {

    if swag.IsZero(m.Metadata) { // not required
        return nil
    }

    for i := 0; i < len(m.Metadata); i++ {

        if swag.IsZero(m.Metadata[i]) { // not required
            continue
        }

        if m.Metadata[i] != nil {

            if err := m.Metadata[i].Validate(formats); err != nil {
                return err
            }
        }

    }

    return nil
}

var jobSpecificationTypeOnAllTasksCompletePropEnum []interface{}

func init() {
    var res []string
    if err := json.Unmarshal([]byte(`["noAction","terminateJob"]`), &res); err != nil {
        panic(err)
    }
    for _, v := range res {
        jobSpecificationTypeOnAllTasksCompletePropEnum = append(jobSpecificationTypeOnAllTasksCompletePropEnum, v)
    }
}

const (
    // JobSpecificationOnAllTasksCompleteNoAction captures enum value "noAction"
    JobSpecificationOnAllTasksCompleteNoAction string = "noAction"
    // JobSpecificationOnAllTasksCompleteTerminateJob captures enum value "terminateJob"
    JobSpecificationOnAllTasksCompleteTerminateJob string = "terminateJob"
)

// prop value enum
func (m *JobSpecification) validateOnAllTasksCompleteEnum(path, location string, value string) error {
    if err := validate.Enum(path, location, value, jobSpecificationTypeOnAllTasksCompletePropEnum); err != nil {
        return err
    }
    return nil
}

func (m *JobSpecification) validateOnAllTasksComplete(formats strfmt.Registry) error {

    if swag.IsZero(m.OnAllTasksComplete) { // not required
        return nil
    }

    // value enum
    if err := m.validateOnAllTasksCompleteEnum("onAllTasksComplete", "body", m.OnAllTasksComplete); err != nil {
        return err
    }

    return nil
}

var jobSpecificationTypeOnTaskFailurePropEnum []interface{}

func init() {
    var res []string
    if err := json.Unmarshal([]byte(`["noAction","performExitOptionsJobAction"]`), &res); err != nil {
        panic(err)
    }
    for _, v := range res {
        jobSpecificationTypeOnTaskFailurePropEnum = append(jobSpecificationTypeOnTaskFailurePropEnum, v)
    }
}

const (
    // JobSpecificationOnTaskFailureNoAction captures enum value "noAction"
    JobSpecificationOnTaskFailureNoAction string = "noAction"
    // JobSpecificationOnTaskFailurePerformExitOptionsJobAction captures enum value "performExitOptionsJobAction"
    JobSpecificationOnTaskFailurePerformExitOptionsJobAction string = "performExitOptionsJobAction"
)

// prop value enum
func (m *JobSpecification) validateOnTaskFailureEnum(path, location string, value string) error {
    if err := validate.Enum(path, location, value, jobSpecificationTypeOnTaskFailurePropEnum); err != nil {
        return err
    }
    return nil
}

func (m *JobSpecification) validateOnTaskFailure(formats strfmt.Registry) error {

    if swag.IsZero(m.OnTaskFailure) { // not required
        return nil
    }

    // value enum
    if err := m.validateOnTaskFailureEnum("onTaskFailure", "body", m.OnTaskFailure); err != nil {
        return err
    }

    return nil
}

func (m *JobSpecification) validatePoolInfo(formats strfmt.Registry) error {

    if err := validate.Required("poolInfo", "body", m.PoolInfo); err != nil {
        return err
    }

    if m.PoolInfo != nil {

        if err := m.PoolInfo.Validate(formats); err != nil {
            return err
        }
    }

    return nil
}