From a0798453c6a219661dac38a2ed9817f260db0dcb Mon Sep 17 00:00:00 2001 From: Daniel De Vera Date: Tue, 16 Jul 2024 08:56:20 -0300 Subject: [PATCH] Addition of jobs traffic manager --- generate/swagger.json | 18 +++++- go.mod | 8 +-- go.sum | 16 ++--- models/job_spec.go | 51 ++++++++++++++++ models/job_traffic_manager.go | 107 ++++++++++++++++++++++++++++++++++ 5 files changed, 187 insertions(+), 13 deletions(-) create mode 100644 models/job_traffic_manager.go diff --git a/generate/swagger.json b/generate/swagger.json index 37ef57a..56ff826 100644 --- a/generate/swagger.json +++ b/generate/swagger.json @@ -355,6 +355,9 @@ "script": { "type": "string" }, + "trafficManager": { + "$ref": "#/definitions/job.TrafficManager" + }, "uploadArtifact": { "items": { "$ref": "#/definitions/job.UploadArtifact" @@ -364,6 +367,19 @@ }, "type": "object" }, + "job.TrafficManager": { + "properties": { + "injectRoutingKey": { + "description": "InjectRoutingKey indicates if the system should perform automatic\ninjection of routing key headers or not. It may be the empty string,\n\"auto\" or \"disabled\". The empty string defaults to meaning \"disabled\".", + "enum": [ + "disabled", + "auto" + ], + "type": "string" + } + }, + "type": "object" + }, "job.UploadArtifact": { "properties": { "meta": { @@ -3662,4 +3678,4 @@ } }, "swagger": "2.0" -} \ No newline at end of file +} diff --git a/go.mod b/go.mod index 7211b63..52ba920 100644 --- a/go.mod +++ b/go.mod @@ -25,10 +25,10 @@ require ( github.com/mitchellh/mapstructure v1.5.0 // indirect github.com/oklog/ulid v1.3.1 // indirect github.com/opentracing/opentracing-go v1.2.0 // indirect - go.mongodb.org/mongo-driver v1.15.1 // indirect - go.opentelemetry.io/otel v1.27.0 // indirect - go.opentelemetry.io/otel/metric v1.27.0 // indirect - go.opentelemetry.io/otel/trace v1.27.0 // indirect + go.mongodb.org/mongo-driver v1.16.0 // indirect + go.opentelemetry.io/otel v1.28.0 // indirect + go.opentelemetry.io/otel/metric v1.28.0 // indirect + go.opentelemetry.io/otel/trace v1.28.0 // indirect golang.org/x/sync v0.7.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/go.sum b/go.sum index f81db49..d48872c 100644 --- a/go.sum +++ b/go.sum @@ -54,16 +54,16 @@ github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+ github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= -go.mongodb.org/mongo-driver v1.15.1 h1:l+RvoUOoMXFmADTLfYDm7On9dRm7p4T80/lEQM+r7HU= -go.mongodb.org/mongo-driver v1.15.1/go.mod h1:Vzb0Mk/pa7e6cWw85R4F/endUC3u0U9jGcNU603k65c= -go.opentelemetry.io/otel v1.27.0 h1:9BZoF3yMK/O1AafMiQTVu0YDj5Ea4hPhxCs7sGva+cg= -go.opentelemetry.io/otel v1.27.0/go.mod h1:DMpAK8fzYRzs+bi3rS5REupisuqTheUlSZJ1WnZaPAQ= -go.opentelemetry.io/otel/metric v1.27.0 h1:hvj3vdEKyeCi4YaYfNjv2NUje8FqKqUY8IlF0FxV/ik= -go.opentelemetry.io/otel/metric v1.27.0/go.mod h1:mVFgmRlhljgBiuk/MP/oKylr4hs85GZAylncepAX/ak= +go.mongodb.org/mongo-driver v1.16.0 h1:tpRsfBJMROVHKpdGyc1BBEzzjDUWjItxbVSZ8Ls4BQ4= +go.mongodb.org/mongo-driver v1.16.0/go.mod h1:oB6AhJQvFQL4LEHyXi6aJzQJtBiTQHiAd83l0GdFaiw= +go.opentelemetry.io/otel v1.28.0 h1:/SqNcYk+idO0CxKEUOtKQClMK/MimZihKYMruSMViUo= +go.opentelemetry.io/otel v1.28.0/go.mod h1:q68ijF8Fc8CnMHKyzqL6akLO46ePnjkgfIMIjUIX9z4= +go.opentelemetry.io/otel/metric v1.28.0 h1:f0HGvSl1KRAU1DLgLGFjrwVyismPlnuU6JD6bOeuA5Q= +go.opentelemetry.io/otel/metric v1.28.0/go.mod h1:Fb1eVBFZmLVTMb6PPohq3TO9IIhUisDsbJoL/+uQW4s= go.opentelemetry.io/otel/sdk v1.24.0 h1:YMPPDNymmQN3ZgczicBY3B6sf9n62Dlj9pWD3ucgoDw= go.opentelemetry.io/otel/sdk v1.24.0/go.mod h1:KVrIYw6tEubO9E96HQpcmpTKDVn9gdv35HoYiQWGDFg= -go.opentelemetry.io/otel/trace v1.27.0 h1:IqYb813p7cmbHk0a5y6pD5JPakbVfftRXABGt5/Rscw= -go.opentelemetry.io/otel/trace v1.27.0/go.mod h1:6RiD1hkAprV4/q+yd2ln1HG9GoPx39SuvvstaLBl+l4= +go.opentelemetry.io/otel/trace v1.28.0 h1:GhQ9cUuQGmNDd5BTCP2dAvv75RdMxEfTmYejp+lkx9g= +go.opentelemetry.io/otel/trace v1.28.0/go.mod h1:jPyXzNPg6da9+38HEwElrQiHlVMTnVfM3/yv2OlIHaI= golang.org/x/sync v0.7.0 h1:YsImfSBoP9QPYL0xyKJPq0gcaJdG3rInoqxTWbfQu9M= golang.org/x/sync v0.7.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= golang.org/x/sys v0.17.0 h1:25cE3gD+tdBA7lp7QfhuV+rJiE9YXTcS3VG1SqssI/Y= diff --git a/models/job_spec.go b/models/job_spec.go index 09b1602..d600db3 100644 --- a/models/job_spec.go +++ b/models/job_spec.go @@ -40,6 +40,9 @@ type JobSpec struct { // script Script string `json:"script,omitempty"` + // traffic manager + TrafficManager *JobTrafficManager `json:"trafficManager,omitempty"` + // upload artifact UploadArtifact []*JobUploadArtifact `json:"uploadArtifact"` } @@ -56,6 +59,10 @@ func (m *JobSpec) Validate(formats strfmt.Registry) error { res = append(res, err) } + if err := m.validateTrafficManager(formats); err != nil { + res = append(res, err) + } + if err := m.validateUploadArtifact(formats); err != nil { res = append(res, err) } @@ -111,6 +118,25 @@ func (m *JobSpec) validateRoutingContext(formats strfmt.Registry) error { return nil } +func (m *JobSpec) validateTrafficManager(formats strfmt.Registry) error { + if swag.IsZero(m.TrafficManager) { // not required + return nil + } + + if m.TrafficManager != nil { + if err := m.TrafficManager.Validate(formats); err != nil { + if ve, ok := err.(*errors.Validation); ok { + return ve.ValidateName("trafficManager") + } else if ce, ok := err.(*errors.CompositeError); ok { + return ce.ValidateName("trafficManager") + } + return err + } + } + + return nil +} + func (m *JobSpec) validateUploadArtifact(formats strfmt.Registry) error { if swag.IsZero(m.UploadArtifact) { // not required return nil @@ -149,6 +175,10 @@ func (m *JobSpec) ContextValidate(ctx context.Context, formats strfmt.Registry) res = append(res, err) } + if err := m.contextValidateTrafficManager(ctx, formats); err != nil { + res = append(res, err) + } + if err := m.contextValidateUploadArtifact(ctx, formats); err != nil { res = append(res, err) } @@ -205,6 +235,27 @@ func (m *JobSpec) contextValidateRoutingContext(ctx context.Context, formats str return nil } +func (m *JobSpec) contextValidateTrafficManager(ctx context.Context, formats strfmt.Registry) error { + + if m.TrafficManager != nil { + + if swag.IsZero(m.TrafficManager) { // not required + return nil + } + + if err := m.TrafficManager.ContextValidate(ctx, formats); err != nil { + if ve, ok := err.(*errors.Validation); ok { + return ve.ValidateName("trafficManager") + } else if ce, ok := err.(*errors.CompositeError); ok { + return ce.ValidateName("trafficManager") + } + return err + } + } + + return nil +} + func (m *JobSpec) contextValidateUploadArtifact(ctx context.Context, formats strfmt.Registry) error { for i := 0; i < len(m.UploadArtifact); i++ { diff --git a/models/job_traffic_manager.go b/models/job_traffic_manager.go new file mode 100644 index 0000000..a4daf79 --- /dev/null +++ b/models/job_traffic_manager.go @@ -0,0 +1,107 @@ +// Code generated by go-swagger; DO NOT EDIT. + +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 ( + "context" + "encoding/json" + + "github.com/go-openapi/errors" + "github.com/go-openapi/strfmt" + "github.com/go-openapi/swag" + "github.com/go-openapi/validate" +) + +// JobTrafficManager job traffic manager +// +// swagger:model job.TrafficManager +type JobTrafficManager struct { + + // InjectRoutingKey indicates if the system should perform automatic + // injection of routing key headers or not. It may be the empty string, + // "auto" or "disabled". The empty string defaults to meaning "disabled". + // Enum: ["disabled","auto"] + InjectRoutingKey string `json:"injectRoutingKey,omitempty"` +} + +// Validate validates this job traffic manager +func (m *JobTrafficManager) Validate(formats strfmt.Registry) error { + var res []error + + if err := m.validateInjectRoutingKey(formats); err != nil { + res = append(res, err) + } + + if len(res) > 0 { + return errors.CompositeValidationError(res...) + } + return nil +} + +var jobTrafficManagerTypeInjectRoutingKeyPropEnum []interface{} + +func init() { + var res []string + if err := json.Unmarshal([]byte(`["disabled","auto"]`), &res); err != nil { + panic(err) + } + for _, v := range res { + jobTrafficManagerTypeInjectRoutingKeyPropEnum = append(jobTrafficManagerTypeInjectRoutingKeyPropEnum, v) + } +} + +const ( + + // JobTrafficManagerInjectRoutingKeyDisabled captures enum value "disabled" + JobTrafficManagerInjectRoutingKeyDisabled string = "disabled" + + // JobTrafficManagerInjectRoutingKeyAuto captures enum value "auto" + JobTrafficManagerInjectRoutingKeyAuto string = "auto" +) + +// prop value enum +func (m *JobTrafficManager) validateInjectRoutingKeyEnum(path, location string, value string) error { + if err := validate.EnumCase(path, location, value, jobTrafficManagerTypeInjectRoutingKeyPropEnum, true); err != nil { + return err + } + return nil +} + +func (m *JobTrafficManager) validateInjectRoutingKey(formats strfmt.Registry) error { + if swag.IsZero(m.InjectRoutingKey) { // not required + return nil + } + + // value enum + if err := m.validateInjectRoutingKeyEnum("injectRoutingKey", "body", m.InjectRoutingKey); err != nil { + return err + } + + return nil +} + +// ContextValidate validates this job traffic manager based on context it is used +func (m *JobTrafficManager) ContextValidate(ctx context.Context, formats strfmt.Registry) error { + return nil +} + +// MarshalBinary interface implementation +func (m *JobTrafficManager) MarshalBinary() ([]byte, error) { + if m == nil { + return nil, nil + } + return swag.WriteJSON(m) +} + +// UnmarshalBinary interface implementation +func (m *JobTrafficManager) UnmarshalBinary(b []byte) error { + var res JobTrafficManager + if err := swag.ReadJSON(b, &res); err != nil { + return err + } + *m = res + return nil +}