Move layer interface definitions to distribution package
After consideration, it has been decided that the interfaces defined in the storage package provide a good base for interacting with various registry instances. Whether interacting with a remote API or a local, on-disk registry, these types have proved flexible. By moving them here, they can become the central components of interacting with distribution components. Signed-off-by: Stephen J Day <stephen.day@docker.com>
This commit is contained in:
parent
5a0f1ceeef
commit
553d48d618
20 changed files with 113 additions and 265 deletions
|
@ -4,11 +4,10 @@ import (
|
|||
"net/http"
|
||||
"time"
|
||||
|
||||
"github.com/docker/distribution/manifest"
|
||||
|
||||
"code.google.com/p/go-uuid/uuid"
|
||||
"github.com/docker/distribution"
|
||||
"github.com/docker/distribution/digest"
|
||||
"github.com/docker/distribution/registry/storage"
|
||||
"github.com/docker/distribution/manifest"
|
||||
)
|
||||
|
||||
type bridge struct {
|
||||
|
@ -53,31 +52,31 @@ func NewRequestRecord(id string, r *http.Request) RequestRecord {
|
|||
}
|
||||
}
|
||||
|
||||
func (b *bridge) ManifestPushed(repo storage.Repository, sm *manifest.SignedManifest) error {
|
||||
func (b *bridge) ManifestPushed(repo distribution.Repository, sm *manifest.SignedManifest) error {
|
||||
return b.createManifestEventAndWrite(EventActionPush, repo, sm)
|
||||
}
|
||||
|
||||
func (b *bridge) ManifestPulled(repo storage.Repository, sm *manifest.SignedManifest) error {
|
||||
func (b *bridge) ManifestPulled(repo distribution.Repository, sm *manifest.SignedManifest) error {
|
||||
return b.createManifestEventAndWrite(EventActionPull, repo, sm)
|
||||
}
|
||||
|
||||
func (b *bridge) ManifestDeleted(repo storage.Repository, sm *manifest.SignedManifest) error {
|
||||
func (b *bridge) ManifestDeleted(repo distribution.Repository, sm *manifest.SignedManifest) error {
|
||||
return b.createManifestEventAndWrite(EventActionDelete, repo, sm)
|
||||
}
|
||||
|
||||
func (b *bridge) LayerPushed(repo storage.Repository, layer storage.Layer) error {
|
||||
func (b *bridge) LayerPushed(repo distribution.Repository, layer distribution.Layer) error {
|
||||
return b.createLayerEventAndWrite(EventActionPush, repo, layer.Digest())
|
||||
}
|
||||
|
||||
func (b *bridge) LayerPulled(repo storage.Repository, layer storage.Layer) error {
|
||||
func (b *bridge) LayerPulled(repo distribution.Repository, layer distribution.Layer) error {
|
||||
return b.createLayerEventAndWrite(EventActionPull, repo, layer.Digest())
|
||||
}
|
||||
|
||||
func (b *bridge) LayerDeleted(repo storage.Repository, layer storage.Layer) error {
|
||||
func (b *bridge) LayerDeleted(repo distribution.Repository, layer distribution.Layer) error {
|
||||
return b.createLayerEventAndWrite(EventActionDelete, repo, layer.Digest())
|
||||
}
|
||||
|
||||
func (b *bridge) createManifestEventAndWrite(action string, repo storage.Repository, sm *manifest.SignedManifest) error {
|
||||
func (b *bridge) createManifestEventAndWrite(action string, repo distribution.Repository, sm *manifest.SignedManifest) error {
|
||||
event, err := b.createManifestEvent(action, repo, sm)
|
||||
if err != nil {
|
||||
return err
|
||||
|
@ -86,7 +85,7 @@ func (b *bridge) createManifestEventAndWrite(action string, repo storage.Reposit
|
|||
return b.sink.Write(*event)
|
||||
}
|
||||
|
||||
func (b *bridge) createManifestEvent(action string, repo storage.Repository, sm *manifest.SignedManifest) (*Event, error) {
|
||||
func (b *bridge) createManifestEvent(action string, repo distribution.Repository, sm *manifest.SignedManifest) (*Event, error) {
|
||||
event := b.createEvent(action)
|
||||
event.Target.Type = EventTargetTypeManifest
|
||||
event.Target.Name = repo.Name()
|
||||
|
@ -112,7 +111,7 @@ func (b *bridge) createManifestEvent(action string, repo storage.Repository, sm
|
|||
return event, nil
|
||||
}
|
||||
|
||||
func (b *bridge) createLayerEventAndWrite(action string, repo storage.Repository, dgst digest.Digest) error {
|
||||
func (b *bridge) createLayerEventAndWrite(action string, repo distribution.Repository, dgst digest.Digest) error {
|
||||
event, err := b.createLayerEvent(action, repo, dgst)
|
||||
if err != nil {
|
||||
return err
|
||||
|
@ -121,7 +120,7 @@ func (b *bridge) createLayerEventAndWrite(action string, repo storage.Repository
|
|||
return b.sink.Write(*event)
|
||||
}
|
||||
|
||||
func (b *bridge) createLayerEvent(action string, repo storage.Repository, dgst digest.Digest) (*Event, error) {
|
||||
func (b *bridge) createLayerEvent(action string, repo distribution.Repository, dgst digest.Digest) (*Event, error) {
|
||||
event := b.createEvent(action)
|
||||
event.Target.Type = EventTargetTypeBlob
|
||||
event.Target.Name = repo.Name()
|
||||
|
|
|
@ -2,31 +2,31 @@ package notifications
|
|||
|
||||
import (
|
||||
"github.com/Sirupsen/logrus"
|
||||
"github.com/docker/distribution"
|
||||
"github.com/docker/distribution/digest"
|
||||
"github.com/docker/distribution/manifest"
|
||||
"github.com/docker/distribution/registry/storage"
|
||||
)
|
||||
|
||||
// ManifestListener describes a set of methods for listening to events related to manifests.
|
||||
type ManifestListener interface {
|
||||
ManifestPushed(repo storage.Repository, sm *manifest.SignedManifest) error
|
||||
ManifestPulled(repo storage.Repository, sm *manifest.SignedManifest) error
|
||||
ManifestPushed(repo distribution.Repository, sm *manifest.SignedManifest) error
|
||||
ManifestPulled(repo distribution.Repository, sm *manifest.SignedManifest) error
|
||||
|
||||
// TODO(stevvooe): Please note that delete support is still a little shaky
|
||||
// and we'll need to propagate these in the future.
|
||||
|
||||
ManifestDeleted(repo storage.Repository, sm *manifest.SignedManifest) error
|
||||
ManifestDeleted(repo distribution.Repository, sm *manifest.SignedManifest) error
|
||||
}
|
||||
|
||||
// LayerListener describes a listener that can respond to layer related events.
|
||||
type LayerListener interface {
|
||||
LayerPushed(repo storage.Repository, layer storage.Layer) error
|
||||
LayerPulled(repo storage.Repository, layer storage.Layer) error
|
||||
LayerPushed(repo distribution.Repository, layer distribution.Layer) error
|
||||
LayerPulled(repo distribution.Repository, layer distribution.Layer) error
|
||||
|
||||
// TODO(stevvooe): Please note that delete support is still a little shaky
|
||||
// and we'll need to propagate these in the future.
|
||||
|
||||
LayerDeleted(repo storage.Repository, layer storage.Layer) error
|
||||
LayerDeleted(repo distribution.Repository, layer distribution.Layer) error
|
||||
}
|
||||
|
||||
// Listener combines all repository events into a single interface.
|
||||
|
@ -36,26 +36,26 @@ type Listener interface {
|
|||
}
|
||||
|
||||
type repositoryListener struct {
|
||||
storage.Repository
|
||||
distribution.Repository
|
||||
listener Listener
|
||||
}
|
||||
|
||||
// Listen dispatches events on the repository to the listener.
|
||||
func Listen(repo storage.Repository, listener Listener) storage.Repository {
|
||||
func Listen(repo distribution.Repository, listener Listener) distribution.Repository {
|
||||
return &repositoryListener{
|
||||
Repository: repo,
|
||||
listener: listener,
|
||||
}
|
||||
}
|
||||
|
||||
func (rl *repositoryListener) Manifests() storage.ManifestService {
|
||||
func (rl *repositoryListener) Manifests() distribution.ManifestService {
|
||||
return &manifestServiceListener{
|
||||
ManifestService: rl.Repository.Manifests(),
|
||||
parent: rl,
|
||||
}
|
||||
}
|
||||
|
||||
func (rl *repositoryListener) Layers() storage.LayerService {
|
||||
func (rl *repositoryListener) Layers() distribution.LayerService {
|
||||
return &layerServiceListener{
|
||||
LayerService: rl.Repository.Layers(),
|
||||
parent: rl,
|
||||
|
@ -63,7 +63,7 @@ func (rl *repositoryListener) Layers() storage.LayerService {
|
|||
}
|
||||
|
||||
type manifestServiceListener struct {
|
||||
storage.ManifestService
|
||||
distribution.ManifestService
|
||||
parent *repositoryListener
|
||||
}
|
||||
|
||||
|
@ -91,11 +91,11 @@ func (msl *manifestServiceListener) Put(tag string, sm *manifest.SignedManifest)
|
|||
}
|
||||
|
||||
type layerServiceListener struct {
|
||||
storage.LayerService
|
||||
distribution.LayerService
|
||||
parent *repositoryListener
|
||||
}
|
||||
|
||||
func (lsl *layerServiceListener) Fetch(dgst digest.Digest) (storage.Layer, error) {
|
||||
func (lsl *layerServiceListener) Fetch(dgst digest.Digest) (distribution.Layer, error) {
|
||||
layer, err := lsl.LayerService.Fetch(dgst)
|
||||
if err == nil {
|
||||
if err := lsl.parent.listener.LayerPulled(lsl.parent.Repository, layer); err != nil {
|
||||
|
@ -106,17 +106,17 @@ func (lsl *layerServiceListener) Fetch(dgst digest.Digest) (storage.Layer, error
|
|||
return layer, err
|
||||
}
|
||||
|
||||
func (lsl *layerServiceListener) Upload() (storage.LayerUpload, error) {
|
||||
func (lsl *layerServiceListener) Upload() (distribution.LayerUpload, error) {
|
||||
lu, err := lsl.LayerService.Upload()
|
||||
return lsl.decorateUpload(lu), err
|
||||
}
|
||||
|
||||
func (lsl *layerServiceListener) Resume(uuid string) (storage.LayerUpload, error) {
|
||||
func (lsl *layerServiceListener) Resume(uuid string) (distribution.LayerUpload, error) {
|
||||
lu, err := lsl.LayerService.Resume(uuid)
|
||||
return lsl.decorateUpload(lu), err
|
||||
}
|
||||
|
||||
func (lsl *layerServiceListener) decorateUpload(lu storage.LayerUpload) storage.LayerUpload {
|
||||
func (lsl *layerServiceListener) decorateUpload(lu distribution.LayerUpload) distribution.LayerUpload {
|
||||
return &layerUploadListener{
|
||||
LayerUpload: lu,
|
||||
parent: lsl,
|
||||
|
@ -124,11 +124,11 @@ func (lsl *layerServiceListener) decorateUpload(lu storage.LayerUpload) storage.
|
|||
}
|
||||
|
||||
type layerUploadListener struct {
|
||||
storage.LayerUpload
|
||||
distribution.LayerUpload
|
||||
parent *layerServiceListener
|
||||
}
|
||||
|
||||
func (lul *layerUploadListener) Finish(dgst digest.Digest) (storage.Layer, error) {
|
||||
func (lul *layerUploadListener) Finish(dgst digest.Digest) (distribution.Layer, error) {
|
||||
layer, err := lul.LayerUpload.Finish(dgst)
|
||||
if err == nil {
|
||||
if err := lul.parent.parent.listener.LayerPushed(lul.parent.parent.Repository, layer); err != nil {
|
||||
|
|
|
@ -5,6 +5,7 @@ import (
|
|||
"reflect"
|
||||
"testing"
|
||||
|
||||
"github.com/docker/distribution"
|
||||
"github.com/docker/distribution/digest"
|
||||
"github.com/docker/distribution/manifest"
|
||||
"github.com/docker/distribution/registry/storage"
|
||||
|
@ -44,40 +45,40 @@ type testListener struct {
|
|||
ops map[string]int
|
||||
}
|
||||
|
||||
func (tl *testListener) ManifestPushed(repo storage.Repository, sm *manifest.SignedManifest) error {
|
||||
func (tl *testListener) ManifestPushed(repo distribution.Repository, sm *manifest.SignedManifest) error {
|
||||
tl.ops["manifest:push"]++
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (tl *testListener) ManifestPulled(repo storage.Repository, sm *manifest.SignedManifest) error {
|
||||
func (tl *testListener) ManifestPulled(repo distribution.Repository, sm *manifest.SignedManifest) error {
|
||||
tl.ops["manifest:pull"]++
|
||||
return nil
|
||||
}
|
||||
|
||||
func (tl *testListener) ManifestDeleted(repo storage.Repository, sm *manifest.SignedManifest) error {
|
||||
func (tl *testListener) ManifestDeleted(repo distribution.Repository, sm *manifest.SignedManifest) error {
|
||||
tl.ops["manifest:delete"]++
|
||||
return nil
|
||||
}
|
||||
|
||||
func (tl *testListener) LayerPushed(repo storage.Repository, layer storage.Layer) error {
|
||||
func (tl *testListener) LayerPushed(repo distribution.Repository, layer distribution.Layer) error {
|
||||
tl.ops["layer:push"]++
|
||||
return nil
|
||||
}
|
||||
|
||||
func (tl *testListener) LayerPulled(repo storage.Repository, layer storage.Layer) error {
|
||||
func (tl *testListener) LayerPulled(repo distribution.Repository, layer distribution.Layer) error {
|
||||
tl.ops["layer:pull"]++
|
||||
return nil
|
||||
}
|
||||
|
||||
func (tl *testListener) LayerDeleted(repo storage.Repository, layer storage.Layer) error {
|
||||
func (tl *testListener) LayerDeleted(repo distribution.Repository, layer distribution.Layer) error {
|
||||
tl.ops["layer:delete"]++
|
||||
return nil
|
||||
}
|
||||
|
||||
// checkExerciseRegistry takes the registry through all of its operations,
|
||||
// carrying out generic checks.
|
||||
func checkExerciseRepository(t *testing.T, repository storage.Repository) {
|
||||
func checkExerciseRepository(t *testing.T, repository distribution.Repository) {
|
||||
// TODO(stevvooe): This would be a nice testutil function. Basically, it
|
||||
// takes the registry through a common set of operations. This could be
|
||||
// used to make cross-cutting updates by changing internals that affect
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue