Merge pull request '容器接口更新' (#529) from zhangweiii/pcm-coordinator:master into master
This commit is contained in:
commit
dcfcd63f67
|
@ -2,6 +2,7 @@ package cloud
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/logic/cloud"
|
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/logic/cloud"
|
||||||
|
"gitlink.org.cn/JointCloud/pcm-coordinator/pkg/models"
|
||||||
"gitlink.org.cn/JointCloud/pcm-coordinator/pkg/repository/result"
|
"gitlink.org.cn/JointCloud/pcm-coordinator/pkg/repository/result"
|
||||||
"io"
|
"io"
|
||||||
"k8s.io/apimachinery/pkg/util/json"
|
"k8s.io/apimachinery/pkg/util/json"
|
||||||
|
@ -24,7 +25,11 @@ func ContainerCreateHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||||
result.ParamErrorResult(r, w, err)
|
result.ParamErrorResult(r, w, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
// 获取用户信息
|
||||||
|
userStr := r.Header.Get("User")
|
||||||
|
user := &models.JccUserInfo{}
|
||||||
|
json.Unmarshal([]byte(userStr), user)
|
||||||
|
req.UserId = user.Id
|
||||||
l := cloud.NewContainerCreateLogic(r.Context(), svcCtx)
|
l := cloud.NewContainerCreateLogic(r.Context(), svcCtx)
|
||||||
resp, err := l.ContainerCreate(&req)
|
resp, err := l.ContainerCreate(&req)
|
||||||
result.HttpResult(r, w, resp, err)
|
result.HttpResult(r, w, resp, err)
|
||||||
|
|
|
@ -37,11 +37,11 @@ func (l *UpdateClusterLogic) UpdateCluster(req *types.ClusterCreateReq) (resp *t
|
||||||
}
|
}
|
||||||
utils.Convert(req, &cluster)
|
utils.Convert(req, &cluster)
|
||||||
// 获取集群经纬度
|
// 获取集群经纬度
|
||||||
location, err := GeoMap(req.RegionName)
|
//location, err := GeoMap(req.RegionName)
|
||||||
if err != nil {
|
//if err != nil {
|
||||||
return nil, err
|
// return nil, err
|
||||||
}
|
//}
|
||||||
cluster.Location = location
|
//cluster.Location = location
|
||||||
l.svcCtx.DbEngin.Table("t_cluster").Model(&cluster).Updates(&cluster)
|
l.svcCtx.DbEngin.Table("t_cluster").Model(&cluster).Updates(&cluster)
|
||||||
// 更新资源价格表
|
// 更新资源价格表
|
||||||
clusterId, err := strconv.ParseInt(req.Id, 10, 64)
|
clusterId, err := strconv.ParseInt(req.Id, 10, 64)
|
||||||
|
|
|
@ -60,7 +60,7 @@ func (l *CommitGeneralTaskLogic) CommitGeneralTask(req *types.GeneralTaskReq) (r
|
||||||
logx.Info("commit success")
|
logx.Info("commit success")
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
adapterId, _ := strconv.ParseUint(req.AdapterIds[0], 10, 64)
|
adapterId, _ := strconv.ParseInt(req.AdapterIds[0], 10, 64)
|
||||||
var clusters []*models.CloudModel
|
var clusters []*models.CloudModel
|
||||||
err = tx.Raw("SELECT * FROM `t_cluster` where adapter_id in ? and id in ?", req.AdapterIds, req.ClusterIds).Scan(&clusters).Error
|
err = tx.Raw("SELECT * FROM `t_cluster` where adapter_id in ? and id in ?", req.AdapterIds, req.ClusterIds).Scan(&clusters).Error
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -111,11 +111,11 @@ func (l *CommitGeneralTaskLogic) CommitGeneralTask(req *types.GeneralTaskReq) (r
|
||||||
for _, s := range req.ReqBody {
|
for _, s := range req.ReqBody {
|
||||||
sStruct := UnMarshalK8sStruct(s, int64(r.Replica))
|
sStruct := UnMarshalK8sStruct(s, int64(r.Replica))
|
||||||
unString, _ := sStruct.MarshalJSON()
|
unString, _ := sStruct.MarshalJSON()
|
||||||
taskCloud.Id = utils.GenSnowflakeIDUint()
|
taskCloud.Id = utils.GenSnowflakeID()
|
||||||
taskCloud.Name = sStruct.GetName() + "-" + sStruct.GetKind()
|
taskCloud.Name = sStruct.GetName() + "-" + sStruct.GetKind()
|
||||||
taskCloud.TaskId = uint(taskModel.Id)
|
taskCloud.TaskId = taskModel.Id
|
||||||
clusterId, _ := strconv.ParseUint(r.ClusterId, 10, 64)
|
clusterId, _ := strconv.ParseUint(r.ClusterId, 10, 64)
|
||||||
taskCloud.AdapterId = uint(adapterId)
|
taskCloud.AdapterId = adapterId
|
||||||
taskCloud.AdapterName = adapterName
|
taskCloud.AdapterName = adapterName
|
||||||
taskCloud.UserId = req.UserId
|
taskCloud.UserId = req.UserId
|
||||||
taskCloud.ClusterId = uint(clusterId)
|
taskCloud.ClusterId = uint(clusterId)
|
||||||
|
|
|
@ -21,7 +21,12 @@ import (
|
||||||
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/participant/cloud"
|
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/participant/cloud"
|
||||||
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/svc"
|
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/svc"
|
||||||
container "gitlink.org.cn/JointCloud/pcm-coordinator/internal/types/cloud"
|
container "gitlink.org.cn/JointCloud/pcm-coordinator/internal/types/cloud"
|
||||||
|
"gitlink.org.cn/JointCloud/pcm-coordinator/pkg/constants"
|
||||||
|
"gitlink.org.cn/JointCloud/pcm-coordinator/pkg/models"
|
||||||
|
cloud2 "gitlink.org.cn/JointCloud/pcm-coordinator/pkg/models/cloud"
|
||||||
|
"gitlink.org.cn/JointCloud/pcm-coordinator/pkg/utils"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
type ContainerCreateLogic struct {
|
type ContainerCreateLogic struct {
|
||||||
|
@ -39,8 +44,10 @@ func NewContainerCreateLogic(ctx context.Context, svcCtx *svc.ServiceContext) *C
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *ContainerCreateLogic) ContainerCreate(req *container.CreateParam) (resp interface{}, err error) {
|
func (l *ContainerCreateLogic) ContainerCreate(req *container.CreateParam) (resp interface{}, err error) {
|
||||||
|
|
||||||
param := &cloud.CreateParam{
|
param := &cloud.CreateParam{
|
||||||
Name: req.Name,
|
Name: req.Name,
|
||||||
|
Description: req.Description,
|
||||||
Port: req.Port,
|
Port: req.Port,
|
||||||
Cpu: req.Cpu,
|
Cpu: req.Cpu,
|
||||||
Memory: req.Memory,
|
Memory: req.Memory,
|
||||||
|
@ -59,6 +66,38 @@ func (l *ContainerCreateLogic) ContainerCreate(req *container.CreateParam) (resp
|
||||||
if create.Code != http.StatusOK {
|
if create.Code != http.StatusOK {
|
||||||
return nil, errors.New(create.Message)
|
return nil, errors.New(create.Message)
|
||||||
}
|
}
|
||||||
resp = create.Data
|
// 构建主任务结构体
|
||||||
|
taskModel := models.Task{
|
||||||
|
Id: utils.GenSnowflakeID(),
|
||||||
|
Status: constants.Saved,
|
||||||
|
Description: req.Description,
|
||||||
|
Name: req.Name,
|
||||||
|
UserId: req.UserId,
|
||||||
|
AdapterTypeDict: "0",
|
||||||
|
CommitTime: time.Now(),
|
||||||
|
}
|
||||||
|
// 保存任务数据到数据库
|
||||||
|
tx := l.svcCtx.DbEngin.Create(&taskModel)
|
||||||
|
if tx.Error != nil {
|
||||||
|
|
||||||
|
}
|
||||||
|
var adapterId int64
|
||||||
|
tx.Table("t_cluster").Select("adapter_id").Where("id=?", req.ClusterId).Find(&adapterId)
|
||||||
|
// 构建cloud任务结构体
|
||||||
|
cloudTaskModel := cloud2.TaskCloudModel{
|
||||||
|
Id: utils.GenSnowflakeID(),
|
||||||
|
TaskId: taskModel.Id,
|
||||||
|
Name: req.Name,
|
||||||
|
AdapterId: adapterId,
|
||||||
|
Status: constants.Saved,
|
||||||
|
Namespace: "default",
|
||||||
|
UserId: req.UserId,
|
||||||
|
}
|
||||||
|
// 保存任务数据到数据库
|
||||||
|
tx = l.svcCtx.DbEngin.Create(&cloudTaskModel)
|
||||||
|
if tx.Error != nil {
|
||||||
|
|
||||||
|
}
|
||||||
|
resp = taskModel.Id
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,6 +13,7 @@ type Resp struct {
|
||||||
|
|
||||||
type CreateParam struct {
|
type CreateParam struct {
|
||||||
ContainerGroupName string `json:"containerGroupName"`
|
ContainerGroupName string `json:"containerGroupName"`
|
||||||
|
Description string `json:"description,omitempty"`
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
Image string `json:"image"`
|
Image string `json:"image"`
|
||||||
Cpu string `json:"cpu,omitempty"`
|
Cpu string `json:"cpu,omitempty"`
|
||||||
|
|
|
@ -59,8 +59,8 @@ func NewCloudScheduler(ctx context.Context, val string, scheduler *scheduler.Sch
|
||||||
|
|
||||||
func (as *CloudScheduler) GetNewStructForDb(task *response.TaskInfo, resource string, participantId int64) (interface{}, error) {
|
func (as *CloudScheduler) GetNewStructForDb(task *response.TaskInfo, resource string, participantId int64) (interface{}, error) {
|
||||||
c := cloud.TaskCloudModel{
|
c := cloud.TaskCloudModel{
|
||||||
AdapterId: uint(participantId),
|
AdapterId: (participantId),
|
||||||
TaskId: uint(task.TaskId),
|
TaskId: (task.TaskId),
|
||||||
Status: constants.Saved,
|
Status: constants.Saved,
|
||||||
YamlString: as.yamlString,
|
YamlString: as.yamlString,
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,6 +12,8 @@ type ContainerDeleteParameter interface {
|
||||||
type CreateParam struct {
|
type CreateParam struct {
|
||||||
ClusterId string `json:"clusterId,omitempty"`
|
ClusterId string `json:"clusterId,omitempty"`
|
||||||
ContainerGroupName string `json:"containerGroupName"`
|
ContainerGroupName string `json:"containerGroupName"`
|
||||||
|
Description string `json:"description,omitempty"`
|
||||||
|
UserId int64 `json:"userId"`
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
Image string `json:"image"`
|
Image string `json:"image"`
|
||||||
Cpu string `json:"cpu,omitempty"`
|
Cpu string `json:"cpu,omitempty"`
|
||||||
|
@ -61,6 +63,7 @@ type EciDeleteParam struct {
|
||||||
|
|
||||||
// 获取容器信息
|
// 获取容器信息
|
||||||
type GetParam struct {
|
type GetParam struct {
|
||||||
|
TaskId string `json:"taskId"`
|
||||||
ClusterId string `json:"clusterId,omitempty"`
|
ClusterId string `json:"clusterId,omitempty"`
|
||||||
Name string `json:"name,omitempty"`
|
Name string `json:"name,omitempty"`
|
||||||
GetParameter ContainerGetParameter `json:"getParameter,omitempty"`
|
GetParameter ContainerGetParameter `json:"getParameter,omitempty"`
|
||||||
|
|
|
@ -6,10 +6,10 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
type TaskCloudModel struct {
|
type TaskCloudModel struct {
|
||||||
Id uint `json:"id" gorm:"primarykey;not null;comment:id"`
|
Id int64 `json:"id" gorm:"primarykey;not null;comment:id"`
|
||||||
Name string `json:"name" gorm:"null;comment:名称"`
|
Name string `json:"name" gorm:"null;comment:名称"`
|
||||||
TaskId uint `json:"taskId" gorm:"not null;comment:task表id"`
|
TaskId int64 `json:"taskId" gorm:"not null;comment:task表id"`
|
||||||
AdapterId uint `json:"adapterId" gorm:"not null;comment:适配器id"`
|
AdapterId int64 `json:"adapterId" gorm:"not null;comment:适配器id"`
|
||||||
AdapterName string `json:"adapterName" gorm:"not null;comment:适配器名称"`
|
AdapterName string `json:"adapterName" gorm:"not null;comment:适配器名称"`
|
||||||
ClusterId uint `json:"clusterId" gorm:"not null;comment:集群id"`
|
ClusterId uint `json:"clusterId" gorm:"not null;comment:集群id"`
|
||||||
ClusterName string `json:"clusterName" gorm:"not null;comment:集群名称"`
|
ClusterName string `json:"clusterName" gorm:"not null;comment:集群名称"`
|
||||||
|
|
Loading…
Reference in New Issue