MCPcopy
hub / github.com/netdata/netdata / CmdAdd

Method CmdAdd

src/go/plugin/framework/dyncfg/handler.go:427–470  ·  view source on GitHub ↗

CmdAdd handles the "add" command.

(fn Function)

Source from the content-addressed store, hash-verified

425
426// CmdAdd handles the "add" command.
427func (h *Handler[C]) CmdAdd(fn Function) {
428 if err := fn.ValidateArgs(3); err != nil {
429 h.api.SendCodef(fn, 400, "%v", err)
430 return
431 }
432
433 key, name, ok := h.cb.ExtractKey(fn)
434 if !ok {
435 h.api.SendCodef(fn, 400, "invalid job ID format.")
436 return
437 }
438
439 if err := fn.ValidateHasPayload(); err != nil {
440 h.api.SendCodef(fn, 400, "%v", err)
441 return
442 }
443
444 if err := h.cb.ValidateJobName(name); err != nil {
445 h.api.SendCodef(fn, 400, "invalid job name '%s': %v.", name, err)
446 return
447 }
448
449 newCfg, err := h.cb.ParseAndValidate(fn, name)
450 if err != nil {
451 h.api.SendCodef(fn, 400, "%v", err)
452 return
453 }
454
455 // Replace existing config at the same key, if any.
456 if existing, ok := h.exposed.LookupByKey(key); ok {
457 if _, found := h.seen.Lookup(existing.Cfg); found && existing.Cfg.SourceType() == "dyncfg" {
458 h.seen.Remove(existing.Cfg)
459 }
460 h.exposed.Remove(existing.Cfg)
461 h.cb.Stop(existing.Cfg)
462 }
463
464 h.seen.Add(newCfg)
465 newEntry := &Entry[C]{Cfg: newCfg, Status: StatusAccepted}
466 h.exposed.Add(newEntry)
467
468 h.api.SendCodef(fn, 202, "")
469 h.NotifyJobCreate(newCfg, StatusAccepted)
470}
471
472// CmdEnable handles the "enable" command.
473func (h *Handler[C]) CmdEnable(fn Function) {

Callers 10

TestCmdAdd_SuccessFunction · 0.80
TestCmdAdd_InvalidArgsFunction · 0.80
TestCmdAdd_NoPayloadFunction · 0.80
TestCmdAdd_ParseErrorFunction · 0.80
dyncfgSeqExecMethod · 0.80

Calls 13

NotifyJobCreateMethod · 0.95
ValidateArgsMethod · 0.80
SendCodefMethod · 0.80
ValidateHasPayloadMethod · 0.80
LookupByKeyMethod · 0.80
ExtractKeyMethod · 0.65
ValidateJobNameMethod · 0.65
ParseAndValidateMethod · 0.65
SourceTypeMethod · 0.65
RemoveMethod · 0.65
StopMethod · 0.65
AddMethod · 0.65