update get enterprise running service

This commit is contained in:
凡羊羊 2020-03-30 18:23:33 +08:00
parent c96ccad819
commit e5862a274b
3 changed files with 19 additions and 12 deletions

View File

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

View File

@ -1683,23 +1683,23 @@ func (s *ServiceAction) GetServicesStatus(tenantID string, serviceIDs []string)
}
// GetEnterpriseRunningServices get running services
func (s *ServiceAction) GetEnterpriseRunningServices(enterpriseID string) []string {
func (s *ServiceAction) GetEnterpriseRunningServices(enterpriseID string) ([]string, *util.APIHandleError) {
var tenantIDs []string
tenants, err := db.GetManager().EnterpriseDao().GetEnterpriseTenants(enterpriseID)
if err != nil {
logrus.Errorf("list tenant failed: %s", err.Error())
return []string{}
return nil, util.CreateAPIHandleErrorFromDBError(fmt.Sprintf("enterprise[%s] get tenant failed", enterpriseID), err)
}
if len(tenants) == 0 {
return nil, util.CreateAPIHandleErrorf(400, "enterprise[%s] has not tenants", enterpriseID)
}
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{}
return nil, util.CreateAPIHandleErrorf(400, "enterprise[%s] has not tenants", enterpriseID)
}
var serviceIDs []string
for _, svc := range services {
@ -1712,7 +1712,7 @@ func (s *ServiceAction) GetEnterpriseRunningServices(enterpriseID string) []stri
retServices = append(retServices, service)
}
}
return retServices
return retServices, nil
}
//CreateTenant create tenant

View File

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