Merge pull request #1217 from lavalamp/fixApi

Rename all XStorage types to REST for clarity
This commit is contained in:
Tim Hockin 2014-09-08 15:38:47 -07:00
commit 81b502b0a6
13 changed files with 149 additions and 147 deletions

View File

@ -114,19 +114,19 @@ func (m *Master) init(cloud cloudprovider.Interface, podInfoGetter client.PodInf
go util.Forever(func() { endpoints.SyncServiceEndpoints() }, time.Second*10) go util.Forever(func() { endpoints.SyncServiceEndpoints() }, time.Second*10)
m.storage = map[string]apiserver.RESTStorage{ m.storage = map[string]apiserver.RESTStorage{
"pods": pod.NewRegistryStorage(&pod.RegistryStorageConfig{ "pods": pod.NewREST(&pod.RESTConfig{
CloudProvider: cloud, CloudProvider: cloud,
PodCache: podCache, PodCache: podCache,
PodInfoGetter: podInfoGetter, PodInfoGetter: podInfoGetter,
Registry: m.podRegistry, Registry: m.podRegistry,
}), }),
"replicationControllers": controller.NewRegistryStorage(m.controllerRegistry, m.podRegistry), "replicationControllers": controller.NewREST(m.controllerRegistry, m.podRegistry),
"services": service.NewRegistryStorage(m.serviceRegistry, cloud, m.minionRegistry), "services": service.NewREST(m.serviceRegistry, cloud, m.minionRegistry),
"endpoints": endpoint.NewStorage(m.endpointRegistry), "endpoints": endpoint.NewREST(m.endpointRegistry),
"minions": minion.NewRegistryStorage(m.minionRegistry), "minions": minion.NewREST(m.minionRegistry),
// TODO: should appear only in scheduler API group. // TODO: should appear only in scheduler API group.
"bindings": binding.NewBindingStorage(m.bindingRegistry), "bindings": binding.NewREST(m.bindingRegistry),
} }
} }

View File

