Merge remote-tracking branch 'origin/master'

This commit is contained in:
bay1ts 2017-11-24 19:00:35 +08:00
commit b9ddecb854
10 changed files with 702 additions and 625 deletions

View File

@ -1145,6 +1145,29 @@
}
}
},
"/v2/tenants/{tenant_name}/event": {
"get": {
"description": "get events",
"produces": [
"application/json",
"application/xml"
],
"tags": [
"v2",
"get"
],
"summary": "获取指定event_ids详细信息 **完成",
"operationId": "events",
"responses": {
"default": {
"description": "统一返回格式",
"schema": {
"$ref": "#/responses/commandResponse"
}
}
}
}
},
"/v2/tenants/{tenant_name}/plugin": {
"get": {
"description": "get plugins",
@ -1463,7 +1486,6 @@
"type": "object",
"required": [
"event_id",
"kind",
"deploy_version",
"info"
],
@ -1478,45 +1500,35 @@
"type": "string",
"x-go-name": "EventID"
},
"git_url": {
"description": "git地址\nin: body",
"type": "string",
"x-go-name": "GitURL"
},
"image_url": {
"description": "镜像地址\nin: body",
"type": "string",
"x-go-name": "ImageURL"
},
"info": {
"description": "版本信息, 协助选择插件版本\nin:body",
"type": "string",
"x-go-name": "Info"
},
"kind": {
"description": "插件构建类型, image/dockerfile\nin: body",
"type": "string",
"x-go-name": "Kind"
},
"operator": {
"description": "操作人\nin: body",
"type": "string",
"x-go-name": "Operator"
},
"plugin_cmd": {
"description": "插件cmd, 默认50\nin: body",
"type": "string",
"x-go-name": "PluginCMD"
},
"plugin_cpu": {
"description": "插件CPU权重, 默认500\nin: body",
"description": "插件CPU权重, 默认125\nin: body",
"type": "integer",
"format": "int64",
"x-go-name": "PluginCPU"
},
"plugin_memory": {
"description": "插件最大内存, 默认128\nin: body",
"description": "插件最大内存, 默认50\nin: body",
"type": "integer",
"format": "int64",
"x-go-name": "PluginMemory"
},
"repo_url": {
"description": "git地址 带版本\nin: body",
"description": "git地址 分支信息\nin: body",
"type": "string",
"x-go-name": "RepoURL"
},
@ -6028,11 +6040,26 @@
"x-go-name": "Header"
},
"limit": {
"description": "限流值\nin:body",
"description": "限流值 max_connections",
"type": "integer",
"format": "int64",
"x-go-name": "Limit"
},
"max_pending_requests": {
"type": "integer",
"format": "int64",
"x-go-name": "MaxPendingRequests"
},
"max_requests": {
"type": "integer",
"format": "int64",
"x-go-name": "MaxRequests"
},
"max_retries": {
"type": "integer",
"format": "int64",
"x-go-name": "MaxRetries"
},
"prefix": {
"description": "path规则\nin: body",
"type": "string",
@ -6169,7 +6196,7 @@
"x-go-name": "EnvName"
},
"env_value": {
"type": "string",
"type": "object",
"x-go-name": "EnvVal"
}
},

View File

