add function to apply mutations over grpc
All checks were successful
Build and Publish / BuildAndDeployAmd64 (push) Successful in 41s
Build and Publish / BuildAndDeployArm64 (push) Successful in 4m50s

This commit is contained in:
matst80
2025-11-28 14:07:43 +01:00
parent 2c0f6c160a
commit 47e69f18a5
12 changed files with 1015 additions and 74 deletions

View File

@@ -8,6 +8,7 @@ import (
"time"
messages "git.k6n.net/go-cart-actor/pkg/messages"
"github.com/gogo/protobuf/proto"
"go.opentelemetry.io/contrib/bridges/otelslog"
"go.opentelemetry.io/otel"
"go.opentelemetry.io/otel/attribute"
@@ -139,6 +140,69 @@ func (s *ControlServer[V]) Ping(ctx context.Context, _ *messages.Empty) (*messag
}, nil
}
func (s *ControlServer[V]) Apply(ctx context.Context, in *messages.ApplyRequest) (*messages.ApplyResult, error) {
msgs := make([]proto.Message, len(in.Messages))
for i, mut := range in.Messages {
var msg proto.Message
if m := mut.GetClearCart(); m != nil {
msg = m
} else if m := mut.GetAddItem(); m != nil {
msg = m
} else if m := mut.GetRemoveItem(); m != nil {
msg = m
} else if m := mut.GetChangeQuantity(); m != nil {
msg = m
} else if m := mut.GetSetDelivery(); m != nil {
msg = m
} else if m := mut.GetSetPickupPoint(); m != nil {
msg = m
} else if m := mut.GetRemoveDelivery(); m != nil {
msg = m
} else if m := mut.GetSetUserId(); m != nil {
msg = m
} else if m := mut.GetLineItemMarking(); m != nil {
msg = m
} else if m := mut.GetRemoveLineItemMarking(); m != nil {
msg = m
} else if m := mut.GetSubscriptionAdded(); m != nil {
msg = m
} else if m := mut.GetPaymentDeclined(); m != nil {
msg = m
} else if m := mut.GetConfirmationViewed(); m != nil {
msg = m
} else if m := mut.GetCreateCheckoutOrder(); m != nil {
msg = m
} else if m := mut.GetOrderCreated(); m != nil {
msg = m
} else if m := mut.GetNoop(); m != nil {
msg = m
} else if m := mut.GetInitializeCheckout(); m != nil {
msg = m
} else if m := mut.GetInventoryReserved(); m != nil {
msg = m
} else if m := mut.GetAddVoucher(); m != nil {
msg = m
} else if m := mut.GetRemoveVoucher(); m != nil {
msg = m
} else if m := mut.GetUpsertSubscriptionDetails(); m != nil {
msg = m
} else if m := mut.GetPreConditionFailed(); m != nil {
msg = m
} else if m := mut.GetAddGiftcard(); m != nil {
msg = m
} else if m := mut.GetRemoveGiftcard(); m != nil {
msg = m
}
msgs[i] = msg
}
_, err := s.pool.Apply(ctx, in.Id, msgs...)
if err != nil {
return &messages.ApplyResult{Accepted: false}, err
}
return &messages.ApplyResult{Accepted: true}, nil
}
// ControlPlane: Negotiate (merge host views)
func (s *ControlServer[V]) Negotiate(ctx context.Context, req *messages.NegotiateRequest) (*messages.NegotiateReply, error) {
ctx, span := tracer.Start(ctx, "grpc_negotiate")