Merge remote-tracking branch 'origin/master'

This commit is contained in:
bay1ts 2017-12-01 14:44:16 +08:00
commit db8fc40311
10 changed files with 118 additions and 9 deletions

View File

@ -46,6 +46,7 @@ type ServiceInterface interface {
Dependency(w http.ResponseWriter, r *http.Request)
Env(w http.ResponseWriter, r *http.Request)
Ports(w http.ResponseWriter, r *http.Request)
PutPorts(w http.ResponseWriter, r *http.Request)
PortOuterController(w http.ResponseWriter, r *http.Request)
PortInnerController(w http.ResponseWriter, r *http.Request)
RollBack(w http.ResponseWriter, r *http.Request)

View File

@ -0,0 +1,30 @@
// 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 cloud
import (
"chi"
)
//Routes routes
func Routes() chi.Router {
r := chi.NewRouter()
//r.Get("/show", controller.GetManager().Show)
return r
}

View File

@ -20,8 +20,8 @@ package version2
import (
"github.com/goodrain/rainbond/pkg/api/controller"
builder_controller "github.com/goodrain/rainbond/pkg/builder/api"
"github.com/goodrain/rainbond/pkg/api/middleware"
builder_controller "github.com/goodrain/rainbond/pkg/builder/api"
"github.com/go-chi/chi"
)
@ -41,7 +41,7 @@ func (v2 *V2) Routes() chi.Router {
r.Mount("/cluster", v2.clusterRouter())
r.Mount("/resources", v2.resourcesRouter())
r.Mount("/prometheus", v2.prometheusRouter())
r.Mount("/builder",builder_controller.APIServer())
r.Mount("/builder", builder_controller.APIServer())
return r
}
@ -124,7 +124,8 @@ func (v2 *V2) serviceRouter() chi.Router {
r.Delete("/env", controller.GetManager().Env)
//端口变量增删改(source)
r.Post("/ports", controller.GetManager().Ports)
r.Put("/ports", controller.GetManager().Ports)
r.Put("/ports", controller.GetManager().PutPorts)
r.Put("/ports/{port}", controller.GetManager().Ports)
r.Delete("/ports/{port}", controller.GetManager().Ports)
r.Put("/ports/{port}/outer", controller.GetManager().PortOuterController)
r.Put("/ports/{port}/inner", controller.GetManager().PortInnerController)

View File

@ -978,6 +978,42 @@ func (t *TenantStruct) Ports(w http.ResponseWriter, r *http.Request) {
}
}
//PutPorts PortVar
// swagger:operation PUT /v2/tenants/{tenant_name}/services/{service_alias}/ports v2 updatePort
//
// 更新应用端口信息(旧)
//
// update port
//
// ---
// consumes:
// - application/json
// - application/x-protobuf
//
// produces:
// - application/json
// - application/xml
//
// responses:
// default:
// schema:
// "$ref": "#/responses/commandResponse"
// description: 统一返回格式
func (t *TenantStruct) PutPorts(w http.ResponseWriter, r *http.Request) {
tenantID := r.Context().Value(middleware.ContextKey("tenant_id")).(string)
serviceID := r.Context().Value(middleware.ContextKey("service_id")).(string)
var ports api_model.ServicePorts
if ok := httputil.ValidatorRequestStructAndErrorResponse(r, w, &ports, nil); !ok {
return
}
if err := handler.GetServiceManager().PortVar("update", tenantID, serviceID, &ports, 0); err != nil {
logrus.Errorf("update port error. %v", err)
httputil.ReturnError(r, w, 500, err.Error())
return
}
httputil.ReturnSuccess(r, w, nil)
}
//AddPortVar PortVar
// swagger:operation POST /v2/tenants/{tenant_name}/services/{service_alias}/ports v2 addPort
//

View File

@ -798,6 +798,9 @@ func (s *ServiceAction) PortVar(action, tenantID, serviceID string, vps *api_mod
vpD.MappingPort = vp.MappingPort
vpD.Protocol = vp.Protocol
vpD.PortAlias = vp.PortAlias
if oldPort == 0 {
oldPort = vp.ContainerPort
}
if err := db.GetManager().TenantServicesPortDaoTransactions(tx).UpdateModel(vpD); err != nil {
logrus.Errorf("update port var error, %v", err)
tx.Rollback()
@ -1642,6 +1645,21 @@ func (s *ServiceAction) SetTenantServicePluginRelation(tenantID, serviceID strin
tx.Rollback()
return util.CreateAPIHandleErrorFromDBError("get plugin by plugin id", err)
}
catePlugin := strings.Split(plugin.PluginModel, ":")[0]
//TODO:检查是否存在该大类插件
crt, err := db.GetManager().TenantServicePluginRelationDao().CheckSomeModelLikePluginByServiceID(
serviceID,
catePlugin,
)
if err != nil {
tx.Rollback()
return util.CreateAPIHandleErrorFromDBError("check plugin model", err)
}
if crt {
tx.Rollback()
return util.CreateAPIHandleError(400, fmt.Errorf("can not add this kind plugin, a same kind plugin has been linked"))
}
if plugin.PluginModel == dbmodel.UpNetPlugin {
ports, err := db.GetManager().TenantServicesPortDao().GetPortsByServiceID(serviceID)
if err != nil {

View File

@ -30,8 +30,8 @@ import (
"github.com/goodrain/rainbond/pkg/api/apiRouters/doc"
"github.com/goodrain/rainbond/pkg/api/apiRouters/license"
//"github.com/goodrain/rainbond/pkg/api/apiRouters/cloud"
"github.com/goodrain/rainbond/pkg/api/apiRouters/version2"
"github.com/goodrain/rainbond/pkg/api/apiRouters/websocket"
apimiddleware "github.com/goodrain/rainbond/pkg/api/middleware"
@ -113,6 +113,7 @@ func (m *Manager) Run() {
v2R := &version2.V2{}
m.r.Mount("/v2", v2R.Routes())
//m.r.Mount("/cloud", cloud.Routes())
m.r.Mount("/", doc.Routes())
m.r.Mount("/license", license.Routes())
//兼容老版docker

View File

@ -129,6 +129,7 @@ type TenantServicePluginRelationDao interface {
GetALLRelationByServiceID(serviceID string) ([]*model.TenantServicePluginRelation, error)
GetRelateionByServiceIDAndPluginID(serviceID, pluginID string) (*model.TenantServicePluginRelation, error)
CheckSomeModelPluginByServiceID(serviceID, pluginModel string) (bool, error)
CheckSomeModelLikePluginByServiceID(serviceID, pluginModel string) (bool, error)
}
//TenantServiceRelationDao TenantServiceRelationDao

View File

@ -166,14 +166,18 @@ func (t *TenantServicesStreamPluginPort) TableName() string {
//Plugin model 插件标签
//TODO: 插件类型名规定
//@ 1. 插件大类 xxx-plugin
//@ 2. 大类细分 冒号+细分 xxx-plugin:up or xxx-plugin:down
//InitPlugin 初始化插件
var InitPlugin = "init-plugin"
//UpNetPlugin 上游网络插件
var UpNetPlugin = "upnet-plugin"
var UpNetPlugin = "net-plugin:up"
//DownNetPlugin 下游网络插件
var DownNetPlugin = "downnet-plugin"
var DownNetPlugin = "net-plugin:down"
//GeneralPlugin 一般插件,默认分类,优先级最低
var GeneralPlugin = "general-plugin"

View File

@ -370,6 +370,19 @@ func (t *TenantServicePluginRelationDaoImpl) CheckSomeModelPluginByServiceID(ser
return false, nil
}
//CheckSomeModelLikePluginByServiceID 检查是否绑定了某大类插件
func (t *TenantServicePluginRelationDaoImpl) CheckSomeModelLikePluginByServiceID(serviceID, pluginModel string) (bool, error) {
var relations []*model.TenantServicePluginRelation
catePlugin := "%" + pluginModel + "%"
if err := t.DB.Where("service_id=? and plugin_model LIKE ?", serviceID, catePlugin).Find(&relations).Error; err != nil {
return false, err
}
if len(relations) == 1 {
return true, nil
}
return false, nil
}
//DeleteALLRelationByServiceID 删除serviceID所有插件依赖 一般用于删除应用时使用
func (t *TenantServicePluginRelationDaoImpl) DeleteALLRelationByServiceID(serviceID string) error {
relation := &model.TenantServicePluginRelation{

View File

@ -13,9 +13,11 @@ gaops='git@code.goodrain.com:goodrain/gaops.git'
gitDescribe=$(git describe --tag|sed 's/^v//')
describe_items=($(echo $gitDescribe | tr '-' ' '))
branch_info=($(git branch | grep '^*' | cut -d ' ' -f 2 | tr '-' " "))
describe_len=${#describe_items[@]}
VERSION=${describe_items[0]}
git_commit=$(git log -n 1 --pretty --format=%h)
if [ $describe_len -ge 3 ];then
buildRelease=${describe_items[-2]}.${describe_items[-1]}
else
@ -25,6 +27,8 @@ if [ -z "$VERSION" ];then
VERSION=3.4
fi
release_desc=${branch_info}-${VERSION}-${buildRelease}
function prepare() {
rm -rf $releasedir
mkdir -pv $releasedir/{tmp,dist}
@ -44,8 +48,11 @@ function build() {
echo "---> Build Binary For ACP"
echo "build rainbond-node"
docker run -v `pwd`:${WORK_DIR} -w ${WORK_DIR} -it golang:1.8.3 go build -ldflags '-w -s' -o $releasedir/dist/usr/local/bin/${BASE_NAME}-node ./cmd/node
echo "grctl version:$release_desc"
sed -i "s/0.0.0/$release_desc/g" ./cmd/grctl/option/version.go
echo "build rainbond-grctl"
docker run -v `pwd`:${WORK_DIR} -w ${WORK_DIR} -it golang:1.8.3 go build -ldflags '-w -s' -o $releasedir/dist/usr/local/bin/${BASE_NAME}-grctl ./cmd/grctl
sed -i "s/$release_desc/0.0.0/g" ./cmd/grctl/option/version.go
}
function build::rpm() {
@ -61,9 +68,6 @@ function build::deb() {
function build::image() {
echo "---> Build Image:$1 FOR ACP"
git_commit=$(git log -n 1 --pretty --format=%h)
branch_info=($(git branch | grep '^*' | cut -d ' ' -f 2 | tr '-' " "))
release_desc=${branch_info}-${VERSION}-${buildRelease}
if [ "$1" = "eventlog" ];then
docker build -t goodraim.me/event-build:v1 ${DOCKER_PATH}/build
docker run --rm -v `pwd`:${WORK_DIR} -w ${WORK_DIR} goodraim.me/event-build:v1 go build -ldflags '-w -s' -o ${DOCKER_PATH}/${BASE_NAME}-$1 ./cmd/eventlog