@ -250,7 +250,7 @@ func (p *PluginAction) BuildPluginManual(bps *api_model.BuildPluginStruct) (stri
if err != nil {
return "", util.CreateAPIHandleErrorFromDBError(fmt.Sprintf("get plugin by %v", bps.PluginID), err)
}
switch bps.Body.Kind {
switch plugin.BuildModel {
case "image":
buildVersion, err := p.ImageBuildPlugin(bps, plugin)
if err != nil {
@ -279,22 +279,31 @@ func createVersionID(s []byte) string {
//ImageBuildPlugin ImageBuildPlugin
func (p *PluginAction) ImageBuildPlugin(b *api_model.BuildPluginStruct, plugin *dbmodel.TenantPlugin) (string, error) {
if b.Body.ImageURL == "" {
if plugin.ImageURL == "" {
return "", fmt.Errorf("need image url")
}
if b.Body.Operator == "" {
b.Body.Operator = "define"
}
diffStr := fmt.Sprintf("%s%s%s%s", b.TenantName, b.Body.ImageURL, b.PluginID, time.Now().Format(time.RFC3339))
diffStr := fmt.Sprintf("%s%s%s%s", b.TenantName, plugin.ImageURL, b.PluginID, time.Now().Format(time.RFC3339))
buildVersion := createVersionID([]byte(diffStr))
pbv := &dbmodel.TenantPluginBuildVersion{
VersionID: buildVersion,
PluginID: b.PluginID,
Kind: b.Body.Kind,
BaseImage: b.Body.ImageURL,
BuildTime: time.Now().Format(time.RFC3339),
Info: b.Body.Info,
Status: "building",
VersionID: buildVersion,
PluginID: b.PluginID,
Kind: plugin.BuildModel,
BaseImage: plugin.ImageURL,
ContainerCPU: b.Body.PluginCPU,
ContainerMemory: b.Body.PluginMemory,
ContainerCMD: b.Body.PluginCMD,
BuildTime: time.Now().Format(time.RFC3339),
Info: b.Body.Info,
Status: "building",
}
if b.Body.PluginCPU == 0 {
pbv.ContainerCPU = 125
}
if b.Body.PluginMemory == 0 {
pbv.ContainerMemory = 50
}
tx := db.GetManager().Begin()
if err := db.GetManager().TenantPluginBuildVersionDaoTransactions(tx).AddModel(pbv); err != nil {
@ -302,13 +311,16 @@ func (p *PluginAction) ImageBuildPlugin(b *api_model.BuildPluginStruct, plugin *
return "", err
}
taskBody := &builder_model.BuildPluginTaskBody{
TenantID: b.Body.TenantID,
PluginID: b.PluginID,
Operator: b.Body.Operator,
ImageURL: b.Body.ImageURL,
EventID: b.Body.EventID,
Kind: b.Body.Kind,
VersionID: buildVersion,
TenantID: b.Body.TenantID,
PluginID: b.PluginID,
Operator: b.Body.Operator,
ImageURL: plugin.ImageURL,
EventID: b.Body.EventID,
Kind: plugin.BuildModel,
PluginCMD: b.Body.PluginCMD,
PluginCPU: b.Body.PluginCPU,
PluginMemory: b.Body.PluginMemory,
VersionID: buildVersion,
}
jtask, errJ := ffjson.Marshal(taskBody)
if errJ != nil {
@ -343,8 +355,11 @@ func (p *PluginAction) ImageBuildPlugin(b *api_model.BuildPluginStruct, plugin *
//DockerfileBuildPlugin DockerfileBuildPlugin
func (p *PluginAction) DockerfileBuildPlugin(b *api_model.BuildPluginStruct, plugin *dbmodel.TenantPlugin) (string, error) {
if b.Body.GitURL == "" || b.Body.RepoURL == "" {
return "", fmt.Errorf("need repo url or git url")
if plugin.GitURL == "" {
return "", fmt.Errorf("need git url")
}
if b.Body.RepoURL == "" {
plugin.Repo = "master"
}
if b.Body.Operator == "" {
b.Body.Operator = "define"
@ -352,14 +367,23 @@ func (p *PluginAction) DockerfileBuildPlugin(b *api_model.BuildPluginStruct, plu
diffStr := fmt.Sprintf("%s%s%s%s", b.TenantName, b.Body.RepoURL, b.PluginID, time.Now().Format(time.RFC3339))
buildVersion := createVersionID([]byte(diffStr))
pbv := &dbmodel.TenantPluginBuildVersion{
VersionID: buildVersion,
PluginID: b.PluginID,
Kind: b.Body.Kind,
Repo: b.Body.RepoURL,
GitURL: b.Body.GitURL,
Info: b.Body.Info,
BuildTime: time.Now().Format(time.RFC3339),
Status: "building",
VersionID: buildVersion,
PluginID: b.PluginID,
Kind: plugin.BuildModel,
Repo: b.Body.RepoURL,
GitURL: plugin.GitURL,
Info: b.Body.Info,
ContainerCPU: b.Body.PluginCPU,
ContainerMemory: b.Body.PluginMemory,
ContainerCMD: b.Body.PluginCMD,
BuildTime: time.Now().Format(time.RFC3339),
Status: "building",
}
if b.Body.PluginCPU == 0 {
pbv.ContainerCPU = 125
}
if b.Body.PluginMemory == 0 {
pbv.ContainerMemory = 50
}
tx := db.GetManager().Begin()
if err := db.GetManager().TenantPluginBuildVersionDaoTransactions(tx).AddModel(pbv); err != nil {
@ -367,14 +391,17 @@ func (p *PluginAction) DockerfileBuildPlugin(b *api_model.BuildPluginStruct, plu
return "", err
}
taskBody := &builder_model.BuildPluginTaskBody{
TenantID: b.Body.TenantID,
PluginID: b.PluginID,
Operator: b.Body.Operator,
EventID: b.Body.EventID,
Repo: b.Body.RepoURL,
GitURL: b.Body.GitURL,
Kind: b.Body.Kind,
VersionID: buildVersion,
TenantID: b.Body.TenantID,
PluginID: b.PluginID,
Operator: b.Body.Operator,
EventID: b.Body.EventID,
Repo: b.Body.RepoURL,
GitURL: plugin.GitURL,
Kind: plugin.BuildModel,
VersionID: buildVersion,
PluginCMD: b.Body.PluginCMD,
PluginCPU: b.Body.PluginCPU,
PluginMemory: b.Body.PluginMemory,
}
jtask, errJ := ffjson.Marshal(taskBody)
if errJ != nil {

View File

@ -201,34 +201,26 @@ type BuildPluginStruct struct {
// in: body
// required: true
EventID string `json:"event_id" validate:"event_id|required"`
// 插件构建类型, image/dockerfile
// in: body
// required: true
Kind string `json:"kind" validate:"kind|required"`
// 插件CPU权重, 默认500
// 插件CPU权重, 默认125
// in: body
// required: false
PluginCPU int `json:"plugin_cpu" validate:"plugin_cpu"`
// 插件最大内存, 默认128
// 插件最大内存, 默认50
// in: body
// required: false
PluginMemory int `json:"plugin_memory" validate:"plugin_memory"`
// 镜像地址
// 插件cmd, 默认50
// in: body
// required: false
ImageURL string `json:"image_url" validate:"image_url"`
PluginCMD string `json:"plugin_cmd" validate:"plugin_cmd"`
// 部署的版本号
// in: body
// required: true
DeployVersion string `json:"deploy_version" validate:"deploy_version|required"`
// git地址 带版本
// git地址 分支信息
// in: body
// required: false
RepoURL string `json:"repo_url" validate:"repo_url"`
// git地址
// in: body
// required: false
GitURL string `json:"git_url" validate:"git_url"`
// 版本信息, 协助选择插件版本
// in:body
// required: true

View File

@ -30,6 +30,9 @@ type BuildPluginTaskBody struct {
EventID string `json:"event_id"`
DeployVersion string `json:"deploy_version"`
Kind string `json:"kind"`
PluginCMD string `json:"plugin_cmd"`
PluginCPU int `json:"plugin_cpu"`
PluginMemory int `json:"plugin_memory"`
}
//BuildPluginVersion BuildPluginVersion
@ -67,7 +70,7 @@ type AppPublish struct {
AppVersion string `json:"app_version"`
Image string `json:"image,omitempty"`
Slug string `json:"slug,omitempty"`
DestYS bool `json:"dest_ys,omitempty"`
DestYB bool `json:"dest_yb,omitempty"`
DestYS bool `json:"dest_ys,omitempty"`
DestYB bool `json:"dest_yb,omitempty"`
ShareID string `json:"share_id,omitempty"`
}

163
pkg/db/model/plugin.go Normal file
View File

@ -0,0 +1,163 @@
// RAINBOND, Application Management Platform
// Copyright (C) 2014-2017 Goodrain Co., Ltd.
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version. For any non-GPL usage of Rainbond,
// one or multiple Commercial Licenses authorized by Goodrain Co., Ltd.
// must be obtained first.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
package model
//TenantPlugin 插件表
type TenantPlugin struct {
Model
//插件id
PluginID string `gorm:"column:plugin_id;size:32"`
//插件名称
PluginName string `gorm:"column:plugin_name;size:32"`
//插件用途描述
PluginInfo string `gorm:"column:plugin_info:size:100"`
//插件CPU权重
PluginCPU int `gorm:"column:plugin_cpu;default:500" json:"plugin_cpu"`
//插件最大内存
PluginMemory int `gorm:"column:plugin_memory;default:128" json:"plugin_memory"`
//插件docker地址
ImageURL string `gorm:"column:image_url"`
//插件goodrain地址
ImageLocal string `gorm:"column:image_local"`
//带分支信息的git地址
Repo string `gorm:"column:repo"`
//git地址
GitURL string `gorm:"column:git_url"`
//构建模式
BuildModel string `gorm:"column:build_model"`
//插件模式
PluginModel string `gorm:"column:plugin_model"`
//插件启动命令
PluginCMD string `gorm:"column:plugin_cmd"`
TenantID string `gorm:"column:tenant_id"`
//tenant_name 统计cpu mem使用
Domain string `gorm:"column:domain"`
//gitlab; github
CodeFrom string `gorm:"column:code_from" json:"code_from"`
}
//TableName 表名
func (t *TenantPlugin) TableName() string {
return "tenant_plugin"
}
//TenantPluginDefaultENV 插件默认环境变量
type TenantPluginDefaultENV struct {
Model
//对应插件id
PluginID string `gorm:"column:plugin_id"`
//配置项名称
ENVName string `gorm:"column:env_name"`
//配置项值
ENVValue string `gorm:"column:env_value"`
//使用人是否可改
IsChange bool `gorm:"column:is_change;default:false"`
}
//TableName 表名
func (t *TenantPluginDefaultENV) TableName() string {
return "tenant_plugin_default_env"
}
//TenantPluginDefaultConf 插件默认配置表 由console提供
type TenantPluginDefaultConf struct {
Model
//对应插件id
PluginID string `gorm:"column:plugin_id"`
//配置项名称
ConfName string `gorm:"column:conf_name"`
//配置项值
ConfValue string `gorm:"column:conf_value"`
//配置项类型由console提供
ConfType string `gorm:"column:conf_type"`
}
//TableName 表名
func (t *TenantPluginDefaultConf) TableName() string {
return "tenant_plugin_default_conf"
}
//TenantPluginBuildVersion 插件构建版本表
type TenantPluginBuildVersion struct {
Model
VersionID string `gorm:"column:version_id;size:32"`
PluginID string `gorm:"column:plugin_id;size:32"`
Kind string `gorm:"column:kind;size:24"`
BaseImage string `gorm:"column:base_image;size:100"`
BuildLocalImage string `gorm:"column:build_local_image;size:100"`
BuildTime string `gorm:"column:build_time"`
Repo string `gorm:"column:repo"`
GitURL string `gorm:"column:git_url"`
Info string `gorm:"column:info"`
Status string `gorm:"column:status;size:24"`
// 容器CPU权重
ContainerCPU int `gorm:"column:container_cpu;default:125" json:"container_cpu"`
// 容器最大内存
ContainerMemory int `gorm:"column:container_memory;default:50" json:"container_memory"`
// 容器启动命令
ContainerCMD string `gorm:"column:container_cmd;size:2048" json:"container_cmd"`
}
//TableName 表名
func (t *TenantPluginBuildVersion) TableName() string {
return "tenant_plugin_build_version"
}
//TenantPluginVersionEnv TenantPluginVersionEnv
type TenantPluginVersionEnv struct {
Model
//VersionID string `gorm:"column:version_id;size:32"`
PluginID string `gorm:"column:plugin_id;size:32"`
EnvName string `gorm:"column:env_name"`
EnvValue string `gorm:"column:env_value"`
ServiceID string `gorm:"column:service_id"`
}
//TableName 表名
func (t *TenantPluginVersionEnv) TableName() string {
return "tenant_plugin_version_env"
}
//TenantServicePluginRelation TenantServicePluginRelation
type TenantServicePluginRelation struct {
Model
VersionID string `gorm:"column:version_id;size:32"`
PluginID string `gorm:"column:plugin_id;size:32"`
ServiceID string `gorm:"column:service_id;size:32"`
Switch bool `gorm:"column:switch;default:false"`
}
//TableName 表名
func (t *TenantServicePluginRelation) TableName() string {
return "tenant_service_plugin_relation"
}
//Plugin model 插件标签
//InitPlugin 初始化插件
var InitPlugin = "init-plugin"
//UpNetPlugin 上游网络插件
var UpNetPlugin = "upnet-plugin"
//DownNetPlugin 下游网络插件
var DownNetPlugin = "downnet-plugin"
//GeneralPlugin 一般插件,默认分类,优先级最低
var GeneralPlugin = "general-plugin"

View File

@ -369,128 +369,6 @@ func (t *TenantServiceStatus) TableName() string {
return "tenant_service_status"
}
//TenantPlugin 插件表
type TenantPlugin struct {
Model
//插件id
PluginID string `gorm:"column:plugin_id;size:32"`
//插件名称
PluginName string `gorm:"column:plugin_name;size:32"`
//插件用途描述
PluginInfo string `gorm:"column:plugin_info:size:100"`
//插件CPU权重
PluginCPU int `gorm:"column:plugin_cpu;default:500" json:"plugin_cpu"`
//插件最大内存
PluginMemory int `gorm:"column:plugin_memory;default:128" json:"plugin_memory"`
//插件docker地址
ImageURL string `gorm:"column:image_url"`
//插件goodrain地址
ImageLocal string `gorm:"column:image_local"`
//带分支信息的git地址
Repo string `gorm:"column:repo"`
//git地址
GitURL string `gorm:"column:git_url"`
//构建模式
BuildModel string `gorm:"column:build_model"`
//插件模式
PluginModel string `gorm:"column:plugin_model"`
//插件启动命令
PluginCMD string `gorm:"column:plugin_cmd"`
TenantID string `gorm:"column:tenant_id"`
//tenant_name 统计cpu mem使用
Domain string `gorm:"column:domain"`
}
//TableName 表名
func (t *TenantPlugin) TableName() string {
return "tenant_plugin"
}
//TenantPluginDefaultENV 插件默认环境变量
type TenantPluginDefaultENV struct {
Model
//对应插件id
PluginID string `gorm:"column:plugin_id"`
//配置项名称
ENVName string `gorm:"column:env_name"`
//配置项值
ENVValue string `gorm:"column:env_value"`
//使用人是否可改
IsChange bool `gorm:"column:is_change;default:false"`
}
//TableName 表名
func (t *TenantPluginDefaultENV) TableName() string {
return "tenant_plugin_default_env"
}
//TenantPluginDefaultConf 插件默认配置表 由console提供
type TenantPluginDefaultConf struct {
Model
//对应插件id
PluginID string `gorm:"column:plugin_id"`
//配置项名称
ConfName string `gorm:"column:conf_name"`
//配置项值
ConfValue string `gorm:"column:conf_value"`
//配置项类型由console提供
ConfType string `gorm:"column:conf_type"`
}
//TableName 表名
func (t *TenantPluginDefaultConf) TableName() string {
return "tenant_plugin_default_conf"
}
//TenantPluginBuildVersion 插件构建版本表
type TenantPluginBuildVersion struct {
Model
VersionID string `gorm:"column:version_id;size:32"`
PluginID string `gorm:"column:plugin_id;size:32"`
Kind string `gorm:"column:kind;size:24"`
BaseImage string `gorm:"column:base_image"`
BuildLocalImage string `gorm:"column:build_local_image"`
BuildTime string `gorm:"column:build_time"`
Repo string `gorm:"column:repo"`
GitURL string `gorm:"column:git_url"`
Info string `gorm:"column:info"`
Status string `gorm:"column:status;size:24"`
}
//TableName 表名
func (t *TenantPluginBuildVersion) TableName() string {
return "tenant_plugin_build_version"
}
//TenantPluginVersionEnv TenantPluginVersionEnv
type TenantPluginVersionEnv struct {
Model
//VersionID string `gorm:"column:version_id;size:32"`
PluginID string `gorm:"column:plugin_id;size:32"`
EnvName string `gorm:"column:env_name"`
EnvValue string `gorm:"column:env_value"`
ServiceID string `gorm:"column:service_id"`
}
//TableName 表名
func (t *TenantPluginVersionEnv) TableName() string {
return "tenant_plugin_version_env"
}
//TenantServicePluginRelation TenantServicePluginRelation
type TenantServicePluginRelation struct {
Model
VersionID string `gorm:"column:version_id;size:32"`
PluginID string `gorm:"column:plugin_id;size:32"`
ServiceID string `gorm:"column:service_id;size:32"`
Switch bool `gorm:"column:switch;default:false"`
}
//TableName 表名
func (t *TenantServicePluginRelation) TableName() string {
return "tenant_service_plugin_relation"
}
//LabelKeyNodeSelector 节点选择标签
var LabelKeyNodeSelector = "node-selector"
@ -508,17 +386,3 @@ var LabelKeyServiceAffinity = "service-affinity"
//LabelKeyServiceAntyAffinity 应用反亲和标签
var LabelKeyServiceAntyAffinity = "service-anti-affinity"
//Plugin model 插件标签
//InitPlugin 初始化插件
var InitPlugin = "init-plugin"
//UpNetPlugin 上游网络插件
var UpNetPlugin = "upnet-plugin"
//DownNetPlugin 下游网络插件
var DownNetPlugin = "downnet-plugin"
//GeneralPlugin 一般插件,默认分类,优先级最低
var GeneralPlugin = "general-plugin"

396
pkg/db/mysql/dao/plugin.go Normal file
View File

@ -0,0 +1,396 @@
// RAINBOND, Application Management Platform
// Copyright (C) 2014-2017 Goodrain Co., Ltd.
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version. For any non-GPL usage of Rainbond,
// one or multiple Commercial Licenses authorized by Goodrain Co., Ltd.
// must be obtained first.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
package dao
import (
"fmt"
"github.com/goodrain/rainbond/pkg/db/model"
"github.com/jinzhu/gorm"
)
//PluginDaoImpl PluginDaoImpl
type PluginDaoImpl struct {
DB *gorm.DB
}
//AddModel 创建插件
func (t *PluginDaoImpl) AddModel(mo model.Interface) error {
plugin := mo.(*model.TenantPlugin)
var oldPlugin model.TenantPlugin
if ok := t.DB.Where("plugin_name = ?", plugin.PluginName).Find(&oldPlugin).RecordNotFound(); ok {
if err := t.DB.Create(plugin).Error; err != nil {
return err
}
} else {
return fmt.Errorf("plugin %s is exist", plugin.PluginName)
}
return nil
}
//UpdateModel 更新插件
func (t *PluginDaoImpl) UpdateModel(mo model.Interface) error {
plugin := mo.(*model.TenantPlugin)
if err := t.DB.Save(plugin).Error; err != nil {
return err
}
return nil
}
//GetPluginByID GetPluginByID
func (t *PluginDaoImpl) GetPluginByID(id string) (*model.TenantPlugin, error) {
var plugin model.TenantPlugin
if err := t.DB.Where("plugin_id = ? ", id).Find(&plugin).Error; err != nil {
return nil, err
}
return &plugin, nil
}
//DeletePluginByID DeletePluginByID
func (t *PluginDaoImpl) DeletePluginByID(id string) error {
relation := &model.TenantPlugin{
PluginID: id,
}
if err := t.DB.Where("plugin_id=?", id).Delete(relation).Error; err != nil {
return err
}
return nil
}
//GetPluginsByTenantID GetPluginsByTenantID
func (t *PluginDaoImpl) GetPluginsByTenantID(tenantID string) ([]*model.TenantPlugin, error) {
var plugins []*model.TenantPlugin
if err := t.DB.Where("tenant_id=?", tenantID).Find(&plugins).Error; err != nil {
return nil, err
}
return plugins, nil
}
//PluginDefaultENVDaoImpl PluginDefaultENVDaoImpl
type PluginDefaultENVDaoImpl struct {
DB *gorm.DB
}
//AddModel 添加插件默认变量
func (t *PluginDefaultENVDaoImpl) AddModel(mo model.Interface) error {
env := mo.(*model.TenantPluginDefaultENV)
var oldENV model.TenantPluginDefaultENV
if ok := t.DB.Where("plugin_id=? and env_name = ?", env.PluginID, env.ENVName).Find(&oldENV).RecordNotFound(); ok {
if err := t.DB.Create(env).Error; err != nil {
return err
}
} else {
return fmt.Errorf("env %s is exist", env.ENVName)
}
return nil
}
//UpdateModel 更新插件默认变量
func (t *PluginDefaultENVDaoImpl) UpdateModel(mo model.Interface) error {
env := mo.(*model.TenantPluginDefaultENV)
if err := t.DB.Save(env).Error; err != nil {
return err
}
return nil
}
//GetDefaultENVByName GetDefaultENVByName
func (t *PluginDefaultENVDaoImpl) GetDefaultENVByName(pluginID string, name string) (*model.TenantPluginDefaultENV, error) {
var env model.TenantPluginDefaultENV
if err := t.DB.Where("plugin_id=? and env_name=?", name).Find(&env).Error; err != nil {
return nil, err
}
return &env, nil
}
//GetDefaultENVSByPluginID GetDefaultENVSByPluginID
func (t *PluginDefaultENVDaoImpl) GetDefaultENVSByPluginID(pluginID string) ([]*model.TenantPluginDefaultENV, error) {
var envs []*model.TenantPluginDefaultENV
if err := t.DB.Where("plugin_id=?", pluginID).Find(&envs).Error; err != nil {
return nil, err
}
return envs, nil
}
//GetDefaultENVSByPluginIDCantBeSet GetDefaultENVSByPluginIDCantBeSet
func (t *PluginDefaultENVDaoImpl) GetDefaultENVSByPluginIDCantBeSet(pluginID string) ([]*model.TenantPluginDefaultENV, error) {
var envs []*model.TenantPluginDefaultENV
if err := t.DB.Where("plugin_id=? and is_change=0", pluginID).Find(&envs).Error; err != nil {
return nil, err
}
return envs, nil
}
//DeleteDefaultENVByName DeleteDefaultENVByName
func (t *PluginDefaultENVDaoImpl) DeleteDefaultENVByName(pluginID, name string) error {
relation := &model.TenantPluginDefaultENV{
ENVName: name,
}
if err := t.DB.Where("plugin_id=? and env_name=?", pluginID, name).Delete(relation).Error; err != nil {
return err
}
return nil
}
//DeleteAllDefaultENVByPluginID DeleteAllDefaultENVByPluginID
func (t *PluginDefaultENVDaoImpl) DeleteAllDefaultENVByPluginID(id string) error {
relation := &model.TenantPluginDefaultENV{
PluginID: id,
}
if err := t.DB.Where("plugin_id=?", id).Delete(relation).Error; err != nil {
return err
}
return nil
}
//GetDefaultEnvWhichCanBeSetByPluginID GetDefaultEnvWhichCanBeSetByPluginID
func (t *PluginDefaultENVDaoImpl) GetDefaultEnvWhichCanBeSetByPluginID(pluginID string) ([]*model.TenantPluginDefaultENV, error) {
var envs []*model.TenantPluginDefaultENV
if err := t.DB.Where("plugin_id=? and is_change=1", pluginID).Find(&envs).Error; err != nil {
return nil, err
}
return envs, nil
}
//PluginBuildVersionDaoImpl PluginBuildVersionDaoImpl
type PluginBuildVersionDaoImpl struct {
DB *gorm.DB
}
//AddModel 添加插件构建版本信息
func (t *PluginBuildVersionDaoImpl) AddModel(mo model.Interface) error {
version := mo.(*model.TenantPluginBuildVersion)
var oldVersion model.TenantPluginBuildVersion
if ok := t.DB.Where("plugin_id =? and version_id = ?", version.PluginID, version.VersionID).Find(&oldVersion).RecordNotFound(); ok {
if err := t.DB.Create(version).Error; err != nil {
return err
}
} else {
return fmt.Errorf("plugin build version %s is exist", version.VersionID)
}
return nil
}
//UpdateModel 更新插件默认变量
//主体信息一般不变更仅构建的本地镜像名与status需要变更
func (t *PluginBuildVersionDaoImpl) UpdateModel(mo model.Interface) error {
version := mo.(*model.TenantPluginBuildVersion)
if version.ID == 0 {
return fmt.Errorf("id can not be empty when update build verion")
}
if err := t.DB.Save(version).Error; err != nil {
return err
}
return nil
}
//DeleteBuildVersionByVersionID DeleteBuildVersionByVersionID
func (t *PluginBuildVersionDaoImpl) DeleteBuildVersionByVersionID(versionID string) error {
relation := &model.TenantPluginBuildVersion{
VersionID: versionID,
}
if err := t.DB.Where("version_id=?", versionID).Delete(relation).Error; err != nil {
return err
}
return nil
}
//DeleteBuildVersionByPluginID DeleteBuildVersionByPluginID
func (t *PluginBuildVersionDaoImpl) DeleteBuildVersionByPluginID(pluginID string) error {
relation := &model.TenantPluginBuildVersion{
PluginID: pluginID,
}
if err := t.DB.Where("plugin_id=?", pluginID).Delete(relation).Error; err != nil {
return err
}
return nil
}
//GetBuildVersionByPluginID GetBuildVersionByPluginID
func (t *PluginBuildVersionDaoImpl) GetBuildVersionByPluginID(pluginID string) ([]*model.TenantPluginBuildVersion, error) {
var versions []*model.TenantPluginBuildVersion
if err := t.DB.Where("plugin_id = ? and status= ?", pluginID, "complete").Find(&versions).Error; err != nil {
return nil, err
}
return versions, nil
}
//GetBuildVersionByVersionID GetBuildVersionByVersionID
func (t *PluginBuildVersionDaoImpl) GetBuildVersionByVersionID(pluginID, versionID string) (*model.TenantPluginBuildVersion, error) {
var version model.TenantPluginBuildVersion
if err := t.DB.Where("plugin_id=? and version_id = ? ", pluginID, versionID).Find(&version).Error; err != nil {
return nil, err
}
return &version, nil
}
//PluginVersionEnvDaoImpl PluginVersionEnvDaoImpl
type PluginVersionEnvDaoImpl struct {
DB *gorm.DB
}
//AddModel 添加插件默认变量
func (t *PluginVersionEnvDaoImpl) AddModel(mo model.Interface) error {
env := mo.(*model.TenantPluginVersionEnv)
var oldENV model.TenantPluginVersionEnv
if ok := t.DB.Where("plugin_id=? and env_name = ?", env.PluginID, env.EnvName).Find(&oldENV).RecordNotFound(); ok {
if err := t.DB.Create(env).Error; err != nil {
return err
}
} else {
return fmt.Errorf("env %s is exist", env.EnvName)
}
return nil
}
//UpdateModel 更新插件默认变量
func (t *PluginVersionEnvDaoImpl) UpdateModel(mo model.Interface) error {
env := mo.(*model.TenantPluginVersionEnv)
if env.ID == 0 || env.ServiceID == "" || env.PluginID == "" {
return fmt.Errorf("id can not be empty when update plugin version env")
}
if err := t.DB.Save(env).Error; err != nil {
return err
}
return nil
}
//DeleteEnvByEnvName 删除单个env
func (t *PluginVersionEnvDaoImpl) DeleteEnvByEnvName(envName, pluginID, serviceID string) error {
env := &model.TenantPluginVersionEnv{
PluginID: pluginID,
EnvName: envName,
ServiceID: serviceID,
}
return t.DB.Where("env_name=? and plugin_id=? and service_id=?", envName, pluginID, serviceID).Delete(env).Error
}
//DeleteEnvByPluginID 删除插件依赖关系时需要操作删除对应env
func (t *PluginVersionEnvDaoImpl) DeleteEnvByPluginID(serviceID, pluginID string) error {
env := &model.TenantPluginVersionEnv{
PluginID: pluginID,
ServiceID: serviceID,
}
return t.DB.Where("plugin_id=? and service_id= ?", pluginID, serviceID).Delete(env).Error
}
//DeleteEnvByServiceID 删除应用时,需要进行此操作
func (t *PluginVersionEnvDaoImpl) DeleteEnvByServiceID(serviceID string) error {
env := &model.TenantPluginVersionEnv{
ServiceID: serviceID,
}
return t.DB.Where("service_id=?", serviceID).Delete(env).Error
}
//GetVersionEnvByServiceID 获取该应用下使用的某个插件依赖的插件变量
func (t *PluginVersionEnvDaoImpl) GetVersionEnvByServiceID(serviceID string, pluginID string) ([]*model.TenantPluginVersionEnv, error) {
var envs []*model.TenantPluginVersionEnv
if err := t.DB.Where("service_id=? and plugin_id=?", serviceID, pluginID).Find(&envs).Error; err != nil {
return nil, err
}
return envs, nil
}
//GetVersionEnvByEnvName GetVersionEnvByEnvName
func (t *PluginVersionEnvDaoImpl) GetVersionEnvByEnvName(serviceID, pluginID, envName string) (*model.TenantPluginVersionEnv, error) {
var env *model.TenantPluginVersionEnv
if err := t.DB.Where("service_id=? and plugin_id=? and env_name=?", serviceID, pluginID, envName).Find(&env).Error; err != nil {
return nil, err
}
return env, nil
}
//TenantServicePluginRelationDaoImpl TenantServicePluginRelationDaoImpl
type TenantServicePluginRelationDaoImpl struct {
DB *gorm.DB
}
//AddModel 添加插件默认变量
func (t *TenantServicePluginRelationDaoImpl) AddModel(mo model.Interface) error {
relation := mo.(*model.TenantServicePluginRelation)
var oldRelation model.TenantServicePluginRelation
if ok := t.DB.Where("service_id= ? and plugin_id=?", relation.ServiceID, relation.PluginID).Find(&oldRelation).RecordNotFound(); ok {
if err := t.DB.Create(relation).Error; err != nil {
return err
}
} else {
return fmt.Errorf("relation between %s and %s is exist", relation.ServiceID, relation.PluginID)
}
return nil
}
//UpdateModel 更新插件默认变量 更新依赖的version id
func (t *TenantServicePluginRelationDaoImpl) UpdateModel(mo model.Interface) error {
relation := mo.(*model.TenantServicePluginRelation)
if relation.ID == 0 {
return fmt.Errorf("id can not be empty when update service plugin relation")
}
if err := t.DB.Save(relation).Error; err != nil {
return err
}
return nil
}
//DeleteRelationByServiceIDAndPluginID 删除service plugin 对应关系
func (t *TenantServicePluginRelationDaoImpl) DeleteRelationByServiceIDAndPluginID(serviceID, pluginID string) error {
relation := &model.TenantServicePluginRelation{
ServiceID: serviceID,
PluginID: pluginID,
}
return t.DB.Where("plugin_id=? and service_id=?",
pluginID,
serviceID).Delete(relation).Error
}
//DeleteALLRelationByServiceID 删除serviceID所有插件依赖 一般用于删除应用时使用
func (t *TenantServicePluginRelationDaoImpl) DeleteALLRelationByServiceID(serviceID string) error {
relation := &model.TenantServicePluginRelation{
ServiceID: serviceID,
}
return t.DB.Where("service_id=?", serviceID).Delete(relation).Error
}
//DeleteALLRelationByPluginID 删除pluginID所有依赖 一般不要使用 会影响关联过的应用启动
func (t *TenantServicePluginRelationDaoImpl) DeleteALLRelationByPluginID(pluginID string) error {
relation := &model.TenantServicePluginRelation{
PluginID: pluginID,
}
return t.DB.Where("plugin_id=?", pluginID).Delete(relation).Error
}
//GetALLRelationByServiceID 获取当前应用所有的插件依赖关系
func (t *TenantServicePluginRelationDaoImpl) GetALLRelationByServiceID(serviceID string) ([]*model.TenantServicePluginRelation, error) {
var relations []*model.TenantServicePluginRelation
if err := t.DB.Where("service_id=?", serviceID).Find(&relations).Error; err != nil {
return nil, err
}
return relations, nil
}
//GetRelateionByServiceIDAndPluginID GetRelateionByServiceIDAndPluginID
func (t *TenantServicePluginRelationDaoImpl) GetRelateionByServiceIDAndPluginID(serviceID, pluginID string) (*model.TenantServicePluginRelation, error) {
relation := &model.TenantServicePluginRelation{
PluginID: pluginID,
ServiceID: serviceID,
}
if err := t.DB.Where("plugin_id=? and service_id=?", pluginID, serviceID).Find(relation).Error; err != nil {
return nil, err
}
return relation, nil
}

View File

@ -1086,373 +1086,3 @@ func (t *ServiceStatusDaoImpl) GetTenantServicesStatus(serviceIDs []string) ([]*
}
return statuss, nil
}
//PluginDaoImpl PluginDaoImpl
type PluginDaoImpl struct {
DB *gorm.DB
}
//AddModel 创建插件
func (t *PluginDaoImpl) AddModel(mo model.Interface) error {
plugin := mo.(*model.TenantPlugin)
var oldPlugin model.TenantPlugin
if ok := t.DB.Where("plugin_name = ?", plugin.PluginName).Find(&oldPlugin).RecordNotFound(); ok {
if err := t.DB.Create(plugin).Error; err != nil {
return err
}
} else {
return fmt.Errorf("plugin %s is exist", plugin.PluginName)
}
return nil
}
//UpdateModel 更新插件
func (t *PluginDaoImpl) UpdateModel(mo model.Interface) error {
plugin := mo.(*model.TenantPlugin)
if err := t.DB.Save(plugin).Error; err != nil {
return err
}
return nil
}
//GetPluginByID GetPluginByID
func (t *PluginDaoImpl) GetPluginByID(id string) (*model.TenantPlugin, error) {
var plugin model.TenantPlugin
if err := t.DB.Where("plugin_id = ? ", id).Find(&plugin).Error; err != nil {
return nil, err
}
return &plugin, nil
}
//DeletePluginByID DeletePluginByID
func (t *PluginDaoImpl) DeletePluginByID(id string) error {
relation := &model.TenantPlugin{
PluginID: id,
}
if err := t.DB.Where("plugin_id=?", id).Delete(relation).Error; err != nil {
return err
}
return nil
}
//GetPluginsByTenantID GetPluginsByTenantID
func (t *PluginDaoImpl) GetPluginsByTenantID(tenantID string) ([]*model.TenantPlugin, error) {
var plugins []*model.TenantPlugin
if err := t.DB.Where("tenant_id=?", tenantID).Find(&plugins).Error; err != nil {
return nil, err
}
return plugins, nil
}
//PluginDefaultENVDaoImpl PluginDefaultENVDaoImpl
type PluginDefaultENVDaoImpl struct {
DB *gorm.DB
}
//AddModel 添加插件默认变量
func (t *PluginDefaultENVDaoImpl) AddModel(mo model.Interface) error {
env := mo.(*model.TenantPluginDefaultENV)
var oldENV model.TenantPluginDefaultENV
if ok := t.DB.Where("plugin_id=? and env_name = ?", env.PluginID, env.ENVName).Find(&oldENV).RecordNotFound(); ok {
if err := t.DB.Create(env).Error; err != nil {
return err
}
} else {
return fmt.Errorf("env %s is exist", env.ENVName)
}
return nil
}
//UpdateModel 更新插件默认变量
func (t *PluginDefaultENVDaoImpl) UpdateModel(mo model.Interface) error {
env := mo.(*model.TenantPluginDefaultENV)
if err := t.DB.Save(env).Error; err != nil {
return err
}
return nil
}
//GetDefaultENVByName GetDefaultENVByName
func (t *PluginDefaultENVDaoImpl) GetDefaultENVByName(pluginID string, name string) (*model.TenantPluginDefaultENV, error) {
var env model.TenantPluginDefaultENV
if err := t.DB.Where("plugin_id=? and env_name=?", name).Find(&env).Error; err != nil {
return nil, err
}
return &env, nil
}
//GetDefaultENVSByPluginID GetDefaultENVSByPluginID
func (t *PluginDefaultENVDaoImpl) GetDefaultENVSByPluginID(pluginID string) ([]*model.TenantPluginDefaultENV, error) {
var envs []*model.TenantPluginDefaultENV
if err := t.DB.Where("plugin_id=?", pluginID).Find(&envs).Error; err != nil {
return nil, err
}
return envs, nil
}
//GetDefaultENVSByPluginIDCantBeSet GetDefaultENVSByPluginIDCantBeSet
func (t *PluginDefaultENVDaoImpl) GetDefaultENVSByPluginIDCantBeSet(pluginID string) ([]*model.TenantPluginDefaultENV, error) {
var envs []*model.TenantPluginDefaultENV
if err := t.DB.Where("plugin_id=? and is_change=0", pluginID).Find(&envs).Error; err != nil {
return nil, err
}
return envs, nil
}
//DeleteDefaultENVByName DeleteDefaultENVByName
func (t *PluginDefaultENVDaoImpl) DeleteDefaultENVByName(pluginID, name string) error {
relation := &model.TenantPluginDefaultENV{
ENVName: name,
}
if err := t.DB.Where("plugin_id=? and env_name=?", pluginID, name).Delete(relation).Error; err != nil {
return err
}
return nil
}
//DeleteAllDefaultENVByPluginID DeleteAllDefaultENVByPluginID
func (t *PluginDefaultENVDaoImpl) DeleteAllDefaultENVByPluginID(id string) error {
relation := &model.TenantPluginDefaultENV{
PluginID: id,
}
if err := t.DB.Where("plugin_id=?", id).Delete(relation).Error; err != nil {
return err
}
return nil
}
//GetDefaultEnvWhichCanBeSetByPluginID GetDefaultEnvWhichCanBeSetByPluginID
func (t *PluginDefaultENVDaoImpl) GetDefaultEnvWhichCanBeSetByPluginID(pluginID string) ([]*model.TenantPluginDefaultENV, error) {
var envs []*model.TenantPluginDefaultENV
if err := t.DB.Where("plugin_id=? and is_change=1", pluginID).Find(&envs).Error; err != nil {
return nil, err
}
return envs, nil
}
//PluginBuildVersionDaoImpl PluginBuildVersionDaoImpl
type PluginBuildVersionDaoImpl struct {
DB *gorm.DB
}
//AddModel 添加插件构建版本信息
func (t *PluginBuildVersionDaoImpl) AddModel(mo model.Interface) error {
version := mo.(*model.TenantPluginBuildVersion)
var oldVersion model.TenantPluginBuildVersion
if ok := t.DB.Where("plugin_id =? and version_id = ?", version.PluginID, version.VersionID).Find(&oldVersion).RecordNotFound(); ok {
if err := t.DB.Create(version).Error; err != nil {
return err
}
} else {
return fmt.Errorf("plugin build version %s is exist", version.VersionID)
}
return nil
}
//UpdateModel 更新插件默认变量
//主体信息一般不变更仅构建的本地镜像名与status需要变更
func (t *PluginBuildVersionDaoImpl) UpdateModel(mo model.Interface) error {
version := mo.(*model.TenantPluginBuildVersion)
if version.ID == 0 {
return fmt.Errorf("id can not be empty when update build verion")
}
if err := t.DB.Save(version).Error; err != nil {
return err
}
return nil
}
//DeleteBuildVersionByVersionID DeleteBuildVersionByVersionID
func (t *PluginBuildVersionDaoImpl) DeleteBuildVersionByVersionID(versionID string) error {
relation := &model.TenantPluginBuildVersion{
VersionID: versionID,
}
if err := t.DB.Where("version_id=?", versionID).Delete(relation).Error; err != nil {
return err
}
return nil
}
//DeleteBuildVersionByPluginID DeleteBuildVersionByPluginID
func (t *PluginBuildVersionDaoImpl) DeleteBuildVersionByPluginID(pluginID string) error {
relation := &model.TenantPluginBuildVersion{
PluginID: pluginID,
}
if err := t.DB.Where("plugin_id=?", pluginID).Delete(relation).Error; err != nil {
return err
}
return nil
}
//GetBuildVersionByPluginID GetBuildVersionByPluginID
func (t *PluginBuildVersionDaoImpl) GetBuildVersionByPluginID(pluginID string) ([]*model.TenantPluginBuildVersion, error) {
var versions []*model.TenantPluginBuildVersion
if err := t.DB.Where("plugin_id = ? and status= ?", pluginID, "complete").Find(&versions).Error; err != nil {
return nil, err
}
return versions, nil
}
//GetBuildVersionByVersionID GetBuildVersionByVersionID
func (t *PluginBuildVersionDaoImpl) GetBuildVersionByVersionID(pluginID, versionID string) (*model.TenantPluginBuildVersion, error) {
var version model.TenantPluginBuildVersion
if err := t.DB.Where("plugin_id=? and version_id = ? ", pluginID, versionID).Find(&version).Error; err != nil {
return nil, err
}
return &version, nil
}
//PluginVersionEnvDaoImpl PluginVersionEnvDaoImpl
type PluginVersionEnvDaoImpl struct {
DB *gorm.DB
}
//AddModel 添加插件默认变量
func (t *PluginVersionEnvDaoImpl) AddModel(mo model.Interface) error {
env := mo.(*model.TenantPluginVersionEnv)
var oldENV model.TenantPluginVersionEnv
if ok := t.DB.Where("plugin_id=? and env_name = ?", env.PluginID, env.EnvName).Find(&oldENV).RecordNotFound(); ok {
if err := t.DB.Create(env).Error; err != nil {
return err
}
} else {
return fmt.Errorf("env %s is exist", env.EnvName)
}
return nil
}
//UpdateModel 更新插件默认变量
func (t *PluginVersionEnvDaoImpl) UpdateModel(mo model.Interface) error {
env := mo.(*model.TenantPluginVersionEnv)
if env.ID == 0 || env.ServiceID == "" || env.PluginID == "" {
return fmt.Errorf("id can not be empty when update plugin version env")
}
if err := t.DB.Save(env).Error; err != nil {
return err
}
return nil
}
//DeleteEnvByEnvName 删除单个env
func (t *PluginVersionEnvDaoImpl) DeleteEnvByEnvName(envName, pluginID, serviceID string) error {
env := &model.TenantPluginVersionEnv{
PluginID: pluginID,
EnvName: envName,
ServiceID: serviceID,
}
return t.DB.Where("env_name=? and plugin_id=? and service_id=?", envName, pluginID, serviceID).Delete(env).Error
}
//DeleteEnvByPluginID 删除插件依赖关系时需要操作删除对应env
func (t *PluginVersionEnvDaoImpl) DeleteEnvByPluginID(serviceID, pluginID string) error {
env := &model.TenantPluginVersionEnv{
PluginID: pluginID,
ServiceID: serviceID,
}
return t.DB.Where("plugin_id=? and service_id= ?", pluginID, serviceID).Delete(env).Error
}
//DeleteEnvByServiceID 删除应用时,需要进行此操作
func (t *PluginVersionEnvDaoImpl) DeleteEnvByServiceID(serviceID string) error {
env := &model.TenantPluginVersionEnv{
ServiceID: serviceID,
}
return t.DB.Where("service_id=?", serviceID).Delete(env).Error
}
//GetVersionEnvByServiceID 获取该应用下使用的某个插件依赖的插件变量
func (t *PluginVersionEnvDaoImpl) GetVersionEnvByServiceID(serviceID string, pluginID string) ([]*model.TenantPluginVersionEnv, error) {
var envs []*model.TenantPluginVersionEnv
if err := t.DB.Where("service_id=? and plugin_id=?", serviceID, pluginID).Find(&envs).Error; err != nil {
return nil, err
}
return envs, nil
}
//GetVersionEnvByEnvName GetVersionEnvByEnvName
func (t *PluginVersionEnvDaoImpl) GetVersionEnvByEnvName(serviceID, pluginID, envName string) (*model.TenantPluginVersionEnv, error) {
var env *model.TenantPluginVersionEnv
if err := t.DB.Where("service_id=? and plugin_id=? and env_name=?", serviceID, pluginID, envName).Find(&env).Error; err != nil {
return nil, err
}
return env, nil
}
//TenantServicePluginRelationDaoImpl TenantServicePluginRelationDaoImpl
type TenantServicePluginRelationDaoImpl struct {
DB *gorm.DB
}
//AddModel 添加插件默认变量
func (t *TenantServicePluginRelationDaoImpl) AddModel(mo model.Interface) error {
relation := mo.(*model.TenantServicePluginRelation)
var oldRelation model.TenantServicePluginRelation
if ok := t.DB.Where("service_id= ? and plugin_id=?", relation.ServiceID, relation.PluginID).Find(&oldRelation).RecordNotFound(); ok {
if err := t.DB.Create(relation).Error; err != nil {
return err
}
} else {
return fmt.Errorf("relation between %s and %s is exist", relation.ServiceID, relation.PluginID)
}
return nil
}
//UpdateModel 更新插件默认变量 更新依赖的version id
func (t *TenantServicePluginRelationDaoImpl) UpdateModel(mo model.Interface) error {
relation := mo.(*model.TenantServicePluginRelation)
if relation.ID == 0 {
return fmt.Errorf("id can not be empty when update service plugin relation")
}
if err := t.DB.Save(relation).Error; err != nil {
return err
}
return nil
}
//DeleteRelationByServiceIDAndPluginID 删除service plugin 对应关系
func (t *TenantServicePluginRelationDaoImpl) DeleteRelationByServiceIDAndPluginID(serviceID, pluginID string) error {
relation := &model.TenantServicePluginRelation{
ServiceID: serviceID,
PluginID: pluginID,
}
return t.DB.Where("plugin_id=? and service_id=?",
pluginID,
serviceID).Delete(relation).Error
}
//DeleteALLRelationByServiceID 删除serviceID所有插件依赖 一般用于删除应用时使用
func (t *TenantServicePluginRelationDaoImpl) DeleteALLRelationByServiceID(serviceID string) error {
relation := &model.TenantServicePluginRelation{
ServiceID: serviceID,
}
return t.DB.Where("service_id=?", serviceID).Delete(relation).Error
}
//DeleteALLRelationByPluginID 删除pluginID所有依赖 一般不要使用 会影响关联过的应用启动
func (t *TenantServicePluginRelationDaoImpl) DeleteALLRelationByPluginID(pluginID string) error {
relation := &model.TenantServicePluginRelation{
PluginID: pluginID,
}
return t.DB.Where("plugin_id=?", pluginID).Delete(relation).Error
}
//GetALLRelationByServiceID 获取当前应用所有的插件依赖关系
func (t *TenantServicePluginRelationDaoImpl) GetALLRelationByServiceID(serviceID string) ([]*model.TenantServicePluginRelation, error) {
var relations []*model.TenantServicePluginRelation
if err := t.DB.Where("service_id=?", serviceID).Find(&relations).Error; err != nil {
return nil, err
}
return relations, nil
}
//GetRelateionByServiceIDAndPluginID GetRelateionByServiceIDAndPluginID
func (t *TenantServicePluginRelationDaoImpl) GetRelateionByServiceIDAndPluginID(serviceID, pluginID string) (*model.TenantServicePluginRelation, error) {
relation := &model.TenantServicePluginRelation{
PluginID: pluginID,
ServiceID: serviceID,
}
if err := t.DB.Where("plugin_id=? and service_id=?", pluginID, serviceID).Find(relation).Error; err != nil {
return nil, err
}
return relation, nil
}

View File

@ -30,25 +30,30 @@ import (
//NewCmdPlugin 插件相关操作
func NewCmdPlugin() cli.Command {
c := cli.Command{
Name: "plugin",
Flags: []cli.Flag{
cli.BoolFlag{
Name: "create, c",
Usage: "创建插件。 grctl plugin -c NAMESPACE PLUGIN_ID -i INFOS",
Name: "plugin",
Usage: "插件相关操作。grctl plugin [create/delete/update/build] NAMESPACE PLUGIN_ID [commands] [sources]",
Subcommands: []cli.Command{
{
Name: "create",
Usage: "创建自定义资源。 grctl sources create -g NAMESPACE/SOURCEALIAS -k ENVNAME -v ENVVALUE",
Action: func(c *cli.Context) error {
return sourcesAction(c, "create")
},
Flags: []cli.Flag{
cli.StringFlag{
Name: "group, g",
Usage: "--group/-g NAMESPACE/SOURCEALIAS",
},
cli.StringFlag{
Name: "key, k",
Usage: "自定义资源名,-k ENVNAME",
},
cli.StringFlag{
Name: "value, v",
Usage: "自定义资源值,-v ENVVALUE",
},
},
},
cli.BoolFlag{
Name: "update, u",
Usage: "更新插件。 grctl plugin -u NAMESPACE PLUGIN_ID -i INFOS",
},
cli.BoolFlag{
Name: "delete, d",
Usage: "删除插件。 grctl plugin -d NAMESPACE PLUGIN_ID",
},
},
Usage: "插件相关操作。grctl plugin [create/delete/update] NAMESPACE PLUGIN_ID [commands] [sources]",
Action: func(c *cli.Context) error {
Common(c)
return pluginAction(c)
},
}
return c

View File

@ -273,36 +273,6 @@ func (p *PodTemplateSpecBuild) createContainer(volumeMounts []v1.VolumeMount, en
}
containers = append(containers, c1)
/*
//构建proxy容器
if p.needProxy {
var AppPropertyHeighten bool
for _, e := range *envs {
if e.Name == "SEVEN_LEVEL" {
AppPropertyHeighten = true
break
}
}
c2 := v1.Container{
Name: "adapter-" + p.serviceID[len(p.serviceID)-20:],
VolumeMounts: []v1.VolumeMount{v1.VolumeMount{
MountPath: "/etc/kubernetes",
Name: "kube-config",
ReadOnly: true,
}},
TerminationMessagePath: "",
Env: *envs,
Resources: p.createAdapterResources(50, 20),
}
//应用性能增强打开
if AppPropertyHeighten {
c2.Image = "goodrain.me/mid_rain"
} else {
c2.Image = "goodrain.me/adapter"
}
containers = append(containers, c2)
}
*/
//构建日志收集容器
var LogMatch bool
for _, e := range *envs {