Skip to content

Commit 7f873b5

Browse files
authored
fix: return ack from control plane (#1098)
# Description Currently the control plane turns an ack with success=false coming from slim nodes into errors, it should return the acks instead. Related issue: #1093 ## Type of Change - [x] Bugfix - [ ] New Feature - [ ] Breaking Change - [ ] Refactor - [ ] Documentation - [ ] Other (please describe) ## Checklist - [x] I have read the [contributing guidelines](/agntcy/repo-template/blob/main/CONTRIBUTING.md) - [x] Existing issues have been referenced (where applicable) - [x] I have verified this change is not present in other open pull requests - [x] Functionality is documented - [x] All code style checks pass - [x] New code contribution is covered by automated tests - [ ] All new and existing tests pass Signed-off-by: Dominik Kolonits <dkolonit@cisco.com>
1 parent 07c7113 commit 7f873b5

File tree

7 files changed

+186
-72
lines changed

7 files changed

+186
-72
lines changed

control-plane/control-plane/internal/services/groupservice/groupservice.go

Lines changed: 39 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -136,12 +136,15 @@ func (s *GroupService) CreateChannel(
136136
return nil, err
137137
}
138138
// check if ack is successful
139-
if ack := response.GetAck(); ack != nil {
140-
if !ack.Success {
141-
return nil, fmt.Errorf("failed to create channel: %s", ack.Messages)
142-
}
143-
logAckMessage(ctx, ack)
144-
zlog.Debug().Msgf("Channel created successfully: %s", channelName)
139+
ack := response.GetAck()
140+
if ack == nil {
141+
zlog.Debug().Msg("failed to create channel: ack is nil")
142+
return nil, fmt.Errorf("failed to create channel")
143+
}
144+
logAckMessage(ctx, ack)
145+
zlog.Debug().Msgf("Channel creation result for %s: success=%t", channelName, ack.Success)
146+
if !ack.Success {
147+
return nil, fmt.Errorf("failed to create channel: %s", ack.Messages)
145148
}
146149

147150
// Saving channel to DB
@@ -207,12 +210,15 @@ func (s *GroupService) DeleteChannel(
207210
return nil, err
208211
}
209212
// check if ack is successful
210-
if ack := response.GetAck(); ack != nil {
211-
if !ack.Success {
212-
return nil, fmt.Errorf("failed to delete participant: %s", ack.Messages)
213-
}
214-
logAckMessage(ctx, ack)
215-
zlog.Debug().Msg("Ack message received, channel deleted successfully.")
213+
ack := response.GetAck()
214+
if ack == nil {
215+
zlog.Debug().Msg("failed to delete channel: ack is nil")
216+
return nil, fmt.Errorf("failed to delete channel")
217+
}
218+
logAckMessage(ctx, ack)
219+
zlog.Debug().Msgf("Channel deletion result for %s: success=%t", deleteChannelRequest.ChannelName, ack.Success)
220+
if !ack.Success {
221+
return ack, nil
216222
}
217223

218224
err = s.dbService.DeleteChannel(deleteChannelRequest.ChannelName)
@@ -221,9 +227,7 @@ func (s *GroupService) DeleteChannel(
221227
}
222228
zlog.Debug().Msg("Channel deleted successfully.")
223229

224-
return &controllerapi.Ack{
225-
Success: true,
226-
}, nil
230+
return ack, nil
227231
}
228232

229233
func (s *GroupService) AddParticipant(
@@ -282,12 +286,15 @@ func (s *GroupService) AddParticipant(
282286
return nil, err
283287
}
284288
// check if ack is successful
285-
if ack := response.GetAck(); ack != nil {
286-
if !ack.Success {
287-
return nil, fmt.Errorf("failed to add participant: %s", ack.Messages)
288-
}
289-
logAckMessage(ctx, ack)
290-
zlog.Debug().Msg("Ack message received, participant added successfully.")
289+
ack := response.GetAck()
290+
if ack == nil {
291+
zlog.Debug().Msg("failed to add participant: ack is nil")
292+
return nil, fmt.Errorf("failed to add participant")
293+
}
294+
logAckMessage(ctx, ack)
295+
zlog.Debug().Msgf("AddParticipant result success=%t", ack.Success)
296+
if !ack.Success {
297+
return ack, nil
291298
}
292299

293300
if slices.Contains(channel.Participants, addParticipantRequest.ParticipantName) {
@@ -302,9 +309,7 @@ func (s *GroupService) AddParticipant(
302309
}
303310
zlog.Debug().Msg("Channel updated, participant added successfully.")
304311

305-
return &controllerapi.Ack{
306-
Success: true,
307-
}, nil
312+
return ack, nil
308313
}
309314

310315
func (s *GroupService) DeleteParticipant(
@@ -369,14 +374,16 @@ func (s *GroupService) DeleteParticipant(
369374
return nil, err
370375
}
371376
// check if ack is successful
372-
if ack := response.GetAck(); ack != nil {
373-
if !ack.Success {
374-
return nil, fmt.Errorf("failed to delete participant: %s", ack.Messages)
375-
}
376-
logAckMessage(ctx, ack)
377-
zlog.Debug().Msg("Ack message received, participant deleted successfully.")
377+
ack := response.GetAck()
378+
if ack == nil {
379+
zlog.Debug().Msg("failed to delete participant: ack is nil")
380+
return nil, fmt.Errorf("failed to delete participant")
381+
}
382+
logAckMessage(ctx, ack)
383+
zlog.Debug().Msgf("DeleteParticipant result success=%t", ack.Success)
384+
if !ack.Success {
385+
return ack, nil
378386
}
379-
380387
// Control plane side DB operations
381388
channel.Participants = append(channel.Participants[:foundIdx], channel.Participants[foundIdx+1:]...)
382389

@@ -386,9 +393,7 @@ func (s *GroupService) DeleteParticipant(
386393
}
387394
zlog.Debug().Msg("Channel updated, participant deleted successfully.")
388395

389-
return &controllerapi.Ack{
390-
Success: true,
391-
}, nil
396+
return ack, nil
392397
}
393398

394399
func (s *GroupService) ListChannels(

0 commit comments

Comments
 (0)