update get enterprise running services

This commit is contained in:
凡羊羊 2020-02-21 22:43:28 +08:00
parent 9a4af3e787
commit 0ff4a17ee0
10 changed files with 71 additions and 25 deletions

View File

@ -59,7 +59,13 @@ func (v2 *V2) Routes() chi.Router {
r.Post("/volume-options", controller.VolumeSetVar) r.Post("/volume-options", controller.VolumeSetVar)
r.Delete("/volume-options/{volume_type}", controller.DeleteVolumeType) r.Delete("/volume-options/{volume_type}", controller.DeleteVolumeType)
r.Put("/volume-options/{volume_type}", controller.UpdateVolumeType) 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 return r
} }

View File

@ -1,19 +1,15 @@
package controller package controller
import ( import (
"github.com/go-chi/chi"
"github.com/goodrain/rainbond/api/handler" "github.com/goodrain/rainbond/api/handler"
apimodel "github.com/goodrain/rainbond/api/model"
httputil "github.com/goodrain/rainbond/util/http" httputil "github.com/goodrain/rainbond/util/http"
"net/http" "net/http"
) )
//GetRunningServices list all running service ids //GetRunningServices list all running service ids
func GetRunningServices(w http.ResponseWriter, r *http.Request) { func GetRunningServices(w http.ResponseWriter, r *http.Request) {
req := apimodel.EnterpriseTenantListStruct{} enterpriseID := chi.URLParam(r, "enterprise_id")
ok := httputil.ValidatorRequestStructAndErrorResponse(r, w, &req.Body, nil) runningList := handler.GetServiceManager().GetEnterpriseRunningServices(enterpriseID)
if !ok {
return
}
runningList := handler.GetServiceManager().GetMultiTenantsRunningServices(req.Body.TenantIDs)
httputil.ReturnNoFomart(r, w, 200, map[string]interface{}{"service_ids": runningList}) httputil.ReturnNoFomart(r, w, 200, map[string]interface{}{"service_ids": runningList})
} }

View File

@ -1661,11 +1661,20 @@ func (s *ServiceAction) GetServicesStatus(tenantID string, serviceIDs []string)
} }
// GetMultiTenantsRunningServices get running services // GetMultiTenantsRunningServices get running services
func (s *ServiceAction) GetMultiTenantsRunningServices(tenants []string) []string { func (s *ServiceAction) GetEnterpriseRunningServices(enterpriseID string) []string {
if len(tenants) == 0 { var tenantIDs []string
tenants, err := db.GetManager().EnterpriseDao().GetEnterpriseTenants(enterpriseID)
if err != nil {
logrus.Errorf("list tenant failed: %s", err.Error())
return []string{} 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 { if err != nil {
logrus.Errorf("list tenants servicee failed: %s", err.Error()) logrus.Errorf("list tenants servicee failed: %s", err.Error())
return []string{} return []string{}

View File

@ -59,7 +59,7 @@ type ServiceHandler interface {
RollBack(rs *api_model.RollbackStruct) error RollBack(rs *api_model.RollbackStruct) error
GetStatus(serviceID string) (*api_model.StatusList, error) GetStatus(serviceID string) (*api_model.StatusList, error)
GetServicesStatus(tenantID string, services []string) map[string]string GetServicesStatus(tenantID string, services []string) map[string]string
GetMultiTenantsRunningServices(servicIDs []string) []string GetEnterpriseRunningServices(enterpriseID string) []string
CreateTenant(*dbmodel.Tenants) error CreateTenant(*dbmodel.Tenants) error
CreateTenandIDAndName(eid string) (string, string, error) CreateTenandIDAndName(eid string) (string, string, error)
GetPods(serviceID string) (*K8sPodInfos, error) GetPods(serviceID string) (*K8sPodInfos, error)

View File

@ -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 //AddServiceLabelStruct AddServiceLabelStruct
//swagger:parameters addServiceLabel updateServiceLabel //swagger:parameters addServiceLabel updateServiceLabel
type AddServiceLabelStruct struct { type AddServiceLabelStruct struct {

View File

@ -41,6 +41,11 @@ type DelDao interface {
DeleteModel(serviceID string, arg ...interface{}) error DeleteModel(serviceID string, arg ...interface{}) error
} }
// EnterpriseDao enterprise dao
type EnterpriseDao interface {
GetEnterpriseTenants(enterpriseID string) ([]*model.Tenants, error)
}
//TenantDao tenant dao //TenantDao tenant dao
type TenantDao interface { type TenantDao interface {
Dao Dao

View File

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

View File

@ -1,5 +1,5 @@
// Code generated by MockGen. DO NOT EDIT. // Code generated by MockGen. DO NOT EDIT.
// Source: db/db.go // Source: db.go
// Package db is a generated GoMock package. // Package db is a generated GoMock package.
package db 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)) 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 // TenantDao mocks base method
func (m *MockManager) TenantDao() dao.TenantDao { func (m *MockManager) TenantDao() dao.TenantDao {
ret := m.ctrl.Call(m, "TenantDao") ret := m.ctrl.Call(m, "TenantDao")

View 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
}

View File

@ -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 租户数据 //TenantDao 租户数据
func (m *Manager) TenantDao() dao.TenantDao { func (m *Manager) TenantDao() dao.TenantDao {
return &mysqldao.TenantDaoImpl{ return &mysqldao.TenantDaoImpl{