pcm-openstack/internal/pkg/cron/taskcron.go

98 lines
2.5 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package cron
import (
"context"
"github.com/zeromicro/go-zero/core/logx"
"gitlink.org.cn/jcce-pcm/pcm-coordinator/rpc/client/pcmcore"
"gitlink.org.cn/jcce-pcm/pcm-coordinator/rpc/pcmCore"
"gitlink.org.cn/jcce-pcm/pcm-participant-openstack/internal/svc"
"gitlink.org.cn/jcce-pcm/utils/tool"
)
func SyncTask(svc *svc.ServiceContext) {
var vmList []*pcmcore.VmInfo
participantId, err := tool.GetParticipantId("etc/pcmopenstack.yaml")
if err != nil {
logx.Errorf("获取participant id失败 err:", err)
return
}
// 查询core端分发下来的任务列表
infoReq := pcmCore.InfoListReq{
ParticipantId: participantId,
}
infoList, err := svc.PcmCoreRpc.InfoList(context.Background(), &infoReq)
if err != nil {
logx.Error(err)
return
}
if infoList != nil && len(infoList.VmInfoList) != 0 {
tool.Convert(&infoList.VmInfoList, &vmList)
if err != nil {
logx.Error(err)
return
}
// 遍历执行任务操作
for index, _ := range infoList.VmInfoList {
// 删除任务
if infoList.VmInfoList[index].State == "WaitDelete" {
delete(infoList.VmInfoList[index], svc)
}
// 执行任务
if infoList.CloudInfoList[index].Status == "Saved" {
insert(infoList.VmInfoList[index], svc)
}
}
// 遍历查询任务信息
for index, _ := range infoList.VmInfoList {
if infoList.VmInfoList[index].State == "Deployment" {
//DeploymentHandler(infoList.CloudInfoList[index], svc)
}
}
// 同步信息到core端
SyncInfoReq := pcmCore.SyncInfoReq{
ParticipantId: participantId,
VmInfoList: make([]*pcmCore.VmInfo, 0),
}
if len(SyncInfoReq.VmInfoList) != 0 {
resp, err := svc.PcmCoreRpc.SyncInfo(context.Background(), &SyncInfoReq)
if err != nil {
logx.Error(resp.Msg)
return
}
}
}
}
// 删除资源
func delete(cloud *pcmCore.VmInfo, svc *svc.ServiceContext) {
//deleteYamlLogic := logic.NewDeleteYamlLogic(context.Background(), svc)
/* deleteReq := kubernetesclient.ApplyReq{
YamlString: cloud.YamlString,
}
_, err := deleteYamlLogic.DeleteYaml(&deleteReq)
if err != nil {
cloud.Status = "DeleteError"
cloud.Result = err.Error()
return
}
cloud.Status = "Deleted"*/
}
// 执行资源
func insert(cloud *pcmCore.VmInfo, svc *svc.ServiceContext) {
//applyYamlLogic := logic.NewApplyYamlLogic(context.Background(), svc)
// 提交任务
/* applyReq := kubernetesclient.ApplyReq{
YamlString: cloud.YamlString,
}
cloud.Status = "Running"
_, err := applyYamlLogic.ApplyYaml(&applyReq)
if err != nil {
cloud.Status = "Failed"
cloud.Result = err.Error()
}*/
}