diff --git a/pkg/contexts/ocm/cpi/repocpi/README.md b/pkg/contexts/ocm/cpi/repocpi/README.md new file mode 100644 index 0000000000..c97d5c00e9 --- /dev/null +++ b/pkg/contexts/ocm/cpi/repocpi/README.md @@ -0,0 +1,77 @@ +# Context Programming Interface for Repositories + +Package repocpi contains the implementation support + for repository backends. It offers three methods + to create component version, component and repository + objects based on three simple implementation interfaces. + + The basic provisioning model is layered: + + ![Implamentation Layers](ocmimpllayers.png) + + - on layer 1 there is the *user facing API* defined + in package [github.com/open-component-model/ocm/pkg/contexts/ocm]. + + - on layer 2 (this package) there is a backend agnostic + implementation of standard functionality based on layer 3. + This is divided into two parts + + a) the *view* objects provided by the `Dup()` calls of the layer 1 API. + All dups are internally based on a single base object. + These objects are called *bridge*. They act as base object + for the views and as abstraction for the implementation objects + providing *generic* implementations potentially based on + the implementation functionality. + (see bridge design pattern https://refactoring.guru/design-patterns/bridge) + + b) the *bridge* object as base for all dup views is used to implement some + common functionality like the view management. The bridge object + is closed, when the last view disappears. + This bridge object then calls the final + storage backend implementation interface. + + - the storage backend implementations based on the implementation + interfaces provided by layer 2. + + The implementation interfaces and the functions to create API objects are: + + - interface [ComponentVersionAccessImpl] is used to create an ocm.ComponentVersionAccess object + using the function [NewComponentVersionAccess]. + - interface [ComponentAccessImpl] is used to create an ocm.ComponentAccess object + using the function [NewComponentAccess]. + - interface [RepositoryImpl] is used to create an ocm.ComponentAccess object + using the function [NewRepository]. + + Component version implementations provide basic access to component versions + and their descriptors. They keep a reference to component implementations, which are + again based on repository implementations. The task of repository implementations is + to provide component objects. Their implementations are responsible to provide + component version objects. + +## Simplified Respository Implementation Interface + Besides this basic implementation interfaces with separated objects for a + repository, component and component version, there is support for a simplified + implementation interface (`StorageBackendImpl`). This is a single interface + bundling all required functionality to implement the objects for the three + concerned elements. With `NewStorageBackend` it is possible to instantiate + a new kind of repository based on this single interface. The required + objects for components and component versions are generically provided + based on the methods provided by this interface. + +## Comparison of Implementation Models + +The simplified implementation model does not provide access to the +implementation objects for components and component versions. +Therefore, it is not possible to keep state for those elements. + +Storage Backend Implementations requiring such state, like the OCI +implementation based on the OCI abstraction provided by the OCI +context, therefore use dedicated implementations for repository, +component and component version objects. This model provides +complete control over the lifecycle of those elements. + +If a storage backend implementation is stateless or just keeps +state at the repository level, the simplified implementation model +can be chosen. + + diff --git a/pkg/contexts/ocm/cpi/repocpi/backend.go b/pkg/contexts/ocm/cpi/repocpi/backend.go index de54b51aac..cbfeabee7b 100644 --- a/pkg/contexts/ocm/cpi/repocpi/backend.go +++ b/pkg/contexts/ocm/cpi/repocpi/backend.go @@ -52,7 +52,7 @@ type StorageBackendImpl interface { } type storageBackendRepository struct { - proxy RepositoryProxy + bridge RepositoryBridge closed atomic.Bool noref cpi.Repository kind string @@ -78,9 +78,9 @@ func NewStorageBackend(kind string, impl StorageBackendImpl) cpi.Repository { return NewRepository(backend, kind) } -func (s *storageBackendRepository) SetProxy(proxy RepositoryProxy) { - s.proxy = proxy - s.noref = NewNoneRefRepositoryView(proxy) +func (s *storageBackendRepository) SetBridge(bridge RepositoryBridge) { + s.bridge = bridge + s.noref = NewNoneRefRepositoryView(bridge) } func (s *storageBackendRepository) Close() error { @@ -124,19 +124,19 @@ func (s *storageBackendRepository) LookupComponent(name string) (*ComponentAcces //////////////////////////////////////////////////////////////////////////////// type storageBackendComponent struct { - proxy ComponentAccessProxy - repo *storageBackendRepository - name string + bridge ComponentAccessBridge + repo *storageBackendRepository + name string } var _ ComponentAccessImpl = (*storageBackendComponent)(nil) -func (s *storageBackendComponent) SetProxy(proxy ComponentAccessProxy) { - s.proxy = proxy +func (s *storageBackendComponent) SetBridge(bridge ComponentAccessBridge) { + s.bridge = bridge } -func (s *storageBackendComponent) GetParentProxy() RepositoryViewManager { - return s.repo.proxy +func (s *storageBackendComponent) GetParentBridge() RepositoryViewManager { + return s.repo.bridge } func (s *storageBackendComponent) Close() error { @@ -213,7 +213,7 @@ func (s *storageBackendComponent) NewVersion(version string, overwrite ...bool) //////////////////////////////////////////////////////////////////////////////// type storageBackendComponentVersion struct { - proxy ComponentVersionAccessProxy + bridge ComponentVersionAccessBridge comp *storageBackendComponent name common.NameVersion descriptor *compdesc.ComponentDescriptor @@ -229,12 +229,12 @@ func (s *storageBackendComponentVersion) GetContext() cpi.Context { return s.comp.repo.impl.GetContext() } -func (s *storageBackendComponentVersion) SetProxy(proxy ComponentVersionAccessProxy) { - s.proxy = proxy +func (s *storageBackendComponentVersion) SetBridge(bridge ComponentVersionAccessBridge) { + s.bridge = bridge } -func (s *storageBackendComponentVersion) GetParentProxy() ComponentAccessProxy { - return s.comp.proxy +func (s *storageBackendComponentVersion) GetParentBridge() ComponentAccessBridge { + return s.comp.bridge } func (s *storageBackendComponentVersion) Repository() cpi.Repository { diff --git a/pkg/contexts/ocm/cpi/repocpi/proxy_c.go b/pkg/contexts/ocm/cpi/repocpi/bridge_c.go similarity index 58% rename from pkg/contexts/ocm/cpi/repocpi/proxy_c.go rename to pkg/contexts/ocm/cpi/repocpi/bridge_c.go index 3e300a7ec8..c552832888 100644 --- a/pkg/contexts/ocm/cpi/repocpi/proxy_c.go +++ b/pkg/contexts/ocm/cpi/repocpi/bridge_c.go @@ -27,8 +27,8 @@ type ComponentVersionAccessInfo struct { // ComponentAccessImpl is the provider implementation // interface for component versions. type ComponentAccessImpl interface { - SetProxy(proxy ComponentAccessProxy) - GetParentProxy() RepositoryViewManager + SetBridge(bridge ComponentAccessBridge) + GetParentBridge() RepositoryViewManager GetContext() cpi.Context GetName() string @@ -42,67 +42,67 @@ type ComponentAccessImpl interface { io.Closer } -type _componentAccessProxyBase = resource.ResourceImplBase[cpi.ComponentAccess] +type _componentAccessBridgeBase = resource.ResourceImplBase[cpi.ComponentAccess] -type componentAccessProxy struct { - *_componentAccessProxyBase +type componentAccessBridge struct { + *_componentAccessBridgeBase ctx cpi.Context name string impl ComponentAccessImpl } -func newComponentAccessProxy(impl ComponentAccessImpl, closer ...io.Closer) (ComponentAccessProxy, error) { - base, err := resource.NewResourceImplBase[cpi.ComponentAccess, cpi.Repository](impl.GetParentProxy(), closer...) +func newComponentAccessBridge(impl ComponentAccessImpl, closer ...io.Closer) (ComponentAccessBridge, error) { + base, err := resource.NewResourceImplBase[cpi.ComponentAccess, cpi.Repository](impl.GetParentBridge(), closer...) if err != nil { return nil, err } - b := &componentAccessProxy{ - _componentAccessProxyBase: base, - ctx: impl.GetContext(), - name: impl.GetName(), - impl: impl, + b := &componentAccessBridge{ + _componentAccessBridgeBase: base, + ctx: impl.GetContext(), + name: impl.GetName(), + impl: impl, } - impl.SetProxy(b) + impl.SetBridge(b) return b, nil } -func (b *componentAccessProxy) Close() error { +func (b *componentAccessBridge) Close() error { list := errors.ErrListf("closing component %s", b.name) - refmgmt.AllocLog.Trace("closing component proxy", "name", b.name) + refmgmt.AllocLog.Trace("closing component bridge", "name", b.name) list.Add(b.impl.Close()) - list.Add(b._componentAccessProxyBase.Close()) - refmgmt.AllocLog.Trace("closed component proxy", "name", b.name) + list.Add(b._componentAccessBridgeBase.Close()) + refmgmt.AllocLog.Trace("closed component bridge", "name", b.name) return list.Result() } -func (b *componentAccessProxy) GetContext() cpi.Context { +func (b *componentAccessBridge) GetContext() cpi.Context { return b.ctx } -func (b *componentAccessProxy) GetName() string { +func (b *componentAccessBridge) GetName() string { return b.name } -func (b *componentAccessProxy) IsReadOnly() bool { +func (b *componentAccessBridge) IsReadOnly() bool { return b.impl.IsReadOnly() } -func (c *componentAccessProxy) IsOwned(cv cpi.ComponentVersionAccess) bool { - proxy, err := GetComponentVersionAccessProxy(cv) +func (c *componentAccessBridge) IsOwned(cv cpi.ComponentVersionAccess) bool { + bridge, err := GetComponentVersionAccessBridge(cv) if err != nil { return false } - impl := proxy.(*componentVersionAccessProxy).impl - cvcompmgr := impl.GetParentProxy() + impl := bridge.(*componentVersionAccessBridge).impl + cvcompmgr := impl.GetParentBridge() return c == cvcompmgr } -func (b *componentAccessProxy) ListVersions() ([]string, error) { +func (b *componentAccessBridge) ListVersions() ([]string, error) { return b.impl.ListVersions() } -func (b *componentAccessProxy) LookupVersion(version string) (cpi.ComponentVersionAccess, error) { +func (b *componentAccessBridge) LookupVersion(version string) (cpi.ComponentVersionAccess, error) { i, err := b.impl.LookupVersion(version) if err != nil { return nil, err @@ -113,11 +113,11 @@ func (b *componentAccessProxy) LookupVersion(version string) (cpi.ComponentVersi return NewComponentVersionAccess(b.GetName(), version, i.Impl, i.Lazy, i.Persistent, !compositionmodeattr.Get(b.GetContext())) } -func (b *componentAccessProxy) HasVersion(vers string) (bool, error) { +func (b *componentAccessBridge) HasVersion(vers string) (bool, error) { return b.impl.HasVersion(vers) } -func (b *componentAccessProxy) NewVersion(version string, overrides ...bool) (cpi.ComponentVersionAccess, error) { +func (b *componentAccessBridge) NewVersion(version string, overrides ...bool) (cpi.ComponentVersionAccess, error) { i, err := b.impl.NewVersion(version, overrides...) if err != nil { return nil, err @@ -128,11 +128,11 @@ func (b *componentAccessProxy) NewVersion(version string, overrides ...bool) (cp return NewComponentVersionAccess(b.GetName(), version, i.Impl, i.Lazy, false, !compositionmodeattr.Get(b.GetContext())) } -func (c *componentAccessProxy) AddVersion(cv cpi.ComponentVersionAccess, opts *cpi.AddVersionOptions) (ferr error) { +func (c *componentAccessBridge) AddVersion(cv cpi.ComponentVersionAccess, opts *cpi.AddVersionOptions) (ferr error) { var finalize finalizer.Finalizer defer finalize.FinalizeWithErrorPropagation(&ferr) - cvproxy, err := GetComponentVersionAccessProxy(cv) + cvbridge, err := GetComponentVersionAccessBridge(cv) if err != nil { return err } @@ -146,7 +146,7 @@ func (c *componentAccessProxy) AddVersion(cv cpi.ComponentVersionAccess, opts *c finalize.With(func() error { return eff.Close() }) - cvproxy, err = GetComponentVersionAccessProxy(eff) + cvbridge, err = GetComponentVersionAccessBridge(eff) if err != nil { return err } @@ -154,20 +154,20 @@ func (c *componentAccessProxy) AddVersion(cv cpi.ComponentVersionAccess, opts *c d := eff.GetDescriptor() *d = *cv.GetDescriptor().Copy() - err = c.setupLocalBlobs("resource", cv, cvproxy, d.Resources, &opts.BlobUploadOptions) + err = c.setupLocalBlobs("resource", cv, cvbridge, d.Resources, &opts.BlobUploadOptions) if err == nil { - err = c.setupLocalBlobs("source", cv, cvproxy, d.Sources, &opts.BlobUploadOptions) + err = c.setupLocalBlobs("source", cv, cvbridge, d.Sources, &opts.BlobUploadOptions) } if err != nil { return err } } - cvproxy.EnablePersistence() - err = cvproxy.Update(!cvproxy.UseDirectAccess()) + cvbridge.EnablePersistence() + err = cvbridge.Update(!cvbridge.UseDirectAccess()) return err } -func (c *componentAccessProxy) setupLocalBlobs(kind string, src cpi.ComponentVersionAccess, tgtproxy ComponentVersionAccessProxy, it compdesc.ArtifactAccessor, opts *cpi.BlobUploadOptions) (ferr error) { +func (c *componentAccessBridge) setupLocalBlobs(kind string, src cpi.ComponentVersionAccess, tgtbridge ComponentVersionAccessBridge, it compdesc.ArtifactAccessor, opts *cpi.BlobUploadOptions) (ferr error) { ctx := src.GetContext() // transfer all local blobs prov := func(spec cpi.AccessSpec) (blob blobaccess.BlobAccess, ref string, global cpi.AccessSpec, err error) { @@ -176,10 +176,10 @@ func (c *componentAccessProxy) setupLocalBlobs(kind string, src cpi.ComponentVer if err != nil { return nil, "", nil, err } - return m.AsBlobAccess(), cpi.ReferenceHint(spec, src), cpi.GlobalAccess(spec, tgtproxy.GetContext()), nil + return m.AsBlobAccess(), cpi.ReferenceHint(spec, src), cpi.GlobalAccess(spec, tgtbridge.GetContext()), nil } return nil, "", nil, nil } - return tgtproxy.(*componentVersionAccessProxy).setupLocalBlobs(kind, prov, it, false, opts) + return tgtbridge.(*componentVersionAccessBridge).setupLocalBlobs(kind, prov, it, false, opts) } diff --git a/pkg/contexts/ocm/cpi/repocpi/proxy_cv.go b/pkg/contexts/ocm/cpi/repocpi/bridge_cv.go similarity index 73% rename from pkg/contexts/ocm/cpi/repocpi/proxy_cv.go rename to pkg/contexts/ocm/cpi/repocpi/bridge_cv.go index ea2d56d03a..95bdc20a47 100644 --- a/pkg/contexts/ocm/cpi/repocpi/proxy_cv.go +++ b/pkg/contexts/ocm/cpi/repocpi/bridge_cv.go @@ -35,8 +35,8 @@ import ( // interface for component versions. type ComponentVersionAccessImpl interface { GetContext() cpi.Context - SetProxy(proxy ComponentVersionAccessProxy) - GetParentProxy() ComponentAccessProxy + SetBridge(bridge ComponentVersionAccessBridge) + GetParentBridge() ComponentAccessBridge Repository() cpi.Repository @@ -52,17 +52,17 @@ type ComponentVersionAccessImpl interface { io.Closer } -type _componentVersionAccessProxyBase = resource.ResourceImplBase[cpi.ComponentVersionAccess] +type _componentVersionAccessBridgeBase = resource.ResourceImplBase[cpi.ComponentVersionAccess] -// componentVersionAccessProxy is the counterpart to views, all views +// componentVersionAccessBridge is the counterpart to views, all views // created by Dup calls use this base object to work on. // Besides some functionality covered by view objects these base objects // implement provider-agnostic parts of the ComponentVersionAccess API. -type componentVersionAccessProxy struct { +type componentVersionAccessBridge struct { lock sync.Mutex id finalizer.ObjectIdentity - *_componentVersionAccessProxyBase + *_componentVersionAccessBridgeBase ctx cpi.Context name string version string @@ -78,37 +78,37 @@ type componentVersionAccessProxy struct { impl ComponentVersionAccessImpl } -var _ ComponentVersionAccessProxy = (*componentVersionAccessProxy)(nil) +var _ ComponentVersionAccessBridge = (*componentVersionAccessBridge)(nil) -func newComponentVersionAccessProxy(name, version string, impl ComponentVersionAccessImpl, lazy, persistent, direct bool, closer ...io.Closer) (ComponentVersionAccessProxy, error) { - base, err := resource.NewResourceImplBase[cpi.ComponentVersionAccess, cpi.ComponentAccess](impl.GetParentProxy(), closer...) +func newComponentVersionAccessBridge(name, version string, impl ComponentVersionAccessImpl, lazy, persistent, direct bool, closer ...io.Closer) (ComponentVersionAccessBridge, error) { + base, err := resource.NewResourceImplBase[cpi.ComponentVersionAccess, cpi.ComponentAccess](impl.GetParentBridge(), closer...) if err != nil { return nil, err } - b := &componentVersionAccessProxy{ - _componentVersionAccessProxyBase: base, - id: finalizer.NewObjectIdentity(fmt.Sprintf("%s:%s", name, version)), - ctx: impl.GetContext(), - name: name, - version: version, - blobcache: NewBlobCache(), - lazy: lazy, - persistent: persistent, - directAccess: direct, - impl: impl, - } - impl.SetProxy(b) + b := &componentVersionAccessBridge{ + _componentVersionAccessBridgeBase: base, + id: finalizer.NewObjectIdentity(fmt.Sprintf("%s:%s", name, version)), + ctx: impl.GetContext(), + name: name, + version: version, + blobcache: NewBlobCache(), + lazy: lazy, + persistent: persistent, + directAccess: direct, + impl: impl, + } + impl.SetBridge(b) return b, nil } func GetComponentVersionImpl[T ComponentVersionAccessImpl](cv cpi.ComponentVersionAccess) (T, error) { var _nil T - impl, err := GetComponentVersionAccessProxy(cv) + impl, err := GetComponentVersionAccessBridge(cv) if err != nil { return _nil, err } - if mine, ok := impl.(*componentVersionAccessProxy); ok { + if mine, ok := impl.(*componentVersionAccessBridge); ok { cont, ok := mine.impl.(T) if ok { return cont, nil @@ -118,7 +118,7 @@ func GetComponentVersionImpl[T ComponentVersionAccessImpl](cv cpi.ComponentVersi return _nil, errors.Newf("non-matching component version implementation %T", impl) } -func (b *componentVersionAccessProxy) Close() error { +func (b *componentVersionAccessBridge) Close() error { list := errors.ErrListf("closing component version %s", common.VersionedElementKey(b)) refmgmt.AllocLog.Trace("closing component version base", "name", common.VersionedElementKey(b)) // prepare artifact access for final close in @@ -127,33 +127,33 @@ func (b *componentVersionAccessProxy) Close() error { list.Add(b.update(true)) } list.Add(b.impl.Close()) - list.Add(b._componentVersionAccessProxyBase.Close()) + list.Add(b._componentVersionAccessBridgeBase.Close()) list.Add(b.blobcache.Clear()) refmgmt.AllocLog.Trace("closed component version base", "name", common.VersionedElementKey(b)) return list.Result() } -func (b *componentVersionAccessProxy) GetContext() cpi.Context { +func (b *componentVersionAccessBridge) GetContext() cpi.Context { return b.ctx } -func (b *componentVersionAccessProxy) GetName() string { +func (b *componentVersionAccessBridge) GetName() string { return b.name } -func (b *componentVersionAccessProxy) GetVersion() string { +func (b *componentVersionAccessBridge) GetVersion() string { return b.version } -func (b *componentVersionAccessProxy) GetImplementation() ComponentVersionAccessImpl { +func (b *componentVersionAccessBridge) GetImplementation() ComponentVersionAccessImpl { return b.impl } -func (b *componentVersionAccessProxy) GetBlobCache() BlobCache { +func (b *componentVersionAccessBridge) GetBlobCache() BlobCache { return b.blobcache } -func (b *componentVersionAccessProxy) EnablePersistence() bool { +func (b *componentVersionAccessBridge) EnablePersistence() bool { if b.discardChanges { return false } @@ -162,30 +162,30 @@ func (b *componentVersionAccessProxy) EnablePersistence() bool { return true } -func (b *componentVersionAccessProxy) IsPersistent() bool { +func (b *componentVersionAccessBridge) IsPersistent() bool { return b.persistent } -func (b *componentVersionAccessProxy) UseDirectAccess() bool { +func (b *componentVersionAccessBridge) UseDirectAccess() bool { return b.directAccess } -func (b *componentVersionAccessProxy) DiscardChanges() { +func (b *componentVersionAccessBridge) DiscardChanges() { b.discardChanges = true } -func (b *componentVersionAccessProxy) Repository() cpi.Repository { +func (b *componentVersionAccessBridge) Repository() cpi.Repository { return b.impl.Repository() } -func (b *componentVersionAccessProxy) IsReadOnly() bool { +func (b *componentVersionAccessBridge) IsReadOnly() bool { return b.impl.IsReadOnly() } //////////////////////////////////////////////////////////////////////////////// // with access to actual view -func (b *componentVersionAccessProxy) AccessMethod(spec cpi.AccessSpec, cv refmgmt.ExtendedAllocatable) (meth cpi.AccessMethod, err error) { +func (b *componentVersionAccessBridge) AccessMethod(spec cpi.AccessSpec, cv refmgmt.ExtendedAllocatable) (meth cpi.AccessMethod, err error) { switch { case compose.Is(spec): cspec, ok := spec.(*compose.AccessSpec) @@ -208,36 +208,36 @@ func (b *componentVersionAccessProxy) AccessMethod(spec cpi.AccessSpec, cv refmg return meth, err } -func (b *componentVersionAccessProxy) GetInexpensiveContentVersionIdentity(acc cpi.AccessSpec, cv refmgmt.ExtendedAllocatable) string { +func (b *componentVersionAccessBridge) GetInexpensiveContentVersionIdentity(acc cpi.AccessSpec, cv refmgmt.ExtendedAllocatable) string { return b.impl.GetInexpensiveContentVersionIdentity(acc, cv) } -func (b *componentVersionAccessProxy) GetDescriptor() *compdesc.ComponentDescriptor { +func (b *componentVersionAccessBridge) GetDescriptor() *compdesc.ComponentDescriptor { b.lock.Lock() defer b.lock.Unlock() return b.getDescriptor() } -func (b *componentVersionAccessProxy) getDescriptor() *compdesc.ComponentDescriptor { +func (b *componentVersionAccessBridge) getDescriptor() *compdesc.ComponentDescriptor { if b.descriptor == nil { b.descriptor = b.impl.GetDescriptor() } return b.descriptor } -func (b *componentVersionAccessProxy) GetStorageContext() cpi.StorageContext { +func (b *componentVersionAccessBridge) GetStorageContext() cpi.StorageContext { return b.impl.GetStorageContext() } -func (b *componentVersionAccessProxy) ShouldUpdate(final bool) bool { +func (b *componentVersionAccessBridge) ShouldUpdate(final bool) bool { b.lock.Lock() defer b.lock.Unlock() return b.shouldUpdate(final) } -func (b *componentVersionAccessProxy) shouldUpdate(final bool) bool { +func (b *componentVersionAccessBridge) shouldUpdate(final bool) bool { if b.discardChanges { return false } @@ -247,14 +247,14 @@ func (b *componentVersionAccessProxy) shouldUpdate(final bool) bool { return !b.lazy && b.directAccess && b.persistent } -func (b *componentVersionAccessProxy) Update(final bool) error { +func (b *componentVersionAccessBridge) Update(final bool) error { b.lock.Lock() defer b.lock.Unlock() return b.update(final) } -func (b *componentVersionAccessProxy) update(final bool) error { +func (b *componentVersionAccessBridge) update(final bool) error { if !b.shouldUpdate(final) { return nil } @@ -280,7 +280,7 @@ func (b *componentVersionAccessProxy) update(final bool) error { return err } -func (b *componentVersionAccessProxy) getLocalBlob(acc cpi.AccessSpec) cpi.BlobAccess { +func (b *componentVersionAccessBridge) getLocalBlob(acc cpi.AccessSpec) cpi.BlobAccess { key, err := json.Marshal(acc) if err != nil { return nil @@ -288,7 +288,7 @@ func (b *componentVersionAccessProxy) getLocalBlob(acc cpi.AccessSpec) cpi.BlobA return b.blobcache.GetBlobFor(string(key)) } -func (b *componentVersionAccessProxy) AddBlob(blob cpi.BlobAccess, artType, refName string, global cpi.AccessSpec, final bool, opts *cpi.BlobUploadOptions) (cpi.AccessSpec, error) { +func (b *componentVersionAccessBridge) AddBlob(blob cpi.BlobAccess, artType, refName string, global cpi.AccessSpec, final bool, opts *cpi.BlobUploadOptions) (cpi.AccessSpec, error) { if blob == nil { return nil, errors.New("a resource has to be defined") } @@ -349,7 +349,7 @@ func (b *componentVersionAccessProxy) AddBlob(blob cpi.BlobAccess, artType, refN return b.cacheLocalBlob(acc, blob) } -func (b *componentVersionAccessProxy) cacheLocalBlob(acc cpi.AccessSpec, blob cpi.BlobAccess) (cpi.AccessSpec, error) { +func (b *componentVersionAccessBridge) cacheLocalBlob(acc cpi.AccessSpec, blob cpi.BlobAccess) (cpi.AccessSpec, error) { key, err := json.Marshal(acc) if err != nil { return nil, errors.Wrapf(err, "cannot marshal access spec") @@ -377,7 +377,7 @@ func (b *componentVersionAccessProxy) cacheLocalBlob(acc cpi.AccessSpec, blob cp //////////////////////////////////////////////////////////////////////////////// -func (b *componentVersionAccessProxy) composeAccess(spec cpi.AccessSpec) (blobaccess.BlobAccess, string, cpi.AccessSpec, error) { +func (b *componentVersionAccessBridge) composeAccess(spec cpi.AccessSpec) (blobaccess.BlobAccess, string, cpi.AccessSpec, error) { if !compose.Is(spec) { return nil, "", nil, nil } @@ -397,7 +397,7 @@ func (b *componentVersionAccessProxy) composeAccess(spec cpi.AccessSpec) (blobac return blob, cspec.ReferenceName, cspec.GlobalAccess.Get(), nil } -func (b *componentVersionAccessProxy) setupLocalBlobs(kind string, accprov func(cpi.AccessSpec) (blobaccess.BlobAccess, string, cpi.AccessSpec, error), it compdesc.ArtifactAccessor, final bool, opts *cpi.BlobUploadOptions) (ferr error) { +func (b *componentVersionAccessBridge) setupLocalBlobs(kind string, accprov func(cpi.AccessSpec) (blobaccess.BlobAccess, string, cpi.AccessSpec, error), it compdesc.ArtifactAccessor, final bool, opts *cpi.BlobUploadOptions) (ferr error) { var finalize finalizer.Finalizer defer finalize.FinalizeWithErrorPropagation(&ferr) diff --git a/pkg/contexts/ocm/cpi/repocpi/proxy_r.go b/pkg/contexts/ocm/cpi/repocpi/bridge_r.go similarity index 58% rename from pkg/contexts/ocm/cpi/repocpi/proxy_r.go rename to pkg/contexts/ocm/cpi/repocpi/bridge_r.go index 1adae9295b..b2d6f093dc 100644 --- a/pkg/contexts/ocm/cpi/repocpi/proxy_r.go +++ b/pkg/contexts/ocm/cpi/repocpi/bridge_r.go @@ -20,7 +20,7 @@ type ComponentAccessInfo struct { } type RepositoryImpl interface { - SetProxy(proxy RepositoryProxy) + SetBridge(bridge RepositoryBridge) GetContext() cpi.Context @@ -33,52 +33,52 @@ type RepositoryImpl interface { io.Closer } -type _repositoryProxyBase = resource.ResourceImplBase[cpi.Repository] +type _repositoryBridgeBase = resource.ResourceImplBase[cpi.Repository] -type repositoryProxy struct { - *_repositoryProxyBase +type repositoryBridge struct { + *_repositoryBridgeBase ctx cpi.Context kind string impl RepositoryImpl } -func newRepositoryProxy(impl RepositoryImpl, kind string, closer ...io.Closer) RepositoryProxy { +func newRepositoryBridge(impl RepositoryImpl, kind string, closer ...io.Closer) RepositoryBridge { base := resource.NewSimpleResourceImplBase[cpi.Repository](closer...) - b := &repositoryProxy{ - _repositoryProxyBase: base, - ctx: impl.GetContext(), - impl: impl, + b := &repositoryBridge{ + _repositoryBridgeBase: base, + ctx: impl.GetContext(), + impl: impl, } - impl.SetProxy(b) + impl.SetBridge(b) return b } -func (b *repositoryProxy) Close() error { +func (b *repositoryBridge) Close() error { list := errors.ErrListf("closing %s", b.kind) - refmgmt.AllocLog.Trace("closing repository proxy", "kind", b.kind) + refmgmt.AllocLog.Trace("closing repository bridge", "kind", b.kind) list.Add(b.impl.Close()) - list.Add(b._repositoryProxyBase.Close()) - refmgmt.AllocLog.Trace("closed repository proxy", "kind", b.kind) + list.Add(b._repositoryBridgeBase.Close()) + refmgmt.AllocLog.Trace("closed repository bridge", "kind", b.kind) return list.Result() } -func (b *repositoryProxy) GetContext() cpi.Context { +func (b *repositoryBridge) GetContext() cpi.Context { return b.ctx } -func (b *repositoryProxy) GetSpecification() cpi.RepositorySpec { +func (b *repositoryBridge) GetSpecification() cpi.RepositorySpec { return b.impl.GetSpecification() } -func (b *repositoryProxy) ComponentLister() cpi.ComponentLister { +func (b *repositoryBridge) ComponentLister() cpi.ComponentLister { return b.impl.ComponentLister() } -func (b *repositoryProxy) ExistsComponentVersion(name string, version string) (bool, error) { +func (b *repositoryBridge) ExistsComponentVersion(name string, version string) (bool, error) { return b.impl.ExistsComponentVersion(name, version) } -func (b *repositoryProxy) LookupComponentVersion(name string, version string) (cv cpi.ComponentVersionAccess, rerr error) { +func (b *repositoryBridge) LookupComponentVersion(name string, version string) (cv cpi.ComponentVersionAccess, rerr error) { c, err := b.LookupComponent(name) if err != nil { return nil, err @@ -88,7 +88,7 @@ func (b *repositoryProxy) LookupComponentVersion(name string, version string) (c return c.LookupVersion(version) } -func (b *repositoryProxy) LookupComponent(name string) (cpi.ComponentAccess, error) { +func (b *repositoryBridge) LookupComponent(name string) (cpi.ComponentAccess, error) { i, err := b.impl.LookupComponent(name) if err != nil { return nil, err diff --git a/pkg/contexts/ocm/cpi/repocpi/doc.go b/pkg/contexts/ocm/cpi/repocpi/doc.go index 4b7f92a21f..017ad14993 100644 --- a/pkg/contexts/ocm/cpi/repocpi/doc.go +++ b/pkg/contexts/ocm/cpi/repocpi/doc.go @@ -18,15 +18,16 @@ // // a) the view objects provided by the Dup() calls of the layer 1 API. // All dups are internally based on a single base object. -// These objects are called proxy. They act as base object -// for the views and as wrapper for the implementation objects +// These objects are called bridge. They act as base object +// for the views and as abstraction for the implementation objects // providing generic implementations potentially based on // the implementation functionality. +// (see bridge design pattern https://refactoring.guru/design-patterns/bridge) // -// b) the base object for all dup views is used to implement some -// common functionality like the view management. The base object +// b) the bridge object as base for all dup views is used to implement some +// common functionality like the view management. The bridge object // is closed, when the last view disappears. -// This base object the uses forwards calls to the final +// This bridge object then calls the final // storage backend implementation interface. // // - the storage backend implementations based on the implementation @@ -42,15 +43,15 @@ // using the function [NewRepository]. // // Component version implementations provide basic access to component versions -// and their descriptors. The keep a reference to component implementations, which are -// again based of repository implementations. The task of repository implementations is -// to provide component objects. Their implementations are the responsible to provide +// and their descriptors. They keep a reference to component implementations, which are +// again based on repository implementations. The task of repository implementations is +// to provide component objects. Their implementations are responsible to provide // component version objects. // // Besides this basic implementation interface with separated object for a // repository, component and component version, there is support for a simplified // implementation interface (StorageBackendImpl). This is a single interface -// bundling all required functionality to implement the object for the three +// bundling all required functionality to implement the objects for the three // concerned elements. With NewStorageBackend it is possible to instantiate // a new kind of repository based on this single interface. The required // objects for components and component versions are generically provided diff --git a/pkg/contexts/ocm/cpi/repocpi/ocmimpllayers.png b/pkg/contexts/ocm/cpi/repocpi/ocmimpllayers.png new file mode 100755 index 0000000000..d0fc75645f Binary files /dev/null and b/pkg/contexts/ocm/cpi/repocpi/ocmimpllayers.png differ diff --git a/pkg/contexts/ocm/cpi/repocpi/view_c.go b/pkg/contexts/ocm/cpi/repocpi/view_c.go index f393faa827..fa6678c1a7 100644 --- a/pkg/contexts/ocm/cpi/repocpi/view_c.go +++ b/pkg/contexts/ocm/cpi/repocpi/view_c.go @@ -21,7 +21,7 @@ type _componentAccessView interface { type ComponentAccessViewManager = resource.ViewManager[cpi.ComponentAccess] // here you have to use an alias -type ComponentAccessProxy interface { +type ComponentAccessBridge interface { resource.ResourceImplementation[cpi.ComponentAccess] GetContext() cpi.Context @@ -41,7 +41,7 @@ type ComponentAccessProxy interface { type componentAccessView struct { _componentAccessView - proxy ComponentAccessProxy + bridge ComponentAccessBridge } var ( @@ -49,57 +49,57 @@ var ( _ utils.Unwrappable = (*componentAccessView)(nil) ) -func GetComponentAccessProxy(n cpi.ComponentAccess) (ComponentAccessProxy, error) { +func GetComponentAccessBridge(n cpi.ComponentAccess) (ComponentAccessBridge, error) { if v, ok := n.(*componentAccessView); ok { - return v.proxy, nil + return v.bridge, nil } return nil, errors.ErrNotSupported("component base type", fmt.Sprintf("%T", n)) } func GetComponentAccessImplementation(n cpi.ComponentAccess) (ComponentAccessImpl, error) { if v, ok := n.(*componentAccessView); ok { - if b, ok := v.proxy.(*componentAccessProxy); ok { + if b, ok := v.bridge.(*componentAccessBridge); ok { return b.impl, nil } - return nil, errors.ErrNotSupported("component base type", fmt.Sprintf("%T", v.proxy)) + return nil, errors.ErrNotSupported("component base type", fmt.Sprintf("%T", v.bridge)) } return nil, errors.ErrNotSupported("component implementation type", fmt.Sprintf("%T", n)) } -func componentAccessViewCreator(i ComponentAccessProxy, v resource.CloserView, d ComponentAccessViewManager) cpi.ComponentAccess { +func componentAccessViewCreator(i ComponentAccessBridge, v resource.CloserView, d ComponentAccessViewManager) cpi.ComponentAccess { return &componentAccessView{ _componentAccessView: resource.NewView[cpi.ComponentAccess](v, d), - proxy: i, + bridge: i, } } func NewComponentAccess(impl ComponentAccessImpl, kind string, main bool, closer ...io.Closer) (cpi.ComponentAccess, error) { - proxy, err := newComponentAccessProxy(impl, closer...) + bridge, err := newComponentAccessBridge(impl, closer...) if err != nil { return nil, errors.Join(err, impl.Close()) } if kind == "" { kind = "component" } - cv := resource.NewResource[cpi.ComponentAccess](proxy, componentAccessViewCreator, fmt.Sprintf("%s %s", kind, impl.GetName()), main) + cv := resource.NewResource[cpi.ComponentAccess](bridge, componentAccessViewCreator, fmt.Sprintf("%s %s", kind, impl.GetName()), main) return cv, nil } func (c *componentAccessView) Unwrap() interface{} { - return c.proxy + return c.bridge } func (c *componentAccessView) GetContext() cpi.Context { - return c.proxy.GetContext() + return c.bridge.GetContext() } func (c *componentAccessView) GetName() string { - return c.proxy.GetName() + return c.bridge.GetName() } func (c *componentAccessView) ListVersions() (list []string, err error) { err = c.Execute(func() error { - list, err = c.proxy.ListVersions() + list, err = c.bridge.ListVersions() return err }) return list, err @@ -107,7 +107,7 @@ func (c *componentAccessView) ListVersions() (list []string, err error) { func (c *componentAccessView) LookupVersion(version string) (acc cpi.ComponentVersionAccess, err error) { err = c.Execute(func() error { - acc, err = c.proxy.LookupVersion(version) + acc, err = c.bridge.LookupVersion(version) return err }) return acc, err @@ -119,7 +119,7 @@ func (c *componentAccessView) AddVersion(acc cpi.ComponentVersionAccess, overwri } return c.Execute(func() error { - return c.proxy.AddVersion(acc, cpi.NewAddVersionOptions(cpi.Overwrite(utils.Optional(overwrite...)))) + return c.bridge.AddVersion(acc, cpi.NewAddVersionOptions(cpi.Overwrite(utils.Optional(overwrite...)))) }) } @@ -128,16 +128,16 @@ func (c *componentAccessView) AddVersionOpt(acc cpi.ComponentVersionAccess, opts return errors.ErrInvalid("component name", acc.GetName()) } return c.Execute(func() error { - return c.proxy.AddVersion(acc, cpi.NewAddVersionOptions(opts...)) + return c.bridge.AddVersion(acc, cpi.NewAddVersionOptions(opts...)) }) } func (c *componentAccessView) NewVersion(version string, overrides ...bool) (acc cpi.ComponentVersionAccess, err error) { err = c.Execute(func() error { - if c.proxy.IsReadOnly() { + if c.bridge.IsReadOnly() { return accessio.ErrReadOnly } - acc, err = c.proxy.NewVersion(version, overrides...) + acc, err = c.bridge.NewVersion(version, overrides...) return err }) return acc, err @@ -145,7 +145,7 @@ func (c *componentAccessView) NewVersion(version string, overrides ...bool) (acc func (c *componentAccessView) HasVersion(vers string) (ok bool, err error) { err = c.Execute(func() error { - ok, err = c.proxy.HasVersion(vers) + ok, err = c.bridge.HasVersion(vers) return err }) return ok, err diff --git a/pkg/contexts/ocm/cpi/repocpi/view_cv.go b/pkg/contexts/ocm/cpi/repocpi/view_cv.go index d196b97885..f6c131f989 100644 --- a/pkg/contexts/ocm/cpi/repocpi/view_cv.go +++ b/pkg/contexts/ocm/cpi/repocpi/view_cv.go @@ -41,7 +41,7 @@ type _componentVersionAccessView interface { type ComponentVersionAccessViewManager = resource.ViewManager[cpi.ComponentVersionAccess] -type ComponentVersionAccessProxy interface { +type ComponentVersionAccessBridge interface { resource.ResourceImplementation[cpi.ComponentVersionAccess] common.VersionedElement io.Closer @@ -96,8 +96,8 @@ type ComponentVersionAccessProxy interface { type componentVersionAccessView struct { _componentVersionAccessView - proxy ComponentVersionAccessProxy - err error + bridge ComponentVersionAccessBridge + err error } var ( @@ -105,41 +105,41 @@ var ( _ utils.Unwrappable = (*componentVersionAccessView)(nil) ) -func GetComponentVersionAccessProxy(n cpi.ComponentVersionAccess) (ComponentVersionAccessProxy, error) { +func GetComponentVersionAccessBridge(n cpi.ComponentVersionAccess) (ComponentVersionAccessBridge, error) { if v, ok := n.(*componentVersionAccessView); ok { - return v.proxy, nil + return v.bridge, nil } - return nil, errors.ErrNotSupported("component version proxy type", fmt.Sprintf("%T", n)) + return nil, errors.ErrNotSupported("component version bridge type", fmt.Sprintf("%T", n)) } func GetComponentVersionAccessImplementation(n cpi.ComponentVersionAccess) (ComponentVersionAccessImpl, error) { if v, ok := n.(*componentVersionAccessView); ok { - if b, ok := v.proxy.(*componentVersionAccessProxy); ok { + if b, ok := v.bridge.(*componentVersionAccessBridge); ok { return b.impl, nil } - return nil, errors.ErrNotSupported("component version proxy type", fmt.Sprintf("%T", v.proxy)) + return nil, errors.ErrNotSupported("component version bridge type", fmt.Sprintf("%T", v.bridge)) } return nil, errors.ErrNotSupported("component version implementation type", fmt.Sprintf("%T", n)) } -func artifactAccessViewCreator(i ComponentVersionAccessProxy, v resource.CloserView, d resource.ViewManager[cpi.ComponentVersionAccess]) cpi.ComponentVersionAccess { +func artifactAccessViewCreator(i ComponentVersionAccessBridge, v resource.CloserView, d resource.ViewManager[cpi.ComponentVersionAccess]) cpi.ComponentVersionAccess { cv := &componentVersionAccessView{ _componentVersionAccessView: resource.NewView[cpi.ComponentVersionAccess](v, d), - proxy: i, + bridge: i, } return cv } func NewComponentVersionAccess(name, version string, impl ComponentVersionAccessImpl, lazy, persistent, direct bool, closer ...io.Closer) (cpi.ComponentVersionAccess, error) { - proxy, err := newComponentVersionAccessProxy(name, version, impl, lazy, persistent, direct, closer...) + bridge, err := newComponentVersionAccessBridge(name, version, impl, lazy, persistent, direct, closer...) if err != nil { return nil, errors.Join(err, impl.Close()) } - return resource.NewResource[cpi.ComponentVersionAccess](proxy, artifactAccessViewCreator, fmt.Sprintf("component version %s/%s", name, version), true), nil + return resource.NewResource[cpi.ComponentVersionAccess](bridge, artifactAccessViewCreator, fmt.Sprintf("component version %s/%s", name, version), true), nil } func (c *componentVersionAccessView) Unwrap() interface{} { - return c.proxy + return c.bridge } func (c *componentVersionAccessView) Close() error { @@ -149,23 +149,23 @@ func (c *componentVersionAccessView) Close() error { } func (c *componentVersionAccessView) Repository() cpi.Repository { - return c.proxy.Repository() + return c.bridge.Repository() } func (c *componentVersionAccessView) GetContext() internal.Context { - return c.proxy.GetContext() + return c.bridge.GetContext() } func (c *componentVersionAccessView) GetName() string { - return c.proxy.GetName() + return c.bridge.GetName() } func (c *componentVersionAccessView) GetVersion() string { - return c.proxy.GetVersion() + return c.bridge.GetVersion() } func (c *componentVersionAccessView) GetDescriptor() *compdesc.ComponentDescriptor { - return c.proxy.GetDescriptor() + return c.bridge.GetDescriptor() } func (c *componentVersionAccessView) GetProvider() *compdesc.Provider { @@ -195,7 +195,7 @@ func (c *componentVersionAccessView) AccessMethod(spec cpi.AccessSpec) (meth cpi func (c *componentVersionAccessView) accessMethod(spec cpi.AccessSpec) (meth cpi.AccessMethod, err error) { switch { case spec.IsLocal(c.GetContext()): - return c.proxy.AccessMethod(spec, c.Allocatable()) + return c.bridge.AccessMethod(spec, c.Allocatable()) default: return spec.AccessMethod(c) } @@ -225,16 +225,16 @@ func (c *componentVersionAccessView) getInexpensiveContentVersionIdentity(spec c // fall back to original version return spec.GetInexpensiveContentVersionIdentity(c) default: - return c.proxy.GetInexpensiveContentVersionIdentity(spec, c.Allocatable()) + return c.bridge.GetInexpensiveContentVersionIdentity(spec, c.Allocatable()) } } func (c *componentVersionAccessView) Update() error { return c.Execute(func() error { - if !c.proxy.IsPersistent() { + if !c.bridge.IsPersistent() { return ErrTempVersion } - return c.proxy.Update(true) + return c.bridge.Update(true) }) } @@ -243,7 +243,7 @@ func (c *componentVersionAccessView) AddBlob(blob cpi.BlobAccess, artType, refNa eff := cpi.NewBlobUploadOptions(opts...) err := c.Execute(func() error { var err error - spec, err = c.proxy.AddBlob(blob, artType, refName, global, false, eff) + spec, err = c.bridge.AddBlob(blob, artType, refName, global, false, eff) return err }) @@ -306,7 +306,7 @@ func setAccess[T any, A internal.ArtifactAccess[T]](c *componentVersionAccessVie set func(*T, compdesc.AccessSpec) error, setblob func(*T, cpi.BlobAccess, string, cpi.AccessSpec) error, ) error { - if c.proxy.IsReadOnly() { + if c.bridge.IsReadOnly() { return accessio.ErrReadOnly } meta := art.Meta() @@ -366,7 +366,7 @@ func (c *componentVersionAccessView) SetResourceAccess(art cpi.ResourceAccess, m } func (c *componentVersionAccessView) SetResource(meta *internal.ResourceMeta, acc compdesc.AccessSpec, modopts ...cpi.ModificationOption) error { - if c.proxy.IsReadOnly() { + if c.bridge.IsReadOnly() { return accessio.ErrReadOnly } @@ -375,11 +375,11 @@ func (c *componentVersionAccessView) SetResource(meta *internal.ResourceMeta, ac Access: acc, } - ctx := c.proxy.GetContext() + ctx := c.bridge.GetContext() opts := internal.NewModificationOptions(modopts...) cpi.CompleteModificationOptions(ctx, opts) - spec, err := c.proxy.GetContext().AccessSpecForSpec(acc) + spec, err := c.bridge.GetContext().AccessSpecForSpec(acc) if err != nil { return err } @@ -403,14 +403,14 @@ func (c *componentVersionAccessView) SetResource(meta *internal.ResourceMeta, ac } } - cd := c.proxy.GetDescriptor() + cd := c.bridge.GetDescriptor() idx := cd.GetResourceIndex(&res.ResourceMeta) if idx >= 0 { old = &cd.Resources[idx] } if old == nil { - if !opts.IsModifyResource() && c.proxy.IsPersistent() { + if !opts.IsModifyResource() && c.bridge.IsPersistent() { return fmt.Errorf("new resource would invalidate signature") } } @@ -456,7 +456,7 @@ func (c *componentVersionAccessView) SetResource(meta *internal.ResourceMeta, ac if old != nil { eq := res.Equivalent(old) - if !eq.IsLocalHashEqual() && c.proxy.IsPersistent() { + if !eq.IsLocalHashEqual() && c.bridge.IsPersistent() { if !opts.IsModifyResource() { return fmt.Errorf("resource would invalidate signature") } @@ -469,7 +469,7 @@ func (c *componentVersionAccessView) SetResource(meta *internal.ResourceMeta, ac } else { cd.Resources[idx] = *res } - return c.proxy.Update(false) + return c.bridge.Update(false) }) } @@ -500,7 +500,7 @@ func (c *componentVersionAccessView) evaluateResourceDigest(res, old *compdesc.R if !old.Digest.IsNone() { digester.HashAlgorithm = old.Digest.HashAlgorithm digester.NormalizationAlgorithm = old.Digest.NormalisationAlgorithm - if opts.IsAcceptExistentDigests() && !opts.IsModifyResource() && c.proxy.IsPersistent() { + if opts.IsAcceptExistentDigests() && !opts.IsModifyResource() && c.bridge.IsPersistent() { res.Digest = old.Digest value = old.Digest.Value } @@ -515,7 +515,7 @@ func (c *componentVersionAccessView) SetSourceByAccess(art cpi.SourceAccess) err } func (c *componentVersionAccessView) SetSource(meta *cpi.SourceMeta, acc compdesc.AccessSpec) error { - if c.proxy.IsReadOnly() { + if c.bridge.IsReadOnly() { return accessio.ErrReadOnly } @@ -525,40 +525,40 @@ func (c *componentVersionAccessView) SetSource(meta *cpi.SourceMeta, acc compdes } return c.Execute(func() error { if res.Version == "" { - res.Version = c.proxy.GetVersion() + res.Version = c.bridge.GetVersion() } - cd := c.proxy.GetDescriptor() + cd := c.bridge.GetDescriptor() if idx := cd.GetSourceIndex(&res.SourceMeta); idx == -1 { cd.Sources = append(cd.Sources, *res) } else { cd.Sources[idx] = *res } - return c.proxy.Update(false) + return c.bridge.Update(false) }) } func (c *componentVersionAccessView) SetReference(ref *cpi.ComponentReference) error { return c.Execute(func() error { - cd := c.proxy.GetDescriptor() + cd := c.bridge.GetDescriptor() if idx := cd.GetComponentReferenceIndex(*ref); idx == -1 { cd.References = append(cd.References, *ref) } else { cd.References[idx] = *ref } - return c.proxy.Update(false) + return c.bridge.Update(false) }) } func (c *componentVersionAccessView) DiscardChanges() { - c.proxy.DiscardChanges() + c.bridge.DiscardChanges() } func (c *componentVersionAccessView) IsPersistent() bool { - return c.proxy.IsPersistent() + return c.bridge.IsPersistent() } func (c *componentVersionAccessView) UseDirectAccess() bool { - return c.proxy.UseDirectAccess() + return c.bridge.UseDirectAccess() } //////////////////////////////////////////////////////////////////////////////// diff --git a/pkg/contexts/ocm/cpi/repocpi/view_r.go b/pkg/contexts/ocm/cpi/repocpi/view_r.go index f7073a3925..3c94f10fb6 100644 --- a/pkg/contexts/ocm/cpi/repocpi/view_r.go +++ b/pkg/contexts/ocm/cpi/repocpi/view_r.go @@ -30,7 +30,7 @@ type _repositoryView interface { type RepositoryViewManager = resource.ViewManager[cpi.Repository] // here you have to use an alias -type RepositoryProxy interface { +type RepositoryBridge interface { resource.ResourceImplementation[cpi.Repository] GetContext() cpi.Context @@ -47,7 +47,7 @@ type RepositoryProxy interface { type repositoryView struct { _repositoryView - proxy RepositoryProxy + bridge RepositoryBridge } var ( @@ -56,74 +56,74 @@ var ( _ utils.Unwrappable = (*repositoryView)(nil) ) -func GetRepositoryProxy(n cpi.Repository) (RepositoryProxy, error) { +func GetRepositoryBridge(n cpi.Repository) (RepositoryBridge, error) { if v, ok := n.(*repositoryView); ok { - return v.proxy, nil + return v.bridge, nil } return nil, errors.ErrNotSupported("repository implementation type", fmt.Sprintf("%T", n)) } func GetRepositoryImplementation(n cpi.Repository) (RepositoryImpl, error) { if v, ok := n.(*repositoryView); ok { - if b, ok := v.proxy.(*repositoryProxy); ok { + if b, ok := v.bridge.(*repositoryBridge); ok { return b.impl, nil } - return nil, errors.ErrNotSupported("repository base type", fmt.Sprintf("%T", v.proxy)) + return nil, errors.ErrNotSupported("repository base type", fmt.Sprintf("%T", v.bridge)) } return nil, errors.ErrNotSupported("repository implementation type", fmt.Sprintf("%T", n)) } -func repositoryViewCreator(i RepositoryProxy, v resource.CloserView, d RepositoryViewManager) cpi.Repository { +func repositoryViewCreator(i RepositoryBridge, v resource.CloserView, d RepositoryViewManager) cpi.Repository { return &repositoryView{ _repositoryView: resource.NewView[cpi.Repository](v, d), - proxy: i, + bridge: i, } } // NewNoneRefRepositoryView provides a repository reflecting the state of the // view manager without holding an additional reference. -func NewNoneRefRepositoryView(i RepositoryProxy) cpi.Repository { +func NewNoneRefRepositoryView(i RepositoryBridge) cpi.Repository { return &repositoryView{ _repositoryView: resource.NewView[cpi.Repository](resource.NewNonRefView[cpi.Repository](i), i), - proxy: i, + bridge: i, } } func NewRepository(impl RepositoryImpl, kind string, closer ...io.Closer) cpi.Repository { - proxy := newRepositoryProxy(impl, kind, closer...) + bridge := newRepositoryBridge(impl, kind, closer...) if kind == "" { kind = "OCM repository" } - return resource.NewResource[cpi.Repository](proxy, repositoryViewCreator, kind, true) + return resource.NewResource[cpi.Repository](bridge, repositoryViewCreator, kind, true) } func (r *repositoryView) Unwrap() interface{} { - return r.proxy + return r.bridge } func (r *repositoryView) GetConsumerId(uctx ...credentials.UsageContext) credentials.ConsumerIdentity { - return credentials.GetProvidedConsumerId(r.proxy, uctx...) + return credentials.GetProvidedConsumerId(r.bridge, uctx...) } func (r *repositoryView) GetIdentityMatcher() string { - return credentials.GetProvidedIdentityMatcher(r.proxy) + return credentials.GetProvidedIdentityMatcher(r.bridge) } func (r *repositoryView) GetSpecification() cpi.RepositorySpec { - return r.proxy.GetSpecification() + return r.bridge.GetSpecification() } func (r *repositoryView) GetContext() cpi.Context { - return r.proxy.GetContext() + return r.bridge.GetContext() } func (r *repositoryView) ComponentLister() cpi.ComponentLister { - return r.proxy.ComponentLister() + return r.bridge.ComponentLister() } func (r *repositoryView) ExistsComponentVersion(name string, version string) (ok bool, err error) { err = r.Execute(func() error { - ok, err = r.proxy.ExistsComponentVersion(name, version) + ok, err = r.bridge.ExistsComponentVersion(name, version) return err }) return ok, err @@ -131,7 +131,7 @@ func (r *repositoryView) ExistsComponentVersion(name string, version string) (ok func (r *repositoryView) LookupComponentVersion(name string, version string) (acc cpi.ComponentVersionAccess, err error) { err = r.Execute(func() error { - acc, err = r.proxy.LookupComponentVersion(name, version) + acc, err = r.bridge.LookupComponentVersion(name, version) return err }) return acc, err @@ -139,7 +139,7 @@ func (r *repositoryView) LookupComponentVersion(name string, version string) (ac func (r *repositoryView) LookupComponent(name string) (acc cpi.ComponentAccess, err error) { err = r.Execute(func() error { - acc, err = r.proxy.LookupComponent(name) + acc, err = r.bridge.LookupComponent(name) return err }) return acc, err diff --git a/pkg/contexts/ocm/repositories/comparch/componentarchive.go b/pkg/contexts/ocm/repositories/comparch/componentarchive.go index 37b01a1f5c..1ee8f4cf25 100644 --- a/pkg/contexts/ocm/repositories/comparch/componentarchive.go +++ b/pkg/contexts/ocm/repositories/comparch/componentarchive.go @@ -103,7 +103,7 @@ func (c *ComponentArchive) SetVersion(v string) { type componentArchiveContainer struct { ctx cpi.Context - base repocpi.ComponentVersionAccessProxy + base repocpi.ComponentVersionAccessBridge fsacc *accessobj.FileSystemBlobAccess spec *RepositorySpec repo cpi.Repository @@ -111,11 +111,11 @@ type componentArchiveContainer struct { var _ repocpi.ComponentVersionAccessImpl = (*componentArchiveContainer)(nil) -func (c *componentArchiveContainer) SetProxy(base repocpi.ComponentVersionAccessProxy) { +func (c *componentArchiveContainer) SetBridge(base repocpi.ComponentVersionAccessBridge) { c.base = base } -func (c *componentArchiveContainer) GetParentProxy() repocpi.ComponentAccessProxy { +func (c *componentArchiveContainer) GetParentBridge() repocpi.ComponentAccessBridge { return nil } diff --git a/pkg/contexts/ocm/repositories/comparch/repository.go b/pkg/contexts/ocm/repositories/comparch/repository.go index c2c81fd957..7ab49eea54 100644 --- a/pkg/contexts/ocm/repositories/comparch/repository.go +++ b/pkg/contexts/ocm/repositories/comparch/repository.go @@ -26,7 +26,7 @@ import ( type RepositoryImpl struct { lock sync.RWMutex - base repocpi.RepositoryProxy + bridge repocpi.RepositoryBridge arch *ComponentArchive nonref cpi.Repository } @@ -57,8 +57,8 @@ func (r *RepositoryImpl) Close() error { return r.arch.container.Close() } -func (r *RepositoryImpl) SetProxy(base repocpi.RepositoryProxy) { - r.base = base +func (r *RepositoryImpl) SetBridge(base repocpi.RepositoryBridge) { + r.bridge = base r.nonref = repocpi.NewNoneRefRepositoryView(base) } @@ -143,7 +143,7 @@ func (r *RepositoryImpl) LookupComponent(name string) (*repocpi.ComponentAccessI //////////////////////////////////////////////////////////////////////////////// type ComponentAccessImpl struct { - base repocpi.ComponentAccessProxy + base repocpi.ComponentAccessBridge repo *RepositoryImpl } @@ -160,12 +160,12 @@ func (c *ComponentAccessImpl) Close() error { return nil } -func (c *ComponentAccessImpl) SetProxy(base repocpi.ComponentAccessProxy) { +func (c *ComponentAccessImpl) SetBridge(base repocpi.ComponentAccessBridge) { c.base = base } -func (c *ComponentAccessImpl) GetParentProxy() repocpi.RepositoryViewManager { - return c.repo.base +func (c *ComponentAccessImpl) GetParentBridge() repocpi.RepositoryViewManager { + return c.repo.bridge } func (c *ComponentAccessImpl) GetContext() cpi.Context { @@ -208,7 +208,7 @@ func (c *ComponentAccessImpl) NewVersion(version string, overrides ...bool) (*re //////////////////////////////////////////////////////////////////////////////// type ComponentVersionContainer struct { - impl repocpi.ComponentVersionAccessProxy + impl repocpi.ComponentVersionAccessBridge comp *ComponentAccessImpl @@ -232,11 +232,11 @@ func newComponentVersionContainer(comp *ComponentAccessImpl) (*ComponentVersionC }, nil } -func (c *ComponentVersionContainer) SetProxy(impl repocpi.ComponentVersionAccessProxy) { +func (c *ComponentVersionContainer) SetBridge(impl repocpi.ComponentVersionAccessBridge) { c.impl = impl } -func (c *ComponentVersionContainer) GetParentProxy() repocpi.ComponentAccessProxy { +func (c *ComponentVersionContainer) GetParentBridge() repocpi.ComponentAccessBridge { return c.comp.base } diff --git a/pkg/contexts/ocm/repositories/genericocireg/component.go b/pkg/contexts/ocm/repositories/genericocireg/component.go index acc87cf4ff..9343493847 100644 --- a/pkg/contexts/ocm/repositories/genericocireg/component.go +++ b/pkg/contexts/ocm/repositories/genericocireg/component.go @@ -24,7 +24,7 @@ const META_SEPARATOR = ".build-" //////////////////////////////////////////////////////////////////////////////// type componentAccessImpl struct { - base repocpi.ComponentAccessProxy + bridge repocpi.ComponentAccessBridge repo *RepositoryImpl name string namespace oci.NamespaceAccess @@ -54,12 +54,12 @@ func (c *componentAccessImpl) Close() error { return err } -func (c *componentAccessImpl) SetProxy(base repocpi.ComponentAccessProxy) { - c.base = base +func (c *componentAccessImpl) SetBridge(base repocpi.ComponentAccessBridge) { + c.bridge = base } -func (c *componentAccessImpl) GetParentProxy() repocpi.RepositoryViewManager { - return c.repo.base +func (c *componentAccessImpl) GetParentBridge() repocpi.RepositoryViewManager { + return c.repo.bridge } func (c *componentAccessImpl) GetContext() cpi.Context { diff --git a/pkg/contexts/ocm/repositories/genericocireg/componentversion.go b/pkg/contexts/ocm/repositories/genericocireg/componentversion.go index 8657f65775..808f737f2b 100644 --- a/pkg/contexts/ocm/repositories/genericocireg/componentversion.go +++ b/pkg/contexts/ocm/repositories/genericocireg/componentversion.go @@ -44,7 +44,7 @@ func newComponentVersionAccess(mode accessobj.AccessMode, comp *componentAccessI // ////////////////////////////////////////////////////////////////////////////// type ComponentVersionContainer struct { - impl repocpi.ComponentVersionAccessProxy + bridge repocpi.ComponentVersionAccessBridge comp *componentAccessImpl version string @@ -75,12 +75,12 @@ func newComponentVersionContainer(mode accessobj.AccessMode, comp *componentAcce }, nil } -func (c *ComponentVersionContainer) SetProxy(impl repocpi.ComponentVersionAccessProxy) { - c.impl = impl +func (c *ComponentVersionContainer) SetBridge(impl repocpi.ComponentVersionAccessBridge) { + c.bridge = impl } -func (c *ComponentVersionContainer) GetParentProxy() repocpi.ComponentAccessProxy { - return c.comp.base +func (c *ComponentVersionContainer) GetParentBridge() repocpi.ComponentAccessBridge { + return c.comp.bridge } func (c *ComponentVersionContainer) Close() error { diff --git a/pkg/contexts/ocm/repositories/genericocireg/repository.go b/pkg/contexts/ocm/repositories/genericocireg/repository.go index 9040e72e4a..88a5824eb2 100644 --- a/pkg/contexts/ocm/repositories/genericocireg/repository.go +++ b/pkg/contexts/ocm/repositories/genericocireg/repository.go @@ -40,7 +40,7 @@ func GetOCIRepository(r cpi.Repository) ocicpi.Repository { } type RepositoryImpl struct { - base repocpi.RepositoryProxy + bridge repocpi.RepositoryBridge ctx cpi.Context meta ComponentRepositoryMeta nonref cpi.Repository @@ -65,8 +65,8 @@ func (r *RepositoryImpl) Close() error { return r.ocirepo.Close() } -func (r *RepositoryImpl) SetProxy(base repocpi.RepositoryProxy) { - r.base = base +func (r *RepositoryImpl) SetBridge(base repocpi.RepositoryBridge) { + r.bridge = base r.nonref = repocpi.NewNoneRefRepositoryView(base) } diff --git a/pkg/contexts/ocm/repositories/virtual/component.go b/pkg/contexts/ocm/repositories/virtual/component.go index a930ba51f1..b09ad99ee2 100644 --- a/pkg/contexts/ocm/repositories/virtual/component.go +++ b/pkg/contexts/ocm/repositories/virtual/component.go @@ -12,7 +12,7 @@ import ( ) type componentAccessImpl struct { - base repocpi.ComponentAccessProxy + bridge repocpi.ComponentAccessBridge repo *RepositoryImpl name string @@ -32,12 +32,12 @@ func (c *componentAccessImpl) Close() error { return nil } -func (c *componentAccessImpl) SetProxy(base repocpi.ComponentAccessProxy) { - c.base = base +func (c *componentAccessImpl) SetBridge(base repocpi.ComponentAccessBridge) { + c.bridge = base } -func (c *componentAccessImpl) GetParentProxy() repocpi.RepositoryViewManager { - return c.repo.base +func (c *componentAccessImpl) GetParentBridge() repocpi.RepositoryViewManager { + return c.repo.bridge } func (c *componentAccessImpl) GetContext() cpi.Context { diff --git a/pkg/contexts/ocm/repositories/virtual/componentversion.go b/pkg/contexts/ocm/repositories/virtual/componentversion.go index 0c9aa4fdd7..a74f4c1dbd 100644 --- a/pkg/contexts/ocm/repositories/virtual/componentversion.go +++ b/pkg/contexts/ocm/repositories/virtual/componentversion.go @@ -33,7 +33,7 @@ func newComponentVersionAccess(comp *componentAccessImpl, version string, persis // ////////////////////////////////////////////////////////////////////////////// type ComponentVersionContainer struct { - base repocpi.ComponentVersionAccessProxy + bridge repocpi.ComponentVersionAccessBridge comp *componentAccessImpl version string @@ -50,12 +50,12 @@ func newComponentVersionContainer(comp *componentAccessImpl, version string, acc }, nil } -func (c *ComponentVersionContainer) SetProxy(base repocpi.ComponentVersionAccessProxy) { - c.base = base +func (c *ComponentVersionContainer) SetBridge(base repocpi.ComponentVersionAccessBridge) { + c.bridge = base } -func (c *ComponentVersionContainer) GetParentProxy() repocpi.ComponentAccessProxy { - return c.comp.base +func (c *ComponentVersionContainer) GetParentBridge() repocpi.ComponentAccessBridge { + return c.comp.bridge } func (c *ComponentVersionContainer) Close() error { diff --git a/pkg/contexts/ocm/repositories/virtual/repository.go b/pkg/contexts/ocm/repositories/virtual/repository.go index 3071faffe2..a1cc262e70 100644 --- a/pkg/contexts/ocm/repositories/virtual/repository.go +++ b/pkg/contexts/ocm/repositories/virtual/repository.go @@ -10,7 +10,7 @@ import ( ) type RepositoryImpl struct { - base repocpi.RepositoryProxy + bridge repocpi.RepositoryBridge ctx cpi.Context access Access nonref cpi.Repository @@ -30,8 +30,8 @@ func (r *RepositoryImpl) Close() error { return r.access.Close() } -func (r *RepositoryImpl) SetProxy(base repocpi.RepositoryProxy) { - r.base = base +func (r *RepositoryImpl) SetBridge(base repocpi.RepositoryBridge) { + r.bridge = base r.nonref = repocpi.NewNoneRefRepositoryView(base) }