From 84201e964678f0be73ed0680b4031e15e41caf39 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs=20Garc=C3=ADa=20Crespo?= Date: Sat, 18 May 2024 05:37:07 +0000 Subject: [PATCH] Implement auto-approval bypass --- hack/ccp/internal/controller/iterator.go | 31 +++++-- hack/ccp/internal/controller/package.go | 12 ++- hack/ccp/internal/controller/transfer.go | 112 +++++++++++------------ 3 files changed, 86 insertions(+), 69 deletions(-) diff --git a/hack/ccp/internal/controller/iterator.go b/hack/ccp/internal/controller/iterator.go index 5ba0a3d02..52fd61260 100644 --- a/hack/ccp/internal/controller/iterator.go +++ b/hack/ccp/internal/controller/iterator.go @@ -62,7 +62,9 @@ type iterator struct { p *Package - startAt uuid.UUID + startAtChainID uuid.UUID + + startAtLinkID uuid.UUID chain *chain @@ -71,12 +73,13 @@ type iterator struct { func NewIterator(logger logr.Logger, gearman *gearmin.Server, wf *workflow.Document, p *Package) *iterator { iter := &iterator{ - logger: logger, - gearman: gearman, - wf: wf, - p: p, - startAt: p.startAt, - waitCh: make(chan waitSignal, 10), + logger: logger, + gearman: gearman, + wf: wf, + p: p, + startAtChainID: p.startAtChainID, + startAtLinkID: p.startAtLinkID, + waitCh: make(chan waitSignal, 10), } return iter @@ -93,7 +96,12 @@ func (i *iterator) Process(ctx context.Context) (err error) { } }() - next := i.startAt + next := i.startAtChainID + + // The package indicates that we should start from a specific chain link + // within the chain. Needed by transfer submission with auto-approval + // enabled, otherwise uuid.Nil. + bypassLink := i.startAtLinkID for { if err := ctx.Err(); err != nil { @@ -109,7 +117,12 @@ func (i *iterator) Process(ctx context.Context) (err error) { } else { i.chain.pCtx = pCtx } - next = ch.LinkID + if bypassLink != uuid.Nil { + next = bypassLink // Bypass in place. + bypassLink = uuid.Nil // Do this only once. + } else { + next = ch.LinkID + } continue } diff --git a/hack/ccp/internal/controller/package.go b/hack/ccp/internal/controller/package.go index 51acf0bb2..28a16bc40 100644 --- a/hack/ccp/internal/controller/package.go +++ b/hack/ccp/internal/controller/package.go @@ -44,7 +44,10 @@ type Package struct { path string // Identifier of the chain where the iterator must start processing. - startAt uuid.UUID + startAtChainID uuid.UUID + + // Identifier of the link where the iterator must start processing. + startAtLinkID uuid.UUID // User decisinon manager decision decision @@ -68,7 +71,7 @@ func NewPackage(ctx context.Context, logger logr.Logger, store store.Store, shar pkg := newPackage(logger, store, sharedDir) pkg.path = path - pkg.startAt = wd.ChainID + pkg.startAtChainID = wd.ChainID switch { case wd.UnitType == "Transfer": @@ -130,7 +133,10 @@ func NewTransferPackage( pkg := newPackage(logger, store, sharedDir) pkg.id = uuid.New() pkg.unit = &Transfer{pkg: pkg} - pkg.startAt = Transfers.WithType(req.Type).Chain + + transferType := Transfers.WithType(req.Type) + pkg.startAtChainID = transferType.BypassChainID + pkg.startAtLinkID = transferType.BypassLinkID var msID uuid.UUID if req.MetadataSetId != nil { diff --git a/hack/ccp/internal/controller/transfer.go b/hack/ccp/internal/controller/transfer.go index 9edb13e52..3eb866d56 100644 --- a/hack/ccp/internal/controller/transfer.go +++ b/hack/ccp/internal/controller/transfer.go @@ -4,34 +4,32 @@ import ( "github.com/google/uuid" adminv1 "github.com/artefactual/archivematica/hack/ccp/internal/api/gen/archivematica/ccp/admin/v1beta1" - "github.com/artefactual/archivematica/hack/ccp/internal/workflow" ) +// TransferType represents a known type of transfer in Archivematica. type TransferType struct { - // Name of the transfer type. + // Name of the transfer type, e.g. "standard", "zipfile", etc... Name string - // Type in the transfer type enum. + // Type enum value as described by the adminv1 proto. Type adminv1.TransferType // WatcheDir is the watched directory used to trigger this type of transfer. WatchedDir string - // Chain is the chain used to start processing if approval is omitted. - Chain uuid.UUID + // BypassChainID is the chain bypass used to start a new transfer of this + // type with auto-approval. + BypassChainID uuid.UUID - // Link is the link used to start processing if approval is omitted. - Link uuid.UUID + // BypassLinkID is the specific chain link within the bypass chain where + // we want to start processing when using auto-approval. + BypassLinkID uuid.UUID - // DecisionLink is the chain link used to require user approval. + // DecisionLink is the chain link used to prompt the user for approval. + // Decision is the chain that we have to choose to accept the transfer. + // TODO: remove these two once we implement the Decision API. DecisionLink uuid.UUID - - // Decision is the approved chain. - Decision uuid.UUID -} - -func (t TransferType) WatchedDirDoc(wf *workflow.Document) *workflow.WatchedDirectory { - return nil + Decision uuid.UUID } type TransferTypes []TransferType @@ -69,61 +67,61 @@ func (t TransferTypes) WithType(tt adminv1.TransferType) *TransferType { // List of transfer types supported by Archivematica. var Transfers TransferTypes = []TransferType{ { - Name: "standard", - Type: adminv1.TransferType_TRANSFER_TYPE_STANDARD, - WatchedDir: "activeTransfers/standardTransfer", - Chain: uuid.MustParse("6953950b-c101-4f4c-a0c3-0cd0684afe5e"), - Link: uuid.MustParse("045c43ae-d6cf-44f7-97d6-c8a602748565"), - DecisionLink: uuid.MustParse("0c94e6b5-4714-4bec-82c8-e187e0c04d77"), - Decision: uuid.MustParse("b4567e89-9fea-4256-99f5-a88987026488"), + Name: "standard", + Type: adminv1.TransferType_TRANSFER_TYPE_STANDARD, + WatchedDir: "activeTransfers/standardTransfer", + BypassChainID: uuid.MustParse("6953950b-c101-4f4c-a0c3-0cd0684afe5e"), + BypassLinkID: uuid.MustParse("045c43ae-d6cf-44f7-97d6-c8a602748565"), + DecisionLink: uuid.MustParse("0c94e6b5-4714-4bec-82c8-e187e0c04d77"), + Decision: uuid.MustParse("b4567e89-9fea-4256-99f5-a88987026488"), }, { - Name: "zipfile", - Type: adminv1.TransferType_TRANSFER_TYPE_ZIP_FILE, - WatchedDir: "activeTransfers/zippedDirectory", - Chain: uuid.MustParse("f3caceff-5ad5-4bad-b98c-e73f8cd03450"), - Link: uuid.MustParse("541f5994-73b0-45bb-9cb5-367c06a21be7"), + Name: "zipfile", + Type: adminv1.TransferType_TRANSFER_TYPE_ZIP_FILE, + WatchedDir: "activeTransfers/zippedDirectory", + BypassChainID: uuid.MustParse("f3caceff-5ad5-4bad-b98c-e73f8cd03450"), + BypassLinkID: uuid.MustParse("541f5994-73b0-45bb-9cb5-367c06a21be7"), }, { - Name: "unzipped bag", - Type: adminv1.TransferType_TRANSFER_TYPE_UNZIPPED_BAG, - WatchedDir: "activeTransfers/baggitDirectory", - Chain: uuid.MustParse("c75ef451-2040-4511-95ac-3baa0f019b48"), - Link: uuid.MustParse("154dd501-a344-45a9-97e3-b30093da35f5"), + Name: "unzipped bag", + Type: adminv1.TransferType_TRANSFER_TYPE_UNZIPPED_BAG, + WatchedDir: "activeTransfers/baggitDirectory", + BypassChainID: uuid.MustParse("c75ef451-2040-4511-95ac-3baa0f019b48"), + BypassLinkID: uuid.MustParse("154dd501-a344-45a9-97e3-b30093da35f5"), }, { - Name: "zipped bag", - Type: adminv1.TransferType_TRANSFER_TYPE_ZIPPED_BAG, - WatchedDir: "activeTransfers/baggitZippedDirectory", - Chain: uuid.MustParse("167dc382-4ab1-4051-8e22-e7f1c1bf3e6f"), - Link: uuid.MustParse("3229e01f-adf3-4294-85f7-4acb01b3fbcf"), + Name: "zipped bag", + Type: adminv1.TransferType_TRANSFER_TYPE_ZIPPED_BAG, + WatchedDir: "activeTransfers/baggitZippedDirectory", + BypassChainID: uuid.MustParse("167dc382-4ab1-4051-8e22-e7f1c1bf3e6f"), + BypassLinkID: uuid.MustParse("3229e01f-adf3-4294-85f7-4acb01b3fbcf"), }, { - Name: "dspace", - Type: adminv1.TransferType_TRANSFER_TYPE_DSPACE, - WatchedDir: "activeTransfers/Dspace", - Chain: uuid.MustParse("1cb2ef0e-afe8-45b5-8d8f-a1e120f06605"), - Link: uuid.MustParse("bda96b35-48c7-44fc-9c9e-d7c5a05016c1"), + Name: "dspace", + Type: adminv1.TransferType_TRANSFER_TYPE_DSPACE, + WatchedDir: "activeTransfers/Dspace", + BypassChainID: uuid.MustParse("1cb2ef0e-afe8-45b5-8d8f-a1e120f06605"), + BypassLinkID: uuid.MustParse("bda96b35-48c7-44fc-9c9e-d7c5a05016c1"), }, { - Name: "maildir", - Type: adminv1.TransferType_TRANSFER_TYPE_MAILDIR, - WatchedDir: "activeTransfers/maildir", - Chain: uuid.MustParse("d381cf76-9313-415f-98a1-55c91e4d78e0"), - Link: uuid.MustParse("da2d650e-8ce3-4b9a-ac97-8ca4744b019f"), + Name: "maildir", + Type: adminv1.TransferType_TRANSFER_TYPE_MAILDIR, + WatchedDir: "activeTransfers/maildir", + BypassChainID: uuid.MustParse("d381cf76-9313-415f-98a1-55c91e4d78e0"), + BypassLinkID: uuid.MustParse("da2d650e-8ce3-4b9a-ac97-8ca4744b019f"), }, { - Name: "TRIM", - Type: adminv1.TransferType_TRANSFER_TYPE_TRIM, - WatchedDir: "activeTransfers/TRIM", - Chain: uuid.MustParse("e4a59e3e-3dba-4eb5-9cf1-c1fb3ae61fa9"), - Link: uuid.MustParse("2483c25a-ade8-4566-a259-c6c37350d0d6"), + Name: "TRIM", + Type: adminv1.TransferType_TRANSFER_TYPE_TRIM, + WatchedDir: "activeTransfers/TRIM", + BypassChainID: uuid.MustParse("e4a59e3e-3dba-4eb5-9cf1-c1fb3ae61fa9"), + BypassLinkID: uuid.MustParse("2483c25a-ade8-4566-a259-c6c37350d0d6"), }, { - Name: "dataverse", - Type: adminv1.TransferType_TRANSFER_TYPE_DATAVERSE, - WatchedDir: "activeTransfers/dataverseTransfer", - Chain: uuid.MustParse("10c00bc8-8fc2-419f-b593-cf5518695186"), - Link: uuid.MustParse("0af6b163-5455-4a76-978b-e35cc9ee445f"), + Name: "dataverse", + Type: adminv1.TransferType_TRANSFER_TYPE_DATAVERSE, + WatchedDir: "activeTransfers/dataverseTransfer", + BypassChainID: uuid.MustParse("10c00bc8-8fc2-419f-b593-cf5518695186"), + BypassLinkID: uuid.MustParse("0af6b163-5455-4a76-978b-e35cc9ee445f"), }, }