jkawamoto/roadie

View on GitHub
cloud/azure/batch/models/job_patch_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"
)

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

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

    // A list of name-value pairs associated with the job as metadata.
    //
    // If omitted, the existing job metadata is left unchanged.
    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 left unchanged. You may not change the value from terminatejob to noaction – that is, once you have engaged automatic job termination, you cannot turn it off again. If you try to do this, the request fails with an 'invalid property value' error response; if you are calling the REST API directly, the HTTP status code is 400 (Bad Request).
    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 Patch 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. If omitted, the job continues to run on its current pool.
    PoolInfo *PoolInformation `json:"poolInfo,omitempty"`

    // 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, the priority of the job is left unchanged.
    Priority int32 `json:"priority,omitempty"`
}

// Validate validates this job patch parameter
func (m *JobPatchParameter) 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 *JobPatchParameter) 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 *JobPatchParameter) 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 jobPatchParameterTypeOnAllTasksCompletePropEnum []interface{}

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

const (
    // JobPatchParameterOnAllTasksCompleteNoAction captures enum value "noAction"
    JobPatchParameterOnAllTasksCompleteNoAction string = "noAction"
    // JobPatchParameterOnAllTasksCompleteTerminateJob captures enum value "terminateJob"
    JobPatchParameterOnAllTasksCompleteTerminateJob string = "terminateJob"
)

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

func (m *JobPatchParameter) 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 *JobPatchParameter) validatePoolInfo(formats strfmt.Registry) error {

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

    if m.PoolInfo != nil {

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

    return nil
}