@ -26,42 +26,42 @@ import (
"github.com/GoogleCloudPlatform/kubernetes/pkg/runtime" "github.com/GoogleCloudPlatform/kubernetes/pkg/runtime"
) )
// BindingStorage implements the RESTStorage interface. When bindings are written, it // REST implements the RESTStorage interface for bindings. When bindings are written, it
// changes the location of the affected pods. This information is eventually reflected // changes the location of the affected pods. This information is eventually reflected
// in the pod's CurrentState.Host field. // in the pod's CurrentState.Host field.
type BindingStorage struct { type REST struct {
registry Registry registry Registry
} }
// NewBindingStorage creates a new BindingStorage backed by the given bindingRegistry. // NewREST creates a new REST backed by the given bindingRegistry.
func NewBindingStorage(bindingRegistry Registry) *BindingStorage { func NewREST(bindingRegistry Registry) *REST {
return &BindingStorage{ return &REST{
registry: bindingRegistry, registry: bindingRegistry,
} }
} }
// List returns an error because bindings are write-only objects. // List returns an error because bindings are write-only objects.
func (*BindingStorage) List(selector labels.Selector) (runtime.Object, error) { func (*REST) List(selector labels.Selector) (runtime.Object, error) {
return nil, errors.NewNotFound("binding", "list") return nil, errors.NewNotFound("binding", "list")
} }
// Get returns an error because bindings are write-only objects. // Get returns an error because bindings are write-only objects.
func (*BindingStorage) Get(id string) (runtime.Object, error) { func (*REST) Get(id string) (runtime.Object, error) {
return nil, errors.NewNotFound("binding", id) return nil, errors.NewNotFound("binding", id)
} }
// Delete returns an error because bindings are write-only objects. // Delete returns an error because bindings are write-only objects.
func (*BindingStorage) Delete(id string) (<-chan runtime.Object, error) { func (*REST) Delete(id string) (<-chan runtime.Object, error) {
return nil, errors.NewNotFound("binding", id) return nil, errors.NewNotFound("binding", id)
} }
// New returns a new binding object fit for having data unmarshalled into it. // New returns a new binding object fit for having data unmarshalled into it.
func (*BindingStorage) New() runtime.Object { func (*REST) New() runtime.Object {
return &api.Binding{} return &api.Binding{}
} }
// Create attempts to make the assignment indicated by the binding it recieves. // Create attempts to make the assignment indicated by the binding it recieves.
func (b *BindingStorage) Create(obj runtime.Object) (<-chan runtime.Object, error) { func (b *REST) Create(obj runtime.Object) (<-chan runtime.Object, error) {
binding, ok := obj.(*api.Binding) binding, ok := obj.(*api.Binding)
if !ok { if !ok {
return nil, fmt.Errorf("incorrect type: %#v", obj) return nil, fmt.Errorf("incorrect type: %#v", obj)
@ -75,6 +75,6 @@ func (b *BindingStorage) Create(obj runtime.Object) (<-chan runtime.Object, erro
} }
// Update returns an error-- this object may not be updated. // Update returns an error-- this object may not be updated.
func (b *BindingStorage) Update(obj runtime.Object) (<-chan runtime.Object, error) { func (b *REST) Update(obj runtime.Object) (<-chan runtime.Object, error) {
return nil, fmt.Errorf("Bindings may not be changed.") return nil, fmt.Errorf("Bindings may not be changed.")
} }

View File

@ -28,11 +28,11 @@ import (
"github.com/GoogleCloudPlatform/kubernetes/pkg/runtime" "github.com/GoogleCloudPlatform/kubernetes/pkg/runtime"
) )
func TestNewBindingStorage(t *testing.T) { func TestNewREST(t *testing.T) {
mockRegistry := MockRegistry{ mockRegistry := MockRegistry{
OnApplyBinding: func(b *api.Binding) error { return nil }, OnApplyBinding: func(b *api.Binding) error { return nil },
} }
b := NewBindingStorage(mockRegistry) b := NewREST(mockRegistry)
binding := &api.Binding{ binding := &api.Binding{
PodID: "foo", PodID: "foo",
@ -52,11 +52,11 @@ func TestNewBindingStorage(t *testing.T) {
} }
} }
func TestBindingStorageUnsupported(t *testing.T) { func TestRESTUnsupported(t *testing.T) {
mockRegistry := MockRegistry{ mockRegistry := MockRegistry{
OnApplyBinding: func(b *api.Binding) error { return nil }, OnApplyBinding: func(b *api.Binding) error { return nil },
} }
b := NewBindingStorage(mockRegistry) b := NewREST(mockRegistry)
if _, err := b.Delete("binding id"); err == nil { if _, err := b.Delete("binding id"); err == nil {
t.Errorf("unexpected non-error") t.Errorf("unexpected non-error")
} }
@ -75,7 +75,7 @@ func TestBindingStorageUnsupported(t *testing.T) {
} }
} }
func TestBindingStoragePost(t *testing.T) { func TestRESTPost(t *testing.T) {
table := []struct { table := []struct {
b *api.Binding b *api.Binding
err error err error
@ -94,7 +94,7 @@ func TestBindingStoragePost(t *testing.T) {
return item.err return item.err
}, },
} }
b := NewBindingStorage(mockRegistry) b := NewREST(mockRegistry)
resultChan, err := b.Create(item.b) resultChan, err := b.Create(item.b)
if err != nil { if err != nil {
t.Errorf("Unexpected error %v", err) t.Errorf("Unexpected error %v", err)

View File

@ -25,7 +25,6 @@ import (
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/validation" "github.com/GoogleCloudPlatform/kubernetes/pkg/api/validation"
"github.com/GoogleCloudPlatform/kubernetes/pkg/apiserver" "github.com/GoogleCloudPlatform/kubernetes/pkg/apiserver"
"github.com/GoogleCloudPlatform/kubernetes/pkg/labels" "github.com/GoogleCloudPlatform/kubernetes/pkg/labels"
"github.com/GoogleCloudPlatform/kubernetes/pkg/registry/pod"
"github.com/GoogleCloudPlatform/kubernetes/pkg/runtime" "github.com/GoogleCloudPlatform/kubernetes/pkg/runtime"
"github.com/GoogleCloudPlatform/kubernetes/pkg/util" "github.com/GoogleCloudPlatform/kubernetes/pkg/util"
"github.com/GoogleCloudPlatform/kubernetes/pkg/watch" "github.com/GoogleCloudPlatform/kubernetes/pkg/watch"
@ -33,26 +32,29 @@ import (
"code.google.com/p/go-uuid/uuid" "code.google.com/p/go-uuid/uuid"
) )
// RegistryStorage stores data for the replication controller service. // PodLister is anything that knows how to list pods.
// It implements apiserver.RESTStorage. type PodLister interface {
type RegistryStorage struct { ListPods(labels.Selector) (*api.PodList, error)
registry Registry
podRegistry pod.Registry
pollPeriod time.Duration
} }
// NewRegistryStorage returns a new apiserver.RESTStorage for the given // REST implements apiserver.RESTStorage for the replication controller service.
// registry and podRegistry. type REST struct {
func NewRegistryStorage(registry Registry, podRegistry pod.Registry) apiserver.RESTStorage { registry Registry
return &RegistryStorage{ podLister PodLister
registry: registry, pollPeriod time.Duration
podRegistry: podRegistry, }
pollPeriod: time.Second * 10,
// NewREST returns a new apiserver.RESTStorage for the given registry and PodLister.
func NewREST(registry Registry, podLister PodLister) *REST {
return &REST{
registry: registry,
podLister: podLister,
pollPeriod: time.Second * 10,
} }
} }
// Create registers the given ReplicationController. // Create registers the given ReplicationController.
func (rs *RegistryStorage) Create(obj runtime.Object) (<-chan runtime.Object, error) { func (rs *REST) Create(obj runtime.Object) (<-chan runtime.Object, error) {
controller, ok := obj.(*api.ReplicationController) controller, ok := obj.(*api.ReplicationController)
if !ok { if !ok {
return nil, fmt.Errorf("not a replication controller: %#v", obj) return nil, fmt.Errorf("not a replication controller: %#v", obj)
@ -78,14 +80,14 @@ func (rs *RegistryStorage) Create(obj runtime.Object) (<-chan runtime.Object, er
} }
// Delete asynchronously deletes the ReplicationController specified by its id. // Delete asynchronously deletes the ReplicationController specified by its id.
func (rs *RegistryStorage) Delete(id string) (<-chan runtime.Object, error) { func (rs *REST) Delete(id string) (<-chan runtime.Object, error) {
return apiserver.MakeAsync(func() (runtime.Object, error) { return apiserver.MakeAsync(func() (runtime.Object, error) {
return &api.Status{Status: api.StatusSuccess}, rs.registry.DeleteController(id) return &api.Status{Status: api.StatusSuccess}, rs.registry.DeleteController(id)
}), nil }), nil
} }
// Get obtains the ReplicationController specified by its id. // Get obtains the ReplicationController specified by its id.
func (rs *RegistryStorage) Get(id string) (runtime.Object, error) { func (rs *REST) Get(id string) (runtime.Object, error) {
controller, err := rs.registry.GetController(id) controller, err := rs.registry.GetController(id)
if err != nil { if err != nil {
return nil, err return nil, err
@ -94,7 +96,7 @@ func (rs *RegistryStorage) Get(id string) (runtime.Object, error) {
} }
// List obtains a list of ReplicationControllers that match selector. // List obtains a list of ReplicationControllers that match selector.
func (rs *RegistryStorage) List(selector labels.Selector) (runtime.Object, error) { func (rs *REST) List(selector labels.Selector) (runtime.Object, error) {
controllers, err := rs.registry.ListControllers() controllers, err := rs.registry.ListControllers()
if err != nil { if err != nil {
return nil, err return nil, err
@ -110,13 +112,13 @@ func (rs *RegistryStorage) List(selector labels.Selector) (runtime.Object, error
} }
// New creates a new ReplicationController for use with Create and Update. // New creates a new ReplicationController for use with Create and Update.
func (rs RegistryStorage) New() runtime.Object { func (*REST) New() runtime.Object {
return &api.ReplicationController{} return &api.ReplicationController{}
} }
// Update replaces a given ReplicationController instance with an existing // Update replaces a given ReplicationController instance with an existing
// instance in storage.registry. // instance in storage.registry.
func (rs *RegistryStorage) Update(obj runtime.Object) (<-chan runtime.Object, error) { func (rs *REST) Update(obj runtime.Object) (<-chan runtime.Object, error) {
controller, ok := obj.(*api.ReplicationController) controller, ok := obj.(*api.ReplicationController)
if !ok { if !ok {
return nil, fmt.Errorf("not a replication controller: %#v", obj) return nil, fmt.Errorf("not a replication controller: %#v", obj)
@ -135,7 +137,7 @@ func (rs *RegistryStorage) Update(obj runtime.Object) (<-chan runtime.Object, er
// Watch returns ReplicationController events via a watch.Interface. // Watch returns ReplicationController events via a watch.Interface.
// It implements apiserver.ResourceWatcher. // It implements apiserver.ResourceWatcher.
func (rs *RegistryStorage) Watch(label, field labels.Selector, resourceVersion uint64) (watch.Interface, error) { func (rs *REST) Watch(label, field labels.Selector, resourceVersion uint64) (watch.Interface, error) {
if !field.Empty() { if !field.Empty() {
return nil, fmt.Errorf("no field selector implemented for controllers") return nil, fmt.Errorf("no field selector implemented for controllers")
} }
@ -149,9 +151,9 @@ func (rs *RegistryStorage) Watch(label, field labels.Selector, resourceVersion u
}), nil }), nil
} }
func (rs *RegistryStorage) waitForController(ctrl *api.ReplicationController) (runtime.Object, error) { func (rs *REST) waitForController(ctrl *api.ReplicationController) (runtime.Object, error) {
for { for {
pods, err := rs.podRegistry.ListPods(labels.Set(ctrl.DesiredState.ReplicaSelector).AsSelector()) pods, err := rs.podLister.ListPods(labels.Set(ctrl.DesiredState.ReplicaSelector).AsSelector())
if err != nil { if err != nil {
return ctrl, err return ctrl, err
} }

View File

@ -26,6 +26,7 @@ import (
"github.com/GoogleCloudPlatform/kubernetes/pkg/api" "github.com/GoogleCloudPlatform/kubernetes/pkg/api"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/errors" "github.com/GoogleCloudPlatform/kubernetes/pkg/api/errors"
_ "github.com/GoogleCloudPlatform/kubernetes/pkg/api/v1beta1"
"github.com/GoogleCloudPlatform/kubernetes/pkg/labels" "github.com/GoogleCloudPlatform/kubernetes/pkg/labels"
"github.com/GoogleCloudPlatform/kubernetes/pkg/registry/registrytest" "github.com/GoogleCloudPlatform/kubernetes/pkg/registry/registrytest"
"github.com/GoogleCloudPlatform/kubernetes/pkg/runtime" "github.com/GoogleCloudPlatform/kubernetes/pkg/runtime"
@ -35,7 +36,7 @@ func TestListControllersError(t *testing.T) {
mockRegistry := registrytest.ControllerRegistry{ mockRegistry := registrytest.ControllerRegistry{
Err: fmt.Errorf("test error"), Err: fmt.Errorf("test error"),
} }
storage := RegistryStorage{ storage := REST{
registry: &mockRegistry, registry: &mockRegistry,
} }
controllers, err := storage.List(nil) controllers, err := storage.List(nil)
@ -49,7 +50,7 @@ func TestListControllersError(t *testing.T) {
func TestListEmptyControllerList(t *testing.T) { func TestListEmptyControllerList(t *testing.T) {
mockRegistry := registrytest.ControllerRegistry{nil, &api.ReplicationControllerList{JSONBase: api.JSONBase{ResourceVersion: 1}}} mockRegistry := registrytest.ControllerRegistry{nil, &api.ReplicationControllerList{JSONBase: api.JSONBase{ResourceVersion: 1}}}
storage := RegistryStorage{ storage := REST{
registry: &mockRegistry, registry: &mockRegistry,
} }
controllers, err := storage.List(labels.Everything()) controllers, err := storage.List(labels.Everything())
@ -82,7 +83,7 @@ func TestListControllerList(t *testing.T) {
}, },
}, },
} }
storage := RegistryStorage{ storage := REST{
registry: &mockRegistry, registry: &mockRegistry,
} }
controllersObj, err := storage.List(labels.Everything()) controllersObj, err := storage.List(labels.Everything())
@ -104,7 +105,7 @@ func TestListControllerList(t *testing.T) {
func TestControllerDecode(t *testing.T) { func TestControllerDecode(t *testing.T) {
mockRegistry := registrytest.ControllerRegistry{} mockRegistry := registrytest.ControllerRegistry{}
storage := RegistryStorage{ storage := REST{
registry: &mockRegistry, registry: &mockRegistry,
} }
controller := &api.ReplicationController{ controller := &api.ReplicationController{
@ -226,10 +227,10 @@ func TestCreateController(t *testing.T) {
}, },
}, },
} }
storage := RegistryStorage{ storage := REST{
registry: &mockRegistry, registry: &mockRegistry,
podRegistry: &mockPodRegistry, podLister: &mockPodRegistry,
pollPeriod: time.Millisecond * 1, pollPeriod: time.Millisecond * 1,
} }
controller := &api.ReplicationController{ controller := &api.ReplicationController{
JSONBase: api.JSONBase{ID: "test"}, JSONBase: api.JSONBase{ID: "test"},
@ -257,10 +258,10 @@ func TestCreateController(t *testing.T) {
func TestControllerStorageValidatesCreate(t *testing.T) { func TestControllerStorageValidatesCreate(t *testing.T) {
mockRegistry := registrytest.ControllerRegistry{} mockRegistry := registrytest.ControllerRegistry{}
storage := RegistryStorage{ storage := REST{
registry: &mockRegistry, registry: &mockRegistry,
podRegistry: nil, podLister: nil,
pollPeriod: time.Millisecond * 1, pollPeriod: time.Millisecond * 1,
} }
failureCases := map[string]api.ReplicationController{ failureCases := map[string]api.ReplicationController{
@ -288,10 +289,10 @@ func TestControllerStorageValidatesCreate(t *testing.T) {
func TestControllerStorageValidatesUpdate(t *testing.T) { func TestControllerStorageValidatesUpdate(t *testing.T) {
mockRegistry := registrytest.ControllerRegistry{} mockRegistry := registrytest.ControllerRegistry{}
storage := RegistryStorage{ storage := REST{
registry: &mockRegistry, registry: &mockRegistry,
podRegistry: nil, podLister: nil,
pollPeriod: time.Millisecond * 1, pollPeriod: time.Millisecond * 1,
} }
failureCases := map[string]api.ReplicationController{ failureCases := map[string]api.ReplicationController{
"empty ID": { "empty ID": {

View File

@ -20,31 +20,30 @@ import (
"errors" "errors"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api" "github.com/GoogleCloudPlatform/kubernetes/pkg/api"
"github.com/GoogleCloudPlatform/kubernetes/pkg/apiserver"
"github.com/GoogleCloudPlatform/kubernetes/pkg/labels" "github.com/GoogleCloudPlatform/kubernetes/pkg/labels"
"github.com/GoogleCloudPlatform/kubernetes/pkg/runtime" "github.com/GoogleCloudPlatform/kubernetes/pkg/runtime"
"github.com/GoogleCloudPlatform/kubernetes/pkg/watch" "github.com/GoogleCloudPlatform/kubernetes/pkg/watch"
) )
// Storage adapts endpoints into apiserver's RESTStorage model. // REST adapts endpoints into apiserver's RESTStorage model.
type Storage struct { type REST struct {
registry Registry registry Registry
} }
// NewStorage returns a new Storage implementation for endpoints // NewREST returns a new apiserver.RESTStorage implementation for endpoints
func NewStorage(registry Registry) apiserver.RESTStorage { func NewREST(registry Registry) *REST {
return &Storage{ return &REST{
registry: registry, registry: registry,
} }
} }
// Get satisfies the RESTStorage interface. // Get satisfies the RESTStorage interface.
func (rs *Storage) Get(id string) (runtime.Object, error) { func (rs *REST) Get(id string) (runtime.Object, error) {
return rs.registry.GetEndpoints(id) return rs.registry.GetEndpoints(id)
} }
// List satisfies the RESTStorage interface. // List satisfies the RESTStorage interface.
func (rs *Storage) List(selector labels.Selector) (runtime.Object, error) { func (rs *REST) List(selector labels.Selector) (runtime.Object, error) {
if !selector.Empty() { if !selector.Empty() {
return nil, errors.New("label selectors are not supported on endpoints") return nil, errors.New("label selectors are not supported on endpoints")
} }
@ -53,26 +52,26 @@ func (rs *Storage) List(selector labels.Selector) (runtime.Object, error) {
// Watch returns Endpoint events via a watch.Interface. // Watch returns Endpoint events via a watch.Interface.
// It implements apiserver.ResourceWatcher. // It implements apiserver.ResourceWatcher.
func (rs *Storage) Watch(label, field labels.Selector, resourceVersion uint64) (watch.Interface, error) { func (rs *REST) Watch(label, field labels.Selector, resourceVersion uint64) (watch.Interface, error) {
return rs.registry.WatchEndpoints(label, field, resourceVersion) return rs.registry.WatchEndpoints(label, field, resourceVersion)
} }
// Create satisfies the RESTStorage interface but is unimplemented. // Create satisfies the RESTStorage interface but is unimplemented.
func (rs *Storage) Create(obj runtime.Object) (<-chan runtime.Object, error) { func (rs *REST) Create(obj runtime.Object) (<-chan runtime.Object, error) {
return nil, errors.New("unimplemented") return nil, errors.New("unimplemented")
} }
// Update satisfies the RESTStorage interface but is unimplemented. // Update satisfies the RESTStorage interface but is unimplemented.
func (rs *Storage) Update(obj runtime.Object) (<-chan runtime.Object, error) { func (rs *REST) Update(obj runtime.Object) (<-chan runtime.Object, error) {
return nil, errors.New("unimplemented") return nil, errors.New("unimplemented")
} }
// Delete satisfies the RESTStorage interface but is unimplemented. // Delete satisfies the RESTStorage interface but is unimplemented.
func (rs *Storage) Delete(id string) (<-chan runtime.Object, error) { func (rs *REST) Delete(id string) (<-chan runtime.Object, error) {
return nil, errors.New("unimplemented") return nil, errors.New("unimplemented")
} }
// New implements the RESTStorage interface. // New implements the RESTStorage interface.
func (rs Storage) New() runtime.Object { func (rs REST) New() runtime.Object {
return &api.Endpoints{} return &api.Endpoints{}
} }

View File

@ -33,7 +33,7 @@ func TestGetEndpoints(t *testing.T) {
Endpoints: []string{"127.0.0.1:9000"}, Endpoints: []string{"127.0.0.1:9000"},
}, },
} }
storage := NewStorage(registry) storage := NewREST(registry)
obj, err := storage.Get("foo") obj, err := storage.Get("foo")
if err != nil { if err != nil {
t.Fatalf("unexpected error: %#v", err) t.Fatalf("unexpected error: %#v", err)
@ -47,7 +47,7 @@ func TestGetEndpointsMissingService(t *testing.T) {
registry := &registrytest.ServiceRegistry{ registry := &registrytest.ServiceRegistry{
Err: errors.NewNotFound("service", "foo"), Err: errors.NewNotFound("service", "foo"),
} }
storage := NewStorage(registry) storage := NewREST(registry)
// returns service not found // returns service not found
_, err := storage.Get("foo") _, err := storage.Get("foo")
@ -71,7 +71,7 @@ func TestGetEndpointsMissingService(t *testing.T) {
func TestEndpointsRegistryList(t *testing.T) { func TestEndpointsRegistryList(t *testing.T) {
registry := registrytest.NewServiceRegistry() registry := registrytest.NewServiceRegistry()
storage := NewStorage(registry) storage := NewREST(registry)
registry.EndpointsList = api.EndpointsList{ registry.EndpointsList = api.EndpointsList{
JSONBase: api.JSONBase{ResourceVersion: 1}, JSONBase: api.JSONBase{ResourceVersion: 1},
Items: []api.Endpoints{ Items: []api.Endpoints{

View File

@ -26,19 +26,19 @@ import (
"github.com/GoogleCloudPlatform/kubernetes/pkg/util" "github.com/GoogleCloudPlatform/kubernetes/pkg/util"
) )
// RegistryStorage implements the RESTStorage interface, backed by a MinionRegistry. // REST implements the RESTStorage interface, backed by a MinionRegistry.
type RegistryStorage struct { type REST struct {
registry Registry registry Registry
} }
// NewRegistryStorage returns a new RegistryStorage. // NewREST returns a new REST.
func NewRegistryStorage(m Registry) apiserver.RESTStorage { func NewREST(m Registry) *REST {
return &RegistryStorage{ return &REST{
registry: m, registry: m,
} }
} }
func (rs *RegistryStorage) Create(obj runtime.Object) (<-chan runtime.Object, error) { func (rs *REST) Create(obj runtime.Object) (<-chan runtime.Object, error) {
minion, ok := obj.(*api.Minion) minion, ok := obj.(*api.Minion)
if !ok { if !ok {
return nil, fmt.Errorf("not a minion: %#v", obj) return nil, fmt.Errorf("not a minion: %#v", obj)
@ -65,7 +65,7 @@ func (rs *RegistryStorage) Create(obj runtime.Object) (<-chan runtime.Object, er
}), nil }), nil
} }
func (rs *RegistryStorage) Delete(id string) (<-chan runtime.Object, error) { func (rs *REST) Delete(id string) (<-chan runtime.Object, error) {
exists, err := rs.registry.Contains(id) exists, err := rs.registry.Contains(id)
if !exists { if !exists {
return nil, ErrDoesNotExist return nil, ErrDoesNotExist
@ -78,7 +78,7 @@ func (rs *RegistryStorage) Delete(id string) (<-chan runtime.Object, error) {
}), nil }), nil
} }
func (rs *RegistryStorage) Get(id string) (runtime.Object, error) { func (rs *REST) Get(id string) (runtime.Object, error) {
exists, err := rs.registry.Contains(id) exists, err := rs.registry.Contains(id)
if !exists { if !exists {
return nil, ErrDoesNotExist return nil, ErrDoesNotExist
@ -86,7 +86,7 @@ func (rs *RegistryStorage) Get(id string) (runtime.Object, error) {
return rs.toApiMinion(id), err return rs.toApiMinion(id), err
} }
func (rs *RegistryStorage) List(selector labels.Selector) (runtime.Object, error) { func (rs *REST) List(selector labels.Selector) (runtime.Object, error) {
nameList, err := rs.registry.List() nameList, err := rs.registry.List()
if err != nil { if err != nil {
return nil, err return nil, err
@ -98,14 +98,14 @@ func (rs *RegistryStorage) List(selector labels.Selector) (runtime.Object, error
return &list, nil return &list, nil
} }
func (rs RegistryStorage) New() runtime.Object { func (*REST) New() runtime.Object {
return &api.Minion{} return &api.Minion{}
} }
func (rs *RegistryStorage) Update(minion runtime.Object) (<-chan runtime.Object, error) { func (rs *REST) Update(minion runtime.Object) (<-chan runtime.Object, error) {
return nil, fmt.Errorf("Minions can only be created (inserted) and deleted.") return nil, fmt.Errorf("Minions can only be created (inserted) and deleted.")
} }
func (rs *RegistryStorage) toApiMinion(name string) *api.Minion { func (rs *REST) toApiMinion(name string) *api.Minion {
return &api.Minion{JSONBase: api.JSONBase{ID: name}} return &api.Minion{JSONBase: api.JSONBase{ID: name}}
} }

View File

@ -24,9 +24,9 @@ import (
"github.com/GoogleCloudPlatform/kubernetes/pkg/labels" "github.com/GoogleCloudPlatform/kubernetes/pkg/labels"
) )
func TestMinionRegistryStorage(t *testing.T) { func TestMinionREST(t *testing.T) {
m := NewRegistry([]string{"foo", "bar"}) m := NewRegistry([]string{"foo", "bar"})
ms := NewRegistryStorage(m) ms := NewREST(m)
if obj, err := ms.Get("foo"); err != nil || obj.(*api.Minion).ID != "foo" { if obj, err := ms.Get("foo"); err != nil || obj.(*api.Minion).ID != "foo" {
t.Errorf("missing expected object") t.Errorf("missing expected object")

View File

@ -37,8 +37,8 @@ import (
"github.com/golang/glog" "github.com/golang/glog"
) )
// RegistryStorage implements the RESTStorage interface in terms of a PodRegistry. // REST implements the RESTStorage interface in terms of a PodRegistry.
type RegistryStorage struct { type REST struct {
cloudProvider cloudprovider.Interface cloudProvider cloudprovider.Interface
mu sync.Mutex mu sync.Mutex
podCache client.PodInfoGetter podCache client.PodInfoGetter
@ -47,16 +47,16 @@ type RegistryStorage struct {
registry Registry registry Registry
} }
type RegistryStorageConfig struct { type RESTConfig struct {
CloudProvider cloudprovider.Interface CloudProvider cloudprovider.Interface
PodCache client.PodInfoGetter PodCache client.PodInfoGetter
PodInfoGetter client.PodInfoGetter PodInfoGetter client.PodInfoGetter
Registry Registry Registry Registry
} }
// NewRegistryStorage returns a new RegistryStorage. // NewREST returns a new REST.
func NewRegistryStorage(config *RegistryStorageConfig) apiserver.RESTStorage { func NewREST(config *RESTConfig) *REST {
return &RegistryStorage{ return &REST{
cloudProvider: config.CloudProvider, cloudProvider: config.CloudProvider,
podCache: config.PodCache, podCache: config.PodCache,
podInfoGetter: config.PodInfoGetter, podInfoGetter: config.PodInfoGetter,
@ -65,7 +65,7 @@ func NewRegistryStorage(config *RegistryStorageConfig) apiserver.RESTStorage {
} }
} }
func (rs *RegistryStorage) Create(obj runtime.Object) (<-chan runtime.Object, error) { func (rs *REST) Create(obj runtime.Object) (<-chan runtime.Object, error) {
pod := obj.(*api.Pod) pod := obj.(*api.Pod)
pod.DesiredState.Manifest.UUID = uuid.NewUUID().String() pod.DesiredState.Manifest.UUID = uuid.NewUUID().String()
if len(pod.ID) == 0 { if len(pod.ID) == 0 {
@ -86,13 +86,13 @@ func (rs *RegistryStorage) Create(obj runtime.Object) (<-chan runtime.Object, er
}), nil }), nil
} }
func (rs *RegistryStorage) Delete(id string) (<-chan runtime.Object, error) { func (rs *REST) Delete(id string) (<-chan runtime.Object, error) {
return apiserver.MakeAsync(func() (runtime.Object, error) { return apiserver.MakeAsync(func() (runtime.Object, error) {
return &api.Status{Status: api.StatusSuccess}, rs.registry.DeletePod(id) return &api.Status{Status: api.StatusSuccess}, rs.registry.DeletePod(id)
}), nil }), nil
} }
func (rs *RegistryStorage) Get(id string) (runtime.Object, error) { func (rs *REST) Get(id string) (runtime.Object, error) {
pod, err := rs.registry.GetPod(id) pod, err := rs.registry.GetPod(id)
if err != nil { if err != nil {
return pod, err return pod, err
@ -108,7 +108,7 @@ func (rs *RegistryStorage) Get(id string) (runtime.Object, error) {
return pod, err return pod, err
} }
func (rs *RegistryStorage) List(selector labels.Selector) (runtime.Object, error) { func (rs *REST) List(selector labels.Selector) (runtime.Object, error) {
pods, err := rs.registry.ListPods(selector) pods, err := rs.registry.ListPods(selector)
if err == nil { if err == nil {
for i := range pods.Items { for i := range pods.Items {
@ -122,7 +122,7 @@ func (rs *RegistryStorage) List(selector labels.Selector) (runtime.Object, error
} }
// Watch begins watching for new, changed, or deleted pods. // Watch begins watching for new, changed, or deleted pods.
func (rs *RegistryStorage) Watch(label, field labels.Selector, resourceVersion uint64) (watch.Interface, error) { func (rs *REST) Watch(label, field labels.Selector, resourceVersion uint64) (watch.Interface, error) {
return rs.registry.WatchPods(resourceVersion, func(pod *api.Pod) bool { return rs.registry.WatchPods(resourceVersion, func(pod *api.Pod) bool {
fields := labels.Set{ fields := labels.Set{
"ID": pod.ID, "ID": pod.ID,
@ -133,11 +133,11 @@ func (rs *RegistryStorage) Watch(label, field labels.Selector, resourceVersion u
}) })
} }
func (rs RegistryStorage) New() runtime.Object { func (*REST) New() runtime.Object {
return &api.Pod{} return &api.Pod{}
} }
func (rs *RegistryStorage) Update(obj runtime.Object) (<-chan runtime.Object, error) { func (rs *REST) Update(obj runtime.Object) (<-chan runtime.Object, error) {
pod := obj.(*api.Pod) pod := obj.(*api.Pod)
if errs := validation.ValidatePod(pod); len(errs) > 0 { if errs := validation.ValidatePod(pod); len(errs) > 0 {
return nil, errors.NewInvalid("pod", pod.ID, errs) return nil, errors.NewInvalid("pod", pod.ID, errs)
@ -150,7 +150,7 @@ func (rs *RegistryStorage) Update(obj runtime.Object) (<-chan runtime.Object, er
}), nil }), nil
} }
func (rs *RegistryStorage) fillPodInfo(pod *api.Pod) { func (rs *REST) fillPodInfo(pod *api.Pod) {
pod.CurrentState.Host = pod.DesiredState.Host pod.CurrentState.Host = pod.DesiredState.Host
if pod.CurrentState.Host == "" { if pod.CurrentState.Host == "" {
return return
@ -237,7 +237,7 @@ func getPodStatus(pod *api.Pod) api.PodStatus {
} }
} }
func (rs *RegistryStorage) waitForPodRunning(pod *api.Pod) (runtime.Object, error) { func (rs *REST) waitForPodRunning(pod *api.Pod) (runtime.Object, error) {
for { for {
podObj, err := rs.Get(pod.ID) podObj, err := rs.Get(pod.ID)
if err != nil || podObj == nil { if err != nil || podObj == nil {

View File

@ -57,7 +57,7 @@ func expectPod(t *testing.T, ch <-chan runtime.Object) (*api.Pod, bool) {
func TestCreatePodRegistryError(t *testing.T) { func TestCreatePodRegistryError(t *testing.T) {
podRegistry := registrytest.NewPodRegistry(nil) podRegistry := registrytest.NewPodRegistry(nil)
podRegistry.Err = fmt.Errorf("test error") podRegistry.Err = fmt.Errorf("test error")
storage := RegistryStorage{ storage := REST{
registry: podRegistry, registry: podRegistry,
} }
desiredState := api.PodState{ desiredState := api.PodState{
@ -76,7 +76,7 @@ func TestCreatePodRegistryError(t *testing.T) {
func TestCreatePodSetsIds(t *testing.T) { func TestCreatePodSetsIds(t *testing.T) {
podRegistry := registrytest.NewPodRegistry(nil) podRegistry := registrytest.NewPodRegistry(nil)
podRegistry.Err = fmt.Errorf("test error") podRegistry.Err = fmt.Errorf("test error")
storage := RegistryStorage{ storage := REST{
registry: podRegistry, registry: podRegistry,
} }
desiredState := api.PodState{ desiredState := api.PodState{
@ -102,7 +102,7 @@ func TestCreatePodSetsIds(t *testing.T) {
func TestCreatePodSetsUUIDs(t *testing.T) { func TestCreatePodSetsUUIDs(t *testing.T) {
podRegistry := registrytest.NewPodRegistry(nil) podRegistry := registrytest.NewPodRegistry(nil)
podRegistry.Err = fmt.Errorf("test error") podRegistry.Err = fmt.Errorf("test error")
storage := RegistryStorage{ storage := REST{
registry: podRegistry, registry: podRegistry,
} }
desiredState := api.PodState{ desiredState := api.PodState{
@ -125,7 +125,7 @@ func TestCreatePodSetsUUIDs(t *testing.T) {
func TestListPodsError(t *testing.T) { func TestListPodsError(t *testing.T) {
podRegistry := registrytest.NewPodRegistry(nil) podRegistry := registrytest.NewPodRegistry(nil)
podRegistry.Err = fmt.Errorf("test error") podRegistry.Err = fmt.Errorf("test error")
storage := RegistryStorage{ storage := REST{
registry: podRegistry, registry: podRegistry,
} }
pods, err := storage.List(labels.Everything()) pods, err := storage.List(labels.Everything())
@ -139,7 +139,7 @@ func TestListPodsError(t *testing.T) {
func TestListEmptyPodList(t *testing.T) { func TestListEmptyPodList(t *testing.T) {
podRegistry := registrytest.NewPodRegistry(&api.PodList{JSONBase: api.JSONBase{ResourceVersion: 1}}) podRegistry := registrytest.NewPodRegistry(&api.PodList{JSONBase: api.JSONBase{ResourceVersion: 1}})
storage := RegistryStorage{ storage := REST{
registry: podRegistry, registry: podRegistry,
} }
pods, err := storage.List(labels.Everything()) pods, err := storage.List(labels.Everything())
@ -171,7 +171,7 @@ func TestListPodList(t *testing.T) {
}, },
}, },
} }
storage := RegistryStorage{ storage := REST{
registry: podRegistry, registry: podRegistry,
} }
podsObj, err := storage.List(labels.Everything()) podsObj, err := storage.List(labels.Everything())
@ -193,7 +193,7 @@ func TestListPodList(t *testing.T) {
func TestPodDecode(t *testing.T) { func TestPodDecode(t *testing.T) {
podRegistry := registrytest.NewPodRegistry(nil) podRegistry := registrytest.NewPodRegistry(nil)
storage := RegistryStorage{ storage := REST{
registry: podRegistry, registry: podRegistry,
} }
expected := &api.Pod{ expected := &api.Pod{
@ -219,7 +219,7 @@ func TestPodDecode(t *testing.T) {
func TestGetPod(t *testing.T) { func TestGetPod(t *testing.T) {
podRegistry := registrytest.NewPodRegistry(nil) podRegistry := registrytest.NewPodRegistry(nil)
podRegistry.Pod = &api.Pod{JSONBase: api.JSONBase{ID: "foo"}} podRegistry.Pod = &api.Pod{JSONBase: api.JSONBase{ID: "foo"}}
storage := RegistryStorage{ storage := REST{
registry: podRegistry, registry: podRegistry,
} }
obj, err := storage.Get("foo") obj, err := storage.Get("foo")
@ -237,7 +237,7 @@ func TestGetPodCloud(t *testing.T) {
fakeCloud := &fake_cloud.FakeCloud{} fakeCloud := &fake_cloud.FakeCloud{}
podRegistry := registrytest.NewPodRegistry(nil) podRegistry := registrytest.NewPodRegistry(nil)
podRegistry.Pod = &api.Pod{JSONBase: api.JSONBase{ID: "foo"}} podRegistry.Pod = &api.Pod{JSONBase: api.JSONBase{ID: "foo"}}
storage := RegistryStorage{ storage := REST{
registry: podRegistry, registry: podRegistry,
cloudProvider: fakeCloud, cloudProvider: fakeCloud,
} }
@ -352,7 +352,7 @@ func TestMakePodStatus(t *testing.T) {
func TestPodStorageValidatesCreate(t *testing.T) { func TestPodStorageValidatesCreate(t *testing.T) {
podRegistry := registrytest.NewPodRegistry(nil) podRegistry := registrytest.NewPodRegistry(nil)
podRegistry.Err = fmt.Errorf("test error") podRegistry.Err = fmt.Errorf("test error")
storage := RegistryStorage{ storage := REST{
registry: podRegistry, registry: podRegistry,
} }
pod := &api.Pod{} pod := &api.Pod{}
@ -368,7 +368,7 @@ func TestPodStorageValidatesCreate(t *testing.T) {
func TestPodStorageValidatesUpdate(t *testing.T) { func TestPodStorageValidatesUpdate(t *testing.T) {
podRegistry := registrytest.NewPodRegistry(nil) podRegistry := registrytest.NewPodRegistry(nil)
podRegistry.Err = fmt.Errorf("test error") podRegistry.Err = fmt.Errorf("test error")
storage := RegistryStorage{ storage := REST{
registry: podRegistry, registry: podRegistry,
} }
pod := &api.Pod{} pod := &api.Pod{}
@ -389,7 +389,7 @@ func TestCreatePod(t *testing.T) {
Host: "machine", Host: "machine",
}, },
} }
storage := RegistryStorage{ storage := REST{
registry: podRegistry, registry: podRegistry,
podPollPeriod: time.Millisecond * 100, podPollPeriod: time.Millisecond * 100,
} }
@ -437,7 +437,7 @@ func TestFillPodInfo(t *testing.T) {
}, },
}, },
} }
storage := RegistryStorage{ storage := REST{
podCache: &fakeGetter, podCache: &fakeGetter,
} }
pod := api.Pod{DesiredState: api.PodState{Host: "foo"}} pod := api.Pod{DesiredState: api.PodState{Host: "foo"}}
@ -460,7 +460,7 @@ func TestFillPodInfoNoData(t *testing.T) {
}, },
}, },
} }
storage := RegistryStorage{ storage := REST{
podCache: &fakeGetter, podCache: &fakeGetter,
} }
pod := api.Pod{DesiredState: api.PodState{Host: "foo"}} pod := api.Pod{DesiredState: api.PodState{Host: "foo"}}

View File

@ -34,23 +34,23 @@ import (
"github.com/GoogleCloudPlatform/kubernetes/pkg/watch" "github.com/GoogleCloudPlatform/kubernetes/pkg/watch"
) )
// RegistryStorage adapts a service registry into apiserver's RESTStorage model. // REST adapts a service registry into apiserver's RESTStorage model.
type RegistryStorage struct { type REST struct {
registry Registry registry Registry
cloud cloudprovider.Interface cloud cloudprovider.Interface
machines minion.Registry machines minion.Registry
} }
// NewRegistryStorage returns a new RegistryStorage. // NewREST returns a new REST.
func NewRegistryStorage(registry Registry, cloud cloudprovider.Interface, machines minion.Registry) apiserver.RESTStorage { func NewREST(registry Registry, cloud cloudprovider.Interface, machines minion.Registry) *REST {
return &RegistryStorage{ return &REST{
registry: registry, registry: registry,
cloud: cloud, cloud: cloud,
machines: machines, machines: machines,
} }
} }
func (rs *RegistryStorage) Create(obj runtime.Object) (<-chan runtime.Object, error) { func (rs *REST) Create(obj runtime.Object) (<-chan runtime.Object, error) {
srv := obj.(*api.Service) srv := obj.(*api.Service)
if errs := validation.ValidateService(srv); len(errs) > 0 { if errs := validation.ValidateService(srv); len(errs) > 0 {
return nil, errors.NewInvalid("service", srv.ID, errs) return nil, errors.NewInvalid("service", srv.ID, errs)
@ -94,7 +94,7 @@ func (rs *RegistryStorage) Create(obj runtime.Object) (<-chan runtime.Object, er
}), nil }), nil
} }
func (rs *RegistryStorage) Delete(id string) (<-chan runtime.Object, error) { func (rs *REST) Delete(id string) (<-chan runtime.Object, error) {
service, err := rs.registry.GetService(id) service, err := rs.registry.GetService(id)
if err != nil { if err != nil {
return nil, err return nil, err
@ -105,7 +105,7 @@ func (rs *RegistryStorage) Delete(id string) (<-chan runtime.Object, error) {
}), nil }), nil
} }
func (rs *RegistryStorage) Get(id string) (runtime.Object, error) { func (rs *REST) Get(id string) (runtime.Object, error) {
s, err := rs.registry.GetService(id) s, err := rs.registry.GetService(id)
if err != nil { if err != nil {
return nil, err return nil, err
@ -113,7 +113,7 @@ func (rs *RegistryStorage) Get(id string) (runtime.Object, error) {
return s, err return s, err
} }
func (rs *RegistryStorage) List(selector labels.Selector) (runtime.Object, error) { func (rs *REST) List(selector labels.Selector) (runtime.Object, error) {
list, err := rs.registry.ListServices() list, err := rs.registry.ListServices()
if err != nil { if err != nil {
return nil, err return nil, err
@ -130,11 +130,11 @@ func (rs *RegistryStorage) List(selector labels.Selector) (runtime.Object, error
// Watch returns Services events via a watch.Interface. // Watch returns Services events via a watch.Interface.
// It implements apiserver.ResourceWatcher. // It implements apiserver.ResourceWatcher.
func (rs *RegistryStorage) Watch(label, field labels.Selector, resourceVersion uint64) (watch.Interface, error) { func (rs *REST) Watch(label, field labels.Selector, resourceVersion uint64) (watch.Interface, error) {
return rs.registry.WatchServices(label, field, resourceVersion) return rs.registry.WatchServices(label, field, resourceVersion)
} }
func (rs RegistryStorage) New() runtime.Object { func (*REST) New() runtime.Object {
return &api.Service{} return &api.Service{}
} }
@ -156,7 +156,7 @@ func GetServiceEnvironmentVariables(registry Registry, machine string) ([]api.En
return result, nil return result, nil
} }
func (rs *RegistryStorage) Update(obj runtime.Object) (<-chan runtime.Object, error) { func (rs *REST) Update(obj runtime.Object) (<-chan runtime.Object, error) {
srv := obj.(*api.Service) srv := obj.(*api.Service)
if errs := validation.ValidateService(srv); len(errs) > 0 { if errs := validation.ValidateService(srv); len(errs) > 0 {
return nil, errors.NewInvalid("service", srv.ID, errs) return nil, errors.NewInvalid("service", srv.ID, errs)
@ -172,7 +172,7 @@ func (rs *RegistryStorage) Update(obj runtime.Object) (<-chan runtime.Object, er
} }
// ResourceLocation returns a URL to which one can send traffic for the specified service. // ResourceLocation returns a URL to which one can send traffic for the specified service.
func (rs *RegistryStorage) ResourceLocation(id string) (string, error) { func (rs *REST) ResourceLocation(id string) (string, error) {
e, err := rs.registry.GetEndpoints(id) e, err := rs.registry.GetEndpoints(id)
if err != nil { if err != nil {
return "", err return "", err
@ -183,7 +183,7 @@ func (rs *RegistryStorage) ResourceLocation(id string) (string, error) {
return "http://" + e.Endpoints[rand.Intn(len(e.Endpoints))], nil return "http://" + e.Endpoints[rand.Intn(len(e.Endpoints))], nil
} }
func (rs *RegistryStorage) deleteExternalLoadBalancer(service *api.Service) error { func (rs *REST) deleteExternalLoadBalancer(service *api.Service) error {
if !service.CreateExternalLoadBalancer || rs.cloud == nil { if !service.CreateExternalLoadBalancer || rs.cloud == nil {
return nil return nil
} }

View File

@ -34,7 +34,7 @@ func TestServiceRegistryCreate(t *testing.T) {
registry := registrytest.NewServiceRegistry() registry := registrytest.NewServiceRegistry()
fakeCloud := &cloud.FakeCloud{} fakeCloud := &cloud.FakeCloud{}
machines := []string{"foo", "bar", "baz"} machines := []string{"foo", "bar", "baz"}
storage := NewRegistryStorage(registry, fakeCloud, minion.NewRegistry(machines)) storage := NewREST(registry, fakeCloud, minion.NewRegistry(machines))
svc := &api.Service{ svc := &api.Service{
Port: 6502, Port: 6502,
JSONBase: api.JSONBase{ID: "foo"}, JSONBase: api.JSONBase{ID: "foo"},
@ -63,7 +63,7 @@ func TestServiceRegistryCreate(t *testing.T) {
func TestServiceStorageValidatesCreate(t *testing.T) { func TestServiceStorageValidatesCreate(t *testing.T) {
registry := registrytest.NewServiceRegistry() registry := registrytest.NewServiceRegistry()
storage := NewRegistryStorage(registry, nil, nil) storage := NewREST(registry, nil, nil)
failureCases := map[string]api.Service{ failureCases := map[string]api.Service{
"empty ID": { "empty ID": {
Port: 6502, Port: 6502,
@ -94,7 +94,7 @@ func TestServiceRegistryUpdate(t *testing.T) {
JSONBase: api.JSONBase{ID: "foo"}, JSONBase: api.JSONBase{ID: "foo"},
Selector: map[string]string{"bar": "baz1"}, Selector: map[string]string{"bar": "baz1"},
}) })
storage := NewRegistryStorage(registry, nil, nil) storage := NewREST(registry, nil, nil)
c, err := storage.Update(&api.Service{ c, err := storage.Update(&api.Service{
Port: 6502, Port: 6502,
JSONBase: api.JSONBase{ID: "foo"}, JSONBase: api.JSONBase{ID: "foo"},
@ -123,7 +123,7 @@ func TestServiceStorageValidatesUpdate(t *testing.T) {
JSONBase: api.JSONBase{ID: "foo"}, JSONBase: api.JSONBase{ID: "foo"},
Selector: map[string]string{"bar": "baz"}, Selector: map[string]string{"bar": "baz"},
}) })
storage := NewRegistryStorage(registry, nil, nil) storage := NewREST(registry, nil, nil)
failureCases := map[string]api.Service{ failureCases := map[string]api.Service{
"empty ID": { "empty ID": {
Port: 6502, Port: 6502,
@ -151,7 +151,7 @@ func TestServiceRegistryExternalService(t *testing.T) {
registry := registrytest.NewServiceRegistry() registry := registrytest.NewServiceRegistry()
fakeCloud := &cloud.FakeCloud{} fakeCloud := &cloud.FakeCloud{}
machines := []string{"foo", "bar", "baz"} machines := []string{"foo", "bar", "baz"}
storage := NewRegistryStorage(registry, fakeCloud, minion.NewRegistry(machines)) storage := NewREST(registry, fakeCloud, minion.NewRegistry(machines))
svc := &api.Service{ svc := &api.Service{
Port: 6502, Port: 6502,
JSONBase: api.JSONBase{ID: "foo"}, JSONBase: api.JSONBase{ID: "foo"},
@ -178,7 +178,7 @@ func TestServiceRegistryExternalServiceError(t *testing.T) {
Err: fmt.Errorf("test error"), Err: fmt.Errorf("test error"),
} }
machines := []string{"foo", "bar", "baz"} machines := []string{"foo", "bar", "baz"}
storage := NewRegistryStorage(registry, fakeCloud, minion.NewRegistry(machines)) storage := NewREST(registry, fakeCloud, minion.NewRegistry(machines))
svc := &api.Service{ svc := &api.Service{
Port: 6502, Port: 6502,
JSONBase: api.JSONBase{ID: "foo"}, JSONBase: api.JSONBase{ID: "foo"},
@ -199,7 +199,7 @@ func TestServiceRegistryDelete(t *testing.T) {
registry := registrytest.NewServiceRegistry() registry := registrytest.NewServiceRegistry()
fakeCloud := &cloud.FakeCloud{} fakeCloud := &cloud.FakeCloud{}
machines := []string{"foo", "bar", "baz"} machines := []string{"foo", "bar", "baz"}
storage := NewRegistryStorage(registry, fakeCloud, minion.NewRegistry(machines)) storage := NewREST(registry, fakeCloud, minion.NewRegistry(machines))
svc := &api.Service{ svc := &api.Service{
JSONBase: api.JSONBase{ID: "foo"}, JSONBase: api.JSONBase{ID: "foo"},
Selector: map[string]string{"bar": "baz"}, Selector: map[string]string{"bar": "baz"},
@ -219,7 +219,7 @@ func TestServiceRegistryDeleteExternal(t *testing.T) {
registry := registrytest.NewServiceRegistry() registry := registrytest.NewServiceRegistry()
fakeCloud := &cloud.FakeCloud{} fakeCloud := &cloud.FakeCloud{}
machines := []string{"foo", "bar", "baz"} machines := []string{"foo", "bar", "baz"}
storage := NewRegistryStorage(registry, fakeCloud, minion.NewRegistry(machines)) storage := NewREST(registry, fakeCloud, minion.NewRegistry(machines))
svc := &api.Service{ svc := &api.Service{
JSONBase: api.JSONBase{ID: "foo"}, JSONBase: api.JSONBase{ID: "foo"},
Selector: map[string]string{"bar": "baz"}, Selector: map[string]string{"bar": "baz"},
@ -262,7 +262,7 @@ func TestServiceRegistryGet(t *testing.T) {
registry := registrytest.NewServiceRegistry() registry := registrytest.NewServiceRegistry()
fakeCloud := &cloud.FakeCloud{} fakeCloud := &cloud.FakeCloud{}
machines := []string{"foo", "bar", "baz"} machines := []string{"foo", "bar", "baz"}
storage := NewRegistryStorage(registry, fakeCloud, minion.NewRegistry(machines)) storage := NewREST(registry, fakeCloud, minion.NewRegistry(machines))
registry.CreateService(&api.Service{ registry.CreateService(&api.Service{
JSONBase: api.JSONBase{ID: "foo"}, JSONBase: api.JSONBase{ID: "foo"},
Selector: map[string]string{"bar": "baz"}, Selector: map[string]string{"bar": "baz"},
@ -281,12 +281,12 @@ func TestServiceRegistryResourceLocation(t *testing.T) {
registry.Endpoints = api.Endpoints{Endpoints: []string{"foo:80"}} registry.Endpoints = api.Endpoints{Endpoints: []string{"foo:80"}}
fakeCloud := &cloud.FakeCloud{} fakeCloud := &cloud.FakeCloud{}
machines := []string{"foo", "bar", "baz"} machines := []string{"foo", "bar", "baz"}
storage := NewRegistryStorage(registry, fakeCloud, minion.NewRegistry(machines)) storage := NewREST(registry, fakeCloud, minion.NewRegistry(machines))
registry.CreateService(&api.Service{ registry.CreateService(&api.Service{
JSONBase: api.JSONBase{ID: "foo"}, JSONBase: api.JSONBase{ID: "foo"},
Selector: map[string]string{"bar": "baz"}, Selector: map[string]string{"bar": "baz"},
}) })
redirector := storage.(apiserver.Redirector) redirector := apiserver.Redirector(storage)
location, err := redirector.ResourceLocation("foo") location, err := redirector.ResourceLocation("foo")
if err != nil { if err != nil {
t.Errorf("Unexpected error: %v", err) t.Errorf("Unexpected error: %v", err)
@ -309,7 +309,7 @@ func TestServiceRegistryList(t *testing.T) {
registry := registrytest.NewServiceRegistry() registry := registrytest.NewServiceRegistry()
fakeCloud := &cloud.FakeCloud{} fakeCloud := &cloud.FakeCloud{}
machines := []string{"foo", "bar", "baz"} machines := []string{"foo", "bar", "baz"}
storage := NewRegistryStorage(registry, fakeCloud, minion.NewRegistry(machines)) storage := NewREST(registry, fakeCloud, minion.NewRegistry(machines))
registry.CreateService(&api.Service{ registry.CreateService(&api.Service{
JSONBase: api.JSONBase{ID: "foo"}, JSONBase: api.JSONBase{ID: "foo"},
Selector: map[string]string{"bar": "baz"}, Selector: map[string]string{"bar": "baz"},