forked from JointCloud/pcm-coordinator
parent
3e11a1789b
commit
8395ac4490
1
go.mod
1
go.mod
|
@ -24,7 +24,6 @@ require (
|
|||
gitlink.org.cn/JointCloud/pcm-openstack v0.0.0-20240403033338-e7edabad4203
|
||||
gitlink.org.cn/JointCloud/pcm-slurm v0.0.0-20240301080743-8b94bbaf57f5
|
||||
gitlink.org.cn/jcce-pcm/pcm-participant-ceph v0.0.0-20230904090036-24fc730ec87d
|
||||
gitlink.org.cn/jcce-pcm/utils v0.0.1
|
||||
go.opentelemetry.io/otel/trace v1.29.0
|
||||
gonum.org/v1/gonum v0.11.0
|
||||
google.golang.org/grpc v1.66.0
|
||||
|
|
2
go.sum
2
go.sum
|
@ -478,8 +478,6 @@ gitlink.org.cn/JointCloud/pcm-slurm v0.0.0-20240301080743-8b94bbaf57f5 h1:+/5vnz
|
|||
gitlink.org.cn/JointCloud/pcm-slurm v0.0.0-20240301080743-8b94bbaf57f5/go.mod h1:97AlUXN13g9UN3+9/DzCHpeoU5sbdyv0IQuTEHNexzQ=
|
||||
gitlink.org.cn/jcce-pcm/pcm-participant-ceph v0.0.0-20230904090036-24fc730ec87d h1:DHjl/rLuH2gKYtY0MKMGNQDHFT12APg25RlMUQo+tHk=
|
||||
gitlink.org.cn/jcce-pcm/pcm-participant-ceph v0.0.0-20230904090036-24fc730ec87d/go.mod h1:r/KLzUpupCV5jdxSfgDhc2pVjP0fBi3VhAWRttsBn30=
|
||||
gitlink.org.cn/jcce-pcm/utils v0.0.1 h1:3PH93Z/JFTH5JRO9MFf3dD1Gnd12aGiIIViWBlQGuhE=
|
||||
gitlink.org.cn/jcce-pcm/utils v0.0.1/go.mod h1:5cwaaqM0+HK5GXVbYozGlWvgwoUby0KytdvhbwQW1ks=
|
||||
go.etcd.io/etcd/api/v3 v3.5.15 h1:3KpLJir1ZEBrYuV2v+Twaa/e2MdDCEZ/70H+lzEiwsk=
|
||||
go.etcd.io/etcd/api/v3 v3.5.15/go.mod h1:N9EhGzXq58WuMllgH9ZvnEr7SI9pS0k0+DHZezGp7jM=
|
||||
go.etcd.io/etcd/client/pkg/v3 v3.5.15 h1:fo0HpWz/KlHGMCC+YejpiCmyWDEuIpnTDzpJLB5fWlA=
|
||||
|
|
|
@ -32,6 +32,13 @@ func NewCreateClusterLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Cre
|
|||
}
|
||||
|
||||
func (l *CreateClusterLogic) CreateCluster(req *types.ClusterCreateReq) (resp *types.ClusterResp, err error) {
|
||||
// 校验集群名称是否唯一
|
||||
var count int64
|
||||
l.svcCtx.DbEngin.Table("t_cluster").Where("name = ?", req.Name).Count(&count)
|
||||
if count > 0 {
|
||||
return nil, errors.New("the cluster name is already in use")
|
||||
}
|
||||
// 校验驱动器是否存在
|
||||
adapter := &types.AdapterInfo{}
|
||||
result := l.svcCtx.DbEngin.Table("t_adapter").First(&adapter, req.AdapterId)
|
||||
if errors.Is(result.Error, gorm.ErrRecordNotFound) {
|
||||
|
@ -45,6 +52,9 @@ func (l *CreateClusterLogic) CreateCluster(req *types.ClusterCreateReq) (resp *t
|
|||
cluster.OwnerId = "0"
|
||||
// 获取集群经纬度
|
||||
location, err := GeoMap(req.RegionName)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
cluster.Location = location
|
||||
|
||||
cluster.Id = tool.GenSnowflakeIDStr()
|
||||
|
@ -54,28 +64,22 @@ func (l *CreateClusterLogic) CreateCluster(req *types.ClusterCreateReq) (resp *t
|
|||
return nil, errors.New("cluster create failed")
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// push cluster info to adapter
|
||||
var adapterServer string
|
||||
l.svcCtx.DbEngin.Raw("select server from t_adapter where id = ?", req.AdapterId).Scan(&adapterServer)
|
||||
response, err := l.svcCtx.HttpClient.R().
|
||||
SetBody(&types.ClusterInfo{
|
||||
Name: req.Name,
|
||||
Server: req.Server,
|
||||
Token: req.Token,
|
||||
MonitorServer: req.MonitorServer,
|
||||
}).
|
||||
ForceContentType("application/json").
|
||||
Post(adapterServer + "/api/v1/cluster/info")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if response.IsError() {
|
||||
return nil, errors.New(string(response.Body()))
|
||||
}
|
||||
go func() {
|
||||
var adapterServer string
|
||||
l.svcCtx.DbEngin.Raw("select server from t_adapter where id = ?", req.AdapterId).Scan(&adapterServer)
|
||||
l.svcCtx.HttpClient.R().
|
||||
SetBody(&types.ClusterInfo{
|
||||
Name: req.Name,
|
||||
Server: req.Server,
|
||||
Token: req.Token,
|
||||
MonitorServer: req.MonitorServer,
|
||||
}).
|
||||
ForceContentType("application/json").
|
||||
Post(adapterServer + "/api/v1/cluster/info")
|
||||
|
||||
}()
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
|
|
|
@ -33,6 +33,12 @@ func (l *UpdateClusterLogic) UpdateCluster(req *types.ClusterCreateReq) (resp *t
|
|||
return nil, errors.New("cluster does not exist")
|
||||
}
|
||||
utils.Convert(req, &cluster)
|
||||
// 获取集群经纬度
|
||||
location, err := GeoMap(req.RegionName)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
cluster.Location = location
|
||||
l.svcCtx.DbEngin.Table("t_cluster").Model(&cluster).Updates(&cluster)
|
||||
return
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue