diff --git a/etc/pcmopenstack.yaml b/etc/pcmopenstack.yaml index 8f52732..92754ad 100644 --- a/etc/pcmopenstack.yaml +++ b/etc/pcmopenstack.yaml @@ -1,6 +1,7 @@ Name: pcm.openstack.rpc ListenOn: 0.0.0.0:2010 AdapterId: 1706858330967773113 +CoreUrl: "http://127.0.0.1:8999" Timeout: 100000 # 100s,设置rpc服务的响应的超时时间,若超过10s还未返回则结束请求 @@ -13,8 +14,11 @@ Participant: TenantName: "host" #租户名 CoreClientConf: - Url: "localhost:8999" - DataSource: "" + #Url: "localhost:8999" + #DataSource: "" + AdapterId: 1706858330967773113 + CoreUrl: "http://127.0.0.1:8999" + openstackConfig: diff --git a/internal/common/server.go b/internal/common/server.go index ad2df3a..9714f79 100644 --- a/internal/common/server.go +++ b/internal/common/server.go @@ -41,9 +41,9 @@ type GetServersDetailedByIdReq struct { } type GetServersDetailedByIdResp struct { - Code int64 `json:"code"` - Msg string `json:"msg"` - Data string `json:"data"` + Code int64 `json:"code"` + Msg string `json:"msg"` + // Data string `json:"data"` Server ServerDetailed `json:"server,omitempty"` } diff --git a/internal/config/config.go b/internal/config/config.go index ca239db..1805882 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -11,14 +11,16 @@ const ( ) type Config struct { - AdapterId int `yaml:"AdapterId"` + //AdapterId int `yaml:"AdapterId"` zrpc.RpcServerConf OpenstackConfig OpenstackConfig - CoreClientConf CoreClientConf `yaml:"CoreClientConf"` + CoreClientConf CoreClientConf LogConf logx.LogConf PcmCoreRpcConf zrpc.RpcClientConf - ParticipantId int64 + AdapterId int64 Participant Participant + CoreUrl string + ParticipantId int64 } type Participant struct { @@ -30,6 +32,8 @@ type Participant struct { } type CoreClientConf struct { - Url string `yaml:"Url"` - DataSource string `yaml:"DataSource"` + /* Url string `yaml:"Url"` + DataSource string `yaml:"DataSource"`*/ + AdapterId int64 `json:"AdapterId"` + CoreUrl string `json:"CoreUrl"` } diff --git a/internal/pkg/cron/cron.go b/internal/pkg/cron/cron.go index 028537e..d5eb2f1 100644 --- a/internal/pkg/cron/cron.go +++ b/internal/pkg/cron/cron.go @@ -5,7 +5,7 @@ import "gitlink.org.cn/JointCloud/pcm-openstack/internal/svc" func AddCronGroup(svc *svc.ServiceContext) { // 同步任务信息到core端 svc.Cron.AddFunc("*/5 * * * * ?", func() { - PullTaskInfo() + PullTaskInfo(svc) }) } diff --git a/internal/pkg/cron/taskcron.go b/internal/pkg/cron/taskcron.go index 08da9fc..5bf3801 100644 --- a/internal/pkg/cron/taskcron.go +++ b/internal/pkg/cron/taskcron.go @@ -9,6 +9,7 @@ import ( "gitlink.org.cn/JointCloud/pcm-coordinator/pkg/utils/httputils" "gitlink.org.cn/JointCloud/pcm-openstack/internal/common" "gitlink.org.cn/JointCloud/pcm-openstack/internal/config" + "gitlink.org.cn/JointCloud/pcm-openstack/internal/svc" "k8s.io/apimachinery/pkg/util/json" "log" "net/http" @@ -20,8 +21,11 @@ var AdapterId int64 var CoreUrl string var C config.Config -func PullTaskInfo() { - +func PullTaskInfo(svc *svc.ServiceContext) { + AdapterId := svc.Config.AdapterId + CoreUrl := svc.Config.CoreUrl + fmt.Println("AdapterId:", AdapterId) + fmt.Println("CoreUrl:", CoreUrl) httpClient := resty.New().R() result, _ := httpClient.SetHeader("Content-Type", "application/json"). SetQueryParam("adapterId", strconv.FormatInt(1706858330967773113, 10)). @@ -53,8 +57,18 @@ func PullTaskInfo() { vmInfo.ServerId = respServer.Server.Id oldVmInfoList = append(oldVmInfoList, *vmInfo) vmInfo.Status = "Running" - } else { //if state is not "Saved" ,then get state from participant and sync to core - + } else if vmInfo.Status == "Running" || vmInfo.Status == "BUILD" { //if state is not "Running" ,then get state from participant and sync to core + GetServersDetailedByIdReq := common.GetServersDetailedByIdReq{} + GetServersDetailedByIdReq.ServerId = vmInfo.ServerId + GetServersDetailedByIdReq.Platform = vmInfo.Platform + GetServersDetailedByIdResp, err := GetServerDetail(GetServersDetailedByIdReq) + if err != nil { + log.Print(err) + continue + } + vmInfo.Status = GetServersDetailedByIdResp.Server.Status + } else { + return } } @@ -69,7 +83,6 @@ func PullTaskInfo() { if len(PushReq.VmInfoList) != 0 { url := "http://127.0.0.1:8999" + "/pcm/v1/core/pushTaskInfo" method := "POST" - jsonStr, _ := json.Marshal(PushReq) payload := bytes.NewBuffer(jsonStr) client := &http.Client{}