Merge pull request #841 from yangkaa/createV6

Tenant Application
This commit is contained in:
黄润豪 2020-09-21 11:48:21 +08:00 committed by GitHub
commit 084a8c050e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
25 changed files with 518 additions and 5 deletions

1
.gitignore vendored
View File

@ -54,6 +54,7 @@ test/*
test.db
*.bak
temp
vendor
.scannerwork

View File

@ -146,6 +146,15 @@ type AppInterface interface {
ImportApp(w http.ResponseWriter, r *http.Request)
}
// ApplicationInterface tenant application interface
type ApplicationInterface interface {
CreateApp(w http.ResponseWriter, r *http.Request)
UpdateApp(w http.ResponseWriter, r *http.Request)
ListApps(w http.ResponseWriter, r *http.Request)
ListServices(w http.ResponseWriter, r *http.Request)
DeleteApp(w http.ResponseWriter, r *http.Request)
}
//Gatewayer gateway api interface
type Gatewayer interface {
HTTPRule(w http.ResponseWriter, r *http.Request)

View File

@ -123,6 +123,10 @@ func (v2 *V2) tenantNameRouter() chi.Router {
r.Mount("/plugin/{plugin_id}", v2.pluginRouter())
r.Get("/event", controller.GetManager().Event)
r.Get("/chargesverify", controller.ChargesVerifyController)
//tenant app
r.Post("/apps", controller.GetManager().CreateApp)
r.Get("/apps", controller.GetManager().ListApps)
r.Mount("/apps/{app_id}", v2.applicationRouter())
//get some service pod info
r.Get("/pods", controller.Pods)
//app backup
@ -281,6 +285,18 @@ func (v2 *V2) serviceRouter() chi.Router {
return r
}
func (v2 *V2) applicationRouter() chi.Router {
r := chi.NewRouter()
// Init Application
r.Use(middleware.InitApplication)
r.Put("/", controller.GetManager().UpdateApp)
r.Delete("/", controller.GetManager().DeleteApp)
r.Get("/services", controller.GetManager().ListServices)
return r
}
func (v2 *V2) resourcesRouter() chi.Router {
r := chi.NewRouter()
r.Get("/labels", controller.GetManager().Labels)

View File

@ -48,6 +48,7 @@ type V2Manager interface {
api.Labeler
api.AppRestoreInterface
api.PodInterface
api.ApplicationInterface
}
var defaultV2Manager V2Manager

View File

@ -32,6 +32,7 @@ import (
"github.com/goodrain/rainbond/api/handler"
"github.com/goodrain/rainbond/api/middleware"
api_model "github.com/goodrain/rainbond/api/model"
"github.com/goodrain/rainbond/api/util/bcode"
"github.com/goodrain/rainbond/cmd"
"github.com/goodrain/rainbond/db"
"github.com/goodrain/rainbond/db/errors"
@ -39,11 +40,11 @@ import (
mqclient "github.com/goodrain/rainbond/mq/client"
validation "github.com/goodrain/rainbond/util/endpoint"
"github.com/goodrain/rainbond/util/fuzzy"
validator "github.com/goodrain/rainbond/util/govalidator"
httputil "github.com/goodrain/rainbond/util/http"
"github.com/goodrain/rainbond/worker/client"
"github.com/jinzhu/gorm"
"github.com/sirupsen/logrus"
validator "github.com/goodrain/rainbond/util/govalidator"
)
//V2Routes v2Routes
@ -57,6 +58,7 @@ type V2Routes struct {
LabelController
AppRestoreController
PodController
TenantAppStruct
}
//Show test
@ -648,6 +650,17 @@ func (t *TenantStruct) CreateService(w http.ResponseWriter, r *http.Request) {
return
}
// Check if the application ID exists
if ss.AppID == "" {
httputil.ReturnBcodeError(r, w, bcode.ErrCreateNeedCorrectAppID)
return
}
_, err := handler.GetTenantApplicationHandler().GetAppByID(ss.AppID)
if err != nil {
httputil.ReturnBcodeError(r, w, err)
return
}
// clean etcd data(source check)
handler.GetEtcdHandler().CleanServiceCheckData(ss.EtcdKey)
@ -705,6 +718,7 @@ func (t *TenantStruct) UpdateService(w http.ResponseWriter, r *http.Request) {
"container_memory": []string{},
"service_name": []string{},
"extend_method": []string{},
"app_id": []string{},
}
data, ok := httputil.ValidatorRequestMapAndErrorResponse(r, w, rules, nil)
if !ok {
@ -712,6 +726,23 @@ func (t *TenantStruct) UpdateService(w http.ResponseWriter, r *http.Request) {
}
serviceID := r.Context().Value(middleware.ContextKey("service_id")).(string)
data["service_id"] = serviceID
// Check if the application ID exists
var appID string
if data["app_id"] != nil {
appID = data["app_id"].(string)
}
if appID == "" {
httputil.ReturnBcodeError(r, w, bcode.ErrUpdateNeedCorrectAppID)
return
}
_, err := handler.GetTenantApplicationHandler().GetAppByID(appID)
if err != nil {
httputil.ReturnBcodeError(r, w, err)
return
}
logrus.Debugf("begin to update service")
if err := handler.GetServiceManager().ServiceUpdate(data); err != nil {
httputil.ReturnError(r, w, 500, fmt.Sprintf("update service error, %v", err))

View File

@ -0,0 +1,123 @@
package controller
import (
"net/http"
"strconv"
"github.com/go-chi/chi"
"github.com/goodrain/rainbond/api/handler"
"github.com/goodrain/rainbond/api/middleware"
"github.com/goodrain/rainbond/api/model"
dbmodel "github.com/goodrain/rainbond/db/model"
httputil "github.com/goodrain/rainbond/util/http"
)
// TenantAppStruct -
type TenantAppStruct struct{}
// CreateApp -
func (a *TenantAppStruct) CreateApp(w http.ResponseWriter, r *http.Request) {
var tenantReq model.Application
if !httputil.ValidatorRequestStructAndErrorResponse(r, w, &tenantReq, nil) {
return
}
// get current tenant
tenant := r.Context().Value(middleware.ContextKey("tenant")).(*dbmodel.Tenants)
tenantReq.TenantID = tenant.UUID
// create app
app, err := handler.GetTenantApplicationHandler().CreateApp(&tenantReq)
if err != nil {
httputil.ReturnBcodeError(r, w, err)
return
}
httputil.ReturnSuccess(r, w, app)
}
// UpdateApp -
func (a *TenantAppStruct) UpdateApp(w http.ResponseWriter, r *http.Request) {
var updateAppReq model.UpdateAppRequest
if !httputil.ValidatorRequestStructAndErrorResponse(r, w, &updateAppReq, nil) {
return
}
app := r.Context().Value(middleware.ContextKey("application")).(*dbmodel.Application)
// update app
app, err := handler.GetTenantApplicationHandler().UpdateApp(app, updateAppReq)
if err != nil {
httputil.ReturnBcodeError(r, w, err)
return
}
httputil.ReturnSuccess(r, w, app)
}
// ListApps -
func (a *TenantAppStruct) ListApps(w http.ResponseWriter, r *http.Request) {
query := r.URL.Query()
appName := query.Get("app_name")
pageQuery := query.Get("page")
pageSizeQuery := query.Get("pageSize")
page, _ := strconv.Atoi(pageQuery)
if page == 0 {
page = 1
}
pageSize, _ := strconv.Atoi(pageSizeQuery)
if pageSize == 0 {
pageSize = 10
}
// get current tenantID
tenantID := r.Context().Value(middleware.ContextKey("tenant_id")).(string)
// List apps
resp, err := handler.GetTenantApplicationHandler().ListApps(tenantID, appName, page, pageSize)
if err != nil {
httputil.ReturnBcodeError(r, w, err)
return
}
httputil.ReturnSuccess(r, w, resp)
}
// ListServices -
func (a *TenantAppStruct) ListServices(w http.ResponseWriter, r *http.Request) {
appID := chi.URLParam(r, "app_id")
query := r.URL.Query()
pageQuery := query.Get("page")
pageSizeQuery := query.Get("pageSize")
page, _ := strconv.Atoi(pageQuery)
if page == 0 {
page = 1
}
pageSize, _ := strconv.Atoi(pageSizeQuery)
if pageSize == 0 {
pageSize = 10
}
// List services
resp, err := handler.GetServiceManager().GetServicesByAppID(appID, page, pageSize)
if err != nil {
httputil.ReturnBcodeError(r, w, err)
return
}
httputil.ReturnSuccess(r, w, resp)
}
// DeleteApp -
func (a *TenantAppStruct) DeleteApp(w http.ResponseWriter, r *http.Request) {
appID := chi.URLParam(r, "app_id")
// Delete application
err := handler.GetTenantApplicationHandler().DeleteApp(appID)
if err != nil {
httputil.ReturnBcodeError(r, w, err)
return
}
httputil.ReturnSuccess(r, w, nil)
}

View File

@ -199,3 +199,10 @@ var defClusterHandler ClusterHandler
func GetClusterHandler() ClusterHandler {
return defClusterHandler
}
var defTenantApplicationHandler *TenantApplicationAction
// GetTenantApplicationHandler returns the default tenant application handler.
func GetTenantApplicationHandler() *TenantApplicationAction {
return defTenantApplicationHandler
}

View File

@ -503,6 +503,7 @@ func (s *ServiceAction) ServiceCreate(sc *api_model.ServiceStruct) error {
volumns := sc.VolumesInfo
dependVolumes := sc.DepVolumesInfo
dependIds := sc.DependIDs
ts.AppID = sc.AppID
ts.DeployVersion = ""
tx := db.GetManager().Begin()
defer func() {
@ -743,6 +744,7 @@ func (s *ServiceAction) ServiceUpdate(sc map[string]interface{}) error {
if err != nil {
return err
}
ts.AppID = sc["app_id"].(string)
version, err := db.GetManager().VersionInfoDao().GetVersionByDeployVersion(ts.DeployVersion, ts.ServiceID)
if sc["container_memory"] != nil {
ts.ContainerMemory = sc["container_memory"].(int)
@ -835,6 +837,36 @@ func (s *ServiceAction) GetService(tenantID string) ([]*dbmodel.TenantServices,
return services, nil
}
//GetServicesByAppID get service(s) by appID
func (s *ServiceAction) GetServicesByAppID(appID string, page, pageSize int) (*api_model.ListServiceResponse, error) {
var resp api_model.ListServiceResponse
services, total, err := db.GetManager().TenantServiceDao().GetServicesInfoByAppID(appID, page, pageSize)
if err != nil {
logrus.Errorf("get service by application id error, %v, %v", services, err)
return nil, err
}
var serviceIDs []string
for _, s := range services {
serviceIDs = append(serviceIDs, s.ServiceID)
}
status := s.statusCli.GetStatuss(strings.Join(serviceIDs, ","))
for _, s := range services {
if status, ok := status[s.ServiceID]; ok {
s.CurStatus = status
}
}
if services != nil {
resp.Services = services
} else {
resp.Services = make([]*dbmodel.TenantServices, 0)
}
resp.Page = page
resp.Total = total
resp.PageSize = pageSize
return &resp, nil
}
//GetPagedTenantRes get pagedTenantServiceRes(s)
func (s *ServiceAction) GetPagedTenantRes(offset, len int) ([]*api_model.TenantResource, int, error) {
allstatus := s.statusCli.GetAllStatus()

View File

@ -41,6 +41,7 @@ type ServiceHandler interface {
ServiceUpdate(sc map[string]interface{}) error
LanguageSet(langS *api_model.LanguageSet) error
GetService(tenantID string) ([]*dbmodel.TenantServices, error)
GetServicesByAppID(appID string, page, pageSize int) (*api_model.ListServiceResponse, error)
GetPagedTenantRes(offset, len int) ([]*api_model.TenantResource, int, error)
GetTenantRes(uuid string) (*api_model.TenantResource, error)
CodeCheck(c *api_model.CheckCodeStruct) error

View File

@ -0,0 +1,90 @@
package handler
import (
"github.com/goodrain/rainbond/api/model"
"github.com/goodrain/rainbond/api/util/bcode"
"github.com/goodrain/rainbond/db"
dbmodel "github.com/goodrain/rainbond/db/model"
"github.com/goodrain/rainbond/util"
)
// TenantApplicationAction -
type TenantApplicationAction struct{}
// TenantApplicationHandler defines handler methods to TenantApplication.
type TenantApplicationHandler interface {
CreateApp(req *model.Application) (*model.Application, error)
UpdateApp(srcApp *dbmodel.Application, req model.UpdateAppRequest) (*dbmodel.Application, error)
ListApps(tenantID, appName string, page, pageSize int) (*model.ListAppResponse, error)
GetAppByID(appID string) (*dbmodel.Application, error)
DeleteApp(appID string) error
}
// NewTenantApplicationHandler creates a new Tenant Application Handler.
func NewTenantApplicationHandler() TenantApplicationHandler {
return &TenantApplicationAction{}
}
// CreateApp -
func (a *TenantApplicationAction) CreateApp(req *model.Application) (*model.Application, error) {
appReq := &dbmodel.Application{
AppName: req.AppName,
AppID: util.NewUUID(),
TenantID: req.TenantID,
}
req.AppID = appReq.AppID
if err := db.GetManager().TenantApplicationDao().AddModel(appReq); err != nil {
return nil, err
}
return req, nil
}
// UpdateApp -
func (a *TenantApplicationAction) UpdateApp(srcApp *dbmodel.Application, req model.UpdateAppRequest) (*dbmodel.Application, error) {
srcApp.AppName = req.AppName
if err := db.GetManager().TenantApplicationDao().UpdateModel(srcApp); err != nil {
return nil, err
}
return srcApp, nil
}
// ListApps -
func (a *TenantApplicationAction) ListApps(tenantID, appName string, page, pageSize int) (*model.ListAppResponse, error) {
var resp model.ListAppResponse
apps, total, err := db.GetManager().TenantApplicationDao().ListApps(tenantID, appName, page, pageSize)
if err != nil {
return nil, err
}
if apps != nil {
resp.Apps = apps
} else {
resp.Apps = make([]*dbmodel.Application, 0)
}
resp.Page = page
resp.Total = total
resp.PageSize = pageSize
return &resp, nil
}
// GetAppByID -
func (a *TenantApplicationAction) GetAppByID(appID string) (*dbmodel.Application, error) {
app, err := db.GetManager().TenantApplicationDao().GetAppByID(appID)
if err != nil {
return nil, err
}
return app, nil
}
// DeleteApp -
func (a *TenantApplicationAction) DeleteApp(appID string) error {
// Get the number of services under the application
total, err := db.GetManager().TenantServiceDao().CountServiceByAppID(appID)
if err != nil {
return err
}
if total != 0 {
return bcode.ErrDeleteDueToBindService
}
return db.GetManager().TenantApplicationDao().DeleteApp(appID)
}

View File

@ -22,7 +22,7 @@ func CheckTenantResource(tenant *dbmodel.Tenants, needMemory int) error {
}
clusterInfo, err := GetTenantManager().GetAllocatableResources()
if err != nil {
logrus.Errorf("get cluster resources failure for check tenant resource.", err.Error())
logrus.Errorf("get cluster resources failure for check tenant resource : %v.", err.Error())
}
if clusterInfo != nil {
clusterAvailMemory := clusterInfo.AllMemory - clusterInfo.RequestMemory

View File

@ -71,7 +71,6 @@ func InitTenant(next http.Handler) http.Handler {
ctx := context.WithValue(r.Context(), ContextKey("tenant_name"), tenantName)
ctx = context.WithValue(ctx, ContextKey("tenant_id"), tenant.UUID)
ctx = context.WithValue(ctx, ContextKey("tenant"), tenant)
next.ServeHTTP(w, r.WithContext(ctx))
}
return http.HandlerFunc(fn)
@ -105,6 +104,23 @@ func InitService(next http.Handler) http.Handler {
return http.HandlerFunc(fn)
}
// InitApplication -
func InitApplication(next http.Handler) http.Handler {
fn := func(w http.ResponseWriter, r *http.Request) {
appID := chi.URLParam(r, "app_id")
tenantApp, err := handler.GetTenantApplicationHandler().GetAppByID(appID)
if err != nil {
httputil.ReturnBcodeError(r, w, err)
return
}
ctx := context.WithValue(r.Context(), ContextKey("app_id"), tenantApp.AppID)
ctx = context.WithValue(ctx, ContextKey("application"), tenantApp)
next.ServeHTTP(w, r.WithContext(ctx))
}
return http.HandlerFunc(fn)
}
//InitPlugin 实现plugin init中间件
func InitPlugin(next http.Handler) http.Handler {
fn := func(w http.ResponseWriter, r *http.Request) {

View File

@ -342,6 +342,7 @@ type ServiceStruct struct {
EnvsInfo []dbmodel.TenantServiceEnvVar `json:"envs_info" validate:"envs_info"`
PortsInfo []dbmodel.TenantServicesPort `json:"ports_info" validate:"ports_info"`
Endpoints *Endpoints `json:"endpoints" validate:"endpoints"`
AppID string `json:"app_id" validate:"required"`
}
// Endpoints holds third-party service endpoints or configuraion to get endpoints.
@ -1624,3 +1625,31 @@ func NewAppStatusFromImport(app *ImportAppStruct) *dbmodel.AppStatus {
Status: "importing",
}
}
// Application -
type Application struct {
AppName string `json:"app_name" validate:"required"`
AppID string `json:"app_id"`
TenantID string `json:"tenant_id"`
}
// ListAppResponse -
type ListAppResponse struct {
Page int `json:"page"`
PageSize int `json:"pageSize"`
Total int64 `json:"total"`
Apps []*dbmodel.Application `json:"apps"`
}
// ListServiceResponse -
type ListServiceResponse struct {
Page int `json:"page"`
PageSize int `json:"pageSize"`
Total int64 `json:"total"`
Services []*dbmodel.TenantServices `json:"services"`
}
// UpdateAppRequest -
type UpdateAppRequest struct {
AppName string `json:"app_name" validate:"required"`
}

View File

@ -0,0 +1,15 @@
package bcode
// tenant application 11000~11099
var (
//ErrApplicationNotFound -
ErrApplicationNotFound = newByMessage(404, 11001, "application not found")
//ErrApplicationExist -
ErrApplicationExist = newByMessage(400, 11002, "application already exist")
//ErrCreateNeedCorrectAppID
ErrCreateNeedCorrectAppID = newByMessage(404, 11003, "create service need correct application ID")
//ErrUpdateNeedCorrectAppID
ErrUpdateNeedCorrectAppID = newByMessage(404, 11004, "update service need correct application ID")
//ErrDeleteDueToBindService
ErrDeleteDueToBindService = newByMessage(400, 11005, "the application cannot be deleted because there are bound services")
)

View File

@ -67,6 +67,14 @@ type AppDao interface {
DeleteModelByEventId(eventID string) error
}
//TenantApplicationDao tenant Application Dao
type TenantApplicationDao interface {
Dao
ListApps(tenantID, appName string, page, pageSize int) ([]*model.Application, int64, error)
GetAppByID(appID string) (*model.Application, error)
DeleteApp(appID string) error
}
// VolumeTypeDao volume type dao
type VolumeTypeDao interface {
Dao
@ -96,6 +104,8 @@ type TenantServiceDao interface {
GetServicesByTenantID(tenantID string) ([]*model.TenantServices, error)
GetServicesByTenantIDs(tenantIDs []string) ([]*model.TenantServices, error)
GetServicesAllInfoByTenantID(tenantID string) ([]*model.TenantServices, error)
GetServicesInfoByAppID(appID string, page, pageSize int) ([]*model.TenantServices, int64, error)
CountServiceByAppID(appID string) (int64, error)
DeleteServiceByServiceID(serviceID string) error
GetServiceMemoryByTenantIDs(tenantIDs, serviceIDs []string) (map[string]map[string]interface{}, error)
GetServiceMemoryByServiceIDs(serviceIDs []string) (map[string]map[string]interface{}, error)

View File

@ -38,6 +38,7 @@ type Manager interface {
VolumeTypeDao() dao.VolumeTypeDao
LicenseDao() dao.LicenseDao
AppDao() dao.AppDao
TenantApplicationDao() dao.TenantApplicationDao
EnterpriseDao() dao.EnterpriseDao
TenantDao() dao.TenantDao
TenantDaoTransactions(db *gorm.DB) dao.TenantDao

View File

@ -36,3 +36,4 @@ type AppBackup struct {
func (t *AppBackup) TableName() string {
return "region_app_backup"
}

View File

@ -0,0 +1,14 @@
package model
// Application -
type Application struct {
Model
AppName string `gorm:"column:app_name" json:"app_name"`
AppID string `gorm:"column:app_id" json:"app_id"`
TenantID string `gorm:"column:tenant_id" json:"tenant_id"`
}
// TableName return tableName "tenant_application"
func (t *Application) TableName() string {
return "tenant_application"
}

View File

@ -188,6 +188,8 @@ type TenantServices struct {
ServiceOrigin string `gorm:"column:service_origin;default:'assistant'" json:"service_origin"`
// kind of service. option: internal, third_party
Kind string `gorm:"column:kind;default:'internal'" json:"kind"`
// service bind appID
AppID string `gorm:"column:app_id" json:"app_id"`
}
//Image 镜像
@ -294,6 +296,8 @@ type TenantServicesDelete struct {
ServiceOrigin string `gorm:"column:service_origin;default:'assistant'" json:"service_origin"`
// kind of service. option: internal, third_party
Kind string `gorm:"column:kind;default:'internal'" json:"kind"`
// service bind appID
AppID string `gorm:"column:app_id" json:"app_id"`
}
//TableName 表名

View File

@ -0,0 +1,74 @@
package dao
import (
"github.com/goodrain/rainbond/api/util/bcode"
"github.com/goodrain/rainbond/db/model"
"github.com/jinzhu/gorm"
)
// TenantApplicationDaoImpl -
type TenantApplicationDaoImpl struct {
DB *gorm.DB
}
//AddModel -
func (a *TenantApplicationDaoImpl) AddModel(mo model.Interface) error {
appReq, _ := mo.(*model.Application)
var oldApp model.Application
if err := a.DB.Where("tenant_id = ? AND app_id = ?", appReq.TenantID, appReq.AppID).Find(&oldApp).Error; err != nil {
if err == gorm.ErrRecordNotFound {
return a.DB.Create(appReq).Error
}
return err
}
return bcode.ErrApplicationExist
}
//UpdateModel -
func (a *TenantApplicationDaoImpl) UpdateModel(mo model.Interface) error {
updateReq := mo.(*model.Application)
return a.DB.Save(updateReq).Error
}
// ListApps -
func (a *TenantApplicationDaoImpl) ListApps(tenantID, appName string, page, pageSize int) ([]*model.Application, int64, error) {
var datas []*model.Application
offset := (page - 1) * pageSize
db := a.DB.Where("tenant_id=?", tenantID).Order("create_time desc")
if appName != "" {
db = db.Where("app_name like ?", "%"+appName+"%")
}
var total int64
if err := db.Model(&model.Application{}).Count(&total).Error; err != nil {
return nil, 0, err
}
if err := db.Limit(pageSize).Offset(offset).Find(&datas).Error; err != nil {
return nil, 0, err
}
return datas, total, nil
}
// GetAppByID -
func (a *TenantApplicationDaoImpl) GetAppByID(appID string) (*model.Application, error) {
var app model.Application
if err := a.DB.Where("app_id=?", appID).Find(&app).Error; err != nil {
if err == gorm.ErrRecordNotFound {
return nil, bcode.ErrApplicationNotFound
}
return nil, err
}
return &app, nil
}
// DeleteApp Delete application By appID -
func (a *TenantApplicationDaoImpl) DeleteApp(appID string) error {
var app model.Application
if err := a.DB.Where("app_id=?", appID).Find(&app).Error; err != nil {
if err == gorm.ErrRecordNotFound {
return bcode.ErrApplicationNotFound
}
return err
}
return a.DB.Delete(&app).Error
}

View File

@ -25,8 +25,8 @@ import (
"strconv"
"time"
"github.com/sirupsen/logrus"
"github.com/jinzhu/gorm"
"github.com/sirupsen/logrus"
"github.com/goodrain/rainbond/db/dao"
"github.com/goodrain/rainbond/db/errors"
@ -454,6 +454,34 @@ func (t *TenantServicesDaoImpl) GetServicesAllInfoByTenantID(tenantID string) ([
return services, nil
}
// GetServicesInfoByAppID Get Services Info By ApplicationID
func (t *TenantServicesDaoImpl) GetServicesInfoByAppID(appID string, page, pageSize int) ([]*model.TenantServices, int64, error) {
var (
total int64
services []*model.TenantServices
)
offset := (page - 1) * pageSize
db := t.DB.Where("app_id=?", appID).Order("create_time desc")
if err := db.Model(&model.TenantServices{}).Count(&total).Error; err != nil {
return nil, 0, err
}
if err := db.Limit(pageSize).Offset(offset).Find(&services).Error; err != nil {
return nil, 0, err
}
return services, total, nil
}
// CountServiceByAppID get Service number by AppID
func (t *TenantServicesDaoImpl) CountServiceByAppID(appID string) (int64, error) {
var total int64
if err := t.DB.Model(&model.TenantServices{}).Where("app_id=?", appID).Count(&total).Error; err != nil {
return 0, err
}
return total, nil
}
//SetTenantServiceStatus SetTenantServiceStatus
func (t *TenantServicesDaoImpl) SetTenantServiceStatus(serviceID, status string) error {
var service model.TenantServices

View File

@ -417,6 +417,13 @@ func (m *Manager) AppDao() dao.AppDao {
}
}
// TenantApplicationDao -
func (m *Manager) TenantApplicationDao() dao.TenantApplicationDao {
return &mysqldao.TenantApplicationDaoImpl{
DB: m.db,
}
}
//AppBackupDao group app backup info
func (m *Manager) AppBackupDao() dao.AppBackupDao {
return &mysqldao.AppBackupDaoImpl{

View File

@ -125,6 +125,7 @@ func (m *Manager) RegisterTableModel() {
m.models = append(m.models, &model.AppStatus{})
m.models = append(m.models, &model.AppBackup{})
m.models = append(m.models, &model.ServiceSourceConfig{})
m.models = append(m.models, &model.Application{})
// gateway
m.models = append(m.models, &model.Certificate{})
m.models = append(m.models, &model.RuleExtension{})

1
go.mod
View File

@ -40,6 +40,7 @@ require (
github.com/golang/mock v1.4.3
github.com/golang/protobuf v1.4.2
github.com/goodrain/rainbond-operator v1.0.0
github.com/google/uuid v1.1.1
github.com/gorilla/mux v1.7.4 // indirect
github.com/gorilla/websocket v1.4.2
github.com/gosuri/uitable v0.0.4

View File

@ -9,6 +9,7 @@ if [ "$BUILD_IMAGE_BASE_NAME" ];
then
IMAGE_BASE_NAME=${BUILD_IMAGE_BASE_NAME}
fi
CACHE=${CACHE:true}
GO_VERSION=1.13
if [ -z "$GOOS" ];then
@ -67,7 +68,7 @@ build::binary() {
build::image() {
local OUTPATH="./_output/binary/$GOOS/${BASE_NAME}-$1"
local build_image_dir="./_output/image/$1/"
if [ -z "${CACHE}" ] || [ ! -f "${OUTPATH}" ];then
if [ !${CACHE} ] || [ ! -f "${OUTPATH}" ];then
build::binary "$1"
fi
sudo mkdir -p "${build_image_dir}"