major changes
This commit is contained in:
@@ -107,19 +107,27 @@ func (s *ControlServer[V]) AnnounceOwnership(ctx context.Context, req *messages.
|
||||
}, nil
|
||||
}
|
||||
|
||||
func toAny[V any](grain V) (*anypb.Any, error) {
|
||||
data, err := json.Marshal(grain)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &anypb.Any{
|
||||
Value: data,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (s *ControlServer[V]) Get(ctx context.Context, req *messages.GetRequest) (*messages.GetReply, error) {
|
||||
grain, err := s.pool.Get(ctx, req.Id)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
data, err := json.Marshal(grain)
|
||||
grainAny, err := toAny(grain)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &messages.GetReply{
|
||||
Grain: &anypb.Any{
|
||||
Value: data,
|
||||
},
|
||||
Grain: grainAny,
|
||||
}, nil
|
||||
}
|
||||
|
||||
@@ -163,16 +171,40 @@ func (s *ControlServer[V]) Apply(ctx context.Context, in *messages.ApplyRequest)
|
||||
for i, anyMsg := range in.Messages {
|
||||
msg, err := anyMsg.UnmarshalNew()
|
||||
if err != nil {
|
||||
return &messages.ApplyResult{Accepted: false}, fmt.Errorf("failed to unmarshal message: %w", err)
|
||||
return nil, fmt.Errorf("failed to unmarshal message: %w", err)
|
||||
}
|
||||
msgs[i] = msg
|
||||
}
|
||||
_, err := s.pool.Apply(ctx, in.Id, msgs...)
|
||||
r, err := s.pool.Apply(ctx, in.Id, msgs...)
|
||||
if err != nil {
|
||||
return &messages.ApplyResult{Accepted: false}, err
|
||||
return nil, err
|
||||
}
|
||||
grainAny, err := toAny(r)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
mutList := make([]*messages.MutationResult, len(in.Messages))
|
||||
for i, msg := range r.Mutations {
|
||||
mut, err := anypb.New(msg.Mutation)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var errString *string
|
||||
if msg.Error != nil {
|
||||
s := msg.Error.Error()
|
||||
errString = &s
|
||||
}
|
||||
mutList[i] = &messages.MutationResult{
|
||||
Type: msg.Type,
|
||||
Message: mut,
|
||||
Error: errString,
|
||||
}
|
||||
}
|
||||
|
||||
return &messages.ApplyResult{Accepted: true}, nil
|
||||
return &messages.ApplyResult{
|
||||
State: grainAny,
|
||||
Mutations: mutList,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// ControlPlane: Negotiate (merge host views)
|
||||
|
||||
Reference in New Issue
Block a user