MCPcopy Create free account
hub / github.com/deepflowio/deepflow / Aplugin

Function Aplugin

cli/ctl/agent_check.go:647–699  ·  view source on GitHub ↗
(cmd *cobra.Command)

Source from the content-addressed store, hash-verified

645}
646
647func Aplugin(cmd *cobra.Command) {
648 conn := agentGetConn(cmd)
649 if conn == nil {
650 return
651 }
652 defer conn.Close()
653 fmt.Printf("request trisolaris(%s), params(%+v)\n", conn.Target(), agentParamData)
654 var pluginType agent.PluginType
655 switch agentParamData.PluginType {
656 case "wasm":
657 pluginType = agent.PluginType_WASM
658 default:
659 fmt.Printf("request pluginType(%s) not supported, pluginType must be in %s\n",
660 agentParamData.PluginType, []string{"wasm"})
661 return
662 }
663 c := agent.NewSynchronizerClient(conn)
664 reqData := &agent.PluginRequest{
665 CtrlIp: &agentParamData.CtrlIP,
666 CtrlMac: &agentParamData.CtrlMac,
667 TeamId: &agentParamData.TeamID,
668 PluginType: &pluginType,
669 PluginName: &agentParamData.PluginName,
670 }
671 stream, err := c.Plugin(context.Background(), reqData)
672 if err != nil {
673 fmt.Println(err)
674 return
675 }
676 var (
677 data []byte
678 md5 string
679 )
680 for {
681 if res, err := stream.Recv(); err == nil {
682 data = append(data, res.GetContent()...)
683 md5 = res.GetMd5()
684 } else {
685 if errors.Is(err, io.EOF) {
686 break
687 }
688 fmt.Println(res, err)
689 return
690 }
691 }
692 fileName := agentParamData.PluginType + "-" + agentParamData.PluginName
693 err = os.WriteFile(fileName, data, 0666)
694 if err != nil {
695 fmt.Printf("save plugin(%s) fail %s\n", fileName, err)
696 return
697 }
698 fmt.Printf("save plugin(%s) success, md5=%s\n", fileName, md5)
699}

Callers 1

agentRegiterCommandFunction · 0.85

Calls 5

agentGetConnFunction · 0.85
GetContentMethod · 0.80
CloseMethod · 0.65
RecvMethod · 0.65
PluginMethod · 0.45

Tested by

no test coverage detected