-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into user/connievi/failover-priority
- Loading branch information
Showing
15 changed files
with
1,525 additions
and
262 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) + ")" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} | ||
} |
Oops, something went wrong.