Compare commits

..

No commits in common. "master" and "master" have entirely different histories.

186 changed files with 1946 additions and 8156 deletions

View File

@ -15,7 +15,7 @@ workflow:
task: git_clone@1.2.9
input:
remote_url: '"https://gitlink.org.cn/JointCloud/pcm-coordinator.git"'
ref: '"refs/heads/test"'
ref: '"refs/heads/master"'
commit_id: '""'
depth: 1
needs:

View File

@ -1,4 +1,4 @@
FROM docker.1ms.run/golang:alpine AS builder
FROM docker-0.unsee.tech/golang:alpine AS builder
WORKDIR /app
@ -21,7 +21,7 @@ RUN --mount=type=cache,target=/go/pkg/mod \
--mount=type=cache,target=/root/.cache/go-build \
GOOS=$TARGETOS GOARCH=$TARGETARCH go build -ldflags="-w -s" -o pcm-core-api
FROM --platform=$TARGETPLATFORM docker.1ms.run/alpine:latest
FROM --platform=$TARGETPLATFORM docker-0.unsee.tech/alpine:latest
WORKDIR /app
RUN apk add --no-cache ca-certificates && update-ca-certificates && \

View File

@ -95,7 +95,6 @@ JcsMiddleware:
Participant:
AdapterId: "1777144940456666666"
CloudAdapterId: "1770658294298316800"
ServiceToken: "CHANGE_ME_INTERNAL_SERVICE_TOKEN"
JccUserService:
Url: http://jcce-admin:8082/jcc-admin/admin/user/{id}
Url: http://jcce-admin:8082/jcc-admin/admin/user/{id}

8
go.mod
View File

