mirror of
https://gitee.com/rainbond/Rainbond.git
synced 2024-11-30 02:38:17 +08:00
[ADD] add uuid for TcpRuleStruct
This commit is contained in:
parent
0a20990804
commit
6bb5216e10
@ -222,7 +222,7 @@ func (g *GatewayAction) UpdateCertificate(req apimodel.HttpRuleStruct, httpRule
|
|||||||
// AddTcpRule adds tcp rule.
|
// AddTcpRule adds tcp rule.
|
||||||
func (g *GatewayAction) AddTcpRule(req *apimodel.TcpRuleStruct) error {
|
func (g *GatewayAction) AddTcpRule(req *apimodel.TcpRuleStruct) error {
|
||||||
tcpRule := &model.TcpRule{
|
tcpRule := &model.TcpRule{
|
||||||
UUID: util.NewUUID(),
|
UUID: req.TcpRuleId,
|
||||||
ServiceID: req.ServiceID,
|
ServiceID: req.ServiceID,
|
||||||
ContainerPort: req.ContainerPort,
|
ContainerPort: req.ContainerPort,
|
||||||
IP: req.IP,
|
IP: req.IP,
|
||||||
@ -262,8 +262,7 @@ func (g *GatewayAction) UpdateTcpRule(req *apimodel.TcpRuleStruct) error {
|
|||||||
// begin transaction
|
// begin transaction
|
||||||
tx := db.GetManager().Begin()
|
tx := db.GetManager().Begin()
|
||||||
// get old tcp rule
|
// get old tcp rule
|
||||||
tcpRule, err := g.dbmanager.TcpRuleDaoTransactions(tx).GetTcpRuleByServiceIDAndContainerPort(req.ServiceID,
|
tcpRule, err := g.dbmanager.TcpRuleDaoTransactions(tx).GetTcpRuleByID(req.TcpRuleId)
|
||||||
req.ContainerPort)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
tx.Rollback()
|
tx.Rollback()
|
||||||
return err
|
return err
|
||||||
@ -274,6 +273,8 @@ func (g *GatewayAction) UpdateTcpRule(req *apimodel.TcpRuleStruct) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
// update tcp rule
|
// update tcp rule
|
||||||
|
tcpRule.ServiceID = req.ServiceID
|
||||||
|
tcpRule.ContainerPort = req.ContainerPort
|
||||||
tcpRule.IP = req.IP
|
tcpRule.IP = req.IP
|
||||||
tcpRule.Port = req.Port
|
tcpRule.Port = req.Port
|
||||||
if err := g.dbmanager.TcpRuleDaoTransactions(tx).UpdateModel(tcpRule); err != nil {
|
if err := g.dbmanager.TcpRuleDaoTransactions(tx).UpdateModel(tcpRule); err != nil {
|
||||||
@ -305,8 +306,7 @@ func (g *GatewayAction) UpdateTcpRule(req *apimodel.TcpRuleStruct) error {
|
|||||||
func (g *GatewayAction) DeleteTcpRule(req *apimodel.TcpRuleStruct) error {
|
func (g *GatewayAction) DeleteTcpRule(req *apimodel.TcpRuleStruct) error {
|
||||||
// begin transaction
|
// begin transaction
|
||||||
tx := db.GetManager().Begin()
|
tx := db.GetManager().Begin()
|
||||||
tcpRule, err := db.GetManager().TcpRuleDaoTransactions(tx).GetTcpRuleByServiceIDAndContainerPort(req.ServiceID,
|
tcpRule, err := db.GetManager().TcpRuleDaoTransactions(tx).GetTcpRuleByID(req.TcpRuleId)
|
||||||
req.ContainerPort)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
tx.Rollback()
|
tx.Rollback()
|
||||||
return err
|
return err
|
||||||
|
@ -20,7 +20,7 @@ package model
|
|||||||
|
|
||||||
//HttpRuleStruct -
|
//HttpRuleStruct -
|
||||||
type HttpRuleStruct struct {
|
type HttpRuleStruct struct {
|
||||||
HttpRuleID string `json:"http_rule_id" validate:"http_rule_id:required"`
|
HttpRuleID string `json:"http_rule_id" validate:"http_rule_id|required"`
|
||||||
ServiceID string `json:"service_id"`
|
ServiceID string `json:"service_id"`
|
||||||
ContainerPort int `json:"container_port"`
|
ContainerPort int `json:"container_port"`
|
||||||
Domain string `json:"domain"`
|
Domain string `json:"domain"`
|
||||||
@ -36,9 +36,9 @@ type HttpRuleStruct struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type TcpRuleStruct struct {
|
type TcpRuleStruct struct {
|
||||||
//TcpRuleId string `json:"tcp_rule_id" validate:"tcp_rule_id:required"`
|
TcpRuleId string `json:"tcp_rule_id" validate:"tcp_rule_id|required"`
|
||||||
ServiceID string `json:"service_id" validate:"service_id|required"`
|
ServiceID string `json:"service_id"`
|
||||||
ContainerPort int `json:"container_port" validate:"container_port|required"`
|
ContainerPort int `json:"container_port"`
|
||||||
IP string `json:"ip"`
|
IP string `json:"ip"`
|
||||||
Port int `json:"port"`
|
Port int `json:"port"`
|
||||||
RuleExtensions []*RuleExtensionStruct `json:"rule_extensions"`
|
RuleExtensions []*RuleExtensionStruct `json:"rule_extensions"`
|
||||||
|
@ -432,5 +432,6 @@ type HttpRuleDao interface {
|
|||||||
type TcpRuleDao interface {
|
type TcpRuleDao interface {
|
||||||
Dao
|
Dao
|
||||||
GetTcpRuleByServiceIDAndContainerPort(serviceID string, containerPort int) (*model.TcpRule, error)
|
GetTcpRuleByServiceIDAndContainerPort(serviceID string, containerPort int) (*model.TcpRule, error)
|
||||||
|
GetTcpRuleByID(id string) (*model.TcpRule, error)
|
||||||
DeleteTcpRule(tcpRule *model.TcpRule) error
|
DeleteTcpRule(tcpRule *model.TcpRule) error
|
||||||
}
|
}
|
||||||
|
@ -245,6 +245,18 @@ func (s *TcpRuleDaoTmpl) GetTcpRuleByServiceIDAndContainerPort(serviceID string,
|
|||||||
return result, nil
|
return result, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetTcpRuleByID gets a TcpRule based on tcpRuleID
|
||||||
|
func (s *TcpRuleDaoTmpl) GetTcpRuleByID(id string) (*model.TcpRule, error) {
|
||||||
|
result := &model.TcpRule{}
|
||||||
|
if err := s.DB.Where("uuid = ?", id).Find(result).Error; err != nil {
|
||||||
|
if err == gorm.ErrRecordNotFound {
|
||||||
|
return result, nil
|
||||||
|
}
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return result, nil
|
||||||
|
}
|
||||||
|
|
||||||
func (s *TcpRuleDaoTmpl) DeleteTcpRule(tcpRule *model.TcpRule) error {
|
func (s *TcpRuleDaoTmpl) DeleteTcpRule(tcpRule *model.TcpRule) error {
|
||||||
return s.DB.Where("uuid = ?", tcpRule.UUID).Delete(tcpRule).Error
|
return s.DB.Where("uuid = ?", tcpRule.UUID).Delete(tcpRule).Error
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user