Skip to content

Commit

Permalink
Rename TryAgainLater status code to ServerTimeout
Browse files Browse the repository at this point in the history
  • Loading branch information
smarterclayton committed Feb 12, 2015
1 parent 3bc8f4e commit c24f4a2
Show file tree
Hide file tree
Showing 10 changed files with 31 additions and 31 deletions.
18 changes: 9 additions & 9 deletions pkg/api/errors/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ const (
StatusUnprocessableEntity = 422
StatusTooManyRequests = 429
// HTTP recommendations are for servers to define 5xx error codes
// for scenarios not covered by behavior. In this case, TryAgainLater
// for scenarios not covered by behavior. In this case, ServerTimeout
// is an indication that a transient server error has occured and the
// client *should* retry, with an optional Retry-After header to specify
// the back off window.
StatusTryAgainLater = 504
StatusServerTimeout = 504
)

// StatusError is an error intended for consumption by a REST API server; it can also be
Expand Down Expand Up @@ -180,13 +180,13 @@ func NewMethodNotSupported(kind, action string) error {
}}
}

// NewTryAgainLater returns an error indicating the requested action could not be completed due to a
// NewServerTimeout returns an error indicating the requested action could not be completed due to a
// transient error, and the client should try again.
func NewTryAgainLater(kind, operation string) error {
func NewServerTimeout(kind, operation string) error {
return &StatusError{api.Status{
Status: api.StatusFailure,
Code: http.StatusInternalServerError,
Reason: api.StatusReasonTryAgainLater,
Reason: api.StatusReasonServerTimeout,
Details: &api.StatusDetails{
Kind: kind,
ID: operation,
Expand All @@ -213,7 +213,7 @@ func NewInternalError(err error) error {
func NewTimeoutError(message string) error {
return &StatusError{api.Status{
Status: api.StatusFailure,
Code: StatusTryAgainLater,
Code: StatusServerTimeout,
Reason: api.StatusReasonTimeout,
Message: fmt.Sprintf("Timeout: %s", message),
}}
Expand Down Expand Up @@ -256,10 +256,10 @@ func IsForbidden(err error) bool {
return reasonForError(err) == api.StatusReasonForbidden
}

// IsTryAgainLater determines if err is an error which indicates that the request needs to be retried
// IsServerTimeout determines if err is an error which indicates that the request needs to be retried
// by the client.
func IsTryAgainLater(err error) bool {
return reasonForError(err) == api.StatusReasonTryAgainLater
func IsServerTimeout(err error) bool {
return reasonForError(err) == api.StatusReasonServerTimeout
}

func reasonForError(err error) api.StatusReason {
Expand Down
8 changes: 4 additions & 4 deletions pkg/api/errors/errors_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ func TestErrorNew(t *testing.T) {
if IsForbidden(err) {
t.Errorf("expected to not be %s", api.StatusReasonForbidden)
}
if IsTryAgainLater(err) {
t.Errorf("expected to not be %s", api.StatusReasonTryAgainLater)
if IsServerTimeout(err) {
t.Errorf("expected to not be %s", api.StatusReasonServerTimeout)
}
if IsMethodNotSupported(err) {
t.Errorf("expected to not be %s", api.StatusReasonMethodNotAllowed)
Expand All @@ -68,8 +68,8 @@ func TestErrorNew(t *testing.T) {
if !IsForbidden(NewForbidden("test", "2", errors.New("reason"))) {
t.Errorf("expected to be %s", api.StatusReasonForbidden)
}
if !IsTryAgainLater(NewTryAgainLater("test", "reason")) {
t.Errorf("expected to be %s", api.StatusReasonTryAgainLater)
if !IsServerTimeout(NewServerTimeout("test", "reason")) {
t.Errorf("expected to be %s", api.StatusReasonServerTimeout)
}
if !IsMethodNotSupported(NewMethodNotSupported("foo", "delete")) {
t.Errorf("expected to be %s", api.StatusReasonMethodNotAllowed)
Expand Down
2 changes: 1 addition & 1 deletion pkg/api/rest/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ func CheckGeneratedNameError(strategy RESTCreateStrategy, err error, obj runtime
return err
}

return errors.NewTryAgainLater(kind, "POST")
return errors.NewServerTimeout(kind, "POST")
}

// objectMetaAndKind retrieves kind and ObjectMeta from a runtime object, or returns an error.
Expand Down
2 changes: 1 addition & 1 deletion pkg/api/rest/create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func TestCheckGeneratedNameError(t *testing.T) {
}

expect = errors.NewAlreadyExists("foo", "bar")
if err := CheckGeneratedNameError(Pods, expect, &api.Pod{ObjectMeta: api.ObjectMeta{GenerateName: "foo"}}); err == nil || !errors.IsTryAgainLater(err) {
if err := CheckGeneratedNameError(Pods, expect, &api.Pod{ObjectMeta: api.ObjectMeta{GenerateName: "foo"}}); err == nil || !errors.IsServerTimeout(err) {
t.Errorf("expected try again later error: %v", err)
}
}
6 changes: 3 additions & 3 deletions pkg/api/rest/resttest/resttest.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func copyOrDie(obj runtime.Object) runtime.Object {
func (t *Tester) TestCreate(valid runtime.Object, invalid ...runtime.Object) {
t.TestCreateHasMetadata(copyOrDie(valid))
t.TestCreateGeneratesName(copyOrDie(valid))
t.TestCreateGeneratesNameReturnsTryAgain(copyOrDie(valid))
t.TestCreateGeneratesNameReturnsServerTimeout(copyOrDie(valid))
if t.clusterScope {
t.TestCreateRejectsNamespace(copyOrDie(valid))
} else {
Expand Down Expand Up @@ -140,7 +140,7 @@ func (t *Tester) TestCreateGeneratesName(valid runtime.Object) {
}
}

func (t *Tester) TestCreateGeneratesNameReturnsTryAgain(valid runtime.Object) {
func (t *Tester) TestCreateGeneratesNameReturnsServerTimeout(valid runtime.Object) {
objectMeta, err := api.ObjectMetaFor(valid)
if err != nil {
t.Fatalf("object does not have ObjectMeta: %v\n%#v", err, valid)
Expand All @@ -149,7 +149,7 @@ func (t *Tester) TestCreateGeneratesNameReturnsTryAgain(valid runtime.Object) {
objectMeta.GenerateName = "test-"
t.withStorageError(errors.NewAlreadyExists("kind", "thing"), func() {
_, err := t.storage.(apiserver.RESTCreater).Create(api.NewDefaultContext(), valid)
if err == nil || !errors.IsTryAgainLater(err) {
if err == nil || !errors.IsServerTimeout(err) {
t.Fatalf("Unexpected error: %v", err)
}
})
Expand Down
6 changes: 3 additions & 3 deletions pkg/api/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ type ObjectMeta struct {
//
// If this field is specified, and Name is not present, the server will NOT return a 409 if the
// generated name exists - instead, it will either return 201 Created or 500 with Reason
// TryAgainLater indicating a unique name could not be found in the time allotted, and the client
// ServerTimeout indicating a unique name could not be found in the time allotted, and the client
// should retry (optionally after the time indicated in the Retry-After header).
GenerateName string `json:"generateName,omitempty"`

Expand Down Expand Up @@ -999,7 +999,7 @@ const (
// Status code 422
StatusReasonInvalid StatusReason = "Invalid"

// StatusReasonTryAgainLater means the server can be reached and understood the request,
// StatusReasonServerTimeout means the server can be reached and understood the request,
// but cannot complete the action in a reasonable time. The client should retry the request.
// This is may be due to temporary server load or a transient communication issue with
// another server. Status code 500 is used because the HTTP spec provides no suitable
Expand All @@ -1008,7 +1008,7 @@ const (
// "kind" string - the kind attribute of the resource being acted on.
// "id" string - the operation that is being attempted.
// Status code 500
StatusReasonTryAgainLater StatusReason = "TryAgainLater"
StatusReasonServerTimeout StatusReason = "ServerTimeout"

// StatusReasonTimeout means that the request could not be completed within the given time.
// Clients can get this response only when they specified a timeout param in the request.
Expand Down
6 changes: 3 additions & 3 deletions pkg/api/v1beta1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ type TypeMeta struct {
//
// If this field is specified, and Name is not present, the server will NOT return a 409 if the
// generated name exists - instead, it will either return 201 Created or 500 with Reason
// TryAgainLater indicating a unique name could not be found in the time allotted, and the client
// ServerTimeout indicating a unique name could not be found in the time allotted, and the client
// should retry (optionally after the time indicated in the Retry-After header).
GenerateName string `json:"generateName,omitempty" description:"an optional prefix to use to generate a unique name; has the same validation rules as name; optional, and is applied only name if is not specified"`

Expand Down Expand Up @@ -804,7 +804,7 @@ const (
// Status code 409
StatusReasonConflict StatusReason = "Conflict"

// StatusReasonTryAgainLater means the server can be reached and understood the request,
// StatusReasonServerTimeout means the server can be reached and understood the request,
// but cannot complete the action in a reasonable time. The client should retry the request.
// This is may be due to temporary server load or a transient communication issue with
// another server. Status code 500 is used because the HTTP spec provides no suitable
Expand All @@ -813,7 +813,7 @@ const (
// "kind" string - the kind attribute of the resource being acted on.
// "id" string - the operation that is being attempted.
// Status code 500
StatusReasonTryAgainLater StatusReason = "TryAgainLater"
StatusReasonServerTimeout StatusReason = "ServerTimeout"
)

// StatusCause provides more information about an api.Status failure, including
Expand Down
6 changes: 3 additions & 3 deletions pkg/api/v1beta2/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ type TypeMeta struct {
//
// If this field is specified, and Name is not present, the server will NOT return a 409 if the
// generated name exists - instead, it will either return 201 Created or 500 with Reason
// TryAgainLater indicating a unique name could not be found in the time allotted, and the client
// ServerTimeout indicating a unique name could not be found in the time allotted, and the client
// should retry (optionally after the time indicated in the Retry-After header).
GenerateName string `json:"generateName,omitempty" description:"an optional prefix to use to generate a unique name; has the same validation rules as name; optional, and is applied only name if is not specified"`

Expand Down Expand Up @@ -778,7 +778,7 @@ const (
// Status code 422
StatusReasonInvalid StatusReason = "Invalid"

// StatusReasonTryAgainLater means the server can be reached and understood the request,
// StatusReasonServerTimeout means the server can be reached and understood the request,
// but cannot complete the action in a reasonable time. The client should retry the request.
// This is may be due to temporary server load or a transient communication issue with
// another server. Status code 500 is used because the HTTP spec provides no suitable
Expand All @@ -787,7 +787,7 @@ const (
// "kind" string - the kind attribute of the resource being acted on.
// "id" string - the operation that is being attempted.
// Status code 500
StatusReasonTryAgainLater StatusReason = "TryAgainLater"
StatusReasonServerTimeout StatusReason = "ServerTimeout"
)

// StatusCause provides more information about an api.Status failure, including
Expand Down
6 changes: 3 additions & 3 deletions pkg/api/v1beta3/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ type ObjectMeta struct {
//
// If this field is specified, and Name is not present, the server will NOT return a 409 if the
// generated name exists - instead, it will either return 201 Created or 500 with Reason
// TryAgainLater indicating a unique name could not be found in the time allotted, and the client
// ServerTimeout indicating a unique name could not be found in the time allotted, and the client
// should retry (optionally after the time indicated in the Retry-After header).
GenerateName string `json:"generateName,omitempty" description:"an optional prefix to use to generate a unique name; has the same validation rules as name; optional, and is applied only name if is not specified"`

Expand Down Expand Up @@ -1003,7 +1003,7 @@ const (
// Status code 422
StatusReasonInvalid StatusReason = "Invalid"

// StatusReasonTryAgainLater means the server can be reached and understood the request,
// StatusReasonServerTimeout means the server can be reached and understood the request,
// but cannot complete the action in a reasonable time. The client should retry the request.
// This is may be due to temporary server load or a transient communication issue with
// another server. Status code 500 is used because the HTTP spec provides no suitable
Expand All @@ -1012,7 +1012,7 @@ const (
// "kind" string - the kind attribute of the resource being acted on.
// "id" string - the operation that is being attempted.
// Status code 500
StatusReasonTryAgainLater StatusReason = "TryAgainLater"
StatusReasonServerTimeout StatusReason = "ServerTimeout"
)

// StatusCause provides more information about an api.Status failure, including
Expand Down
2 changes: 1 addition & 1 deletion pkg/apiserver/apiserver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1147,7 +1147,7 @@ func TestCreateTimeout(t *testing.T) {

simple := &Simple{Other: "foo"}
data, _ := codec.Encode(simple)
itemOut := expectApiStatus(t, "POST", server.URL+"/prefix/version/foo?timeout=4ms", data, apierrs.StatusTryAgainLater)
itemOut := expectApiStatus(t, "POST", server.URL+"/prefix/version/foo?timeout=4ms", data, apierrs.StatusServerTimeout)
if itemOut.Status != api.StatusFailure || itemOut.Reason != api.StatusReasonTimeout {
t.Errorf("Unexpected status %#v", itemOut)
}
Expand Down

0 comments on commit c24f4a2

Please sign in to comment.