diff --git a/internal/cmdline/agent.go b/internal/cmdline/agent.go deleted file mode 100644 index 8cd6eb2..0000000 --- a/internal/cmdline/agent.go +++ /dev/null @@ -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") -} diff --git a/internal/services/agent.go b/internal/services/agent.go index b15233e..1c7b4b4 100644 --- a/internal/services/agent.go +++ b/internal/services/agent.go @@ -1,12 +1,5 @@ package services -import ( - "fmt" - - "gitlink.org.cn/cloudream/client/internal/config" - agtcli "gitlink.org.cn/cloudream/rabbitmq/client/agent" -) - type AgentService struct { *Service } @@ -14,18 +7,3 @@ type AgentService struct { func (svc *Service) AgentSvc() *AgentService { 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 -} diff --git a/internal/services/object.go b/internal/services/object.go index cd85723..b1cc166 100644 --- a/internal/services/object.go +++ b/internal/services/object.go @@ -253,7 +253,7 @@ func (svc *ObjectService) uploadToLocalIPFS(file io.ReadCloser, nodeID int) (str } // 然后让最近节点pin本地上传的文件 - agentClient, err := agtcli.NewAgentClient(nodeID, &config.Cfg().RabbitMQ) + agentClient, err := agtcli.NewClient(nodeID, &config.Cfg().RabbitMQ) if err != nil { return "", fmt.Errorf("create agent client to %d failed, err: %w", nodeID, err) } diff --git a/internal/services/service.go b/internal/services/service.go index 16e7762..2c76a96 100644 --- a/internal/services/service.go +++ b/internal/services/service.go @@ -7,12 +7,12 @@ import ( ) type Service struct { - coordinator *racli.CoordinatorClient + coordinator *racli.Client 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{ coordinator: coorClient, ipfs: ipfsClient, diff --git a/internal/services/storage.go b/internal/services/storage.go index ae85e49..8ccd02e 100644 --- a/internal/services/storage.go +++ b/internal/services/storage.go @@ -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 { return fmt.Errorf("create agent client to %d failed, err: %w", preMoveResp.Body.NodeID, err) } diff --git a/main.go b/main.go index 9f7acf7..08fef0c 100644 --- a/main.go +++ b/main.go @@ -28,13 +28,13 @@ func main() { os.Exit(1) } - coorClient, err := coorcli.NewCoordinatorClient(&config.Cfg().RabbitMQ) + coorClient, err := coorcli.NewClient(&config.Cfg().RabbitMQ) if err != nil { log.Warnf("new coordinator client failed, err: %s", err.Error()) os.Exit(1) } - scanner, err := sccli.NewScannerClient(&config.Cfg().RabbitMQ) + scanner, err := sccli.NewClient(&config.Cfg().RabbitMQ) if err != nil { log.Warnf("new scanner client failed, err: %s", err.Error()) os.Exit(1)