Skip to content

Commit

Permalink
feat: adds custome_service table
Browse files Browse the repository at this point in the history
  • Loading branch information
ZhengYa-0110 committed Feb 14, 2025
1 parent d4877ce commit a37041e
Show file tree
Hide file tree
Showing 8 changed files with 90 additions and 0 deletions.
5 changes: 5 additions & 0 deletions server/controller/common/const.go
Original file line number Diff line number Diff line change
Expand Up @@ -720,3 +720,8 @@ const TRISOLARIS_NODE_TYPE_MASTER = "master"
const CLICK_HOUSE_VERSION = "24"

const TAP_TYPE_VALUE_CLOUD_NETWORK = 3

const (
CUSTOM_SERVICE_TYPE_IP = 1
CUSTOM_SERVICE_TYPE_PORT = 2
)
2 changes: 2 additions & 0 deletions server/controller/common/resource_type.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ const (
RESOURCE_TYPE_IP_EN = "ip"
RESOURCE_TYPE_ALL_IP_EN = "all_ip"
RESOURCE_TYPE_LB_RULE_EN = "lb_rule"

RESOURCE_TYPE_CUSTOM_SERVICE_EN = "custom_service"
)

var VIF_DEVICE_TYPE_TO_RESOURCE_TYPE = map[int]string{
Expand Down
4 changes: 4 additions & 0 deletions server/controller/common/uid.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,3 +111,7 @@ func GenerateKuberneteClusterIDByMD5(md5 string) (string, error) {
}
return "d-" + string(b2) + string(b8), nil
}

func GenerateVPCShortUUID() string {
return "vpc" + GenerateShortUUID()
}
16 changes: 16 additions & 0 deletions server/controller/db/metadb/migrator/schema/rawsql/mysql/init.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2635,3 +2635,19 @@ CREATE TABLE IF NOT EXISTS ch_user (
updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
)ENGINE=innodb DEFAULT CHARSET=utf8;
TRUNCATE TABLE ch_user;

CREATE TABLE IF NOT EXISTS custom_service (
id INTEGER NOT NULL AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(128) NOT NULL,
team_id INTEGER DEFAULT 1,
type INTEGER DEFAULT 0 COMMENT '0: unknown 1: IP 2: PORT',
resource TEXT DEFAULT '',
epc_id INTEGER DEFAULT 0,
domain_id INTEGER DEFAULT 0,
domain CHAR(64) DEFAULT '' COMMENT 'reserved for backend',
lcuuid CHAR(64) DEFAULT '',
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
updated_at DATETIME NOT NULL ON UPDATE CURRENT_TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
UNIQUE INDEX name_index(name)
) ENGINE=innodb DEFAULT CHARSET=utf8 AUTO_INCREMENT=1;
TRUNCATE TABLE custom_service;
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
CREATE TABLE IF NOT EXISTS custom_service (
id INTEGER NOT NULL AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(128) NOT NULL,
team_id INTEGER DEFAULT 1,
type INTEGER DEFAULT 0 COMMENT '0: unknown 1: IP 2: PORT',
resource TEXT DEFAULT '',
epc_id INTEGER DEFAULT 0,
domain_id INTEGER DEFAULT 0,
domain CHAR(64) DEFAULT '' COMMENT 'reserved for backend',
lcuuid CHAR(64) DEFAULT '',
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
updated_at DATETIME NOT NULL ON UPDATE CURRENT_TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
UNIQUE INDEX name_index(name)
) ENGINE=innodb DEFAULT CHARSET=utf8 AUTO_INCREMENT=1;

UPDATE db_version SET version='7.0.1.9';
Original file line number Diff line number Diff line change
Expand Up @@ -2774,3 +2774,21 @@ CREATE TABLE IF NOT EXISTS ch_user (
updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP
);
TRUNCATE TABLE ch_user;

