mirror of
https://gitee.com/rainbond/Rainbond.git
synced 2024-12-02 03:37:46 +08:00
Merge branch 'master' of code.goodrain.com:goodrain/rainbond
This commit is contained in:
commit
0fd74e3d8d
@ -23,6 +23,8 @@ import (
|
||||
"sort"
|
||||
"github.com/urfave/cli"
|
||||
"github.com/goodrain/rainbond/pkg/grctl/cmd"
|
||||
//"github.com/Sirupsen/logrus"
|
||||
//"github.com/goodrain/rainbond/pkg/grctl/clients"
|
||||
"github.com/Sirupsen/logrus"
|
||||
"github.com/goodrain/rainbond/pkg/grctl/clients"
|
||||
)
|
||||
@ -41,7 +43,7 @@ func Run() error {
|
||||
sort.Sort(cli.FlagsByName(App.Flags))
|
||||
sort.Sort(cli.CommandsByName(App.Commands))
|
||||
App.Commands=cmd.GetCmds()
|
||||
if err := clients.InitNodeClient("http://test.goodrain.com:8888/v2"); err != nil {
|
||||
if err := clients.InitNodeClient("http://127.0.0.1:6100/v2"); err != nil {
|
||||
logrus.Warnf("error config region")
|
||||
}
|
||||
|
||||
|
@ -808,7 +808,7 @@
|
||||
"tags": [
|
||||
"v2"
|
||||
],
|
||||
"summary": "监控数据查询 **完成",
|
||||
"summary": "监控数据查询",
|
||||
"operationId": "oentsdbquery",
|
||||
"parameters": [
|
||||
{
|
||||
@ -855,7 +855,7 @@
|
||||
"tags": [
|
||||
"v2"
|
||||
],
|
||||
"summary": "租户资源使用情况 **完成",
|
||||
"summary": "租户资源使用情况",
|
||||
"operationId": "tenantResources",
|
||||
"parameters": [
|
||||
{
|
||||
@ -899,7 +899,7 @@
|
||||
"tags": [
|
||||
"v2"
|
||||
],
|
||||
"summary": "获取租户数量 **完成",
|
||||
"summary": "获取租户数量",
|
||||
"operationId": "sumTenants",
|
||||
"responses": {
|
||||
"default": {
|
||||
@ -947,7 +947,7 @@
|
||||
"tags": [
|
||||
"v2"
|
||||
],
|
||||
"summary": "添加租户信息 **完成",
|
||||
"summary": "添加租户信息",
|
||||
"operationId": "addTenant",
|
||||
"parameters": [
|
||||
{
|
||||
@ -991,7 +991,7 @@
|
||||
},
|
||||
"/v2/tenants/{tenant_name}/cloud-share": {
|
||||
"post": {
|
||||
"description": "share cloud **完成",
|
||||
"description": "share cloud",
|
||||
"consumes": [
|
||||
"application/json",
|
||||
"application/x-protobuf"
|
||||
@ -1049,7 +1049,7 @@
|
||||
},
|
||||
"/v2/tenants/{tenant_name}/code-check": {
|
||||
"post": {
|
||||
"description": "check code **完成",
|
||||
"description": "check code",
|
||||
"consumes": [
|
||||
"application/json",
|
||||
"application/x-protobuf"
|
||||
@ -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"
|
||||
},
|
||||
@ -1693,6 +1705,22 @@
|
||||
],
|
||||
"summary": "获取插件默认设定的env",
|
||||
"operationId": "getPluginDefaultEnv",
|
||||
"parameters": [
|
||||
{
|
||||
"type": "string",
|
||||
"x-go-name": "TenantName",
|
||||
"name": "tenant_name",
|
||||
"in": "path",
|
||||
"required": true
|
||||
},
|
||||
{
|
||||
"type": "string",
|
||||
"x-go-name": "PluginID",
|
||||
"name": "plugin_id",
|
||||
"in": "path",
|
||||
"required": true
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"default": {
|
||||
"description": "统一返回格式",
|
||||
@ -1881,7 +1909,7 @@
|
||||
"tags": [
|
||||
"v2"
|
||||
],
|
||||
"summary": "指定租户资源使用情况 **完成",
|
||||
"summary": "指定租户资源使用情况",
|
||||
"operationId": "singletenantResources",
|
||||
"parameters": [
|
||||
{
|
||||
@ -1904,7 +1932,7 @@
|
||||
},
|
||||
"/v2/tenants/{tenant_name}/services": {
|
||||
"get": {
|
||||
"description": "get services info in tenant **完成",
|
||||
"description": "get services info in tenant",
|
||||
"consumes": [
|
||||
"application/json",
|
||||
"application/x-protobuf"
|
||||
@ -1937,7 +1965,7 @@
|
||||
}
|
||||
},
|
||||
"post": {
|
||||
"description": "create service **完成",
|
||||
"description": "create service",
|
||||
"consumes": [
|
||||
"application/json",
|
||||
"application/x-protobuf"
|
||||
@ -2163,7 +2191,7 @@
|
||||
},
|
||||
"/v2/tenants/{tenant_name}/services/{service_alias}": {
|
||||
"get": {
|
||||
"description": "get service info **完成",
|
||||
"description": "get service info",
|
||||
"consumes": [
|
||||
"application/json",
|
||||
"application/x-protobuf"
|
||||
@ -2203,7 +2231,7 @@
|
||||
}
|
||||
},
|
||||
"put": {
|
||||
"description": "update service **完成",
|
||||
"description": "update service",
|
||||
"consumes": [
|
||||
"application/json",
|
||||
"application/x-protobuf"
|
||||
@ -2310,7 +2338,7 @@
|
||||
},
|
||||
"/v2/tenants/{tenant_name}/services/{service_alias}/build": {
|
||||
"post": {
|
||||
"description": "service build **完成",
|
||||
"description": "service build",
|
||||
"consumes": [
|
||||
"application/json",
|
||||
"application/x-protobuf"
|
||||
@ -2416,7 +2444,7 @@
|
||||
},
|
||||
"/v2/tenants/{tenant_name}/services/{service_alias}/dependency": {
|
||||
"post": {
|
||||
"description": "add dependency **完成",
|
||||
"description": "add dependency",
|
||||
"consumes": [
|
||||
"application/json",
|
||||
"application/x-protobuf"
|
||||
@ -2483,7 +2511,7 @@
|
||||
}
|
||||
},
|
||||
"delete": {
|
||||
"description": "delete dependency **完成",
|
||||
"description": "delete dependency",
|
||||
"consumes": [
|
||||
"application/json",
|
||||
"application/x-protobuf"
|
||||
@ -2592,7 +2620,7 @@
|
||||
}
|
||||
},
|
||||
"post": {
|
||||
"description": "add volume dependency **完成",
|
||||
"description": "add volume dependency",
|
||||
"consumes": [
|
||||
"application/json",
|
||||
"application/x-protobuf"
|
||||
@ -2661,7 +2689,7 @@
|
||||
}
|
||||
},
|
||||
"delete": {
|
||||
"description": "delete volume dependency **完成",
|
||||
"description": "delete volume dependency",
|
||||
"consumes": [
|
||||
"application/json",
|
||||
"application/x-protobuf"
|
||||
@ -2726,7 +2754,7 @@
|
||||
},
|
||||
"/v2/tenants/{tenant_name}/services/{service_alias}/env": {
|
||||
"post": {
|
||||
"description": "add env var **完成",
|
||||
"description": "add env var",
|
||||
"consumes": [
|
||||
"application/json",
|
||||
"application/x-protobuf"
|
||||
@ -2809,7 +2837,7 @@
|
||||
}
|
||||
},
|
||||
"delete": {
|
||||
"description": "delete env var **完成",
|
||||
"description": "delete env var",
|
||||
"consumes": [
|
||||
"application/json",
|
||||
"application/x-protobuf"
|
||||
@ -2902,7 +2930,7 @@
|
||||
"tags": [
|
||||
"v2"
|
||||
],
|
||||
"summary": "获取指定操作的操作日志 **完成",
|
||||
"summary": "获取指定操作的操作日志",
|
||||
"operationId": "logByAction",
|
||||
"parameters": [
|
||||
{
|
||||
@ -2955,7 +2983,7 @@
|
||||
},
|
||||
"/v2/tenants/{tenant_name}/services/{service_alias}/horizontal": {
|
||||
"put": {
|
||||
"description": "service horizontal **完成",
|
||||
"description": "service horizontal",
|
||||
"consumes": [
|
||||
"application/json",
|
||||
"application/x-protobuf"
|
||||
@ -3017,7 +3045,7 @@
|
||||
},
|
||||
"/v2/tenants/{tenant_name}/services/{service_alias}/language": {
|
||||
"post": {
|
||||
"description": "set language **完成",
|
||||
"description": "set language",
|
||||
"consumes": [
|
||||
"application/json",
|
||||
"application/x-protobuf"
|
||||
@ -3090,7 +3118,7 @@
|
||||
"tags": [
|
||||
"v2"
|
||||
],
|
||||
"summary": "获取最新指定数量条日志 **完成",
|
||||
"summary": "获取最新指定数量条日志",
|
||||
"operationId": "lastLinesLogs",
|
||||
"parameters": [
|
||||
{
|
||||
@ -3146,7 +3174,7 @@
|
||||
"tags": [
|
||||
"v2"
|
||||
],
|
||||
"summary": "获取应用日志列表 **完成",
|
||||
"summary": "获取应用日志列表",
|
||||
"operationId": "logList",
|
||||
"parameters": [
|
||||
{
|
||||
@ -3184,7 +3212,7 @@
|
||||
"tags": [
|
||||
"v2"
|
||||
],
|
||||
"summary": "下载应用指定日志 **完成",
|
||||
"summary": "下载应用指定日志",
|
||||
"operationId": "logFile",
|
||||
"parameters": [
|
||||
{
|
||||
@ -3229,7 +3257,7 @@
|
||||
"tags": [
|
||||
"v2"
|
||||
],
|
||||
"summary": "获取应用日志web-socket实例 **完成",
|
||||
"summary": "获取应用日志web-socket实例",
|
||||
"operationId": "logSocket",
|
||||
"parameters": [
|
||||
{
|
||||
@ -3480,7 +3508,7 @@
|
||||
},
|
||||
"/v2/tenants/{tenant_name}/services/{service_alias}/node-label": {
|
||||
"post": {
|
||||
"description": "add node label **完成",
|
||||
"description": "add node label",
|
||||
"consumes": [
|
||||
"application/json",
|
||||
"application/x-protobuf"
|
||||
@ -3540,7 +3568,7 @@
|
||||
}
|
||||
},
|
||||
"delete": {
|
||||
"description": "delete node label **完成",
|
||||
"description": "delete node label",
|
||||
"consumes": [
|
||||
"application/json",
|
||||
"application/x-protobuf"
|
||||
@ -4025,7 +4053,7 @@
|
||||
},
|
||||
"/v2/tenants/{tenant_name}/services/{service_alias}/pods": {
|
||||
"get": {
|
||||
"description": "get pods info **完成",
|
||||
"description": "get pods info",
|
||||
"consumes": [
|
||||
"application/json",
|
||||
"application/x-protobuf"
|
||||
@ -4067,7 +4095,7 @@
|
||||
},
|
||||
"/v2/tenants/{tenant_name}/services/{service_alias}/ports": {
|
||||
"put": {
|
||||
"description": "update port **完成",
|
||||
"description": "update port",
|
||||
"consumes": [
|
||||
"application/json",
|
||||
"application/x-protobuf"
|
||||
@ -4122,7 +4150,7 @@
|
||||
}
|
||||
},
|
||||
"post": {
|
||||
"description": "add port **完成",
|
||||
"description": "add port",
|
||||
"consumes": [
|
||||
"application/json",
|
||||
"application/x-protobuf"
|
||||
@ -4179,7 +4207,7 @@
|
||||
},
|
||||
"/v2/tenants/{tenant_name}/services/{service_alias}/ports/{port}": {
|
||||
"delete": {
|
||||
"description": "delete port **完成",
|
||||
"description": "delete port",
|
||||
"consumes": [
|
||||
"application/json",
|
||||
"application/x-protobuf"
|
||||
@ -4230,7 +4258,7 @@
|
||||
},
|
||||
"/v2/tenants/{tenant_name}/services/{service_alias}/ports/{port}/inner": {
|
||||
"put": {
|
||||
"description": "add port **完成",
|
||||
"description": "add port",
|
||||
"consumes": [
|
||||
"application/json",
|
||||
"application/x-protobuf"
|
||||
@ -4297,7 +4325,7 @@
|
||||
},
|
||||
"/v2/tenants/{tenant_name}/services/{service_alias}/ports/{port}/outer": {
|
||||
"put": {
|
||||
"description": "add port **完成",
|
||||
"description": "add port",
|
||||
"consumes": [
|
||||
"application/json",
|
||||
"application/x-protobuf"
|
||||
@ -4364,7 +4392,7 @@
|
||||
},
|
||||
"/v2/tenants/{tenant_name}/services/{service_alias}/probe": {
|
||||
"put": {
|
||||
"description": "update probe ** 完成",
|
||||
"description": "update probe",
|
||||
"consumes": [
|
||||
"application/json",
|
||||
"application/x-protobuf"
|
||||
@ -4488,7 +4516,7 @@
|
||||
}
|
||||
},
|
||||
"post": {
|
||||
"description": "add probe **完成",
|
||||
"description": "add probe",
|
||||
"consumes": [
|
||||
"application/json",
|
||||
"application/x-protobuf"
|
||||
@ -4612,7 +4640,7 @@
|
||||
}
|
||||
},
|
||||
"delete": {
|
||||
"description": "delete probe **完成",
|
||||
"description": "delete probe",
|
||||
"consumes": [
|
||||
"application/json",
|
||||
"application/x-protobuf"
|
||||
@ -4671,7 +4699,7 @@
|
||||
},
|
||||
"/v2/tenants/{tenant_name}/services/{service_alias}/restart": {
|
||||
"post": {
|
||||
"description": "restart service **完成",
|
||||
"description": "restart service",
|
||||
"consumes": [
|
||||
"application/json",
|
||||
"application/x-protobuf"
|
||||
@ -4727,7 +4755,7 @@
|
||||
},
|
||||
"/v2/tenants/{tenant_name}/services/{service_alias}/rollback": {
|
||||
"post": {
|
||||
"description": "service rollback **完成",
|
||||
"description": "service rollback",
|
||||
"consumes": [
|
||||
"application/json",
|
||||
"application/x-protobuf"
|
||||
@ -4796,7 +4824,7 @@
|
||||
},
|
||||
"/v2/tenants/{tenant_name}/services/{service_alias}/service-label": {
|
||||
"put": {
|
||||
"description": "delete service label **完成",
|
||||
"description": "delete service label",
|
||||
"consumes": [
|
||||
"application/json",
|
||||
"application/x-protobuf"
|
||||
@ -4853,7 +4881,7 @@
|
||||
}
|
||||
},
|
||||
"post": {
|
||||
"description": "add service label **完成",
|
||||
"description": "add service label",
|
||||
"consumes": [
|
||||
"application/json",
|
||||
"application/x-protobuf"
|
||||
@ -4912,7 +4940,7 @@
|
||||
},
|
||||
"/v2/tenants/{tenant_name}/services/{service_alias}/start": {
|
||||
"post": {
|
||||
"description": "start service **完成",
|
||||
"description": "start service",
|
||||
"consumes": [
|
||||
"application/json",
|
||||
"application/x-protobuf"
|
||||
@ -5010,7 +5038,7 @@
|
||||
},
|
||||
"/v2/tenants/{tenant_name}/services/{service_alias}/stop": {
|
||||
"post": {
|
||||
"description": "stop service **完成",
|
||||
"description": "stop service",
|
||||
"consumes": [
|
||||
"application/json",
|
||||
"application/x-protobuf"
|
||||
@ -5066,7 +5094,7 @@
|
||||
},
|
||||
"/v2/tenants/{tenant_name}/services/{service_alias}/upgrade": {
|
||||
"post": {
|
||||
"description": "upgrade service **完成",
|
||||
"description": "upgrade service",
|
||||
"consumes": [
|
||||
"application/json",
|
||||
"application/x-protobuf"
|
||||
@ -5137,7 +5165,7 @@
|
||||
},
|
||||
"/v2/tenants/{tenant_name}/services/{service_alias}/vertical": {
|
||||
"put": {
|
||||
"description": "service vertical **完成",
|
||||
"description": "service vertical",
|
||||
"consumes": [
|
||||
"application/json",
|
||||
"application/x-protobuf"
|
||||
@ -5205,7 +5233,7 @@
|
||||
},
|
||||
"/v2/tenants/{tenant_name}/services/{service_alias}/volume": {
|
||||
"post": {
|
||||
"description": "add volume **完成",
|
||||
"description": "add volume",
|
||||
"consumes": [
|
||||
"application/json",
|
||||
"application/x-protobuf"
|
||||
@ -5274,7 +5302,7 @@
|
||||
}
|
||||
},
|
||||
"delete": {
|
||||
"description": "delete volume **完成",
|
||||
"description": "delete volume",
|
||||
"consumes": [
|
||||
"application/json",
|
||||
"application/x-protobuf"
|
||||
@ -5339,7 +5367,7 @@
|
||||
},
|
||||
"/v2/tenants/{tenant_name}/services/{service_alias}/volume-dependency": {
|
||||
"post": {
|
||||
"description": "add volume dependency **完成",
|
||||
"description": "add volume dependency",
|
||||
"consumes": [
|
||||
"application/json",
|
||||
"application/x-protobuf"
|
||||
@ -5408,7 +5436,7 @@
|
||||
}
|
||||
},
|
||||
"delete": {
|
||||
"description": "delete volume dependency **完成",
|
||||
"description": "delete volume dependency",
|
||||
"consumes": [
|
||||
"application/json",
|
||||
"application/x-protobuf"
|
||||
@ -5507,7 +5535,7 @@
|
||||
}
|
||||
},
|
||||
"post": {
|
||||
"description": "add volume **完成",
|
||||
"description": "add volume",
|
||||
"consumes": [
|
||||
"application/json",
|
||||
"application/x-protobuf"
|
||||
@ -5584,7 +5612,7 @@
|
||||
},
|
||||
"/v2/tenants/{tenant_name}/services/{service_alias}/volumes/{volume_name}": {
|
||||
"delete": {
|
||||
"description": "delete volume **完成",
|
||||
"description": "delete volume",
|
||||
"consumes": [
|
||||
"application/json",
|
||||
"application/x-protobuf"
|
||||
@ -6028,11 +6056,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 +6212,7 @@
|
||||
"x-go-name": "EnvName"
|
||||
},
|
||||
"env_value": {
|
||||
"type": "string",
|
||||
"type": "object",
|
||||
"x-go-name": "EnvVal"
|
||||
}
|
||||
},
|
||||
|
@ -90,6 +90,17 @@ class AppImage():
|
||||
if self.region_registry.exist_image(image):
|
||||
logger.debug("mq_work.app_image",
|
||||
"now local exists, oss doesnot exists")
|
||||
data = {
|
||||
'service_key': service_key,
|
||||
'app_version': app_version,
|
||||
'image': image,
|
||||
'dest_yb': True,
|
||||
'dest_ys': False,
|
||||
'slug': ""
|
||||
}
|
||||
if share_id is not None:
|
||||
data["share_id"] = share_id
|
||||
self.region_client.service_publish_new_region(data)
|
||||
if self.is_region_image and not self.oss_registry.exist_image(
|
||||
oss_image):
|
||||
try:
|
||||
@ -100,6 +111,8 @@ class AppImage():
|
||||
"拉取镜像发生错误,构建退出。",
|
||||
step="callback",
|
||||
status="failure")
|
||||
|
||||
self.region_client.service_publish_failure_region(data)
|
||||
return
|
||||
image_id = self.get_image_property(image, 'Id')
|
||||
self.log.info("拉取镜像完成。")
|
||||
@ -111,46 +124,57 @@ class AppImage():
|
||||
"拉取镜像发生错误,构建退出。",
|
||||
step="callback",
|
||||
status="failure")
|
||||
|
||||
self.region_client.service_publish_failure_region(data)
|
||||
return
|
||||
self.log.info("上传镜像到云帮完成")
|
||||
# 发送通知到web
|
||||
data = {
|
||||
'service_key': service_key,
|
||||
'app_version': app_version,
|
||||
'image': image,
|
||||
'dest_yb': True
|
||||
}
|
||||
if share_id is not None:
|
||||
data["share_id"] = share_id
|
||||
self.user_cs_client.service_publish_success(
|
||||
json.dumps(data))
|
||||
try:
|
||||
self.region_client.service_publish_success_region(json.dumps(data))
|
||||
except Exception as e:
|
||||
logger.exception(e)
|
||||
self.region_client.service_publish_failure_region(data)
|
||||
pass
|
||||
|
||||
self.log.info(
|
||||
"云帮应用发布完毕", step="last", status="success")
|
||||
except (shell.ExecException, Exception), e:
|
||||
logger.exception("mq_work.app_image", e)
|
||||
logger.error("mq_work.app_image", e)
|
||||
|
||||
self.region_client.service_publish_failure_region(data)
|
||||
self.log.error(
|
||||
"云帮应用发布失败 {}".format(e.message),
|
||||
step="callback",
|
||||
status="failure")
|
||||
else:
|
||||
# 发送通知到web
|
||||
data = {
|
||||
'service_key': service_key,
|
||||
'app_version': app_version,
|
||||
'image': image,
|
||||
'dest_yb': True
|
||||
}
|
||||
if share_id is not None:
|
||||
data["share_id"] = share_id
|
||||
self.user_cs_client.service_publish_success(
|
||||
json.dumps(data))
|
||||
try:
|
||||
self.region_client.service_publish_success_region(json.dumps(data))
|
||||
except Exception as e:
|
||||
self.region_client.service_publish_failure_region(data)
|
||||
logger.exception(e)
|
||||
pass
|
||||
|
||||
self.log.info("云帮应用发布完毕", step="last", status="success")
|
||||
elif dest == "ys":
|
||||
# 当前有镜像并且云市的image数据中心开启
|
||||
if self.region_registry.exist_image(image) and self.is_oss_image:
|
||||
req = {
|
||||
'service_key': service_key,
|
||||
'app_version': app_version,
|
||||
'image': image,
|
||||
'slug': "",
|
||||
'dest_ys': True,
|
||||
'dest_yb': False
|
||||
}
|
||||
if share_id is not None:
|
||||
req["share_id"] = share_id
|
||||
self.region_client.service_publish_new_region(req)
|
||||
self.log.info("开始上传镜像到云市")
|
||||
# 修改image name
|
||||
hub_image = self.hubclient.rename_image(image)
|
||||
@ -171,6 +195,7 @@ class AppImage():
|
||||
"拉取镜像发生错误,构建退出。",
|
||||
step="callback",
|
||||
status="failure")
|
||||
self.region_client.service_publish_failure_region(req)
|
||||
return
|
||||
image_id = self.get_image_property(image, 'Id')
|
||||
self.log.info("从云帮拉取镜像完成,更改镜像TAG")
|
||||
@ -182,24 +207,24 @@ class AppImage():
|
||||
"拉取镜像发生错误,构建退出。",
|
||||
step="callback",
|
||||
status="failure")
|
||||
self.region_client.service_publish_failure_region(req)
|
||||
return
|
||||
self.log.info("上传镜像到云市完成。")
|
||||
# 发送通知到web
|
||||
data = {
|
||||
'service_key': service_key,
|
||||
'app_version': app_version,
|
||||
'image': image,
|
||||
'dest_ys': True
|
||||
}
|
||||
if share_id is not None:
|
||||
data["share_id"] = share_id
|
||||
self.user_cs_client.service_publish_success(
|
||||
json.dumps(data))
|
||||
self.region_client.service_publish_success_region(json.dumps(data))
|
||||
json.dumps(req))
|
||||
try:
|
||||
self.region_client.service_publish_success_region(json.dumps(req))
|
||||
except Exception as e:
|
||||
self.region_client.service_publish_failure_region(req)
|
||||
logger.exception(e)
|
||||
pass
|
||||
|
||||
self.log.info("云市应用发布完毕", step="last", status="success")
|
||||
except (shell.ExecException, Exception), e:
|
||||
logger.exception("mq_work.app_image", e)
|
||||
logger.error("mq_work.app_image", e)
|
||||
self.region_client.service_publish_failure_region(req)
|
||||
self.log.error(
|
||||
"云市应用发布失败 {}".format(e.message),
|
||||
step="callback",
|
||||
|
@ -28,11 +28,11 @@ class AppSlug():
|
||||
self.job = job
|
||||
self.configs = kwargs.get("config")
|
||||
self.region_api = RegionAPI(conf=self.configs['region'])
|
||||
self.region_client = RegionBackAPI()
|
||||
self.oss_api = OssAPI(conf=self.configs['oss']['ali_shanghai'])
|
||||
self.locker = TaskLocker(conf=self.configs['etcd'])
|
||||
self.user_cs_client = UserConsoleAPI(conf=self.configs['userconsole'])
|
||||
self.api = ACPAPI(conf=self.configs['region'])
|
||||
self.region_client = RegionBackAPI()
|
||||
self.slug_configs = self.configs["publish"]["slug"]
|
||||
self.is_region_slug = self.slug_configs.get('all_region_ftp')
|
||||
self.is_oss_ftp = self.slug_configs.get('oss_ftp')
|
||||
@ -168,6 +168,17 @@ class AppSlug():
|
||||
slug = self.SLUG_PATH.format(
|
||||
serviceKey=service_key, appVersion=app_version)
|
||||
if dest == "yb":
|
||||
data = {
|
||||
'service_key': service_key,
|
||||
'app_version': app_version,
|
||||
'slug': slug,
|
||||
'image': "",
|
||||
'dest_yb': True,
|
||||
'dest_ys': False,
|
||||
}
|
||||
if share_id is not None:
|
||||
data['share_id'] = share_id
|
||||
self.region_client.service_publish_new_region(data)
|
||||
if self.is_region_slug:
|
||||
try:
|
||||
self.log.info("开始上传应用到本地云帮")
|
||||
@ -176,39 +187,49 @@ class AppSlug():
|
||||
"*******ftp upload success!")
|
||||
# self.update_publish_event(event_id=event_id, status='end', desc=u"云帮应用本地发布完毕")
|
||||
|
||||
data = {
|
||||
'service_key': service_key,
|
||||
'app_version': app_version,
|
||||
'slug': slug,
|
||||
'dest_yb': True
|
||||
}
|
||||
if share_id is not None:
|
||||
data['share_id'] = share_id
|
||||
|
||||
self.user_cs_client.service_publish_success(
|
||||
json.dumps(data))
|
||||
try:
|
||||
self.region_client.service_publish_success_region(json.dumps(data))
|
||||
except Exception as e:
|
||||
self.region_client.service_publish_failure_region(data)
|
||||
logger.exception(e)
|
||||
pass
|
||||
|
||||
self.log.info("云帮应用本地发布完毕", step="last", status="success")
|
||||
except Exception as e:
|
||||
logger.error("mq_work.app_slug",
|
||||
"*******ftp upload failed")
|
||||
logger.exception("mq_work.app_slug", e)
|
||||
self.region_client.service_publish_failure_region(data)
|
||||
self.log.info(
|
||||
"云帮应用本地发布失败。{}".format(e.message),
|
||||
step="callback",
|
||||
status="failure")
|
||||
else:
|
||||
|
||||
self.user_cs_client.service_publish_success(json.dumps(data))
|
||||
try:
|
||||
self.region_client.service_publish_success_region(json.dumps(data))
|
||||
except Exception as e:
|
||||
self.region_client.service_publish_failure_region(data)
|
||||
logger.exception(e)
|
||||
pass
|
||||
|
||||
self.log.info("云帮应用本地发布完毕", step="last", status="success")
|
||||
elif dest == "ys":
|
||||
data = {
|
||||
'service_key': service_key,
|
||||
'app_version': app_version,
|
||||
'slug': slug,
|
||||
'dest_yb': True
|
||||
'image': "",
|
||||
'dest_ys': True,
|
||||
'dest_yb': False
|
||||
}
|
||||
if share_id is not None:
|
||||
data['share_id'] = share_id
|
||||
self.user_cs_client.service_publish_success(json.dumps(data))
|
||||
self.region_client.service_publish_success_region(json.dumps(data))
|
||||
self.log.info("云帮应用本地发布完毕", step="last", status="success")
|
||||
elif dest == "ys":
|
||||
self.region_client.service_publish_new_region(data)
|
||||
if self.is_oss_ftp:
|
||||
try:
|
||||
self.log.info("开始上传应用到云市")
|
||||
@ -216,33 +237,31 @@ class AppSlug():
|
||||
logger.debug("mq_work.app_slug",
|
||||
"*******ftp upload success!")
|
||||
self.log.info("云市应用发布完毕", step="last", status="success")
|
||||
data = {
|
||||
'service_key': service_key,
|
||||
'app_version': app_version,
|
||||
'slug': slug,
|
||||
'dest_ys': True
|
||||
}
|
||||
if share_id is not None:
|
||||
data['share_id'] = share_id
|
||||
|
||||
self.user_cs_client.service_publish_success(
|
||||
json.dumps(data))
|
||||
try:
|
||||
self.region_client.service_publish_success_region(json.dumps(data))
|
||||
except Exception as e:
|
||||
logger.exception(e)
|
||||
self.region_client.service_publish_failure_region(data)
|
||||
pass
|
||||
|
||||
except Exception as e:
|
||||
logger.error("mq_work.app_slug",
|
||||
"*******ftp upload failed, {0}".format(e))
|
||||
self.region_client.service_publish_failure_region(data)
|
||||
self.log.error(
|
||||
"云市应用发布失败.", status="failure", step="callback")
|
||||
else:
|
||||
data = {
|
||||
'service_key': service_key,
|
||||
'app_version': app_version,
|
||||
'slug': slug,
|
||||
'dest_ys': True
|
||||
}
|
||||
if share_id is not None:
|
||||
data['share_id'] = share_id
|
||||
self.user_cs_client.service_publish_success(json.dumps(data))
|
||||
try:
|
||||
self.region_client.service_publish_success_region(json.dumps(data))
|
||||
except Exception as e:
|
||||
logger.exception(e)
|
||||
self.region_client.service_publish_failure_region(data)
|
||||
pass
|
||||
|
||||
self.log.info("云市应用发布完毕", step="last", status="success")
|
||||
|
||||
def _download_ftp(self, service_key, app_version, namespace, is_md5=False):
|
||||
|
@ -330,7 +330,7 @@ class RepoBuilder():
|
||||
h = self.user_cs_client
|
||||
try:
|
||||
h.update_service(self.service_id, json.dumps(update_items))
|
||||
self.region_client.updte_service_region(self.service_id,json.dumps(update_items))
|
||||
self.region_client.update_service_region(self.service_id,json.dumps(update_items))
|
||||
except h.CallApiError, e:
|
||||
self.log.error(
|
||||
"网络异常,更新应用镜像名称失败. {}".format(e.message),
|
||||
|
@ -11,5 +11,5 @@ from oss.oss_api import OssAPI as API
|
||||
class OssAPI(API):
|
||||
|
||||
def __init__(self, conf, *args, **kwargs):
|
||||
API.__init__(self, conf.endpoint, conf.id, conf.secret)
|
||||
API.__init__(self, conf["endpoint"], conf["id"], conf["secret"])
|
||||
self.timeout = 90
|
||||
|
@ -1,5 +1,6 @@
|
||||
import logging
|
||||
import os
|
||||
import json
|
||||
from _base import BaseHttpClient
|
||||
|
||||
logger = logging.getLogger('default')
|
||||
@ -18,9 +19,24 @@ class RegionBackAPI(BaseHttpClient):
|
||||
def service_publish_success_region(self, body):
|
||||
# url = self.base_url + '/api/tenants/services/publish'
|
||||
url = self.base_url+ '/publish'
|
||||
body["status"]="success"
|
||||
logger.info("publish app to ys?{}".format(body["dest_ys"]))
|
||||
res, body = self._post(url, self.default_headers, body)
|
||||
return res, body
|
||||
|
||||
def service_publish_failure_region(self, body):
|
||||
# url = self.base_url + '/api/tenants/services/publish'
|
||||
url = self.base_url+ '/publish'
|
||||
body["status"]="failure"
|
||||
logger.info("publish app to ys?{}".format(body["dest_ys"]))
|
||||
res, body = self._post(url, self.default_headers, json.dumps(body))
|
||||
return res, body
|
||||
def service_publish_new_region(self, body):
|
||||
# url = self.base_url + '/api/tenants/services/publish'
|
||||
url = self.base_url+ '/publish'
|
||||
body["status"]="pushing"
|
||||
logger.info("publish app to ys?{}".format(body["dest_ys"]))
|
||||
res, body = self._post(url, self.default_headers, json.dumps(body))
|
||||
return res, body
|
||||
def code_check_region(self, body):
|
||||
|
||||
# url = self.base_url + '/api/tenants/services/codecheck'
|
||||
|
@ -1,8 +1,9 @@
|
||||
#!/bin/sh
|
||||
set -e
|
||||
|
||||
if [ -f "/usr/share/gr-rainbond-node/gaops/gaops.tgz" ];then
|
||||
tar xf /usr/share/gr-rainbond-node/gaops/gaops.tgz -C /usr/share/gr-rainbond-node/gaops/
|
||||
if [ -f "/usr/share/gr-rainbond-node/gaops.tgz" ];then
|
||||
mkdir -p /usr/share/gr-rainbond-node/gaops/
|
||||
tar xf /usr/share/gr-rainbond-node/gaops.tgz -C /usr/share/gr-rainbond-node/gaops/
|
||||
fi
|
||||
|
||||
case "$1" in
|
||||
|
@ -37,9 +37,11 @@ install -p -m 755 usr/share/gr-rainbond-node/gaops/gaops.tgz %{buildroot}/usr/sh
|
||||
echo "NODE_TYPE=compute" >> /etc/goodrain/envs/rainbond-node.sh
|
||||
else
|
||||
echo "NODE_TYPE=" >> /etc/goodrain/envs/rainbond-node.sh
|
||||
echo "ROLE=manage" >> /etc/goodrain/envs/rainbond-node.sh
|
||||
fi
|
||||
) || (
|
||||
echo "NODE_TYPE=" >> /etc/goodrain/envs/rainbond-node.sh
|
||||
echo "ROLE=manage" >> /etc/goodrain/envs/rainbond-node.sh
|
||||
)
|
||||
|
||||
|
||||
|
@ -1,15 +1,16 @@
|
||||
#!/bin/sh
|
||||
|
||||
ETCD_ADDR=$(cat /etc/goodrain/envs/etcd.sh | awk -F '=' '{print $2}')
|
||||
HOSTIP=$(cat /etc/goodrain/envs/ip.sh | awk -F '=' '{print $2}')
|
||||
|
||||
if [ -z $NODE_TYPE ];then
|
||||
eval $(ssh-agent) > /dev/null
|
||||
eval $(ssh-add) > /dev/null
|
||||
#eval $(ssh-add /path/key) > /dev/null
|
||||
ACP_NODE_OPTS="--static-task-path=/usr/share/gr-rainbond-node/gaops/tasks/ --etcd=http://$ETCD_ADDR:2379 --kube-conf=/etc/goodrain/kubernetes/kubeconfig --hostIP=$HOSTIP --run-mode master --noderule manage,compute"
|
||||
ETCD_ADDR=$(cat /etc/goodrain/envs/etcd.sh | awk -F '=' '{print $2}')
|
||||
ACP_NODE_OPTS="--log-level=debug --static-task-path=/usr/share/gr-rainbond-node/gaops/tasks/ --etcd=http://$ETCD_ADDR:2379 --kube-conf=/etc/goodrain/kubernetes/kubeconfig --hostIP=$HOSTIP --run-mode master --noderule ${ROLE:-manage}"
|
||||
else
|
||||
ACP_NODE_OPTS='--log-level=debug'
|
||||
|
||||
ACP_NODE_OPTS="--log-level=debug --static-task-path=/usr/share/gr-rainbond-node/gaops/tasks/ --etcd=http://127.0.0.1:2379 --kube-conf=/etc/goodrain/kubernetes/kubeconfig --hostIP=$HOSTIP"
|
||||
fi
|
||||
|
||||
exec /usr/local/bin/rainbond-node $ACP_NODE_OPTS
|
@ -39,6 +39,7 @@ type ServiceInterface interface {
|
||||
SingleServiceInfo(w http.ResponseWriter, r *http.Request)
|
||||
CheckCode(w http.ResponseWriter, r *http.Request)
|
||||
ShareCloud(w http.ResponseWriter, r *http.Request)
|
||||
Event(w http.ResponseWriter, r *http.Request)
|
||||
BuildList(w http.ResponseWriter, r *http.Request)
|
||||
CreateService(w http.ResponseWriter, r *http.Request)
|
||||
UpdateService(w http.ResponseWriter, r *http.Request)
|
||||
|
@ -75,6 +75,8 @@ func (v2 *V2) tenantNameRouter() chi.Router {
|
||||
r.Mount("/services/{service_alias}", v2.serviceRouter())
|
||||
r.Mount("/plugin/{plugin_id}", v2.pluginRouter())
|
||||
r.Mount("/sources", v2.defineSourcesRouter())
|
||||
r.Get("/event", controller.GetManager().Event)
|
||||
|
||||
return r
|
||||
}
|
||||
|
||||
|
56
pkg/api/controller/event.go
Normal file
56
pkg/api/controller/event.go
Normal file
@ -0,0 +1,56 @@
|
||||
package controller
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
|
||||
"github.com/Sirupsen/logrus"
|
||||
"github.com/bitly/go-simplejson"
|
||||
"github.com/goodrain/rainbond/pkg/db"
|
||||
dbmodel "github.com/goodrain/rainbond/pkg/db/model"
|
||||
httputil "github.com/goodrain/rainbond/pkg/util/http"
|
||||
)
|
||||
|
||||
//Events GetLogs
|
||||
func (e *TenantStruct) Event(w http.ResponseWriter, r *http.Request) {
|
||||
// swagger:operation GET /v2/tenants/{tenant_name}/event v2 get events
|
||||
//
|
||||
// 获取指定event_ids详细信息
|
||||
//
|
||||
// get events
|
||||
//
|
||||
// ---
|
||||
// produces:
|
||||
// - application/json
|
||||
// - application/xml
|
||||
//
|
||||
// responses:
|
||||
// default:
|
||||
// schema:
|
||||
// "$ref": "#/responses/commandResponse"
|
||||
// description: 统一返回格式
|
||||
b, _ := ioutil.ReadAll(r.Body)
|
||||
defer r.Body.Close()
|
||||
j, err := simplejson.NewJson(b)
|
||||
if err != nil {
|
||||
logrus.Errorf("error decode json,details %s", err.Error())
|
||||
httputil.ReturnError(r, w, 400, "bad request")
|
||||
return
|
||||
}
|
||||
eventIDS, err := j.Get("event_ids").StringArray()
|
||||
if err != nil {
|
||||
logrus.Errorf("error get event_id in json,details %s", err.Error())
|
||||
httputil.ReturnError(r, w, 400, "bad request")
|
||||
return
|
||||
}
|
||||
result := []*dbmodel.ServiceEvent{}
|
||||
for _, v := range eventIDS {
|
||||
serviceEvent, err := db.GetManager().ServiceEventDao().GetEventByEventID(v)
|
||||
if err != nil {
|
||||
logrus.Warnf("can't find event by given id %s ,details %s", v, err.Error())
|
||||
continue
|
||||
}
|
||||
result = append(result, serviceEvent)
|
||||
}
|
||||
httputil.ReturnSuccess(r, w, result)
|
||||
}
|
@ -1,4 +1,3 @@
|
||||
|
||||
// RAINBOND, Application Management Platform
|
||||
// Copyright (C) 2014-2017 Goodrain Co., Ltd.
|
||||
|
||||
@ -20,11 +19,12 @@
|
||||
package controller
|
||||
|
||||
import (
|
||||
httputil "github.com/goodrain/rainbond/pkg/util/http"
|
||||
"net/http"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
httputil "github.com/goodrain/rainbond/pkg/util/http"
|
||||
|
||||
"github.com/Sirupsen/logrus"
|
||||
"github.com/go-chi/chi"
|
||||
|
||||
@ -40,7 +40,7 @@ type EventLogStruct struct{}
|
||||
func (e *EventLogStruct) Logs(w http.ResponseWriter, r *http.Request) {
|
||||
// swagger:operation POST /v2/tenants/{tenant_name}/services/{service_alias}/log v2 lastLinesLogs
|
||||
//
|
||||
// 获取最新指定数量条日志 **完成
|
||||
// 获取最新指定数量条日志
|
||||
//
|
||||
// get last x lines logs
|
||||
//
|
||||
@ -77,7 +77,7 @@ func (e *EventLogStruct) Logs(w http.ResponseWriter, r *http.Request) {
|
||||
func (e *EventLogStruct) LogList(w http.ResponseWriter, r *http.Request) {
|
||||
// swagger:operation GET /v2/tenants/{tenant_name}/services/{service_alias}/log-file v2 logList
|
||||
//
|
||||
// 获取应用日志列表 **完成
|
||||
// 获取应用日志列表
|
||||
//
|
||||
// get log list
|
||||
//
|
||||
@ -109,7 +109,7 @@ func (e *EventLogStruct) LogList(w http.ResponseWriter, r *http.Request) {
|
||||
func (e *EventLogStruct) LogFile(w http.ResponseWriter, r *http.Request) {
|
||||
// swagger:operation GET /v2/tenants/{tenant_name}/services/{service_alias}/log-file/{file_name} v2 logFile
|
||||
//
|
||||
// 下载应用指定日志 **完成
|
||||
// 下载应用指定日志
|
||||
//
|
||||
// get log file
|
||||
//
|
||||
@ -143,7 +143,7 @@ func (e *EventLogStruct) LogFile(w http.ResponseWriter, r *http.Request) {
|
||||
func (e *EventLogStruct) LogSocket(w http.ResponseWriter, r *http.Request) {
|
||||
// swagger:operation GET /v2/tenants/{tenant_name}/services/{service_alias}/log-instance v2 logSocket
|
||||
//
|
||||
// 获取应用日志web-socket实例 **完成
|
||||
// 获取应用日志web-socket实例
|
||||
//
|
||||
// get log socket
|
||||
//
|
||||
@ -173,7 +173,7 @@ func (e *EventLogStruct) LogSocket(w http.ResponseWriter, r *http.Request) {
|
||||
func (e *EventLogStruct) LogByAction(w http.ResponseWriter, r *http.Request) {
|
||||
// swagger:operation POST /v2/tenants/{tenant_name}/services/{service_alias}/event-log v2 logByAction
|
||||
//
|
||||
// 获取指定操作的操作日志 **完成
|
||||
// 获取指定操作的操作日志
|
||||
//
|
||||
// get log by level
|
||||
//
|
||||
|
@ -104,7 +104,7 @@ func (t *TenantStruct) AllTenantResources(w http.ResponseWriter, r *http.Request
|
||||
func (t *TenantStruct) TenantResources(w http.ResponseWriter, r *http.Request) {
|
||||
// swagger:operation POST /v2/resources/tenants v2 tenantResources
|
||||
//
|
||||
// 租户资源使用情况 **完成
|
||||
// 租户资源使用情况
|
||||
//
|
||||
// get tenant resources
|
||||
//
|
||||
@ -136,7 +136,7 @@ func (t *TenantStruct) TenantResources(w http.ResponseWriter, r *http.Request) {
|
||||
func (t *TenantStruct) SumTenants(w http.ResponseWriter, r *http.Request) {
|
||||
// swagger:operation GET /v2/resources/tenants/sum v2 sumTenants
|
||||
//
|
||||
// 获取租户数量 **完成
|
||||
// 获取租户数量
|
||||
//
|
||||
// get tenant resources
|
||||
//
|
||||
@ -173,7 +173,7 @@ func (t *TenantStruct) Tenant(w http.ResponseWriter, r *http.Request) {
|
||||
func (t *TenantStruct) AddTenant(w http.ResponseWriter, r *http.Request) {
|
||||
// swagger:operation POST /v2/tenants v2 addTenant
|
||||
//
|
||||
// 添加租户信息 **完成
|
||||
// 添加租户信息
|
||||
//
|
||||
// add tenant
|
||||
//
|
||||
@ -262,7 +262,7 @@ func (t *TenantStruct) ServicesInfo(w http.ResponseWriter, r *http.Request) {
|
||||
//
|
||||
// 获取租户所有应用信息
|
||||
//
|
||||
// get services info in tenant **完成
|
||||
// get services info in tenant
|
||||
//
|
||||
// ---
|
||||
// consumes:
|
||||
@ -294,7 +294,7 @@ func (t *TenantStruct) CreateService(w http.ResponseWriter, r *http.Request) {
|
||||
//
|
||||
// 创建应用
|
||||
//
|
||||
// create service **完成
|
||||
// create service
|
||||
//
|
||||
// ---
|
||||
// consumes:
|
||||
@ -341,7 +341,7 @@ func (t *TenantStruct) UpdateService(w http.ResponseWriter, r *http.Request) {
|
||||
//
|
||||
// 应用更新
|
||||
//
|
||||
// update service **完成
|
||||
// update service
|
||||
//
|
||||
// ---
|
||||
// consumes:
|
||||
@ -387,7 +387,7 @@ func (t *TenantStruct) SetLanguage(w http.ResponseWriter, r *http.Request) {
|
||||
//
|
||||
// 设置应用语言
|
||||
//
|
||||
// set language **完成
|
||||
// set language
|
||||
//
|
||||
// ---
|
||||
// consumes:
|
||||
@ -521,7 +521,7 @@ func (t *TenantStruct) AddServiceLabel(w http.ResponseWriter, r *http.Request) {
|
||||
//
|
||||
// 添加应用标签
|
||||
//
|
||||
// add service label **完成
|
||||
// add service label
|
||||
//
|
||||
// ---
|
||||
// consumes:
|
||||
@ -560,7 +560,7 @@ func (t *TenantStruct) UpdateServiceLabel(w http.ResponseWriter, r *http.Request
|
||||
//
|
||||
// 更新应用标签
|
||||
//
|
||||
// delete service label **完成
|
||||
// delete service label
|
||||
//
|
||||
// ---
|
||||
// consumes:
|
||||
@ -608,7 +608,7 @@ func (t *TenantStruct) AddNodeLabel(w http.ResponseWriter, r *http.Request) {
|
||||
//
|
||||
// 添加节点标签
|
||||
//
|
||||
// add node label **完成
|
||||
// add node label
|
||||
//
|
||||
// ---
|
||||
// consumes:
|
||||
@ -646,7 +646,7 @@ func (t *TenantStruct) DeleteNodeLabel(w http.ResponseWriter, r *http.Request) {
|
||||
//
|
||||
// 删除节点标签
|
||||
//
|
||||
// delete node label **完成
|
||||
// delete node label
|
||||
//
|
||||
// ---
|
||||
// consumes:
|
||||
@ -699,7 +699,7 @@ func (t *TenantStruct) GetSingleServiceInfo(w http.ResponseWriter, r *http.Reque
|
||||
//
|
||||
// 获取应用信息
|
||||
//
|
||||
// get service info **完成
|
||||
// get service info
|
||||
//
|
||||
// ---
|
||||
// consumes:
|
||||
@ -777,7 +777,7 @@ func (t *TenantStruct) Dependency(w http.ResponseWriter, r *http.Request) {
|
||||
//
|
||||
// 增加应用依赖关系
|
||||
//
|
||||
// add dependency **完成
|
||||
// add dependency
|
||||
//
|
||||
// ---
|
||||
// consumes:
|
||||
@ -821,7 +821,7 @@ func (t *TenantStruct) AddDependency(w http.ResponseWriter, r *http.Request) {
|
||||
//
|
||||
// 删除应用依赖关系
|
||||
//
|
||||
// delete dependency **完成
|
||||
// delete dependency
|
||||
//
|
||||
// ---
|
||||
// consumes:
|
||||
@ -875,7 +875,7 @@ func (t *TenantStruct) Env(w http.ResponseWriter, r *http.Request) {
|
||||
//
|
||||
// 增加环境变量
|
||||
//
|
||||
// add env var **完成
|
||||
// add env var
|
||||
//
|
||||
// ---
|
||||
// consumes:
|
||||
@ -920,7 +920,7 @@ func (t *TenantStruct) AddEnv(w http.ResponseWriter, r *http.Request) {
|
||||
//
|
||||
// 删除环境变量
|
||||
//
|
||||
// delete env var **完成
|
||||
// delete env var
|
||||
//
|
||||
// ---
|
||||
// consumes:
|
||||
@ -983,7 +983,7 @@ func (t *TenantStruct) Ports(w http.ResponseWriter, r *http.Request) {
|
||||
//
|
||||
// 增加应用端口,默认关闭对内和对外选项,需要开启使用相应接口
|
||||
//
|
||||
// add port **完成
|
||||
// add port
|
||||
//
|
||||
// ---
|
||||
// consumes:
|
||||
@ -1019,7 +1019,7 @@ func (t *TenantStruct) addPortController(w http.ResponseWriter, r *http.Request)
|
||||
//
|
||||
// 更新应用端口信息
|
||||
//
|
||||
// update port **完成
|
||||
// update port
|
||||
//
|
||||
// ---
|
||||
// consumes:
|
||||
@ -1055,7 +1055,7 @@ func (t *TenantStruct) updatePortController(w http.ResponseWriter, r *http.Reque
|
||||
//
|
||||
// 开关端口对外服务,应用无需重启自动生效
|
||||
//
|
||||
// add port **完成
|
||||
// add port
|
||||
//
|
||||
// ---
|
||||
// Consumes:
|
||||
@ -1119,7 +1119,7 @@ func (t *TenantStruct) PortOuterController(w http.ResponseWriter, r *http.Reques
|
||||
//
|
||||
// 开关对内服务,应用无需重启,自动生效
|
||||
//
|
||||
// add port **完成
|
||||
// add port
|
||||
//
|
||||
// ---
|
||||
// Consumes:
|
||||
@ -1168,7 +1168,7 @@ func (t *TenantStruct) PortInnerController(w http.ResponseWriter, r *http.Reques
|
||||
//
|
||||
// 删除端口变量
|
||||
//
|
||||
// delete port **完成
|
||||
// delete port
|
||||
//
|
||||
// ---
|
||||
// Consumes:
|
||||
@ -1216,7 +1216,7 @@ func (t *TenantStruct) deletePortController(w http.ResponseWriter, r *http.Reque
|
||||
//
|
||||
// 获取pods信息
|
||||
//
|
||||
// get pods info **完成
|
||||
// get pods info
|
||||
//
|
||||
// ---
|
||||
// consumes:
|
||||
@ -1264,7 +1264,7 @@ func (t *TenantStruct) AddProbe(w http.ResponseWriter, r *http.Request) {
|
||||
//
|
||||
// 增加应用探针
|
||||
//
|
||||
// add probe **完成
|
||||
// add probe
|
||||
//
|
||||
// ---
|
||||
// consumes:
|
||||
@ -1315,7 +1315,7 @@ func (t *TenantStruct) UpdateProbe(w http.ResponseWriter, r *http.Request) {
|
||||
//
|
||||
// 更新应用探针信息, *注意此处为全量更新
|
||||
//
|
||||
// update probe ** 完成
|
||||
// update probe
|
||||
//
|
||||
// ---
|
||||
// consumes:
|
||||
@ -1371,7 +1371,7 @@ func (t *TenantStruct) DeleteProbe(w http.ResponseWriter, r *http.Request) {
|
||||
//
|
||||
// 删除应用探针
|
||||
//
|
||||
// delete probe **完成
|
||||
// delete probe
|
||||
//
|
||||
// ---
|
||||
// consumes:
|
||||
@ -1436,7 +1436,7 @@ func (t *TenantStruct) UpdatePort(w http.ResponseWriter, r *http.Request) {
|
||||
func (t *TenantStruct) SingleTenantResources(w http.ResponseWriter, r *http.Request) {
|
||||
// swagger:operation GET /v2/tenants/{tenant_name}/resources v2 singletenantResources
|
||||
//
|
||||
// 指定租户资源使用情况 **完成
|
||||
// 指定租户资源使用情况
|
||||
//
|
||||
// get tenant resources
|
||||
//
|
||||
|
@ -201,7 +201,7 @@ func handleStatus(status int, err error, w http.ResponseWriter, r *http.Request)
|
||||
//
|
||||
// 启动应用
|
||||
//
|
||||
// start service **完成
|
||||
// start service
|
||||
//
|
||||
// ---
|
||||
// consumes:
|
||||
@ -259,7 +259,7 @@ func (t *TenantStruct) StartService(w http.ResponseWriter, r *http.Request) {
|
||||
//
|
||||
// 关闭应用
|
||||
//
|
||||
// stop service **完成
|
||||
// stop service
|
||||
//
|
||||
// ---
|
||||
// consumes:
|
||||
@ -311,7 +311,7 @@ func (t *TenantStruct) StopService(w http.ResponseWriter, r *http.Request) {
|
||||
//
|
||||
// 重启应用
|
||||
//
|
||||
// restart service **完成
|
||||
// restart service
|
||||
//
|
||||
// ---
|
||||
// consumes:
|
||||
@ -364,7 +364,7 @@ func (t *TenantStruct) RestartService(w http.ResponseWriter, r *http.Request) {
|
||||
//
|
||||
// 应用垂直伸缩
|
||||
//
|
||||
// service vertical **完成
|
||||
// service vertical
|
||||
//
|
||||
// ---
|
||||
// consumes:
|
||||
@ -421,7 +421,7 @@ func (t *TenantStruct) VerticalService(w http.ResponseWriter, r *http.Request) {
|
||||
//
|
||||
// 应用水平伸缩
|
||||
//
|
||||
// service horizontal **完成
|
||||
// service horizontal
|
||||
//
|
||||
// ---
|
||||
// consumes:
|
||||
@ -474,7 +474,7 @@ func (t *TenantStruct) HorizontalService(w http.ResponseWriter, r *http.Request)
|
||||
//
|
||||
// 应用构建
|
||||
//
|
||||
// service build **完成
|
||||
// service build
|
||||
//
|
||||
// ---
|
||||
// consumes:
|
||||
@ -558,7 +558,7 @@ func (t *TenantStruct) DeployService(w http.ResponseWriter, r *http.Request) {
|
||||
//
|
||||
// 升级应用
|
||||
//
|
||||
// upgrade service **完成
|
||||
// upgrade service
|
||||
//
|
||||
// ---
|
||||
// consumes:
|
||||
@ -613,7 +613,7 @@ func (t *TenantStruct) UpgradeService(w http.ResponseWriter, r *http.Request) {
|
||||
//
|
||||
// 应用代码检测
|
||||
//
|
||||
// check code **完成
|
||||
// check code
|
||||
//
|
||||
// ---
|
||||
// consumes:
|
||||
@ -654,7 +654,7 @@ func (t *TenantStruct) ShareCloud(w http.ResponseWriter, r *http.Request) {
|
||||
//
|
||||
// 云市分享
|
||||
//
|
||||
// share cloud **完成
|
||||
// share cloud
|
||||
//
|
||||
// ---
|
||||
// consumes:
|
||||
@ -692,7 +692,7 @@ func (t *TenantStruct) ShareCloud(w http.ResponseWriter, r *http.Request) {
|
||||
//
|
||||
// 应用版本回滚
|
||||
//
|
||||
// service rollback **完成
|
||||
// service rollback
|
||||
//
|
||||
// ---
|
||||
// consumes:
|
||||
|
@ -1,4 +1,3 @@
|
||||
|
||||
// RAINBOND, Application Management Platform
|
||||
// Copyright (C) 2014-2017 Goodrain Co., Ltd.
|
||||
|
||||
@ -20,9 +19,10 @@
|
||||
package controller
|
||||
|
||||
import (
|
||||
api_model "github.com/goodrain/rainbond/pkg/api/model"
|
||||
"net/http"
|
||||
|
||||
api_model "github.com/goodrain/rainbond/pkg/api/model"
|
||||
|
||||
"github.com/Sirupsen/logrus"
|
||||
|
||||
"github.com/goodrain/rainbond/pkg/api/handler"
|
||||
@ -36,7 +36,7 @@ type OpentsdbStruct struct{}
|
||||
func (tsdb *OpentsdbStruct) TsdbQuery(w http.ResponseWriter, r *http.Request) {
|
||||
// swagger:operation POST /v2/opentsdb/query v2 oentsdbquery
|
||||
//
|
||||
// 监控数据查询 **完成
|
||||
// 监控数据查询
|
||||
//
|
||||
// query opentsdb
|
||||
//
|
||||
|
@ -1,4 +1,3 @@
|
||||
|
||||
// RAINBOND, Application Management Platform
|
||||
// Copyright (C) 2014-2017 Goodrain Co., Ltd.
|
||||
|
||||
@ -20,11 +19,12 @@
|
||||
package controller
|
||||
|
||||
import (
|
||||
"github.com/goodrain/rainbond/pkg/api/handler"
|
||||
"github.com/goodrain/rainbond/pkg/api/middleware"
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
"github.com/goodrain/rainbond/pkg/api/handler"
|
||||
"github.com/goodrain/rainbond/pkg/api/middleware"
|
||||
|
||||
api_model "github.com/goodrain/rainbond/pkg/api/model"
|
||||
dbmodel "github.com/goodrain/rainbond/pkg/db/model"
|
||||
httputil "github.com/goodrain/rainbond/pkg/util/http"
|
||||
@ -49,7 +49,7 @@ func (t *TenantStruct) AddVolumeDependency(w http.ResponseWriter, r *http.Reques
|
||||
//
|
||||
// 增加应用持久化依赖
|
||||
//
|
||||
// add volume dependency **完成
|
||||
// add volume dependency
|
||||
//
|
||||
// ---
|
||||
// consumes:
|
||||
@ -93,7 +93,7 @@ func (t *TenantStruct) DeleteVolumeDependency(w http.ResponseWriter, r *http.Req
|
||||
//
|
||||
// 删除应用持久化依赖
|
||||
//
|
||||
// delete volume dependency **完成
|
||||
// delete volume dependency
|
||||
//
|
||||
// ---
|
||||
// consumes:
|
||||
@ -134,7 +134,7 @@ func (t *TenantStruct) AddVolume(w http.ResponseWriter, r *http.Request) {
|
||||
//
|
||||
// 增加应用持久化信息
|
||||
//
|
||||
// add volume **完成
|
||||
// add volume
|
||||
//
|
||||
// ---
|
||||
// consumes:
|
||||
@ -181,7 +181,7 @@ func (t *TenantStruct) DeleteVolume(w http.ResponseWriter, r *http.Request) {
|
||||
//
|
||||
// 删除应用持久化信息
|
||||
//
|
||||
// delete volume **完成
|
||||
// delete volume
|
||||
//
|
||||
// ---
|
||||
// consumes:
|
||||
@ -224,7 +224,7 @@ func AddVolumeDependency(w http.ResponseWriter, r *http.Request) {
|
||||
//
|
||||
// 增加应用持久化依赖(V2.1支持多种类型存储)
|
||||
//
|
||||
// add volume dependency **完成
|
||||
// add volume dependency
|
||||
//
|
||||
// ---
|
||||
// consumes:
|
||||
@ -268,7 +268,7 @@ func DeleteVolumeDependency(w http.ResponseWriter, r *http.Request) {
|
||||
//
|
||||
// 删除应用持久化依赖(V2.1支持多种类型存储)
|
||||
//
|
||||
// delete volume dependency **完成
|
||||
// delete volume dependency
|
||||
//
|
||||
// ---
|
||||
// consumes:
|
||||
@ -310,7 +310,7 @@ func AddVolume(w http.ResponseWriter, r *http.Request) {
|
||||
//
|
||||
// 增加应用持久化信息(V2.1支持多种类型存储)
|
||||
//
|
||||
// add volume **完成
|
||||
// add volume
|
||||
//
|
||||
// ---
|
||||
// consumes:
|
||||
@ -357,7 +357,7 @@ func DeleteVolume(w http.ResponseWriter, r *http.Request) {
|
||||
//
|
||||
// 删除应用持久化信息(V2.1支持多种类型存储)
|
||||
//
|
||||
// delete volume **完成
|
||||
// delete volume
|
||||
//
|
||||
// ---
|
||||
// consumes:
|
||||
|
@ -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,23 +279,32 @@ 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,
|
||||
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 {
|
||||
tx.Rollback()
|
||||
@ -305,9 +314,12 @@ func (p *PluginAction) ImageBuildPlugin(b *api_model.BuildPluginStruct, plugin *
|
||||
TenantID: b.Body.TenantID,
|
||||
PluginID: b.PluginID,
|
||||
Operator: b.Body.Operator,
|
||||
ImageURL: b.Body.ImageURL,
|
||||
ImageURL: plugin.ImageURL,
|
||||
EventID: b.Body.EventID,
|
||||
Kind: b.Body.Kind,
|
||||
Kind: plugin.BuildModel,
|
||||
PluginCMD: b.Body.PluginCMD,
|
||||
PluginCPU: b.Body.PluginCPU,
|
||||
PluginMemory: b.Body.PluginMemory,
|
||||
VersionID: buildVersion,
|
||||
}
|
||||
jtask, errJ := ffjson.Marshal(taskBody)
|
||||
@ -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"
|
||||
@ -354,13 +369,22 @@ func (p *PluginAction) DockerfileBuildPlugin(b *api_model.BuildPluginStruct, plu
|
||||
pbv := &dbmodel.TenantPluginBuildVersion{
|
||||
VersionID: buildVersion,
|
||||
PluginID: b.PluginID,
|
||||
Kind: b.Body.Kind,
|
||||
Kind: plugin.BuildModel,
|
||||
Repo: b.Body.RepoURL,
|
||||
GitURL: b.Body.GitURL,
|
||||
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 {
|
||||
tx.Rollback()
|
||||
@ -372,9 +396,12 @@ func (p *PluginAction) DockerfileBuildPlugin(b *api_model.BuildPluginStruct, plu
|
||||
Operator: b.Body.Operator,
|
||||
EventID: b.Body.EventID,
|
||||
Repo: b.Body.RepoURL,
|
||||
GitURL: b.Body.GitURL,
|
||||
Kind: b.Body.Kind,
|
||||
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 {
|
||||
|
@ -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
|
||||
@ -330,7 +322,7 @@ type DeletePluginSetStruct struct {
|
||||
}
|
||||
|
||||
//GetPluginEnvStruct GetPluginEnvStruct
|
||||
//swagger:parameters getPluginEnv, getPluginDefaultEnv
|
||||
//swagger:parameters getPluginEnv getPluginDefaultEnv
|
||||
type GetPluginEnvStruct struct {
|
||||
// in: path
|
||||
// required: true
|
||||
|
@ -45,17 +45,37 @@ type TaskInterface interface {
|
||||
}
|
||||
type NodeInterface interface {
|
||||
Add(node *model.APIHostNode)
|
||||
Delete()
|
||||
Rule(rule string) []*model.HostNode
|
||||
Get(node string) *Node
|
||||
List() []*model.HostNode
|
||||
Up()
|
||||
Down()
|
||||
UnSchedulable()
|
||||
ReSchedulable()
|
||||
Label(label map[string]string)
|
||||
}
|
||||
|
||||
func (t *Node)Label(label map[string]string) {
|
||||
body,_:=json.Marshal(label)
|
||||
_,_,err:=nodeServer.Request("/nodes/"+t.Id+"/labels","PUT",body)
|
||||
if err != nil {
|
||||
logrus.Errorf("error details %s",err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
func (t *Node)Add(node *model.APIHostNode) {
|
||||
body,_:=json.Marshal(node)
|
||||
nodeServer.Request("/nodes/","POST",body)
|
||||
_,_,err:=nodeServer.Request("/nodes","POST",body)
|
||||
if err != nil {
|
||||
logrus.Errorf("error details %s",err.Error())
|
||||
}
|
||||
}
|
||||
func (t *Node) Delete() {
|
||||
_,_,err:=nodeServer.Request("/nodes/"+t.Id,"DELETE",nil)
|
||||
if err != nil {
|
||||
logrus.Errorf("error details %s",err.Error())
|
||||
}
|
||||
}
|
||||
func (t *Node)Up() {
|
||||
nodeServer.Request("/nodes/"+t.Id+"/up","POST",nil)
|
||||
@ -69,6 +89,7 @@ func (t *Node)UnSchedulable() {
|
||||
func (t *Node)ReSchedulable() {
|
||||
nodeServer.Request("/nodes/"+t.Id+"/reschedulable","PUT",nil)
|
||||
}
|
||||
|
||||
func (t *Node)Get(node string) *Node {
|
||||
body,_,err:=nodeServer.Request("/nodes/"+node,"GET",nil)
|
||||
if err != nil {
|
||||
@ -96,12 +117,43 @@ func (t *Node)Get(node string) *Node {
|
||||
t.Node=&stored
|
||||
return t
|
||||
}
|
||||
|
||||
func (t *Node)Rule(rule string) []*model.HostNode {
|
||||
body,_,err:=nodeServer.Request("/nodes/"+rule,"GET",nil)
|
||||
if err != nil {
|
||||
logrus.Errorf("error get rule %s ,details %s",rule,err.Error())
|
||||
return nil
|
||||
}
|
||||
j,err:=simplejson.NewJson(body)
|
||||
if err != nil {
|
||||
logrus.Errorf("error get json ,details %s",err.Error())
|
||||
return nil
|
||||
}
|
||||
nodeArr,err:=j.Get("list").Array()
|
||||
if err != nil {
|
||||
logrus.Infof("error occurd,details %s",err.Error())
|
||||
return nil
|
||||
}
|
||||
jsonA, _ := json.Marshal(nodeArr)
|
||||
nodes := []*model.HostNode{}
|
||||
err=json.Unmarshal(jsonA, &nodes)
|
||||
if err != nil {
|
||||
logrus.Infof("error occurd,details %s",err.Error())
|
||||
return nil
|
||||
}
|
||||
return nodes
|
||||
}
|
||||
func (t *Node)List() []*model.HostNode {
|
||||
body,_,err:=nodeServer.Request("/nodes","GET",nil)
|
||||
if err != nil {
|
||||
logrus.Errorf("error get nodes ,details %s",err.Error())
|
||||
return nil
|
||||
}
|
||||
j,err:=simplejson.NewJson(body)
|
||||
if err != nil {
|
||||
logrus.Errorf("error get json ,details %s",err.Error())
|
||||
return nil
|
||||
}
|
||||
j,_:=simplejson.NewJson(body)
|
||||
nodeArr,err:=j.Get("list").Array()
|
||||
if err != nil {
|
||||
logrus.Infof("error occurd,details %s",err.Error())
|
||||
@ -143,26 +195,60 @@ type TaskStatus struct {
|
||||
}
|
||||
func (t *Task)Status() (*TaskStatus,error) {
|
||||
taskId:=t.TaskID
|
||||
resp,code,err:=nodeServer.Request("/tasks/"+taskId+"/status","GET",nil)
|
||||
return HandleTaskStatus(taskId)
|
||||
}
|
||||
func HandleUnStructedJson(b []byte) *model.TaskStatus {
|
||||
json,_:=simplejson.NewJson(b)
|
||||
|
||||
second:=json.Interface()
|
||||
|
||||
logrus.Infof("second level is %v",second)
|
||||
m:=second.(map[string]interface{})
|
||||
var taskStatus model.TaskStatus
|
||||
for k,_:=range m {
|
||||
logrus.Infof("handling %s status",k)
|
||||
taskStatus.CompleStatus=m[k].(map[string]interface{})["comple_status"].(string)
|
||||
taskStatus.Status=m[k].(map[string]interface{})["status"].(string)
|
||||
taskStatus.JobID=k
|
||||
taskStatus.ShellCode=m[k].(map[string]interface{})["shell_code"].(int)
|
||||
break
|
||||
}
|
||||
return &taskStatus
|
||||
}
|
||||
func HandleTaskStatus(task string) (*TaskStatus,error) {
|
||||
resp,code,err:=nodeServer.Request("/tasks/"+task+"/status","GET",nil)
|
||||
if err != nil {
|
||||
logrus.Errorf("error execute status Request,details %s",err.Error())
|
||||
return nil,err
|
||||
}
|
||||
if code == 200 {
|
||||
j, _ := simplejson.NewJson(resp)
|
||||
bean,_:=j.Get("bean").Bytes()
|
||||
bean := j.Get("bean")
|
||||
beanB, _ := json.Marshal(bean)
|
||||
var status TaskStatus
|
||||
err=json.Unmarshal(bean,&status)
|
||||
if err != nil {
|
||||
logrus.Errorf("error unmarshal response,details %s",err.Error())
|
||||
return nil,err
|
||||
|
||||
json,_:=simplejson.NewJson(beanB)
|
||||
|
||||
second:=json.Interface()
|
||||
|
||||
logrus.Infof("second level is %v",second)
|
||||
m:=second.(map[string]interface{})
|
||||
|
||||
for k,_:=range m {
|
||||
var taskStatus model.TaskStatus
|
||||
logrus.Infof("handling %s status",k)
|
||||
taskStatus.CompleStatus=m[k].(map[string]interface{})["comple_status"].(string)
|
||||
taskStatus.Status=m[k].(map[string]interface{})["status"].(string)
|
||||
taskStatus.JobID=k
|
||||
taskStatus.ShellCode=m[k].(map[string]interface{})["shell_code"].(int)
|
||||
status.Status[k]=taskStatus
|
||||
}
|
||||
return &status,nil
|
||||
}
|
||||
return nil,nil
|
||||
}
|
||||
func (r *RNodeServer)Request(url ,method string, body []byte) ([]byte,int,error) {
|
||||
logrus.Infof("requesting url: %s by method :%s",r.NodeAPI+url,method)
|
||||
logrus.Infof("requesting url: %s by method :%s,and body is ",r.NodeAPI+url,method,string(body))
|
||||
request, err := http.NewRequest(method, r.NodeAPI+url, bytes.NewBuffer(body))
|
||||
if err != nil {
|
||||
return nil,500,err
|
||||
@ -176,5 +262,6 @@ func (r *RNodeServer)Request(url ,method string, body []byte) ([]byte,int,error)
|
||||
|
||||
data, err := ioutil.ReadAll(res.Body)
|
||||
defer res.Body.Close()
|
||||
logrus.Infof("response is %s,response code is %d",string(data),res.StatusCode)
|
||||
return data,res.StatusCode,err
|
||||
}
|
55
pkg/builder/api/controller/eventController.go
Normal file
55
pkg/builder/api/controller/eventController.go
Normal file
@ -0,0 +1,55 @@
|
||||
// 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 controller
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"github.com/goodrain/rainbond/pkg/db"
|
||||
dbmodel "github.com/goodrain/rainbond/pkg/db/model"
|
||||
httputil "github.com/goodrain/rainbond/pkg/util/http"
|
||||
"github.com/Sirupsen/logrus"
|
||||
"github.com/bitly/go-simplejson"
|
||||
"io/ioutil"
|
||||
)
|
||||
|
||||
func GetEventsByIds(w http.ResponseWriter, r *http.Request) {
|
||||
b,_:=ioutil.ReadAll(r.Body)
|
||||
defer r.Body.Close()
|
||||
j,err:=simplejson.NewJson(b)
|
||||
if err != nil {
|
||||
logrus.Errorf("error decode json,details %s",err.Error())
|
||||
httputil.ReturnError(r,w,400,"bad request")
|
||||
return
|
||||
}
|
||||
eventIDS,err:=j.Get("event_ids").StringArray()
|
||||
if err != nil {
|
||||
logrus.Errorf("error get event_id in json,details %s",err.Error())
|
||||
httputil.ReturnError(r,w,400,"bad request")
|
||||
return
|
||||
}
|
||||
result:=[]*dbmodel.ServiceEvent{}
|
||||
for _,v:=range eventIDS{
|
||||
serviceEvent,err:=db.GetManager().ServiceEventDao().GetEventByEventID(v)
|
||||
if err != nil {
|
||||
logrus.Warnf("can't find event by given id %s ,details %s",v,err.Error())
|
||||
continue
|
||||
}
|
||||
result=append(result,serviceEvent)
|
||||
}
|
||||
httputil.ReturnSuccess(r, w, result)
|
||||
}
|
@ -28,6 +28,7 @@ import (
|
||||
"strings"
|
||||
"github.com/bitly/go-simplejson"
|
||||
"io/ioutil"
|
||||
"encoding/json"
|
||||
)
|
||||
|
||||
func GetAppPublish(w http.ResponseWriter, r *http.Request) {
|
||||
@ -39,7 +40,24 @@ func GetAppPublish(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
httputil.ReturnSuccess(r, w, appp)
|
||||
}
|
||||
func GetVersionByEventID(w http.ResponseWriter, r *http.Request) {
|
||||
eventID := strings.TrimSpace(chi.URLParam(r, "eventID"))
|
||||
|
||||
version,err:=db.GetManager().VersionInfoDao().GetVersionByEventID(eventID)
|
||||
if err != nil {
|
||||
httputil.ReturnError(r,w,404,err.Error())
|
||||
}
|
||||
httputil.ReturnSuccess(r, w, version)
|
||||
}
|
||||
func GetVersionByServiceID(w http.ResponseWriter, r *http.Request) {
|
||||
serviceID := strings.TrimSpace(chi.URLParam(r, "serviceID"))
|
||||
|
||||
versions,err:=db.GetManager().VersionInfoDao().GetVersionByServiceID(serviceID)
|
||||
if err != nil {
|
||||
httputil.ReturnError(r,w,404,err.Error())
|
||||
}
|
||||
httputil.ReturnSuccess(r, w, versions)
|
||||
}
|
||||
func UpdateDeliveredPath(w http.ResponseWriter, r *http.Request) {
|
||||
in,err:=ioutil.ReadAll(r.Body)
|
||||
if err != nil {
|
||||
@ -71,35 +89,28 @@ func UpdateDeliveredPath(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
|
||||
func AddAppPublish(w http.ResponseWriter, r *http.Request) {
|
||||
result := new(model.AppPublish)
|
||||
|
||||
|
||||
b,_:=ioutil.ReadAll(r.Body)
|
||||
defer r.Body.Close()
|
||||
j,err:=simplejson.NewJson(b)
|
||||
var result model.AppPublish
|
||||
b,err:=ioutil.ReadAll(r.Body)
|
||||
if err != nil {
|
||||
logrus.Errorf("error decode json,details %s",err.Error())
|
||||
httputil.ReturnError(r,w,400,"bad request")
|
||||
logrus.Errorf("error get request body ,details %s",err.Error())
|
||||
return
|
||||
}
|
||||
defer r.Body.Close()
|
||||
logrus.Infof("request body is %s",b)
|
||||
err=json.Unmarshal(b,&result)
|
||||
if err != nil {
|
||||
logrus.Errorf("error unmarshal use raw support,details %s",err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
result.AppVersion,_=j.Get("app_version").String()
|
||||
result.ServiceKey,_=j.Get("service_key").String()
|
||||
result.Slug,_=j.Get("slug").String()
|
||||
result.Image,_=j.Get("image").String()
|
||||
result.DestYS,_=j.Get("dest_ys").Bool()
|
||||
result.DestYB,_=j.Get("dest_yb").Bool()
|
||||
result.ShareID,_=j.Get("share_id").String()
|
||||
|
||||
|
||||
dbmodel:=convertPublishToDB(result)
|
||||
dbmodel:=convertPublishToDB(&result)
|
||||
//checkAndGet
|
||||
db.GetManager().AppPublishDao().AddModel(dbmodel)
|
||||
httputil.ReturnSuccess(r, w, nil)
|
||||
}
|
||||
func convertPublishToDB(publish *model.AppPublish) *dbmodel.AppPublish {
|
||||
|
||||
dbm:=dbmodel.AppPublish{}
|
||||
var dbm dbmodel.AppPublish
|
||||
dbm.ShareID=publish.ShareID
|
||||
dbm.AppVersion=publish.AppVersion
|
||||
dbm.DestYB=publish.DestYB
|
||||
@ -107,5 +118,6 @@ func convertPublishToDB(publish *model.AppPublish) *dbmodel.AppPublish {
|
||||
dbm.Image=publish.Image
|
||||
dbm.ServiceKey=publish.ServiceKey
|
||||
dbm.Slug=publish.Slug
|
||||
dbm.Status=publish.Status
|
||||
return &dbm
|
||||
}
|
||||
|
@ -33,9 +33,15 @@ func APIServer() *chi.Mux {
|
||||
r.Route("/publish", func(r chi.Router) {
|
||||
r.Get("/service/{serviceKey}/version/{appVersion}",controller.GetAppPublish)
|
||||
r.Post("/",controller.AddAppPublish)
|
||||
|
||||
})
|
||||
r.Route("/version", func(r chi.Router) {
|
||||
r.Post("/",controller.UpdateDeliveredPath)
|
||||
r.Get("/event/{eventID}",controller.GetVersionByEventID)
|
||||
r.Get("/service/{serviceID}",controller.GetVersionByServiceID)
|
||||
})
|
||||
r.Route("/event", func(r chi.Router) {
|
||||
r.Get("/",controller.GetEventsByIds)
|
||||
})
|
||||
return r
|
||||
}
|
||||
|
@ -30,6 +30,7 @@ import (
|
||||
"github.com/Sirupsen/logrus"
|
||||
"github.com/docker/docker/client"
|
||||
"github.com/tidwall/gjson"
|
||||
"strings"
|
||||
)
|
||||
|
||||
//Manager 任务执行管理器
|
||||
@ -61,6 +62,7 @@ type exectorManager struct {
|
||||
//code_check 代码检测
|
||||
//app_build 源码构建
|
||||
func (e *exectorManager) AddTask(task *pb.TaskMessage) error {
|
||||
|
||||
switch task.TaskType {
|
||||
case "app_image":
|
||||
e.appImage(task.TaskBody)
|
||||
@ -92,6 +94,7 @@ const pluginDockerfile = "plugins/plugin_dockerfile.pyc"
|
||||
|
||||
func (e *exectorManager) appImage(in []byte) {
|
||||
eventID := gjson.GetBytes(in, "event_id").String()
|
||||
dest := gjson.GetBytes(in, "dest").String()
|
||||
finalStatus:="failure"
|
||||
logger := event.GetManager().GetLogger(eventID)
|
||||
logger.Info("应用镜像构建任务开始执行", map[string]string{"step": "builder-exector", "status": "starting"})
|
||||
@ -110,17 +113,45 @@ func (e *exectorManager) appImage(in []byte) {
|
||||
}
|
||||
} else {
|
||||
finalStatus="success"
|
||||
updateBuildResult(eventID,finalStatus)
|
||||
updateBuildResult(eventID,finalStatus,dest)
|
||||
break
|
||||
}
|
||||
}
|
||||
}()
|
||||
updateBuildResult(eventID,finalStatus)
|
||||
updateBuildResult(eventID,finalStatus,dest)
|
||||
}
|
||||
func (e *exectorManager) appSlug(in []byte) {
|
||||
eventID := gjson.GetBytes(in, "event_id").String()
|
||||
finalStatus:="failure"
|
||||
//eventID := gjson.GetBytes(in, "event_id").String()
|
||||
////dest := gjson.GetBytes(in, "dest").String()
|
||||
////finalStatus:="failure"
|
||||
//
|
||||
//logger := event.GetManager().GetLogger(eventID)
|
||||
//logger.Info("应用代码包构建任务开始执行", map[string]string{"step": "builder-exector", "status": "starting"})
|
||||
//w := NewWorker(appSlug, "", nil, in)
|
||||
//go func() {
|
||||
// logrus.Info("start exec app slug worker")
|
||||
// defer event.GetManager().ReleaseLogger(logger)
|
||||
// for i := 0; i < 3; i++ {
|
||||
// _, err := w.run(time.Minute * 30)
|
||||
// if err != nil {
|
||||
// logrus.Errorf("exec app slug python shell error:%s", err.Error())
|
||||
// if i < 3 {
|
||||
// logger.Info("应用代码包构建任务执行失败,开始重试", map[string]string{"step": "builder-exector", "status": "failure"})
|
||||
// } else {
|
||||
// logger.Info("应用代码包构建任务执行失败", map[string]string{"step": "callback", "status": "failure"})
|
||||
//
|
||||
// }
|
||||
// } else {
|
||||
// //updateBuildResult(eventID,"success",dest)
|
||||
// break
|
||||
// }
|
||||
// }
|
||||
//}()
|
||||
//updateBuildResult(eventID,"failure",dest)
|
||||
|
||||
|
||||
|
||||
eventID := gjson.GetBytes(in, "event_id").String()
|
||||
logger := event.GetManager().GetLogger(eventID)
|
||||
logger.Info("应用代码包构建任务开始执行", map[string]string{"step": "builder-exector", "status": "starting"})
|
||||
w := NewWorker(appSlug, "", nil, in)
|
||||
@ -135,21 +166,17 @@ func (e *exectorManager) appSlug(in []byte) {
|
||||
logger.Info("应用代码包构建任务执行失败,开始重试", map[string]string{"step": "builder-exector", "status": "failure"})
|
||||
} else {
|
||||
logger.Info("应用代码包构建任务执行失败", map[string]string{"step": "callback", "status": "failure"})
|
||||
|
||||
}
|
||||
} else {
|
||||
finalStatus="success"
|
||||
updateBuildResult(eventID,finalStatus)
|
||||
break
|
||||
}
|
||||
}
|
||||
}()
|
||||
updateBuildResult(eventID,finalStatus)
|
||||
}
|
||||
func (e *exectorManager) imageManual(in []byte) {
|
||||
eventID := gjson.GetBytes(in, "event_id").String()
|
||||
logger := event.GetManager().GetLogger(eventID)
|
||||
|
||||
dest := gjson.GetBytes(in, "dest").String()
|
||||
finalStatus:="failure"
|
||||
|
||||
logger.Info("应用镜像构建任务开始执行", map[string]string{"step": "builder-exector", "status": "starting"})
|
||||
@ -168,12 +195,12 @@ func (e *exectorManager) imageManual(in []byte) {
|
||||
}
|
||||
} else {
|
||||
finalStatus="success"
|
||||
updateBuildResult(eventID,finalStatus)
|
||||
updateBuildResult(eventID,finalStatus,dest)
|
||||
break
|
||||
}
|
||||
}
|
||||
}()
|
||||
updateBuildResult(eventID,finalStatus)
|
||||
updateBuildResult(eventID,finalStatus,dest)
|
||||
}
|
||||
func (e *exectorManager) codeCheck(in []byte) {
|
||||
eventID := gjson.GetBytes(in, "event_id").String()
|
||||
@ -201,6 +228,7 @@ func (e *exectorManager) codeCheck(in []byte) {
|
||||
func (e *exectorManager) appBuild(in []byte) {
|
||||
eventID := gjson.GetBytes(in, "event_id").String()
|
||||
finalStatus:="failure"
|
||||
dest := gjson.GetBytes(in, "dest").String()
|
||||
logger := event.GetManager().GetLogger(eventID)
|
||||
logger.Info("应用编译构建任务开始执行", map[string]string{"step": "builder-exector", "status": "starting"})
|
||||
|
||||
@ -218,21 +246,22 @@ func (e *exectorManager) appBuild(in []byte) {
|
||||
logger.Info("应用编译构建任务执行失败", map[string]string{"step": "callback", "status": "failure"})
|
||||
}
|
||||
} else {
|
||||
logrus.Infof("build task success,eventID is %s",eventID)
|
||||
//logger.Info("应用编译构建任务执行成功", map[string]string{"step": "callback", "status": "success"})
|
||||
finalStatus="success"
|
||||
updateBuildResult(eventID,finalStatus)
|
||||
updateBuildResult(eventID,finalStatus,dest)
|
||||
break
|
||||
}
|
||||
}
|
||||
}()
|
||||
updateBuildResult(eventID,finalStatus)
|
||||
updateBuildResult(eventID,finalStatus,dest)
|
||||
}
|
||||
func updateBuildResult(eventID,finalStatus string) {
|
||||
func updateBuildResult(eventID,finalStatus,dest string) {
|
||||
if dest == ""||!strings.Contains(dest,"y") {
|
||||
v,_:=db.GetManager().VersionInfoDao().GetVersionByEventID(eventID)
|
||||
v.FinalStatus=finalStatus
|
||||
db.GetManager().VersionInfoDao().UpdateModel(v)
|
||||
}
|
||||
|
||||
}
|
||||
func (e *exectorManager) pluginImageBuild1(in []byte) {
|
||||
eventID := gjson.GetBytes(in, "event_id").String()
|
||||
logger := event.GetManager().GetLogger(eventID)
|
||||
|
@ -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
|
||||
@ -65,9 +68,10 @@ type CodeCheckResult struct {
|
||||
type AppPublish struct {
|
||||
ServiceKey string `json:"service_key"`
|
||||
AppVersion string `json:"app_version"`
|
||||
Image string `json:"image"`
|
||||
Slug string `json:"slug"`
|
||||
DestYS bool `json:"dest_ys"`
|
||||
DestYB bool `json:"dest_yb"`
|
||||
ShareID string `json:"share_id"`
|
||||
Image string `json:"image,omitempty"`
|
||||
Slug string `json:"slug,omitempty"`
|
||||
DestYS bool `json:"dest_ys,omitempty"`
|
||||
DestYB bool `json:"dest_yb,omitempty"`
|
||||
ShareID string `json:"share_id,omitempty"`
|
||||
Status string `json:"status,omitempty"`
|
||||
}
|
||||
|
@ -274,5 +274,5 @@ type EventDao interface {
|
||||
type VersionInfoDao interface {
|
||||
Dao
|
||||
GetVersionByEventID(eventID string) (*model.VersionInfo, error)
|
||||
GetVersionByBuildVersion(buildVersion string) ([]*model.VersionInfo, error)
|
||||
GetVersionByServiceID(serviceID string) ([]*model.VersionInfo, error)
|
||||
}
|
@ -1,4 +1,3 @@
|
||||
|
||||
// RAINBOND, Application Management Platform
|
||||
// Copyright (C) 2014-2017 Goodrain Co., Ltd.
|
||||
|
||||
@ -18,22 +17,21 @@
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
package model
|
||||
|
||||
//AppPublish AppPublish
|
||||
type AppPublish struct {
|
||||
Model
|
||||
ServiceKey string `gorm:"column:service_key;size:70"`
|
||||
AppVersion string `gorm:"column:app_version;size:70"`
|
||||
Status string `gorm:"column:status;size:10"`
|
||||
Image string `gorm:"column:image;size:50"`
|
||||
Slug string `gorm:"column:slug;size:50"`
|
||||
Image string `gorm:"column:image;size:200"`
|
||||
Slug string `gorm:"column:slug;size:200"`
|
||||
DestYS bool `gorm:"column:dest_ys"`
|
||||
DestYB bool `gorm:"column:dest_yb"`
|
||||
ShareID string `gorm:"column:share_id;size:70"`
|
||||
}
|
||||
|
||||
|
||||
//TableName 表名
|
||||
func (t *AppPublish) TableName() string {
|
||||
return "app_publish"
|
||||
}
|
||||
|
||||
|
163
pkg/db/model/plugin.go
Normal file
163
pkg/db/model/plugin.go
Normal 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"
|
@ -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"
|
||||
|
@ -23,18 +23,28 @@ import (
|
||||
"github.com/goodrain/rainbond/pkg/db/model"
|
||||
|
||||
"github.com/jinzhu/gorm"
|
||||
"github.com/Sirupsen/logrus"
|
||||
)
|
||||
|
||||
|
||||
//AddModel AddModel
|
||||
func (c *AppPublishDaoImpl) AddModel(mo model.Interface) error {
|
||||
result := mo.(*model.AppPublish)
|
||||
result.Status="success"
|
||||
var oldResult model.AppPublish
|
||||
if ok := c.DB.Where("service_key=? and app_version=?", result.ServiceKey,result.AppVersion).Find(&oldResult).RecordNotFound(); ok {
|
||||
if err := c.DB.Create(result).Error; err != nil {
|
||||
if err != nil {
|
||||
logrus.Errorf("error save app publish,details %s",err.Error())
|
||||
}
|
||||
return err
|
||||
}
|
||||
}else {
|
||||
|
||||
oldResult.Status=result.Status
|
||||
if err := c.DB.Save(oldResult).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
396
pkg/db/mysql/dao/plugin.go
Normal file
396
pkg/db/mysql/dao/plugin.go
Normal 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
|
||||
}
|
@ -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
|
||||
}
|
||||
|
@ -71,9 +71,9 @@ func (c *VersionInfoDaoImpl) GetVersionByEventID(eventID string) (*model.Version
|
||||
|
||||
|
||||
//GetEventLogMessages get event log message
|
||||
func (c *VersionInfoDaoImpl) GetVersionByBuildVersion(buildVersion string) ([]*model.VersionInfo, error) {
|
||||
func (c *VersionInfoDaoImpl) GetVersionByServiceID(serviceID string) ([]*model.VersionInfo, error) {
|
||||
var result []*model.VersionInfo
|
||||
if err := c.DB.Where("build_version=?", buildVersion).Find(&result).Error; err != nil {
|
||||
if err := c.DB.Where("service_id=?", serviceID).Find(&result).Error; err != nil {
|
||||
if err == gorm.ErrRecordNotFound {
|
||||
//return messageRaw, nil
|
||||
}
|
||||
|
@ -326,7 +326,7 @@ func (h *handleMessageStore) handleBarrelEvent() {
|
||||
version.CommitMsg=i[1]
|
||||
}
|
||||
}
|
||||
cdb.GetManager().VersionInfoDao().UpdateModel(version)
|
||||
cdb.GetManager().VersionInfoDao()
|
||||
h.log.Infof("run web hook update code version .event_id %s code_version %s", eventID, codeVersion)
|
||||
}
|
||||
}
|
||||
|
@ -71,6 +71,8 @@ func Common(c *cli.Context) {
|
||||
if err := clients.InitRegionClient(*config.RegionAPI); err != nil {
|
||||
logrus.Warnf("error config region")
|
||||
}
|
||||
|
||||
if err := clients.InitNodeClient("http://127.0.0.1:6100/v2"); err != nil {
|
||||
logrus.Warnf("error config region")
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -25,7 +25,8 @@ import (
|
||||
"io/ioutil"
|
||||
"strings"
|
||||
"bytes"
|
||||
"runtime"
|
||||
"github.com/goodrain/rainbond/pkg/grctl/clients"
|
||||
//"runtime"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
@ -62,6 +63,10 @@ func NewCmdInit() cli.Command {
|
||||
return c
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// grctl exec POD_ID COMMAND
|
||||
func initCluster(c *cli.Context) error {
|
||||
//logrus.Infof("start init command")
|
||||
@ -92,26 +97,18 @@ func initCluster(c *cli.Context) error {
|
||||
arg=""
|
||||
}
|
||||
//logrus.Infof("args is %s,len is %d",arg,len(arg))
|
||||
fmt.Println("开始初始化集群")
|
||||
cmd := exec.Command("bash", "-c",arg+string(b))
|
||||
|
||||
go func(c *exec.Cmd) {
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
const size = 64 << 10
|
||||
buf := make([]byte, size)
|
||||
buf = buf[:runtime.Stack(buf, false)]
|
||||
logrus.Warnf("panic running job: %v\n%s", r, buf)
|
||||
}
|
||||
}()
|
||||
buf:=bytes.NewBuffer(nil)
|
||||
cmd.Stderr=buf
|
||||
c.Run()
|
||||
cmd.Run()
|
||||
out:=buf.String()
|
||||
arr:=strings.SplitN(out,"{",2)
|
||||
arr[1]="{"+arr[1]
|
||||
json:=arr[1]
|
||||
fmt.Println(json)
|
||||
}(cmd)
|
||||
jsonStr:=arr[1]
|
||||
|
||||
fmt.Println(jsonStr)
|
||||
clients.NodeClient.Tasks().Get("install_manage_ready").Status()
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -20,8 +20,8 @@ package cmd
|
||||
import (
|
||||
"github.com/urfave/cli"
|
||||
"github.com/Sirupsen/logrus"
|
||||
"encoding/json"
|
||||
"github.com/goodrain/rainbond/pkg/grctl/clients"
|
||||
"time"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
@ -33,7 +33,7 @@ func GetCommand(status bool)[]cli.Command {
|
||||
Flags: []cli.Flag{
|
||||
cli.StringSliceFlag{
|
||||
Name: "nodes",
|
||||
Usage: "10.0.0.2 10.0.0.3,空表示全部",
|
||||
Usage: "hostID1 hostID2 ...,空表示全部",
|
||||
},
|
||||
},
|
||||
Action: func(c *cli.Context) error {
|
||||
@ -70,7 +70,7 @@ func GetCommand(status bool)[]cli.Command {
|
||||
Flags: []cli.Flag{
|
||||
cli.StringSliceFlag{
|
||||
Name: "nodes",
|
||||
Usage: "10.0.0.2 10.0.0.3,空表示全部",
|
||||
Usage: "hostID1 hostID2 ...,空表示全部",
|
||||
},
|
||||
},
|
||||
Action: func(c *cli.Context) error {
|
||||
@ -116,7 +116,7 @@ func GetCommand(status bool)[]cli.Command {
|
||||
Flags: []cli.Flag{
|
||||
cli.StringSliceFlag{
|
||||
Name: "nodes",
|
||||
Usage: "10.0.0.2 10.0.0.3,空表示全部",
|
||||
Usage: "hostID1 hostID2 ...,空表示全部",
|
||||
},
|
||||
},
|
||||
Subcommands:[]cli.Command{
|
||||
@ -167,7 +167,7 @@ func NewCmdInstall() cli.Command {
|
||||
Flags: []cli.Flag{
|
||||
cli.StringSliceFlag{
|
||||
Name: "nodes",
|
||||
Usage: "10.0.0.2 10.0.0.3,空表示全部",
|
||||
Usage: "hostID1 hostID2 ...,空表示全部",
|
||||
},
|
||||
},
|
||||
Subcommands:GetCommand(false),
|
||||
@ -181,7 +181,7 @@ func NewCmdStatus() cli.Command {
|
||||
Flags: []cli.Flag{
|
||||
cli.StringSliceFlag{
|
||||
Name: "nodes",
|
||||
Usage: "10.0.0.2 10.0.0.3,空表示全部",
|
||||
Usage: "hostID1 hostID2 ...,空表示全部",
|
||||
},
|
||||
},
|
||||
Subcommands:GetCommand(true),
|
||||
@ -189,17 +189,6 @@ func NewCmdStatus() cli.Command {
|
||||
return c
|
||||
}
|
||||
func Task(c *cli.Context,task string,status bool) error {
|
||||
if status{
|
||||
status,err:=clients.NodeClient.Tasks().Get(task).Status()
|
||||
if err != nil {
|
||||
logrus.Errorf("error get task:%s 's status,details %s",task,err.Error())
|
||||
return err
|
||||
}
|
||||
a:=status.Status
|
||||
b,_:=json.Marshal(a)
|
||||
fmt.Println(string(b))
|
||||
return nil
|
||||
}
|
||||
|
||||
nodes:=c.StringSlice("nodes")
|
||||
err:=clients.NodeClient.Tasks().Get(task).Exec(nodes)
|
||||
@ -207,5 +196,23 @@ func Task(c *cli.Context,task string,status bool) error {
|
||||
logrus.Errorf("error exec task:%s,details %s",task,err.Error())
|
||||
return err
|
||||
}
|
||||
for true {
|
||||
time.Sleep(3*time.Second)
|
||||
taskStatus,err:=clients.NodeClient.Tasks().Get(task).Status()
|
||||
if err != nil {
|
||||
logrus.Errorf("error get task:%s 's status,details %s",task,err.Error())
|
||||
return err
|
||||
}
|
||||
fmt.Printf("安装中 ")
|
||||
for k,v:=range taskStatus.Status{
|
||||
if v.Status!="complete" {
|
||||
fmt.Printf(".")
|
||||
continue
|
||||
}else {
|
||||
fmt.Printf("%s is %s-----%s",k,v.CompleStatus,v.Status)
|
||||
return nil
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
@ -123,6 +123,61 @@ func NewCmdNode() cli.Command {
|
||||
return nil
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: "delete",
|
||||
Usage: "delete hostID",
|
||||
Action: func(c *cli.Context) error {
|
||||
id:=c.Args().First()
|
||||
if id == "" {
|
||||
logrus.Errorf("need hostID")
|
||||
return nil
|
||||
}
|
||||
clients.NodeClient.Nodes().Get(id).Delete()
|
||||
return nil
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: "rule",
|
||||
Usage: "rule ruleName",
|
||||
Action: func(c *cli.Context) error {
|
||||
rule:=c.Args().First()
|
||||
if rule == "" {
|
||||
logrus.Errorf("need rule name")
|
||||
return nil
|
||||
}
|
||||
clients.NodeClient.Nodes().Rule(rule)
|
||||
return nil
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: "label",
|
||||
Usage: "label hostID",
|
||||
Flags: []cli.Flag{
|
||||
cli.StringFlag{
|
||||
Name: "key",
|
||||
Value: "",
|
||||
Usage: "key",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "val",
|
||||
Value: "",
|
||||
Usage: "val",
|
||||
},
|
||||
},
|
||||
Action: func(c *cli.Context) error {
|
||||
hostID:=c.Args().First()
|
||||
if hostID == "" {
|
||||
logrus.Errorf("need hostID")
|
||||
return nil
|
||||
}
|
||||
k:=c.String("key")
|
||||
v:=c.String("val")
|
||||
label:=make(map[string]string)
|
||||
label[k]=v
|
||||
clients.NodeClient.Nodes().Get(hostID).Label(label)
|
||||
return nil
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: "add",
|
||||
Usage: "add 添加节点",
|
||||
@ -135,7 +190,7 @@ func NewCmdNode() cli.Command {
|
||||
cli.StringFlag{
|
||||
Name: "InternalIP,i",
|
||||
Value:"",
|
||||
Usage: "InternalIP",
|
||||
Usage: "InternalIP|required",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "ExternalIP,e",
|
||||
@ -148,7 +203,7 @@ func NewCmdNode() cli.Command {
|
||||
Usage: "RootPass",
|
||||
},
|
||||
cli.StringSliceFlag{
|
||||
Name: "Role,r",
|
||||
Name: "Role,ro",
|
||||
Usage: "Role|required",
|
||||
},
|
||||
},
|
||||
|
@ -31,24 +31,29 @@ import (
|
||||
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",
|
||||
},
|
||||
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]",
|
||||
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 {
|
||||
Common(c)
|
||||
return pluginAction(c)
|
||||
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",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
return c
|
||||
|
@ -52,11 +52,12 @@ type NodeCluster struct {
|
||||
lock sync.Mutex
|
||||
client *store.Client
|
||||
k8sClient *kubernetes.Clientset
|
||||
currentNode *model.HostNode
|
||||
checkInstall chan *model.HostNode
|
||||
}
|
||||
|
||||
//CreateNodeCluster 创建节点管理器
|
||||
func CreateNodeCluster(k8sClient *kubernetes.Clientset) (*NodeCluster, error) {
|
||||
func CreateNodeCluster(k8sClient *kubernetes.Clientset,node *model.HostNode) (*NodeCluster, error) {
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
nc := NodeCluster{
|
||||
ctx: ctx,
|
||||
@ -64,6 +65,7 @@ func CreateNodeCluster(k8sClient *kubernetes.Clientset) (*NodeCluster, error) {
|
||||
nodes: make(map[string]*model.HostNode, 5),
|
||||
client: store.DefalutClient,
|
||||
k8sClient: k8sClient,
|
||||
currentNode: node,
|
||||
checkInstall: make(chan *model.HostNode, 4),
|
||||
}
|
||||
if err := nc.loadNodes(); err != nil {
|
||||
@ -296,7 +298,12 @@ func (n *NodeCluster) checkNodeInstall(node *model.HostNode) {
|
||||
}
|
||||
var stdout bytes.Buffer
|
||||
var stderr bytes.Buffer
|
||||
client := util.NewSSHClient(node.InternalIP, "root", node.RootPass, "", 22, &stdout, &stderr)
|
||||
role:=node.Role[0]
|
||||
|
||||
etcd:=n.currentNode.InternalIP
|
||||
cmd:="bash -c \"set "+node.ID+" "+etcd+" "+role+";$(curl -s repo.goodrain.com/gaops/jobs/install/prepare/init.sh)\""
|
||||
logrus.Infof("init endpoint node cmd is %s",cmd)
|
||||
client := util.NewSSHClient(node.InternalIP, "root", node.RootPass, cmd, 22, &stdout, &stderr)
|
||||
if err := client.Connection(); err != nil {
|
||||
logrus.Error("init endpoint node error:", err.Error())
|
||||
errorCondition("SSH登陆初始化目标节点失败", err)
|
||||
@ -304,6 +311,7 @@ func (n *NodeCluster) checkNodeInstall(node *model.HostNode) {
|
||||
}
|
||||
//TODO:
|
||||
//处理安装结果
|
||||
fmt.Println("初始化节点成功")
|
||||
logrus.Info(stdout.String())
|
||||
}
|
||||
|
||||
|
@ -43,7 +43,7 @@ type MasterServer struct {
|
||||
func NewMasterServer(node *model.HostNode, k8sClient *kubernetes.Clientset) (*MasterServer, error) {
|
||||
datacenterConfig := config.CreateDataCenterConfig()
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
cluster, err := CreateNodeCluster(k8sClient)
|
||||
cluster, err := CreateNodeCluster(k8sClient,node)
|
||||
if err != nil {
|
||||
cancel()
|
||||
return nil, err
|
||||
|
@ -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 {
|
||||
|
Loading…
Reference in New Issue
Block a user