Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only unpublish a dataset on the provider. #81

Merged
merged 2 commits into from
Nov 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 13 additions & 6 deletions dsp/statemachine/contract_statemachine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -338,12 +338,6 @@ func TestStateMachineConsumerInitConsumerPull(t *testing.T) {
},
}, nil)

mockProvider.On("UnpublishDataset", mock.Anything, &providerv1.UnpublishDatasetRequest{
PublishId: trProviderPID.String(),
}).Return(&providerv1.UnpublishDatasetResponse{
Success: true,
}, nil)

apply, err = pTransNext.Send(ctx)
assert.Nil(t, err)
apply()
Expand Down Expand Up @@ -395,6 +389,19 @@ func TestStateMachineConsumerInitConsumerPull(t *testing.T) {
assert.Nil(t, err)
assert.Equal(t, trCPID.URN(), trCompletionMSG.ConsumerPID)
assert.Equal(t, trProviderPID.URN(), trCompletionMSG.ProviderPID)

mockProvider.On("UnpublishDataset", mock.Anything, &providerv1.UnpublishDatasetRequest{
PublishId: trProviderPID.String(),
}).Return(&providerv1.UnpublishDatasetResponse{
Success: true,
}, nil)

pTransContractStarted, err := store.GetProviderTransfer(ctx, trProviderPID)
validateTransfer(t, err, pTransContractStarted, statemachine.TransferRequestStates.STARTED, agreementID)

pTransStarted := statemachine.GetTransferRequestNegotiation(store, pTransContractStarted, mockProvider, reconciler)
pTransNext, err = pTransStarted.Recv(ctx, trCompletionMSG)
validateTransfer(t, err, pTransNext.GetTransferRequest(), statemachine.TransferRequestStates.COMPLETED, agreementID)
}

// TestContractStateMachineConsumerInit tests a whole contract statemachine run, this will do the happy path,
Expand Down
33 changes: 23 additions & 10 deletions dsp/statemachine/transfer_request_transitions.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,33 +147,46 @@ func (tr *TransferRequestNegotiationStarted) Recv(
) (TransferRequestNegotiationState, error) {
switch t := message.(type) {
case shared.TransferCompletionMessage:
err := unpublishTransfer(ctx, tr)
if err != nil {
return nil, err
}
return verifyAndTransformTransfer(ctx, tr, t.ProviderPID, t.ConsumerPID, TransferRequestStates.COMPLETED)
case shared.TransferTerminationMessage:
return verifyAndTransformTransfer(ctx, tr, t.ProviderPID, t.ConsumerPID, TransferRequestStates.TRANSFERTERMINATED)

default:
return nil, fmt.Errorf("invalid message type")
}
}

func (tr *TransferRequestNegotiationStarted) Send(ctx context.Context) (func(), error) {
err := unpublishTransfer(ctx, tr)
if err != nil {
return func() {}, err
}
return sendTransferCompletion(ctx, tr)
}

func unpublishTransfer(ctx context.Context, tr TransferRequestNegotiationState) error {
switch tr.GetTransferDirection() {
case DirectionPull:
_, err := tr.GetProvider().UnpublishDataset(ctx, &providerv1.UnpublishDatasetRequest{
PublishId: tr.GetProviderPID().String(),
})
if err != nil {
return func() {}, err
if tr.GetRole() == DataspaceProvider {
_, err := tr.GetProvider().UnpublishDataset(ctx, &providerv1.UnpublishDatasetRequest{
PublishId: tr.GetProviderPID().String(),
})
if err != nil {
return err
}
}
case DirectionPush:
// TODO: Signal provider to start uploading dataset here.
return func() {}, fmt.Errorf("push flow: %w", ErrNotImplemented)

return fmt.Errorf("push flow: %w", ErrNotImplemented)
case DirectionUnknown:
return func() {}, fmt.Errorf("unknown transfer direction")
return fmt.Errorf("unknown transfer direction")
default:
panic("unexpected statemachine.TransferDirection")
}
return sendTransferCompletion(ctx, tr)
return nil
}

type TransferRequestNegotiationSuspended struct {
Expand Down