Skip to content

Commit

Permalink
rename base to proxy
Browse files Browse the repository at this point in the history
  • Loading branch information
mandelsoft committed Nov 28, 2023
1 parent c0d5a9d commit 203c9ee
Show file tree
Hide file tree
Showing 16 changed files with 240 additions and 244 deletions.
34 changes: 17 additions & 17 deletions pkg/contexts/ocm/cpi/repocpi/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
// and component version objects, which are generically implemented
// based on the methods of this interface.
//
// A repositotry interface based on this implementation interface can be
// A repository interface based on this implementation interface can be
// created using the function NewStorageBackend.
type StorageBackendImpl interface {
// repository related methods.
Expand Down Expand Up @@ -52,7 +52,7 @@ type StorageBackendImpl interface {
}

type storageBackendRepository struct {
base RepositoryBase
proxy RepositoryProxy
closed atomic.Bool
noref cpi.Repository
kind string
Expand All @@ -78,9 +78,9 @@ func NewStorageBackend(kind string, impl StorageBackendImpl) cpi.Repository {
return NewRepository(backend, kind)
}

func (s *storageBackendRepository) SetBase(base RepositoryBase) {
s.base = base
s.noref = NewNoneRefRepositoryView(base)
func (s *storageBackendRepository) SetProxy(proxy RepositoryProxy) {
s.proxy = proxy
s.noref = NewNoneRefRepositoryView(proxy)
}

func (s *storageBackendRepository) Close() error {
Expand Down Expand Up @@ -124,19 +124,19 @@ func (s *storageBackendRepository) LookupComponent(name string) (*ComponentAcces
////////////////////////////////////////////////////////////////////////////////

type storageBackendComponent struct {
base ComponentAccessBase
repo *storageBackendRepository
name string
proxy ComponentAccessProxy
repo *storageBackendRepository
name string
}

var _ ComponentAccessImpl = (*storageBackendComponent)(nil)

func (s *storageBackendComponent) SetBase(base ComponentAccessBase) {
s.base = base
func (s *storageBackendComponent) SetProxy(proxy ComponentAccessProxy) {
s.proxy = proxy
}

func (s *storageBackendComponent) GetParentBase() RepositoryViewManager {
return s.repo.base
func (s *storageBackendComponent) GetParentProxy() RepositoryViewManager {
return s.repo.proxy
}

func (s *storageBackendComponent) Close() error {
Expand Down Expand Up @@ -213,7 +213,7 @@ func (s *storageBackendComponent) NewVersion(version string, overwrite ...bool)
////////////////////////////////////////////////////////////////////////////////

type storageBackendComponentVersion struct {
base ComponentVersionAccessBase
proxy ComponentVersionAccessProxy
comp *storageBackendComponent
name common.NameVersion
descriptor *compdesc.ComponentDescriptor
Expand All @@ -229,12 +229,12 @@ func (s *storageBackendComponentVersion) GetContext() cpi.Context {
return s.comp.repo.impl.GetContext()
}

func (s *storageBackendComponentVersion) SetBase(base ComponentVersionAccessBase) {
s.base = base
func (s *storageBackendComponentVersion) SetProxy(proxy ComponentVersionAccessProxy) {
s.proxy = proxy
}

func (s *storageBackendComponentVersion) GetParentBase() ComponentAccessBase {
return s.comp.base
func (s *storageBackendComponentVersion) GetParentProxy() ComponentAccessProxy {
return s.comp.proxy
}

func (s *storageBackendComponentVersion) Repository() cpi.Repository {
Expand Down
6 changes: 5 additions & 1 deletion pkg/contexts/ocm/cpi/repocpi/doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,15 @@
// in package [github.com/open-component-model/ocm/pkg/contexts/ocm].
//
// - on layer 2 (this package) there is a backend agnostic
// implementation od standard functionality based on layer 3.
// 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 proxy. They act as base object
// for the views and as wrapper for the implementation objects
// providing generic implementations potentially based on
// the implementation functionality.
//
// b) the base object for all dup views is used to implement some
// common functionality like the view management. The base object
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ type ComponentVersionAccessInfo struct {
// ComponentAccessImpl is the provider implementation
// interface for component versions.
type ComponentAccessImpl interface {
SetBase(base ComponentAccessBase)
GetParentBase() RepositoryViewManager
SetProxy(proxy ComponentAccessProxy)
GetParentProxy() RepositoryViewManager

GetContext() cpi.Context
GetName() string
Expand All @@ -42,67 +42,67 @@ type ComponentAccessImpl interface {
io.Closer
}

type _componentAccessImplBase = resource.ResourceImplBase[cpi.ComponentAccess]
type _componentAccessProxyBase = resource.ResourceImplBase[cpi.ComponentAccess]

type componentAccessBase struct {
*_componentAccessImplBase
type componentAccessProxy struct {
*_componentAccessProxyBase
ctx cpi.Context
name string
impl ComponentAccessImpl
}

func newComponentAccessImplBase(impl ComponentAccessImpl, closer ...io.Closer) (ComponentAccessBase, error) {
base, err := resource.NewResourceImplBase[cpi.ComponentAccess, cpi.Repository](impl.GetParentBase(), closer...)
func newComponentAccessProxy(impl ComponentAccessImpl, closer ...io.Closer) (ComponentAccessProxy, error) {
base, err := resource.NewResourceImplBase[cpi.ComponentAccess, cpi.Repository](impl.GetParentProxy(), closer...)
if err != nil {
return nil, err
}
b := &componentAccessBase{
_componentAccessImplBase: base,
ctx: impl.GetContext(),
name: impl.GetName(),
impl: impl,
b := &componentAccessProxy{
_componentAccessProxyBase: base,
ctx: impl.GetContext(),
name: impl.GetName(),
impl: impl,
}
impl.SetBase(b)
impl.SetProxy(b)
return b, nil
}

func (b *componentAccessBase) Close() error {
func (b *componentAccessProxy) Close() error {
list := errors.ErrListf("closing component %s", b.name)
refmgmt.AllocLog.Trace("closing component base", "name", b.name)
refmgmt.AllocLog.Trace("closing component proxy", "name", b.name)
list.Add(b.impl.Close())
list.Add(b._componentAccessImplBase.Close())
refmgmt.AllocLog.Trace("closed component base", "name", b.name)
list.Add(b._componentAccessProxyBase.Close())
refmgmt.AllocLog.Trace("closed component proxy", "name", b.name)
return list.Result()
}

func (b *componentAccessBase) GetContext() cpi.Context {
func (b *componentAccessProxy) GetContext() cpi.Context {
return b.ctx
}

func (b *componentAccessBase) GetName() string {
func (b *componentAccessProxy) GetName() string {
return b.name
}

func (b *componentAccessBase) IsReadOnly() bool {
func (b *componentAccessProxy) IsReadOnly() bool {
return b.impl.IsReadOnly()
}

func (c *componentAccessBase) IsOwned(cv cpi.ComponentVersionAccess) bool {
base, err := GetComponentVersionAccessBase(cv)
func (c *componentAccessProxy) IsOwned(cv cpi.ComponentVersionAccess) bool {
proxy, err := GetComponentVersionAccessProxy(cv)
if err != nil {
return false
}

impl := base.(*componentVersionAccessBase).impl
cvcompmgr := impl.GetParentBase()
impl := proxy.(*componentVersionAccessProxy).impl
cvcompmgr := impl.GetParentProxy()
return c == cvcompmgr
}

func (b *componentAccessBase) ListVersions() ([]string, error) {
func (b *componentAccessProxy) ListVersions() ([]string, error) {
return b.impl.ListVersions()
}

func (b *componentAccessBase) LookupVersion(version string) (cpi.ComponentVersionAccess, error) {
func (b *componentAccessProxy) LookupVersion(version string) (cpi.ComponentVersionAccess, error) {
i, err := b.impl.LookupVersion(version)
if err != nil {
return nil, err
Expand All @@ -113,11 +113,11 @@ func (b *componentAccessBase) LookupVersion(version string) (cpi.ComponentVersio
return NewComponentVersionAccess(b.GetName(), version, i.Impl, i.Lazy, i.Persistent, !compositionmodeattr.Get(b.GetContext()))
}

func (b *componentAccessBase) HasVersion(vers string) (bool, error) {
func (b *componentAccessProxy) HasVersion(vers string) (bool, error) {
return b.impl.HasVersion(vers)
}

func (b *componentAccessBase) NewVersion(version string, overrides ...bool) (cpi.ComponentVersionAccess, error) {
func (b *componentAccessProxy) NewVersion(version string, overrides ...bool) (cpi.ComponentVersionAccess, error) {
i, err := b.impl.NewVersion(version, overrides...)
if err != nil {
return nil, err
Expand All @@ -128,11 +128,11 @@ func (b *componentAccessBase) NewVersion(version string, overrides ...bool) (cpi
return NewComponentVersionAccess(b.GetName(), version, i.Impl, i.Lazy, false, !compositionmodeattr.Get(b.GetContext()))
}

func (c *componentAccessBase) AddVersion(cv cpi.ComponentVersionAccess, opts *cpi.AddVersionOptions) (ferr error) {
func (c *componentAccessProxy) AddVersion(cv cpi.ComponentVersionAccess, opts *cpi.AddVersionOptions) (ferr error) {
var finalize finalizer.Finalizer
defer finalize.FinalizeWithErrorPropagation(&ferr)

cvbase, err := GetComponentVersionAccessBase(cv)
cvproxy, err := GetComponentVersionAccessProxy(cv)
if err != nil {
return err
}
Expand All @@ -146,28 +146,28 @@ func (c *componentAccessBase) AddVersion(cv cpi.ComponentVersionAccess, opts *cp
finalize.With(func() error {
return eff.Close()
})
cvbase, err = GetComponentVersionAccessBase(eff)
cvproxy, err = GetComponentVersionAccessProxy(eff)
if err != nil {
return err
}

d := eff.GetDescriptor()
*d = *cv.GetDescriptor().Copy()

err = c.setupLocalBlobs("resource", cv, cvbase, d.Resources, &opts.BlobUploadOptions)
err = c.setupLocalBlobs("resource", cv, cvproxy, d.Resources, &opts.BlobUploadOptions)
if err == nil {
err = c.setupLocalBlobs("source", cv, cvbase, d.Sources, &opts.BlobUploadOptions)
err = c.setupLocalBlobs("source", cv, cvproxy, d.Sources, &opts.BlobUploadOptions)
}
if err != nil {
return err
}
}
cvbase.EnablePersistence()
err = cvbase.Update(!cvbase.UseDirectAccess())
cvproxy.EnablePersistence()
err = cvproxy.Update(!cvproxy.UseDirectAccess())
return err
}

func (c *componentAccessBase) setupLocalBlobs(kind string, src cpi.ComponentVersionAccess, tgtbase ComponentVersionAccessBase, it compdesc.ArtifactAccessor, opts *cpi.BlobUploadOptions) (ferr error) {
func (c *componentAccessProxy) setupLocalBlobs(kind string, src cpi.ComponentVersionAccess, tgtproxy ComponentVersionAccessProxy, 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) {
Expand All @@ -176,10 +176,10 @@ func (c *componentAccessBase) setupLocalBlobs(kind string, src cpi.ComponentVers
if err != nil {
return nil, "", nil, err
}
return m.AsBlobAccess(), cpi.ReferenceHint(spec, src), cpi.GlobalAccess(spec, tgtbase.GetContext()), nil
return m.AsBlobAccess(), cpi.ReferenceHint(spec, src), cpi.GlobalAccess(spec, tgtproxy.GetContext()), nil
}
return nil, "", nil, nil
}

return tgtbase.(*componentVersionAccessBase).setupLocalBlobs(kind, prov, it, false, opts)
return tgtproxy.(*componentVersionAccessProxy).setupLocalBlobs(kind, prov, it, false, opts)
}
Loading

0 comments on commit 203c9ee

Please sign in to comment.