jkawamoto/roadie

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

Summary

Maintainability
A
2 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"
)

// JobUpdateParameter The set of changes to be made to a job.
// swagger:model JobUpdateParameter
type JobUpdateParameter struct {

    // The execution constraints for the job.
    //
    // If omitted, the constraints are cleared.
    Constraints *JobConstraints `json:"constraints,omitempty"`

    // A list of name-value pairs associated with the job as metadata.
    //
    // If omitted, it takes the default value of an empty list; in effect, any existing metadata is deleted.
    Metadata []*MetadataItem `json:"metadata"`

    // Specifies an action the Batch service should take when all tasks in the job are in the completed state.
    //
    // If omitted, the completion behavior is set to noaction. If the current value is terminatejob, this is an error because a job's completion behavior may not be changed from terminatejob to noaction.
    OnAllTasksComplete string `json:"onAllTasksComplete,omitempty"`

    // The pool on which the Batch service runs the job's tasks.
    //
    // You may change the pool for a job only when the job is disabled. The Update Job call will fail if you include the poolInfo element and the job is not disabled. If you specify an autoPoolSpecification specification in the poolInfo, only the keepAlive property can be updated, and then only if the auto pool has a poolLifetimeOption of job.
    // Required: true
    PoolInfo *PoolInformation `json:"poolInfo"`

    // The priority of the job.
    //
    // Priority values can range from -1000 to 1000, with -1000 being the lowest priority and 1000 being the highest priority. If omitted, it is set to the default value 0.
    Priority int32 `json:"priority,omitempty"`
}

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

    if err := m.validateConstraints(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.validatePoolInfo(formats); err != nil {
        // prop
        res = append(res, err)
    }

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

func (m *JobUpdateParameter) 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 *JobUpdateParameter) 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 jobUpdateParameterTypeOnAllTasksCompletePropEnum []interface{}

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

const (
    // JobUpdateParameterOnAllTasksCompleteNoAction captures enum value "noAction"
    JobUpdateParameterOnAllTasksCompleteNoAction string = "noAction"
    // JobUpdateParameterOnAllTasksCompleteTerminateJob captures enum value "terminateJob"
    JobUpdateParameterOnAllTasksCompleteTerminateJob string = "terminateJob"
)

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

func (m *JobUpdateParameter) 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
}

func (m *JobUpdateParameter) 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
}