Skip to content

Commit

Permalink
Merge branch 'main' into user/connievi/failover-priority
Browse files Browse the repository at this point in the history
  • Loading branch information
connievi authored Oct 17, 2024
2 parents 2208f57 + 264b820 commit 3ca95c1
Show file tree
Hide file tree
Showing 15 changed files with 1,525 additions and 262 deletions.
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ require (
github.com/jmespath/go-jmespath v0.4.0
github.com/pkg/errors v0.9.1
github.com/stretchr/testify v1.8.3
go.uber.org/multierr v1.11.0
google.golang.org/grpc v1.59.0
gopkg.in/yaml.v3 v3.0.1
)
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ github.com/stretchr/testify v1.8.3 h1:RP3t2pwF7cMEbC1dqtB6poj3niw/9gnV4Cjg5oW5gt
github.com/stretchr/testify v1.8.3/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
go.uber.org/multierr v1.11.0 h1:blXXJkSxSSfBVBlC76pxqeO+LN3aDfLQo+309xJstO0=
go.uber.org/multierr v1.11.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN80Y=
golang.org/x/crypto v0.17.0/go.mod h1:gCAAfMLgwOJRpTjQ2zCCt2OcSfYMTeZVSRtQlPC7Nq4=
golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
Expand Down
89 changes: 89 additions & 0 deletions pkg/errors/codes/codes.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the Apache v2.0 license.
package codes

import "strings"

// MocCode - error codes used by MOC
type MocCode uint32

const (
OK MocCode = iota
NotFound
Degraded
InvalidConfiguration
InvalidInput
InvalidType
NotSupported
AlreadyExists
InUse
Duplicates
InvalidFilter
Failed
InvalidGroup
InvalidVersion
OldVersion
OutOfCapacity
OutOfNodeCapacity
OutOfMemory
UpdateFailed
NotInitialized
NotImplemented
OutOfRange
AlreadySet
NotSet
InconsistentState
PendingState
WrongHost
PoolFull
NoActionTaken
Expired
Revoked
Timeout
RunCommandFailed
InvalidToken
Unknown
DeleteFailed
DeletePending
FileNotFound
PathNotFound
NotEnoughSpace
AccessDenied
BlobNotFound
GenericFailure
NoAuthenticationInformation
MeasurementUnitError
QuotaViolation
IPOutOfRange

// This is not a valid code, it is used to get the maximum code value.
// Any new codes should be defined above this.
_maxCode
)

// IsValid - check if the code is a valid MocCode.
func (c MocCode) IsValid() bool {
if c >= _maxCode {
return false
}

// Check if the string has been defined for the code.
if strings.Contains(c.String(), "MocCode") {
return false
}

return true
}

func (c MocCode) ToUint32() uint32 {
return uint32(c)
}

// Convert an uint32 to a MocCode. If the uint32 is not a valid MocCode, return Unknown.
func Convert(code uint32) MocCode {
c := MocCode(code)
if !c.IsValid() {
return Unknown
}
return c
}
109 changes: 109 additions & 0 deletions pkg/errors/codes/codes_string.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the Apache v2.0 license.
package codes

import (
"strconv"
)

// String returns the string representation of the MocCode
func (c MocCode) String() string {
switch c {
case OK:
return ""
case NotFound:
return "NotFound"
case Degraded:
return "Degraded"
case InvalidConfiguration:
return "InvalidConfiguration"
case InvalidInput:
return "InvalidInput"
case InvalidType:
return "InvalidType"
case NotSupported:
return "NotSupported"
case AlreadyExists:
return "AlreadyExists"
case InUse:
return "InUse"
case Duplicates:
return "Duplicates"
case InvalidFilter:
return "InvalidFilter"
case Failed:
return "Failed"
case InvalidGroup:
return "InvalidGroup"
case InvalidVersion:
return "InvalidVersion"
case OldVersion:
return "OldVersion"
case OutOfCapacity:
return "OutOfCapacity"
case OutOfNodeCapacity:
return "OutOfNodeCapacity"
case OutOfMemory:
return "OutOfMemory"
case UpdateFailed:
return "UpdateFailed"
case NotInitialized:
return "NotInitialized"
case NotImplemented:
return "NotImplemented"
case OutOfRange:
return "OutOfRange"
case AlreadySet:
return "AlreadySet"
case NotSet:
return "NotSet"
case InconsistentState:
return "InconsistentState"
case PendingState:
return "PendingState"
case WrongHost:
return "WrongHost"
case PoolFull:
return "PoolFull"
case NoActionTaken:
return "NoActionTaken"
case Expired:
return "Expired"
case Revoked:
return "Revoked"
case Timeout:
return "Timeout"
case RunCommandFailed:
return "RunCommandFailed"
case InvalidToken:
return "InvalidToken"
case Unknown:
return "Unknown"
case DeleteFailed:
return "DeleteFailed"
case DeletePending:
return "DeletePending"
case FileNotFound:
return "FileNotFound"
case PathNotFound:
return "PathNotFound"
case NotEnoughSpace:
return "NotEnoughSpace"
case AccessDenied:
return "AccessDenied"
case BlobNotFound:
return "BlobNotFound"
case GenericFailure:
return "GenericFailure"
case NoAuthenticationInformation:
return "NoAuthenticationInformation"
case MeasurementUnitError:
return "MeasurementUnitError"
case QuotaViolation:
return "QuotaViolation"
case IPOutOfRange:
return "IPOutOfRange"
default:
return "MocCode(" + strconv.FormatUint(uint64(c), 10) + ")"
}
}
16 changes: 16 additions & 0 deletions pkg/errors/codes/codes_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package codes

import (
"testing"
)

func TestErrorMessages(t *testing.T) {
// Test that all error codes have a corresponding message
maxMocCode := int(_maxCode) - 1
for i := 0; i <= maxMocCode; i++ {
mocCode := MocCode(i)
if !mocCode.IsValid() {
t.Errorf("MocCode %d is not valid, ensure that it has been assigned a string and error code", mocCode)
}
}
}
Loading

0 comments on commit 3ca95c1

Please sign in to comment.