CREATE TABLE IF NOT EXISTS custom_service (
id SERIAL PRIMARY KEY,
name VARCHAR(128) NOT NULL,
team_id INTEGER DEFAULT 1,
epc_id INTEGER DEFAULT 0,
type INTEGER DEFAULT 0,
resource TEXT DEFAULT '',
domain_id INTEGER DEFAULT 0,
domain CHAR(64) DEFAULT '',
lcuuid CHAR(64) DEFAULT '',
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP
);
TRUNCATE TABLE custom_service;
CREATE UNIQUE INDEX IF NOT EXISTS custom_service_name_idx ON custom_service(name);
COMMENT ON COLUMN custom_service.type IS '0: unknown 1: IP 2: PORT';
COMMENT ON COLUMN custom_service.domain IS 'reserved for backend';
16 changes: 16 additions & 0 deletions server/controller/db/metadb/model/platform_rsc_model.go
Original file line number Diff line number Diff line change
Expand Up @@ -995,3 +995,19 @@ func (p Pod) GetDomainLcuuid() string {
func (p Pod) GetSubDomainLcuuid() string {
return p.SubDomain
}

type CustomService struct {
Base `gorm:"embedded" mapstructure:",squash"`
OperatedTime `gorm:"embedded" mapstructure:",squash"`
Name string `gorm:"column:name;type:varchar(128);default:''" json:"NAME" mapstructure:"NAME"`
TeamID int `gorm:"column:team_id;type:int;default:0" json:"TEAM_ID" mapstructure:"TEAM_ID"`
VPCID int `gorm:"column:epc_id;type:int;default:0" json:"VPC_ID" mapstructure:"EPC_ID"`
Type int `gorm:"column:type;type:int;default:0" json:"TYPE" mapstructure:"TYPE"`
Resource string `gorm:"column:resource;type:text;default:''" json:"RESOURCE" mapstructure:"RESOURCE"`
DomainID int `gorm:"column:domain_id;type:int;default:0" json:"DOMAIN_ID" mapstructure:"DOMAIN_ID"`
Domain string `gorm:"column:domain;type:char(64);not null" json:"DOMAIN" mapstructure:"DOMAIN"`
}

func (CustomService) TableName() string {
return "custom_service"
}
13 changes: 13 additions & 0 deletions server/controller/recorder/updater/vpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package updater

import (
cloudmodel "github.com/deepflowio/deepflow/server/controller/cloud/model"
"github.com/deepflowio/deepflow/server/controller/common"
ctrlrcommon "github.com/deepflowio/deepflow/server/controller/common"
metadbmodel "github.com/deepflowio/deepflow/server/controller/db/metadb/model"
"github.com/deepflowio/deepflow/server/controller/recorder/cache"
Expand Down Expand Up @@ -74,6 +75,9 @@ func (v *VPC) getDiffBaseByCloudItem(cloudItem *cloudmodel.VPC) (diffBase *diffb
}

func (v *VPC) generateDBItemToAdd(cloudItem *cloudmodel.VPC) (*metadbmodel.VPC, bool) {
if cloudItem.Label == "" {
cloudItem.Label = common.GenerateVPCShortUUID()
}
dbItem := &metadbmodel.VPC{
Name: cloudItem.Name,
Label: cloudItem.Label,
Expand All @@ -95,9 +99,18 @@ func (v *VPC) generateUpdateInfo(diffBase *diffbase.VPC, cloudItem *cloudmodel.V
mapInfo["name"] = cloudItem.Name
structInfo.Name.Set(diffBase.Name, cloudItem.Name)
}

if cloudItem.Label == "" {
if diffBase.Label == "" {
cloudItem.Label = common.GenerateVPCShortUUID()
} else {
cloudItem.Label = diffBase.Label
}
}
if diffBase.Label != cloudItem.Label {
mapInfo["label"] = cloudItem.Label
structInfo.Label.Set(diffBase.Label, cloudItem.Label)
mapInfo["uid"] = cloudItem.Label
}
if diffBase.RegionLcuuid != cloudItem.RegionLcuuid {
mapInfo["region"] = cloudItem.RegionLcuuid
Expand Down

0 comments on commit a37041e

Please sign in to comment.