[ADD] Add region support protocol list

This commit is contained in:
pujielan 2018-01-02 18:04:51 +08:00
parent 28c5c9bff0
commit 695f189bcf
2 changed files with 132 additions and 0 deletions

54
pkg/db/model/protocol.go Normal file
View File

@ -0,0 +1,54 @@
// 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
import "time"
//TableName 表名
func (t *RegionProcotols) TableName() string {
return "region_protocols"
}
//RegionProcotols RegionProcotol
type RegionProcotols struct {
ID uint `gorm:"column:ID"`
CreatedAt time.Time `gorm:"column:create_time"`
ProtocolGroup string `gorm:"column:protocol_group;size:32;primary_key" json:"protocol_group"`
ProtocolChild string `gorm:"column:protocol_child;size:32;primary_key" json:"protocol_child"`
APIVersion string `gorm:"column:api_version;size:8" json:"api_version"`
IsSupport bool `gorm:"column:is_support;default:false" json:"is_support"`
}
//STREAMGROUP STREAMGROUP
var STREAMGROUP = "stream"
//HTTPGROUP HTTPGROUP
var HTTPGROUP = "http"
//MYSQLPROTOCOL MYSQLPROTOCOL
var MYSQLPROTOCOL = "mysql"
//UDPPROTOCOL UDPPROTOCOL
var UDPPROTOCOL = "udp"
//TCPPROTOCOL TCPPROTOCOL
var TCPPROTOCOL = "tcp"
//V2VERSION region version
var V2VERSION = "v2"

View File

@ -0,0 +1,78 @@
// 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/jinzhu/gorm"
"github.com/goodrain/rainbond/pkg/db/model"
)
//RegionProcotolsDaoImpl RegionProcotolsDaoImpl
type RegionProcotolsDaoImpl struct {
DB *gorm.DB
}
//AddModel 添加cloud信息
func (t *RegionProcotolsDaoImpl) AddModel(mo model.Interface) error {
info := mo.(*model.RegionProcotols)
var oldInfo model.RegionProcotols
if ok := t.DB.Where("protocol_group = ? and ProtocolChild = ?", info.ProtocolGroup, info.ProtocolChild).Find(&oldInfo).RecordNotFound(); ok {
if err := t.DB.Create(info).Error; err != nil {
return err
}
} else {
return fmt.Errorf("prococol group %s or child %s is exist", info.ProtocolGroup, info.ProtocolChild)
}
return nil
}
//UpdateModel 更新cloud信息
func (t *RegionProcotolsDaoImpl) UpdateModel(mo model.Interface) error {
info := mo.(*model.RegionProcotols)
if info.ID == 0 {
return fmt.Errorf("region protocol id can not be empty when update ")
}
if err := t.DB.Save(info).Error; err != nil {
return err
}
return nil
}
//GetAllSupportProtocol 获取当前数据中心支持的所有协议
func (t *RegionProcotolsDaoImpl) GetAllSupportProtocol(version string) ([]*model.RegionProcotols, error) {
var rpss []*model.RegionProcotols
if err := t.DB.Where("api_version= ? and is_support = 1", version).Find(&rpss).Error; err != nil {
return nil, err
}
return rpss, nil
}
//GetProtocolGroupByProtocolChild 获取协议族名称
func (t *RegionProcotolsDaoImpl) GetProtocolGroupByProtocolChild(
version,
protocolChild string) (*model.RegionProcotols, error) {
var rps model.RegionProcotols
if err := t.DB.Where("api_version=? and protocol_child = ?", version, protocolChild).Find(&rps).Error; err != nil {
return nil, err
}
return &rps, nil
}