| @@ -858,7 +858,7 @@ type ( | |||||
| Token string `json:"token,optional"` | Token string `json:"token,optional"` | ||||
| Ak string `json:"ak,optional"` | Ak string `json:"ak,optional"` | ||||
| Sk string `json:"sk,optional"` | Sk string `json:"sk,optional"` | ||||
| Region string `json:"region,optional"` | |||||
| Region []string `json:"region,optional"` | |||||
| ProjectId string `json:"projectId,optional"` | ProjectId string `json:"projectId,optional"` | ||||
| Version string `json:"version,optional"` | Version string `json:"version,optional"` | ||||
| Label string `json:"label,optional"` | Label string `json:"label,optional"` | ||||
| @@ -866,6 +866,7 @@ type ( | |||||
| AuthType string `json:"authType,optional"` | AuthType string `json:"authType,optional"` | ||||
| ProducerDict string `json:"producerDict,optional"` | ProducerDict string `json:"producerDict,optional"` | ||||
| RegionDict string `json:"regionDict,optional"` | RegionDict string `json:"regionDict,optional"` | ||||
| RegionName string `json:"regionName,optional"` | |||||
| } | } | ||||
| ClusterInfo { | ClusterInfo { | ||||
| Id string `json:"id,omitempty" db:"id"` | Id string `json:"id,omitempty" db:"id"` | ||||
| @@ -888,6 +889,7 @@ type ( | |||||
| AuthType string `json:"authType,omitempty" db:"auth_type"` | AuthType string `json:"authType,omitempty" db:"auth_type"` | ||||
| ProducerDict string `json:"producerDict,omitempty" db:"producer_dict"` | ProducerDict string `json:"producerDict,omitempty" db:"producer_dict"` | ||||
| RegionDict string `json:"regionDict,omitempty" db:"region_dict"` | RegionDict string `json:"regionDict,omitempty" db:"region_dict"` | ||||
| Location string `json:"location,omitempty" db:"location"` | |||||
| CreateTime string `json:"createTime,omitempty" db:"created_time" gorm:"autoCreateTime"` | CreateTime string `json:"createTime,omitempty" db:"created_time" gorm:"autoCreateTime"` | ||||
| } | } | ||||
| ) | ) | ||||
| @@ -19,11 +19,12 @@ require ( | |||||
| github.com/robfig/cron/v3 v3.0.1 | github.com/robfig/cron/v3 v3.0.1 | ||||
| github.com/zeromicro/go-zero v1.7.2 | github.com/zeromicro/go-zero v1.7.2 | ||||
| gitlink.org.cn/JointCloud/pcm-ac v0.0.0-20240918015229-59c579d1a437 | gitlink.org.cn/JointCloud/pcm-ac v0.0.0-20240918015229-59c579d1a437 | ||||
| gitlink.org.cn/JointCloud/pcm-modelarts v0.0.0-20240909072501-939c3144cd9e | |||||
| gitlink.org.cn/JointCloud/pcm-modelarts v0.0.0-20240918011543-482dcd609877 | |||||
| gitlink.org.cn/JointCloud/pcm-octopus v0.0.0-20240817071412-44397870b110 | gitlink.org.cn/JointCloud/pcm-octopus v0.0.0-20240817071412-44397870b110 | ||||
| gitlink.org.cn/JointCloud/pcm-openstack v0.0.0-20240403033338-e7edabad4203 | 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/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/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 | go.opentelemetry.io/otel/trace v1.29.0 | ||||
| gonum.org/v1/gonum v0.11.0 | gonum.org/v1/gonum v0.11.0 | ||||
| google.golang.org/grpc v1.66.0 | google.golang.org/grpc v1.66.0 | ||||
| @@ -468,8 +468,8 @@ github.com/zeromicro/go-zero v1.7.2 h1:a8lyVOG3KXG4LrAy6ZmtJTJtisX4Ostc4Pst4fE70 | |||||
| github.com/zeromicro/go-zero v1.7.2/go.mod h1:WFXfF92Exw0O7WECifS6r99JSzv4KEN49x9RhAfgkMc= | github.com/zeromicro/go-zero v1.7.2/go.mod h1:WFXfF92Exw0O7WECifS6r99JSzv4KEN49x9RhAfgkMc= | ||||
| gitlink.org.cn/JointCloud/pcm-ac v0.0.0-20240918015229-59c579d1a437 h1:ta6h9+FU7AQ2fNyQiXrZnMdlNBjOKdyBx4e3RF7BE84= | gitlink.org.cn/JointCloud/pcm-ac v0.0.0-20240918015229-59c579d1a437 h1:ta6h9+FU7AQ2fNyQiXrZnMdlNBjOKdyBx4e3RF7BE84= | ||||
| gitlink.org.cn/JointCloud/pcm-ac v0.0.0-20240918015229-59c579d1a437/go.mod h1:3eECiw9O2bIFkkePlloKyLNXiqBAhOxNrDoGaaGseGY= | gitlink.org.cn/JointCloud/pcm-ac v0.0.0-20240918015229-59c579d1a437/go.mod h1:3eECiw9O2bIFkkePlloKyLNXiqBAhOxNrDoGaaGseGY= | ||||
| gitlink.org.cn/JointCloud/pcm-modelarts v0.0.0-20240909072501-939c3144cd9e h1:6LYJggBoeAQxy/otzWjt40Pa7gnVvUR4c5YMi6A/NdU= | |||||
| gitlink.org.cn/JointCloud/pcm-modelarts v0.0.0-20240909072501-939c3144cd9e/go.mod h1:/eOmBFZKWGoabG3sRVkVvIbLwsd2631k4jkUBR6x1AA= | |||||
| gitlink.org.cn/JointCloud/pcm-modelarts v0.0.0-20240918011543-482dcd609877 h1:a+1FpxqLPRojlAkJlAeRhKRbxajymXYgrM+s9bfQx0E= | |||||
| gitlink.org.cn/JointCloud/pcm-modelarts v0.0.0-20240918011543-482dcd609877/go.mod h1:/eOmBFZKWGoabG3sRVkVvIbLwsd2631k4jkUBR6x1AA= | |||||
| gitlink.org.cn/JointCloud/pcm-octopus v0.0.0-20240817071412-44397870b110 h1:GaXwr5sgDh0raHjUf9IewTvnRvajYea7zbLsaerYyXo= | gitlink.org.cn/JointCloud/pcm-octopus v0.0.0-20240817071412-44397870b110 h1:GaXwr5sgDh0raHjUf9IewTvnRvajYea7zbLsaerYyXo= | ||||
| gitlink.org.cn/JointCloud/pcm-octopus v0.0.0-20240817071412-44397870b110/go.mod h1:QOD5+/l2D+AYBjF2h5T0mdJyfGAmF78QmeKdbBXbjLQ= | gitlink.org.cn/JointCloud/pcm-octopus v0.0.0-20240817071412-44397870b110/go.mod h1:QOD5+/l2D+AYBjF2h5T0mdJyfGAmF78QmeKdbBXbjLQ= | ||||
| gitlink.org.cn/JointCloud/pcm-openstack v0.0.0-20240403033338-e7edabad4203 h1:s6PsZ1+bev294IWdZRlV7mnOwI1+UzFcldVW/BqhQzI= | gitlink.org.cn/JointCloud/pcm-openstack v0.0.0-20240403033338-e7edabad4203 h1:s6PsZ1+bev294IWdZRlV7mnOwI1+UzFcldVW/BqhQzI= | ||||
| @@ -478,6 +478,8 @@ 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/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 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/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 h1:3KpLJir1ZEBrYuV2v+Twaa/e2MdDCEZ/70H+lzEiwsk= | ||||
| go.etcd.io/etcd/api/v3 v3.5.15/go.mod h1:N9EhGzXq58WuMllgH9ZvnEr7SI9pS0k0+DHZezGp7jM= | 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= | go.etcd.io/etcd/client/pkg/v3 v3.5.15 h1:fo0HpWz/KlHGMCC+YejpiCmyWDEuIpnTDzpJLB5fWlA= | ||||
| @@ -3,12 +3,16 @@ package adapters | |||||
| import ( | import ( | ||||
| "context" | "context" | ||||
| "errors" | "errors" | ||||
| "gitlink.org.cn/JointCloud/pcm-coordinator/pkg/utils" | |||||
| "gorm.io/gorm" | |||||
| "time" | |||||
| "fmt" | |||||
| "gitlink.org.cn/JointCloud/pcm-coordinator/internal/svc" | "gitlink.org.cn/JointCloud/pcm-coordinator/internal/svc" | ||||
| "gitlink.org.cn/JointCloud/pcm-coordinator/internal/types" | "gitlink.org.cn/JointCloud/pcm-coordinator/internal/types" | ||||
| tool "gitlink.org.cn/JointCloud/pcm-coordinator/pkg/utils" | |||||
| "gorm.io/gorm" | |||||
| "io/ioutil" | |||||
| "k8s.io/apimachinery/pkg/util/json" | |||||
| "net/http" | |||||
| "net/url" | |||||
| "time" | |||||
| "github.com/zeromicro/go-zero/core/logx" | "github.com/zeromicro/go-zero/core/logx" | ||||
| ) | ) | ||||
| @@ -33,17 +37,27 @@ func (l *CreateClusterLogic) CreateCluster(req *types.ClusterCreateReq) (resp *t | |||||
| if errors.Is(result.Error, gorm.ErrRecordNotFound) { | if errors.Is(result.Error, gorm.ErrRecordNotFound) { | ||||
| return nil, errors.New("adapter does not exist") | return nil, errors.New("adapter does not exist") | ||||
| } | } | ||||
| cluster := types.ClusterInfo{} | cluster := types.ClusterInfo{} | ||||
| utils.Convert(req, &cluster) | |||||
| cluster.Id = utils.GenSnowflakeIDStr() | |||||
| tool.Convert(req, &cluster) | |||||
| cluster.CreateTime = time.Now().Format("2006-01-02 15:04:05") | cluster.CreateTime = time.Now().Format("2006-01-02 15:04:05") | ||||
| cluster.OwnerId = "0" | cluster.OwnerId = "0" | ||||
| // 获取集群经纬度 | |||||
| location, err := GeoMap(req.RegionName) | |||||
| cluster.Location = location | |||||
| cluster.Id = tool.GenSnowflakeIDStr() | |||||
| tx := l.svcCtx.DbEngin.Table("t_cluster").Create(&cluster) | tx := l.svcCtx.DbEngin.Table("t_cluster").Create(&cluster) | ||||
| if tx.Error != nil { | if tx.Error != nil { | ||||
| logx.Errorf(tx.Error.Error()) | logx.Errorf(tx.Error.Error()) | ||||
| return nil, errors.New("cluster create failed") | return nil, errors.New("cluster create failed") | ||||
| } | } | ||||
| if err != nil { | |||||
| return nil, err | |||||
| } | |||||
| // push cluster info to adapter | // push cluster info to adapter | ||||
| var adapterServer string | var adapterServer string | ||||
| l.svcCtx.DbEngin.Raw("select server from t_adapter where id = ?", req.AdapterId).Scan(&adapterServer) | l.svcCtx.DbEngin.Raw("select server from t_adapter where id = ?", req.AdapterId).Scan(&adapterServer) | ||||
| @@ -64,3 +78,63 @@ func (l *CreateClusterLogic) CreateCluster(req *types.ClusterCreateReq) (resp *t | |||||
| } | } | ||||
| return | return | ||||
| } | } | ||||
| func GeoMap(address string) (string, error) { | |||||
| // 此处填写您在控制台-应用管理-创建应用后获取的AK | |||||
| ak := "d3cc9eee0266d39a52498726d1b82f87" | |||||
| // 接口地址 | |||||
| uri := "https://restapi.amap.com/v3/geocode/geo" | |||||
| // 设置请求参数 | |||||
| params := url.Values{ | |||||
| "address": []string{address}, | |||||
| "output": []string{"json"}, | |||||
| "key": []string{ak}, | |||||
| } | |||||
| // 发起请求 | |||||
| request, err := url.Parse(uri + "?" + params.Encode()) | |||||
| if nil != err { | |||||
| fmt.Printf("host error: %v", err) | |||||
| return "", err | |||||
| } | |||||
| resp, err1 := http.Get(request.String()) | |||||
| fmt.Printf("url: %s\n", request.String()) | |||||
| defer resp.Body.Close() | |||||
| if err1 != nil { | |||||
| fmt.Printf("request error: %v", err1) | |||||
| return "", err | |||||
| } | |||||
| body, err2 := ioutil.ReadAll(resp.Body) | |||||
| if err2 != nil { | |||||
| fmt.Printf("response error: %v", err2) | |||||
| } | |||||
| fmt.Println(string(body)) | |||||
| geoResponse := GeoResponse{} | |||||
| json.Unmarshal(body, &geoResponse) | |||||
| return geoResponse.Geocodes[0].Location, err | |||||
| } | |||||
| type GeoResponse struct { | |||||
| Status string `json:"status"` | |||||
| Info string `json:"info"` | |||||
| InfoCode string `json:"infocode"` | |||||
| Count string `json:"count"` | |||||
| Geocodes []GeoCode `json:"geocodes"` | |||||
| } | |||||
| type GeoCode struct { | |||||
| FormattedAddress string `json:"formatted_address"` | |||||
| Country string `json:"country"` | |||||
| Province string `json:"province"` | |||||
| CityCode string `json:"citycode"` | |||||
| City string `json:"city"` | |||||
| District string `json:"district"` | |||||
| Adcode string `json:"adcode"` | |||||
| Number string `json:"number"` | |||||
| Location string `json:"location"` | |||||
| Level string `json:"level"` | |||||
| } | |||||
| @@ -779,26 +779,27 @@ type ClusterReq struct { | |||||
| } | } | ||||
| type ClusterCreateReq struct { | type ClusterCreateReq struct { | ||||
| Id string `json:"id,optional"` | |||||
| AdapterId string `json:"adapterId,optional"` | |||||
| Name string `json:"name,optional"` | |||||
| Nickname string `json:"nickname,optional"` | |||||
| Description string `json:"description,optional"` | |||||
| Server string `json:"server,optional"` | |||||
| MonitorServer string `json:"monitorServer,optional"` | |||||
| Username string `json:"username,optional"` | |||||
| Password string `json:"password,optional"` | |||||
| Token string `json:"token,optional"` | |||||
| Ak string `json:"ak,optional"` | |||||
| Sk string `json:"sk,optional"` | |||||
| Region string `json:"region,optional"` | |||||
| ProjectId string `json:"projectId,optional"` | |||||
| Version string `json:"version,optional"` | |||||
| Label string `json:"label,optional"` | |||||
| OwnerId string `json:"ownerId,omitempty,optional"` | |||||
| AuthType string `json:"authType,optional"` | |||||
| ProducerDict string `json:"producerDict,optional"` | |||||
| RegionDict string `json:"regionDict,optional"` | |||||
| Id string `json:"id,optional"` | |||||
| AdapterId string `json:"adapterId,optional"` | |||||
| Name string `json:"name,optional"` | |||||
| Nickname string `json:"nickname,optional"` | |||||
| Description string `json:"description,optional"` | |||||
| Server string `json:"server,optional"` | |||||
| MonitorServer string `json:"monitorServer,optional"` | |||||
| Username string `json:"username,optional"` | |||||
| Password string `json:"password,optional"` | |||||
| Token string `json:"token,optional"` | |||||
| Ak string `json:"ak,optional"` | |||||
| Sk string `json:"sk,optional"` | |||||
| Region []string `json:"region,optional"` | |||||
| ProjectId string `json:"projectId,optional"` | |||||
| Version string `json:"version,optional"` | |||||
| Label string `json:"label,optional"` | |||||
| OwnerId string `json:"ownerId,omitempty,optional"` | |||||
| AuthType string `json:"authType,optional"` | |||||
| ProducerDict string `json:"producerDict,optional"` | |||||
| RegionDict string `json:"regionDict,optional"` | |||||
| RegionName string `json:"regionName,optional"` | |||||
| } | } | ||||
| type ClusterInfo struct { | type ClusterInfo struct { | ||||
| @@ -822,6 +823,7 @@ type ClusterInfo struct { | |||||
| AuthType string `json:"authType,omitempty" db:"auth_type"` | AuthType string `json:"authType,omitempty" db:"auth_type"` | ||||
| ProducerDict string `json:"producerDict,omitempty" db:"producer_dict"` | ProducerDict string `json:"producerDict,omitempty" db:"producer_dict"` | ||||
| RegionDict string `json:"regionDict,omitempty" db:"region_dict"` | RegionDict string `json:"regionDict,omitempty" db:"region_dict"` | ||||
| Location string `json:"location,omitempty" db:"location"` | |||||
| CreateTime string `json:"createTime,omitempty" db:"created_time" gorm:"autoCreateTime"` | CreateTime string `json:"createTime,omitempty" db:"created_time" gorm:"autoCreateTime"` | ||||
| } | } | ||||