| @@ -1,36 +0,0 @@ | |||||
| package cmdline | |||||
| import ( | |||||
| "fmt" | |||||
| "gitlink.org.cn/cloudream/common/pkg/cmdtrie" | |||||
| myreflect "gitlink.org.cn/cloudream/common/utils/reflect" | |||||
| agtevt "gitlink.org.cn/cloudream/rabbitmq/message/agent/event" | |||||
| ) | |||||
| var parseAgentEventCmdTrie cmdtrie.StaticCommandTrie[any] = cmdtrie.NewStaticCommandTrie[any]() | |||||
| func AgentPostEvent(ctx CommandContext, nodeID int, args []string) error { | |||||
| ret, err := parseAgentEventCmdTrie.Execute(args, cmdtrie.ExecuteOption{ReplaceEmptyArrayWithNil: true}) | |||||
| if err != nil { | |||||
| return fmt.Errorf("execute parsing event command failed, err: %w", err) | |||||
| } | |||||
| // TODO 支持设置标志 | |||||
| err = ctx.Cmdline.Svc.AgentSvc().PostEvent(nodeID, ret, false, false) | |||||
| if err != nil { | |||||
| return fmt.Errorf("post event to agent failed, err: %w", err) | |||||
| } | |||||
| return nil | |||||
| } | |||||
| func init() { | |||||
| parseAgentEventCmdTrie.MustAdd(agtevt.NewCheckCache, myreflect.TypeNameOf[agtevt.CheckCache]()) | |||||
| parseAgentEventCmdTrie.MustAdd(agtevt.NewCheckState, myreflect.TypeNameOf[agtevt.CheckState]()) | |||||
| parseAgentEventCmdTrie.MustAdd(agtevt.NewCheckStorage, myreflect.TypeNameOf[agtevt.CheckStorage]()) | |||||
| commands.MustAdd(AgentPostEvent, "agent", "event") | |||||
| } | |||||
| @@ -1,12 +1,5 @@ | |||||
| package services | package services | ||||
| import ( | |||||
| "fmt" | |||||
| "gitlink.org.cn/cloudream/client/internal/config" | |||||
| agtcli "gitlink.org.cn/cloudream/rabbitmq/client/agent" | |||||
| ) | |||||
| type AgentService struct { | type AgentService struct { | ||||
| *Service | *Service | ||||
| } | } | ||||
| @@ -14,18 +7,3 @@ type AgentService struct { | |||||
| func (svc *Service) AgentSvc() *AgentService { | func (svc *Service) AgentSvc() *AgentService { | ||||
| return &AgentService{Service: svc} | return &AgentService{Service: svc} | ||||
| } | } | ||||
| func (svc *AgentService) PostEvent(nodeID int, event any, isEmergency bool, dontMerge bool) error { | |||||
| agentClient, err := agtcli.NewAgentClient(nodeID, &config.Cfg().RabbitMQ) | |||||
| if err != nil { | |||||
| return fmt.Errorf("create agent client to %d failed, err: %w", nodeID, err) | |||||
| } | |||||
| defer agentClient.Close() | |||||
| err = agentClient.PostEvent(event, isEmergency, dontMerge) | |||||
| if err != nil { | |||||
| return fmt.Errorf("request to agent %d failed, err: %w", nodeID, err) | |||||
| } | |||||
| return nil | |||||
| } | |||||
| @@ -253,7 +253,7 @@ func (svc *ObjectService) uploadToLocalIPFS(file io.ReadCloser, nodeID int) (str | |||||
| } | } | ||||
| // 然后让最近节点pin本地上传的文件 | // 然后让最近节点pin本地上传的文件 | ||||
| agentClient, err := agtcli.NewAgentClient(nodeID, &config.Cfg().RabbitMQ) | |||||
| agentClient, err := agtcli.NewClient(nodeID, &config.Cfg().RabbitMQ) | |||||
| if err != nil { | if err != nil { | ||||
| return "", fmt.Errorf("create agent client to %d failed, err: %w", nodeID, err) | return "", fmt.Errorf("create agent client to %d failed, err: %w", nodeID, err) | ||||
| } | } | ||||
| @@ -7,12 +7,12 @@ import ( | |||||
| ) | ) | ||||
| type Service struct { | type Service struct { | ||||
| coordinator *racli.CoordinatorClient | |||||
| coordinator *racli.Client | |||||
| ipfs *ipfs.IPFS | ipfs *ipfs.IPFS | ||||
| scanner *sccli.ScannerClient | |||||
| scanner *sccli.Client | |||||
| } | } | ||||
| func NewService(coorClient *racli.CoordinatorClient, ipfsClient *ipfs.IPFS, scanner *sccli.ScannerClient) (*Service, error) { | |||||
| func NewService(coorClient *racli.Client, ipfsClient *ipfs.IPFS, scanner *sccli.Client) (*Service, error) { | |||||
| return &Service{ | return &Service{ | ||||
| coordinator: coorClient, | coordinator: coorClient, | ||||
| ipfs: ipfsClient, | ipfs: ipfsClient, | ||||
| @@ -28,7 +28,7 @@ func (svc *StorageService) MoveObjectToStorage(userID int, objectID int, storage | |||||
| } | } | ||||
| // 然后向代理端发送移动文件的请求 | // 然后向代理端发送移动文件的请求 | ||||
| agentClient, err := agtcli.NewAgentClient(preMoveResp.Body.NodeID, &config.Cfg().RabbitMQ) | |||||
| agentClient, err := agtcli.NewClient(preMoveResp.Body.NodeID, &config.Cfg().RabbitMQ) | |||||
| if err != nil { | if err != nil { | ||||
| return fmt.Errorf("create agent client to %d failed, err: %w", preMoveResp.Body.NodeID, err) | return fmt.Errorf("create agent client to %d failed, err: %w", preMoveResp.Body.NodeID, err) | ||||
| } | } | ||||
| @@ -28,13 +28,13 @@ func main() { | |||||
| os.Exit(1) | os.Exit(1) | ||||
| } | } | ||||
| coorClient, err := coorcli.NewCoordinatorClient(&config.Cfg().RabbitMQ) | |||||
| coorClient, err := coorcli.NewClient(&config.Cfg().RabbitMQ) | |||||
| if err != nil { | if err != nil { | ||||
| log.Warnf("new coordinator client failed, err: %s", err.Error()) | log.Warnf("new coordinator client failed, err: %s", err.Error()) | ||||
| os.Exit(1) | os.Exit(1) | ||||
| } | } | ||||
| scanner, err := sccli.NewScannerClient(&config.Cfg().RabbitMQ) | |||||
| scanner, err := sccli.NewClient(&config.Cfg().RabbitMQ) | |||||
| if err != nil { | if err != nil { | ||||
| log.Warnf("new scanner client failed, err: %s", err.Error()) | log.Warnf("new scanner client failed, err: %s", err.Error()) | ||||
| os.Exit(1) | os.Exit(1) | ||||