Skip to content

Commit

Permalink
Merge pull request kubernetes#4263 from smarterclayton/simplify_apise…
Browse files Browse the repository at this point in the history
…rver

Remove layers of indirection between apiinstaller and resthandler
  • Loading branch information
smarterclayton committed Feb 12, 2015
2 parents 371349f + e6fdac1 commit 0a2d713
Show file tree
Hide file tree
Showing 31 changed files with 1,121 additions and 939 deletions.
17 changes: 17 additions & 0 deletions pkg/api/errors/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ import (
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
// 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
)

// StatusError is an error intended for consumption by a REST API server; it can also be
Expand Down Expand Up @@ -202,6 +208,17 @@ func NewInternalError(err error) error {
}}
}

// NewTimeoutError returns an error indicating that a timeout occurred before the request
// could be completed. Clients may retry, but the operation may still complete.
func NewTimeoutError(message string) error {
return &StatusError{api.Status{
Status: api.StatusFailure,
Code: StatusTryAgainLater,
Reason: api.StatusReasonTimeout,
Message: fmt.Sprintf("Timeout: %s", message),
}}
}

// IsNotFound returns true if the specified error was created by NewNotFoundErr.
func IsNotFound(err error) bool {
return reasonForError(err) == api.StatusReasonNotFound
Expand Down
20 changes: 8 additions & 12 deletions pkg/api/rest/resttest/resttest.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,12 @@ func (t *Tester) TestCreateResetsUserData(valid runtime.Object) {
objectMeta.UID = "bad-uid"
objectMeta.CreationTimestamp = now

channel, err := t.storage.(apiserver.RESTCreater).Create(api.NewDefaultContext(), valid)
obj, err := t.storage.(apiserver.RESTCreater).Create(api.NewDefaultContext(), valid)
if err != nil {
t.Fatalf("Unexpected error: %v", err)
}
if obj := <-channel; obj.Object == nil {
t.Fatalf("Unexpected object from channel: %#v", obj)
if obj == nil {
t.Fatalf("Unexpected object from result: %#v", obj)
}
if objectMeta.UID == "bad-uid" || objectMeta.CreationTimestamp == now {
t.Errorf("ObjectMeta did not reset basic fields: %#v", objectMeta)
Expand All @@ -111,12 +111,12 @@ func (t *Tester) TestCreateHasMetadata(valid runtime.Object) {
context = api.NewContext()
}

channel, err := t.storage.(apiserver.RESTCreater).Create(context, valid)
obj, err := t.storage.(apiserver.RESTCreater).Create(context, valid)
if err != nil {
t.Fatalf("Unexpected error: %v", err)
}
if obj := <-channel; obj.Object == nil {
t.Fatalf("Unexpected object from channel: %#v", obj)
if obj == nil {
t.Fatalf("Unexpected object from result: %#v", obj)
}
if !api.HasObjectMetaSystemFieldValues(objectMeta) {
t.Errorf("storage did not populate object meta field values")
Expand Down Expand Up @@ -148,12 +148,8 @@ func (t *Tester) TestCreateGeneratesNameReturnsTryAgain(valid runtime.Object) {

objectMeta.GenerateName = "test-"
t.withStorageError(errors.NewAlreadyExists("kind", "thing"), func() {
ch, err := t.storage.(apiserver.RESTCreater).Create(api.NewDefaultContext(), valid)
if err != nil {
t.Fatalf("Unexpected error: %v", err)
}
res := <-ch
if err := errors.FromObject(res.Object); err == nil || !errors.IsTryAgainLater(err) {
_, err := t.storage.(apiserver.RESTCreater).Create(api.NewDefaultContext(), valid)
if err == nil || !errors.IsTryAgainLater(err) {
t.Fatalf("Unexpected error: %v", err)
}
})
Expand Down
Loading

0 comments on commit 0a2d713

Please sign in to comment.