补充应用创建
This commit is contained in:
parent
0d7cdec6ea
commit
f018f28390
@ -88,7 +88,7 @@ func toJsonArray(arr []string) string {
|
||||
return string(b)
|
||||
}
|
||||
|
||||
func (r ResourceScope) GormResourceFilter(query *gorm.DB) {
|
||||
func (r ResourceScope) GormResourceFilter(query *gorm.DB) *gorm.DB {
|
||||
if r.NamespaceId != nil {
|
||||
query = query.Where("namespace = ?", r.NamespaceId)
|
||||
}
|
||||
@ -109,6 +109,8 @@ func (r ResourceScope) GormResourceFilter(query *gorm.DB) {
|
||||
query = query.Where("label->>? IN (?)", "$."+key, values)
|
||||
}
|
||||
}
|
||||
|
||||
return query
|
||||
}
|
||||
|
||||
func (r *CreatePolicyRequest) Validate() error {
|
||||
|
19
devcloud/mpaas/apps/application/fn_test.go
Normal file
19
devcloud/mpaas/apps/application/fn_test.go
Normal file
@ -0,0 +1,19 @@
|
||||
package application_test
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
"122.51.31.227/go-course/go18/devcloud/mpaas/apps/application"
|
||||
)
|
||||
|
||||
func TestXxx(t *testing.T) {
|
||||
app := &application.Application{}
|
||||
tt := reflect.TypeOf(app)
|
||||
// If app is a pointer, get the element type
|
||||
if tt.Kind() == reflect.Ptr {
|
||||
tt = tt.Elem()
|
||||
}
|
||||
fnName := tt.PkgPath() + "." + tt.Name()
|
||||
t.Log(fnName)
|
||||
}
|
@ -16,7 +16,7 @@ func (i *ApplicationServiceImpl) CreateApplication(ctx context.Context, in *appl
|
||||
}
|
||||
|
||||
if err := datasource.DBFromCtx(ctx).
|
||||
Create(ins).
|
||||
Save(ins).
|
||||
Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -38,7 +38,13 @@ func (i *ApplicationServiceImpl) QueryApplication(ctx context.Context, in *appli
|
||||
query = query.Where("ready = ?", *in.Ready)
|
||||
}
|
||||
|
||||
in.GormResourceFilter(query)
|
||||
if in.NamespaceId != nil {
|
||||
query = query.Where("namespace = ?", in.NamespaceId)
|
||||
}
|
||||
// 过滤条件, Label
|
||||
|
||||
if in.Scope != nil {
|
||||
}
|
||||
|
||||
err := query.Count(&set.Total).Error
|
||||
if err != nil {
|
||||
|
22
devcloud/mpaas/apps/application/impl/application_test.go
Normal file
22
devcloud/mpaas/apps/application/impl/application_test.go
Normal file
@ -0,0 +1,22 @@
|
||||
package impl_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"122.51.31.227/go-course/go18/devcloud/mpaas/apps/application"
|
||||
)
|
||||
|
||||
func TestCreateApplication(t *testing.T) {
|
||||
req := application.NewCreateApplicationRequest()
|
||||
req.Name = "devcloud"
|
||||
req.Description = "应用研发云"
|
||||
req.Type = application.TYPE_SOURCE_CODE
|
||||
req.CodeRepository = application.CodeRepository{
|
||||
SshUrl: "git@122.51.31.227:go-course/go18.git",
|
||||
}
|
||||
ins, err := svc.CreateApplication(ctx, req)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
t.Log(ins)
|
||||
}
|
18
devcloud/mpaas/apps/application/impl/impl_test.go
Normal file
18
devcloud/mpaas/apps/application/impl/impl_test.go
Normal file
@ -0,0 +1,18 @@
|
||||
package impl_test
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"122.51.31.227/go-course/go18/devcloud/mpaas/apps/application"
|
||||
"122.51.31.227/go-course/go18/devcloud/mpaas/test"
|
||||
)
|
||||
|
||||
var (
|
||||
svc application.Service
|
||||
ctx = context.Background()
|
||||
)
|
||||
|
||||
func init() {
|
||||
test.DevelopmentSetUp()
|
||||
svc = application.GetService()
|
||||
}
|
@ -57,6 +57,7 @@ type DeleteApplicationRequest struct {
|
||||
}
|
||||
|
||||
type DescribeApplicationRequest struct {
|
||||
policy.ResourceScope
|
||||
// 应用ID
|
||||
Id string `json:"id" bson:"_id"`
|
||||
}
|
||||
|
@ -20,7 +20,7 @@ func NewApplication(req CreateApplicationRequest) (*Application, error) {
|
||||
}
|
||||
|
||||
// 动态计算评审状态
|
||||
if len(req.Audits) > 0 {
|
||||
if len(req.Audits) == 0 {
|
||||
app.SetReady(true)
|
||||
} else {
|
||||
app.SetReady(false)
|
||||
@ -34,7 +34,7 @@ type Application struct {
|
||||
// 对象Id
|
||||
Id string `json:"id" bson:"_id" gorm:"column:id;primary_key"`
|
||||
// 更新时间
|
||||
UpdateAt time.Time `json:"update_at" bson:"update_at" gorm:"column:update_at"`
|
||||
UpdateAt *time.Time `json:"update_at" bson:"update_at" gorm:"column:update_at"`
|
||||
// 更新人
|
||||
UpdateBy string `json:"update_by" bson:"update_by" gorm:"column:update_by"`
|
||||
// 创建请求
|
||||
@ -71,6 +71,7 @@ func (a *Application) BuildId() {
|
||||
|
||||
func NewCreateApplicationRequest() *CreateApplicationRequest {
|
||||
return &CreateApplicationRequest{
|
||||
CreateAt: time.Now(),
|
||||
CreateApplicationSpec: CreateApplicationSpec{
|
||||
Extras: map[string]string{},
|
||||
ImageRepository: []ImageRepository{},
|
||||
@ -115,7 +116,7 @@ type CreateApplicationSpec struct {
|
||||
// 应用代码仓库信息
|
||||
CodeRepository CodeRepository `json:"code_repository" bson:",inline" gorm:"embedded" description:"应用代码仓库信息"`
|
||||
// 应用镜像仓库信息
|
||||
ImageRepository []ImageRepository `json:"image_repository" gorm:"column:image_repository;serializer:json;" bson:"image_repository" description:"应用镜像仓库信息"`
|
||||
ImageRepository []ImageRepository `json:"image_repository" gorm:"column:image_repository;type:json;serializer:json;" bson:"image_repository" description:"应用镜像仓库信息"`
|
||||
// 应用所有者
|
||||
Owner string `json:"owner" bson:"owner" gorm:"column:owner" description:"应用所有者"`
|
||||
// 应用等级, 评估这个应用的重要程度
|
||||
@ -123,10 +124,10 @@ type CreateApplicationSpec struct {
|
||||
// 应用优先级, 应用启动的先后顺序
|
||||
Priority *uint32 `json:"priority" bson:"priority" gorm:"column:priority" description:"应用优先级, 应用启动的先后顺序"`
|
||||
// 额外的其他属性
|
||||
Extras map[string]string `json:"extras" form:"extras" bson:"extras" gorm:"column:extras;serializer:json;"`
|
||||
Extras map[string]string `json:"extras" form:"extras" bson:"extras" gorm:"column:extras;type:json;serializer:json;"`
|
||||
|
||||
// 指定应用的评审方
|
||||
Audits []ApplicationReadyAudit `json:"audits" bson:"audits" gorm:"column:audits;serializer:json" description:"参与应用准备就绪的评审方"`
|
||||
Audits []ApplicationReadyAudit `json:"audits" bson:"audits" gorm:"column:audits;type:json;serializer:json" description:"参与应用准备就绪的评审方"`
|
||||
}
|
||||
|
||||
// 服务代码仓库信息
|
||||
@ -154,7 +155,7 @@ type CodeRepository struct {
|
||||
// scm设置Hook后返回的id, 用于删除应用时,取消hook使用
|
||||
HookId string `json:"hook_id" bson:"hook_id" gorm:"column:hook_id"`
|
||||
// 仓库的创建时间
|
||||
CreatedAt time.Time `json:"created_at" bson:"created_at" gorm:"column:created_at"`
|
||||
CreatedAt *time.Time `json:"created_at" bson:"created_at" gorm:"column:created_at"`
|
||||
}
|
||||
|
||||
// 镜像仓库
|
||||
@ -169,7 +170,7 @@ type ApplicationStatus struct {
|
||||
// 该应用是否已经准备就绪,多方确认的一个过程后计算出来的
|
||||
Ready *bool `json:"ready" bson:"ready" gorm:"column:ready" description:"该应用是否已经准备就绪"`
|
||||
// 就绪状态修改时间
|
||||
UpdateAt time.Time `json:"ready_update_at" bson:"ready_update_at" gorm:"column:ready_update_at" description:"就绪状态修改时间"`
|
||||
UpdateAt *time.Time `json:"ready_update_at" bson:"ready_update_at" gorm:"column:ready_update_at" description:"就绪状态修改时间"`
|
||||
}
|
||||
|
||||
// 参与应用准备就绪的评审方
|
||||
|
17
devcloud/mpaas/test/set_up.go
Normal file
17
devcloud/mpaas/test/set_up.go
Normal file
@ -0,0 +1,17 @@
|
||||
package test
|
||||
|
||||
import (
|
||||
"os"
|
||||
|
||||
"github.com/infraboard/mcube/v2/ioc"
|
||||
// 要注册哪些对象, Book, Comment
|
||||
|
||||
// 加载的业务对象
|
||||
_ "122.51.31.227/go-course/go18/devcloud/mpaas/apps"
|
||||
)
|
||||
|
||||
func DevelopmentSetUp() {
|
||||
// import 后自动执行的逻辑
|
||||
// 工具对象的初始化, 需要的是绝对路径
|
||||
ioc.DevelopmentSetupWithPath(os.Getenv("CONFIG_PATH"))
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user