Browse Source

取消agent的event机制,改为对外提供API

gitlink
Sydonian 2 years ago
parent
commit
688e77e76c
6 changed files with 7 additions and 65 deletions
  1. +0
    -36
      internal/cmdline/agent.go
  2. +0
    -22
      internal/services/agent.go
  3. +1
    -1
      internal/services/object.go
  4. +3
    -3
      internal/services/service.go
  5. +1
    -1
      internal/services/storage.go
  6. +2
    -2
      main.go

+ 0
- 36
internal/cmdline/agent.go View File

@@ -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")
}

+ 0
- 22
internal/services/agent.go View File

@@ -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
}

+ 1
- 1
internal/services/object.go View File

@@ -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)
}


+ 3
- 3
internal/services/service.go View File

@@ -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,


+ 1
- 1
internal/services/storage.go View File

@@ -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)
}


+ 2
- 2
main.go View File

@@ -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)


Loading…
Cancel
Save