@ -5,8 +5,8 @@ go 1.23.0
require (
github.com/JCCE-nudt/apigw-go-sdk v0.0.0-20230525025609-34159d6f2818
github.com/Masterminds/squirrel v1.5.4
github.com/aliyun/alibaba-cloud-sdk-go v1.63.107
github.com/bwmarrin/snowflake v0.3.0
github.com/ghodss/yaml v1.0.0
github.com/go-redis/redis/v8 v8.11.5
github.com/go-resty/resty/v2 v2.16.2
github.com/golang-jwt/jwt/v5 v5.2.2
@ -24,12 +24,11 @@ require (
gitlink.org.cn/JointCloud/pcm-ac v0.0.0-20250107025835-8fc888b1d170
gitlink.org.cn/JointCloud/pcm-hpc v0.0.0-20241125115811-72f3568255a4
gitlink.org.cn/JointCloud/pcm-modelarts v0.0.0-20250313064001-91fb558cfdb6
gitlink.org.cn/JointCloud/pcm-octopus v0.0.0-20250912031150-2f5de7195a9f
gitlink.org.cn/JointCloud/pcm-octopus v0.0.0-20250624091120-dee975c73c57
gitlink.org.cn/JointCloud/pcm-openi v0.0.0-20250320103718-7bd6650118ee
gitlink.org.cn/JointCloud/pcm-openstack v0.0.0-20240403033338-e7edabad4203
gitlink.org.cn/JointCloud/pcm-slurm v0.0.0-20240301080743-8b94bbaf57f5
go.opentelemetry.io/otel/trace v1.32.0
golang.org/x/exp v0.0.0-20240119083558-1b970713d09a
gonum.org/v1/gonum v0.11.0
google.golang.org/grpc v1.68.1
gopkg.in/yaml.v2 v2.4.0
@ -129,7 +128,7 @@ require (
github.com/mwitkow/go-conntrack v0.0.0-20190716064945-2f068394615f // indirect
github.com/oklog/run v1.1.0 // indirect
github.com/oklog/ulid v1.3.1 // indirect
github.com/opentracing/opentracing-go v1.2.1-0.20220228012449-10b1cf09e00b // indirect
github.com/opentracing/opentracing-go v1.2.0 // indirect
github.com/openzipkin/zipkin-go v0.4.3 // indirect
github.com/pelletier/go-toml/v2 v2.2.3 // indirect
github.com/prometheus/client_model v0.6.1 // indirect
@ -173,6 +172,7 @@ require (
go.uber.org/zap v1.27.0 // indirect
golang.org/x/arch v0.15.0 // indirect
golang.org/x/crypto v0.36.0 // indirect
golang.org/x/exp v0.0.0-20240119083558-1b970713d09a // indirect
golang.org/x/mod v0.22.0 // indirect
golang.org/x/net v0.37.0 // indirect
golang.org/x/oauth2 v0.24.0 // indirect

38
go.sum
View File

@ -38,12 +38,10 @@ github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym
github.com/DATA-DOG/go-sqlmock v1.5.2 h1:OcvFkGmslmlZibjAjaHm3L//6LiuBgolP7OputlJIzU=
github.com/DATA-DOG/go-sqlmock v1.5.2/go.mod h1:88MAG/4G7SMwSE3CeA0ZKzrT5CiOU3OJ+JlNzwDqpNU=
github.com/DataDog/datadog-go v3.2.0+incompatible/go.mod h1:LButxg5PwREeZtORoXG3tL4fMGNddJ+vMq1mwgfaqoQ=
github.com/HdrHistogram/hdrhistogram-go v1.1.2/go.mod h1:yDgFjdqOqDEKOvasDdhWNXYg9BVp4O+o5f6V/ehm6Oo=
github.com/JCCE-nudt/apigw-go-sdk v0.0.0-20230525025609-34159d6f2818 h1:QLulhUyxPDs9FFieVZwmKAnUBLeRDhsVNehotAAL/FE=
github.com/JCCE-nudt/apigw-go-sdk v0.0.0-20230525025609-34159d6f2818/go.mod h1:j+am5/1URgsvyhOAyURFR9vH3malaW7Tq6d33OyPsnM=
github.com/Masterminds/squirrel v1.5.4 h1:uUcX/aBc8O7Fg9kaISIUsHXdKuqehiXAMQTYX8afzqM=
github.com/Masterminds/squirrel v1.5.4/go.mod h1:NNaOrjSoIDfDA40n7sr2tPNZRfjzjA400rg+riTZj10=
github.com/ajstarks/svgo v0.0.0-20180226025133-644b8db467af/go.mod h1:K08gAheRH3/J6wwsYMMT4xOr94bZjxIelGM0+d/wbFw=
github.com/alecthomas/kingpin/v2 v2.4.0 h1:f48lwail6p8zpO1bC4TxtqACaGqHYA22qkHjHpqDjYY=
github.com/alecthomas/kingpin/v2 v2.4.0/go.mod h1:0gyi0zQnjuFk8xrkNKamJoyUo382HRL7ATRpFZCw6tE=
github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
@ -57,8 +55,6 @@ github.com/alicebob/gopher-json v0.0.0-20230218143504-906a9b012302 h1:uvdUDbHQHO
github.com/alicebob/gopher-json v0.0.0-20230218143504-906a9b012302/go.mod h1:SGnFV6hVsYE877CKEZ6tDNTjaSXYUk6QqoIK6PrAtcc=
github.com/alicebob/miniredis/v2 v2.33.0 h1:uvTF0EDeu9RLnUEG27Db5I68ESoIxTiXbNUiji6lZrA=
github.com/alicebob/miniredis/v2 v2.33.0/go.mod h1:MhP4a3EU7aENRi9aO+tHfTBZicLqQevyi/DJpoj6mi0=
github.com/aliyun/alibaba-cloud-sdk-go v1.63.107 h1:qagvUyrgOnBIlVRQWOyCZGVKUIYbMBdGdJ104vBpRFU=
github.com/aliyun/alibaba-cloud-sdk-go v1.63.107/go.mod h1:SOSDHfe1kX91v3W5QiBsWSLqeLxImobbMX1mxrFHsVQ=
github.com/armon/go-metrics v0.0.0-20180917152333-f0300d1749da/go.mod h1:Q73ZrmVTwzkszR9V5SSuryQ31EELlFMUz1kKyl939pY=
github.com/armon/go-metrics v0.4.1 h1:hR91U9KYmb6bLBYLQjyM+3j+rcd/UhE+G78SFnF8gJA=
github.com/armon/go-metrics v0.4.1/go.mod h1:E6amYzXo6aW1tqzoZGT755KkbgrJsSdpwZ+3JqfkOG4=
@ -105,7 +101,6 @@ github.com/coreos/go-semver v0.3.1/go.mod h1:irMmmIw/7yzSRPWryHsK7EYSg09caPQL03V
github.com/coreos/go-systemd/v22 v22.3.3-0.20220203105225-a9a7ef127534/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc=
github.com/coreos/go-systemd/v22 v22.5.0 h1:RrqgGjYQKalulkV8NGVIfkXQf6YYmOyiJKk8iXXhfZs=
github.com/coreos/go-systemd/v22 v22.5.0/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc=
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM=
@ -120,7 +115,6 @@ github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1m
github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c=
github.com/fatih/color v1.18.0 h1:S8gINlzdQ840/4pfAwic/ZE0djQEH3wM94VfqLTZcOM=
github.com/fatih/color v1.18.0/go.mod h1:4FelSpRwEGDpQ12mAdzqdOukCy4u8WUtOY6lkT/6HfU=
github.com/fogleman/gg v1.2.1-0.20190220221249-0403632d5b90/go.mod h1:R/bRT+9gY/C5z7JzPU0zXsXHKM4/ayA+zqcVNZzPa1k=
github.com/frankban/quicktest v1.14.6 h1:7Xjx+VpznH+oBnejlPUj8oUpdxnVs4f8XU8WnHkI4W8=
github.com/frankban/quicktest v1.14.6/go.mod h1:4ptaffx2x8+WTWXmUCuVU6aPUX1/Mz7zb5vbUoiM6w0=
github.com/fsnotify/fsnotify v1.7.0 h1:8JEhPFa5W2WU7YfeZzPNqzMP6Lwt7L2715Ggo0nosvA=
@ -129,6 +123,8 @@ github.com/fxamacker/cbor/v2 v2.7.0 h1:iM5WgngdRBanHcxugY4JySA0nk1wZorNOpTgCMedv
github.com/fxamacker/cbor/v2 v2.7.0/go.mod h1:pxXPTn3joSm21Gbwsv0w9OSA2y1HFR9qXEeXQVeNoDQ=
github.com/gabriel-vasile/mimetype v1.4.8 h1:FfZ3gj38NjllZIeJAmMhr+qKL8Wu+nOoI3GqacKw1NM=
github.com/gabriel-vasile/mimetype v1.4.8/go.mod h1:ByKUIKGjh1ODkGM1asKUbQZOLGrPjydw3hYPU2YU9t8=
github.com/ghodss/yaml v1.0.0 h1:wQHKEahhL6wmXdzwWG11gIVCkOv05bNOh+Rxn0yngAk=
github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04=
github.com/gin-contrib/sse v1.0.0 h1:y3bT1mUWUxDpW4JLQg/HnTqV4rozuW4tC9eFKTxYI9E=
github.com/gin-contrib/sse v1.0.0/go.mod h1:zNuFdwarAygJBht0NTKiSi3jRf6RbqeILZ9Sp6Slhe0=
github.com/gin-gonic/gin v1.10.0 h1:nTuyha1TYqgedzytsKYqna+DfLos46nTv2ygFy86HFU=
@ -198,7 +194,6 @@ github.com/gofrs/uuid v4.4.0+incompatible/go.mod h1:b2aQJv3Z4Fp6yNu3cdSllBxTCLRx
github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ=
github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q=
github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q=
github.com/goji/httpauth v0.0.0-20160601135302-2da839ab0f4d/go.mod h1:nnjvkQ9ptGaCkuDUx6wNykzzlUixGxvkme+H/lnzb+A=
github.com/golang-jwt/jwt/v4 v4.5.1 h1:JdqV9zKUdtaa9gdPlywC3aeoEsR681PlKC+4F5gQgeo=
github.com/golang-jwt/jwt/v4 v4.5.1/go.mod h1:m21LjoU+eqJr34lmDMbreY2eSTRJ1cv77w39/MY0Ch0=
github.com/golang-jwt/jwt/v5 v5.2.2 h1:Rl4B7itRWVtYIHFrSNd7vhTiz9UpLdi6gZhZ3wEeDy8=
@ -207,7 +202,6 @@ github.com/golang-sql/civil v0.0.0-20220223132316-b832511892a9 h1:au07oEsX2xN0kt
github.com/golang-sql/civil v0.0.0-20220223132316-b832511892a9/go.mod h1:8vg3r2VgvsThLBIFL93Qb5yWzgyZWhEmBwUJWevAkK0=
github.com/golang-sql/sqlexp v0.1.0 h1:ZCD6MBpcuOVfGVqsEmY5/4FtYiKz6tSyUv9LPEDei6A=
github.com/golang-sql/sqlexp v0.1.0/go.mod h1:J4ad9Vo8ZCWQ2GMrC4UCQy1JpCbwU9m3EOqtpKwwwHI=
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0/go.mod h1:E/TSTwGwJL78qG/PmXZO1EjYhfJinVAhrmmHX6Z8B9k=
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q=
github.com/golang/groupcache v0.0.0-20190702054246-869f871628b6/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc=
github.com/golang/groupcache v0.0.0-20191227052852-215e87163ea7/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc=
@ -340,7 +334,6 @@ github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod h1
github.com/jstemmer/go-junit-report v0.9.1/go.mod h1:Brl9GWCQeLvo8nXZwPNNblvFj/XSXhF0NWZEnDohbsk=
github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w=
github.com/julienschmidt/httprouter v1.3.0/go.mod h1:JR6WtHb+2LUe8TCKY3cZOxFyyO8IZAc4RVcycCCAKdM=
github.com/jung-kurt/gofpdf v1.0.3-0.20190309125859-24315acbbda5/go.mod h1:7Id9E/uU8ce6rXgefFLlgrJj/GYY22cpxn+r32jIOes=
github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8=
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
github.com/klauspost/compress v1.17.11 h1:In6xLpyWOi1+C7tXUUWv2ot1QvBjxevKAaI6IXrJmUc=
@ -402,7 +395,6 @@ github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822/go.mod h1:+n7T8m
github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U=
github.com/mwitkow/go-conntrack v0.0.0-20190716064945-2f068394615f h1:KUppIJq7/+SVif2QVs3tOP0zanoHgBEVAwHxUSIzRqU=
github.com/mwitkow/go-conntrack v0.0.0-20190716064945-2f068394615f/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U=
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno=
github.com/nxadm/tail v1.4.8 h1:nPr65rt6Y5JFSKQO7qToXr7pePgD6Gwiw05lkbyAQTE=
github.com/nxadm/tail v1.4.8/go.mod h1:+ncqLTQzXmGhMZNUePPaPqPvBxHAIsmXswZKocGu+AU=
github.com/oklog/run v1.1.0 h1:GEenZ1cK0+q0+wsJew9qUg/DyD8k3JzYsZAi5gYi2mA=
@ -415,8 +407,8 @@ github.com/onsi/ginkgo/v2 v2.19.0 h1:9Cnnf7UHo57Hy3k6/m5k3dRfGTMXGvxhHFvkDTCTpvA
github.com/onsi/ginkgo/v2 v2.19.0/go.mod h1:rlwLi9PilAFJ8jCg9UE1QP6VBpd6/xj3SRC0d6TU0To=
github.com/onsi/gomega v1.33.1 h1:dsYjIxxSR755MDmKVsaFQTE22ChNBcuuTWgkUDSubOk=
github.com/onsi/gomega v1.33.1/go.mod h1:U4R44UsT+9eLIaYRB2a5qajjtQYn0hauxvRm16AVYg0=
github.com/opentracing/opentracing-go v1.2.1-0.20220228012449-10b1cf09e00b h1:FfH+VrHHk6Lxt9HdVS0PXzSXFyS2NbZKXv33FYPol0A=
github.com/opentracing/opentracing-go v1.2.1-0.20220228012449-10b1cf09e00b/go.mod h1:AC62GU6hc0BrNm+9RK9VSiwa/EUe1bkIeFORAMcHvJU=
github.com/opentracing/opentracing-go v1.2.0 h1:uEJPy/1a5RIPAJ0Ov+OIO8OxWu77jEv+1B0VhjKrZUs=
github.com/opentracing/opentracing-go v1.2.0/go.mod h1:GxEUsuufX4nBwe+T+Wl9TAgYrxe9dPLANfrWvHYVTgc=
github.com/openzipkin/zipkin-go v0.4.3 h1:9EGwpqkgnwdEIJ+Od7QVSEIH+ocmm5nPat0G7sjsSdg=
github.com/openzipkin/zipkin-go v0.4.3/go.mod h1:M9wCJZFWCo2RiY+o1eBCEMe0Dp2S5LDHcMZmk3RmK7c=
github.com/pascaldekloe/goe v0.0.0-20180627143212-57f6aae5913c/go.mod h1:lzWF7FIEvWOWxwDKqyGYQf6ZUaNfKdP144TG7ZOy1lc=
@ -524,10 +516,6 @@ github.com/subosito/gotenv v1.6.0/go.mod h1:Dk4QP5c2W3ibzajGcXpNraDfq2IrhjMIvMSW
github.com/tv42/httpunix v0.0.0-20150427012821-b75d8614f926/go.mod h1:9ESjWnEqriFuLhtthL60Sar/7RFoluCcXsuvEwTV5KM=
github.com/twitchyliquid64/golang-asm v0.15.1 h1:SU5vSMR7hnwNxj24w34ZyCi/FmDZTkS4MhqMhdFk5YI=
github.com/twitchyliquid64/golang-asm v0.15.1/go.mod h1:a1lVb/DtPvCB8fslRZhAngC2+aY1QWCk3Cedj/Gdt08=
github.com/uber/jaeger-client-go v2.30.0+incompatible h1:D6wyKGCecFaSRUpo8lCVbaOOb6ThwMmTEbhRwtKR97o=
github.com/uber/jaeger-client-go v2.30.0+incompatible/go.mod h1:WVhlPFC8FDjOFMMWRy2pZqQJSXxYSwNYOkTr/Z6d3Kk=
github.com/uber/jaeger-lib v2.4.1+incompatible h1:td4jdvLcExb4cBISKIpHuGoVXh+dVKhn2Um6rjCsSsg=
github.com/uber/jaeger-lib v2.4.1+incompatible/go.mod h1:ComeNDZlWwrWnDv8aPp0Ba6+uUTzImX/AauajbLI56U=
github.com/ugorji/go/codec v1.2.12 h1:9LC83zGrHhuUA9l16C9AHXAqEV/2wBQ4nkvumAE65EE=
github.com/ugorji/go/codec v1.2.12/go.mod h1:UNopzCgEMSXjBc6AOMqYvWC1ktqTAfzJZUZgYf6w6lg=
github.com/x448/float16 v0.8.4 h1:qLwI1I70+NjRFUR3zs1JPUCgaCXSh3SW62uAKT1mSBM=
@ -551,8 +539,8 @@ gitlink.org.cn/JointCloud/pcm-hpc v0.0.0-20241125115811-72f3568255a4 h1:WIs/189l
gitlink.org.cn/JointCloud/pcm-hpc v0.0.0-20241125115811-72f3568255a4/go.mod h1:YbuoRgF9sEVvNJPQtGRjdocX7Du6NBOTLn+GVwqRVjo=
gitlink.org.cn/JointCloud/pcm-modelarts v0.0.0-20250313064001-91fb558cfdb6 h1:9o0ONbSiQHTzODptzgtVZjRYFBLncZ6dpHp9YF+v73I=
gitlink.org.cn/JointCloud/pcm-modelarts v0.0.0-20250313064001-91fb558cfdb6/go.mod h1:MxtnJJcU8S4zfGKZVcg2MOXGtwucKy7MMDwA0IemBd0=
gitlink.org.cn/JointCloud/pcm-octopus v0.0.0-20250912031150-2f5de7195a9f h1:W9x63bxs13zbb05Wo+cYi4EZhbqd+6KAn+yWw7Tdk88=
gitlink.org.cn/JointCloud/pcm-octopus v0.0.0-20250912031150-2f5de7195a9f/go.mod h1:iQtyaoeMP4mNY0xutDBDD/305QwnPjj0zNtiQjXix50=
gitlink.org.cn/JointCloud/pcm-octopus v0.0.0-20250624091120-dee975c73c57 h1:+T/ZPk1hjNBQy5pKqLsd27s4PVJbee4CzB0OWV27mg4=
gitlink.org.cn/JointCloud/pcm-octopus v0.0.0-20250624091120-dee975c73c57/go.mod h1:iQtyaoeMP4mNY0xutDBDD/305QwnPjj0zNtiQjXix50=
gitlink.org.cn/JointCloud/pcm-openi v0.0.0-20250320103718-7bd6650118ee h1:+YYzcWPX0Up98nOb5ngkCaqiWHpSH7XJQRTUSvYclWU=
gitlink.org.cn/JointCloud/pcm-openi v0.0.0-20250320103718-7bd6650118ee/go.mod h1:0VMTWXsRx7Z5z+kxBid2zf7kq5YtFlxubXEwPHiicyM=
gitlink.org.cn/JointCloud/pcm-openstack v0.0.0-20240403033338-e7edabad4203 h1:s6PsZ1+bev294IWdZRlV7mnOwI1+UzFcldVW/BqhQzI=
@ -594,7 +582,6 @@ go.opentelemetry.io/otel/trace v1.32.0 h1:WIC9mYrXf8TmY/EXuULKc8hR17vE+Hjv2cssQD
go.opentelemetry.io/otel/trace v1.32.0/go.mod h1:+i4rkvCraA+tG6AzwloGaCtkx53Fa+L+V8e9a7YvhT8=
go.opentelemetry.io/proto/otlp v1.4.0 h1:TA9WRvW6zMwP+Ssb6fLoUIuirti1gGbP28GcKG1jgeg=
go.opentelemetry.io/proto/otlp v1.4.0/go.mod h1:PPBWZIP98o2ElSqI35IHfu7hIhSwvc5N38Jw8pXuGFY=
go.uber.org/atomic v1.9.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc=
go.uber.org/atomic v1.11.0 h1:ZvwS0R+56ePWxUNi+Atn9dWONBPp/AUETXlHW0DxSjE=
go.uber.org/atomic v1.11.0/go.mod h1:LUxbIzbOniOlMKjJjyPfpl4v+PKK2cNJn91OQbhoJI0=
go.uber.org/automaxprocs v1.6.0 h1:O3y2/QNTOdbF+e/dpXNNW7Rx2hZ4sTIPyybbxyNqTUs=
@ -616,10 +603,7 @@ golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8U
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/crypto v0.36.0 h1:AnAEvhDddvBdpY+uR+MyHmuZzzNqXSe/GvuDeob5L34=
golang.org/x/crypto v0.36.0/go.mod h1:Y4J0ReaxCR1IMaabaSMugxJES1EpwhBHhv2bDHklZvc=
golang.org/x/exp v0.0.0-20180321215751-8460e604b9de/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
golang.org/x/exp v0.0.0-20180807140117-3d87b88a115f/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
golang.org/x/exp v0.0.0-20190125153040-c74c464bbbf2/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
golang.org/x/exp v0.0.0-20190510132918-efd6b22b2522/go.mod h1:ZjyILWgesfNpC6sMxTJOJm9Kp84zZh5NQWvqDGG3Qr8=
golang.org/x/exp v0.0.0-20190829153037-c13cbed26979/go.mod h1:86+5VVa7VpoJ4kLfm080zCjGlMRFzhUhsZKEZO7MGek=
@ -631,7 +615,6 @@ golang.org/x/exp v0.0.0-20200207192155-f17229e696bd/go.mod h1:J/WKrq2StrnmMY6+EH
golang.org/x/exp v0.0.0-20200224162631-6cc2880d07d6/go.mod h1:3jZMyOhIsHpP37uCMkUooju7aAi5cS1Q23tOzKc+0MU=
golang.org/x/exp v0.0.0-20240119083558-1b970713d09a h1:Q8/wZp0KX97QFTc2ywcOE0YRjZPVIx+MXInMzdvQqcA=
golang.org/x/exp v0.0.0-20240119083558-1b970713d09a/go.mod h1:idGWGoKP1toJGkd5/ig9ZLuPcZBC3ewk7SzmH0uou08=
golang.org/x/image v0.0.0-20180708004352-c73c2afc3b81/go.mod h1:ux5Hcp/YLpHSI86hEcLt0YII63i6oz57MZXIpbrjZUs=
golang.org/x/image v0.0.0-20190227222117-0694c2d4d067/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js=
golang.org/x/image v0.0.0-20190802002840-cff245a6509b/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0=
golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
@ -774,10 +757,8 @@ golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxb
golang.org/x/time v0.0.0-20191024005414-555d28b269f0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/time v0.8.0 h1:9i3RxcPv3PZnitoVGMPDKZSq1xW1gK1Xy3ArNOGZfEg=
golang.org/x/time v0.8.0/go.mod h1:3BpzKBy/shNhVucY/MWOyx10tF3SFh9QdLuxbVysPQM=
golang.org/x/tools v0.0.0-20180525024113-a5b4c53f6e8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20190206041539-40960b6deb8e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY=
golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
golang.org/x/tools v0.0.0-20190312151545-0bb0c0a6e846/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
@ -826,12 +807,8 @@ golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8T
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
gonum.org/v1/gonum v0.0.0-20180816165407-929014505bf4/go.mod h1:Y+Yx5eoAFn32cQvJDxZx5Dpnq+c3wtXuadVZAcxbbBo=
gonum.org/v1/gonum v0.8.2/go.mod h1:oe/vMfY3deqTw+1EZJhuvEW2iwGF1bW9wwu7XCu0+v0=
gonum.org/v1/gonum v0.11.0 h1:f1IJhK4Km5tBJmaiJXtk/PkL4cdVX6J+tGiM187uT5E=
gonum.org/v1/gonum v0.11.0/go.mod h1:fSG4YDCxxUZQJ7rKsQrj0gMOg00Il0Z96/qMA4bVQhA=
gonum.org/v1/netlib v0.0.0-20190313105609-8cb42192e0e0/go.mod h1:wa6Ws7BG/ESfp6dHfk7C6KdzKA7wR7u/rKwOGE66zvw=
gonum.org/v1/plot v0.0.0-20190515093506-e2840ee46a6b/go.mod h1:Wt8AAjI+ypCyYX3nZBvf6cAIx93T+c/OS2HFAYskSZc=
google.golang.org/api v0.4.0/go.mod h1:8k5glujaEP+g9n7WNsDg8QP6cUVNI86fCNMcbazEtwE=
google.golang.org/api v0.7.0/go.mod h1:WtwebWUNSVBH/HAw79HIFXZNqEvBhG+Ra+ax0hx3E3M=
google.golang.org/api v0.8.0/go.mod h1:o4eAsZoiT+ibD93RtjEohWalFOjRDx6CVaqeizhEnKg=
@ -918,7 +895,6 @@ gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLks
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI=
@ -939,7 +915,6 @@ gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.0/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gorm.io/datatypes v1.2.0 h1:5YT+eokWdIxhJgWHdrb2zYUimyk0+TaFth+7a0ybzco=
@ -976,7 +951,6 @@ k8s.io/utils v0.0.0-20241210054802-24370beab758 h1:sdbE21q2nlQtFh65saZY+rRM6x6aJ
k8s.io/utils v0.0.0-20241210054802-24370beab758/go.mod h1:OLgZIPagt7ERELqWJFomSt595RzquPNLL48iOWgYOg0=
nullprogram.com/x/optparse v1.0.0/go.mod h1:KdyPE+Igbe0jQUrVfMqDMeJQIJZEuyV7pjYmp6pbG50=
rsc.io/binaryregexp v0.2.0/go.mod h1:qTv7/COck+e2FymRvadv62gMdZztPaShugOCi3I+8D8=
rsc.io/pdf v0.1.1/go.mod h1:n8OzWcQ6Sp37PL01nO98y4iUCRdTGarVfzxY20ICaU4=
rsc.io/quote/v3 v3.1.0/go.mod h1:yEA65RcK8LyAZtP9Kv3t0HmxON59tX3rD+tICJqUlj0=
rsc.io/sampler v1.3.0/go.mod h1:T1hPZKmBbMNahiBKFy5HrXp6adAjACjK9JXDnKaTXpA=
sigs.k8s.io/json v0.0.0-20241014173422-cfa47c3a1cc8 h1:gBQPwqORJ8d8/YNZWEjoZs7npUVDpVXUUOFfW6CgAqE=

View File

@ -73,5 +73,4 @@ type JcsMiddleware struct {
type Participant struct {
AdapterId string
CloudAdapterId string
ServiceToken string
}

View File

@ -17,7 +17,6 @@ package cron
import (
"github.com/zeromicro/go-zero/core/logx"
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/logic/schedule"
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/scheduler/service/utils/stat"
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/scheduler/service/utils/status"
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/svc"
)
@ -28,20 +27,20 @@ func AddCronGroup(svc *svc.ServiceContext) {
UpdateAiAdapterMaps(svc)
})
svc.Cron.AddFunc("30 * * * * ?", func() {
adapterList, err := svc.Scheduler.AiStorages.GetAdaptersByType("1")
if err != nil {
logx.Errorf(err.Error())
return
}
stat.UpdateClusterResources(svc, adapterList)
//svc.Cron.AddFunc("30 * * * * ?", func() {
// adapterList, err := svc.Scheduler.AiStorages.GetAdaptersByType("1")
// if err != nil {
// logx.Errorf(err.Error())
// return
// }
// stat.UpdateClusterResources(svc, adapterList)
//})
svc.Cron.AddFunc("@hourly", func() {
status.UpdateAutoStoppedInstance(svc)
})
svc.Cron.AddFunc("0 */5 * * * *", func() {
svc.Scheduler.AiService.Si.UpdateAutoStoppedInstance()
})
svc.Cron.AddFunc("0 */1 * * * *", func() {
svc.Cron.AddFunc("1 * * * * *", func() {
queryResource := schedule.NewQueryResourcesLogic(svc.HttpClient.R().Context(), svc)
trainResrc, err := queryResource.QueryResourcesByClusterId(nil, "Train")
if err != nil {
@ -61,7 +60,7 @@ func AddCronGroup(svc *svc.ServiceContext) {
})
//更新推理任务状态
svc.Cron.AddFunc("*/10 * * * * ?", func() {
svc.Cron.AddFunc("*/5 * * * * ?", func() {
tasks, err := svc.Scheduler.AiStorages.GetInferDeployInstanceListLastMonth()
if err != nil {
logx.Error(err)
@ -70,7 +69,7 @@ func AddCronGroup(svc *svc.ServiceContext) {
})
//更新训练任务状态
svc.Cron.AddFunc("0 */1 * * * *", func() {
svc.Cron.AddFunc("*/10 * * * * ?", func() {
tasks, err := svc.Scheduler.AiStorages.AllTaskLastMonth()
if err != nil {
logx.Error(err)
@ -78,7 +77,6 @@ func AddCronGroup(svc *svc.ServiceContext) {
go svc.Scheduler.AiService.St.UpdateTaskStatus(tasks)
go svc.Scheduler.AiService.St.UpdateAiTaskStatus(tasks)
})
svc.Cron.AddFunc("*/30 * * * * ?", func() {
status.UpdateCloudTaskStatus(svc)
})

View File

@ -1,48 +0,0 @@
package adapters
import (
"net/http"
"strings"
"github.com/zeromicro/go-zero/rest/httpx"
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/logic/adapters"
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/svc"
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/types"
"gitlink.org.cn/JointCloud/pcm-coordinator/pkg/repository/result"
)
func ClusterBootstrapHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
if !validateServiceToken(r, svcCtx) {
http.Error(w, "unauthorized", http.StatusUnauthorized)
return
}
var req types.ClusterBootstrapReq
if err := httpx.Parse(r, &req); err != nil {
result.ParamErrorResult(r, w, err)
return
}
l := adapters.NewClusterBootstrapLogic(r.Context(), svcCtx)
resp, err := l.ClusterBootstrap(&req)
result.HttpResult(r, w, resp, err)
}
}
func validateServiceToken(r *http.Request, svcCtx *svc.ServiceContext) bool {
expected := strings.TrimSpace(svcCtx.Config.Participant.ServiceToken)
if expected == "" {
return false
}
provided := strings.TrimSpace(r.Header.Get("X-Service-Token"))
if provided == expected {
return true
}
auth := strings.TrimSpace(r.Header.Get("Authorization"))
if auth == "" {
return false
}
return strings.TrimSpace(strings.TrimPrefix(auth, "Bearer")) == expected
}

View File

@ -25,10 +25,6 @@ func CreateAlgorithmHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return
}
// 获取token信息
token := r.Header.Get("Authorization")
req.Token = token
l := ai.NewCreateAlgorithmLogic(r.Context(), svcCtx)
resp, err := l.CreateAlgorithm(&req)
result.HttpResult(r, w, resp, err)

View File

@ -25,10 +25,6 @@ func TaskResultSyncHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return
}
// 获取token信息
token := r.Header.Get("Authorization")
req.Token = token
l := ai.NewTaskResultSyncLogic(r.Context(), svcCtx)
resp, err := l.TaskResultSync(&req)
result.HttpResult(r, w, resp, err)

View File

@ -1,24 +0,0 @@
package ai
import (
"github.com/zeromicro/go-zero/rest/httpx"
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/logic/ai"
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/svc"
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/types"
"gitlink.org.cn/JointCloud/pcm-coordinator/pkg/repository/result"
"net/http"
)
func TrainingTaskDetailsHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.TaskDetailReq
if err := httpx.Parse(r, &req); err != nil {
result.ParamErrorResult(r, w, err)
return
}
l := ai.NewTrainingTaskDetailsLogic(r.Context(), svcCtx)
resp, err := l.TaskDetails(&req)
result.HttpResult(r, w, resp, err)
}
}

View File

@ -2,7 +2,6 @@ package ai
import (
"gitlink.org.cn/JointCloud/pcm-coordinator/pkg/repository/result"
"gitlink.org.cn/JointCloud/pcm-coordinator/pkg/utils"
"net/http"
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/logic/ai"
@ -11,14 +10,8 @@ import (
func TrainingTaskStatHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
token := r.Header.Get("Authorization")
jccUserInfo, err := utils.ParseTokenWithoutVerify(token)
if err != nil {
result.ParamErrorResult(r, w, err)
return
}
l := ai.NewTrainingTaskStatLogic(r.Context(), svcCtx)
resp, err := l.TrainingTaskStat(jccUserInfo.UserName, jccUserInfo.Id)
resp, err := l.TrainingTaskStat()
result.HttpResult(r, w, resp, err)
}
}

View File

@ -1,11 +1,11 @@
package cloud
import (
"gitlink.org.cn/JointCloud/pcm-coordinator/pkg/utils"
"io"
"net/http"
"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"
"k8s.io/apimachinery/pkg/util/json"
@ -26,15 +26,12 @@ func ContainerCreateHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
result.ParamErrorResult(r, w, err)
return
}
// 获取token信息
token := r.Header.Get("Authorization")
jccUserInfo, err := utils.ParseTokenWithoutVerify(token)
if err != nil {
result.ParamErrorResult(r, w, err)
return
}
req.UserId = jccUserInfo.Id
req.UserName = jccUserInfo.UserName
// 获取用户信息
userStr := r.Header.Get("User")
user := &models.JccUserInfo{}
json.Unmarshal([]byte(userStr), user)
req.UserId = user.Id
req.UserName = user.UserName
l := cloud.NewContainerCreateLogic(r.Context(), svcCtx)
resp, err := l.ContainerCreate(&req)
result.HttpResult(r, w, resp, err)

View File

@ -1,9 +1,10 @@
package cloud
import (
"github.com/zeromicro/go-zero/rest/httpx"
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/logic/cloud"
"gitlink.org.cn/JointCloud/pcm-coordinator/pkg/repository/result"
"io"
"k8s.io/apimachinery/pkg/util/json"
"net/http"
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/svc"
@ -13,10 +14,17 @@ import (
func ContainerDeleteHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req container.DeleteParam
if err := httpx.Parse(r, &req); err != nil {
body, err := io.ReadAll(r.Body)
if err != nil {
result.ParamErrorResult(r, w, err)
return
}
if err = json.Unmarshal(body, &req); err != nil {
result.ParamErrorResult(r, w, err)
return
}
l := cloud.NewContainerDeleteLogic(r.Context(), svcCtx)
resp, err := l.ContainerDelete(&req)
result.HttpResult(r, w, resp, err)

View File

@ -1,12 +1,11 @@
package cloud
import (
"io"
"net/http"
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/logic/cloud"
"gitlink.org.cn/JointCloud/pcm-coordinator/pkg/repository/result"
"io"
"k8s.io/apimachinery/pkg/util/json"
"net/http"
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/svc"
container "gitlink.org.cn/JointCloud/pcm-coordinator/internal/types/cloud"

View File

@ -1,10 +1,10 @@
package cloud
import (
"github.com/zeromicro/go-zero/rest/httpx"
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/logic/cloud"
"gitlink.org.cn/JointCloud/pcm-coordinator/pkg/repository/result"
"io"
"k8s.io/apimachinery/pkg/util/json"
"net/http"
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/svc"
@ -14,10 +14,17 @@ import (
func ContainerLogHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req container.LogParam
if err := httpx.Parse(r, &req); err != nil {
body, err := io.ReadAll(r.Body)
if err != nil {
result.ParamErrorResult(r, w, err)
return
}
if err = json.Unmarshal(body, &req); err != nil {
result.ParamErrorResult(r, w, err)
return
}
l := cloud.NewContainerLogLogic(r.Context(), svcCtx)
resp, err := l.ContainerLog(&req)
result.HttpResult(r, w, resp, err)

View File

@ -1,24 +1,24 @@
package cloud
import (
"net/http"
"github.com/zeromicro/go-zero/rest/httpx"
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/logic/cloud"
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/svc"
container "gitlink.org.cn/JointCloud/pcm-coordinator/internal/types/cloud"
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/types"
"gitlink.org.cn/JointCloud/pcm-coordinator/pkg/repository/result"
"net/http"
)
func ContainerImagesHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
func DeleteYamlHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req container.ImagesParam
var req types.ApplyReq
if err := httpx.Parse(r, &req); err != nil {
result.ParamErrorResult(r, w, err)
return
}
l := cloud.NewContainerImagesLogic(r.Context(), svcCtx)
resp, err := l.ContainerImages(&req)
l := cloud.NewDeleteYamlLogic(r.Context(), svcCtx)
resp, err := l.DeleteYaml(&req)
result.HttpResult(r, w, resp, err)
}
}

View File

@ -1,32 +0,0 @@
package cloud
import (
"net/http"
"github.com/zeromicro/go-zero/rest/httpx"
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/logic/cloud"
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/svc"
instance "gitlink.org.cn/JointCloud/pcm-coordinator/internal/types/cloud"
"gitlink.org.cn/JointCloud/pcm-coordinator/pkg/repository/result"
)
func InstanceImagesHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req instance.InstanceImagesParam
if err := httpx.Parse(r, &req); err != nil {
result.ParamErrorResult(r, w, err)
return
}
// 获取token信息
//token := r.Header.Get("Authorization")
//jccUserInfo, err := utils.ParseTokenWithoutVerify(token)
//if err != nil {
// result.ParamErrorResult(r, w, err)
// return
//}
//req.UserId = jccUserInfo.Id
l := cloud.NewInstanceImagesLogic(r.Context(), svcCtx)
resp, err := l.InstanceImages(&req)
result.HttpResult(r, w, resp, err)
}
}

View File

@ -1,40 +0,0 @@
package cloud
import (
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/logic/cloud"
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/svc"
container "gitlink.org.cn/JointCloud/pcm-coordinator/internal/types/cloud"
"gitlink.org.cn/JointCloud/pcm-coordinator/pkg/repository/result"
"gitlink.org.cn/JointCloud/pcm-coordinator/pkg/utils"
"io"
"k8s.io/apimachinery/pkg/util/json"
"net/http"
)
func InstanceCreateHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req container.CreateInstanceParam
body, err := io.ReadAll(r.Body)
if err != nil {
result.ParamErrorResult(r, w, err)
return
}
if err = json.Unmarshal(body, &req); err != nil {
result.ParamErrorResult(r, w, err)
return
}
// 获取token信息
token := r.Header.Get("Authorization")
jccUserInfo, err := utils.ParseTokenWithoutVerify(token)
if err != nil {
result.ParamErrorResult(r, w, err)
return
}
req.UserId = jccUserInfo.Id
req.Username = jccUserInfo.UserName
l := cloud.NewInstanceCreateLogic(r.Context(), svcCtx)
resp, err := l.InstanceCreate(&req)
result.HttpResult(r, w, resp, err)
}
}

View File

@ -1,32 +0,0 @@
package cloud
import (
"github.com/zeromicro/go-zero/rest/httpx"
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/logic/cloud"
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/svc"
instance "gitlink.org.cn/JointCloud/pcm-coordinator/internal/types/cloud"
"gitlink.org.cn/JointCloud/pcm-coordinator/pkg/repository/result"
"gitlink.org.cn/JointCloud/pcm-coordinator/pkg/utils"
"net/http"
)
func InstanceInfoHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req instance.InstanceInfoParam
if err := httpx.Parse(r, &req); err != nil {
result.ParamErrorResult(r, w, err)
return
}
// 获取token信息
token := r.Header.Get("Authorization")
jccUserInfo, err := utils.ParseTokenWithoutVerify(token)
if err != nil {
result.ParamErrorResult(r, w, err)
return
}
req.UserId = jccUserInfo.Id
l := cloud.NewInstanceInfoLogic(r.Context(), svcCtx)
resp, err := l.InstanceInfo(&req)
result.HttpResult(r, w, resp, err)
}
}

View File

@ -1,34 +0,0 @@
package cloud
import (
"net/http"
"github.com/zeromicro/go-zero/rest/httpx"
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/logic/cloud"
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/svc"
instance "gitlink.org.cn/JointCloud/pcm-coordinator/internal/types/cloud"
"gitlink.org.cn/JointCloud/pcm-coordinator/pkg/repository/result"
"gitlink.org.cn/JointCloud/pcm-coordinator/pkg/utils"
)
func InstanceListHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req instance.PageInstanceParam
if err := httpx.Parse(r, &req); err != nil {
result.ParamErrorResult(r, w, err)
return
}
// 获取token信息
token := r.Header.Get("Authorization")
jccUserInfo, err := utils.ParseTokenWithoutVerify(token)
if err != nil {
result.ParamErrorResult(r, w, err)
return
}
req.UserId = jccUserInfo.Id
req.UserName = jccUserInfo.UserName
l := cloud.NewInstanceListLogic(r.Context(), svcCtx)
resp, err := l.InstanceList(&req)
result.HttpResult(r, w, resp, err)
}
}

View File

@ -1,31 +0,0 @@
package cloud
import (
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/logic/cloud"
cloud2 "gitlink.org.cn/JointCloud/pcm-coordinator/internal/types/cloud"
"gitlink.org.cn/JointCloud/pcm-coordinator/pkg/repository/result"
"io"
"k8s.io/apimachinery/pkg/util/json"
"net/http"
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/svc"
)
func InstanceOperateHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req cloud2.OperateInstanceParam
body, err := io.ReadAll(r.Body)
if err != nil {
result.ParamErrorResult(r, w, err)
return
}
if err = json.Unmarshal(body, &req); err != nil {
result.ParamErrorResult(r, w, err)
return
}
l := cloud.NewInstanceOperateLogic(r.Context(), svcCtx)
resp, err := l.InstanceOperate(&req)
result.HttpResult(r, w, resp, err)
}
}

View File

@ -1,32 +0,0 @@
package cloud
import (
"github.com/zeromicro/go-zero/rest/httpx"
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/logic/cloud"
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/svc"
instance "gitlink.org.cn/JointCloud/pcm-coordinator/internal/types/cloud"
"gitlink.org.cn/JointCloud/pcm-coordinator/pkg/repository/result"
"gitlink.org.cn/JointCloud/pcm-coordinator/pkg/utils"
"net/http"
)
func InstanceTypesHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req instance.InstanceTypesParam
if err := httpx.Parse(r, &req); err != nil {
result.ParamErrorResult(r, w, err)
return
}
// 获取token信息
token := r.Header.Get("Authorization")
jccUserInfo, err := utils.ParseTokenWithoutVerify(token)
if err != nil {
result.ParamErrorResult(r, w, err)
return
}
req.UserId = jccUserInfo.Id
l := cloud.NewInstanceTypesLogic(r.Context(), svcCtx)
resp, err := l.InstanceTypes(&req)
result.HttpResult(r, w, resp, err)
}
}

View File

@ -1,33 +0,0 @@
package cloud
import (
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/logic/cloud"
"io"
"net/http"
"gitlink.org.cn/JointCloud/pcm-coordinator/pkg/repository/result"
"k8s.io/apimachinery/pkg/util/json"
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/svc"
cloud2 "gitlink.org.cn/JointCloud/pcm-coordinator/internal/types/cloud"
)
func NamespaceCreateHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req cloud2.CreateNamespaceParam
body, err := io.ReadAll(r.Body)
if err != nil {
result.ParamErrorResult(r, w, err)
return
}
if err = json.Unmarshal(body, &req); err != nil {
result.ParamErrorResult(r, w, err)
return
}
l := cloud.NewNamespaceCreateLogic(r.Context(), svcCtx)
resp, err := l.NamespaceCreate(&req)
result.HttpResult(r, w, resp, err)
}
}

View File

@ -2,24 +2,23 @@ package cloud
import (
"github.com/zeromicro/go-zero/rest/httpx"
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/logic/cloud"
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/svc"
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/types"
"gitlink.org.cn/JointCloud/pcm-coordinator/pkg/repository/result"
"net/http"
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/svc"
container "gitlink.org.cn/JointCloud/pcm-coordinator/internal/types/cloud"
)
func ContainerMetricsHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
func PodLogsHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req container.MetricsParam
var req types.PodLogsReq
if err := httpx.Parse(r, &req); err != nil {
result.ParamErrorResult(r, w, err)
return
}
l := cloud.NewContainerMetricsLogic(r.Context(), svcCtx)
resp, err := l.ContainerMetrics(&req)
l := cloud.NewPodLogsLogic(r.Context(), svcCtx, w)
resp, err := l.PodLogs(&req, w)
result.HttpResult(r, w, resp, err)
}
}

View File

@ -1,25 +1,24 @@
package core
import (
"net/http"
"github.com/zeromicro/go-zero/rest/httpx"
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/logic/core"
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/svc"
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/types"
"gitlink.org.cn/JointCloud/pcm-coordinator/pkg/repository/result"
"net/http"
)
func EditAchievementHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
func CommitTaskHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.EditAchievementReq
var req types.CommitTaskReq
if err := httpx.Parse(r, &req); err != nil {
result.ParamErrorResult(r, w, err)
return
}
l := core.NewEditAchievementLogic(r.Context(), svcCtx)
resp, err := l.EditAchievement(&req)
result.HttpResult(r, w, resp, err)
l := core.NewCommitTaskLogic(r.Context(), svcCtx)
err := l.CommitTask(&req)
result.HttpResult(r, w, nil, err)
}
}

