Signed-off-by: devad <cossjie@foxmail.com>
Former-commit-id: c860a80b83
pull/9/head
| @@ -0,0 +1,9 @@ | |||
| package config | |||
| import {{.authImport}} | |||
| type Config struct { | |||
| rest.RestConf | |||
| {{.auth}} | |||
| {{.jwtTrans}} | |||
| } | |||
| @@ -0,0 +1,17 @@ | |||
| package svc | |||
| import ( | |||
| {{.configImport}} | |||
| ) | |||
| type ServiceContext struct { | |||
| Config {{.config}} | |||
| {{.middleware}} | |||
| } | |||
| func NewServiceContext(c {{.config}}) *ServiceContext { | |||
| return &ServiceContext{ | |||
| Config: c, | |||
| {{.middlewareAssignment}} | |||
| } | |||
| } | |||
| @@ -0,0 +1,3 @@ | |||
| Name: {{.serviceName}} | |||
| Host: {{.host}} | |||
| Port: {{.port}} | |||
| @@ -0,0 +1,24 @@ | |||
| package {{.PkgName}} | |||
| import ( | |||
| "net/http" | |||
| "PCM/common/result" | |||
| "github.com/zeromicro/go-zero/rest/httpx" | |||
| {{.ImportPackages}} | |||
| ) | |||
| func {{.HandlerName}}(svcCtx *svc.ServiceContext) http.HandlerFunc { | |||
| return func(w http.ResponseWriter, r *http.Request) { | |||
| {{if .HasRequest}}var req types.{{.RequestType}} | |||
| if err := httpx.Parse(r, &req); err != nil { | |||
| result.ParamErrorResult(r,w,err) | |||
| return | |||
| } | |||
| {{end}}l := {{.LogicName}}.New{{.LogicType}}(r.Context(), svcCtx) | |||
| {{if .HasResp}}resp, {{end}}err := l.{{.Call}}({{if .HasRequest}}&req{{end}}) | |||
| result.HttpResult(r, w, {{if .HasResp}}resp{{else}}nil{{end}}, err) | |||
| } | |||
| } | |||
| @@ -0,0 +1,25 @@ | |||
| package {{.pkgName}} | |||
| import ( | |||
| {{.imports}} | |||
| ) | |||
| type {{.logic}} struct { | |||
| logx.Logger | |||
| ctx context.Context | |||
| svcCtx *svc.ServiceContext | |||
| } | |||
| func New{{.logic}}(ctx context.Context, svcCtx *svc.ServiceContext) *{{.logic}} { | |||
| return &{{.logic}}{ | |||
| Logger: logx.WithContext(ctx), | |||
| ctx: ctx, | |||
| svcCtx: svcCtx, | |||
| } | |||
| } | |||
| func (l *{{.logic}}) {{.function}}({{.request}}) {{.responseType}} { | |||
| // todo: add your logic here and delete this line | |||
| {{.returnString}} | |||
| } | |||
| @@ -0,0 +1,26 @@ | |||
| package main | |||
| import ( | |||
| "flag" | |||
| "fmt" | |||
| {{.importPackages}} | |||
| ) | |||
| var configFile = flag.String("f", "etc/{{.serviceName}}.yaml", "the config file") | |||
| func main() { | |||
| flag.Parse() | |||
| var c config.Config | |||
| conf.MustLoad(*configFile, &c) | |||
| server := rest.MustNewServer(c.RestConf) | |||
| defer server.Stop() | |||
| ctx := svc.NewServiceContext(c) | |||
| handler.RegisterHandlers(server, ctx) | |||
| fmt.Printf("Starting server at %s:%d...\n", c.Host, c.Port) | |||
| server.Start() | |||
| } | |||
| @@ -0,0 +1,19 @@ | |||
| package middleware | |||
| import "net/http" | |||
| type {{.name}} struct { | |||
| } | |||
| func New{{.name}}() *{{.name}} { | |||
| return &{{.name}}{} | |||
| } | |||
| func (m *{{.name}})Handle(next http.HandlerFunc) http.HandlerFunc { | |||
| return func(w http.ResponseWriter, r *http.Request) { | |||
| // TODO generate middleware implement function, delete after code implementation | |||
| // Passthrough to next handler if need | |||
| next(w, r) | |||
| } | |||
| } | |||
| @@ -0,0 +1,4 @@ | |||
| server.AddRoutes( | |||
| {{.routes}} {{.jwt}}{{.signature}} {{.prefix}} {{.timeout}} | |||
| ) | |||
| @@ -0,0 +1,13 @@ | |||
| // Code generated by goctl. DO NOT EDIT. | |||
| package handler | |||
| import ( | |||
| "net/http"{{if .hasTimeout}} | |||
| "time"{{end}} | |||
| {{.importPackages}} | |||
| ) | |||
| func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) { | |||
| {{.routesAdditions}} | |||
| } | |||
| @@ -0,0 +1,24 @@ | |||
| syntax = "v1" | |||
| info ( | |||
| title: // TODO: add title | |||
| desc: // TODO: add description | |||
| author: "{{.gitUser}}" | |||
| email: "{{.gitEmail}}" | |||
| ) | |||
| type request { | |||
| // TODO: add members here and delete this comment | |||
| } | |||
| type response { | |||
| // TODO: add members here and delete this comment | |||
| } | |||
| service {{.serviceName}} { | |||
| @handler GetUser // TODO: set handler name and delete this comment | |||
| get /users/id/:userId(request) returns(response) | |||
| @handler CreateUser // TODO: set handler name and delete this comment | |||
| post /users/create(request) | |||
| } | |||
| @@ -0,0 +1,6 @@ | |||
| // Code generated by goctl. DO NOT EDIT. | |||
| package types{{if .containsTime}} | |||
| import ( | |||
| "time" | |||
| ){{end}} | |||
| {{.types}} | |||
| @@ -0,0 +1,33 @@ | |||
| FROM golang:{{.Version}}alpine AS builder | |||
| LABEL stage=gobuilder | |||
| ENV CGO_ENABLED 0 | |||
| {{if .Chinese}}ENV GOPROXY https://goproxy.cn,direct | |||
| RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories | |||
| {{end}}{{if .HasTimezone}} | |||
| RUN apk update --no-cache && apk add --no-cache tzdata | |||
| {{end}} | |||
| WORKDIR /build | |||
| ADD go.mod . | |||
| ADD go.sum . | |||
| RUN go mod download | |||
| COPY . . | |||
| {{if .Argument}}COPY {{.GoRelPath}}/etc /app/etc | |||
| {{end}}RUN go build -ldflags="-s -w" -o /app/{{.ExeFile}} {{.GoMainFrom}} | |||
| FROM {{.BaseImage}} | |||
| COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt | |||
| {{if .HasTimezone}}COPY --from=builder /usr/share/zoneinfo/{{.Timezone}} /usr/share/zoneinfo/{{.Timezone}} | |||
| ENV TZ {{.Timezone}} | |||
| {{end}} | |||
| WORKDIR /app | |||
| COPY --from=builder /app/{{.ExeFile}} /app/{{.ExeFile}}{{if .Argument}} | |||
| COPY --from=builder /app/etc /app/etc{{end}} | |||
| {{if .HasPort}} | |||
| EXPOSE {{.Port}} | |||
| {{end}} | |||
| CMD ["./{{.ExeFile}}"{{.Argument}}] | |||
| @@ -0,0 +1,113 @@ | |||
| apiVersion: apps/v1 | |||
| kind: Deployment | |||
| metadata: | |||
| name: {{.Name}} | |||
| namespace: {{.Namespace}} | |||
| labels: | |||
| app: {{.Name}} | |||
| spec: | |||
| replicas: {{.Replicas}} | |||
| revisionHistoryLimit: {{.Revisions}} | |||
| selector: | |||
| matchLabels: | |||
| app: {{.Name}} | |||
| template: | |||
| metadata: | |||
| labels: | |||
| app: {{.Name}} | |||
| spec:{{if .ServiceAccount}} | |||
| serviceAccountName: {{.ServiceAccount}}{{end}} | |||
| containers: | |||
| - name: {{.Name}} | |||
| image: {{.Image}} | |||
| {{if .ImagePullPolicy}}imagePullPolicy: {{.ImagePullPolicy}} | |||
| {{end}}ports: | |||
| - containerPort: {{.Port}} | |||
| readinessProbe: | |||
| tcpSocket: | |||
| port: {{.Port}} | |||
| initialDelaySeconds: 5 | |||
| periodSeconds: 10 | |||
| livenessProbe: | |||
| tcpSocket: | |||
| port: {{.Port}} | |||
| initialDelaySeconds: 15 | |||
| periodSeconds: 20 | |||
| resources: | |||
| requests: | |||
| cpu: {{.RequestCpu}}m | |||
| memory: {{.RequestMem}}Mi | |||
| limits: | |||
| cpu: {{.LimitCpu}}m | |||
| memory: {{.LimitMem}}Mi | |||
| volumeMounts: | |||
| - name: timezone | |||
| mountPath: /etc/localtime | |||
| {{if .Secret}}imagePullSecrets: | |||
| - name: {{.Secret}} | |||
| {{end}}volumes: | |||
| - name: timezone | |||
| hostPath: | |||
| path: /usr/share/zoneinfo/Asia/Shanghai | |||
| --- | |||
| apiVersion: v1 | |||
| kind: Service | |||
| metadata: | |||
| name: {{.Name}}-svc | |||
| namespace: {{.Namespace}} | |||
| spec: | |||
| ports: | |||
| {{if .UseNodePort}}- nodePort: {{.NodePort}} | |||
| port: {{.Port}} | |||
| protocol: TCP | |||
| targetPort: {{.TargetPort}} | |||
| type: NodePort{{else}}- port: {{.Port}} | |||
| targetPort: {{.TargetPort}}{{end}} | |||
| selector: | |||
| app: {{.Name}} | |||
| --- | |||
| apiVersion: autoscaling/v2beta1 | |||
| kind: HorizontalPodAutoscaler | |||
| metadata: | |||
| name: {{.Name}}-hpa-c | |||
| namespace: {{.Namespace}} | |||
| labels: | |||
| app: {{.Name}}-hpa-c | |||
| spec: | |||
| scaleTargetRef: | |||
| apiVersion: apps/v1 | |||
| kind: Deployment | |||
| name: {{.Name}} | |||
| minReplicas: {{.MinReplicas}} | |||
| maxReplicas: {{.MaxReplicas}} | |||
| metrics: | |||
| - type: Resource | |||
| resource: | |||
| name: cpu | |||
| targetAverageUtilization: 80 | |||
| --- | |||
| apiVersion: autoscaling/v2beta1 | |||
| kind: HorizontalPodAutoscaler | |||
| metadata: | |||
| name: {{.Name}}-hpa-m | |||
| namespace: {{.Namespace}} | |||
| labels: | |||
| app: {{.Name}}-hpa-m | |||
| spec: | |||
| scaleTargetRef: | |||
| apiVersion: apps/v1 | |||
| kind: Deployment | |||
| name: {{.Name}} | |||
| minReplicas: {{.MinReplicas}} | |||
| maxReplicas: {{.MaxReplicas}} | |||
| metrics: | |||
| - type: Resource | |||
| resource: | |||
| name: memory | |||
| targetAverageUtilization: 80 | |||
| @@ -0,0 +1,37 @@ | |||
| apiVersion: batch/v1 | |||
| kind: CronJob | |||
| metadata: | |||
| name: {{.Name}} | |||
| namespace: {{.Namespace}} | |||
| spec: | |||
| successfulJobsHistoryLimit: {{.SuccessfulJobsHistoryLimit}} | |||
| schedule: "{{.Schedule}}" | |||
| jobTemplate: | |||
| spec: | |||
| template: | |||
| spec:{{if .ServiceAccount}} | |||
| serviceAccountName: {{.ServiceAccount}}{{end}} | |||
| {{end}}containers: | |||
| - name: {{.Name}} | |||
| image: # todo image url | |||
| resources: | |||
| requests: | |||
| cpu: {{.RequestCpu}}m | |||
| memory: {{.RequestMem}}Mi | |||
| limits: | |||
| cpu: {{.LimitCpu}}m | |||
| memory: {{.LimitMem}}Mi | |||
| command: | |||
| - ./{{.ServiceName}} | |||
| - -f | |||
| - ./{{.Name}}.yaml | |||
| volumeMounts: | |||
| - name: timezone | |||
| mountPath: /etc/localtime | |||
| imagePullSecrets: | |||
| - name: # registry secret, if no, remove this | |||
| restartPolicy: OnFailure | |||
| volumes: | |||
| - name: timezone | |||
| hostPath: | |||
| path: /usr/share/zoneinfo/Asia/Shanghai | |||
| @@ -0,0 +1,14 @@ | |||
| func (m *default{{.upperStartCamelObject}}Model) Delete(ctx context.Context, {{.lowerStartCamelPrimaryKey}} {{.dataType}}) error { | |||
| {{if .withCache}}{{if .containsIndexCache}}data, err:=m.FindOne(ctx, {{.lowerStartCamelPrimaryKey}}) | |||
| if err!=nil{ | |||
| return err | |||
| } | |||
| {{end}} {{.keys}} | |||
| _, err {{if .containsIndexCache}}={{else}}:={{end}} m.ExecCtx(ctx, func(ctx context.Context, conn sqlx.SqlConn) (result sql.Result, err error) { | |||
| query := fmt.Sprintf("delete from %s where {{.originalPrimaryKey}} = {{if .postgreSql}}$1{{else}}?{{end}}", m.table) | |||
| return conn.ExecCtx(ctx, query, {{.lowerStartCamelPrimaryKey}}) | |||
| }, {{.keyValues}}){{else}}query := fmt.Sprintf("delete from %s where {{.originalPrimaryKey}} = {{if .postgreSql}}$1{{else}}?{{end}}", m.table) | |||
| _,err:=m.conn.ExecCtx(ctx, query, {{.lowerStartCamelPrimaryKey}}){{end}} | |||
| return err | |||
| } | |||
| @@ -0,0 +1,5 @@ | |||
| package {{.pkg}} | |||
| import "github.com/zeromicro/go-zero/core/stores/sqlx" | |||
| var ErrNotFound = sqlx.ErrNotFound | |||
| @@ -0,0 +1 @@ | |||
| {{.name}} {{.type}} {{.tag}} {{if .hasComment}}// {{.comment}}{{end}} | |||
| @@ -0,0 +1,8 @@ | |||
| func (m *default{{.upperStartCamelObject}}Model) formatPrimary(primary interface{}) string { | |||
| return fmt.Sprintf("%s%v", {{.primaryKeyLeft}}, primary) | |||
| } | |||
| func (m *default{{.upperStartCamelObject}}Model) queryPrimary(ctx context.Context, conn sqlx.SqlConn, v, primary interface{}) error { | |||
| query := fmt.Sprintf("select %s from %s where {{.originalPrimaryField}} = {{if .postgreSql}}$1{{else}}?{{end}} limit 1", {{.lowerStartCamelObject}}Rows, m.table ) | |||
| return conn.QueryRowCtx(ctx, v, query, primary) | |||
| } | |||
| @@ -0,0 +1,30 @@ | |||
| func (m *default{{.upperStartCamelObject}}Model) FindOneBy{{.upperField}}(ctx context.Context, {{.in}}) (*{{.upperStartCamelObject}}, error) { | |||
| {{if .withCache}}{{.cacheKey}} | |||
| var resp {{.upperStartCamelObject}} | |||
| err := m.QueryRowIndexCtx(ctx, &resp, {{.cacheKeyVariable}}, m.formatPrimary, func(ctx context.Context, conn sqlx.SqlConn, v interface{}) (i interface{}, e error) { | |||
| query := fmt.Sprintf("select %s from %s where {{.originalField}} limit 1", {{.lowerStartCamelObject}}Rows, m.table) | |||
| if err := conn.QueryRowCtx(ctx, &resp, query, {{.lowerStartCamelField}}); err != nil { | |||
| return nil, err | |||
| } | |||
| return resp.{{.upperStartCamelPrimaryKey}}, nil | |||
| }, m.queryPrimary) | |||
| switch err { | |||
| case nil: | |||
| return &resp, nil | |||
| case sqlc.ErrNotFound: | |||
| return nil, ErrNotFound | |||
| default: | |||
| return nil, err | |||
| } | |||
| }{{else}}var resp {{.upperStartCamelObject}} | |||
| query := fmt.Sprintf("select %s from %s where {{.originalField}} limit 1", {{.lowerStartCamelObject}}Rows, m.table ) | |||
| err := m.conn.QueryRowCtx(ctx, &resp, query, {{.lowerStartCamelField}}) | |||
| switch err { | |||
| case nil: | |||
| return &resp, nil | |||
| case sqlc.ErrNotFound: | |||
| return nil, ErrNotFound | |||
| default: | |||
| return nil, err | |||
| } | |||
| }{{end}} | |||
| @@ -0,0 +1,26 @@ | |||
| func (m *default{{.upperStartCamelObject}}Model) FindOne(ctx context.Context, {{.lowerStartCamelPrimaryKey}} {{.dataType}}) (*{{.upperStartCamelObject}}, error) { | |||
| {{if .withCache}}{{.cacheKey}} | |||
| var resp {{.upperStartCamelObject}} | |||
| err := m.QueryRowCtx(ctx, &resp, {{.cacheKeyVariable}}, func(ctx context.Context, conn sqlx.SqlConn, v interface{}) error { | |||
| query := fmt.Sprintf("select %s from %s where {{.originalPrimaryKey}} = {{if .postgreSql}}$1{{else}}?{{end}} limit 1", {{.lowerStartCamelObject}}Rows, m.table) | |||
| return conn.QueryRowCtx(ctx, v, query, {{.lowerStartCamelPrimaryKey}}) | |||
| }) | |||
| switch err { | |||
| case nil: | |||
| return &resp, nil | |||
| case sqlc.ErrNotFound: | |||
| return nil, ErrNotFound | |||
| default: | |||
| return nil, err | |||
| }{{else}}query := fmt.Sprintf("select %s from %s where {{.originalPrimaryKey}} = {{if .postgreSql}}$1{{else}}?{{end}} limit 1", {{.lowerStartCamelObject}}Rows, m.table) | |||
| var resp {{.upperStartCamelObject}} | |||
| err := m.conn.QueryRowCtx(ctx, &resp, query, {{.lowerStartCamelPrimaryKey}}) | |||
| switch err { | |||
| case nil: | |||
| return &resp, nil | |||
| case sqlc.ErrNotFound: | |||
| return nil, ErrNotFound | |||
| default: | |||
| return nil, err | |||
| }{{end}} | |||
| } | |||
| @@ -0,0 +1,13 @@ | |||
| import ( | |||
| "context" | |||
| "database/sql" | |||
| "fmt" | |||
| "strings" | |||
| {{if .time}}"time"{{end}} | |||
| {{if .containsPQ}}"github.com/lib/pq"{{end}} | |||
| "github.com/zeromicro/go-zero/core/stores/builder" | |||
| "github.com/zeromicro/go-zero/core/stores/sqlc" | |||
| "github.com/zeromicro/go-zero/core/stores/sqlx" | |||
| "github.com/zeromicro/go-zero/core/stringx" | |||
| ) | |||
| @@ -0,0 +1,14 @@ | |||
| import ( | |||
| "context" | |||
| "database/sql" | |||
| "fmt" | |||
| "strings" | |||
| {{if .time}}"time"{{end}} | |||
| {{if .containsPQ}}"github.com/lib/pq"{{end}} | |||
| "github.com/zeromicro/go-zero/core/stores/builder" | |||
| "github.com/zeromicro/go-zero/core/stores/cache" | |||
| "github.com/zeromicro/go-zero/core/stores/sqlc" | |||
| "github.com/zeromicro/go-zero/core/stores/sqlx" | |||
| "github.com/zeromicro/go-zero/core/stringx" | |||
| ) | |||
| @@ -0,0 +1,9 @@ | |||
| func (m *default{{.upperStartCamelObject}}Model) Insert(ctx context.Context, data *{{.upperStartCamelObject}}) (sql.Result,error) { | |||
| {{if .withCache}}{{.keys}} | |||
| ret, err := m.ExecCtx(ctx, func(ctx context.Context, conn sqlx.SqlConn) (result sql.Result, err error) { | |||
| query := fmt.Sprintf("insert into %s (%s) values ({{.expression}})", m.table, {{.lowerStartCamelObject}}RowsExpectAutoSet) | |||
| return conn.ExecCtx(ctx, query, {{.expressionValues}}) | |||
| }, {{.keyValues}}){{else}}query := fmt.Sprintf("insert into %s (%s) values ({{.expression}})", m.table, {{.lowerStartCamelObject}}RowsExpectAutoSet) | |||
| ret,err:=m.conn.ExecCtx(ctx, query, {{.expressionValues}}){{end}} | |||
| return ret,err | |||
| } | |||
| @@ -0,0 +1 @@ | |||
| Delete(ctx context.Context, {{.lowerStartCamelPrimaryKey}} {{.dataType}}) error | |||
| @@ -0,0 +1 @@ | |||
| FindOneBy{{.upperField}}(ctx context.Context, {{.in}}) (*{{.upperStartCamelObject}}, error) | |||
| @@ -0,0 +1 @@ | |||
| FindOne(ctx context.Context, {{.lowerStartCamelPrimaryKey}} {{.dataType}}) (*{{.upperStartCamelObject}}, error) | |||
| @@ -0,0 +1 @@ | |||
| Insert(ctx context.Context, data *{{.upperStartCamelObject}}) (sql.Result,error) | |||
| @@ -0,0 +1 @@ | |||
| Update(ctx context.Context, {{if .containsIndexCache}}newData{{else}}data{{end}} *{{.upperStartCamelObject}}) error | |||
| @@ -0,0 +1,13 @@ | |||
| // Code generated by goctl. DO NOT EDIT. | |||
| package {{.pkg}} | |||
| {{.imports}} | |||
| {{.vars}} | |||
| {{.types}} | |||
| {{.new}} | |||
| {{.delete}} | |||
| {{.find}} | |||
| {{.insert}} | |||
| {{.update}} | |||
| {{.extraMethod}} | |||
| {{.tableName}} | |||
| @@ -0,0 +1,6 @@ | |||
| func new{{.upperStartCamelObject}}Model(conn sqlx.SqlConn{{if .withCache}}, c cache.CacheConf{{end}}) *default{{.upperStartCamelObject}}Model { | |||
| return &default{{.upperStartCamelObject}}Model{ | |||
| {{if .withCache}}CachedConn: sqlc.NewConn(conn, c){{else}}conn:conn{{end}}, | |||
| table: {{.table}}, | |||
| } | |||
| } | |||
| @@ -0,0 +1,30 @@ | |||
| package {{.pkg}} | |||
| {{if .withCache}} | |||
| import ( | |||
| "github.com/zeromicro/go-zero/core/stores/cache" | |||
| "github.com/zeromicro/go-zero/core/stores/sqlx" | |||
| ) | |||
| {{else}} | |||
| import "github.com/zeromicro/go-zero/core/stores/sqlx" | |||
| {{end}} | |||
| var _ {{.upperStartCamelObject}}Model = (*custom{{.upperStartCamelObject}}Model)(nil) | |||
| type ( | |||
| // {{.upperStartCamelObject}}Model is an interface to be customized, add more methods here, | |||
| // and implement the added methods in custom{{.upperStartCamelObject}}Model. | |||
| {{.upperStartCamelObject}}Model interface { | |||
| {{.lowerStartCamelObject}}Model | |||
| } | |||
| custom{{.upperStartCamelObject}}Model struct { | |||
| *default{{.upperStartCamelObject}}Model | |||
| } | |||
| ) | |||
| // New{{.upperStartCamelObject}}Model returns a model for the database table. | |||
| func New{{.upperStartCamelObject}}Model(conn sqlx.SqlConn{{if .withCache}}, c cache.CacheConf{{end}}) {{.upperStartCamelObject}}Model { | |||
| return &custom{{.upperStartCamelObject}}Model{ | |||
| default{{.upperStartCamelObject}}Model: new{{.upperStartCamelObject}}Model(conn{{if .withCache}}, c{{end}}), | |||
| } | |||
| } | |||
| @@ -0,0 +1,3 @@ | |||
| func (m *default{{.upperStartCamelObject}}Model) tableName() string { | |||
| return m.table | |||
| } | |||
| @@ -0,0 +1 @@ | |||
| `db:"{{.field}}"` | |||
| @@ -0,0 +1,14 @@ | |||
| type ( | |||
| {{.lowerStartCamelObject}}Model interface{ | |||
| {{.method}} | |||
| } | |||
| default{{.upperStartCamelObject}}Model struct { | |||
| {{if .withCache}}sqlc.CachedConn{{else}}conn sqlx.SqlConn{{end}} | |||
| table string | |||
| } | |||
| {{.upperStartCamelObject}} struct { | |||
| {{.fields}} | |||
| } | |||
| ) | |||
| @@ -0,0 +1,14 @@ | |||
| func (m *default{{.upperStartCamelObject}}Model) Update(ctx context.Context, {{if .containsIndexCache}}newData{{else}}data{{end}} *{{.upperStartCamelObject}}) error { | |||
| {{if .withCache}}{{if .containsIndexCache}}data, err:=m.FindOne(ctx, newData.{{.upperStartCamelPrimaryKey}}) | |||
| if err!=nil{ | |||
| return err | |||
| } | |||
| {{end}} {{.keys}} | |||
| _, {{if .containsIndexCache}}err{{else}}err:{{end}}= m.ExecCtx(ctx, func(ctx context.Context, conn sqlx.SqlConn) (result sql.Result, err error) { | |||
| query := fmt.Sprintf("update %s set %s where {{.originalPrimaryKey}} = {{if .postgreSql}}$1{{else}}?{{end}}", m.table, {{.lowerStartCamelObject}}RowsWithPlaceHolder) | |||
| return conn.ExecCtx(ctx, query, {{.expressionValues}}) | |||
| }, {{.keyValues}}){{else}}query := fmt.Sprintf("update %s set %s where {{.originalPrimaryKey}} = {{if .postgreSql}}$1{{else}}?{{end}}", m.table, {{.lowerStartCamelObject}}RowsWithPlaceHolder) | |||
| _,err:=m.conn.ExecCtx(ctx, query, {{.expressionValues}}){{end}} | |||
| return err | |||
| } | |||
| @@ -0,0 +1,8 @@ | |||
| var ( | |||
| {{.lowerStartCamelObject}}FieldNames = builder.RawFieldNames(&{{.upperStartCamelObject}}{}{{if .postgreSql}}, true{{end}}) | |||
| {{.lowerStartCamelObject}}Rows = strings.Join({{.lowerStartCamelObject}}FieldNames, ",") | |||
| {{.lowerStartCamelObject}}RowsExpectAutoSet = {{if .postgreSql}}strings.Join(stringx.Remove({{.lowerStartCamelObject}}FieldNames, {{if .autoIncrement}}"{{.originalPrimaryKey}}", {{end}} {{.ignoreColumns}}), ","){{else}}strings.Join(stringx.Remove({{.lowerStartCamelObject}}FieldNames, {{if .autoIncrement}}"{{.originalPrimaryKey}}", {{end}} {{.ignoreColumns}}), ","){{end}} | |||
| {{.lowerStartCamelObject}}RowsWithPlaceHolder = {{if .postgreSql}}builder.PostgreSqlJoin(stringx.Remove({{.lowerStartCamelObject}}FieldNames, "{{.originalPrimaryKey}}", {{.ignoreColumns}})){{else}}strings.Join(stringx.Remove({{.lowerStartCamelObject}}FieldNames, "{{.originalPrimaryKey}}", {{.ignoreColumns}}), "=?,") + "=?"{{end}} | |||
| {{if .withCache}}{{.cacheKeys}}{{end}} | |||
| ) | |||
| @@ -0,0 +1,12 @@ | |||
| package model | |||
| import ( | |||
| "errors" | |||
| "github.com/zeromicro/go-zero/core/stores/mon" | |||
| ) | |||
| var ( | |||
| ErrNotFound = mon.ErrNotFound | |||
| ErrInvalidObjectId = errors.New("invalid objectId") | |||
| ) | |||
| @@ -0,0 +1,78 @@ | |||
| // Code generated by goctl. DO NOT EDIT. | |||
| package model | |||
| import ( | |||
| "context" | |||
| "time" | |||
| {{if .Cache}}"github.com/zeromicro/go-zero/core/stores/monc"{{else}}"github.com/zeromicro/go-zero/core/stores/mon"{{end}} | |||
| "go.mongodb.org/mongo-driver/bson" | |||
| "go.mongodb.org/mongo-driver/bson/primitive" | |||
| "go.mongodb.org/mongo-driver/mongo" | |||
| ) | |||
| {{if .Cache}}var prefix{{.Type}}CacheKey = "cache:{{.lowerType}}:"{{end}} | |||
| type {{.lowerType}}Model interface{ | |||
| Insert(ctx context.Context,data *{{.Type}}) error | |||
| FindOne(ctx context.Context,id string) (*{{.Type}}, error) | |||
| Update(ctx context.Context,data *{{.Type}}) (*mongo.UpdateResult, error) | |||
| Delete(ctx context.Context,id string) (int64, error) | |||
| } | |||
| type default{{.Type}}Model struct { | |||
| conn {{if .Cache}}*monc.Model{{else}}*mon.Model{{end}} | |||
| } | |||
| func newDefault{{.Type}}Model(conn {{if .Cache}}*monc.Model{{else}}*mon.Model{{end}}) *default{{.Type}}Model { | |||
| return &default{{.Type}}Model{conn: conn} | |||
| } | |||
| func (m *default{{.Type}}Model) Insert(ctx context.Context, data *{{.Type}}) error { | |||
| if data.ID.IsZero() { | |||
| data.ID = primitive.NewObjectID() | |||
| data.CreateAt = time.Now() | |||
| data.UpdateAt = time.Now() | |||
| } | |||
| {{if .Cache}}key := prefix{{.Type}}CacheKey + data.ID.Hex(){{end}} | |||
| _, err := m.conn.InsertOne(ctx, {{if .Cache}}key, {{end}} data) | |||
| return err | |||
| } | |||
| func (m *default{{.Type}}Model) FindOne(ctx context.Context, id string) (*{{.Type}}, error) { | |||
| oid, err := primitive.ObjectIDFromHex(id) | |||
| if err != nil { | |||
| return nil, ErrInvalidObjectId | |||
| } | |||
| var data {{.Type}} | |||
| {{if .Cache}}key := prefix{{.Type}}CacheKey + id{{end}} | |||
| err = m.conn.FindOne(ctx, {{if .Cache}}key, {{end}}&data, bson.M{"_id": oid}) | |||
| switch err { | |||
| case nil: | |||
| return &data, nil | |||
| case {{if .Cache}}monc{{else}}mon{{end}}.ErrNotFound: | |||
| return nil, ErrNotFound | |||
| default: | |||
| return nil, err | |||
| } | |||
| } | |||
| func (m *default{{.Type}}Model) Update(ctx context.Context, data *{{.Type}}) (*mongo.UpdateResult, error) { | |||
| data.UpdateAt = time.Now() | |||
| {{if .Cache}}key := prefix{{.Type}}CacheKey + data.ID.Hex(){{end}} | |||
| res, err := m.conn.UpdateOne(ctx, {{if .Cache}}key, {{end}}bson.M{"_id": data.ID}, bson.M{"$set": data}) | |||
| return res, err | |||
| } | |||
| func (m *default{{.Type}}Model) Delete(ctx context.Context, id string) (int64, error) { | |||
| oid, err := primitive.ObjectIDFromHex(id) | |||
| if err != nil { | |||
| return 0, ErrInvalidObjectId | |||
| } | |||
| {{if .Cache}}key := prefix{{.Type}}CacheKey +id{{end}} | |||
| res, err := m.conn.DeleteOne(ctx, {{if .Cache}}key, {{end}}bson.M{"_id": oid}) | |||
| return res, err | |||
| } | |||
| @@ -0,0 +1,38 @@ | |||
| package model | |||
| {{if .Cache}}import ( | |||
| "github.com/zeromicro/go-zero/core/stores/cache" | |||
| "github.com/zeromicro/go-zero/core/stores/monc" | |||
| ){{else}}import "github.com/zeromicro/go-zero/core/stores/mon"{{end}} | |||
| {{if .Easy}} | |||
| const {{.Type}}CollectionName = "{{.snakeType}}" | |||
| {{end}} | |||
| var _ {{.Type}}Model = (*custom{{.Type}}Model)(nil) | |||
| type ( | |||
| // {{.Type}}Model is an interface to be customized, add more methods here, | |||
| // and implement the added methods in custom{{.Type}}Model. | |||
| {{.Type}}Model interface { | |||
| {{.lowerType}}Model | |||
| } | |||
| custom{{.Type}}Model struct { | |||
| *default{{.Type}}Model | |||
| } | |||
| ) | |||
| // New{{.Type}}Model returns a model for the mongo. | |||
| {{if .Easy}}func New{{.Type}}Model(url, db string{{if .Cache}}, c cache.CacheConf{{end}}) {{.Type}}Model { | |||
| conn := {{if .Cache}}monc{{else}}mon{{end}}.MustNewModel(url, db, {{.Type}}CollectionName{{if .Cache}}, c{{end}}) | |||
| return &custom{{.Type}}Model{ | |||
| default{{.Type}}Model: newDefault{{.Type}}Model(conn), | |||
| } | |||
| }{{else}}func New{{.Type}}Model(url, db, collection string{{if .Cache}}, c cache.CacheConf{{end}}) {{.Type}}Model { | |||
| conn := {{if .Cache}}monc{{else}}mon{{end}}.MustNewModel(url, db, collection{{if .Cache}}, c{{end}}) | |||
| return &custom{{.Type}}Model{ | |||
| default{{.Type}}Model: newDefault{{.Type}}Model(conn), | |||
| } | |||
| }{{end}} | |||
| @@ -0,0 +1,14 @@ | |||
| package model | |||
| import ( | |||
| "time" | |||
| "go.mongodb.org/mongo-driver/bson/primitive" | |||
| ) | |||
| type {{.Type}} struct { | |||
| ID primitive.ObjectID `bson:"_id,omitempty" json:"id,omitempty"` | |||
| // TODO: Fill your own fields | |||
| UpdateAt time.Time `bson:"updateAt,omitempty" json:"updateAt,omitempty"` | |||
| CreateAt time.Time `bson:"createAt,omitempty" json:"createAt,omitempty"` | |||
| } | |||
| @@ -0,0 +1,12 @@ | |||
| type Request { | |||
| Name string `path:"name,options=you|me"` | |||
| } | |||
| type Response { | |||
| Message string `json:"message"` | |||
| } | |||
| service {{.name}}-api { | |||
| @handler {{.handler}}Handler | |||
| get /from/:name(Request) returns (Response) | |||
| } | |||
| @@ -0,0 +1,33 @@ | |||
| {{.head}} | |||
| package {{.filePackage}} | |||
| import ( | |||
| "context" | |||
| {{.pbPackage}} | |||
| {{if ne .pbPackage .protoGoPackage}}{{.protoGoPackage}}{{end}} | |||
| "github.com/zeromicro/go-zero/zrpc" | |||
| "google.golang.org/grpc" | |||
| ) | |||
| type ( | |||
| {{.alias}} | |||
| {{.serviceName}} interface { | |||
| {{.interface}} | |||
| } | |||
| default{{.serviceName}} struct { | |||
| cli zrpc.Client | |||
| } | |||
| ) | |||
| func New{{.serviceName}}(cli zrpc.Client) {{.serviceName}} { | |||
| return &default{{.serviceName}}{ | |||
| cli: cli, | |||
| } | |||
| } | |||
| {{.functions}} | |||
| @@ -0,0 +1,7 @@ | |||
| package config | |||
| import "github.com/zeromicro/go-zero/zrpc" | |||
| type Config struct { | |||
| zrpc.RpcServerConf | |||
| } | |||
| @@ -0,0 +1,6 @@ | |||
| Name: {{.serviceName}}.rpc | |||
| ListenOn: 0.0.0.0:8080 | |||
| Etcd: | |||
| Hosts: | |||
| - 127.0.0.1:2379 | |||
| Key: {{.serviceName}}.rpc | |||
| @@ -0,0 +1,6 @@ | |||
| {{if .hasComment}}{{.comment}}{{end}} | |||
| func (l *{{.logicName}}) {{.method}} ({{if .hasReq}}in {{.request}}{{if .stream}},stream {{.streamBody}}{{end}}{{else}}stream {{.streamBody}}{{end}}) ({{if .hasReply}}{{.response}},{{end}} error) { | |||
| // todo: add your logic here and delete this line | |||
| return {{if .hasReply}}&{{.responseType}}{},{{end}} nil | |||
| } | |||
| @@ -0,0 +1,24 @@ | |||
| package {{.packageName}} | |||
| import ( | |||
| "context" | |||
| {{.imports}} | |||
| "github.com/zeromicro/go-zero/core/logx" | |||
| ) | |||
| type {{.logicName}} struct { | |||
| ctx context.Context | |||
| svcCtx *svc.ServiceContext | |||
| logx.Logger | |||
| } | |||
| func New{{.logicName}}(ctx context.Context,svcCtx *svc.ServiceContext) *{{.logicName}} { | |||
| return &{{.logicName}}{ | |||
| ctx: ctx, | |||
| svcCtx: svcCtx, | |||
| Logger: logx.WithContext(ctx), | |||
| } | |||
| } | |||
| {{.functions}} | |||
| @@ -0,0 +1,36 @@ | |||
| package main | |||
| import ( | |||
| "flag" | |||
| "fmt" | |||
| {{.imports}} | |||
| "github.com/zeromicro/go-zero/core/conf" | |||
| "github.com/zeromicro/go-zero/core/service" | |||
| "github.com/zeromicro/go-zero/zrpc" | |||
| "google.golang.org/grpc" | |||
| "google.golang.org/grpc/reflection" | |||
| ) | |||
| var configFile = flag.String("f", "etc/{{.serviceName}}.yaml", "the config file") | |||
| func main() { | |||
| flag.Parse() | |||
| var c config.Config | |||
| conf.MustLoad(*configFile, &c) | |||
| ctx := svc.NewServiceContext(c) | |||
| s := zrpc.MustNewServer(c.RpcServerConf, func(grpcServer *grpc.Server) { | |||
| {{range .serviceNames}} {{.Pkg}}.Register{{.Service}}Server(grpcServer, {{.ServerPkg}}.New{{.Service}}Server(ctx)) | |||
| {{end}} | |||
| if c.Mode == service.DevMode || c.Mode == service.TestMode { | |||
| reflection.Register(grpcServer) | |||
| } | |||
| }) | |||
| defer s.Stop() | |||
| fmt.Printf("Starting rpc server at %s...\n", c.ListenOn) | |||
| s.Start() | |||
| } | |||
| @@ -0,0 +1,6 @@ | |||
| {{if .hasComment}}{{.comment}}{{end}} | |||
| func (s *{{.server}}Server) {{.method}} ({{if .notStream}}ctx context.Context,{{if .hasReq}} in {{.request}}{{end}}{{else}}{{if .hasReq}} in {{.request}},{{end}}stream {{.streamBody}}{{end}}) ({{if .notStream}}{{.response}},{{end}}error) { | |||
| l := {{.logicPkg}}.New{{.logicName}}({{if .notStream}}ctx,{{else}}stream.Context(),{{end}}s.svcCtx) | |||
| return l.{{.method}}({{if .hasReq}}in{{if .stream}} ,stream{{end}}{{else}}{{if .stream}}stream{{end}}{{end}}) | |||
| } | |||
| @@ -0,0 +1,22 @@ | |||
| {{.head}} | |||
| package server | |||
| import ( | |||
| {{if .notStream}}"context"{{end}} | |||
| {{.imports}} | |||
| ) | |||
| type {{.server}}Server struct { | |||
| svcCtx *svc.ServiceContext | |||
| {{.unimplementedServer}} | |||
| } | |||
| func New{{.server}}Server(svcCtx *svc.ServiceContext) *{{.server}}Server { | |||
| return &{{.server}}Server{ | |||
| svcCtx: svcCtx, | |||
| } | |||
| } | |||
| {{.funcs}} | |||
| @@ -0,0 +1,13 @@ | |||
| package svc | |||
| import {{.imports}} | |||
| type ServiceContext struct { | |||
| Config config.Config | |||
| } | |||
| func NewServiceContext(c config.Config) *ServiceContext { | |||
| return &ServiceContext{ | |||
| Config:c, | |||
| } | |||
| } | |||
| @@ -0,0 +1,16 @@ | |||
| syntax = "proto3"; | |||
| package {{.package}}; | |||
| option go_package="./{{.package}}"; | |||
| message Request { | |||
| string ping = 1; | |||
| } | |||
| message Response { | |||
| string pong = 1; | |||
| } | |||
| service {{.serviceName}} { | |||
| rpc Ping(Request) returns(Response); | |||
| } | |||
| @@ -19,7 +19,7 @@ require ( | |||
| gitlink.org.cn/jcce-pcm/pcm-participant-modelarts v0.0.0-20230714013255-149a9b428b28 | |||
| gitlink.org.cn/jcce-pcm/pcm-participant-octopus v0.0.0-20230714012611-c66005610d0c | |||
| gitlink.org.cn/jcce-pcm/pcm-participant-slurm v0.0.0-20230714015940-004100bfa168 | |||
| gitlink.org.cn/jcce-pcm/utils v0.0.1 | |||
| gitlink.org.cn/jcce-pcm/utils v0.0.0-20230724072501-2a0519bd57bd | |||
| google.golang.org/grpc v1.56.2 | |||
| google.golang.org/protobuf v1.31.0 | |||
| gorm.io/driver/mysql v1.5.1 | |||
| @@ -34,6 +34,7 @@ require ( | |||
| github.com/aliyun/alibaba-cloud-sdk-go v1.61.1704 // indirect | |||
| github.com/beorn7/perks v1.0.1 // indirect | |||
| github.com/buger/jsonparser v1.1.1 // indirect | |||
| github.com/bwmarrin/snowflake v0.3.0 // indirect | |||
| github.com/cenkalti/backoff/v4 v4.2.0 // indirect | |||
| github.com/cespare/xxhash/v2 v2.2.0 // indirect | |||
| github.com/coreos/go-semver v0.3.1 // indirect | |||
| @@ -444,6 +444,8 @@ github.com/bkaradzic/go-lz4 v1.0.0/go.mod h1:0YdlkowM3VswSROI7qDxhRvJ3sLhlFrRRwj | |||
| github.com/bufbuild/protocompile v0.4.0/go.mod h1:3v93+mbWn/v3xzN+31nwkJfrEpAUwp+BagBSZWx+TP8= | |||
| github.com/buger/jsonparser v1.1.1 h1:2PnMjfWD7wBILjqQbt530v576A/cAbQvEW9gGIpYMUs= | |||
| github.com/buger/jsonparser v1.1.1/go.mod h1:6RYKKt7H4d4+iWqouImQ9R2FZql3VbhNgx27UK13J/0= | |||
| github.com/bwmarrin/snowflake v0.3.0 h1:xm67bEhkKh6ij1790JB83OujPR5CzNe8QuQqAgISZN0= | |||
| github.com/bwmarrin/snowflake v0.3.0/go.mod h1:NdZxfVWX+oR6y2K0o6qAYv6gIOP9rjG0/E9WsDpxqwE= | |||
| github.com/cenkalti/backoff/v4 v4.1.3/go.mod h1:scbssz8iZGpm3xbr14ovlUdkxfGXNInqkPWOWmG2CLw= | |||
| github.com/cenkalti/backoff/v4 v4.2.0 h1:HN5dHm3WBOgndBH6E8V0q2jIYIR3s9yglV8k/+MN3u4= | |||
| github.com/cenkalti/backoff/v4 v4.2.0/go.mod h1:Y3VNntkOUPxTVeUxJ/G5vcM//AlwfmyYozVcomhLiZE= | |||
| @@ -1035,8 +1037,8 @@ gitlink.org.cn/jcce-pcm/pcm-participant-octopus v0.0.0-20230714012611-c66005610d | |||
| gitlink.org.cn/jcce-pcm/pcm-participant-octopus v0.0.0-20230714012611-c66005610d0c/go.mod h1:9Ad9vxCPGbY1yF1NhHWL2EhxsXJBB6bzz9i7PeSfKG4= | |||
| gitlink.org.cn/jcce-pcm/pcm-participant-slurm v0.0.0-20230714015940-004100bfa168 h1:BgTVUqJMOhdm6mNPx1ti5ClTnyMjZlCvH0avI1dz1xg= | |||
| gitlink.org.cn/jcce-pcm/pcm-participant-slurm v0.0.0-20230714015940-004100bfa168/go.mod h1:lY3jXmmMvC7j4Q2ogliThURWp9c1XCToSCnRkdc1aW8= | |||
| gitlink.org.cn/jcce-pcm/utils v0.0.1 h1:3PH93Z/JFTH5JRO9MFf3dD1Gnd12aGiIIViWBlQGuhE= | |||
| gitlink.org.cn/jcce-pcm/utils v0.0.1/go.mod h1:5cwaaqM0+HK5GXVbYozGlWvgwoUby0KytdvhbwQW1ks= | |||
| gitlink.org.cn/jcce-pcm/utils v0.0.0-20230724072501-2a0519bd57bd h1:A9i6TPZ58OwycgWNQpIMrjSIMK8lXmmakig7IkonrVA= | |||
| gitlink.org.cn/jcce-pcm/utils v0.0.0-20230724072501-2a0519bd57bd/go.mod h1:zTa+selMe02jZ3u6Ij1rTF2CrGd2ZqzqyMQ/FwhdpvY= | |||
| go.etcd.io/etcd/api/v3 v3.5.5/go.mod h1:KFtNaxGDw4Yx/BA4iPPwevUTAuqcsPxzyX8PHydchN8= | |||
| go.etcd.io/etcd/api/v3 v3.5.7/go.mod h1:9qew1gCdDDLu+VwmeG+iFpL+QlpHTo7iubavdVDgCAA= | |||
| go.etcd.io/etcd/api/v3 v3.5.9 h1:4wSsluwyTbGGmyjJktOf3wFQoTBIURXHnq9n/G/JQHs= | |||
| @@ -1,5 +1,12 @@ | |||
| package model | |||
| import ( | |||
| "github.com/zeromicro/go-zero/core/stores/cache" | |||
| "github.com/zeromicro/go-zero/core/stores/sqlx" | |||
| ) | |||
| var _ ScNodeAvailInfoModel = (*customScNodeAvailInfoModel)(nil) | |||
| type ( | |||
| // ScNodeAvailInfoModel is an interface to be customized, add more methods here, | |||
| // and implement the added methods in customScNodeAvailInfoModel. | |||
| @@ -11,3 +18,10 @@ type ( | |||
| *defaultScNodeAvailInfoModel | |||
| } | |||
| ) | |||
| // NewScNodeAvailInfoModel returns a model for the database table. | |||
| func NewScNodeAvailInfoModel(conn sqlx.SqlConn, c cache.CacheConf, opts ...cache.Option) ScNodeAvailInfoModel { | |||
| return &customScNodeAvailInfoModel{ | |||
| defaultScNodeAvailInfoModel: newScNodeAvailInfoModel(conn, c, opts...), | |||
| } | |||
| } | |||
| @@ -5,6 +5,7 @@ package model | |||
| import ( | |||
| "context" | |||
| "database/sql" | |||
| "fmt" | |||
| "strings" | |||
| "time" | |||
| @@ -38,22 +39,22 @@ type ( | |||
| } | |||
| ScNodeAvailInfo struct { | |||
| Id int64 `db:"id"` // id | |||
| NodeName string `db:"node_name"` // 节点名称 | |||
| CpuTotal int64 `db:"cpu_total"` // cpu核数 | |||
| CpuUsable float64 `db:"cpu_usable"` // cpu可用率 | |||
| DiskTotal int64 `db:"disk_total"` // 磁盘空间 | |||
| DiskAvail int64 `db:"disk_avail"` // 磁盘可用空间 | |||
| MemTotal int64 `db:"mem_total"` // 内存总数 | |||
| MemAvail int64 `db:"mem_avail"` // 内存可用数 | |||
| GpuTotal int64 `db:"gpu_total"` // gpu总数 | |||
| GpuAvail int64 `db:"gpu_avail"` // gpu可用数 | |||
| ParticipantId int64 `db:"participant_id"` // 集群静态信息id | |||
| DeletedFlag int64 `db:"deleted_flag"` // 是否删除 | |||
| CreatedBy int64 `db:"created_by"` // 创建人 | |||
| CreatedTime time.Time `db:"created_time"` // 创建时间 | |||
| UpdatedBy int64 `db:"updated_by"` // 更新人 | |||
| UpdatedTime time.Time `db:"updated_time"` // 更新时间 | |||
| Id int64 `db:"id"` // id | |||
| NodeName sql.NullString `db:"node_name"` // 节点名称 | |||
| CpuTotal sql.NullInt64 `db:"cpu_total"` // cpu核数 | |||
| CpuUsable sql.NullFloat64 `db:"cpu_usable"` // cpu可用率 | |||
| DiskTotal sql.NullInt64 `db:"disk_total"` // 磁盘空间 | |||
| DiskAvail sql.NullInt64 `db:"disk_avail"` // 磁盘可用空间 | |||
| MemTotal sql.NullInt64 `db:"mem_total"` // 内存总数 | |||
| MemAvail sql.NullInt64 `db:"mem_avail"` // 内存可用数 | |||
| GpuTotal sql.NullInt64 `db:"gpu_total"` // gpu总数 | |||
| GpuAvail sql.NullInt64 `db:"gpu_avail"` // gpu可用数 | |||
| ParticipantId int64 `db:"participant_id"` // 集群静态信息id | |||
| DeletedFlag int64 `db:"deleted_flag"` // 是否删除 | |||
| CreatedBy sql.NullInt64 `db:"created_by"` // 创建人 | |||
| CreatedTime time.Time `db:"created_time"` // 创建时间 | |||
| UpdatedBy sql.NullInt64 `db:"updated_by"` // 更新人 | |||
| UpdatedTime sql.NullTime `db:"updated_time"` // 更新时间 | |||
| } | |||
| ) | |||
| @@ -70,6 +71,60 @@ func (m *defaultScNodeAvailInfoModel) withSession(session sqlx.Session) *default | |||
| table: "`sc_node_avail_info`", | |||
| } | |||
| } | |||
| func (m *defaultScNodeAvailInfoModel) Delete(ctx context.Context, id int64) error { | |||
| pcmScNodeAvailInfoIdKey := fmt.Sprintf("%s%v", cachePcmScNodeAvailInfoIdPrefix, id) | |||
| _, err := m.ExecCtx(ctx, func(ctx context.Context, conn sqlx.SqlConn) (result sql.Result, err error) { | |||
| query := fmt.Sprintf("delete from %s where `id` = ?", m.table) | |||
| return conn.ExecCtx(ctx, query, id) | |||
| }, pcmScNodeAvailInfoIdKey) | |||
| return err | |||
| } | |||
| func (m *defaultScNodeAvailInfoModel) FindOne(ctx context.Context, id int64) (*ScNodeAvailInfo, error) { | |||
| pcmScNodeAvailInfoIdKey := fmt.Sprintf("%s%v", cachePcmScNodeAvailInfoIdPrefix, id) | |||
| var resp ScNodeAvailInfo | |||
| err := m.QueryRowCtx(ctx, &resp, pcmScNodeAvailInfoIdKey, func(ctx context.Context, conn sqlx.SqlConn, v any) error { | |||
| query := fmt.Sprintf("select %s from %s where `id` = ? limit 1", scNodeAvailInfoRows, m.table) | |||
| return conn.QueryRowCtx(ctx, v, query, id) | |||
| }) | |||
| switch err { | |||
| case nil: | |||
| return &resp, nil | |||
| case sqlc.ErrNotFound: | |||
| return nil, ErrNotFound | |||
| default: | |||
| return nil, err | |||
| } | |||
| } | |||
| func (m *defaultScNodeAvailInfoModel) Insert(ctx context.Context, data *ScNodeAvailInfo) (sql.Result, error) { | |||
| pcmScNodeAvailInfoIdKey := fmt.Sprintf("%s%v", cachePcmScNodeAvailInfoIdPrefix, data.Id) | |||
| ret, err := m.ExecCtx(ctx, func(ctx context.Context, conn sqlx.SqlConn) (result sql.Result, err error) { | |||
| query := fmt.Sprintf("insert into %s (%s) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", m.table, scNodeAvailInfoRowsExpectAutoSet) | |||
| return conn.ExecCtx(ctx, query, data.Id, data.NodeName, data.CpuTotal, data.CpuUsable, data.DiskTotal, data.DiskAvail, data.MemTotal, data.MemAvail, data.GpuTotal, data.GpuAvail, data.ParticipantId, data.DeletedFlag, data.CreatedBy, data.CreatedTime, data.UpdatedBy, data.UpdatedTime) | |||
| }, pcmScNodeAvailInfoIdKey) | |||
| return ret, err | |||
| } | |||
| func (m *defaultScNodeAvailInfoModel) Update(ctx context.Context, data *ScNodeAvailInfo) error { | |||
| pcmScNodeAvailInfoIdKey := fmt.Sprintf("%s%v", cachePcmScNodeAvailInfoIdPrefix, data.Id) | |||
| _, err := m.ExecCtx(ctx, func(ctx context.Context, conn sqlx.SqlConn) (result sql.Result, err error) { | |||
| query := fmt.Sprintf("update %s set %s where `id` = ?", m.table, scNodeAvailInfoRowsWithPlaceHolder) | |||
| return conn.ExecCtx(ctx, query, data.NodeName, data.CpuTotal, data.CpuUsable, data.DiskTotal, data.DiskAvail, data.MemTotal, data.MemAvail, data.GpuTotal, data.GpuAvail, data.ParticipantId, data.DeletedFlag, data.CreatedBy, data.CreatedTime, data.UpdatedBy, data.UpdatedTime, data.Id) | |||
| }, pcmScNodeAvailInfoIdKey) | |||
| return err | |||
| } | |||
| func (m *defaultScNodeAvailInfoModel) formatPrimary(primary any) string { | |||
| return fmt.Sprintf("%s%v", cachePcmScNodeAvailInfoIdPrefix, primary) | |||
| } | |||
| func (m *defaultScNodeAvailInfoModel) queryPrimary(ctx context.Context, conn sqlx.SqlConn, v, primary any) error { | |||
| query := fmt.Sprintf("select %s from %s where `id` = ? limit 1", scNodeAvailInfoRows, m.table) | |||
| return conn.QueryRowCtx(ctx, v, query, primary) | |||
| } | |||
| func (m *defaultScNodeAvailInfoModel) tableName() string { | |||
| return m.table | |||
| } | |||
| @@ -1,5 +1,12 @@ | |||
| package model | |||
| import ( | |||
| "github.com/zeromicro/go-zero/core/stores/cache" | |||
| "github.com/zeromicro/go-zero/core/stores/sqlx" | |||
| ) | |||
| var _ ScNodePhyInfoModel = (*customScNodePhyInfoModel)(nil) | |||
| type ( | |||
| // ScNodePhyInfoModel is an interface to be customized, add more methods here, | |||
| // and implement the added methods in customScNodePhyInfoModel. | |||
| @@ -11,3 +18,10 @@ type ( | |||
| *defaultScNodePhyInfoModel | |||
| } | |||
| ) | |||
| // NewScNodePhyInfoModel returns a model for the database table. | |||
| func NewScNodePhyInfoModel(conn sqlx.SqlConn, c cache.CacheConf, opts ...cache.Option) ScNodePhyInfoModel { | |||
| return &customScNodePhyInfoModel{ | |||
| defaultScNodePhyInfoModel: newScNodePhyInfoModel(conn, c, opts...), | |||
| } | |||
| } | |||
| @@ -39,19 +39,19 @@ type ( | |||
| } | |||
| ScNodePhyInfo struct { | |||
| Id int64 `db:"id"` // id | |||
| NodeName string `db:"node_name"` // 节点名称 | |||
| OsName string `db:"os_name"` // 系统名称 | |||
| OsVersion int64 `db:"os_version"` // 系统版本 | |||
| ArchType string `db:"arch_type"` // 架构类型 | |||
| ArchName string `db:"arch_name"` // 架构名称 | |||
| ArchFreq string `db:"arch_freq"` // 架构频率 | |||
| ParticipantId int64 `db:"participant_id"` // 集群静态信息id | |||
| DeletedFlag int64 `db:"deleted_flag"` // 是否删除 | |||
| CreatedBy int64 `db:"created_by"` // 创建人 | |||
| CreatedTime time.Time `db:"created_time"` // 创建时间 | |||
| UpdatedBy int64 `db:"updated_by"` // 更新人 | |||
| UpdatedTime time.Time `db:"updated_time"` // 更新时间 | |||
| Id int64 `db:"id"` // id | |||
| NodeName string `db:"node_name"` // 节点名称 | |||
| OsName string `db:"os_name"` // 系统名称 | |||
| OsVersion int64 `db:"os_version"` // 系统版本 | |||
| ArchType string `db:"arch_type"` // 架构类型 | |||
| ArchName string `db:"arch_name"` // 架构名称 | |||
| ArchFreq string `db:"arch_freq"` // 架构频率 | |||
| ParticipantId int64 `db:"participant_id"` // 集群静态信息id | |||
| DeletedFlag int64 `db:"deleted_flag"` // 是否删除 | |||
| CreatedBy sql.NullInt64 `db:"created_by"` // 创建人 | |||
| CreatedTime time.Time `db:"created_time"` // 创建时间 | |||
| UpdatedBy sql.NullInt64 `db:"updated_by"` // 更新人 | |||
| UpdatedTime sql.NullTime `db:"updated_time"` // 更新时间 | |||
| } | |||
| ) | |||
| @@ -95,6 +95,33 @@ func (m *defaultScNodePhyInfoModel) FindOne(ctx context.Context, id int64) (*ScN | |||
| } | |||
| } | |||
| func (m *defaultScNodePhyInfoModel) Insert(ctx context.Context, data *ScNodePhyInfo) (sql.Result, error) { | |||
| pcmScNodePhyInfoIdKey := fmt.Sprintf("%s%v", cachePcmScNodePhyInfoIdPrefix, data.Id) | |||
| ret, err := m.ExecCtx(ctx, func(ctx context.Context, conn sqlx.SqlConn) (result sql.Result, err error) { | |||
| query := fmt.Sprintf("insert into %s (%s) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", m.table, scNodePhyInfoRowsExpectAutoSet) | |||
| return conn.ExecCtx(ctx, query, data.Id, data.NodeName, data.OsName, data.OsVersion, data.ArchType, data.ArchName, data.ArchFreq, data.ParticipantId, data.DeletedFlag, data.CreatedBy, data.CreatedTime, data.UpdatedBy, data.UpdatedTime) | |||
| }, pcmScNodePhyInfoIdKey) | |||
| return ret, err | |||
| } | |||
| func (m *defaultScNodePhyInfoModel) Update(ctx context.Context, data *ScNodePhyInfo) error { | |||
| pcmScNodePhyInfoIdKey := fmt.Sprintf("%s%v", cachePcmScNodePhyInfoIdPrefix, data.Id) | |||
| _, err := m.ExecCtx(ctx, func(ctx context.Context, conn sqlx.SqlConn) (result sql.Result, err error) { | |||
| query := fmt.Sprintf("update %s set %s where `id` = ?", m.table, scNodePhyInfoRowsWithPlaceHolder) | |||
| return conn.ExecCtx(ctx, query, data.NodeName, data.OsName, data.OsVersion, data.ArchType, data.ArchName, data.ArchFreq, data.ParticipantId, data.DeletedFlag, data.CreatedBy, data.CreatedTime, data.UpdatedBy, data.UpdatedTime, data.Id) | |||
| }, pcmScNodePhyInfoIdKey) | |||
| return err | |||
| } | |||
| func (m *defaultScNodePhyInfoModel) formatPrimary(primary any) string { | |||
| return fmt.Sprintf("%s%v", cachePcmScNodePhyInfoIdPrefix, primary) | |||
| } | |||
| func (m *defaultScNodePhyInfoModel) queryPrimary(ctx context.Context, conn sqlx.SqlConn, v, primary any) error { | |||
| query := fmt.Sprintf("select %s from %s where `id` = ? limit 1", scNodePhyInfoRows, m.table) | |||
| return conn.QueryRowCtx(ctx, v, query, primary) | |||
| } | |||
| func (m *defaultScNodePhyInfoModel) tableName() string { | |||
| return m.table | |||
| } | |||
| @@ -1,5 +1,12 @@ | |||
| package model | |||
| import ( | |||
| "github.com/zeromicro/go-zero/core/stores/cache" | |||
| "github.com/zeromicro/go-zero/core/stores/sqlx" | |||
| ) | |||
| var _ ScParticipantAvailInfoModel = (*customScParticipantAvailInfoModel)(nil) | |||
| type ( | |||
| // ScParticipantAvailInfoModel is an interface to be customized, add more methods here, | |||
| // and implement the added methods in customScParticipantAvailInfoModel. | |||
| @@ -11,3 +18,10 @@ type ( | |||
| *defaultScParticipantAvailInfoModel | |||
| } | |||
| ) | |||
| // NewScParticipantAvailInfoModel returns a model for the database table. | |||
| func NewScParticipantAvailInfoModel(conn sqlx.SqlConn, c cache.CacheConf, opts ...cache.Option) ScParticipantAvailInfoModel { | |||
| return &customScParticipantAvailInfoModel{ | |||
| defaultScParticipantAvailInfoModel: newScParticipantAvailInfoModel(conn, c, opts...), | |||
| } | |||
| } | |||
| @@ -5,6 +5,7 @@ package model | |||
| import ( | |||
| "context" | |||
| "database/sql" | |||
| "fmt" | |||
| "strings" | |||
| "time" | |||
| @@ -38,19 +39,19 @@ type ( | |||
| } | |||
| ScParticipantAvailInfo struct { | |||
| Id int64 `db:"id"` // id | |||
| Host string `db:"host"` // 集群p端host | |||
| Port string `db:"port"` // 集群p端端口 | |||
| AvailStorageSpace int64 `db:"avail_storage_space"` // 集群存储可用空间 | |||
| UserNum int64 `db:"user_num"` // 用户数量 | |||
| PendingJobNum int64 `db:"pending_job_num"` // 待处理作业数量 | |||
| RunningJobNum int64 `db:"running_job_num"` // 运行作业数量 | |||
| ParticipantId int64 `db:"participant_id"` // 集群静态信息id | |||
| DeletedFlag int64 `db:"deleted_flag"` // 是否删除 | |||
| CreatedBy sql.NullInt64 `db:"created_by"` // 创建人 | |||
| CreatedTime time.Time `db:"created_time"` // 创建时间 | |||
| UpdatedBy sql.NullInt64 `db:"updated_by"` // 更新人 | |||
| UpdatedTime sql.NullTime `db:"updated_time"` // 更新时间 | |||
| Id int64 `db:"id"` // id | |||
| Host sql.NullString `db:"host"` // 集群p端host | |||
| Port sql.NullString `db:"port"` // 集群p端端口 | |||
| AvailStorageSpace sql.NullInt64 `db:"avail_storage_space"` // 集群存储可用空间 | |||
| UserNum sql.NullInt64 `db:"user_num"` // 用户数量 | |||
| PendingJobNum sql.NullInt64 `db:"pending_job_num"` // 待处理作业数量 | |||
| RunningJobNum int64 `db:"running_job_num"` // 运行作业数量 | |||
| ParticipantId int64 `db:"participant_id"` // 集群静态信息id | |||
| DeletedFlag int64 `db:"deleted_flag"` // 是否删除 | |||
| CreatedBy sql.NullInt64 `db:"created_by"` // 创建人 | |||
| CreatedTime time.Time `db:"created_time"` // 创建时间 | |||
| UpdatedBy sql.NullInt64 `db:"updated_by"` // 更新人 | |||
| UpdatedTime sql.NullTime `db:"updated_time"` // 更新时间 | |||
| } | |||
| ) | |||
| @@ -68,6 +69,59 @@ func (m *defaultScParticipantAvailInfoModel) withSession(session sqlx.Session) * | |||
| } | |||
| } | |||
| func (m *defaultScParticipantAvailInfoModel) Delete(ctx context.Context, id int64) error { | |||
| pcmScParticipantAvailInfoIdKey := fmt.Sprintf("%s%v", cachePcmScParticipantAvailInfoIdPrefix, id) | |||
| _, err := m.ExecCtx(ctx, func(ctx context.Context, conn sqlx.SqlConn) (result sql.Result, err error) { | |||
| query := fmt.Sprintf("delete from %s where `id` = ?", m.table) | |||
| return conn.ExecCtx(ctx, query, id) | |||
| }, pcmScParticipantAvailInfoIdKey) | |||
| return err | |||
| } | |||
| func (m *defaultScParticipantAvailInfoModel) FindOne(ctx context.Context, id int64) (*ScParticipantAvailInfo, error) { | |||
| pcmScParticipantAvailInfoIdKey := fmt.Sprintf("%s%v", cachePcmScParticipantAvailInfoIdPrefix, id) | |||
| var resp ScParticipantAvailInfo | |||
| err := m.QueryRowCtx(ctx, &resp, pcmScParticipantAvailInfoIdKey, func(ctx context.Context, conn sqlx.SqlConn, v any) error { | |||
| query := fmt.Sprintf("select %s from %s where `id` = ? limit 1", scParticipantAvailInfoRows, m.table) | |||
| return conn.QueryRowCtx(ctx, v, query, id) | |||
| }) | |||
| switch err { | |||
| case nil: | |||
| return &resp, nil | |||
| case sqlc.ErrNotFound: | |||
| return nil, ErrNotFound | |||
| default: | |||
| return nil, err | |||
| } | |||
| } | |||
| func (m *defaultScParticipantAvailInfoModel) Insert(ctx context.Context, data *ScParticipantAvailInfo) (sql.Result, error) { | |||
| pcmScParticipantAvailInfoIdKey := fmt.Sprintf("%s%v", cachePcmScParticipantAvailInfoIdPrefix, data.Id) | |||
| ret, err := m.ExecCtx(ctx, func(ctx context.Context, conn sqlx.SqlConn) (result sql.Result, err error) { | |||
| query := fmt.Sprintf("insert into %s (%s) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", m.table, scParticipantAvailInfoRowsExpectAutoSet) | |||
| return conn.ExecCtx(ctx, query, data.Id, data.Host, data.Port, data.AvailStorageSpace, data.UserNum, data.PendingJobNum, data.RunningJobNum, data.ParticipantId, data.DeletedFlag, data.CreatedBy, data.CreatedTime, data.UpdatedBy, data.UpdatedTime) | |||
| }, pcmScParticipantAvailInfoIdKey) | |||
| return ret, err | |||
| } | |||
| func (m *defaultScParticipantAvailInfoModel) Update(ctx context.Context, data *ScParticipantAvailInfo) error { | |||
| pcmScParticipantAvailInfoIdKey := fmt.Sprintf("%s%v", cachePcmScParticipantAvailInfoIdPrefix, data.Id) | |||
| _, err := m.ExecCtx(ctx, func(ctx context.Context, conn sqlx.SqlConn) (result sql.Result, err error) { | |||
| query := fmt.Sprintf("update %s set %s where `id` = ?", m.table, scParticipantAvailInfoRowsWithPlaceHolder) | |||
| return conn.ExecCtx(ctx, query, data.Host, data.Port, data.AvailStorageSpace, data.UserNum, data.PendingJobNum, data.RunningJobNum, data.ParticipantId, data.DeletedFlag, data.CreatedBy, data.CreatedTime, data.UpdatedBy, data.UpdatedTime, data.Id) | |||
| }, pcmScParticipantAvailInfoIdKey) | |||
| return err | |||
| } | |||
| func (m *defaultScParticipantAvailInfoModel) formatPrimary(primary any) string { | |||
| return fmt.Sprintf("%s%v", cachePcmScParticipantAvailInfoIdPrefix, primary) | |||
| } | |||
| func (m *defaultScParticipantAvailInfoModel) queryPrimary(ctx context.Context, conn sqlx.SqlConn, v, primary any) error { | |||
| query := fmt.Sprintf("select %s from %s where `id` = ? limit 1", scParticipantAvailInfoRows, m.table) | |||
| return conn.QueryRowCtx(ctx, v, query, primary) | |||
| } | |||
| func (m *defaultScParticipantAvailInfoModel) tableName() string { | |||
| return m.table | |||
| } | |||
| @@ -40,6 +40,8 @@ type ( | |||
| ScParticipantPhyInfo struct { | |||
| Id int64 `db:"id"` // id | |||
| Host string `db:"host"` // 集群p端host | |||
| Port string `db:"port"` // 集群p端端口 | |||
| NetworkType string `db:"network_type"` // 集群网络类型 | |||
| NetworkBandwidth string `db:"network_bandwidth"` // 集群网络带宽 | |||
| StorageType string `db:"storage_type"` // 集群存储类型 | |||
| @@ -47,6 +49,7 @@ type ( | |||
| StorageAvailSpace string `db:"storage_avail_space"` // 集群存储可用空间 | |||
| StorageBandwidth string `db:"storage_bandwidth"` // 集群存储带宽 | |||
| TenantId int64 `db:"tenant_id"` // 租户信息id | |||
| Type int64 `db:"type"` // 类型:0-数算集群;1-智算集群;2-超算集群 | |||
| DeletedFlag int64 `db:"deleted_flag"` // 是否删除 | |||
| CreatedBy sql.NullInt64 `db:"created_by"` // 创建人 | |||
| CreatedTime time.Time `db:"created_time"` // 创建时间 | |||
| @@ -98,8 +101,8 @@ func (m *defaultScParticipantPhyInfoModel) FindOne(ctx context.Context, id int64 | |||
| func (m *defaultScParticipantPhyInfoModel) Insert(ctx context.Context, data *ScParticipantPhyInfo) (sql.Result, error) { | |||
| pcmScParticipantPhyInfoIdKey := fmt.Sprintf("%s%v", cachePcmScParticipantPhyInfoIdPrefix, data.Id) | |||
| ret, err := m.ExecCtx(ctx, func(ctx context.Context, conn sqlx.SqlConn) (result sql.Result, err error) { | |||
| query := fmt.Sprintf("insert into %s (%s) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", m.table, scParticipantPhyInfoRowsExpectAutoSet) | |||
| return conn.ExecCtx(ctx, query, data.Id, data.NetworkType, data.NetworkBandwidth, data.StorageType, data.StorageSpace, data.StorageAvailSpace, data.StorageBandwidth, data.TenantId, data.DeletedFlag, data.CreatedBy, data.CreatedTime, data.UpdatedBy, data.UpdatedTime) | |||
| query := fmt.Sprintf("insert into %s (%s) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", m.table, scParticipantPhyInfoRowsExpectAutoSet) | |||
| return conn.ExecCtx(ctx, query, data.Id, data.Host, data.Port, data.NetworkType, data.NetworkBandwidth, data.StorageType, data.StorageSpace, data.StorageAvailSpace, data.StorageBandwidth, data.TenantId, data.Type, data.DeletedFlag, data.CreatedBy, data.CreatedTime, data.UpdatedBy, data.UpdatedTime) | |||
| }, pcmScParticipantPhyInfoIdKey) | |||
| return ret, err | |||
| } | |||
| @@ -108,7 +111,7 @@ func (m *defaultScParticipantPhyInfoModel) Update(ctx context.Context, data *ScP | |||
| pcmScParticipantPhyInfoIdKey := fmt.Sprintf("%s%v", cachePcmScParticipantPhyInfoIdPrefix, data.Id) | |||
| _, err := m.ExecCtx(ctx, func(ctx context.Context, conn sqlx.SqlConn) (result sql.Result, err error) { | |||
| query := fmt.Sprintf("update %s set %s where `id` = ?", m.table, scParticipantPhyInfoRowsWithPlaceHolder) | |||
| return conn.ExecCtx(ctx, query, data.NetworkType, data.NetworkBandwidth, data.StorageType, data.StorageSpace, data.StorageAvailSpace, data.StorageBandwidth, data.TenantId, data.DeletedFlag, data.CreatedBy, data.CreatedTime, data.UpdatedBy, data.UpdatedTime, data.Id) | |||
| return conn.ExecCtx(ctx, query, data.Host, data.Port, data.NetworkType, data.NetworkBandwidth, data.StorageType, data.StorageSpace, data.StorageAvailSpace, data.StorageBandwidth, data.TenantId, data.Type, data.DeletedFlag, data.CreatedBy, data.CreatedTime, data.UpdatedBy, data.UpdatedTime, data.Id) | |||
| }, pcmScParticipantPhyInfoIdKey) | |||
| return err | |||
| } | |||
| @@ -0,0 +1,5 @@ | |||
| pcm-core-rpc: | |||
| CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o pcm-core-rpc adaptor/PCM-CORE/rpc/pcmcore.go | |||
| rpc-gen: | |||
| goctl rpc protoc pb/*.proto --go_out=. --go-grpc_out=. --zrpc_out=. -m | |||
| @@ -0,0 +1,49 @@ | |||
| // Code generated by goctl. DO NOT EDIT. | |||
| // Source: pcmCore.proto | |||
| package participantservice | |||
| import ( | |||
| "context" | |||
| "gitlink.org.cn/jcce-pcm/pcm-coordinator/rpc/pcmCore" | |||
| "github.com/zeromicro/go-zero/zrpc" | |||
| "google.golang.org/grpc" | |||
| ) | |||
| type ( | |||
| AiInfo = pcmCore.AiInfo | |||
| CloudInfo = pcmCore.CloudInfo | |||
| HpcInfo = pcmCore.HpcInfo | |||
| InfoListReq = pcmCore.InfoListReq | |||
| InfoListResp = pcmCore.InfoListResp | |||
| NodeLabel = pcmCore.NodeLabel | |||
| NodePhyInfo = pcmCore.NodePhyInfo | |||
| ParticipantPhyReq = pcmCore.ParticipantPhyReq | |||
| ParticipantPhyResp = pcmCore.ParticipantPhyResp | |||
| ParticipantTenant = pcmCore.ParticipantTenant | |||
| SyncInfoReq = pcmCore.SyncInfoReq | |||
| SyncInfoResp = pcmCore.SyncInfoResp | |||
| ParticipantService interface { | |||
| // registerParticipant Participant注册接口 | |||
| RegisterParticipant(ctx context.Context, in *ParticipantPhyReq, opts ...grpc.CallOption) (*ParticipantPhyResp, error) | |||
| } | |||
| defaultParticipantService struct { | |||
| cli zrpc.Client | |||
| } | |||
| ) | |||
| func NewParticipantService(cli zrpc.Client) ParticipantService { | |||
| return &defaultParticipantService{ | |||
| cli: cli, | |||
| } | |||
| } | |||
| // registerParticipant Participant注册接口 | |||
| func (m *defaultParticipantService) RegisterParticipant(ctx context.Context, in *ParticipantPhyReq, opts ...grpc.CallOption) (*ParticipantPhyResp, error) { | |||
| client := pcmCore.NewParticipantServiceClient(m.cli.Conn()) | |||
| return client.RegisterParticipant(ctx, in, opts...) | |||
| } | |||
| @@ -1,7 +1,7 @@ | |||
| // Code generated by goctl. DO NOT EDIT. | |||
| // Source: pcmCore.proto | |||
| package pcmcoreclient | |||
| package pcmcore | |||
| import ( | |||
| "context" | |||
| @@ -13,13 +13,18 @@ import ( | |||
| ) | |||
| type ( | |||
| AiInfo = pcmCore.AiInfo | |||
| CloudInfo = pcmCore.CloudInfo | |||
| HpcInfo = pcmCore.HpcInfo | |||
| InfoListReq = pcmCore.InfoListReq | |||
| InfoListResp = pcmCore.InfoListResp | |||
| SyncInfoReq = pcmCore.SyncInfoReq | |||
| SyncInfoResp = pcmCore.SyncInfoResp | |||
| AiInfo = pcmCore.AiInfo | |||
| CloudInfo = pcmCore.CloudInfo | |||
| HpcInfo = pcmCore.HpcInfo | |||
| InfoListReq = pcmCore.InfoListReq | |||
| InfoListResp = pcmCore.InfoListResp | |||
| NodeLabel = pcmCore.NodeLabel | |||
| NodePhyInfo = pcmCore.NodePhyInfo | |||
| ParticipantPhyReq = pcmCore.ParticipantPhyReq | |||
| ParticipantPhyResp = pcmCore.ParticipantPhyResp | |||
| ParticipantTenant = pcmCore.ParticipantTenant | |||
| SyncInfoReq = pcmCore.SyncInfoReq | |||
| SyncInfoResp = pcmCore.SyncInfoResp | |||
| PcmCore interface { | |||
| // SyncInfo Synchronous data information | |||
| @@ -4,7 +4,7 @@ NacosConfig: | |||
| ServerConfigs: | |||
| # - IpAddr: 127.0.0.1 | |||
| # Port: 8848 | |||
| - IpAddr: nacos.jcce.dev | |||
| - IpAddr: 10.101.15.7 | |||
| Port: 8848 | |||
| ClientConfig: | |||
| NamespaceId: test | |||
| @@ -10,5 +10,11 @@ type Config struct { | |||
| DB struct { | |||
| DataSource string | |||
| } | |||
| LogConf logx.LogConf | |||
| LogConf logx.LogConf | |||
| SnowflakeConf SnowflakeConf | |||
| } | |||
| // SnowflakeConf 雪花算法机器id配置 | |||
| type SnowflakeConf struct { | |||
| MachineId int64 `json:"machineId"` | |||
| } | |||
| @@ -0,0 +1,71 @@ | |||
| package participantservicelogic | |||
| import ( | |||
| "context" | |||
| "gitlink.org.cn/jcce-pcm/pcm-coordinator/model" | |||
| "gitlink.org.cn/jcce-pcm/utils/tool" | |||
| "time" | |||
| "gitlink.org.cn/jcce-pcm/pcm-coordinator/rpc/internal/svc" | |||
| "gitlink.org.cn/jcce-pcm/pcm-coordinator/rpc/pcmCore" | |||
| "github.com/zeromicro/go-zero/core/logx" | |||
| ) | |||
| type RegisterParticipantLogic struct { | |||
| ctx context.Context | |||
| svcCtx *svc.ServiceContext | |||
| logx.Logger | |||
| } | |||
| func NewRegisterParticipantLogic(ctx context.Context, svcCtx *svc.ServiceContext) *RegisterParticipantLogic { | |||
| return &RegisterParticipantLogic{ | |||
| ctx: ctx, | |||
| svcCtx: svcCtx, | |||
| Logger: logx.WithContext(ctx), | |||
| } | |||
| } | |||
| // RegisterParticipant Participant注册接口 | |||
| func (l *RegisterParticipantLogic) RegisterParticipant(in *pcmCore.ParticipantPhyReq) (*pcmCore.ParticipantPhyResp, error) { | |||
| //判断ParticipantId是否存在 | |||
| db := l.svcCtx.DbEngin | |||
| if db.Error != nil { | |||
| return nil, db.Error | |||
| } | |||
| participantInfo := &model.ScParticipantPhyInfo{} | |||
| tool.Convert(in, participantInfo) | |||
| if in.ParticipantId == 0 { | |||
| var err error | |||
| participantInfo.Id, err = tool.GenSnowflakeID(l.svcCtx.Config.SnowflakeConf.MachineId) | |||
| if err != nil { | |||
| logx.Errorf("生成id错误 err:", err) | |||
| } | |||
| } else { | |||
| participantInfo.Id = in.ParticipantId | |||
| } | |||
| participantInfo.CreatedTime = time.Now() | |||
| //保存participant静态信息 | |||
| result := db.Save(&participantInfo) | |||
| //保存节点信息 | |||
| nodeInfo := &model.ScNodePhyInfo{} | |||
| for _, info := range in.NodeInfo { | |||
| var err error | |||
| tool.Convert(info, nodeInfo) | |||
| nodeInfo.CreatedTime = time.Now() | |||
| nodeInfo.ParticipantId = participantInfo.Id | |||
| nodeInfo.Id, err = tool.GenSnowflakeID(l.svcCtx.Config.SnowflakeConf.MachineId) | |||
| if err != nil { | |||
| logx.Errorf("生成id错误 err:", err) | |||
| } | |||
| result = db.Save(nodeInfo) | |||
| if result.Error != nil { | |||
| logx.Errorf("orm err:", result.Error) | |||
| return &pcmCore.ParticipantPhyResp{}, nil | |||
| } | |||
| } | |||
| if result.Error != nil { | |||
| logx.Errorf("orm err:", result.Error) | |||
| } | |||
| return &pcmCore.ParticipantPhyResp{}, nil | |||
| } | |||
| @@ -1,4 +1,4 @@ | |||
| package logic | |||
| package pcmcorelogic | |||
| import ( | |||
| "context" | |||
| @@ -1,4 +1,4 @@ | |||
| package logic | |||
| package pcmcorelogic | |||
| import ( | |||
| "context" | |||
| @@ -0,0 +1,29 @@ | |||
| // Code generated by goctl. DO NOT EDIT. | |||
| // Source: pcmCore.proto | |||
| package server | |||
| import ( | |||
| "context" | |||
| "gitlink.org.cn/jcce-pcm/pcm-coordinator/rpc/internal/logic/participantservice" | |||
| "gitlink.org.cn/jcce-pcm/pcm-coordinator/rpc/internal/svc" | |||
| "gitlink.org.cn/jcce-pcm/pcm-coordinator/rpc/pcmCore" | |||
| ) | |||
| type ParticipantServiceServer struct { | |||
| svcCtx *svc.ServiceContext | |||
| pcmCore.UnimplementedParticipantServiceServer | |||
| } | |||
| func NewParticipantServiceServer(svcCtx *svc.ServiceContext) *ParticipantServiceServer { | |||
| return &ParticipantServiceServer{ | |||
| svcCtx: svcCtx, | |||
| } | |||
| } | |||
| // registerParticipant Participant注册接口 | |||
| func (s *ParticipantServiceServer) RegisterParticipant(ctx context.Context, in *pcmCore.ParticipantPhyReq) (*pcmCore.ParticipantPhyResp, error) { | |||
| l := participantservicelogic.NewRegisterParticipantLogic(ctx, s.svcCtx) | |||
| return l.RegisterParticipant(in) | |||
| } | |||
| @@ -6,7 +6,7 @@ package server | |||
| import ( | |||
| "context" | |||
| "gitlink.org.cn/jcce-pcm/pcm-coordinator/rpc/internal/logic" | |||
| "gitlink.org.cn/jcce-pcm/pcm-coordinator/rpc/internal/logic/pcmcore" | |||
| "gitlink.org.cn/jcce-pcm/pcm-coordinator/rpc/internal/svc" | |||
| "gitlink.org.cn/jcce-pcm/pcm-coordinator/rpc/pcmCore" | |||
| ) | |||
| @@ -24,12 +24,12 @@ func NewPcmCoreServer(svcCtx *svc.ServiceContext) *PcmCoreServer { | |||
| // SyncInfo Synchronous data information | |||
| func (s *PcmCoreServer) SyncInfo(ctx context.Context, in *pcmCore.SyncInfoReq) (*pcmCore.SyncInfoResp, error) { | |||
| l := logic.NewSyncInfoLogic(ctx, s.svcCtx) | |||
| l := pcmcorelogic.NewSyncInfoLogic(ctx, s.svcCtx) | |||
| return l.SyncInfo(in) | |||
| } | |||
| // InfoList | |||
| func (s *PcmCoreServer) InfoList(ctx context.Context, in *pcmCore.InfoListReq) (*pcmCore.InfoListResp, error) { | |||
| l := logic.NewInfoListLogic(ctx, s.svcCtx) | |||
| l := pcmcorelogic.NewInfoListLogic(ctx, s.svcCtx) | |||
| return l.InfoList(in) | |||
| } | |||
| @@ -20,13 +20,13 @@ message AiInfo { | |||
| string startTime = 6; | |||
| int64 runningTime = 7; | |||
| string result = 8; | |||
| string jobId =9; | |||
| string jobId = 9; | |||
| string createTime = 10; | |||
| string imageUrl =11; | |||
| string imageUrl = 11; | |||
| string command = 12; | |||
| string flavorId =13; | |||
| string subscriptionId =14; | |||
| string itemVersionId =15; | |||
| string flavorId = 13; | |||
| string subscriptionId = 14; | |||
| string itemVersionId = 15; | |||
| } | |||
| message CloudInfo { | |||
| @@ -57,13 +57,13 @@ message HpcInfo { | |||
| string wallTime = 10; | |||
| string cmdScript = 11; | |||
| string derivedEs = 12; | |||
| string cluster =13; | |||
| string cluster = 13; | |||
| string blockId = 14; | |||
| uint32 allocNodes = 15; | |||
| uint32 allocCpu =16; | |||
| uint32 allocCpu = 16; | |||
| string version = 17; | |||
| string account =18; | |||
| uint32 exitCode =19; | |||
| string account = 18; | |||
| uint32 exitCode = 19; | |||
| uint32 assocId = 20; | |||
| } | |||
| @@ -84,7 +84,6 @@ message InfoListResp{ | |||
| } | |||
| // pcm core services | |||
| service pcmCore { | |||
| @@ -93,5 +92,67 @@ service pcmCore { | |||
| //InfoList | |||
| rpc InfoList(InfoListReq) returns (InfoListResp); | |||
| } | |||
| // participantTenant 租户信息 | |||
| message participantTenant{ | |||
| string tenantName = 1; //租户名称 | |||
| } | |||
| // 节点标签 | |||
| message NodeLabel { | |||
| string id = 1; //id | |||
| string label = 2; //标签名称 | |||
| } | |||
| enum MessageStatus { | |||
| FAIL = 0; | |||
| SUCCESS = 1; | |||
| UNKNOWN = 2; | |||
| } | |||
| message ParticipantPhyResp { | |||
| int64 code = 1; | |||
| string msg = 2; | |||
| string participantId = 3; //participant 唯一标识 | |||
| } | |||
| //participantPhy 静态信息 | |||
| message ParticipantPhyReq { | |||
| string host = 2; //host | |||
| string port = 3; //端口号 | |||
| string networkType = 4; //集群网络类型 | |||
| string networkBandwidth = 5; //集群网络带宽 | |||
| string storageType = 6; //集群存储类型 | |||
| string storageSpace = 7; //集群存储空间 | |||
| string storageAvailSpace = 8; //集群存储可用空间 | |||
| string storageBandwidth = 9; //集群存储带宽 | |||
| string type = 10; //参与者类型:0-数算集群;1-智算集群;2-超算集群 | |||
| int64 tenantId = 11; //租户id | |||
| string tenantName = 12; //租户名称 | |||
| repeated NodePhyInfo nodeInfo = 13; //节点信息 | |||
| int64 participantId = 14; //participant id | |||
| } | |||
| // nodePhyInfo 节点信息 | |||
| message NodePhyInfo { | |||
| string nodeName = 1; //节点名称 | |||
| string osName = 2; //系统名称 | |||
| string osVersion = 3; //系统版本 | |||
| string archType = 4; //架构类型 | |||
| string archName = 5; //架构名称 | |||
| string archFreq = 6; //架构频率 | |||
| repeated NodeLabel nodeLabel = 7; //节点标签 | |||
| } | |||
| // participant 参与者 | |||
| service participantService { | |||
| // registerParticipant Participant注册接口 | |||
| rpc registerParticipant (ParticipantPhyReq) returns (ParticipantPhyResp) {}; | |||
| // //集群心跳 | |||
| // rpc reportHeartbeat (ClusterHeartbeatMessageProto) returns (MessageResponseProto) {}; | |||
| // //集群动态信息 | |||
| // rpc reportAvailResource (ClusterAvailResMessageProto) returns (MessageResponseProto) {}; | |||
| // //集群静态信息 | |||
| // rpc reportPhysicResource (ClusterPhyResMessageProto) returns (MessageResponseProto) {}; | |||
| } | |||
| @@ -1,8 +1,8 @@ | |||
| // Code generated by protoc-gen-go-grpc. DO NOT EDIT. | |||
| // versions: | |||
| // - protoc-gen-go-grpc v1.3.0 | |||
| // - protoc v4.22.2 | |||
| // source: pcmCore.proto | |||
| // - protoc v4.23.4 | |||
| // source: pb/pcmCore.proto | |||
| package pcmCore | |||
| @@ -146,5 +146,97 @@ var PcmCore_ServiceDesc = grpc.ServiceDesc{ | |||
| }, | |||
| }, | |||
| Streams: []grpc.StreamDesc{}, | |||
| Metadata: "pcmCore.proto", | |||
| Metadata: "pb/pcmCore.proto", | |||
| } | |||
| const ( | |||
| ParticipantService_RegisterParticipant_FullMethodName = "/pcmCore.participantService/registerParticipant" | |||
| ) | |||
| // ParticipantServiceClient is the client API for ParticipantService service. | |||
| // | |||
| // For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream. | |||
| type ParticipantServiceClient interface { | |||
| // registerParticipant Participant注册接口 | |||
| RegisterParticipant(ctx context.Context, in *ParticipantPhyReq, opts ...grpc.CallOption) (*ParticipantPhyResp, error) | |||
| } | |||
| type participantServiceClient struct { | |||
| cc grpc.ClientConnInterface | |||
| } | |||
| func NewParticipantServiceClient(cc grpc.ClientConnInterface) ParticipantServiceClient { | |||
| return &participantServiceClient{cc} | |||
| } | |||
| func (c *participantServiceClient) RegisterParticipant(ctx context.Context, in *ParticipantPhyReq, opts ...grpc.CallOption) (*ParticipantPhyResp, error) { | |||
| out := new(ParticipantPhyResp) | |||
| err := c.cc.Invoke(ctx, ParticipantService_RegisterParticipant_FullMethodName, in, out, opts...) | |||
| if err != nil { | |||
| return nil, err | |||
| } | |||
| return out, nil | |||
| } | |||
| // ParticipantServiceServer is the server API for ParticipantService service. | |||
| // All implementations must embed UnimplementedParticipantServiceServer | |||
| // for forward compatibility | |||
| type ParticipantServiceServer interface { | |||
| // registerParticipant Participant注册接口 | |||
| RegisterParticipant(context.Context, *ParticipantPhyReq) (*ParticipantPhyResp, error) | |||
| mustEmbedUnimplementedParticipantServiceServer() | |||
| } | |||
| // UnimplementedParticipantServiceServer must be embedded to have forward compatible implementations. | |||
| type UnimplementedParticipantServiceServer struct { | |||
| } | |||
| func (UnimplementedParticipantServiceServer) RegisterParticipant(context.Context, *ParticipantPhyReq) (*ParticipantPhyResp, error) { | |||
| return nil, status.Errorf(codes.Unimplemented, "method RegisterParticipant not implemented") | |||
| } | |||
| func (UnimplementedParticipantServiceServer) mustEmbedUnimplementedParticipantServiceServer() {} | |||
| // UnsafeParticipantServiceServer may be embedded to opt out of forward compatibility for this service. | |||
| // Use of this interface is not recommended, as added methods to ParticipantServiceServer will | |||
| // result in compilation errors. | |||
| type UnsafeParticipantServiceServer interface { | |||
| mustEmbedUnimplementedParticipantServiceServer() | |||
| } | |||
| func RegisterParticipantServiceServer(s grpc.ServiceRegistrar, srv ParticipantServiceServer) { | |||
| s.RegisterService(&ParticipantService_ServiceDesc, srv) | |||
| } | |||
| func _ParticipantService_RegisterParticipant_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { | |||
| in := new(ParticipantPhyReq) | |||
| if err := dec(in); err != nil { | |||
| return nil, err | |||
| } | |||
| if interceptor == nil { | |||
| return srv.(ParticipantServiceServer).RegisterParticipant(ctx, in) | |||
| } | |||
| info := &grpc.UnaryServerInfo{ | |||
| Server: srv, | |||
| FullMethod: ParticipantService_RegisterParticipant_FullMethodName, | |||
| } | |||
| handler := func(ctx context.Context, req interface{}) (interface{}, error) { | |||
| return srv.(ParticipantServiceServer).RegisterParticipant(ctx, req.(*ParticipantPhyReq)) | |||
| } | |||
| return interceptor(ctx, in, info, handler) | |||
| } | |||
| // ParticipantService_ServiceDesc is the grpc.ServiceDesc for ParticipantService service. | |||
| // It's only intended for direct use with grpc.RegisterService, | |||
| // and not to be introspected or modified (even as a copy) | |||
| var ParticipantService_ServiceDesc = grpc.ServiceDesc{ | |||
| ServiceName: "pcmCore.participantService", | |||
| HandlerType: (*ParticipantServiceServer)(nil), | |||
| Methods: []grpc.MethodDesc{ | |||
| { | |||
| MethodName: "registerParticipant", | |||
| Handler: _ParticipantService_RegisterParticipant_Handler, | |||
| }, | |||
| }, | |||
| Streams: []grpc.StreamDesc{}, | |||
| Metadata: "pb/pcmCore.proto", | |||
| } | |||
| @@ -8,7 +8,8 @@ import ( | |||
| "github.com/zeromicro/go-zero/zrpc" | |||
| "gitlink.org.cn/jcce-pcm/pcm-coordinator/rpc/internal/config" | |||
| "gitlink.org.cn/jcce-pcm/pcm-coordinator/rpc/internal/logic" | |||
| "gitlink.org.cn/jcce-pcm/pcm-coordinator/rpc/internal/server" | |||
| participantserviceServer "gitlink.org.cn/jcce-pcm/pcm-coordinator/rpc/internal/server/participantservice" | |||
| pcmcoreServer "gitlink.org.cn/jcce-pcm/pcm-coordinator/rpc/internal/server/pcmcore" | |||
| "gitlink.org.cn/jcce-pcm/pcm-coordinator/rpc/internal/svc" | |||
| "gitlink.org.cn/jcce-pcm/pcm-coordinator/rpc/pcmCore" | |||
| "gitlink.org.cn/jcce-pcm/utils/interceptor/rpcserver" | |||
| @@ -48,8 +49,8 @@ func main() { | |||
| ctx := svc.NewServiceContext(c) | |||
| s := zrpc.MustNewServer(c.RpcServerConf, func(grpcServer *grpc.Server) { | |||
| pcmCore.RegisterPcmCoreServer(grpcServer, server.NewPcmCoreServer(ctx)) | |||
| pcmCore.RegisterPcmCoreServer(grpcServer, pcmcoreServer.NewPcmCoreServer(ctx)) | |||
| pcmCore.RegisterParticipantServiceServer(grpcServer, participantserviceServer.NewParticipantServiceServer(ctx)) | |||
| if c.Mode == service.DevMode || c.Mode == service.TestMode { | |||
| reflection.Register(grpcServer) | |||
| } | |||