From 1282b0f36d0aa029459256f85d3547355315c953 Mon Sep 17 00:00:00 2001 From: kangxiang Date: Fri, 10 Jan 2025 10:12:58 +0800 Subject: [PATCH] feat: add cloud common for fc --- cli/ctl/common/const.go | 2 ++ server/controller/cloud/cloud.go | 18 +++++++--- server/controller/cloud/config/config.go | 42 ++++++++++++++---------- server/controller/common/const.go | 17 ++++++---- server/server.yaml | 4 +++ 5 files changed, 53 insertions(+), 30 deletions(-) diff --git a/cli/ctl/common/const.go b/cli/ctl/common/const.go index 1e2099f09ca..4e4d2c787a8 100644 --- a/cli/ctl/common/const.go +++ b/cli/ctl/common/const.go @@ -64,6 +64,7 @@ const ( DOMAIN_TYPE_SUGON DomainType = 29 // sugon DOMAIN_TYPE_VOLCENGINE DomainType = 30 // volcengine DOMAIN_TYPE_H3C DomainType = 31 // h3c + DOMAIN_TYPE_FUSIONCOMPUTE DomainType = 32 // fusioncompute ) var DomainTypes []DomainType = []DomainType{ @@ -91,6 +92,7 @@ var DomainTypes []DomainType = []DomainType{ DOMAIN_TYPE_SUGON, DOMAIN_TYPE_VOLCENGINE, DOMAIN_TYPE_H3C, + DOMAIN_TYPE_FUSIONCOMPUTE, } func GetDomainTypeByName(domainTypeName string) DomainType { diff --git a/server/controller/cloud/cloud.go b/server/controller/cloud/cloud.go index cd4251406d2..a71edbc910b 100644 --- a/server/controller/cloud/cloud.go +++ b/server/controller/cloud/cloud.go @@ -77,11 +77,19 @@ func NewCloud(orgID int, domain mysql.Domain, cfg config.CloudConfig, ctx contex } // maybe all types will be supported later + var triggerTimeString string + switch domain.Type { + case common.QINGCLOUD, common.QINGCLOUD_PRIVATE: + triggerTimeString = cfg.QingCloudConfig.DailyTriggerTime + case common.FUSIONCOMPUTE: + triggerTimeString = cfg.FusionComputeConfig.DailyTriggerTime + default: + } var triggerTime time.Time - if domain.Type == common.QINGCLOUD || domain.Type == common.QINGCLOUD_PRIVATE { - triggerTime, err = time.ParseInLocation("15:04", cfg.QingCloudConfig.DailyTriggerTime, time.Local) + if triggerTimeString != "" { + triggerTime, err = time.ParseInLocation("15:04", triggerTimeString, time.Local) if err != nil { - log.Errorf("parse qing config daily trigger time failed: (%s)", err.Error()) + log.Errorf("parse cloud daily trigger time config failed: (%s)", err.Error()) } } @@ -272,8 +280,8 @@ func (c *Cloud) GetStatter() statsd.StatsdStatter { } func (c *Cloud) getCloudGatherInterval() int { - if (c.basicInfo.Type == common.QINGCLOUD || c.basicInfo.Type == common.QINGCLOUD_PRIVATE) && c.cfg.QingCloudConfig.DailyTriggerTime != "" { - log.Infof("qing and qing private daily trigger time is (%s), sync timer is default (%d)s", c.cfg.QingCloudConfig.DailyTriggerTime, cloudcommon.CLOUD_SYNC_TIMER_DEFAULT) + if !c.triggerTime.IsZero() { + log.Infof("cloud (%s) daily trigger time is (%s), sync timer is default (%d)s", c.basicInfo.Name, c.triggerTime.Format("15:04"), cloudcommon.CLOUD_SYNC_TIMER_DEFAULT) return cloudcommon.CLOUD_SYNC_TIMER_DEFAULT } var domain mysql.Domain diff --git a/server/controller/cloud/config/config.go b/server/controller/cloud/config/config.go index 1ec3d3c5b89..31e21e062fc 100644 --- a/server/controller/cloud/config/config.go +++ b/server/controller/cloud/config/config.go @@ -25,28 +25,34 @@ type QingCloudConfig struct { DisableSyncLBListener bool `default:"false" yaml:"disable_sync_lb_listener"` // disable sync for lb listener and target server } +type FusionComputeConfig struct { + DailyTriggerTime string `default:"" yaml:"daily_trigger_time"` // %H:%M 05:00 +} + type CloudConfig struct { - KubernetesGatherInterval uint32 `default:"30" yaml:"kubernetes_gather_interval"` - AliyunRegionName string `default:"cn-beijing" yaml:"aliyun_region_name"` - AWSRegionName string `default:"cn-north-1" yaml:"aws_region_name"` - HostnameToIPFile string `default:"/etc/hostname_to_ip.csv" yaml:"hostname_to_ip_file"` - DNSEnable bool `default:"false" yaml:"dns_enable"` - HTTPTimeout int `default:"30" yaml:"http_timeout"` - CustomTagLenMax int `default:"256" yaml:"custom_tag_len_max"` - ProcessNameLenMax int `default:"256" yaml:"process_name_len_max"` - DebugEnabled bool `default:"false" yaml:"debug_enabled"` - QingCloudConfig QingCloudConfig `yaml:"qingcloud_config"` + KubernetesGatherInterval uint32 `default:"30" yaml:"kubernetes_gather_interval"` + AliyunRegionName string `default:"cn-beijing" yaml:"aliyun_region_name"` + AWSRegionName string `default:"cn-north-1" yaml:"aws_region_name"` + HostnameToIPFile string `default:"/etc/hostname_to_ip.csv" yaml:"hostname_to_ip_file"` + DNSEnable bool `default:"false" yaml:"dns_enable"` + HTTPTimeout int `default:"30" yaml:"http_timeout"` + CustomTagLenMax int `default:"256" yaml:"custom_tag_len_max"` + ProcessNameLenMax int `default:"256" yaml:"process_name_len_max"` + DebugEnabled bool `default:"false" yaml:"debug_enabled"` + QingCloudConfig QingCloudConfig `yaml:"qingcloud_config"` + FusionComputeConfig FusionComputeConfig `yaml:"fusioncompute_config"` } func SetCloudGlobalConfig(c CloudConfig) { CONF = &CloudConfig{ - HostnameToIPFile: c.HostnameToIPFile, - DNSEnable: c.DNSEnable, - HTTPTimeout: c.HTTPTimeout, - DebugEnabled: c.DebugEnabled, - AWSRegionName: c.AWSRegionName, - CustomTagLenMax: c.CustomTagLenMax, - ProcessNameLenMax: c.ProcessNameLenMax, - QingCloudConfig: c.QingCloudConfig, + HostnameToIPFile: c.HostnameToIPFile, + DNSEnable: c.DNSEnable, + HTTPTimeout: c.HTTPTimeout, + DebugEnabled: c.DebugEnabled, + AWSRegionName: c.AWSRegionName, + CustomTagLenMax: c.CustomTagLenMax, + ProcessNameLenMax: c.ProcessNameLenMax, + QingCloudConfig: c.QingCloudConfig, + FusionComputeConfig: c.FusionComputeConfig, } } diff --git a/server/controller/common/const.go b/server/controller/common/const.go index 88ee8c6ee2a..47e49043d8c 100644 --- a/server/controller/common/const.go +++ b/server/controller/common/const.go @@ -297,6 +297,7 @@ const ( SUGON = 29 VOLCENGINE = 30 H3C = 31 + FUSIONCOMPUTE = 32 OPENSTACK_EN = "openstack" VSPHERE_EN = "vsphere" @@ -328,6 +329,7 @@ const ( SUGON_EN = "sugon" VOLCENGINE_EN = "volcengine" H3C_EN = "h3c" + FUSIONCOMPUTE_EN = "fusioncompute" TENCENT_CH = "腾讯云" ALIYUN_CH = "阿里云" @@ -342,13 +344,14 @@ const ( VOLCENGINE_CH = "火山云" H3C_CH = "华三云" - OPENSTACK_CH = "OpenStack" - VSPHERE_CH = "vSphere" - NSP_CH = "NSP" - AWS_CH = "AWS" - ZSTACK_CH = "ZStack" - KUBERNETES_CH = "Kubernetes" - CLOUD_TOWER_CH = "CloudTower" + OPENSTACK_CH = "OpenStack" + VSPHERE_CH = "vSphere" + NSP_CH = "NSP" + AWS_CH = "AWS" + ZSTACK_CH = "ZStack" + KUBERNETES_CH = "Kubernetes" + CLOUD_TOWER_CH = "CloudTower" + FUSIONCOMPUTE_CH = "FusionCompute" ) var DomainTypeToIconID = map[int]int{ diff --git a/server/server.yaml b/server/server.yaml index 58aedd65e6d..b9f994330f0 100644 --- a/server/server.yaml +++ b/server/server.yaml @@ -211,6 +211,10 @@ controller: daily_trigger_time: "" # 关闭 lb 监听器及后端主机对接 disable_sync_lb_listener: false + # fc配置 + fusioncompute_config: + # 对接 fusioncompute 定时执行,根据配置的时间点每日执行一次,配置后循环执行失效,格式:%H:%M ,例:05:30 ,每日5点30分执行一次对接 + daily_trigger_time: "" recorder: # recorder模块缓存自愈刷新时间间隔,单位:分钟 cache_refresh_interval: 60