View File

@ -1,25 +0,0 @@
package core
import (
"net/http"
"github.com/zeromicro/go-zero/rest/httpx"
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/logic/core"
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/svc"
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/types"
"gitlink.org.cn/JointCloud/pcm-coordinator/pkg/repository/result"
)
func ListAchievementHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.ListAchievementReq
if err := httpx.Parse(r, &req); err != nil {
result.ParamErrorResult(r, w, err)
return
}
l := core.NewListAchievementLogic(r.Context(), svcCtx)
resp, err := l.ListAchievement(&req)
result.HttpResult(r, w, resp, err)
}
}

View File

@ -1,34 +0,0 @@
package core
import (
"net/http"
"github.com/zeromicro/go-zero/rest/httpx"
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/logic/core"
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/svc"
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/types"
"gitlink.org.cn/JointCloud/pcm-coordinator/pkg/repository/result"
"gitlink.org.cn/JointCloud/pcm-coordinator/pkg/utils"
)
func PublishAchievementHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.PublishAchievementReq
if err := httpx.Parse(r, &req); err != nil {
result.ParamErrorResult(r, w, err)
return
}
// 获取token信息
token := r.Header.Get("Authorization")
jccUserInfo, err := utils.ParseTokenWithoutVerify(token)
if err != nil {
result.ParamErrorResult(r, w, err)
return
}
req.UserId = jccUserInfo.Id
req.UserName = jccUserInfo.UserName
l := core.NewPublishAchievementLogic(r.Context(), svcCtx)
resp, err := l.PublishAchievement(&req)
result.HttpResult(r, w, resp, err)
}
}

View File

@ -1,25 +0,0 @@
package core
import (
"net/http"
"github.com/zeromicro/go-zero/rest/httpx"
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/logic/core"
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/svc"
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/types"
"gitlink.org.cn/JointCloud/pcm-coordinator/pkg/repository/result"
)
func QueryAchievementHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.QueryAchievementReq
if err := httpx.Parse(r, &req); err != nil {
result.ParamErrorResult(r, w, err)
return
}
l := core.NewQueryAchievementLogic(r.Context(), svcCtx)
resp, err := l.QueryAchievement(&req)
result.HttpResult(r, w, resp, err)
}
}

View File

@ -1,25 +0,0 @@
package core
import (
"net/http"
"github.com/zeromicro/go-zero/rest/httpx"
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/logic/core"
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/svc"
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/types"
"gitlink.org.cn/JointCloud/pcm-coordinator/pkg/repository/result"
)
func RevokeAchievementHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.RevokeAchievementReq
if err := httpx.Parse(r, &req); err != nil {
result.ParamErrorResult(r, w, err)
return
}
l := core.NewRevokeAchievementLogic(r.Context(), svcCtx)
resp, err := l.RevokeAchievement(&req)
result.HttpResult(r, w, resp, err)
}
}

View File

@ -1,25 +0,0 @@
package core
import (
"net/http"
"github.com/zeromicro/go-zero/rest/httpx"
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/logic/core"
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/svc"
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/types"
"gitlink.org.cn/JointCloud/pcm-coordinator/pkg/repository/result"
)
func TypeClusterResourceHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.TypeResourceSpecReq
if err := httpx.Parse(r, &req); err != nil {
result.ParamErrorResult(r, w, err)
return
}
l := core.NewTypeClusterResourceLogic(r.Context(), svcCtx)
resp, err := l.TypeClusterResource(&req)
result.HttpResult(r, w, resp, err)
}
}

View File

@ -20,9 +20,6 @@ func CommitHpcTaskHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
result.ParamErrorResult(r, w, err)
return
}
if req.Parameters == nil {
req.Parameters = make(map[string]string)
}
// 获取ip信息
ip := utils.GetClientIP(r)
req.Parameters["UserIp"] = ip
@ -37,8 +34,6 @@ func CommitHpcTaskHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
}
req.Parameters[constants.UserId] = strconv.FormatInt(jccUserInfo.Id, 10)
req.Parameters[constants.UserName] = jccUserInfo.UserName
jcsUserID := r.Header.Get("JCS-UserID")
req.JcsUserID = jcsUserID
l := hpc.NewCommitHpcTaskLogic(r.Context(), svcCtx)
resp, err := l.CommitHpcTask(&req)

View File

@ -1,24 +0,0 @@
package inference
import (
"github.com/zeromicro/go-zero/rest/httpx"
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/logic/inference"
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/svc"
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/types"
"gitlink.org.cn/JointCloud/pcm-coordinator/pkg/repository/result"
"net/http"
)
func InferenceTaskLogHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.InferenceTaskLogReq
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
return
}
l := inference.NewInferenceTaskLogLogic(r.Context(), svcCtx)
resp, err := l.InferenceTaskLog(&req)
result.HttpResult(r, w, resp, err)
}
}

View File

@ -26,7 +26,6 @@ func CreateInferenceTaskHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return
}
req.UserId = jccUserInfo.Id
req.Token = token
l := inference.NewCreateInferenceTaskLogic(r.Context(), svcCtx)
resp, err := l.CreateInferenceTask(&req)
result.HttpResult(r, w, resp, err)

View File

@ -2,7 +2,6 @@ package inference
import (
"gitlink.org.cn/JointCloud/pcm-coordinator/pkg/repository/result"
"gitlink.org.cn/JointCloud/pcm-coordinator/pkg/utils"
"net/http"
"github.com/zeromicro/go-zero/rest/httpx"
@ -19,14 +18,8 @@ func DeployInstanceStatHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return
}
token := r.Header.Get("Authorization")
jccUserInfo, err := utils.ParseTokenWithoutVerify(token)
if err != nil {
result.ParamErrorResult(r, w, err)
return
}
l := inference.NewDeployInstanceStatLogic(r.Context(), svcCtx)
resp, err := l.DeployInstanceStat(&req, jccUserInfo.UserName, jccUserInfo.Id)
resp, err := l.DeployInstanceStat(&req)
result.HttpResult(r, w, resp, err)
}

View File

@ -6,7 +6,6 @@ import (
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/svc"
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/types"
"gitlink.org.cn/JointCloud/pcm-coordinator/pkg/repository/result"
"gitlink.org.cn/JointCloud/pcm-coordinator/pkg/utils"
"net/http"
)
@ -18,14 +17,8 @@ func InferenceTaskStatHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return
}
token := r.Header.Get("Authorization")
jccUserInfo, err := utils.ParseTokenWithoutVerify(token)
if err != nil {
result.ParamErrorResult(r, w, err)
return
}
l := inference.NewInferenceTaskStatLogic(r.Context(), svcCtx)
resp, err := l.InferenceTaskStat(&req, jccUserInfo.UserName, jccUserInfo.Id)
resp, err := l.InferenceTaskStat(&req)
result.HttpResult(r, w, resp, err)
}

View File

@ -13,6 +13,7 @@ import (
inference "gitlink.org.cn/JointCloud/pcm-coordinator/internal/handler/inference"
monitoring "gitlink.org.cn/JointCloud/pcm-coordinator/internal/handler/monitoring"
schedule "gitlink.org.cn/JointCloud/pcm-coordinator/internal/handler/schedule"
storage "gitlink.org.cn/JointCloud/pcm-coordinator/internal/handler/storage"
storelink "gitlink.org.cn/JointCloud/pcm-coordinator/internal/handler/storelink"
vm "gitlink.org.cn/JointCloud/pcm-coordinator/internal/handler/vm"
xjlab "gitlink.org.cn/JointCloud/pcm-coordinator/internal/handler/xjlab"
@ -98,17 +99,6 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
rest.WithPrefix("/pcm/v1"),
)
server.AddRoutes(
[]rest.Route{
{
Method: http.MethodGet,
Path: "/participant/cluster/bootstrap",
Handler: adapters.ClusterBootstrapHandler(serverCtx),
},
},
rest.WithPrefix("/internal/v1"),
)
server.AddRoutes(
[]rest.Route{
{
@ -231,12 +221,6 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
Path: "/ai/chat",
Handler: ai.ChatHandler(serverCtx),
},
{
// 训练任务详情
Method: http.MethodGet,
Path: "/ai/task/details",
Handler: ai.TrainingTaskDetailsHandler(serverCtx),
},
{
// 创建数据集
Method: http.MethodPost,
@ -352,7 +336,12 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
Path: "/cloud/model/bind",
Handler: cloud.BindModelHandler(serverCtx),
},
{
// yaml删除
Method: http.MethodGet,
Path: "/cloud/DeleteYaml",
Handler: cloud.DeleteYamlHandler(serverCtx),
},
{
// 控制器监控
Method: http.MethodGet,
@ -365,7 +354,11 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
Path: "/cloud/deleteCluster",
Handler: cloud.DeleteClusterHandler(serverCtx),
},
{
Method: http.MethodPost,
Path: "/cloud/pod/logs",
Handler: cloud.PodLogsHandler(serverCtx),
},
{
Method: http.MethodGet,
Path: "/cloud/pods/list",
@ -404,7 +397,7 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
{
// 删除容器
Method: http.MethodDelete,
Path: "/cloud/container/delete/:id",
Path: "/cloud/container/delete",
Handler: cloud.ContainerDeleteHandler(serverCtx),
},
{
@ -416,63 +409,9 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
{
// 获取容器
Method: http.MethodGet,
Path: "/cloud/container/images",
Handler: cloud.ContainerImagesHandler(serverCtx),
},
{
// 获取容器日志
Method: http.MethodGet,
Path: "/cloud/container/log/:id",
Path: "/cloud/container/log",
Handler: cloud.ContainerLogHandler(serverCtx),
},
{
// 获取容器监控数据
Method: http.MethodGet,
Path: "/cloud/container/metrics/:id",
Handler: cloud.ContainerMetricsHandler(serverCtx),
},
{
// 创建命名空间
Method: http.MethodPost,
Path: "/cloud/namespace/create",
Handler: cloud.NamespaceCreateHandler(serverCtx),
},
{
// 查询实例
Method: http.MethodGet,
Path: "/cloud/instance/types",
Handler: cloud.InstanceTypesHandler(serverCtx),
},
{
// 查询实例
Method: http.MethodGet,
Path: "/cloud/instance/images",
Handler: cloud.InstanceImagesHandler(serverCtx),
},
{
// 查询实例
Method: http.MethodGet,
Path: "/cloud/instance/get/:instanceId",
Handler: cloud.InstanceInfoHandler(serverCtx),
},
{
// 创建实例
Method: http.MethodPost,
Path: "/cloud/instance/create",
Handler: cloud.InstanceCreateHandler(serverCtx),
},
{
// 分页查询实例列表
Method: http.MethodGet,
Path: "/cloud/instance/page",
Handler: cloud.InstanceListHandler(serverCtx),
},
{
// 删除容器
Method: http.MethodPut,
Path: "/cloud/instance/operate",
Handler: cloud.InstanceOperateHandler(serverCtx),
},
},
rest.WithPrefix("/pcm/v1"),
)
@ -527,12 +466,6 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
Path: "/core/ai/resourceSpec/sync",
Handler: core.SyncResourceSpecHandler(serverCtx),
},
{
// 获取通过type过滤资源规格获取对应集群
Method: http.MethodGet,
Path: "/core/resourceSpec/typeCluster",
Handler: core.TypeClusterResourceHandler(serverCtx),
},
{
// 获取节点资产
Method: http.MethodGet,
@ -551,6 +484,12 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
Path: "/core/centerResources",
Handler: core.CenterResourcesHandler(serverCtx),
},
{
// 提交任务
Method: http.MethodPost,
Path: "/core/commitTask",
Handler: core.CommitTaskHandler(serverCtx),
},
{
// 提交虚拟机任务
Method: http.MethodPost,
@ -755,36 +694,6 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
Path: "/core/taskList",
Handler: core.TaskListHandler(serverCtx),
},
{
// 成果发布
Method: http.MethodPost,
Path: "/core/publishAchievement",
Handler: core.PublishAchievementHandler(serverCtx),
},
{
// 成果查看
Method: http.MethodGet,
Path: "/core/queryAchievement/:taskId",
Handler: core.QueryAchievementHandler(serverCtx),
},
{
// 成果编辑
Method: http.MethodPut,
Path: "/core/editAchievement",
Handler: core.EditAchievementHandler(serverCtx),
},
{
// 成果撤销
Method: http.MethodPut,
Path: "/core/revokeAchievement/:taskId",
Handler: core.RevokeAchievementHandler(serverCtx),
},
{
// 成果查看
Method: http.MethodGet,
Path: "/core/listAchievement",
Handler: core.ListAchievementHandler(serverCtx),
},
},
rest.WithPrefix("/pcm/v1"),
)
@ -1019,11 +928,6 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
Path: "/inference/text",
Handler: inference.TextToTextInferenceHandler(serverCtx),
},
{
Method: http.MethodGet,
Path: "/inference/taskLog/:taskId",
Handler: inference.InferenceTaskLogHandler(serverCtx),
},
},
rest.WithPrefix("/pcm/v1"),
)
@ -1175,6 +1079,24 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
rest.WithPrefix("/pcm/v1"),
)
server.AddRoutes(
[]rest.Route{
{
// 日常算力查询
Method: http.MethodGet,
Path: "/storage/dailyPowerScreen",
Handler: storage.DailyPowerScreenHandler(serverCtx),
},
{
// 算力中心算力情况
Method: http.MethodGet,
Path: "/storage/perCenterComputerPowers",
Handler: storage.PerCenterComputerPowersHandler(serverCtx),
},
},
rest.WithPrefix("/pcm/v1"),
)
server.AddRoutes(
[]rest.Route{
{
@ -1830,53 +1752,11 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
Handler: xjlab.TaskResourceUsageHandler(serverCtx),
},
{
//任务状态统计
//任务状态监控
Method: http.MethodGet,
Path: "/xjlab/taskStatusStatistics",
Handler: xjlab.TaskStatusStatisticsHandler(serverCtx),
},
{
//单任务失败分析
Method: http.MethodGet,
Path: "/xjlab/task/failureAnalyze",
Handler: xjlab.TaskFailureAnalyzeHandler(serverCtx),
},
{
//大屏-融合资源占比-计算类型占比
Method: http.MethodGet,
Path: "/xjlab/overview/computeTypeRatio",
Handler: xjlab.ComputeTypeRatioHandler(serverCtx),
},
{
//大屏-超算应用执行情况
Method: http.MethodGet,
Path: "/xjlab/overview/countHpcAppExec",
Handler: xjlab.CountHpcAppExecHandler(serverCtx),
},
{
//大屏-统计任务执行状态
Method: http.MethodGet,
Path: "/xjlab/overview/countTaskStatus",
Handler: xjlab.CountTaskStatusHandler(serverCtx),
},
{
//大屏-任务执行列表
Method: http.MethodGet,
Path: "/xjlab/overview/listTask",
Handler: xjlab.ListTaskHandler(serverCtx),
},
{
//大屏-计算域信息
Method: http.MethodGet,
Path: "/xjlab/overview/computeDomainInfo",
Handler: xjlab.ComputeDomainInfoHandler(serverCtx),
},
{
//大屏-算力清单
Method: http.MethodGet,
Path: "/xjlab/overview/computerPowerList",
Handler: xjlab.ComputerPowerListHandler(serverCtx),
},
},
rest.WithPrefix("/pcm/v1"),
)

View File

@ -0,0 +1,17 @@
package storage
import (
"gitlink.org.cn/JointCloud/pcm-coordinator/pkg/repository/result"
"net/http"
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/logic/storage"
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/svc"
)
func DailyPowerScreenHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
l := storage.NewDailyPowerScreenLogic(r.Context(), svcCtx)
resp, err := l.DailyPowerScreen()
result.HttpResult(r, w, resp, err)
}
}

View File

@ -0,0 +1,17 @@
package storage
import (
"gitlink.org.cn/JointCloud/pcm-coordinator/pkg/repository/result"
"net/http"
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/logic/storage"
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/svc"
)
func PerCenterComputerPowersHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
l := storage.NewPerCenterComputerPowersLogic(r.Context(), svcCtx)
resp, err := l.PerCenterComputerPowers()
result.HttpResult(r, w, resp, err)
}
}

View File

@ -1,95 +0,0 @@
package xjlab
import (
"net/http"
"github.com/zeromicro/go-zero/rest/httpx"
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/logic/xjlab"
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/svc"
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/types"
"gitlink.org.cn/JointCloud/pcm-coordinator/pkg/repository/result"
)
func ComputeTypeRatioHandler(ctx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.XJLABCommonReq
if err := httpx.Parse(r, &req); err != nil {
result.ParamErrorResult(r, w, err)
return
}
l := xjlab.NewComputeTypeRatioLogic(r.Context(), ctx)
resp, err := l.ComputeTypeRatio(&req)
result.HttpResult(r, w, resp, err)
}
}
func CountHpcAppExecHandler(ctx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.XJLABCommonReq
if err := httpx.Parse(r, &req); err != nil {
result.ParamErrorResult(r, w, err)
return
}
l := xjlab.NewCountHpcAppExecLogic(r.Context(), ctx)
resp, err := l.CountHpcAppExec(&req)
result.HttpResult(r, w, resp, err)
}
}
func CountTaskStatusHandler(ctx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.XJLABCommonReq
if err := httpx.Parse(r, &req); err != nil {
result.ParamErrorResult(r, w, err)
return
}
l := xjlab.NewCountTaskStatusLogic(r.Context(), ctx)
resp, err := l.CountTaskStatus(&req)
result.HttpResult(r, w, resp, err)
}
}
func ListTaskHandler(ctx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.XJLABCommonReq
if err := httpx.Parse(r, &req); err != nil {
result.ParamErrorResult(r, w, err)
return
}
l := xjlab.NewListTaskLogic(r.Context(), ctx)
resp, err := l.ListTask(&req)
result.HttpResult(r, w, resp, err)
}
}
func ComputeDomainInfoHandler(ctx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.XJLABCommonReq
if err := httpx.Parse(r, &req); err != nil {
result.ParamErrorResult(r, w, err)
return
}
l := xjlab.NewComputeDomainInfoLogic(r.Context(), ctx)
resp, err := l.ComputeDomainInfo(&req)
result.HttpResult(r, w, resp, err)
}
}
func ComputerPowerListHandler(ctx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.XJLABCommonReq
if err := httpx.Parse(r, &req); err != nil {
result.ParamErrorResult(r, w, err)
return
}
l := xjlab.NewComputerPowerListLogic(r.Context(), ctx)
resp, err := l.ComputerPowerList(&req)
result.HttpResult(r, w, resp, err)
}
}

View File

@ -62,17 +62,3 @@ func TaskStatusStatisticsHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
result.HttpResult(r, w, resp, err)
}
}
func TaskFailureAnalyzeHandler(ctx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.FId
if err := httpx.Parse(r, &req); err != nil {
result.ParamErrorResult(r, w, err)
return
}
l := xjlab.NewTaskFailureAnalyzeLogic(r.Context(), ctx)
resp, err := l.TaskFailureAnalyze(&req)
result.HttpResult(r, w, resp, err)
}
}

View File

