2023-12-31 15:26:53 +08:00
|
|
|
package config
|
2023-12-30 17:38:08 +08:00
|
|
|
|
|
|
|
import (
|
2024-01-09 17:30:58 +08:00
|
|
|
"errors"
|
2024-03-26 14:54:50 +08:00
|
|
|
"github.com/aceld/kis-flow/common"
|
|
|
|
"github.com/aceld/kis-flow/log"
|
2023-12-30 17:38:08 +08:00
|
|
|
)
|
|
|
|
|
2024-04-15 17:50:02 +08:00
|
|
|
// FParam represents the type for custom fixed configuration parameters for the Function in the current Flow
|
2023-12-30 17:38:08 +08:00
|
|
|
type FParam map[string]string
|
|
|
|
|
2024-04-15 17:50:02 +08:00
|
|
|
// KisSource represents the business source of the current Function
|
2023-12-30 17:38:08 +08:00
|
|
|
type KisSource struct {
|
2024-04-15 17:50:02 +08:00
|
|
|
Name string `yaml:"name"` // Description of the data source for this layer Function
|
|
|
|
Must []string `yaml:"must"` // Required fields for the source
|
2023-12-30 17:38:08 +08:00
|
|
|
}
|
|
|
|
|
2024-04-15 17:50:02 +08:00
|
|
|
// KisFuncOption represents optional configurations
|
2023-12-30 17:38:08 +08:00
|
|
|
type KisFuncOption struct {
|
2024-04-15 17:50:02 +08:00
|
|
|
CName string `yaml:"cname"` // Connector name
|
|
|
|
RetryTimes int `yaml:"retry_times"` // Optional, maximum retry times for Function scheduling (excluding normal scheduling)
|
|
|
|
RetryDuration int `yaml:"return_duration"` // Optional, maximum time interval for each retry in Function scheduling (unit: ms)
|
|
|
|
Params FParam `yaml:"default_params"` // Optional, custom fixed configuration parameters for the Function in the current Flow
|
2023-12-30 17:38:08 +08:00
|
|
|
}
|
|
|
|
|
2024-04-15 17:50:02 +08:00
|
|
|
// KisFuncConfig represents a KisFunction strategy configuration
|
2023-12-30 17:38:08 +08:00
|
|
|
type KisFuncConfig struct {
|
2024-01-09 17:30:58 +08:00
|
|
|
KisType string `yaml:"kistype"`
|
|
|
|
FName string `yaml:"fname"`
|
|
|
|
FMode string `yaml:"fmode"`
|
|
|
|
Source KisSource `yaml:"source"`
|
|
|
|
Option KisFuncOption `yaml:"option"`
|
|
|
|
connConf *KisConnConfig
|
2023-12-30 17:38:08 +08:00
|
|
|
}
|
|
|
|
|
2024-04-15 17:50:02 +08:00
|
|
|
// NewFuncConfig creates a Function strategy configuration object, used to describe a KisFunction information
|
2023-12-30 17:38:08 +08:00
|
|
|
func NewFuncConfig(
|
2024-01-03 10:16:54 +08:00
|
|
|
funcName string, mode common.KisMode,
|
2023-12-30 17:38:08 +08:00
|
|
|
source *KisSource, option *KisFuncOption) *KisFuncConfig {
|
|
|
|
|
|
|
|
config := new(KisFuncConfig)
|
2024-01-03 10:16:54 +08:00
|
|
|
config.FName = funcName
|
2023-12-30 17:38:08 +08:00
|
|
|
|
|
|
|
if source == nil {
|
2024-03-26 14:41:49 +08:00
|
|
|
defaultSource := KisSource{
|
|
|
|
Name: "unNamedSource",
|
|
|
|
}
|
|
|
|
source = &defaultSource
|
2024-04-15 11:17:47 +08:00
|
|
|
log.Logger().InfoF("funcName NewConfig source is nil, funcName = %s, use default unNamed Source.", funcName)
|
2023-12-30 17:38:08 +08:00
|
|
|
}
|
|
|
|
config.Source = *source
|
|
|
|
|
2024-01-03 10:16:54 +08:00
|
|
|
config.FMode = string(mode)
|
2023-12-30 17:38:08 +08:00
|
|
|
|
2024-04-03 18:44:00 +08:00
|
|
|
/*
|
2024-04-15 17:50:02 +08:00
|
|
|
// Functions S and L require the KisConnector parameters to be passed as they need to establish streaming relationships through Connector
|
2024-04-03 18:44:00 +08:00
|
|
|
if mode == common.S || mode == common.L {
|
|
|
|
if option == nil {
|
2024-04-15 17:50:02 +08:00
|
|
|
log.Logger().ErrorF("Function S/L needs option->Cid\n")
|
2024-04-03 18:44:00 +08:00
|
|
|
return nil
|
|
|
|
} else if option.CName == "" {
|
2024-04-15 17:50:02 +08:00
|
|
|
log.Logger().ErrorF("Function S/L needs option->Cid\n")
|
2024-04-03 18:44:00 +08:00
|
|
|
return nil
|
|
|
|
}
|
2023-12-30 17:38:08 +08:00
|
|
|
}
|
2024-04-03 18:44:00 +08:00
|
|
|
*/
|
2023-12-30 17:38:08 +08:00
|
|
|
|
|
|
|
if option != nil {
|
|
|
|
config.Option = *option
|
|
|
|
}
|
|
|
|
|
|
|
|
return config
|
|
|
|
}
|
2024-01-09 17:30:58 +08:00
|
|
|
|
2024-04-15 17:50:02 +08:00
|
|
|
// AddConnConfig WithConn binds Function to Connector
|
2024-01-09 17:30:58 +08:00
|
|
|
func (fConf *KisFuncConfig) AddConnConfig(cConf *KisConnConfig) error {
|
|
|
|
if cConf == nil {
|
|
|
|
return errors.New("KisConnConfig is nil")
|
|
|
|
}
|
|
|
|
|
2024-04-15 17:50:02 +08:00
|
|
|
// Function needs to be associated with Connector
|
2024-01-09 17:30:58 +08:00
|
|
|
fConf.connConf = cConf
|
|
|
|
|
2024-04-15 17:50:02 +08:00
|
|
|
// Connector needs to be associated with Function
|
2024-01-09 17:30:58 +08:00
|
|
|
_ = cConf.WithFunc(fConf)
|
|
|
|
|
2024-04-15 17:50:02 +08:00
|
|
|
// Update CName in Function configuration
|
2024-04-03 19:06:46 +08:00
|
|
|
fConf.Option.CName = cConf.CName
|
|
|
|
|
2024-01-09 17:30:58 +08:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2024-04-15 17:50:02 +08:00
|
|
|
// GetConnConfig gets the Connector configuration
|
2024-01-09 17:30:58 +08:00
|
|
|
func (fConf *KisFuncConfig) GetConnConfig() (*KisConnConfig, error) {
|
|
|
|
if fConf.connConf == nil {
|
|
|
|
return nil, errors.New("KisFuncConfig.connConf not set")
|
|
|
|
}
|
|
|
|
|
|
|
|
return fConf.connConf, nil
|
|
|
|
}
|