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.
|
||||
func (g *GatewayAction) AddTcpRule(req *apimodel.TcpRuleStruct) error {
|
||||
tcpRule := &model.TcpRule{
|
||||
UUID: util.NewUUID(),
|
||||
UUID: req.TcpRuleId,
|
||||
ServiceID: req.ServiceID,
|
||||
ContainerPort: req.ContainerPort,
|
||||
IP: req.IP,
|
||||
@ -262,8 +262,7 @@ func (g *GatewayAction) UpdateTcpRule(req *apimodel.TcpRuleStruct) error {
|
||||
// begin transaction
|
||||
tx := db.GetManager().Begin()
|
||||
// get old tcp rule
|
||||
tcpRule, err := g.dbmanager.TcpRuleDaoTransactions(tx).GetTcpRuleByServiceIDAndContainerPort(req.ServiceID,
|
||||
req.ContainerPort)
|
||||
tcpRule, err := g.dbmanager.TcpRuleDaoTransactions(tx).GetTcpRuleByID(req.TcpRuleId)
|
||||
if err != nil {
|
||||
tx.Rollback()
|
||||
return err
|
||||
@ -274,6 +273,8 @@ func (g *GatewayAction) UpdateTcpRule(req *apimodel.TcpRuleStruct) error {
|
||||
return err
|
||||
}
|
||||
// update tcp rule
|
||||
tcpRule.ServiceID = req.ServiceID
|
||||
tcpRule.ContainerPort = req.ContainerPort
|
||||
tcpRule.IP = req.IP
|
||||
tcpRule.Port = req.Port
|
||||
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 {
|
||||
// begin transaction
|
||||
tx := db.GetManager().Begin()
|
||||
tcpRule, err := db.GetManager().TcpRuleDaoTransactions(tx).GetTcpRuleByServiceIDAndContainerPort(req.ServiceID,
|
||||
req.ContainerPort)
|
||||
tcpRule, err := db.GetManager().TcpRuleDaoTransactions(tx).GetTcpRuleByID(req.TcpRuleId)
|
||||
if err != nil {
|
||||
tx.Rollback()
|
||||
return err
|
||||
|
@ -20,7 +20,7 @@ package model
|
||||
|
||||
//HttpRuleStruct -
|
||||
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"`
|
||||
ContainerPort int `json:"container_port"`
|
||||
Domain string `json:"domain"`
|
||||
@ -36,9 +36,9 @@ type HttpRuleStruct struct {
|
||||
}
|
||||
|
||||
type TcpRuleStruct struct {
|
||||
//TcpRuleId string `json:"tcp_rule_id" validate:"tcp_rule_id:required"`
|
||||
ServiceID string `json:"service_id" validate:"service_id|required"`
|
||||
ContainerPort int `json:"container_port" validate:"container_port|required"`
|
||||
TcpRuleId string `json:"tcp_rule_id" validate:"tcp_rule_id|required"`
|
||||
ServiceID string `json:"service_id"`
|
||||
ContainerPort int `json:"container_port"`
|
||||
IP string `json:"ip"`
|
||||
Port int `json:"port"`
|
||||
RuleExtensions []*RuleExtensionStruct `json:"rule_extensions"`
|
||||
|
@ -432,5 +432,6 @@ type HttpRuleDao interface {
|
||||
type TcpRuleDao interface {
|
||||
Dao
|
||||
GetTcpRuleByServiceIDAndContainerPort(serviceID string, containerPort int) (*model.TcpRule, error)
|
||||
GetTcpRuleByID(id string) (*model.TcpRule, error)
|
||||
DeleteTcpRule(tcpRule *model.TcpRule) error
|
||||
}
|
||||
|
@ -245,6 +245,18 @@ func (s *TcpRuleDaoTmpl) GetTcpRuleByServiceIDAndContainerPort(serviceID string,
|
||||
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 {
|
||||
return s.DB.Where("uuid = ?", tcpRule.UUID).Delete(tcpRule).Error
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user