@ -1,50 +0,0 @@
package adapters
import (
"context"
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/svc"
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/types"
"github.com/zeromicro/go-zero/core/logx"
)
type ClusterBootstrapLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewClusterBootstrapLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ClusterBootstrapLogic {
return &ClusterBootstrapLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *ClusterBootstrapLogic) ClusterBootstrap(req *types.ClusterBootstrapReq) (resp *types.PageResult, err error) {
resp = &types.PageResult{}
list := make([]types.ClusterInfo, 0)
db := l.svcCtx.DbEngin.Model(&types.AdapterInfo{}).Table("t_cluster").
Joins("left join t_adapter on t_adapter.id = t_cluster.adapter_id").
Where("t_cluster.deleted_at is null")
if req.AdapterId != "" {
db = db.Where("t_cluster.adapter_id = ?", req.AdapterId)
}
if req.Type != "" {
db = db.Where("t_adapter.type = ?", req.Type)
}
if err = db.Select("t_cluster.*").Order("t_cluster.create_time desc").Scan(&list).Error; err != nil {
return nil, err
}
resp.List = list
resp.Total = int64(len(list))
resp.PageNum = 1
resp.PageSize = len(list)
return resp, nil
}

View File

@ -2,7 +2,6 @@ package adapters
import (
"context"
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/logic/security"
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/svc"
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/types"
@ -75,7 +74,6 @@ func (l *ClusterListLogic) ClusterList(req *types.ClusterReq) (resp *types.PageR
if err != nil {
return resp, err
}
security.SanitizeClusterSecretList(list)
resp.List = list
resp.PageSize = req.PageSize
resp.PageNum = req.PageNum

View File

@ -125,6 +125,8 @@ func GeoMap(address string) (string, error) {
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

View File

@ -2,9 +2,6 @@ package adapters
import (
"context"
"strconv"
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/logic/security"
"gitlink.org.cn/JointCloud/pcm-coordinator/pkg/utils"
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/svc"
@ -61,7 +58,7 @@ func (l *GetAdapterRelationLogic) GetAdapterRelation(req *types.AdapterRelationQ
cr = &types.ClusterRelationInfo{}
utils.Convert(&v, &cr)
cr.CId = c.Id
cr.CAdapterId = strconv.FormatInt(c.AdapterId, 10)
cr.CAdapterId = string(c.AdapterId)
cr.CName = c.Name
cr.CNickname = c.Nickname
cr.CDescription = c.Description
@ -81,11 +78,9 @@ func (l *GetAdapterRelationLogic) GetAdapterRelation(req *types.AdapterRelationQ
cr.CRegionDict = c.RegionDict
cr.CProducerDict = c.ProducerDict
cr.CCreateTime = c.CreateTime
security.SanitizeClusterRelationSecret(cr)
rlist = append(rlist, cr)
}
if len(clusters) == 0 {
security.SanitizeClusterRelationSecret(cr)
rlist = append(rlist, cr)
}
}

View File

@ -32,9 +32,6 @@ func (l *GetClusterBaseInfoLogic) GetClusterBaseInfo(req *types.ClusterReq) (res
db = db.Joins("left join t_adapter on t_adapter.id = t_cluster.adapter_id").
Where("t_cluster.deleted_at is null")
if req.Id != "" {
db = db.Where("t_cluster.id = ?", req.Id)
}
if req.Name != "" {
db = db.Where("t_cluster.name LIKE ?", "%"+req.Name+"%")
}

View File

@ -3,7 +3,6 @@ package adapters
import (
"context"
"github.com/pkg/errors"
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/logic/security"
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/svc"
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/types"
@ -32,7 +31,6 @@ func (l *GetClusterLogic) GetCluster(req *types.FId) (resp *types.ClusterInfo, e
logx.Errorf("err %v", db.Error.Error())
return nil, errors.New("Adapter does not exist")
}
security.SanitizeClusterSecret(resp)
return
}

View File

@ -39,25 +39,13 @@ func NewCreateAlgorithmLogic(ctx context.Context, svcCtx *svc.ServiceContext) *C
}
func (l *CreateAlgorithmLogic) CreateAlgorithm(req *algorithm.CreateAlgorithmReq) (resp interface{}, err error) {
cinfo, err := l.svcCtx.Scheduler.AiStorages.GetClusterByIdAndAdapterId(req.ClusterId, l.svcCtx.Config.Participant.AdapterId)
if err != nil {
return nil, err
}
algorithmParam, err := l.svcCtx.Scheduler.AiService.Cvt.ConvertToCreateAlgorithmParam(req.Param, cinfo.Driver)
if err != nil {
return nil, err
}
param := &participant.CreateParam{
Name: req.Name,
Desc: req.Desc,
CType: cinfo.Driver,
Src: req.Src,
Param: algorithmParam,
Param: req.Param,
}
create, err := l.svcCtx.Scheduler.AiService.Ai.AlgorithmCreateById(req.Token, req.ClusterId, param)
create, err := l.svcCtx.Ai.AlgorithmCreateById(req.ClusterId, param)
if err != nil {
return nil, err
}

View File

@ -39,24 +39,13 @@ func NewCreateDataSetLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Cre
}
func (l *CreateDataSetLogic) CreateDataSet(req *dataset.CreateDatasetReq) (resp interface{}, err error) {
cinfo, err := l.svcCtx.Scheduler.AiStorages.GetClusterByIdAndAdapterId(req.ClusterId, l.svcCtx.Config.Participant.AdapterId)
if err != nil {
return nil, err
}
dtsParam, err := l.svcCtx.Scheduler.AiService.Cvt.ConvertToCreateDatasetParam(req.Param, cinfo.Driver)
if err != nil {
return nil, err
}
param := &participant.CreateParam{
Name: req.Name,
Desc: req.Desc,
CType: cinfo.Driver,
Src: req.Src,
Param: dtsParam,
Param: req.Param,
}
create, err := l.svcCtx.Scheduler.AiService.Ai.DatasetCreateById(req.ClusterId, param)
create, err := l.svcCtx.Ai.DatasetCreateById(req.ClusterId, param)
if err != nil {
return nil, err
}

View File

@ -39,24 +39,13 @@ func NewCreateModelLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Creat
}
func (l *CreateModelLogic) CreateModel(req *model.CreateModelReq) (resp interface{}, err error) {
cinfo, err := l.svcCtx.Scheduler.AiStorages.GetClusterByIdAndAdapterId(req.ClusterId, l.svcCtx.Config.Participant.AdapterId)
if err != nil {
return nil, err
}
modelParam, err := l.svcCtx.Scheduler.AiService.Cvt.ConvertToCreateModelParam(req.Param, cinfo.Driver)
if err != nil {
return nil, err
}
param := &participant.CreateParam{
Name: req.Name,
Desc: req.Desc,
CType: cinfo.Driver,
Src: req.Src,
Param: modelParam,
Param: req.Param,
}
create, err := l.svcCtx.Scheduler.AiService.Ai.ModelCreateById(req.ClusterId, param)
create, err := l.svcCtx.Ai.ModelCreateById(req.ClusterId, param)
if err != nil {
return nil, err
}

View File

@ -37,7 +37,7 @@ func NewListAlgorithmsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Li
}
func (l *ListAlgorithmsLogic) ListAlgorithms(req *types.ListAlgorithmsReq) (resp interface{}, err error) {
list, err := l.svcCtx.Scheduler.AiService.Ai.AlgorithmById(req.ProjectId)
list, err := l.svcCtx.Ai.AlgorithmById(req.ProjectId)
if err != nil {
return nil, err
}

View File

@ -39,16 +39,12 @@ func NewTaskResultSyncLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Ta
}
func (l *TaskResultSyncLogic) TaskResultSync(req *sync.ResultSyncReq) (resp interface{}, err error) {
cinfo, err := l.svcCtx.Scheduler.AiStorages.GetClusterByIdAndAdapterId(req.ClusterId, l.svcCtx.Config.Participant.AdapterId)
if err != nil {
return nil, err
}
param := &participant.TaskResultSyncParam{
CType: cinfo.Driver,
Src: req.Src,
Param: req.Param,
}
rs, err := l.svcCtx.Scheduler.AiService.Ai.TaskResultSync(req.Token, req.ClusterId, param)
rs, err := l.svcCtx.Ai.TaskResultSync(req.ClusterId, param)
if err != nil {
return nil, err
}

View File

@ -1,72 +0,0 @@
package ai
import (
"context"
"github.com/pkg/errors"
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/svc"
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/types"
"gitlink.org.cn/JointCloud/pcm-coordinator/pkg/models"
"gitlink.org.cn/JointCloud/pcm-coordinator/pkg/utils"
"gorm.io/gorm"
"strings"
"github.com/zeromicro/go-zero/core/logx"
)
type TrainingTaskDetailsLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewTrainingTaskDetailsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *TrainingTaskDetailsLogic {
return &TrainingTaskDetailsLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *TrainingTaskDetailsLogic) TaskDetails(req *types.TaskDetailReq) (resp *types.TaskDetailsResp, err error) {
resp = &types.TaskDetailsResp{}
task := &models.Task{}
if errors.Is(l.svcCtx.DbEngin.Where("id", req.TaskId).First(&task).Error, gorm.ErrRecordNotFound) {
return nil, errors.New("记录不存在")
}
clusterIds := make([]string, 0)
var cList []*types.ClusterInfo
var subList []*types.SubTaskInfo
switch task.AdapterTypeDict {
case "0":
l.svcCtx.DbEngin.Table("task_cloud").Where("task_id", task.Id).Scan(&subList)
if len(subList) <= 0 {
l.svcCtx.DbEngin.Table("task_vm").Where("task_id", task.Id).Find(&subList)
}
case "1":
l.svcCtx.DbEngin.Table("task_ai").Where("task_id", task.Id).Scan(&subList)
if len(subList) <= 0 {
l.svcCtx.DbEngin.Table("task_ai_asynchronous").Where("task_id", task.Id).Scan(&subList)
}
case "2":
l.svcCtx.DbEngin.Table("task_hpc").Where("task_id", task.Id).Scan(&subList)
for _, hpc := range subList {
var cluster types.ClusterInfo
tx := l.svcCtx.DbEngin.Table("t_cluster").Where("id = ?", hpc.ClusterId).Scan(&cluster)
if tx.Error != nil {
}
hpc.WorkDir = strings.TrimPrefix(hpc.WorkDir, cluster.WorkDir)
}
}
for _, sub := range subList {
clusterIds = append(clusterIds, sub.ClusterId)
}
err = l.svcCtx.DbEngin.Table("t_cluster").Select("id,adapter_id,name,nickname,description,create_time").Where("storage_schedule = 1 and id in ?", clusterIds).Scan(&cList).Error
if err != nil {
return resp, err
}
utils.Convert(&task, &resp)
resp.ClusterInfos = cList
resp.SubTaskInfos = subList
return
}

View File

@ -22,34 +22,20 @@ func NewTrainingTaskStatLogic(ctx context.Context, svcCtx *svc.ServiceContext) *
}
}
func (l *TrainingTaskStatLogic) TrainingTaskStat(userName string, userId int64) (resp *types.TrainingTaskStatResp, err error) {
func (l *TrainingTaskStatLogic) TrainingTaskStat() (resp *types.TrainingTaskStatResp, err error) {
resp = &types.TrainingTaskStatResp{}
if userName != "" && userName != "admin" {
total, err := l.svcCtx.Scheduler.AiStorages.GetTrainingTaskTotalNumByUserId(userId)
if err != nil {
return nil, err
}
running, err := l.svcCtx.Scheduler.AiStorages.GetTrainingTaskRunningNumByUserId(userId)
if err != nil {
return nil, err
}
resp.Total = total
resp.Running = running
} else {
total, err := l.svcCtx.Scheduler.AiStorages.GetTrainingTaskTotalNum()
if err != nil {
return nil, err
}
running, err := l.svcCtx.Scheduler.AiStorages.GetTrainingTaskRunningNum()
if err != nil {
return nil, err
}
resp.Total = total
resp.Running = running
total, err := l.svcCtx.Scheduler.AiStorages.GetTrainingTaskTotalNum()
if err != nil {
return nil, err
}
running, err := l.svcCtx.Scheduler.AiStorages.GetTrainingTaskRunningNum()
if err != nil {
return nil, err
}
resp.Total = total
resp.Running = running
return resp, nil
}

View File

@ -47,67 +47,32 @@ func NewContainerCreateLogic(ctx context.Context, svcCtx *svc.ServiceContext) *C
}
func (l *ContainerCreateLogic) ContainerCreate(req *container.CreateParam) (resp *ContainerCreateRespStruct, err error) {
// 构建云适配器的创建参数(使用结构体字面量直接映射)
resp = &ContainerCreateRespStruct{}
param := &cloud.CreateParam{
Name: req.Name,
Description: req.Description,
Capacity: req.Capacity,
UserId: strconv.FormatInt(req.UserId, 10),
Image: req.Image,
Cpu: req.Cpu,
Memory: req.Memory,
Port: req.Port,
NodePort: req.NodePort,
MountPath: req.MountPath,
Args: req.Args,
Command: req.Command,
Envs: req.Envs,
Replica: req.Replica,
ImagePullSecrets: req.ImagePullSecrets,
ImageRegistry: req.ImageRegistry,
ImageUsername: req.ImageUsername,
ImagePassword: req.ImagePassword,
Port: req.Port,
Cpu: req.Cpu,
Memory: req.Memory,
Image: req.Image,
Args: req.Args,
MountPath: req.MountPath,
Envs: req.Envs,
NodePort: req.NodePort,
ContainerGroupName: req.ContainerGroupName,
CreateParameter: req.ContainerCreateParameter,
FileParams: req.FileParams,
BillingType: req.BillingType,
Region: req.Region,
PayPeriod: req.PayPeriod,
ServiceModel: req.ServiceModel,
}
gen := utils.NewRandomStringGenerator("0123456789abcdefghijklmnopqrstuvwxyz")
param.ContainerGroupName = gen.Generate(15)
// 调用云适配器创建容器
createResp, err := l.svcCtx.Cloud.ContainerCreate(req.ClusterId, param)
create, err := l.svcCtx.Cloud.ContainerCreate(req.ClusterId, param)
if err != nil {
l.Logger.Errorf("调用p端创建容器失败clusterId: %s, name: %s, err: %v", req.ClusterId, req.Name, err)
return nil, err
}
if createResp.Code != http.StatusOK {
l.Logger.Errorf("p端返回错误clusterId: %s, name: %s, message: %s", req.ClusterId, req.Name, createResp.Message)
return nil, errors.New(createResp.Message)
if create.Code != http.StatusOK {
return nil, errors.New(create.Message)
}
// 查询集群信息
type ClusterInfo struct {
Name string `json:"name"`
AdapterId int64 `json:"adapter_id"`
}
var clusterInfo ClusterInfo
err = l.svcCtx.DbEngin.Table("t_cluster").Select("adapter_id,name").Where("id=?", req.ClusterId).First(&clusterInfo).Error
if err != nil {
l.Logger.Errorf("查询集群信息失败clusterId: %s, err: %v", req.ClusterId, err)
return nil, errors.New("查询集群信息失败")
}
// 开启事务
tx := l.svcCtx.DbEngin.Begin()
defer func() {
if r := recover(); r != nil {
tx.Rollback()
}
}()
// 构建主任务结构体
taskModel := models.Task{
Id: utils.GenSnowflakeID(),
@ -118,57 +83,36 @@ func (l *ContainerCreateLogic) ContainerCreate(req *container.CreateParam) (resp
UserName: req.UserName,
AdapterTypeDict: "0",
CommitTime: time.Now(),
TaskTypeDict: "container",
}
// 保存任务数据到数据库
tx := l.svcCtx.DbEngin.Create(&taskModel)
if tx.Error != nil {
// 保存主任务数据到数据库
if err = tx.Create(&taskModel).Error; err != nil {
tx.Rollback()
l.Logger.Errorf("保存主任务失败name: %s, err: %v", req.Name, err)
return nil, errors.New("保存主任务失败")
}
// 构建 cloud 任务结构体
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: clusterInfo.AdapterId,
Status: constants.Saved,
Namespace: "default",
UserId: req.UserId,
ClusterId: req.ClusterId,
ClusterName: clusterInfo.Name,
Id: utils.GenSnowflakeID(),
TaskId: taskModel.Id,
Name: req.Name,
AdapterId: adapterId,
Status: constants.Saved,
Namespace: "default",
UserId: req.UserId,
ClusterId: req.ClusterId,
ResourceSpec: cloud2.ResourceSpec{
ResourceName: fmt.Sprintf("%s_cpu %s_mem %s", clusterInfo.Name, req.Cpu, req.Memory),
ResourceType: constants.TaskTypeCloud,
Specifications: map[string]interface{}{
"CPU": req.Cpu,
"Memory": req.Memory,
},
CPU: req.Cpu,
Memory: req.Memory,
},
}
if createResp.Data != nil {
cloudTaskModel.BusinessCode = fmt.Sprintf("%v", createResp.Data)
}
// 保存 cloud 任务数据到数据库
if err = tx.Create(&cloudTaskModel).Error; err != nil {
tx.Rollback()
l.Logger.Errorf("保存 cloud 任务失败name: %s, err: %v", req.Name, err)
return nil, errors.New("保存 cloud 任务失败")
}
// 提交事务
if err = tx.Commit().Error; err != nil {
l.Logger.Errorf("提交事务失败err: %v", err)
return nil, errors.New("提交事务失败")
}
l.Logger.Infof("创建容器成功taskId: %d, clusterId: %s, name: %s", taskModel.Id, req.ClusterId, req.Name)
resp = &ContainerCreateRespStruct{
TaskId: strconv.FormatInt(taskModel.Id, 10),
// 保存任务数据到数据库
tx = l.svcCtx.DbEngin.Create(&cloudTaskModel)
if tx.Error != nil {
fmt.Println()
return nil, tx.Error
}
resp.TaskId = strconv.FormatInt(taskModel.Id, 10)
return resp, nil
}

View File

@ -17,14 +17,11 @@ package cloud
import (
"context"
"errors"
"net/http"
"strconv"
"github.com/zeromicro/go-zero/core/logx"
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/participant/cloud"
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/svc"
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/types"
container "gitlink.org.cn/JointCloud/pcm-coordinator/internal/types/cloud"
"gitlink.org.cn/JointCloud/pcm-coordinator/pkg/models"
"net/http"
)
type ContainerDeleteLogic struct {
@ -42,75 +39,16 @@ func NewContainerDeleteLogic(ctx context.Context, svcCtx *svc.ServiceContext) *C
}
func (l *ContainerDeleteLogic) ContainerDelete(req *container.DeleteParam) (resp interface{}, err error) {
// 查询任务信息
task := &types.TaskModel{}
err = l.svcCtx.DbEngin.Table("task").Where("id", req.Id).First(task).Error
if err != nil || task.Id == 0 {
l.Logger.Errorf("任务不存在id: %d, err: %v", req.Id, err)
return nil, errors.New("任务不存在")
param := &cloud.DeleteParam{
Name: req.Name,
}
// 查询通算任务信息
taskCloud := &models.TaskCloud{}
err = l.svcCtx.DbEngin.Table("task_cloud").Where("task_id", req.Id).First(taskCloud).Error
if err != nil || taskCloud.Id == 0 {
l.Logger.Errorf("通算任务不存在taskId: %d, err: %v", req.Id, err)
return nil, errors.New("通算任务不存在")
}
// 设置删除请求参数
clusterId := strconv.FormatInt(taskCloud.ClusterId, 10)
deleteReq := &container.DeleteParam{
Id: req.Id,
ClusterId: clusterId,
}
if taskCloud.BusinessCode != "" && taskCloud.BusinessCode != "null" {
deleteReq.Name = taskCloud.BusinessCode
} else {
deleteReq.Name = taskCloud.Name
}
// 调用底层删除接口
create, err := l.svcCtx.Cloud.ContainerDelete(clusterId, deleteReq)
create, err := l.svcCtx.Cloud.ContainerDelete(req.ClusterId, param)
if err != nil {
l.Logger.Errorf("删除容器失败clusterId: %s, name: %s, err: %v", clusterId, deleteReq.Name, err)
return nil, err
}
if create.Code != http.StatusOK {
l.Logger.Errorf("删除容器返回错误clusterId: %s, name: %s, message: %s", clusterId, deleteReq.Name, create.Message)
return nil, errors.New(create.Message)
}
// 开启事务更新状态
tx := l.svcCtx.DbEngin.Begin()
defer func() {
if r := recover(); r != nil {
tx.Rollback()
}
}()
// 更新 task_cloud 状态
err = tx.Model(&models.TaskCloud{}).Where("id", taskCloud.Id).Update("status", "Deleted").Error
if err != nil {
tx.Rollback()
l.Logger.Errorf("更新 task_cloud 状态失败id: %d, err: %v", taskCloud.Id, err)
return nil, errors.New("更新任务状态失败")
}
// 更新 task 状态
err = tx.Model(&types.Task{}).Where("id", req.Id).Update("status", "Deleted").Error
if err != nil {
tx.Rollback()
l.Logger.Errorf("更新 task 状态失败id: %d, err: %v", req.Id, err)
return nil, errors.New("更新任务状态失败")
}
// 提交事务
if err = tx.Commit().Error; err != nil {
l.Logger.Errorf("提交事务失败err: %v", err)
return nil, errors.New("提交事务失败")
}
l.Logger.Infof("删除容器成功taskId: %d, clusterId: %s, name: %s", req.Id, clusterId, deleteReq.Name)
resp = create.Data
return
}

View File

@ -1,57 +0,0 @@
/*
Copyright (c) [2023] [pcm]
[pcm-coordinator] is licensed under Mulan PSL v2.
You can use this software according to the terms and conditions of the Mulan PSL v2.
You may obtain a copy of Mulan PSL v2 at:
http://license.coscl.org.cn/MulanPSL2
THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
EITHER EXPaRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
See the Mulan PSL v2 for more details.
*/
package cloud
import (
"context"
"errors"
"net/http"
"github.com/zeromicro/go-zero/core/logx"
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/participant/cloud"
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/svc"
container "gitlink.org.cn/JointCloud/pcm-coordinator/internal/types/cloud"
)
type ContainerImagesLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewContainerImagesLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ContainerImagesLogic {
return &ContainerImagesLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *ContainerImagesLogic) ContainerImages(req *container.ImagesParam) (resp interface{}, err error) {
param := &cloud.ImagesParam{
Region: req.Region,
PageNum: req.PageNum,
PageSize: req.PageSize,
}
get, err := l.svcCtx.Cloud.ContainerImages(req.ClusterId, param)
if err != nil {
return nil, err
}
if get.Code != http.StatusOK {
return nil, errors.New(get.Message)
}
resp = get.Data
return
}

View File

@ -17,14 +17,10 @@ package cloud
import (
"context"
"errors"
"net/http"
"strconv"
"github.com/zeromicro/go-zero/core/logx"
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/svc"
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/types"
container "gitlink.org.cn/JointCloud/pcm-coordinator/internal/types/cloud"
"gitlink.org.cn/JointCloud/pcm-coordinator/pkg/models"
"net/http"
)
type ContainerLogLogic struct {
@ -42,19 +38,10 @@ func NewContainerLogLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Cont
}
func (l *ContainerGetLogic) ContainerLog(req *container.LogParam) (resp interface{}, err error) {
task := &types.TaskModel{}
l.svcCtx.DbEngin.Table("task").Where("id", req.Id).Scan(&task)
if task.Name == "" {
return nil, errors.New("任务不存在")
param := &container.LogParam{
Name: req.Name,
}
taskCloud := models.TaskCloud{}
l.svcCtx.DbEngin.Table("task_cloud").Where("task_id", req.Id).Scan(&taskCloud)
if taskCloud.Name == "" {
return nil, errors.New("通算任务不存在")
}
req.Name = taskCloud.BusinessCode
req.ClusterId = strconv.FormatInt(taskCloud.ClusterId, 10)
get, err := l.svcCtx.Cloud.ContainerLog(req.ClusterId, req)
get, err := l.svcCtx.Cloud.ContainerLog(req.ClusterId, param)
if err != nil {
return nil, err
}
@ -62,6 +49,5 @@ func (l *ContainerGetLogic) ContainerLog(req *container.LogParam) (resp interfac
return nil, errors.New(get.Message)
}
resp = get.Data
return resp, nil
return
}

View File

@ -1,78 +0,0 @@
/*
Copyright (c) [2023] [pcm]
[pcm-coordinator] is licensed under Mulan PSL v2.
You can use this software according to the terms and conditions of the Mulan PSL v2.
You may obtain a copy of Mulan PSL v2 at:
http://license.coscl.org.cn/MulanPSL2
THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
EITHER EXPaRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
See the Mulan PSL v2 for more details.
*/
package cloud
import (
"context"
"errors"
"github.com/zeromicro/go-zero/core/logx"
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/participant/cloud"
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/svc"
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/types"
container "gitlink.org.cn/JointCloud/pcm-coordinator/internal/types/cloud"
"gitlink.org.cn/JointCloud/pcm-coordinator/pkg/models"
"k8s.io/apimachinery/pkg/util/json"
"net/http"
"strconv"
)
type ContainerMetricsLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewContainerMetricsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ContainerMetricsLogic {
return &ContainerMetricsLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *ContainerMetricsLogic) ContainerMetrics(req *container.MetricsParam) (resp interface{}, err error) {
task := &types.TaskModel{}
l.svcCtx.DbEngin.Table("task").Where("id", req.Id).Scan(&task)
if task.Name == "" {
return nil, errors.New("任务不存在")
}
taskCloud := models.TaskCloud{}
l.svcCtx.DbEngin.Table("task_cloud").Where("task_id", req.Id).Scan(&taskCloud)
if taskCloud.Name == "" {
return nil, errors.New("通算任务不存在")
}
if taskCloud.BusinessCode != "" && taskCloud.BusinessCode != "null" {
var eciRequestParam cloud.EciRequestParam
err := json.Unmarshal([]byte(taskCloud.BusinessCode), &eciRequestParam)
if err != nil {
logx.Errorf("Failed to unmarshal BusinessCode: %v", err)
return nil, err
}
req.Name = eciRequestParam.ContainerGroupId
} else {
req.Name = taskCloud.Name
}
req.ClusterId = strconv.FormatInt(taskCloud.ClusterId, 10)
get, err := l.svcCtx.Cloud.ContainerMetrics(req.ClusterId, req)
if err != nil {
return nil, err
}
if get.Code != http.StatusOK {
return nil, errors.New(get.Message)
}
resp = get.Data
return resp, nil
}

View File

@ -16,30 +16,29 @@ package cloud
import (
"context"
"github.com/zeromicro/go-zero/core/logx"
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/svc"
instance "gitlink.org.cn/JointCloud/pcm-coordinator/internal/types/cloud"
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/types"
"github.com/zeromicro/go-zero/core/logx"
)
type InstanceTypesLogic struct {
type DeleteYamlLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewInstanceTypesLogic(ctx context.Context, svcCtx *svc.ServiceContext) *InstanceTypesLogic {
return &InstanceTypesLogic{
func NewDeleteYamlLogic(ctx context.Context, svcCtx *svc.ServiceContext) *DeleteYamlLogic {
return &DeleteYamlLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *InstanceTypesLogic) InstanceTypes(req *instance.InstanceTypesParam) (resp interface{}, err error) {
func (l *DeleteYamlLogic) DeleteYaml(req *types.ApplyReq) (resp *types.DeleteResp, err error) {
// todo: add your logic here and delete this line
resp, err = l.svcCtx.Cloud.InstanceTypes(req.ClusterId, req)
if err != nil {
return nil, err
}
return resp, nil
return
}

View File

@ -2,7 +2,6 @@ package cloud
import (
"context"
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/logic/security"
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/svc"
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/types"
@ -26,6 +25,5 @@ func NewGetClusterListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Ge
func (l *GetClusterListLogic) GetClusterList(req *types.GetClusterListReq) (resp *types.GetClusterListResp, err error) {
resp = &types.GetClusterListResp{}
l.svcCtx.DbEngin.Raw("select * from t_cluster where adapter_id = ?", req.AdapterId).Scan(&resp.Clusters)
security.SanitizeClusterSecretList(resp.Clusters)
return resp, nil
}

View File

@ -1,139 +0,0 @@
/*
Copyright (c) [2023] [pcm]
[pcm-coordinator] is licensed under Mulan PSL v2.
You can use this software according to the terms and conditions of the Mulan PSL v2.
You may obtain a copy of Mulan PSL v2 at:
http://license.coscl.org.cn/MulanPSL2
THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
EITHER EXPaRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
See the Mulan PSL v2 for more details.
*/
package cloud
import (
"context"
"errors"
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/types"
"k8s.io/apimachinery/pkg/util/json"
"net/http"
"strconv"
"time"
"github.com/zeromicro/go-zero/core/logx"
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/svc"
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"
"gitlink.org.cn/JointCloud/pcm-coordinator/pkg/utils"
)
type InstanceCreateLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewInstanceCreateLogic(ctx context.Context, svcCtx *svc.ServiceContext) *InstanceCreateLogic {
return &InstanceCreateLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *InstanceCreateLogic) InstanceCreate(req *container.CreateInstanceParam) (resp *ContainerCreateRespStruct, err error) {
resp = &ContainerCreateRespStruct{}
param := &container.CreateInstanceParam{
ClusterId: req.ClusterId,
ImageId: req.ImageId,
InstanceType: req.InstanceType,
InstanceChargeType: req.InstanceChargeType,
HostName: req.HostName,
Username: req.Username,
Password: req.Password,
SecurityGroupId: req.SecurityGroupId,
SystemDiskSize: req.SystemDiskSize,
SystemDiskCategory: req.SystemDiskCategory,
SystemDiskPerformanceLevel: req.SystemDiskPerformanceLevel,
Replica: req.Replica,
}
createResp, err := l.svcCtx.Cloud.InstanceCreate(req.ClusterId, param)
if err != nil {
return nil, err
}
if createResp.Code != http.StatusOK {
return nil, errors.New(createResp.Message)
}
// 构建主任务结构体
taskModel := models.Task{
Id: utils.GenSnowflakeID(),
Status: constants.Saved,
Description: req.Description,
Name: req.HostName,
UserId: req.UserId,
UserName: req.Username,
AdapterTypeDict: "0",
CommitTime: time.Now(),
TaskTypeDict: "instance",
}
// 保存任务数据到数据库
tx := l.svcCtx.DbEngin.Create(&taskModel)
if tx.Error != nil {
return nil, err
}
type ClusterInfo struct {
Name string `json:"name"`
AdapterId int64 `json:"adapter_id"`
}
var ci ClusterInfo
tx.Table("t_cluster").Select("adapter_id,name").Where("id=?", req.ClusterId).Find(&ci)
// 构建cloud任务结构体
clusterId, err := strconv.ParseInt(req.ClusterId, 10, 64)
bytes, err := json.Marshal(createResp.Data)
if err != nil {
return nil, err
}
instanceIds := make([]string, 0)
err = json.Unmarshal(bytes, &instanceIds)
if err != nil {
return nil, err
}
if len(instanceIds) != 0 {
for _, instanceId := range instanceIds {
instance := types.VmInstance{
Id: utils.GenSnowflakeID(),
TaskId: taskModel.Id,
HostName: req.HostName,
Status: constants.Saved,
UserId: req.UserId,
ClusterId: clusterId,
InstanceType: req.InstanceType,
Password: req.Password,
ImageId: req.ImageId,
SystemDiskSize: req.SystemDiskSize,
Replica: req.Replica,
ClusterName: ci.Name,
InstanceId: instanceId,
}
// 保存任务数据到数据库
tx = l.svcCtx.DbEngin.Create(&instance)
if tx.Error != nil {
return nil, tx.Error
}
}
}
resp.TaskId = strconv.FormatInt(taskModel.Id, 10)
return resp, nil
}
type InstanceCreateRespStruct struct {
TaskId string `json:"taskId"`
}

View File

@ -1,80 +0,0 @@
/*
Copyright (c) [2023] [pcm]
[pcm-coordinator] is licensed under Mulan PSL v2.
You can use this software according to the terms and conditions of the Mulan PSL v2.
You may obtain a copy of Mulan PSL v2 at:
http://license.coscl.org.cn/MulanPSL2
THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
EITHER EXPaRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
See the Mulan PSL v2 for more details.
*/
package cloud
import (
"context"
"github.com/zeromicro/go-zero/core/logx"
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/participant/cloud"
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/svc"
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/types"
instance "gitlink.org.cn/JointCloud/pcm-coordinator/internal/types/cloud"
"k8s.io/apimachinery/pkg/util/json"
"strconv"
)
type InstanceInfoLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewInstanceInfoLogic(ctx context.Context, svcCtx *svc.ServiceContext) *InstanceInfoLogic {
return &InstanceInfoLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *InstanceInfoLogic) InstanceInfo(req *instance.InstanceInfoParam) (resp *cloud.InstanceInfo, err error) {
vmInstance := &types.VmInstance{}
tx := l.svcCtx.DbEngin.Model(&types.VmInstance{}).Where("instance_id = ?", req.InstanceId).Table("vm_instance").Find(&vmInstance)
if tx.Error != nil {
return nil, tx.Error
}
// 查询公有云数据
remoteResp := &cloud.Resp{}
remoteResp, err = l.svcCtx.Cloud.InstanceInfo(strconv.FormatInt(vmInstance.ClusterId, 10), req)
bytes, err := json.Marshal(remoteResp.Data)
if err != nil {
return nil, err
}
remoteInfo := cloud.InstanceInfo{}
json.Unmarshal(bytes, &remoteInfo)
if remoteInfo.InstanceId == "" {
vmInstance.Status = "Deleted"
} else {
vmInstance.PrivateIpAddress = remoteInfo.PrivateIpAddress
vmInstance.PublicIpAddress = remoteInfo.PublicIpAddress
vmInstance.Status = remoteInfo.Status
vmInstance.OSName = remoteInfo.OSName
}
l.svcCtx.DbEngin.Updates(vmInstance)
marshal, err := json.Marshal(vmInstance)
if err != nil {
return nil, err
}
json.Unmarshal(marshal, &resp)
// 封装返回信息
resp.InternetInRate = remoteInfo.InternetInRate
resp.InternetOutRate = remoteInfo.InternetOutRate
resp.CPUUtilization = remoteInfo.CPUUtilization
resp.MemoryUtilization = remoteInfo.MemoryUtilization
resp.DiskUtilization = remoteInfo.DiskUtilization
return resp, nil
}

View File

@ -1,69 +0,0 @@
/*
Copyright (c) [2023] [pcm]
[pcm-coordinator] is licensed under Mulan PSL v2.
You can use this software according to the terms and conditions of the Mulan PSL v2.
You may obtain a copy of Mulan PSL v2 at:
http://license.coscl.org.cn/MulanPSL2
THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
EITHER EXPaRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
See the Mulan PSL v2 for more details.
*/
package cloud
import (
"context"
"github.com/zeromicro/go-zero/core/logx"
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/svc"
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/types"
instance "gitlink.org.cn/JointCloud/pcm-coordinator/internal/types/cloud"
)
type InstanceListLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewInstanceListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *InstanceListLogic {
return &InstanceListLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *InstanceListLogic) InstanceList(req *instance.PageInstanceParam) (resp *types.PageResult, err error) {
limit := req.PageSize
offset := req.PageSize * (req.PageNum - 1)
resp = &types.PageResult{}
var localList []types.VmInstance
db := l.svcCtx.DbEngin.Model(&types.VmInstance{}).Table("vm_instance")
if req.HostName != "" {
db = db.Where("host_name LIKE ?", "%"+req.HostName+"%")
}
if req.UserName != "" && req.UserName != "admin" {
db = db.Where("user_id = ?", req.UserId)
}
if req.Status != "" {
db = db.Where("status = ?", req.Status)
}
var total int64
err = db.Count(&total).Error
if err != nil {
return resp, err
}
db = db.Where("deleted_at is null").Limit(limit).Offset(offset)
err = db.Order("create_time desc").Find(&localList).Error
resp.List = localList
resp.PageSize = req.PageSize
resp.PageNum = req.PageNum
resp.Total = total
return resp, nil
}

View File

@ -1,68 +0,0 @@
/*
Copyright (c) [2023] [pcm]
[pcm-coordinator] is licensed under Mulan PSL v2.
You can use this software according to the terms and conditions of the Mulan PSL v2.
You may obtain a copy of Mulan PSL v2 at:
http://license.coscl.org.cn/MulanPSL2
THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
EITHER EXPaRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
See the Mulan PSL v2 for more details.
*/
package cloud
import (
"context"
"errors"
"github.com/zeromicro/go-zero/core/logx"
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/participant/cloud"
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/svc"
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/types"
container "gitlink.org.cn/JointCloud/pcm-coordinator/internal/types/cloud"
"net/http"
"strconv"
)
type InstanceOperateLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewInstanceOperateLogic(ctx context.Context, svcCtx *svc.ServiceContext) *InstanceOperateLogic {
return &InstanceOperateLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *InstanceOperateLogic) InstanceOperate(req *container.OperateInstanceParam) (resp interface{}, err error) {
instance := types.VmInstance{}
l.svcCtx.DbEngin.Table("vm_instance").Where("instance_id", req.InstanceIds[0]).Scan(&instance)
remoteResp := &cloud.Resp{}
switch req.OperateType {
case "delete":
remoteResp, err = l.svcCtx.Cloud.InstanceDelete(strconv.FormatInt(instance.ClusterId, 10), req)
case "stop":
remoteResp, err = l.svcCtx.Cloud.InstanceStop(strconv.FormatInt(instance.ClusterId, 10), req)
case "start":
remoteResp, err = l.svcCtx.Cloud.InstanceStart(strconv.FormatInt(instance.ClusterId, 10), req)
case "reboot":
remoteResp, err = l.svcCtx.Cloud.InstanceReboot(strconv.FormatInt(instance.ClusterId, 10), req)
}
if err != nil {
return nil, err
}
if remoteResp.Code != http.StatusOK {
return nil, errors.New(remoteResp.Message)
}
if req.OperateType == "delete" {
instance.Status = "Deleted"
l.svcCtx.DbEngin.Updates(instance)
}
return
}

View File

@ -0,0 +1,30 @@
package cloud
import (
"context"
"github.com/zeromicro/go-zero/core/logx"
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/svc"
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/types"
"net/http"
)
type PodLogsLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
w http.ResponseWriter
}
func NewPodLogsLogic(ctx context.Context, svcCtx *svc.ServiceContext, w http.ResponseWriter) *PodLogsLogic {
return &PodLogsLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
w: w,
}
}
func (l *PodLogsLogic) PodLogs(req *types.PodLogsReq, w http.ResponseWriter) (resp string, err error) {
// todo: add your logic here and delete this line
return
}

View File

@ -0,0 +1,66 @@
package core
import (
"context"
"github.com/ghodss/yaml"
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/mqs"
"gitlink.org.cn/JointCloud/pcm-coordinator/pkg/constants"
"gitlink.org.cn/JointCloud/pcm-coordinator/pkg/models"
"gitlink.org.cn/JointCloud/pcm-coordinator/pkg/response"
"strings"
"time"
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/svc"
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/types"
"github.com/zeromicro/go-zero/core/logx"
)
type CommitTaskLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewCommitTaskLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CommitTaskLogic {
return &CommitTaskLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *CommitTaskLogic) CommitTask(req *types.CommitTaskReq) error {
//req.YamlList转换为json
var yamlStr []string
for _, s := range req.YamlList {
j2, err := yaml.YAMLToJSON([]byte(s))
if err != nil {
logx.Errorf("Failed to convert yaml to JSON, err: %v", err)
return err
}
yamlStr = append(yamlStr, string(j2))
}
result := strings.Join(yamlStr, ",")
taskModel := models.Task{
Status: constants.Saved,
Name: req.Name,
CommitTime: time.Now(),
NsID: req.NsID,
YamlString: "[" + result + "]",
}
// 保存任务数据到数据库
tx := l.svcCtx.DbEngin.Create(&taskModel)
if tx.Error != nil {
return tx.Error
}
task := response.TaskInfo{
TaskId: taskModel.Id,
MatchLabels: req.MatchLabels,
NsID: req.NsID,
Metadata: req.YamlList,
Replicas: req.Replicas,
}
mqs.InsQueue.Beta.Add(&task)
return nil
}

View File

@ -1,43 +0,0 @@
package core
import (
"context"
"strconv"
"github.com/zeromicro/go-zero/core/logx"
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/svc"
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/types"
"gitlink.org.cn/JointCloud/pcm-coordinator/pkg/models"
)
type EditAchievementLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewEditAchievementLogic(ctx context.Context, svcCtx *svc.ServiceContext) *EditAchievementLogic {
return &EditAchievementLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *EditAchievementLogic) EditAchievement(req *types.EditAchievementReq) (resp *types.TaskListResp, err error) {
id, err := strconv.ParseInt(req.Id, 10, 64)
taskId, err := strconv.ParseInt(req.TaskId, 10, 64)
achievement := models.Achievement{
Id: id,
TaskId: taskId,
Title: req.Title,
TitleImagePath: req.TitleImagePath,
Label: req.Label,
Description: req.Description,
Content: req.Content,
Status: req.Status,
}
l.svcCtx.DbEngin.Table("achievement").Updates(&achievement)
return nil, nil
}

View File

@ -3,7 +3,6 @@ package core
import (
"context"
"github.com/pkg/errors"
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/logic/security"
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/svc"
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/types"
@ -32,6 +31,5 @@ func (l *GetClusterByIdLogic) GetClusterById(req *types.GetClusterByIdReq) (resp
logx.Errorf(tx.Error.Error())
return nil, errors.New("cluster create failed")
}
security.SanitizeClusterSecret(&resp.ClusterInfo)
return resp, nil
}

View File

@ -1,60 +0,0 @@
package core
import (
"context"
"fmt"
"github.com/zeromicro/go-zero/core/logx"
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/svc"
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/types"
"gitlink.org.cn/JointCloud/pcm-coordinator/pkg/models"
)
type ListAchievementLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewListAchievementLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ListAchievementLogic {
return &ListAchievementLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *ListAchievementLogic) ListAchievement(req *types.ListAchievementReq) (resp *[]types.ListAchievementResp, err error) {
var achievements []models.Achievement
query := l.svcCtx.DbEngin.Table("achievement")
// 添加成果名称模糊查询条件
if req.Title != "" {
query = query.Where("title LIKE ?", "%"+req.Title+"%")
}
// 添加标签名称查询条件假设标签存储在tags字段中
if req.Label != "" {
query = query.Where("label LIKE ?", "%"+req.Label+"%")
}
query = query.Where("status = 1")
tx := query.Find(&achievements)
if tx.Error != nil {
return nil, tx.Error
}
result := make([]types.ListAchievementResp, len(achievements))
for i, achievement := range achievements {
result[i] = types.ListAchievementResp{
Id: fmt.Sprintf("%d", achievement.Id),
TaskId: fmt.Sprintf("%d", achievement.TaskId),
Title: achievement.Title,
Label: achievement.Label,
Description: achievement.Description,
Status: achievement.Status,
UserName: achievement.UserName,
PublishTime: achievement.PublishTime,
}
}
return &result, nil
}

View File

@ -2,13 +2,11 @@ package core
import (
"context"
"strings"
"time"
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/svc"
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/types"
"gitlink.org.cn/JointCloud/pcm-coordinator/pkg/repository/result"
"gitlink.org.cn/JointCloud/pcm-coordinator/pkg/utils/timeutils"
"time"
"github.com/zeromicro/go-zero/core/logx"
)
@ -51,18 +49,8 @@ func (l *PageListTaskLogic) PageListTask(req *types.PageTaskReq) (resp *types.Pa
if req.Name != "" {
db = db.Where("name LIKE ?", "%"+req.Name+"%")
}
// 任务状态筛选
if req.Status != "" {
split := strings.Split(req.Status, ",")
if len(split) > 1 {
db = db.Where("status IN ?", split)
} else {
db = db.Where("status = ?", req.Status)
}
}
if req.Type != "" {
db = db.Where("adapter_type_dict = ?", req.Type)
db = db.Where("task_type_dict != ?", "instance")
}
// 计算总数
var total int64
@ -82,16 +70,6 @@ func (l *PageListTaskLogic) PageListTask(req *types.PageTaskReq) (resp *types.Pa
// 计算每个任务的运行时间x
for _, model := range list {
model.RunningTime = calculateRunningTime(model.StartTime, model.EndTime)
if model.AdapterTypeDict == "0" {
type tempSpec struct { // 嵌套临时 struct对应 JSON 的 specifications 字段
CPU string `json:"CPU"`
Memory string `json:"Memory"`
}
var temp tempSpec
l.svcCtx.DbEngin.Raw("SELECT IFNULL(resource_spec->>'$.specifications.CPU', '') AS cpu,IFNULL(resource_spec->>'$.specifications.Memory', '') AS memory FROM task_cloud where task_id = ?", model.Id).Scan(&temp)
model.Cpu = temp.CPU
model.Memory = temp.Memory
}
}
// 填充响应数据

View File

@ -3,7 +3,6 @@ package core
import (
"context"
"fmt"
"gitlink.org.cn/JointCloud/pcm-coordinator/pkg/models"
"gorm.io/gorm"
@ -53,32 +52,26 @@ func (l *PageResourceRangeLogic) PageResourceRange(req *types.ResourceSpecReq) (
}
func (l *PageResourceRangeLogic) buildBaseQuery(req *types.ResourceSpecReq) *gorm.DB {
query := l.svcCtx.DbEngin.Model(&models.TResourceSpec{}).Table("t_resource_spec as rs").
Where("rs.deleted_at IS NULL")
query := l.svcCtx.DbEngin.Model(&models.TResourceSpec{}).
Where("deleted_at IS NULL")
if req.ClusterId != "" {
query = query.Where("rs.cluster_id = ?", req.ClusterId)
query = query.Where("cluster_id = ?", req.ClusterId)
}
if req.Tag != "" {
query = query.Where("rs.tag = ?", req.Tag)
query = query.Where("tag = ?", req.Tag)
}
if req.Status != "" {
query = query.Where("rs.status = ?", req.Status)
query = query.Where("status = ?", req.Status)
}
if req.ChangeType != "" {
query = query.Where("rs.change_type = ?", req.ChangeType)
query = query.Where("change_type = ?", req.ChangeType)
}
if req.Type != "" {
query = query.Where("rs.type = ?", req.Type)
query = query.Where("type = ?", req.Type)
}
if req.Name != "" {
query = query.Where("rs.name LIKE ?", "%"+req.Name+"%")
}
if req.ClusterType != "" {
query = query.
Joins("JOIN t_cluster c ON rs.cluster_id = c.id").
Where("c.cluster_type = ?", req.ClusterType).
Where("c.deleted_at IS NULL")
query = query.Where("name LIKE ?", "%"+req.Name+"%")
}
return query

View File

@ -1,47 +0,0 @@
package core
import (
"context"
"strconv"
"time"
"github.com/zeromicro/go-zero/core/logx"
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/svc"
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/types"
"gitlink.org.cn/JointCloud/pcm-coordinator/pkg/models"
tool "gitlink.org.cn/JointCloud/pcm-coordinator/pkg/utils"
)
type PublishAchievementLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewPublishAchievementLogic(ctx context.Context, svcCtx *svc.ServiceContext) *PublishAchievementLogic {
return &PublishAchievementLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *PublishAchievementLogic) PublishAchievement(req *types.PublishAchievementReq) (resp *types.TaskListResp, err error) {
taskId, err := strconv.ParseInt(req.TaskId, 10, 64)
achievement := models.Achievement{
Id: tool.GenSnowflakeID(),
TaskId: taskId,
Title: req.Title,
TitleImagePath: req.TitleImagePath,
Label: req.Label,
Description: req.Description,
Content: req.Content,
Status: 1,
PublishTime: time.Now().Format("2006-01-02 15:04:05"),
UserId: req.UserId,
UserName: req.UserName,
}
l.svcCtx.DbEngin.Table("achievement").Create(&achievement)
return nil, nil
}

View File

@ -1,46 +0,0 @@
package core
import (
"context"
"strconv"
"github.com/zeromicro/go-zero/core/logx"
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/svc"
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/types"
"gitlink.org.cn/JointCloud/pcm-coordinator/pkg/models"
"k8s.io/apimachinery/pkg/util/json"
)
type QueryAchievementLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewQueryAchievementLogic(ctx context.Context, svcCtx *svc.ServiceContext) *QueryAchievementLogic {
return &QueryAchievementLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *QueryAchievementLogic) QueryAchievement(req *types.QueryAchievementReq) (resp *types.QueryAchievementResp, err error) {
achievement := models.Achievement{}
tx := l.svcCtx.DbEngin.Table("achievement").Where("task_id = ?", req.TaskId).Find(&achievement)
if tx.Error != nil {
return nil, tx.Error
}
bytes, err := json.Marshal(achievement)
if err != nil {
return nil, err
}
json.Unmarshal(bytes, &resp)
if achievement.Id != 0 {
resp.Id = strconv.FormatInt(achievement.Id, 10)
}
if achievement.TaskId != 0 {
resp.TaskId = strconv.FormatInt(achievement.TaskId, 10)
}
return resp, nil
}

View File

@ -1,44 +0,0 @@
package core
import (
"context"
"errors"
"github.com/zeromicro/go-zero/core/logx"
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/svc"
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/types"
)
type RevokeAchievementLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewRevokeAchievementLogic(ctx context.Context, svcCtx *svc.ServiceContext) *RevokeAchievementLogic {
return &RevokeAchievementLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *RevokeAchievementLogic) RevokeAchievement(req *types.RevokeAchievementReq) (resp *types.TaskListResp, err error) {
// 更新成就状态为草稿
result := l.svcCtx.DbEngin.Table("achievement").
Where("task_id = ?", req.TaskId).
Updates(map[string]interface{}{
"status": "0",
})
if result.Error != nil {
return nil, result.Error
}
if result.RowsAffected == 0 {
return nil, errors.New("未找到要更新的记录")
}
return nil, nil
}

View File

@ -61,7 +61,7 @@ func (l *TaskDetailsLogic) TaskDetails(req *types.FId) (resp *types.TaskDetailsR
for _, sub := range subList {
clusterIds = append(clusterIds, sub.ClusterId)
}
err = l.svcCtx.DbEngin.Table("t_cluster").Select("id,adapter_id,name,nickname,description,create_time").Where("storage_schedule = 1 and id in ?", clusterIds).Scan(&cList).Error
err = l.svcCtx.DbEngin.Table("t_cluster").Select("id,adapter_id,name,nickname,description,create_time").Where("id in ?", clusterIds).Scan(&cList).Error
if err != nil {
return resp, err
}

View File

@ -1,57 +0,0 @@
package core
import (
"context"
"fmt"
"strings"
"github.com/zeromicro/go-zero/core/logx"
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/svc"
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/types"
)
type TypeClusterResourceLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewTypeClusterResourceLogic(ctx context.Context, svcCtx *svc.ServiceContext) *TypeClusterResourceLogic {
return &TypeClusterResourceLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
// TypeClusterResource 根据资源类型获取对应的集群信息
func (l *TypeClusterResourceLogic) TypeClusterResource(req *types.TypeResourceSpecReq) (resp []types.ClusterInfo, err error) {
if len(req.Type) == 0 {
return nil, nil
}
// 将逗号分隔的字符串拆分为类型列表
typeList := strings.Split(req.Type, ",")
// 构建占位符和参数
placeholders := make([]string, len(typeList))
args := make([]interface{}, len(typeList))
for i, t := range typeList {
placeholders[i] = "?"
args[i] = strings.TrimSpace(t) // 去除可能的前后空格
}
sqlStr := fmt.Sprintf(`SELECT c.id , c.name, c.nickname
FROM t_resource_spec rs
INNER JOIN t_cluster c ON rs.cluster_id = c.id
WHERE rs.type IN (%s)
AND rs.deleted_at IS NULL
AND c.deleted_at IS NULL
AND rs.status = 1
AND c.storage_schedule = 1
GROUP BY c.id, c.name, c.nickname
ORDER BY c.id;`, strings.Join(placeholders, ","))
l.svcCtx.DbEngin.Raw(sqlStr, args...).Scan(&resp)
return resp, nil
}

View File

@ -3,7 +3,6 @@ package hpc
import (
"context"
"fmt"
"github.com/zeromicro/go-zero/core/logx"
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/scheduler/service"
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/svc"
@ -40,6 +39,33 @@ func NewCancelJobLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CancelJ
}
func (l *CancelJobLogic) CancelJob(req *types.CancelJobReq) error {
//var clusterInfo *types.ClusterInfo
//tx := l.svcCtx.DbEngin.Raw("select * from t_cluster where id = ?", req.ClusterId).Scan(&clusterInfo)
//if tx.Error != nil {
// return tx.Error
//}
//// 查询p端调用地址
//var adapterAddress string
//l.svcCtx.DbEngin.Raw("SELECT server FROM `t_adapter` where id = ?", clusterInfo.AdapterId).Scan(&adapterAddress)
//var jobResp slurm.GetJobResp
//httpClient := resty.New().R()
//_, err := httpClient.SetHeader("Content-Type", "application/json").
// SetQueryParams(map[string]string{
// "jobId": req.JobId,
// "server": clusterInfo.Server,
// "version": clusterInfo.Version,
// "token": clusterInfo.Token,
// "username": clusterInfo.Username,
// }).
// SetResult(&jobResp).
// Delete(adapterAddress + "/api/v1/job/cancel")
//if err != nil {
// return err
//}
//if len(jobResp.Errors) != 0 {
// return errors.Errorf(jobResp.Errors[0].Description)
//}
//return nil
var hpcR TaskHPCResult
tx := l.svcCtx.DbEngin.Raw(
"SELECT t.id, hpc.job_id ,hpc.adapter_id, hpc.cluster_id FROM task t "+
@ -53,19 +79,23 @@ func (l *CancelJobLogic) CancelJob(req *types.CancelJobReq) error {
if hpcR.ID == 0 || hpcR.JobID == "" {
return fmt.Errorf("作业不存在")
}
var adapterInfo types.AdapterInfo
l.svcCtx.DbEngin.Raw("SELECT * FROM `t_adapter` where id = ?", hpcR.AdapterId).Scan(&adapterInfo)
if adapterInfo.Id == "" {
return fmt.Errorf("adapter not found")
}
// 取消作业
err := l.hpcService.HpcExecutorClusterMap[hpcR.ClusterId].CancelTask(l.ctx, hpcR.JobID, hpcR.ClusterId)
err := l.hpcService.HpcExecutorAdapterMap[adapterInfo.Id].CancelTask(l.ctx, hpcR.JobID, hpcR.ClusterId)
if err != nil {
return err
}
// 更新数据库状态
tx = l.svcCtx.DbEngin.Model(&types.Task{}).Where("id = ?", hpcR.ID).Update("status", "Cancelled").Error
tx = l.svcCtx.DbEngin.Model(&types.Task{}).Where("id = ?", hpcR.ID).Update("status", "Canceled").Error
if tx != nil {
return fmt.Errorf("数据库更新失败: %v", tx.Error)
}
// 更新数据库状态
tx = l.svcCtx.DbEngin.Model(&models.TaskHpc{}).Where("task_id = ?", hpcR.ID).Update("status", "Cancelled").Error
tx = l.svcCtx.DbEngin.Model(&models.TaskHpc{}).Where("task_id = ?", hpcR.ID).Update("status", "Canceled").Error
if tx != nil {
return fmt.Errorf("数据库更新失败: %v", tx.Error)
}

View File

@ -209,7 +209,6 @@ func (l *CommitHpcTaskLogic) SaveHpcTaskToDB(req *types.CommitHpcTaskReq, jobScr
AdapterTypeDict: constants.AdapterTypeHPC,
UserId: userID,
UserName: req.Parameters[constants.UserName],
Token: req.Parameters["Token"],
}
if err = tx.Table("task").Create(&taskModel).Error; err != nil {
@ -232,8 +231,7 @@ func (l *CommitHpcTaskLogic) SaveHpcTaskToDB(req *types.CommitHpcTaskReq, jobScr
slurmResource := parser.ParseScript(jobScript)
resource = models.ResourceSpec{
//资源规格名称,采用拼接的方式 集群名+队列名
ResourceName: fmt.Sprintf("%s_partition %s", clusterInfo.Name, slurmResource.Partition),
ResourceType: constants.TaskTypeHpc,
ResourceName: fmt.Sprintf("%s_%s", clusterInfo.Name, slurmResource.Partition),
Partition: slurmResource.Partition,
Specifications: slurmResource,
}
@ -298,17 +296,17 @@ func (l *CommitHpcTaskLogic) SaveHpcTaskToDB(req *types.CommitHpcTaskReq, jobScr
}
func (l *CommitHpcTaskLogic) CommitHpcTask(req *types.CommitHpcTaskReq) (resp *types.CommitHpcTaskResp, err error) {
logc.Debugf(
l.ctx,
"提交超算任务请求: clusterId=%s, app=%s, backend=%s, operateType=%s",
req.ClusterId, req.App, req.Backend, req.OperateType,
)
reqJSON, err := jsoniter.MarshalToString(req)
if err != nil {
return nil, fmt.Errorf("failed to marshal request: %w", err)
}
logc.Infof(l.ctx, "提交超算任务请求参数: %s", reqJSON)
jobName := generateJobName(req)
req.Parameters["jobName"] = jobName
// 获取集群和适配器信息
clusterInfo, _, err := l.getClusterInfo(req.ClusterId)
clusterInfo, adapterInfo, err := l.getClusterInfo(req.ClusterId)
if err != nil {
return nil, err
}
@ -339,6 +337,7 @@ func (l *CommitHpcTaskLogic) CommitHpcTask(req *types.CommitHpcTaskReq) (resp *t
scriptContent = script
}
q, _ := jsoniter.MarshalToString(scriptContent)
submitQ := types.SubmitHpcTaskReq{
App: req.App,
ClusterId: req.ClusterId,
@ -346,15 +345,11 @@ func (l *CommitHpcTaskLogic) CommitHpcTask(req *types.CommitHpcTaskReq) (resp *t
ScriptContent: scriptContent,
Parameters: req.Parameters,
Backend: req.Backend,
JcsUserID: req.JcsUserID,
}
log.Info().Msgf(
"Submitting HPC task to cluster %s, backend: %s, scriptLength: %d",
clusterInfo.Name, req.Backend, len(scriptContent),
)
resp, err = l.hpcService.HpcExecutorClusterMap[clusterInfo.Id].SubmitTask(l.ctx, submitQ)
log.Info().Msgf("Submitting HPC task to cluster %s with params: %s", clusterInfo.Name, q)
resp, err = l.hpcService.HpcExecutorAdapterMap[adapterInfo.Id].SubmitTask(l.ctx, submitQ)
if err != nil {
log.Error().Err(err).Msgf("提交超算任务失败, cluster: %s, jobName: %s", clusterInfo.Name, jobName)
log.Error().Err(err).Msgf("提交超算任务失败, cluster: %s, jobName: %s, scriptContent: %s", clusterInfo.Name, jobName, scriptContent)
return nil, fmt.Errorf("网络请求失败,请稍后重试")
}
@ -362,7 +357,7 @@ func (l *CommitHpcTaskLogic) CommitHpcTask(req *types.CommitHpcTaskReq) (resp *t
workDir := resp.Data.JobInfo["jobDir"]
taskID, err := l.SaveHpcTaskToDB(req, scriptContent, jobID, workDir)
if err != nil {
log.Error().Msgf("超算任务保存到数据库失败, cluster: %s, jobName: %s, error: %v", clusterInfo.Name, jobName, err)
log.Error().Msgf("超算任务保存到数据库失败, cluster: %s, jobName: %s, scriptContent: %s, error: %v", clusterInfo.Name, jobName, scriptContent, err)
return nil, fmt.Errorf("保存超算任务到数据库失败: %w", err)
}

View File

@ -3,7 +3,6 @@ package hpc
import (
"context"
"fmt"
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/scheduler/service"
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/svc"
@ -48,9 +47,13 @@ func (l *GetHpcTaskLogLogic) GetHpcTaskLog(req *types.HpcTaskLogReq) (resp inter
if hpcR.ID == 0 {
return nil, fmt.Errorf("任务不存在")
}
// 获取作业任务日志
resp, err = l.hpcService.HpcExecutorClusterMap[hpcR.ClusterId].GetTaskLogs(l.ctx, hpcR.JobID, hpcR.ClusterId)
var adapterInfo types.AdapterInfo
l.svcCtx.DbEngin.Raw("SELECT * FROM `t_adapter` where id = ?", hpcR.AdapterId).Scan(&adapterInfo)
if adapterInfo.Id == "" {
return nil, fmt.Errorf("adapter not found")
}
// 取消作业
resp, err = l.hpcService.HpcExecutorAdapterMap[adapterInfo.Id].GetTaskLogs(l.ctx, hpcR.JobID, hpcR.ClusterId)
if err != nil {
return nil, err
}

View File

@ -2,13 +2,11 @@ package hpc
import (
"context"
"fmt"
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/scheduler/service/collector"
hpcservice "gitlink.org.cn/JointCloud/pcm-coordinator/internal/scheduler/service/hpc"
"github.com/go-resty/resty/v2"
"github.com/pkg/errors"
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/svc"
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/types"
"strconv"
"strings"
"gitlink.org.cn/JointCloud/pcm-hpc/slurm"
"github.com/zeromicro/go-zero/core/logx"
)
@ -29,49 +27,34 @@ func NewJobInfoLogic(ctx context.Context, svcCtx *svc.ServiceContext) *JobInfoLo
func (l *JobInfoLogic) JobInfo(req *types.JobInfoReq) (resp *types.JobInfoResp, err error) {
resp = &types.JobInfoResp{}
clusterInfo := &types.ClusterInfo{}
tx := l.svcCtx.DbEngin.Raw("select * from t_cluster where id = ?", req.ClusterId).Scan(clusterInfo)
var clusterInfo *types.ClusterInfo
tx := l.svcCtx.DbEngin.Raw("select * from t_cluster where id = ?", req.ClusterId).Scan(&clusterInfo)
if tx.Error != nil {
return nil, tx.Error
}
if strings.TrimSpace(clusterInfo.Id) == "" {
return nil, fmt.Errorf("cluster %d not found", req.ClusterId)
}
hpcCollector, err := l.resolveHpcCollector(clusterInfo)
// 查询p端调用地址
var adapterAddress string
l.svcCtx.DbEngin.Raw("SELECT server FROM `t_adapter` where id = ?", clusterInfo.AdapterId).Scan(&adapterAddress)
var jobResp slurm.GetJobResp
httpClient := resty.New().R()
_, err = httpClient.SetHeader("Content-Type", "application/json").
SetQueryParams(map[string]string{
"jobId": req.JobId,
"server": clusterInfo.Server,
"version": clusterInfo.Version,
"token": clusterInfo.Token,
"username": clusterInfo.Username,
}).
SetResult(&jobResp).
Get(adapterAddress + "/api/v1/job/info")
if err != nil {
return nil, err
}
task, err := hpcCollector.GetTaskDetail(l.ctx, req.JobId, clusterInfo.Id)
if err != nil {
return nil, err
if len(jobResp.Errors) != 0 {
return nil, errors.Errorf(jobResp.Errors[0].Description)
}
resp.JobId = task.Id
resp.JobState = task.Status
resp.CurrentWorkingDirectory = task.WorkDir
resp.JobId = jobResp.Jobs[0].JobId
resp.JobState = jobResp.Jobs[0].JobState
resp.CurrentWorkingDirectory = jobResp.Jobs[0].CurrentWorkingDirectory
return resp, nil
}
func (l *JobInfoLogic) resolveHpcCollector(clusterInfo *types.ClusterInfo) (collector.HPCCollector, error) {
if l.svcCtx.Scheduler != nil &&
l.svcCtx.Scheduler.HpcService != nil &&
l.svcCtx.Scheduler.HpcService.HpcExecutorClusterMap != nil {
if c, ok := l.svcCtx.Scheduler.HpcService.HpcExecutorClusterMap[clusterInfo.Id]; ok && c != nil {
return c, nil
}
}
if strings.TrimSpace(clusterInfo.Server) == "" {
return nil, fmt.Errorf("cluster %s server is empty", clusterInfo.Id)
}
clusterID, err := strconv.ParseInt(clusterInfo.Id, 10, 64)
if err != nil {
return nil, fmt.Errorf("parse cluster id %s failed: %w", clusterInfo.Id, err)
}
return hpcservice.NewHpc(clusterInfo.Server, clusterID, clusterInfo.Nickname), nil
}

View File

@ -2,7 +2,6 @@ package hpc
import (
"context"
"gitlink.org.cn/JointCloud/pcm-coordinator/pkg/models"
"github.com/zeromicro/go-zero/core/logx"
@ -49,7 +48,7 @@ func (l *ListInstanceCenterLogic) ListInstanceCenter(req *types.HpcInstanceCente
return resp, err
}
db = db.Where("deleted_at is null").Limit(limit).Offset(offset)
err = db.Order("status desc ,sort_order desc").Find(&list).Error
err = db.Order("created_at desc").Find(&list).Error
if err != nil {
return nil, err
}

View File

@ -1,60 +0,0 @@
package inference
import (
"context"
"errors"
"github.com/zeromicro/go-zero/core/logx"
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/svc"
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/types"
"strconv"
)
type InferenceTaskLogLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewInferenceTaskLogLogic(ctx context.Context, svcCtx *svc.ServiceContext) *InferenceTaskLogLogic {
return &InferenceTaskLogLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *InferenceTaskLogLogic) InferenceTaskLog(req *types.InferenceTaskLogReq) (resp *types.InferenceTaskLogResp, err error) {
resp = &types.InferenceTaskLogResp{}
taskId, err := strconv.ParseInt(req.TaskId, 10, 64)
if err != nil {
return nil, err
}
instance, err := l.svcCtx.Scheduler.AiStorages.GetInferDeployInstanceByTaskId(taskId)
if err != nil {
return nil, err
}
if instance == nil {
return nil, errors.New("deploy instance not found")
}
clusterId := strconv.Itoa(int(instance.ClusterId))
log, err := l.svcCtx.Scheduler.AiService.Ai.TaskInferenceLog(clusterId, instance.InstanceId)
if err != nil {
return nil, err
}
if log.Code != 200 {
return nil, errors.New(log.Message)
}
str, ok := log.Data.(string)
if ok {
resp.Log = str
} else {
return nil, errors.New("not a string")
}
return resp, nil
}

View File

@ -50,7 +50,7 @@ func (l *CreateDeployTaskLogic) CreateDeployTask(req *types.CreateDeployTaskReq)
return nil, errors.New("TaskName already exists")
}
taskId, err := l.svcCtx.Scheduler.AiStorages.SaveInferDeployTask("", req.TaskName, 0, req.ModelName, req.ModelType, req.TaskDesc)
taskId, err := l.svcCtx.Scheduler.AiStorages.SaveInferDeployTask(req.TaskName, 0, req.ModelName, req.ModelType, req.TaskDesc)
if err != nil {
return nil, err
}

View File

@ -5,14 +5,11 @@ import (
"encoding/json"
"errors"
"fmt"
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/participant"
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/scheduler/entity"
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/scheduler/schedulers/option"
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/scheduler/service/utils/status"
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/scheduler/service/utils/task"
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/scheduler/strategy"
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/storeLink"
"net/http"
"strconv"
"strings"
"sync"
@ -72,18 +69,18 @@ func (l *CreateInferenceTaskLogic) CreateInferenceTask(req *types.CreateInferenc
Cmd: "",
}
taskId, err := l.svcCtx.Scheduler.AiStorages.SaveInferDeployTask(req.Token, taskName, req.UserId, modelName, "", req.Description)
taskId, err := l.svcCtx.Scheduler.AiStorages.SaveInferDeployTask(taskName, req.UserId, modelName, "", req.Description)
if err != nil {
return nil, err
}
adapterClusterMap := make(map[string][]*strategy.AssignedCluster)
adapterClusterMap[l.svcCtx.Config.Participant.AdapterId] = assignedClusters
adapterClusterMap[AdapterId] = assignedClusters
err = l.createInferenceTask(taskId, adapterClusterMap, opt)
if err != nil {
if len(assignedClusters) != 0 {
_ = status.ReportInferenceStatusMessages(l.svcCtx, nil, taskName, strconv.FormatInt(taskId, 10), assignedClusters[0].ClusterId, "", false, err.Error())
_ = status.ReportInferenceStatusMessages(l.svcCtx, nil, taskName, strconv.FormatInt(taskId, 10), assignedClusters[0].ClusterId, "", false, "")
logx.Errorf("############ Report Infer Task Status Message Error %s", err.Error())
}
return nil, err
@ -110,11 +107,11 @@ func (l *CreateInferenceTaskLogic) createInferenceTask(taskId int64, adapterClus
cluster := c
buf <- true
go func() {
//opt, _ := cloneOption(option)
//
//updateInferOption(cluster, opt)
opt, _ := cloneOption(option)
err := l.createDeployInstance(taskId, aid, cluster)
updateInferOption(cluster, opt)
err := l.createDeployInstance(taskId, aid, cluster.ClusterId, opt)
if err != nil {
e := struct {
err error
@ -201,7 +198,6 @@ func generateClustersForTaskCreation(distributes types.DataDistribute, taskName
}
cluster.CodeId = jsonData.Id
cluster.CodeName = jsonData.Name
clusterMap[c.ClusterID] = cluster
}
}
@ -227,10 +223,11 @@ func generateClustersForTaskCreation(distributes types.DataDistribute, taskName
cluster, ok := clusterMap[c.ClusterID]
if ok {
cluster.ModelId += jsonData.Id + storeLink.SEMMI_COLON
cluster.ModelId = jsonData.Id
cluster.ModelName = jsonData.Name
}
}
}
for _, distribute := range distributes.Image {
@ -296,26 +293,16 @@ func generateModelName(clusters []*strategy.AssignedCluster) (string, error) {
return modelName, nil
}
func (l *CreateInferenceTaskLogic) createDeployInstance(taskId int64, adapterId string, c *strategy.AssignedCluster) error {
//cmap, found := l.svcCtx.Scheduler.AiService.InferenceAdapterMap[adapterId]
//if !found {
// return errors.New("adapterId not exist: " + adapterId)
//}
//iCluster, found := cmap[clusterId]
//if !found {
// return errors.New("clusterId not exist: " + clusterId)
//}
//insId, err := iCluster.CreateInferDeployInstance(l.ctx, opt)
//if err != nil {
// return err
//}
resp, err := l.runTask(c)
if err != nil {
return err
func (l *CreateInferenceTaskLogic) createDeployInstance(taskId int64, adapterId string, clusterId string, opt *option.InferOption) error {
cmap, found := l.svcCtx.Scheduler.AiService.InferenceAdapterMap[adapterId]
if !found {
return errors.New("adapterId not exist: " + adapterId)
}
insId, err := l.svcCtx.Scheduler.AiService.Cvt.ConvertToInferenceTaskResult(resp, c.ClusterId)
iCluster, found := cmap[clusterId]
if !found {
return errors.New("clusterId not exist: " + clusterId)
}
insId, err := iCluster.CreateInferDeployInstance(l.ctx, opt)
if err != nil {
return err
}
@ -324,7 +311,7 @@ func (l *CreateInferenceTaskLogic) createDeployInstance(taskId int64, adapterId
if err != nil {
return err
}
cid, err := strconv.ParseInt(c.ClusterId, 10, 64)
cid, err := strconv.ParseInt(clusterId, 10, 64)
if err != nil {
return err
}
@ -334,39 +321,16 @@ func (l *CreateInferenceTaskLogic) createDeployInstance(taskId int64, adapterId
return err
}
clusterName, err := l.svcCtx.Scheduler.AiStorages.GetClusterNameById(c.ClusterId)
clusterName, err := l.svcCtx.Scheduler.AiStorages.GetClusterNameById(clusterId)
if err != nil {
return err
}
detail, err := l.svcCtx.Scheduler.AiService.Ai.TaskInferenceDetail(c.ClusterId, insId)
ins, err := iCluster.GetInferDeployInstance(l.ctx, insId)
if err != nil {
return err
}
if detail.Code != http.StatusOK {
return errors.New(detail.Message)
}
//url, err := l.svcCtx.Ai.TaskInferenceUrl(c.ClusterId, insId)
//if err != nil {
// return err
//}
//
//if url.Code != http.StatusOK {
// return errors.New(url.Message)
//}
ins, err := l.svcCtx.Scheduler.AiService.Cvt.ConvertToDeployInstance(l.svcCtx.Scheduler.AiService.Ai, detail.Data, c.ClusterId, nil, false)
if err != nil {
return err
}
//ins, err := iCluster.GetInferDeployInstance(l.ctx, insId)
//if err != nil {
// return err
//}
_, err = l.svcCtx.Scheduler.AiStorages.SaveInferDeployInstance(taskId, ins.InstanceId, ins.InstanceName, aid, adapterName, cid, clusterName, ins.ModelName, ins.ModelType, ins.InferCard, ins.ClusterType)
if err != nil {
return err
@ -375,45 +339,6 @@ func (l *CreateInferenceTaskLogic) createDeployInstance(taskId int64, adapterId
return nil
}
func (l *CreateInferenceTaskLogic) runTask(c *strategy.AssignedCluster) (interface{}, error) {
param := &participant.TaskCreateInferParam{
Id: c.ClusterId,
Algorithm: struct {
Id string `json:"id"`
Name string `json:"name"`
}{
Id: c.CodeId,
Name: c.CodeName,
},
Model: struct {
Id string `json:"id"`
Name string `json:"name"`
}{
Id: c.ModelId,
Name: c.ModelName,
},
Image: struct {
Id string `json:"id"`
Name string `json:"name"`
}{
Id: c.ImageId,
},
Resource: struct {
ResourcesRequired []map[string]interface{} `json:"resourcesRequired"`
}{
ResourcesRequired: c.ResourcesRequired,
},
}
cresp, err := l.svcCtx.Scheduler.AiService.Ai.TaskCreateInfer(c.ClusterId, param)
if err != nil {
return nil, err
}
if cresp.Code != http.StatusOK {
return nil, errors.New(cresp.Message)
}
return cresp.Data, nil
}
func cloneOption(opt *option.InferOption) (*option.InferOption, error) {
origJSON, err := json.Marshal(opt)
if err != nil {

View File

@ -22,36 +22,20 @@ func NewDeployInstanceStatLogic(ctx context.Context, svcCtx *svc.ServiceContext)
}
}
func (l *DeployInstanceStatLogic) DeployInstanceStat(req *types.DeployInstanceStatReq, userName string, userId int64) (resp *types.DeployInstanceStatResp, err error) {
func (l *DeployInstanceStatLogic) DeployInstanceStat(req *types.DeployInstanceStatReq) (resp *types.DeployInstanceStatResp, err error) {
resp = &types.DeployInstanceStatResp{}
if userName != "" && userName != "admin" {
total, err := l.svcCtx.Scheduler.AiStorages.GetInferDeployInstanceTotalNumByUserId(userId)
if err != nil {
return nil, err
}
running, err := l.svcCtx.Scheduler.AiStorages.GetInferDeployInstanceRunningNumByUserId(userId)
if err != nil {
return nil, err
}
resp.Total = total
resp.Running = running
} else {
total, err := l.svcCtx.Scheduler.AiStorages.GetInferDeployInstanceTotalNum()
if err != nil {
return nil, err
}
running, err := l.svcCtx.Scheduler.AiStorages.GetInferDeployInstanceRunningNum()
if err != nil {
return nil, err
}
resp.Total = total
resp.Running = running
total, err := l.svcCtx.Scheduler.AiStorages.GetInferDeployInstanceTotalNum()
if err != nil {
return nil, err
}
running, err := l.svcCtx.Scheduler.AiStorages.GetInferDeployInstanceRunningNum()
if err != nil {
return nil, err
}
resp.Total = total
resp.Running = running
return resp, nil
}

View File

@ -2,11 +2,10 @@ package inference
import (
"context"
"errors"
"strconv"
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/svc"
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/types"
"net/http"
"strconv"
"github.com/zeromicro/go-zero/core/logx"
)
@ -28,35 +27,13 @@ func NewGetDeployInstanceLogic(ctx context.Context, svcCtx *svc.ServiceContext)
func (l *GetDeployInstanceLogic) GetDeployInstance(req *types.GetDeployInstanceReq) (resp *types.GetDeployInstanceResp, err error) {
resp = &types.GetDeployInstanceResp{}
taskId, err := strconv.ParseInt(req.TaskId, 10, 64)
if err != nil {
return nil, err
}
instance, err := l.svcCtx.Scheduler.AiService.Ai.Store.GetInferDeployInstanceByTaskId(taskId)
id, err := strconv.ParseInt(req.Id, 10, 64)
ins, err := l.svcCtx.Scheduler.AiStorages.GetInferDeployInstanceById(id)
if err != nil {
return nil, err
}
clusterId := strconv.Itoa(int(instance.ClusterId))
detail, err := l.svcCtx.Scheduler.AiService.Ai.TaskInferenceDetail(clusterId, instance.InstanceId)
if err != nil {
return nil, err
}
if detail.Code != http.StatusOK {
return nil, errors.New(detail.Message)
}
//url, err := l.svcCtx.Ai.TaskInferenceUrl(clusterId, instance.InstanceId)
//if err != nil {
// return nil, err
//}
//
//if url.Code != http.StatusOK {
// return nil, errors.New(url.Message)
//}
in, err := l.svcCtx.Scheduler.AiService.Cvt.ConvertToDeployInstance(l.svcCtx.Scheduler.AiService.Ai, detail.Data, clusterId, instance, true)
in, err := l.svcCtx.Scheduler.AiService.InferenceAdapterMap[strconv.FormatInt(ins.AdapterId, 10)][strconv.FormatInt(ins.ClusterId, 10)].GetInferDeployInstance(l.ctx, ins.InstanceId)
if err != nil {
return nil, err
}

View File

@ -22,35 +22,20 @@ func NewInferenceTaskStatLogic(ctx context.Context, svcCtx *svc.ServiceContext)
}
}
func (l *InferenceTaskStatLogic) InferenceTaskStat(req *types.InferenceTaskStatReq, userName string, userId int64) (resp *types.InferenceTaskStatResp, err error) {
func (l *InferenceTaskStatLogic) InferenceTaskStat(req *types.InferenceTaskStatReq) (resp *types.InferenceTaskStatResp, err error) {
resp = &types.InferenceTaskStatResp{}
if userName != "" && userName != "admin" {
total, err := l.svcCtx.Scheduler.AiStorages.GetInferDeployInstanceTotalNumByUserId(userId)
if err != nil {
return nil, err
}
running, err := l.svcCtx.Scheduler.AiStorages.GetInferDeployInstanceRunningNumByUserId(userId)
if err != nil {
return nil, err
}
resp.Total = total
resp.Running = running
} else {
total, err := l.svcCtx.Scheduler.AiStorages.GetInferDeployInstanceTotalNum()
if err != nil {
return nil, err
}
running, err := l.svcCtx.Scheduler.AiStorages.GetInferDeployInstanceRunningNum()
if err != nil {
return nil, err
}
resp.Total = total
resp.Running = running
total, err := l.svcCtx.Scheduler.AiStorages.GetInferenceTaskTotalNum()
if err != nil {
return nil, err
}
running, err := l.svcCtx.Scheduler.AiStorages.GetInferenceTaskRunningNum()
if err != nil {
return nil, err
}
resp.Total = total
resp.Running = running
return resp, nil
}

View File

@ -4,11 +4,8 @@ import (
"context"
"errors"
"github.com/zeromicro/go-zero/core/logx"
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/participant/utils"
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/scheduler/service/inference"
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/svc"
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/types"
"net/http"
"strconv"
)
@ -29,52 +26,26 @@ func NewStopDeployInstanceLogic(ctx context.Context, svcCtx *svc.ServiceContext)
func (l *StopDeployInstanceLogic) StopDeployInstance(req *types.StopDeployInstanceReq) (resp *types.StopDeployInstanceResp, err error) {
resp = &types.StopDeployInstanceResp{}
taskId, err := strconv.ParseInt(req.TaskId, 10, 64)
if err != nil {
return nil, err
}
instance, err := l.svcCtx.Scheduler.AiStorages.GetInferDeployInstanceByTaskId(taskId)
id, err := strconv.ParseInt(req.Id, 10, 64)
ins, err := l.svcCtx.Scheduler.AiStorages.GetInferDeployInstanceById(id)
if err != nil {
return nil, err
}
if instance == nil {
return nil, errors.New("deploy instance not found")
}
clusterId := strconv.Itoa(int(instance.ClusterId))
detail, err := l.svcCtx.Scheduler.AiService.Ai.TaskInferenceDetail(clusterId, instance.InstanceId)
in, err := l.svcCtx.Scheduler.AiService.InferenceAdapterMap[strconv.FormatInt(ins.AdapterId, 10)][strconv.FormatInt(ins.ClusterId, 10)].GetInferDeployInstance(l.ctx, ins.InstanceId)
if err != nil {
return nil, err
}
if detail.Code != http.StatusOK {
return nil, errors.New(detail.Message)
}
in, err := l.svcCtx.Scheduler.AiService.Cvt.ConvertToDeployInstance(l.svcCtx.Scheduler.AiService.Ai, detail.Data, clusterId, nil, false)
if err != nil {
return nil, err
}
// temporarily convert to type
deployInstance := &inference.DeployInstance{}
err = utils.InstanceToObj(in, deployInstance)
if err != nil {
return nil, err
}
if l.svcCtx.Scheduler.AiService.Si.CheckRunningStatus(deployInstance) {
stop, err := l.svcCtx.Scheduler.AiService.Ai.TaskInferenceStop(clusterId, instance.InstanceId)
if err != nil {
return nil, err
}
if stop.Code != http.StatusOK {
return nil, errors.New(stop.Message)
if l.svcCtx.Scheduler.AiService.Si.CheckRunningStatus(in) {
success := l.svcCtx.Scheduler.AiService.InferenceAdapterMap[req.AdapterId][req.ClusterId].StopInferDeployInstance(l.ctx, in.InstanceId)
if !success {
return nil, errors.New("stop instance failed")
}
}
instance.Status = "Updating"
err = l.svcCtx.Scheduler.AiStorages.UpdateInferDeployInstance(instance, true)
ins.Status = "Updating"
err = l.svcCtx.Scheduler.AiStorages.UpdateInferDeployInstance(ins, true)
if err != nil {
return nil, err
}

View File

@ -2,21 +2,20 @@ package schedule
import (
"context"
"encoding/json"
"errors"
"fmt"
"github.com/zeromicro/go-zero/core/logx"
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/scheduler/service/collector"
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/storeLink"
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/svc"
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/types"
"strconv"
"strings"
"sync"
"time"
)
const (
ADAPTERID = "1777144940456666666" // 异构适配器id
ADAPTERID = "1777144940459986944" // 异构适配器id
QUERY_TRAIN_RESOURCES = "train_resources"
QUERY_INFERENCE_RESOURCES = "inference_resources"
)
@ -72,7 +71,7 @@ func (l *QueryResourcesLogic) QueryResources(req *types.QueryResourcesReq) (resp
} else {
var clusters []types.ClusterInfo
for _, id := range req.ClusterIDs {
cluster, err := l.svcCtx.Scheduler.AiStorages.GetStorageScheduledClustersById(id)
cluster, err := l.svcCtx.Scheduler.AiStorages.GetClustersById(id)
if err != nil {
return nil, err
}
@ -118,48 +117,22 @@ func (l *QueryResourcesLogic) QueryResourcesByClusterId(clusterinfos []types.Clu
defer wg.Done()
done := make(chan bool)
var u *collector.ResourceSpec
//var err error
var err error
go func() {
specs, err := l.svcCtx.Scheduler.AiService.Ai.ResourceSpecs(c.Id, resrcType)
col, found := l.svcCtx.Scheduler.AiService.AiCollectorAdapterMap[strconv.FormatInt(c.AdapterId, 10)][c.Id]
if !found {
done <- true
return
}
u, err = col.GetResourceSpecs(l.ctx, resrcType)
if err != nil {
logx.Error(err)
done <- true
return
}
if specs.Code != 200 {
logx.Error(specs.Message)
done <- true
return
}
bytes, err := json.Marshal(specs.Data)
if err != nil {
logx.Error(err)
done <- true
return
}
u, err = parseResourceSpec(bytes)
if err != nil {
logx.Error(err)
done <- true
return
}
//col, found := l.svcCtx.Scheduler.AiService.AiCollectorAdapterMap[strconv.FormatInt(c.AdapterId, 10)][c.Id]
//if !found {
// done <- true
// return
//}
//
//u, err = col.GetResourceSpecs(l.ctx, resrcType)
//if err != nil {
// logx.Error(err)
// done <- true
// return
//}
done <- true
}()
@ -237,61 +210,6 @@ func handleEmptyResourceUsage(list []types.ClusterInfo, ulist []*collector.Resou
return rus
}
func parseResourceSpec(jsonData []byte) (*collector.ResourceSpec, error) {
auxiliary := struct {
ClusterId string `json:"clusterID"`
ClusterType string `json:"clusterType"`
Region string `json:"region"`
Tag string `json:"tag"`
Resources json.RawMessage `json:"resources"`
Msg string `json:"msg"`
}{}
if err := json.Unmarshal(jsonData, &auxiliary); err != nil {
return nil, err
}
resources, err := convertRawMessageToInterfaceSlice(auxiliary.Resources)
if err != nil {
return nil, err
}
return &collector.ResourceSpec{
ClusterId: auxiliary.ClusterId,
ClusterType: auxiliary.ClusterType,
Region: auxiliary.Region,
Tag: auxiliary.Tag,
Resources: resources,
Msg: auxiliary.Msg,
}, nil
}
func convertRawMessageToInterfaceSlice(raw json.RawMessage) ([]interface{}, error) {
if len(raw) == 0 || string(raw) == "null" {
return []interface{}{}, nil
}
// 尝试解析为数组
var slice []interface{}
if err := json.Unmarshal(raw, &slice); err == nil {
return slice, nil
}
// 尝试解析为单个对象
var single interface{}
if err := json.Unmarshal(raw, &single); err == nil {
return []interface{}{single}, nil
}
// 尝试解析为其他类型(字符串、数字等)
var value interface{}
if err := json.Unmarshal(raw, &value); err == nil {
return []interface{}{value}, nil
}
return nil, fmt.Errorf("invalid resources format")
}
func checkCachingCondition(clusters []types.ClusterInfo, specs []*collector.ResourceSpec) bool {
var count int
for _, spec := range specs {

View File

@ -3,7 +3,6 @@ package schedule
import (
"context"
"fmt"
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/scheduler/entity"
"slices"
"strings"
"time"
@ -27,6 +26,11 @@ const (
QUERY_RESOURCE_RETRY = 3
)
type ClustersWithDataDistributes struct {
Clusters []*strategy.AssignedCluster
DataDistributes *types.DataDistribute
}
type ScheduleCreateTaskLogic struct {
logx.Logger
ctx context.Context
@ -43,18 +47,14 @@ func NewScheduleCreateTaskLogic(ctx context.Context, svcCtx *svc.ServiceContext)
}
}
func (l *ScheduleCreateTaskLogic) generateFilteredDataDistributes(clusters []*strategy.AssignedCluster, distribute types.DataDistribute) *entity.ClustersWithDataDistributes {
func generateFilteredDataDistributes(clusters []*strategy.AssignedCluster, distribute types.DataDistribute) *ClustersWithDataDistributes {
var clusterIds []string
for _, c := range clusters {
clusterName, _ := l.svcCtx.Scheduler.AiStorages.GetClusterNameById(c.ClusterId)
if clusterName != "" {
c.ClusterName = clusterName
}
clusterIds = append(clusterIds, c.ClusterId)
}
clustersWithDataDistributes := &entity.ClustersWithDataDistributes{
clustersWithDataDistributes := &ClustersWithDataDistributes{
Clusters: clusters,
DataDistributes: &types.DataDistribute{
Dataset: make([]*types.DatasetDistribute, 0),
@ -166,7 +166,7 @@ func (l *ScheduleCreateTaskLogic) ScheduleCreateTask(req *types.CreateTaskReq) (
}}, req.JobResources.Clusters, "")
// filter data distribution
clustersWithDataDistributes := l.generateFilteredDataDistributes(assignedClusters, req.DataDistributes)
clustersWithDataDistributes := generateFilteredDataDistributes(assignedClusters, req.DataDistributes)
taskId, err := l.createTask(taskName, req.Description, req.UserId, req.JobResources.ScheduleStrategy, clustersWithDataDistributes, req.Token, req.UserIp, req.UserName)
if err != nil {
@ -197,7 +197,7 @@ func (l *ScheduleCreateTaskLogic) ScheduleCreateTask(req *types.CreateTaskReq) (
}
// filter data distribution
clustersWithDataDistributes := l.generateFilteredDataDistributes(assignedClusters, req.DataDistributes)
clustersWithDataDistributes := generateFilteredDataDistributes(assignedClusters, req.DataDistributes)
taskId, err := l.createTask(taskName, req.Description, req.UserId, req.JobResources.ScheduleStrategy, clustersWithDataDistributes, req.Token, req.UserIp, req.UserName)
if err != nil {
@ -263,7 +263,7 @@ func (l *ScheduleCreateTaskLogic) getAssignedClustersByStrategy(resources *types
return assignedClusters, nil
}
func (l *ScheduleCreateTaskLogic) createTask(taskName string, desc string, userId int64, strategyName string, clustersWithDataDistributes *entity.ClustersWithDataDistributes, token string, userIp string, userName string) (int64, error) {
func (l *ScheduleCreateTaskLogic) createTask(taskName string, desc string, userId int64, strategyName string, clustersWithDataDistributes *ClustersWithDataDistributes, token string, userIp string, userName string) (int64, error) {
var synergyStatus int64
if len(clustersWithDataDistributes.Clusters) > 1 {
synergyStatus = 1
@ -397,11 +397,11 @@ func (l *ScheduleCreateTaskLogic) updateStorageType(schedatas *[]*types.Schedule
var storageType string
var sTypes []string
for _, id := range s.ClusterIDs {
cluster, err := l.svcCtx.Scheduler.AiStorages.GetStorageScheduledClustersById(id)
cluster, err := l.svcCtx.Scheduler.AiStorages.GetClustersById(id)
if err != nil {
return err
}
stype, ok := storeLink.StorageTypeMap[strings.Title(cluster.Driver)]
stype, ok := storeLink.StorageTypeMap[strings.Title(cluster.Name)]
if ok {
sTypes = append(sTypes, stype)
}

View File

@ -2,9 +2,6 @@ package schedule
import (
"context"
"errors"
"gitlink.org.cn/JointCloud/pcm-coordinator/pkg/constants"
"strconv"
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/svc"
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/types"
@ -29,51 +26,15 @@ func NewScheduleGetAiJobLogLogLogic(ctx context.Context, svcCtx *svc.ServiceCont
func (l *ScheduleGetAiJobLogLogLogic) ScheduleGetAiJobLogLog(req *types.AiJobLogReq) (resp *types.AiJobLogResp, err error) {
resp = &types.AiJobLogResp{}
taskId, err := strconv.ParseInt(req.TaskId, 10, 64)
id, err := l.svcCtx.Scheduler.AiStorages.GetAiTaskIdByClusterIdAndTaskId(req.ClusterId, req.TaskId)
if err != nil {
return nil, err
}
task, err := l.svcCtx.Scheduler.AiStorages.GetTaskById(taskId)
log, err := l.svcCtx.Scheduler.AiService.AiCollectorAdapterMap[req.AdapterId][req.ClusterId].GetTrainingTaskLog(l.ctx, id, req.InstanceNum)
if err != nil {
return nil, err
}
aiTasks, err := l.svcCtx.Scheduler.AiStorages.GetAiTasksByTaskId(req.TaskId)
if err != nil {
return nil, err
}
if len(aiTasks) == 0 && task.Status == constants.Failed {
return nil, errors.New("submit failed, no log available")
} else if len(aiTasks) > 1 {
return nil, errors.New("multiple ai task found")
}
aiTask := aiTasks[0]
//adapterId := strconv.FormatInt(aiTask.AdapterId, 10)
clusterId := strconv.FormatInt(aiTask.ClusterId, 10)
if aiTask.Msg != "" {
resp.Log = aiTask.Msg
return resp, nil
}
jobId := aiTask.JobId
log, err := l.svcCtx.Scheduler.AiService.Ai.TaskLog(clusterId, jobId)
if err != nil {
return nil, err
}
if log.Code != 200 {
return nil, errors.New(log.Message)
}
str, ok := log.Data.(string)
if ok {
resp.Log = str
} else {
return nil, errors.New("not a string")
}
resp.Log = log
return resp, nil
}

View File

@ -5,19 +5,18 @@ import (
"encoding/json"
"errors"
"fmt"
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/scheduler/service/executor"
"strings"
"github.com/zeromicro/go-zero/core/logx"
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/scheduler/entity"
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/scheduler/schedulers"
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/scheduler/schedulers/option"
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/scheduler/service/executor"
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/scheduler/strategy"
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/svc"
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/types"
"gitlink.org.cn/JointCloud/pcm-coordinator/pkg/constants"
"gitlink.org.cn/JointCloud/pcm-coordinator/pkg/models"
"gopkg.in/yaml.v2"
"strings"
)
type ScheduleRunTaskLogic struct {
@ -60,39 +59,25 @@ func (l *ScheduleRunTaskLogic) ScheduleRunTask(req *types.RunTaskReq) (resp *typ
}
}
var clustersWithDataDistributes entity.ClustersWithDataDistributes
var clustersWithDataDistributes ClustersWithDataDistributes
err = yaml.Unmarshal([]byte(task.YamlString), &clustersWithDataDistributes)
if err != nil {
return nil, err
}
opt := &option.AiOption{
AdapterId: ADAPTERID,
TaskName: task.Name,
TaskId: task.Id,
StrategyName: "",
}
// update assignedClusters
assignedClusters, err := updateClustersByScheduledDatas(task.Id, &clustersWithDataDistributes, req.ScheduledDatas)
if err != nil {
opt := &option.AiOption{
AdapterId: l.svcCtx.Config.Participant.AdapterId,
TaskName: task.Name,
TaskId: task.Id,
StrategyName: "",
ResourcesRequired: clustersWithDataDistributes.Clusters[0].ResourcesRequired,
}
clusterId := clustersWithDataDistributes.Clusters[0].ClusterId
clusterName := clustersWithDataDistributes.Clusters[0].ClusterName
err = l.svcCtx.Scheduler.AiStorages.SaveAiTask(task.Id, opt, "", clusterId, clusterName, "", constants.Failed, err.Error())
if err != nil {
return nil, err
}
return nil, err
}
opt := &option.AiOption{
AdapterId: ADAPTERID,
TaskName: task.Name,
TaskId: task.Id,
StrategyName: "",
ResourcesRequired: clustersWithDataDistributes.Clusters[0].ResourcesRequired,
}
aiSchdl, err := schedulers.NewAiScheduler(l.ctx, "", l.svcCtx.Scheduler, opt)
if err != nil {
return nil, err
@ -141,7 +126,7 @@ func (l *ScheduleRunTaskLogic) SaveResult(task *models.Task, results []*schedule
}
func updateClustersByScheduledDatas(taskId int64, clustersWithDataDistributes *entity.ClustersWithDataDistributes, scheduledDatas []*types.DataScheduleResults) ([]*strategy.AssignedCluster, error) {
func updateClustersByScheduledDatas(taskId int64, clustersWithDataDistributes *ClustersWithDataDistributes, scheduledDatas []*types.DataScheduleResults) ([]*strategy.AssignedCluster, error) {
assignedClusters := make([]*strategy.AssignedCluster, 0)
if len(scheduledDatas) == 0 {
@ -169,7 +154,6 @@ func updateClustersByScheduledDatas(taskId int64, clustersWithDataDistributes *e
return nil, fmt.Errorf("pass-in jsonData convert failed, task %d, cluster %s, datatype: %s", taskId, cluster.ClusterId, "dataset")
}
cluster.DatasetId = jsonData.Id
cluster.DatasetName = jsonData.Name
}
}
}
@ -208,7 +192,6 @@ func updateClustersByScheduledDatas(taskId int64, clustersWithDataDistributes *e
return nil, fmt.Errorf("pass-in jsonData convert failed, task %d, cluster %s, datatype: %s", taskId, cluster.ClusterId, "code")
}
cluster.CodeId = jsonData.Id
cluster.CodeName = jsonData.Name
}
}
}
@ -252,7 +235,6 @@ func updateClustersByScheduledDatas(taskId int64, clustersWithDataDistributes *e
return nil, fmt.Errorf("db yaml jsonData convert failed, task %d, cluster %s, datatype: %s", taskId, cluster.ClusterId, "dataset")
}
cluster.DatasetId = jsonData.Id
cluster.DatasetName = jsonData.Name
}
}
}
@ -293,7 +275,6 @@ func updateClustersByScheduledDatas(taskId int64, clustersWithDataDistributes *e
return nil, fmt.Errorf("db yaml jsonData convert failed, task %d, cluster %s, datatype: %s", taskId, cluster.ClusterId, "code")
}
cluster.CodeId = jsonData.Id
cluster.CodeName = jsonData.Name
}
}
@ -312,7 +293,7 @@ func updateClustersByScheduledDatas(taskId int64, clustersWithDataDistributes *e
if err != nil {
return nil, fmt.Errorf("jsonData convert failed, task %d, cluster %s, datatype: %s", taskId, cluster.ClusterId, "model")
}
cluster.ModelId += jsonData.Id + ";"
cluster.ModelId = jsonData.Id
}
}
}

View File

@ -1,33 +0,0 @@
package security
import "gitlink.org.cn/JointCloud/pcm-coordinator/internal/types"
func SanitizeClusterSecret(cluster *types.ClusterInfo) {
if cluster == nil {
return
}
cluster.Username = ""
cluster.Password = ""
cluster.Token = ""
cluster.Ak = ""
cluster.Sk = ""
cluster.PrivateKey = ""
cluster.Passphrase = ""
}
func SanitizeClusterSecretList(clusters []types.ClusterInfo) {
for i := range clusters {
SanitizeClusterSecret(&clusters[i])
}
}
func SanitizeClusterRelationSecret(info *types.ClusterRelationInfo) {
if info == nil {
return
}
info.CUsername = ""
info.CPassword = ""
info.CToken = ""
info.CAk = ""
info.CSk = ""
}

View File

@ -0,0 +1,40 @@
package storage
import (
"context"
"gitlink.org.cn/JointCloud/pcm-coordinator/pkg/utils/httputils"
"k8s.io/apimachinery/pkg/util/json"
"strings"
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/svc"
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/types"
"github.com/zeromicro/go-zero/core/logx"
)
type DailyPowerScreenLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewDailyPowerScreenLogic(ctx context.Context, svcCtx *svc.ServiceContext) *DailyPowerScreenLogic {
return &DailyPowerScreenLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *DailyPowerScreenLogic) DailyPowerScreen() (resp *types.DailyPowerScreenResp, err error) {
resp = &types.DailyPowerScreenResp{}
statusCode, body, err := httputils.HttpClientWithScreen(httputils.GET, "https://grampus.openi.org.cn/openapi/v1/sharescreen/computepower/dailytrend", strings.NewReader(``))
if statusCode == 200 {
json.Unmarshal(body, &resp.Chart)
println(resp)
} else if statusCode != 200 {
return nil, err
}
return resp, nil
}

View File

@ -0,0 +1,39 @@
package storage
import (
"context"
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/svc"
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/types"
"gitlink.org.cn/JointCloud/pcm-coordinator/pkg/utils/httputils"
"k8s.io/apimachinery/pkg/util/json"
"strings"
"github.com/zeromicro/go-zero/core/logx"
)
type PerCenterComputerPowersLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewPerCenterComputerPowersLogic(ctx context.Context, svcCtx *svc.ServiceContext) *PerCenterComputerPowersLogic {
return &PerCenterComputerPowersLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *PerCenterComputerPowersLogic) PerCenterComputerPowers() (resp *types.PerCenterComputerPowersResp, err error) {
resp = &types.PerCenterComputerPowersResp{}
statusCode, body, err := httputils.HttpClientWithScreen(httputils.GET, "https://grampus.openi.org.cn/openapi/v1/sharescreen/computepower/percenter", strings.NewReader(``))
if statusCode == 200 {
json.Unmarshal(body, &resp.Chart)
println(resp)
} else if statusCode != 200 {
return nil, err
}
return resp, nil
}

View File

@ -0,0 +1,30 @@
package storage
import (
"context"
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/svc"
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/types"
"github.com/zeromicro/go-zero/core/logx"
)
type ScreenStorageLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewScreenStorageLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ScreenStorageLogic {
return &ScreenStorageLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *ScreenStorageLogic) ScreenStorage(req *types.StorageScreenReq) (resp *types.StorageScreenResp, err error) {
// todo: add your logic here and delete this line
return
}

View File

@ -1,167 +0,0 @@
package xjlab
import (
"context"
"fmt"
"strings"
"github.com/zeromicro/go-zero/core/logx"
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/scheduler/service"
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/svc"
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/types"
)
type ComputeDomainInfoLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
hpcService *service.HpcService
}
func NewComputeDomainInfoLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ComputeDomainInfoLogic {
cache := make(map[string]interface{}, 10)
hpcService, err := service.NewHpcService(&svcCtx.Config, svcCtx.Scheduler.HpcStorages, cache)
if err != nil {
return nil
}
return &ComputeDomainInfoLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
hpcService: hpcService,
}
}
// ComputeDomainInfo 计算域信息
func (l *ComputeDomainInfoLogic) ComputeDomainInfo(req *types.XJLABCommonReq) (interface{}, error) {
logx.Infof("ComputeDomainInfo req: %+v", req)
// ClusterResource 集群资源信息
type ClusterResource struct {
ClusterID string `json:"clusterId"`
ClusterName string `json:"clusterName"`
TotalCPU string `json:"totalCpu"`
TotalRAM string `json:"totalRam"`
TotalVRAM string `json:"totalVram"`
TotalDisk string `json:"totalDisk"`
SpecCount string `json:"specCount"`
Driver string `json:"driver"`
ClusterType string `json:"clusterType"`
}
// resourceQueryResult SQL查询结果
type resourceQueryResult struct {
ClusterID string `json:"clusterId" gorm:"column:cluster_id"`
ResourceType string `json:"resourceType" gorm:"column:resource_type"`
ResourceName string `json:"resourceName" gorm:"column:resource_name"`
Unit string `json:"unit" gorm:"column:unit"`
TotalCapacity string `json:"totalCapacity" gorm:"column:total_capacity"`
SpecCount string `json:"specCount" gorm:"column:spec_count"`
}
// clusterInfo 集群基本信息
type clusterInfo struct {
ID string `json:"id" gorm:"column:id"`
Name string `json:"name" gorm:"column:name"`
Driver string `json:"driver" gorm:"column:driver"`
ClusterType string `json:"clusterType" gorm:"column:cluster_type"`
}
// 查询资源信息
const sqlStr = `
SELECT
rs.cluster_id,
brs.type as resource_type,
brs.name as resource_name,
brs.total_unit as unit,
SUM(brs.total_value) as total_capacity,
COUNT(DISTINCT rs.id) as spec_count
FROM t_resource_spec rs
INNER JOIN t_base_resource_spec brs ON rs.id = brs.resource_spec_id
WHERE rs.deleted_at IS NULL
AND brs.deleted_at IS NULL
AND rs.change_type != 2
GROUP BY rs.cluster_id, brs.type, brs.name, brs.total_unit
ORDER BY rs.cluster_id, brs.name`
var resources []*resourceQueryResult
if err := l.svcCtx.DbEngin.Raw(sqlStr).Scan(&resources).Error; err != nil {
logx.Errorf("failed to query resource specs: %v", err)
return nil, fmt.Errorf("查询资源规格失败: %w", err)
}
if len(resources) == 0 {
return []*ClusterResource{}, nil
}
// 聚合每个集群的资源信息
clusterMap := make(map[string]*ClusterResource)
for _, res := range resources {
cr, exists := clusterMap[res.ClusterID]
if !exists {
cr = &ClusterResource{
ClusterID: res.ClusterID,
TotalCPU: "0",
TotalRAM: "0",
TotalVRAM: "0",
TotalDisk: "0",
SpecCount: "0",
}
clusterMap[res.ClusterID] = cr
}
// 设置资源值
resourceType := strings.ToUpper(res.ResourceType)
resourceName := strings.ToUpper(res.ResourceName)
switch resourceType {
case "CPU":
cr.TotalCPU = res.TotalCapacity
case "MEMORY":
if resourceName == "RAM" {
cr.TotalRAM = res.TotalCapacity
} else if resourceName == "VRAM" {
cr.TotalVRAM = res.TotalCapacity
}
case "STORAGE":
cr.TotalDisk = res.TotalCapacity
}
cr.SpecCount = res.SpecCount
}
// 获取集群基本信息
clusterIDs := make([]string, 0, len(clusterMap))
for clusterID := range clusterMap {
clusterIDs = append(clusterIDs, clusterID)
}
var clusterList []*clusterInfo
if len(clusterIDs) > 0 {
err := l.svcCtx.DbEngin.
Table("t_cluster").
Select("id, name, driver, cluster_type").
Where("id IN ?", clusterIDs).
Find(&clusterList).Error
if err != nil {
logx.Errorf("failed to query cluster info: %v", err)
return nil, fmt.Errorf("获取集群信息失败: %w", err)
}
}
// 更新集群名称等信息
for _, cl := range clusterList {
if cr, exists := clusterMap[cl.ID]; exists {
cr.ClusterName = cl.Name
cr.Driver = cl.Driver
cr.ClusterType = cl.ClusterType
}
}
// 转换为结果列表
result := make([]*ClusterResource, 0, len(clusterMap))
for _, cr := range clusterMap {
result = append(result, cr)
}
return result, nil
}

View File

@ -1,69 +0,0 @@
package xjlab
import (
"context"
"github.com/zeromicro/go-zero/core/logx"
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/scheduler/service"
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/svc"
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/types"
"gitlink.org.cn/JointCloud/pcm-coordinator/pkg/constants"
)
type ComputeTypeRatioLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
hpcService *service.HpcService
}
func NewComputeTypeRatioLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ComputeTypeRatioLogic {
cache := make(map[string]interface{}, 10)
hpcService, err := service.NewHpcService(&svcCtx.Config, svcCtx.Scheduler.HpcStorages, cache)
if err != nil {
return nil
}
return &ComputeTypeRatioLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
hpcService: hpcService,
}
}
func (l *ComputeTypeRatioLogic) ComputeTypeRatio(req *types.XJLABCommonReq) (resp interface{}, err error) {
logx.Infof("ComputeTypeRatio req: %+v", req)
type computeTypeRatioResp struct {
ClusterType string `json:"clusterType"`
Count int `json:"count"`
Name string `json:"name"`
Ratio float64 `json:"ratio"`
}
var ctR []*computeTypeRatioResp
//计算各个cluster_type的占比
err = l.svcCtx.DbEngin.Raw("select count(*) as count,cluster_type from t_cluster where deleted_at is null group by cluster_type").Scan(&ctR).Error
if err != nil {
return nil, err
}
sum := 0
for _, v := range ctR {
sum += v.Count
}
for _, v := range ctR {
switch v.ClusterType {
case constants.AdapterTypeCloud:
v.Name = "云算资源"
v.Ratio = float64(v.Count) / float64(sum)
case constants.AdapterTypeAI:
v.Name = "智算资源"
v.Ratio = float64(v.Count) / float64(sum)
case constants.AdapterTypeHPC:
v.Name = "超算资源"
v.Ratio = float64(v.Count) / float64(sum)
default:
v.Name = "未知"
v.Ratio = float64(v.Count) / float64(sum)
}
}
return ctR, nil
}

View File

@ -1,85 +0,0 @@
package xjlab
import (
"context"
"fmt"
"github.com/zeromicro/go-zero/core/logx"
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/scheduler/service"
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/svc"
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/types"
)
type ComputerPowerListLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
hpcService *service.HpcService
}
func NewComputerPowerListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ComputerPowerListLogic {
cache := make(map[string]interface{}, 10)
hpcService, err := service.NewHpcService(&svcCtx.Config, svcCtx.Scheduler.HpcStorages, cache)
if err != nil {
return nil
}
return &ComputerPowerListLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
hpcService: hpcService,
}
}
type ComputingPower struct {
Provider string `json:"provider"`
Cluster string `json:"cluster"`
Type string `json:"type"`
Tops string `json:"tops"`
Mode string `json:"mode"`
}
type Stats struct {
TotalCenters int `json:"totalCenters"`
TotalComputingPower float64 `json:"totalComputingPower"`
ConnectedClusters int `json:"connectedClusters"`
}
type ComputerPowerResponse struct {
ComputingPowers []ComputingPower `json:"computingPowers"`
TotalCenters int `json:"totalCenters"`
TotalComputingPower float64 `json:"totalComputingPower"`
ConnectedClusters int `json:"connectedClusters"`
}
func (l *ComputerPowerListLogic) ComputerPowerList(req *types.XJLABCommonReq) (*ComputerPowerResponse, error) {
logx.Infof("ComputerPowerList req: %+v", req)
var (
computingPowers []ComputingPower
stats Stats
)
if err := l.svcCtx.DbEngin.Raw("SELECT provider, cluster, type, tops, mode FROM computing_power").Scan(&computingPowers).Error; err != nil {
return nil, fmt.Errorf("failed to fetch computing powers: %w", err)
}
sqlStr := `SELECT
COUNT(DISTINCT provider) as total_centers,
COALESCE(SUM(CAST(tops AS FLOAT)), 0) as total_computing_power,
COUNT(DISTINCT cluster) as connected_clusters
FROM computing_power`
if err := l.svcCtx.DbEngin.Raw(sqlStr).Scan(&stats).Error; err != nil {
return nil, fmt.Errorf("failed to fetch stats: %w", err)
}
response := &ComputerPowerResponse{
ComputingPowers: computingPowers,
TotalCenters: stats.TotalCenters,
TotalComputingPower: stats.TotalComputingPower,
ConnectedClusters: stats.ConnectedClusters,
}
return response, nil
}

Some files were not shown because too many files have changed in this diff Show More