mirror of
https://gitee.com/rainbond/Rainbond.git
synced 2024-11-29 18:27:58 +08:00
update tenant_service struct, add service_type
This commit is contained in:
parent
6e65282ab9
commit
4393dddc63
@ -660,6 +660,7 @@ func (t *TenantStruct) CreateService(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
tenantID := r.Context().Value(middleware.ContextKey("tenant_id")).(string)
|
||||
ss.TenantID = tenantID
|
||||
ss.ServiceType = ss.ExtendMethod
|
||||
if err := handler.GetServiceManager().ServiceCreate(&ss); err != nil {
|
||||
if strings.Contains(err.Error(), "is exist in tenant") {
|
||||
httputil.ReturnError(r, w, 400, fmt.Sprintf("create service error, %v", err))
|
||||
@ -692,7 +693,7 @@ func (t *TenantStruct) UpdateService(w http.ResponseWriter, r *http.Request) {
|
||||
// schema:
|
||||
// "$ref": "#/responses/commandResponse"
|
||||
// description: 统一返回格式
|
||||
|
||||
// TODO fanyangyang 支持组件类型的修改
|
||||
logrus.Debugf("trans update service service")
|
||||
//目前提供三个元素的修改
|
||||
rules := validator.MapData{
|
||||
|
@ -230,11 +230,11 @@ func (h *BackupHandle) snapshot(ids []string, sourceDir string) error {
|
||||
ServiceID: id,
|
||||
}
|
||||
status := h.statusCli.GetStatus(id)
|
||||
serviceType, err := db.GetManager().TenantServiceLabelDao().GetTenantServiceTypeLabel(id)
|
||||
serviceInfo, err := db.GetManager().TenantServiceDao().GetServiceTypeById(id)
|
||||
if err != nil {
|
||||
return fmt.Errorf("Get service deploy type error,%s", err.Error())
|
||||
}
|
||||
if status != v1.CLOSED && serviceType != nil && serviceType.LabelValue == core_util.StatefulServiceType {
|
||||
if status != v1.CLOSED && serviceInfo != nil && serviceInfo.IsState() { // TODO fanyangyang根据组件类型确定是否支持
|
||||
return fmt.Errorf("Statefulset app must be closed before backup,%s", err.Error())
|
||||
}
|
||||
data.ServiceStatus = status
|
||||
|
@ -37,7 +37,6 @@ import (
|
||||
"github.com/goodrain/rainbond/cmd/api/option"
|
||||
"github.com/goodrain/rainbond/db"
|
||||
dberrors "github.com/goodrain/rainbond/db/errors"
|
||||
core_model "github.com/goodrain/rainbond/db/model"
|
||||
dbmodel "github.com/goodrain/rainbond/db/model"
|
||||
"github.com/goodrain/rainbond/event"
|
||||
eventutil "github.com/goodrain/rainbond/eventlog/util"
|
||||
@ -249,17 +248,12 @@ func (s *ServiceAction) AddLabel(l *api_model.LabelsStruct, serviceID string) er
|
||||
tx.Rollback()
|
||||
}
|
||||
}()
|
||||
//V5.2: do not support service type label
|
||||
for _, label := range l.Labels {
|
||||
var labelModel dbmodel.TenantServiceLable
|
||||
switch label.LabelKey {
|
||||
case core_model.LabelKeyServiceType:
|
||||
labelModel.ServiceID = serviceID
|
||||
labelModel.LabelKey = core_model.LabelKeyServiceType
|
||||
labelModel.LabelValue = chekeServiceLabel(label.LabelValue)
|
||||
default:
|
||||
labelModel.ServiceID = serviceID
|
||||
labelModel.LabelKey = label.LabelKey
|
||||
labelModel.LabelValue = label.LabelValue
|
||||
labelModel := dbmodel.TenantServiceLable{
|
||||
ServiceID: serviceID,
|
||||
LabelKey: label.LabelKey,
|
||||
LabelValue: label.LabelValue,
|
||||
}
|
||||
if err := db.GetManager().TenantServiceLabelDaoTransactions(tx).AddModel(&labelModel); err != nil {
|
||||
tx.Rollback()
|
||||
@ -291,17 +285,12 @@ func (s *ServiceAction) UpdateLabel(l *api_model.LabelsStruct, serviceID string)
|
||||
tx.Rollback()
|
||||
return err
|
||||
}
|
||||
// V5.2 do not support service type label
|
||||
// add new labels
|
||||
var labelModel dbmodel.TenantServiceLable
|
||||
switch label.LabelKey {
|
||||
case core_model.LabelKeyServiceType:
|
||||
labelModel.ServiceID = serviceID
|
||||
labelModel.LabelKey = core_model.LabelKeyServiceType
|
||||
labelModel.LabelValue = chekeServiceLabel(label.LabelValue)
|
||||
default:
|
||||
labelModel.ServiceID = serviceID
|
||||
labelModel.LabelKey = label.LabelKey
|
||||
labelModel.LabelValue = label.LabelValue
|
||||
labelModel := dbmodel.TenantServiceLable{
|
||||
ServiceID: serviceID,
|
||||
LabelKey: label.LabelKey,
|
||||
LabelValue: label.LabelValue,
|
||||
}
|
||||
if err := db.GetManager().TenantServiceLabelDaoTransactions(tx).AddModel(&labelModel); err != nil {
|
||||
logrus.Errorf("error adding new labels: %v", err)
|
||||
@ -342,24 +331,6 @@ func (s *ServiceAction) DeleteLabel(l *api_model.LabelsStruct, serviceID string)
|
||||
return nil
|
||||
}
|
||||
|
||||
//UpdateServiceLabel UpdateLabel
|
||||
func (s *ServiceAction) UpdateServiceLabel(serviceID, value string) error {
|
||||
sls, err := db.GetManager().TenantServiceLabelDao().GetTenantServiceLabel(serviceID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if len(sls) > 0 {
|
||||
for _, sl := range sls {
|
||||
sl.ServiceID = serviceID
|
||||
sl.LabelKey = core_model.LabelKeyServiceType
|
||||
value = chekeServiceLabel(value)
|
||||
sl.LabelValue = value
|
||||
return db.GetManager().TenantServiceLabelDao().UpdateModel(sl)
|
||||
}
|
||||
}
|
||||
return fmt.Errorf("Get tenant service label error")
|
||||
}
|
||||
|
||||
//StartStopService start service
|
||||
func (s *ServiceAction) StartStopService(sss *api_model.StartStopStruct) error {
|
||||
services, err := db.GetManager().TenantServiceDao().GetServiceByID(sss.ServiceID)
|
||||
@ -635,16 +606,6 @@ func (s *ServiceAction) ServiceCreate(sc *api_model.ServiceStruct) error {
|
||||
}
|
||||
}
|
||||
}
|
||||
//set app label
|
||||
if err := db.GetManager().TenantServiceLabelDaoTransactions(tx).AddModel(&dbmodel.TenantServiceLable{
|
||||
ServiceID: ts.ServiceID,
|
||||
LabelKey: core_model.LabelKeyServiceType,
|
||||
LabelValue: sc.ServiceLabel,
|
||||
}); err != nil {
|
||||
logrus.Errorf("add label %v error, %v", ts.ServiceID, err)
|
||||
tx.Rollback()
|
||||
return err
|
||||
}
|
||||
// sc.Endpoints can't be nil
|
||||
// sc.Endpoints.Discovery or sc.Endpoints.Static can't be nil
|
||||
if sc.Kind == dbmodel.ServiceKindThirdParty.String() { // TODO: validate request data
|
||||
@ -1343,11 +1304,11 @@ func (s *ServiceAction) VolumnVar(tsv *dbmodel.TenantServiceVolume, tenantID, fi
|
||||
tsv.HostPath = fmt.Sprintf("%s/tenant/%s/service/%s%s", sharePath, tenantID, tsv.ServiceID, tsv.VolumePath)
|
||||
//本地文件存储
|
||||
case dbmodel.LocalVolumeType.String():
|
||||
serviceType, err := db.GetManager().TenantServiceLabelDao().GetTenantServiceTypeLabel(tsv.ServiceID)
|
||||
serviceInfo, err := db.GetManager().TenantServiceDao().GetServiceTypeById(tsv.ServiceID)
|
||||
if err != nil {
|
||||
return util.CreateAPIHandleErrorFromDBError("service type", err)
|
||||
}
|
||||
if serviceType == nil || serviceType.LabelValue != core_util.StatefulServiceType {
|
||||
if serviceInfo == nil || serviceInfo.IsState() { // TODO fanyangyang 根据组件类型确定是否支持
|
||||
return util.CreateAPIHandleError(400, fmt.Errorf("应用类型不为有状态应用.不支持本地存储"))
|
||||
}
|
||||
tsv.HostPath = fmt.Sprintf("%s/tenant/%s/service/%s%s", localPath, tenantID, tsv.ServiceID, tsv.VolumePath)
|
||||
@ -2173,13 +2134,3 @@ func CheckMapKey(rebody map[string]interface{}, key string, defaultValue interfa
|
||||
rebody[key] = defaultValue
|
||||
return rebody
|
||||
}
|
||||
|
||||
func chekeServiceLabel(v string) string {
|
||||
if strings.Contains(v, "有状态") {
|
||||
return core_util.StatefulServiceType
|
||||
}
|
||||
if strings.Contains(v, "无状态") {
|
||||
return core_util.StatelessServiceType
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
@ -33,7 +33,6 @@ type ServiceHandler interface {
|
||||
AddLabel(l *api_model.LabelsStruct, serviceID string) error
|
||||
DeleteLabel(l *api_model.LabelsStruct, serviceID string) error
|
||||
UpdateLabel(l *api_model.LabelsStruct, serviceID string) error
|
||||
UpdateServiceLabel(serviceID, value string) error
|
||||
StartStopService(s *api_model.StartStopStruct) error
|
||||
ServiceVertical(v *model.VerticalScalingTaskBody) error
|
||||
ServiceHorizontal(h *model.HorizontalScalingTaskBody) error
|
||||
|
@ -258,6 +258,10 @@ type ServiceStruct struct {
|
||||
// in: body
|
||||
// required: true
|
||||
ServiceAlias string `json:"service_alias" validate:"service_alias"`
|
||||
// 组件类型
|
||||
// in: body
|
||||
// required: true
|
||||
ServiceType string `json:"service_type" validate:"service_type"`
|
||||
// 服务描述
|
||||
// in: body
|
||||
// required: false
|
||||
@ -286,7 +290,7 @@ type ServiceStruct struct {
|
||||
// in: body
|
||||
// required: false
|
||||
ContainerEnv string `json:"container_env" validate:"container_env"`
|
||||
// 扩容方式;0:无状态;1:有状态;2:分区
|
||||
// 扩容方式;0:无状态;1:有状态;2:分区(v5.2用于接收组件的类型)
|
||||
// in: body
|
||||
// required: false
|
||||
ExtendMethod string `json:"extend_method" validate:"extend_method"`
|
||||
@ -323,7 +327,7 @@ type ServiceStruct struct {
|
||||
// required: false
|
||||
ServiceOrigin string `json:"service_origin" validate:"service_origin"`
|
||||
Kind string `json:"kind" validate:"kind|in:internal,third_party"`
|
||||
|
||||
// V5.2 弃用
|
||||
ServiceLabel string `json:"service_label" validate:"service_label|in:StatelessServiceType,StatefulServiceType"`
|
||||
NodeLabel string `json:"node_label" validate:"node_label"`
|
||||
Operator string `json:"operator" validate:"operator"`
|
||||
|
@ -426,13 +426,3 @@ func GetVolumeDir() (string, string) {
|
||||
}
|
||||
return localPath, sharePath
|
||||
}
|
||||
|
||||
//GetServiceType get service deploy type
|
||||
func GetServiceType(labels []*dbmodel.TenantServiceLable) string {
|
||||
for _, l := range labels {
|
||||
if l.LabelKey == dbmodel.LabelKeyServiceType {
|
||||
return l.LabelValue
|
||||
}
|
||||
}
|
||||
return util.StatelessServiceType
|
||||
}
|
||||
|
@ -213,8 +213,9 @@ func (b *BackupAPPRestore) restoreVersionAndData(backup *dbmodel.AppBackup, appS
|
||||
os.MkdirAll(volume.HostPath, 0777)
|
||||
continue
|
||||
}
|
||||
|
||||
//if app type is statefulset, change pod hostpath
|
||||
if GetServiceType(app.ServiceLabel) == util.StatefulServiceType {
|
||||
if app.Service.IsState() { // TODO fanyangyang 备份时需要备份组件的类型
|
||||
//Next two level directory
|
||||
list, err := util.GetDirList(tmpDir, 2)
|
||||
if err != nil {
|
||||
|
@ -44,17 +44,17 @@ type DockerComposeParse struct {
|
||||
|
||||
//ServiceInfoFromDC service info from dockercompose
|
||||
type ServiceInfoFromDC struct {
|
||||
ports map[int]*types.Port
|
||||
volumes map[string]*types.Volume
|
||||
envs map[string]*types.Env
|
||||
source string
|
||||
memory int
|
||||
image Image
|
||||
args []string
|
||||
depends []string
|
||||
imageAlias string
|
||||
deployType string
|
||||
name string
|
||||
ports map[int]*types.Port
|
||||
volumes map[string]*types.Volume
|
||||
envs map[string]*types.Env
|
||||
source string
|
||||
memory int
|
||||
image Image
|
||||
args []string
|
||||
depends []string
|
||||
imageAlias string
|
||||
serviceType string
|
||||
name string
|
||||
}
|
||||
|
||||
//GetPorts 获取端口列表
|
||||
@ -163,7 +163,7 @@ func (d *DockerComposeParse) Parse() ParseErrorList {
|
||||
if sc.DependsON != nil {
|
||||
service.depends = sc.DependsON
|
||||
}
|
||||
service.deployType = DetermineDeployType(service.image)
|
||||
service.serviceType = DetermineDeployType(service.image)
|
||||
d.services[kev] = &service
|
||||
}
|
||||
for serviceName, service := range d.services {
|
||||
@ -212,16 +212,16 @@ func (d *DockerComposeParse) GetServiceInfo() []ServiceInfo {
|
||||
var sis []ServiceInfo
|
||||
for _, service := range d.services {
|
||||
si := ServiceInfo{
|
||||
Ports: service.GetPorts(),
|
||||
Envs: service.GetEnvs(),
|
||||
Volumes: service.GetVolumes(),
|
||||
Image: service.image,
|
||||
Args: service.args,
|
||||
DependServices: service.depends,
|
||||
ImageAlias: service.imageAlias,
|
||||
ServiceDeployType: service.deployType,
|
||||
Name: service.name,
|
||||
Cname: service.name,
|
||||
Ports: service.GetPorts(),
|
||||
Envs: service.GetEnvs(),
|
||||
Volumes: service.GetVolumes(),
|
||||
Image: service.image,
|
||||
Args: service.args,
|
||||
DependServices: service.depends,
|
||||
ImageAlias: service.imageAlias,
|
||||
ServiceType: service.serviceType,
|
||||
Name: service.name,
|
||||
Cname: service.name,
|
||||
}
|
||||
if service.memory != 0 {
|
||||
si.Memory = service.memory
|
||||
|
@ -38,7 +38,7 @@ type DockerRunOrImageParse struct {
|
||||
volumes map[string]*types.Volume
|
||||
envs map[string]*types.Env
|
||||
source string
|
||||
deployType string
|
||||
serviceType string
|
||||
memory int
|
||||
image Image
|
||||
args []string
|
||||
@ -133,7 +133,7 @@ func (d *DockerRunOrImageParse) Parse() ParseErrorList {
|
||||
}
|
||||
}
|
||||
}
|
||||
d.deployType = DetermineDeployType(d.image)
|
||||
d.serviceType = DetermineDeployType(d.image)
|
||||
return d.errors
|
||||
}
|
||||
|
||||
@ -267,14 +267,14 @@ func (d *DockerRunOrImageParse) GetMemory() int {
|
||||
//GetServiceInfo 获取service info
|
||||
func (d *DockerRunOrImageParse) GetServiceInfo() []ServiceInfo {
|
||||
serviceInfo := ServiceInfo{
|
||||
Ports: d.GetPorts(),
|
||||
Envs: d.GetEnvs(),
|
||||
Volumes: d.GetVolumes(),
|
||||
Image: d.GetImage(),
|
||||
Args: d.GetArgs(),
|
||||
Branchs: d.GetBranchs(),
|
||||
Memory: d.memory,
|
||||
ServiceDeployType: d.deployType,
|
||||
Ports: d.GetPorts(),
|
||||
Envs: d.GetEnvs(),
|
||||
Volumes: d.GetVolumes(),
|
||||
Image: d.GetImage(),
|
||||
Args: d.GetArgs(),
|
||||
Branchs: d.GetBranchs(),
|
||||
Memory: d.memory,
|
||||
ServiceType: d.serviceType,
|
||||
}
|
||||
if serviceInfo.Memory == 0 {
|
||||
serviceInfo.Memory = 512
|
||||
|
@ -20,6 +20,7 @@ package parser
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
dbmodel "github.com/goodrain/rainbond/db/model"
|
||||
"strings"
|
||||
|
||||
"github.com/Sirupsen/logrus"
|
||||
@ -28,7 +29,6 @@ import (
|
||||
"github.com/goodrain/rainbond/builder/parser/discovery"
|
||||
"github.com/goodrain/rainbond/builder/parser/types"
|
||||
"github.com/goodrain/rainbond/builder/sources"
|
||||
"github.com/goodrain/rainbond/util"
|
||||
"k8s.io/apimachinery/pkg/api/resource"
|
||||
)
|
||||
|
||||
@ -165,18 +165,18 @@ type Lang string
|
||||
|
||||
//ServiceInfo 智能获取的应用信息
|
||||
type ServiceInfo struct {
|
||||
ID string `json:"id,omitempty"`
|
||||
Ports []types.Port `json:"ports,omitempty"`
|
||||
Envs []types.Env `json:"envs,omitempty"`
|
||||
Volumes []types.Volume `json:"volumes,omitempty"`
|
||||
Image Image `json:"image,omitempty"`
|
||||
Args []string `json:"args,omitempty"`
|
||||
DependServices []string `json:"depends,omitempty"`
|
||||
ServiceDeployType string `json:"deploy_type,omitempty"`
|
||||
Branchs []string `json:"branchs,omitempty"`
|
||||
Memory int `json:"memory,omitempty"`
|
||||
Lang code.Lang `json:"language,omitempty"`
|
||||
ImageAlias string `json:"image_alias,omitempty"`
|
||||
ID string `json:"id,omitempty"`
|
||||
Ports []types.Port `json:"ports,omitempty"`
|
||||
Envs []types.Env `json:"envs,omitempty"`
|
||||
Volumes []types.Volume `json:"volumes,omitempty"`
|
||||
Image Image `json:"image,omitempty"`
|
||||
Args []string `json:"args,omitempty"`
|
||||
DependServices []string `json:"depends,omitempty"`
|
||||
ServiceType string `json:"service_type,omitempty"`
|
||||
Branchs []string `json:"branchs,omitempty"`
|
||||
Memory int `json:"memory,omitempty"`
|
||||
Lang code.Lang `json:"language,omitempty"`
|
||||
ImageAlias string `json:"image_alias,omitempty"`
|
||||
//For third party services
|
||||
Endpoints []*discovery.Endpoint `json:"endpoints,omitempty"`
|
||||
|
||||
@ -236,10 +236,10 @@ var dbImageKey = []string{
|
||||
func DetermineDeployType(imageName Image) string {
|
||||
for _, key := range dbImageKey {
|
||||
if strings.ToLower(imageName.GetSimpleName()) == key {
|
||||
return util.StatefulServiceType
|
||||
return dbmodel.ServiceTypeStatelessSingleton.String() // TODO fanyangyang 通过镜像要挂载的存储确定更细致的组件类型
|
||||
}
|
||||
}
|
||||
return util.StatelessServiceType
|
||||
return dbmodel.ServiceTypeStatelessSingleton.String()
|
||||
}
|
||||
|
||||
//readmemory
|
||||
|
@ -477,15 +477,15 @@ func (d *SourceCodeParse) GetLang() code.Lang {
|
||||
//GetServiceInfo 获取service info
|
||||
func (d *SourceCodeParse) GetServiceInfo() []ServiceInfo {
|
||||
serviceInfo := ServiceInfo{
|
||||
Ports: d.GetPorts(),
|
||||
Envs: d.GetEnvs(),
|
||||
Volumes: d.GetVolumes(),
|
||||
Image: d.GetImage(),
|
||||
Args: d.GetArgs(),
|
||||
Branchs: d.GetBranchs(),
|
||||
Memory: d.memory,
|
||||
Lang: d.GetLang(),
|
||||
ServiceDeployType: util.StatelessServiceType,
|
||||
Ports: d.GetPorts(),
|
||||
Envs: d.GetEnvs(),
|
||||
Volumes: d.GetVolumes(),
|
||||
Image: d.GetImage(),
|
||||
Args: d.GetArgs(),
|
||||
Branchs: d.GetBranchs(),
|
||||
Memory: d.memory,
|
||||
Lang: d.GetLang(),
|
||||
ServiceType: model.ServiceTypeStatelessSingleton.String(), // TODO fanyangyang 使用存储确定组件类型
|
||||
}
|
||||
var res []ServiceInfo
|
||||
if d.isMulti && d.services != nil && len(d.services) > 0 {
|
||||
|
@ -99,6 +99,7 @@ type TenantServiceDao interface {
|
||||
UpdateDeployVersion(serviceID, deployversion string) error
|
||||
ListThirdPartyServices() ([]*model.TenantServices, error)
|
||||
ListServicesByTenantID(tenantID string) ([]*model.TenantServices, error)
|
||||
GetServiceTypeById(serviceID string) (*model.TenantServices, error)
|
||||
}
|
||||
|
||||
//TenantServiceDeleteDao TenantServiceDeleteDao
|
||||
|
@ -155,8 +155,8 @@ func TestSetServiceLabel(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
label := model.TenantServiceLable{
|
||||
LabelKey: model.LabelKeyServiceType,
|
||||
LabelValue: util.StatefulServiceType,
|
||||
LabelKey: "labelkey",
|
||||
LabelValue: "labelvalue",
|
||||
ServiceID: "889bb1f028f655bebd545f24aa184a0b",
|
||||
}
|
||||
label.CreatedAt = time.Now()
|
||||
|
@ -85,6 +85,41 @@ func (s ServiceKind) String() string {
|
||||
return string(s)
|
||||
}
|
||||
|
||||
// ServiceType type of service
|
||||
type ServiceType string
|
||||
|
||||
// String imple String
|
||||
func (s ServiceType) String() string {
|
||||
return string(s)
|
||||
}
|
||||
|
||||
// TODO fanyangyang 根据组件简单判断是否是有状态
|
||||
// IsState is state service or stateless service
|
||||
func (ts TenantServices) IsState() bool {
|
||||
if ts.ServiceType == "" {
|
||||
return false
|
||||
}
|
||||
if ts.ServiceType == ServiceTypeStatelessSingleton.String() || ts.ServiceType == ServiceTypeStatelessMultiple.String() {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
// ServiceTypeUnknown unknown
|
||||
var ServiceTypeUnknown ServiceType = "unknown"
|
||||
|
||||
//ServiceTypeStatelessSingleton stateless_singleton
|
||||
var ServiceTypeStatelessSingleton ServiceType = "stateless_singleton"
|
||||
|
||||
// ServiceTypeStatelessMultiple stateless_multiple
|
||||
var ServiceTypeStatelessMultiple ServiceType = "stateless_multiple"
|
||||
|
||||
// ServiceTypeStateSingleton state_singleton
|
||||
var ServiceTypeStateSingleton ServiceType = "state_singleton"
|
||||
|
||||
// ServiceTypeStateMultiple state_multiple
|
||||
var ServiceTypeStateMultiple ServiceType = "state_multiple"
|
||||
|
||||
//TenantServices app service base info
|
||||
type TenantServices struct {
|
||||
Model
|
||||
@ -96,6 +131,8 @@ type TenantServices struct {
|
||||
ServiceAlias string `gorm:"column:service_alias;size:30" json:"service_alias"`
|
||||
// service regist endpoint name(host name), used of statefulset
|
||||
ServiceName string `gorm:"column:service_name;size:100" json:"service_name"`
|
||||
// Service type now service support stateless_singleton/stateless_multiple/state_singleton/state_multiple
|
||||
ServiceType string `gorm:"column:service_type;size:32" json:"service_type"`
|
||||
// 服务描述
|
||||
Comment string `gorm:"column:comment" json:"comment"`
|
||||
// 容器CPU权重
|
||||
@ -105,7 +142,7 @@ type TenantServices struct {
|
||||
//UpgradeMethod service upgrade controller type
|
||||
//such as : `Rolling` `OnDelete`
|
||||
UpgradeMethod string `gorm:"column:upgrade_method;default:'Rolling'" json:"upgrade_method"`
|
||||
// 扩容方式;0:无状态;1:有状态;2:分区
|
||||
// 扩容方式;0:无状态;1:有状态;2:分区(V5.2已弃用)
|
||||
ExtendMethod string `gorm:"column:extend_method;default:'stateless';" json:"extend_method"`
|
||||
// 节点数
|
||||
Replicas int `gorm:"column:replicas;default:1" json:"replicas"`
|
||||
@ -197,6 +234,8 @@ type TenantServicesDelete struct {
|
||||
ServiceAlias string `gorm:"column:service_alias;size:30" json:"service_alias"`
|
||||
// service regist endpoint name(host name), used of statefulset
|
||||
ServiceName string `gorm:"column:service_name;size:100" json:"service_name"`
|
||||
// Service type now service support stateless_singleton/stateless_multiple/state_singleton/state_multiple
|
||||
ServiceType string `gorm:"column:service_type;size:20" json:"service_type"`
|
||||
// 服务描述
|
||||
Comment string `gorm:"column:comment" json:"comment"`
|
||||
// 容器CPU权重
|
||||
@ -423,6 +462,7 @@ var LabelKeyNodeSelector = "node-selector"
|
||||
//LabelKeyNodeAffinity 节点亲和标签
|
||||
var LabelKeyNodeAffinity = "node-affinity"
|
||||
|
||||
// TODO fanyangyang 待删除,组件类型记录在tenant_service表中
|
||||
//LabelKeyServiceType 应用部署类型标签
|
||||
var LabelKeyServiceType = "service-type"
|
||||
|
||||
|
@ -172,6 +172,27 @@ type TenantServicesDaoImpl struct {
|
||||
DB *gorm.DB
|
||||
}
|
||||
|
||||
// GetServiceTypeById get service type by service id
|
||||
func (t *TenantServicesDaoImpl) GetServiceTypeById(serviceID string) (*model.TenantServices, error) {
|
||||
var service model.TenantServices
|
||||
if err := t.DB.Select("tenant_id, service_id, service_alias, service_type").Where("service_id=?", serviceID).Find(&service).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if service.ServiceType == "" {
|
||||
// for before V5.2 version
|
||||
logrus.Infof("get low version service[%s] type", serviceID)
|
||||
rows, err := t.DB.Raw("select label_value from tenant_services_label where service_id=? and label_key=?", serviceID, "service-type").Rows()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
for rows.Next() {
|
||||
rows.Scan(&service.ServiceType)
|
||||
}
|
||||
}
|
||||
return &service, nil
|
||||
}
|
||||
|
||||
//GetAllServicesID get all service sample info
|
||||
func (t *TenantServicesDaoImpl) GetAllServicesID() ([]*model.TenantServices, error) {
|
||||
var services []*model.TenantServices
|
||||
@ -1322,22 +1343,12 @@ type ServiceLabelDaoImpl struct {
|
||||
func (t *ServiceLabelDaoImpl) AddModel(mo model.Interface) error {
|
||||
label := mo.(*model.TenantServiceLable)
|
||||
var oldLabel model.TenantServiceLable
|
||||
if label.LabelKey == model.LabelKeyServiceType { //LabelKeyServiceType 只能有一条
|
||||
if ok := t.DB.Where("service_id = ? and label_key=?", label.ServiceID, label.LabelKey).Find(&oldLabel).RecordNotFound(); ok {
|
||||
if err := t.DB.Create(label).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
return fmt.Errorf("label key %s of service %s is exist", label.LabelKey, label.ServiceID)
|
||||
if ok := t.DB.Where("service_id = ? and label_key=? and label_value=?", label.ServiceID, label.LabelKey, label.LabelValue).Find(&oldLabel).RecordNotFound(); ok {
|
||||
if err := t.DB.Create(label).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
if ok := t.DB.Where("service_id = ? and label_key=? and label_value=?", label.ServiceID, label.LabelKey, label.LabelValue).Find(&oldLabel).RecordNotFound(); ok {
|
||||
if err := t.DB.Create(label).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
return fmt.Errorf("label key %s value %s of service %s is exist", label.LabelKey, label.LabelValue, label.ServiceID)
|
||||
}
|
||||
return fmt.Errorf("label key %s value %s of service %s is exist", label.LabelKey, label.LabelValue, label.ServiceID)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@ -1439,15 +1450,10 @@ func (t *ServiceLabelDaoImpl) GetTenantServiceAffinityLabel(serviceID string) ([
|
||||
return labels, nil
|
||||
}
|
||||
|
||||
// no usages func. get tenant service type use TenantServiceDao.GetServiceTypeById(serviceID string)
|
||||
//GetTenantServiceTypeLabel GetTenantServiceTypeLabel
|
||||
func (t *ServiceLabelDaoImpl) GetTenantServiceTypeLabel(serviceID string) (*model.TenantServiceLable, error) {
|
||||
var label model.TenantServiceLable
|
||||
if err := t.DB.Where("service_id=? and label_key=?", serviceID, model.LabelKeyServiceType).Find(&label).Error; err != nil {
|
||||
if err == gorm.ErrRecordNotFound {
|
||||
return nil, nil
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
return &label, nil
|
||||
}
|
||||
|
||||
|
@ -163,7 +163,6 @@ func TestApplyTcpRule(t *testing.T) {
|
||||
Comment: "application info",
|
||||
ContainerCPU: 20,
|
||||
ContainerMemory: 128,
|
||||
ExtendMethod: "stateless",
|
||||
Replicas: 1,
|
||||
DeployVersion: "20181022200709",
|
||||
Category: "application",
|
||||
@ -289,7 +288,6 @@ func TestAppServiceBuild_ApplyHttpRule(t *testing.T) {
|
||||
Comment: "application info",
|
||||
ContainerCPU: 20,
|
||||
ContainerMemory: 128,
|
||||
ExtendMethod: "stateless",
|
||||
Replicas: 1,
|
||||
DeployVersion: "20181022200709",
|
||||
Category: "application",
|
||||
@ -430,7 +428,6 @@ func TestAppServiceBuild_ApplyHttpRuleWithCertificate(t *testing.T) {
|
||||
Comment: "application info",
|
||||
ContainerCPU: 20,
|
||||
ContainerMemory: 128,
|
||||
ExtendMethod: "stateless",
|
||||
Replicas: 1,
|
||||
DeployVersion: "20181022200709",
|
||||
Category: "application",
|
||||
|
@ -110,7 +110,8 @@ func TenantServiceBase(as *v1.AppService, dbmanager db.Manager) error {
|
||||
if tenantService.Kind == dbmodel.ServiceKindThirdParty.String() {
|
||||
return nil
|
||||
}
|
||||
serviceType, err := dbmanager.TenantServiceLabelDao().GetTenantServiceTypeLabel(as.ServiceID)
|
||||
//TODO fanyangyang 根据组件类型确定是否支持
|
||||
serviceInfo, err := dbmanager.TenantServiceDao().GetServiceTypeById(as.ServiceID)
|
||||
if err != nil {
|
||||
return fmt.Errorf("get service type info failure %s", err.Error())
|
||||
}
|
||||
@ -118,11 +119,11 @@ func TenantServiceBase(as *v1.AppService, dbmanager db.Manager) error {
|
||||
if label != nil {
|
||||
as.IsWindowsService = true
|
||||
}
|
||||
if serviceType == nil || serviceType.LabelValue == util.StatelessServiceType {
|
||||
if serviceInfo == nil || !serviceInfo.IsState() {
|
||||
initBaseDeployment(as, tenantService)
|
||||
return nil
|
||||
}
|
||||
if serviceType.LabelValue == util.StatefulServiceType {
|
||||
if serviceInfo.IsState() {
|
||||
initBaseStatefulSet(as, tenantService)
|
||||
return nil
|
||||
}
|
||||
|
@ -279,16 +279,11 @@ func createEnv(as *v1.AppService, dbmanager db.Manager) (*[]corev1.EnvVar, error
|
||||
as.ExtensionSet[strings.ToLower(e.AttrName[3:])] = e.AttrValue
|
||||
}
|
||||
}
|
||||
svc, err := dbmanager.TenantServiceDao().GetServiceByID(as.ServiceID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
//set default env
|
||||
envs = append(envs, corev1.EnvVar{Name: "TENANT_ID", Value: as.TenantID})
|
||||
envs = append(envs, corev1.EnvVar{Name: "SERVICE_ID", Value: as.ServiceID})
|
||||
envs = append(envs, corev1.EnvVar{Name: "MEMORY_SIZE", Value: getMemoryType(as.ContainerMemory)})
|
||||
envs = append(envs, corev1.EnvVar{Name: "SERVICE_NAME", Value: as.ServiceAlias})
|
||||
envs = append(envs, corev1.EnvVar{Name: "SERVICE_EXTEND_METHOD", Value: svc.ExtendMethod})
|
||||
envs = append(envs, corev1.EnvVar{Name: "SERVICE_POD_NUM", Value: strconv.Itoa(as.Replicas)})
|
||||
envs = append(envs, corev1.EnvVar{Name: "HOST_IP", ValueFrom: &corev1.EnvVarSource{
|
||||
FieldRef: &corev1.ObjectFieldSelector{
|
||||
|
@ -350,16 +350,11 @@ func createEnv(as *v1.AppService, dbmanager db.Manager) (*[]corev1.EnvVar, error
|
||||
as.ExtensionSet[strings.ToLower(e.AttrName[3:])] = e.AttrValue
|
||||
}
|
||||
}
|
||||
svc, err := dbmanager.TenantServiceDao().GetServiceByID(as.ServiceID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
//set default env
|
||||
envs = append(envs, corev1.EnvVar{Name: "TENANT_ID", Value: as.TenantID})
|
||||
envs = append(envs, corev1.EnvVar{Name: "SERVICE_ID", Value: as.ServiceID})
|
||||
envs = append(envs, corev1.EnvVar{Name: "MEMORY_SIZE", Value: getMemoryType(as.ContainerMemory)})
|
||||
envs = append(envs, corev1.EnvVar{Name: "SERVICE_NAME", Value: as.ServiceAlias})
|
||||
envs = append(envs, corev1.EnvVar{Name: "SERVICE_EXTEND_METHOD", Value: svc.ExtendMethod})
|
||||
envs = append(envs, corev1.EnvVar{Name: "SERVICE_POD_NUM", Value: strconv.Itoa(as.Replicas)})
|
||||
envs = append(envs, corev1.EnvVar{Name: "HOST_IP", ValueFrom: &corev1.EnvVarSource{
|
||||
FieldRef: &corev1.ObjectFieldSelector{
|
||||
|
Loading…
Reference in New Issue
Block a user