mirror of
https://gitee.com/rainbond/Rainbond.git
synced 2024-11-30 02:38:17 +08:00
update get enterprise running services
This commit is contained in:
parent
9a4af3e787
commit
0ff4a17ee0
@ -59,7 +59,13 @@ func (v2 *V2) Routes() chi.Router {
|
||||
r.Post("/volume-options", controller.VolumeSetVar)
|
||||
r.Delete("/volume-options/{volume_type}", controller.DeleteVolumeType)
|
||||
r.Put("/volume-options/{volume_type}", controller.UpdateVolumeType)
|
||||
r.Post("/enterprise/running-services", controller.GetRunningServices)
|
||||
r.Mount("/enterprise/{enterprise_id}", v2.enterpriseRouter())
|
||||
return r
|
||||
}
|
||||
|
||||
func (v2 *V2) enterpriseRouter() chi.Router {
|
||||
r := chi.NewRouter()
|
||||
r.Get("/running-services", controller.GetRunningServices)
|
||||
return r
|
||||
}
|
||||
|
||||
|
@ -1,19 +1,15 @@
|
||||
package controller
|
||||
|
||||
import (
|
||||
"github.com/go-chi/chi"
|
||||
"github.com/goodrain/rainbond/api/handler"
|
||||
apimodel "github.com/goodrain/rainbond/api/model"
|
||||
httputil "github.com/goodrain/rainbond/util/http"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
//GetRunningServices list all running service ids
|
||||
func GetRunningServices(w http.ResponseWriter, r *http.Request) {
|
||||
req := apimodel.EnterpriseTenantListStruct{}
|
||||
ok := httputil.ValidatorRequestStructAndErrorResponse(r, w, &req.Body, nil)
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
runningList := handler.GetServiceManager().GetMultiTenantsRunningServices(req.Body.TenantIDs)
|
||||
enterpriseID := chi.URLParam(r, "enterprise_id")
|
||||
runningList := handler.GetServiceManager().GetEnterpriseRunningServices(enterpriseID)
|
||||
httputil.ReturnNoFomart(r, w, 200, map[string]interface{}{"service_ids": runningList})
|
||||
}
|
||||
|
@ -1661,11 +1661,20 @@ func (s *ServiceAction) GetServicesStatus(tenantID string, serviceIDs []string)
|
||||
}
|
||||
|
||||
// GetMultiTenantsRunningServices get running services
|
||||
func (s *ServiceAction) GetMultiTenantsRunningServices(tenants []string) []string {
|
||||
if len(tenants) == 0 {
|
||||
func (s *ServiceAction) GetEnterpriseRunningServices(enterpriseID string) []string {
|
||||
var tenantIDs []string
|
||||
tenants, err := db.GetManager().EnterpriseDao().GetEnterpriseTenants(enterpriseID)
|
||||
if err != nil {
|
||||
logrus.Errorf("list tenant failed: %s", err.Error())
|
||||
return []string{}
|
||||
}
|
||||
services, err := db.GetManager().TenantServiceDao().GetServicesByTenantIDs(tenants)
|
||||
for _, tenant := range tenants {
|
||||
tenantIDs = append(tenantIDs, tenant.UUID)
|
||||
}
|
||||
if len(tenantIDs) == 0 {
|
||||
return []string{}
|
||||
}
|
||||
services, err := db.GetManager().TenantServiceDao().GetServicesByTenantIDs(tenantIDs)
|
||||
if err != nil {
|
||||
logrus.Errorf("list tenants servicee failed: %s", err.Error())
|
||||
return []string{}
|
||||
|
@ -59,7 +59,7 @@ type ServiceHandler interface {
|
||||
RollBack(rs *api_model.RollbackStruct) error
|
||||
GetStatus(serviceID string) (*api_model.StatusList, error)
|
||||
GetServicesStatus(tenantID string, services []string) map[string]string
|
||||
GetMultiTenantsRunningServices(servicIDs []string) []string
|
||||
GetEnterpriseRunningServices(enterpriseID string) []string
|
||||
CreateTenant(*dbmodel.Tenants) error
|
||||
CreateTenandIDAndName(eid string) (string, string, error)
|
||||
GetPods(serviceID string) (*K8sPodInfos, error)
|
||||
|
@ -809,18 +809,6 @@ type StatusServiceListStruct struct {
|
||||
}
|
||||
}
|
||||
|
||||
//EnterpriseTenantListStruct enterprise tenants list
|
||||
type EnterpriseTenantListStruct struct {
|
||||
// in: body
|
||||
// required: true
|
||||
Body struct {
|
||||
// 需要获取状态的租户ID列表,若不指定,返回空列表
|
||||
// in: body
|
||||
// required: true
|
||||
TenantIDs []string `json:"tenant_ids" validate:"tenant_ids|required"`
|
||||
}
|
||||
}
|
||||
|
||||
//AddServiceLabelStruct AddServiceLabelStruct
|
||||
//swagger:parameters addServiceLabel updateServiceLabel
|
||||
type AddServiceLabelStruct struct {
|
||||
|
@ -41,6 +41,11 @@ type DelDao interface {
|
||||
DeleteModel(serviceID string, arg ...interface{}) error
|
||||
}
|
||||
|
||||
// EnterpriseDao enterprise dao
|
||||
type EnterpriseDao interface {
|
||||
GetEnterpriseTenants(enterpriseID string) ([]*model.Tenants, error)
|
||||
}
|
||||
|
||||
//TenantDao tenant dao
|
||||
type TenantDao interface {
|
||||
Dao
|
||||
|
1
db/db.go
1
db/db.go
@ -36,6 +36,7 @@ type Manager interface {
|
||||
VolumeTypeDao() dao.VolumeTypeDao
|
||||
LicenseDao() dao.LicenseDao
|
||||
AppDao() dao.AppDao
|
||||
EnterpriseDao() dao.EnterpriseDao
|
||||
TenantDao() dao.TenantDao
|
||||
TenantDaoTransactions(db *gorm.DB) dao.TenantDao
|
||||
TenantServiceDao() dao.TenantServiceDao
|
||||
|
@ -1,5 +1,5 @@
|
||||
// Code generated by MockGen. DO NOT EDIT.
|
||||
// Source: db/db.go
|
||||
// Source: db.go
|
||||
|
||||
// Package db is a generated GoMock package.
|
||||
package db
|
||||
@ -106,6 +106,18 @@ func (mr *MockManagerMockRecorder) AppDao() *gomock.Call {
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AppDao", reflect.TypeOf((*MockManager)(nil).AppDao))
|
||||
}
|
||||
|
||||
// EnterpriseDao mocks base method
|
||||
func (m *MockManager) EnterpriseDao() dao.EnterpriseDao {
|
||||
ret := m.ctrl.Call(m, "EnterpriseDao")
|
||||
ret0, _ := ret[0].(dao.EnterpriseDao)
|
||||
return ret0
|
||||
}
|
||||
|
||||
// EnterpriseDao indicates an expected call of EnterpriseDao
|
||||
func (mr *MockManagerMockRecorder) EnterpriseDao() *gomock.Call {
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "EnterpriseDao", reflect.TypeOf((*MockManager)(nil).EnterpriseDao))
|
||||
}
|
||||
|
||||
// TenantDao mocks base method
|
||||
func (m *MockManager) TenantDao() dao.TenantDao {
|
||||
ret := m.ctrl.Call(m, "TenantDao")
|
||||
|
22
db/mysql/dao/enterprise.go
Normal file
22
db/mysql/dao/enterprise.go
Normal file
@ -0,0 +1,22 @@
|
||||
package dao
|
||||
|
||||
import (
|
||||
"github.com/goodrain/rainbond/db/model"
|
||||
"github.com/jinzhu/gorm"
|
||||
)
|
||||
|
||||
//EnterpriseDaoImpl 租户信息管理
|
||||
type EnterpriseDaoImpl struct {
|
||||
DB *gorm.DB
|
||||
}
|
||||
|
||||
func (e *EnterpriseDaoImpl) GetEnterpriseTenants(enterpriseID string) ([]*model.Tenants, error) {
|
||||
var tenants []*model.Tenants
|
||||
if enterpriseID == "" {
|
||||
return []*model.Tenants{}, nil
|
||||
}
|
||||
if err := e.DB.Where("eid= ?", enterpriseID).Find(&tenants).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return tenants, nil
|
||||
}
|
@ -39,6 +39,13 @@ func (m *Manager) LicenseDao() dao.LicenseDao {
|
||||
}
|
||||
}
|
||||
|
||||
// EnterpriseDao enterprise dao
|
||||
func (m *Manager) EnterpriseDao() dao.EnterpriseDao {
|
||||
return &mysqldao.EnterpriseDaoImpl{
|
||||
DB: m.db,
|
||||
}
|
||||
}
|
||||
|
||||
//TenantDao 租户数据
|
||||
func (m *Manager) TenantDao() dao.TenantDao {
|
||||
return &mysqldao.TenantDaoImpl{
|
||||
|
Loading…
Reference in New Issue
Block a user