3737 Subscribe (ctx context.Context )
3838 IsConnected () bool
3939 CreateConnection (ctx context.Context , resource * mpi.Resource ) (* mpi.CreateConnectionResponse , error )
40- UpdateAgentConfiguration (ctx context.Context , request * mpi.AgentConfig ) error
40+ UpdateAgentConfig (ctx context.Context , request * mpi.AgentConfig ) ( * config. Config , error )
4141 }
4242
4343 CommandPlugin struct {
@@ -128,8 +128,6 @@ func (cp *CommandPlugin) Process(ctx context.Context, msg *bus.Message) {
128128 cp .processDataPlaneHealth (ctxWithMetadata , msg )
129129 case bus .DataPlaneResponseTopic :
130130 cp .processDataPlaneResponse (ctxWithMetadata , msg )
131- case bus .AgentConfigUpdateTopic :
132- cp .processAgentConfigUpdate (ctxWithMetadata , msg )
133131 default :
134132 slog .DebugContext (ctxWithMetadata , "Command plugin received unknown topic" , "topic" , msg .Topic )
135133 }
@@ -143,7 +141,6 @@ func (cp *CommandPlugin) Subscriptions() []string {
143141 bus .InstanceHealthTopic ,
144142 bus .DataPlaneHealthResponseTopic ,
145143 bus .DataPlaneResponseTopic ,
146- bus .AgentConfigUpdateTopic ,
147144 }
148145}
149146
@@ -185,12 +182,23 @@ func (cp *CommandPlugin) createConnection(ctx context.Context, resource *mpi.Res
185182 Data : createConnectionResponse ,
186183 })
187184
188- // update agent configuration after connection is created, and notify other plugins
189- _ = cp .commandService .UpdateAgentConfiguration (ctx , createConnectionResponse .AgentConfig )
190- cp .messagePipe .Process (ctx , & bus.Message {
191- Topic : bus .AgentConfigUpdateTopic ,
192- Data : createConnectionResponse .AgentConfig ,
193- })
185+ if createConnectionResponse .GetAgentConfig () != nil {
186+ newAgentConfig , updateConfigError := cp .commandService .UpdateAgentConfig (
187+ ctx ,
188+ createConnectionResponse .GetAgentConfig (),
189+ )
190+ if updateConfigError != nil {
191+ slog .ErrorContext (ctx , "Unable to update agent configuration" , "error" , updateConfigError )
192+ } else {
193+ slog .DebugContext (
194+ ctx , "Notifying other plugins of agent configuration update from create connection response" ,
195+ )
196+ cp .messagePipe .Process (ctx , & bus.Message {
197+ Topic : bus .AgentConfigUpdateTopic ,
198+ Data : newAgentConfig ,
199+ })
200+ }
201+ }
194202 }
195203}
196204
@@ -273,19 +281,6 @@ func (cp *CommandPlugin) processConnectionReset(ctx context.Context, msg *bus.Me
273281 }
274282}
275283
276- func (cp * CommandPlugin ) processAgentConfigUpdate (ctx context.Context , msg * bus.Message ) {
277- slog .DebugContext (ctx , "Command plugin received agent config update message" , "data" , msg .Data )
278- //
279- if mpiConf , ok := msg .Data .(* mpi.AgentConfig ); ok {
280- err := cp .commandService .UpdateAgentConfiguration (ctx , mpiConf )
281- if err != nil {
282- slog .ErrorContext (ctx , "Unable to update agent configuration" , "error" , err )
283- }
284- } else {
285- slog .ErrorContext (ctx , "Invalid data for agent config update message" , "data" , msg .Data )
286- }
287- }
288-
289284//nolint:revive // cognitive complexity is 14
290285func (cp * CommandPlugin ) monitorSubscribeChannel (ctx context.Context ) {
291286 for {
@@ -436,8 +431,47 @@ func (cp *CommandPlugin) handleInvalidRequest(ctx context.Context,
436431}
437432
438433func (cp * CommandPlugin ) handleAgentConfigUpdateRequest (ctx context.Context , request * mpi.ManagementPlaneRequest ) {
439- // notify plugins about the agent config update request
440- cp .Process (ctx , & bus.Message {Topic : bus .AgentConfigUpdateTopic , Data : request })
434+ newAgentConfig , err := cp .commandService .UpdateAgentConfig (
435+ ctx ,
436+ request .GetUpdateNginxAgentConfigurationRequest ().GetAgentConfig (),
437+ )
438+ if err != nil {
439+ slog .ErrorContext (ctx , "Command service was unable to update agent configuration" , "error" , err )
440+
441+ responseError := cp .commandService .SendDataPlaneResponse (ctx , & mpi.DataPlaneResponse {
442+ MessageMeta : & mpi.MessageMeta {
443+ MessageId : id .GenerateMessageID (),
444+ CorrelationId : request .GetMessageMeta ().GetCorrelationId (),
445+ Timestamp : timestamppb .Now (),
446+ },
447+ CommandResponse : & mpi.CommandResponse {
448+ Status : mpi .CommandResponse_COMMAND_STATUS_FAILURE ,
449+ Message : "Failed to update agent configuration" ,
450+ },
451+ })
452+
453+ if responseError != nil {
454+ slog .ErrorContext (ctx , "Unable to send data plane response" , "error" , responseError )
455+ }
456+ } else {
457+ cp .Process (ctx , & bus.Message {Topic : bus .AgentConfigUpdateTopic , Data : newAgentConfig })
458+
459+ responseError := cp .commandService .SendDataPlaneResponse (ctx , & mpi.DataPlaneResponse {
460+ MessageMeta : & mpi.MessageMeta {
461+ MessageId : id .GenerateMessageID (),
462+ CorrelationId : request .GetMessageMeta ().GetCorrelationId (),
463+ Timestamp : timestamppb .Now (),
464+ },
465+ CommandResponse : & mpi.CommandResponse {
466+ Status : mpi .CommandResponse_COMMAND_STATUS_OK ,
467+ Message : "Successfully updated agent configuration" ,
468+ },
469+ })
470+
471+ if responseError != nil {
472+ slog .ErrorContext (ctx , "Unable to send data plane response" , "error" , responseError )
473+ }
474+ }
441475}
442476
443477func (cp * CommandPlugin ) createDataPlaneResponse (correlationID string , status mpi.CommandResponse_CommandStatus ,
0 commit comments