yamlConfigMeta.go 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652
  1. // Copyright 2022 EMQ Technologies Co., Ltd.
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. package meta
  15. import (
  16. "encoding/json"
  17. "fmt"
  18. "strings"
  19. "sync"
  20. "github.com/lf-edge/ekuiper/internal/conf"
  21. "github.com/lf-edge/ekuiper/internal/pkg/store"
  22. "github.com/lf-edge/ekuiper/pkg/cast"
  23. "github.com/lf-edge/ekuiper/pkg/kv"
  24. )
  25. type configManager struct {
  26. lock sync.RWMutex
  27. cfgOperators map[string]conf.ConfigOperator
  28. sourceConfigStatusDb kv.KeyValue
  29. sinkConfigStatusDb kv.KeyValue
  30. connectionConfigStatusDb kv.KeyValue
  31. }
  32. // ConfigManager Hold the ConfigOperator for yaml configs defined in etc/sources/xxx.yaml and etc/connections/connection.yaml
  33. // for configs in etc/sources/xxx.yaml, the map key is sources.xxx format, xxx will be mqtt/httppull and so on
  34. // for configs in etc/connections/connection.yaml, the map key is connections.xxx format, xxx will be mqtt/edgex
  35. var ConfigManager *configManager
  36. func InitYamlConfigManager() {
  37. ConfigManager = &configManager{
  38. lock: sync.RWMutex{},
  39. cfgOperators: make(map[string]conf.ConfigOperator),
  40. }
  41. ConfigManager.sourceConfigStatusDb, _ = store.GetKV("sourceConfigStatus")
  42. ConfigManager.sinkConfigStatusDb, _ = store.GetKV("sinkConfigStatus")
  43. ConfigManager.connectionConfigStatusDb, _ = store.GetKV("connectionConfigStatus")
  44. }
  45. const (
  46. SourceCfgOperatorKeyTemplate = "sources.%s"
  47. SourceCfgOperatorKeyPrefix = "sources."
  48. SinkCfgOperatorKeyTemplate = "sinks.%s"
  49. SinkCfgOperatorKeyPrefix = "sinks."
  50. ConnectionCfgOperatorKeyTemplate = "connections.%s"
  51. ConnectionCfgOperatorKeyPrefix = "connections."
  52. )
  53. // loadConfigOperatorForSource
  54. // Try to load ConfigOperator for plugin xxx from /etc/sources/xxx.yaml /data/sources/xxx.yaml
  55. // If plugin xxx not exist, no error response
  56. func loadConfigOperatorForSource(pluginName string) {
  57. yamlKey := fmt.Sprintf(SourceCfgOperatorKeyTemplate, pluginName)
  58. if cfg, _ := conf.NewConfigOperatorFromSourceYaml(pluginName); cfg != nil {
  59. ConfigManager.lock.Lock()
  60. ConfigManager.cfgOperators[yamlKey] = cfg
  61. ConfigManager.lock.Unlock()
  62. conf.Log.Infof("Loading yaml file for source: %s", pluginName)
  63. }
  64. }
  65. // loadConfigOperatorForSink
  66. // Try to load ConfigOperator for plugin xxx from /data/sinks/xxx.yaml
  67. // If plugin xxx not exist, no error response
  68. func loadConfigOperatorForSink(pluginName string) {
  69. yamlKey := fmt.Sprintf(SinkCfgOperatorKeyTemplate, pluginName)
  70. if cfg, _ := conf.NewConfigOperatorFromSinkYaml(pluginName); cfg != nil {
  71. ConfigManager.lock.Lock()
  72. ConfigManager.cfgOperators[yamlKey] = cfg
  73. ConfigManager.lock.Unlock()
  74. conf.Log.Infof("Loading yaml file for sink: %s", pluginName)
  75. }
  76. }
  77. // loadConfigOperatorForConnection
  78. // Try to load ConfigOperator for plugin from /etc/connections/connection.yaml /data/connections/connection.yaml
  79. // If plugin not exist in /etc/connections/connection.yaml, no error response
  80. func loadConfigOperatorForConnection(pluginName string) {
  81. yamlKey := fmt.Sprintf(ConnectionCfgOperatorKeyTemplate, pluginName)
  82. if cfg, _ := conf.NewConfigOperatorFromConnectionYaml(pluginName); cfg != nil {
  83. ConfigManager.lock.Lock()
  84. ConfigManager.cfgOperators[yamlKey] = cfg
  85. ConfigManager.lock.Unlock()
  86. conf.Log.Infof("Loading yaml file for connection: %s", pluginName)
  87. }
  88. }
  89. func delConfKey(configOperatorKey, confKey, language string) error {
  90. ConfigManager.lock.Lock()
  91. defer ConfigManager.lock.Unlock()
  92. cfgOps, ok := ConfigManager.cfgOperators[configOperatorKey]
  93. if !ok {
  94. return fmt.Errorf(`%s%s`, getMsg(language, source, "not_found_plugin"), configOperatorKey)
  95. }
  96. cfgOps.DeleteConfKey(confKey)
  97. err := cfgOps.SaveCfgToFile()
  98. if err != nil {
  99. return fmt.Errorf(`%s%s.%v`, getMsg(language, source, "write_data_fail"), configOperatorKey, err)
  100. }
  101. return nil
  102. }
  103. func DelSourceConfKey(plgName, confKey, language string) error {
  104. configOperatorKey := fmt.Sprintf(SourceCfgOperatorKeyTemplate, plgName)
  105. return delConfKey(configOperatorKey, confKey, language)
  106. }
  107. func DelSinkConfKey(plgName, confKey, language string) error {
  108. configOperatorKey := fmt.Sprintf(SinkCfgOperatorKeyTemplate, plgName)
  109. return delConfKey(configOperatorKey, confKey, language)
  110. }
  111. func DelConnectionConfKey(plgName, confKey, language string) error {
  112. configOperatorKey := fmt.Sprintf(ConnectionCfgOperatorKeyTemplate, plgName)
  113. return delConfKey(configOperatorKey, confKey, language)
  114. }
  115. func delYamlConf(configOperatorKey string) {
  116. ConfigManager.lock.Lock()
  117. defer ConfigManager.lock.Unlock()
  118. _, ok := ConfigManager.cfgOperators[configOperatorKey]
  119. if ok {
  120. delete(ConfigManager.cfgOperators, configOperatorKey)
  121. }
  122. }
  123. func GetYamlConf(configOperatorKey, language string) (b []byte, err error) {
  124. ConfigManager.lock.RLock()
  125. defer ConfigManager.lock.RUnlock()
  126. cfgOps, ok := ConfigManager.cfgOperators[configOperatorKey]
  127. if !ok {
  128. return nil, fmt.Errorf(`%s%s`, getMsg(language, source, "not_found_plugin"), configOperatorKey)
  129. }
  130. cf := cfgOps.CopyConfContent()
  131. if b, err = json.Marshal(cf); nil != err {
  132. return nil, fmt.Errorf(`%s%v`, getMsg(language, source, "json_marshal_fail"), cf)
  133. } else {
  134. return b, err
  135. }
  136. }
  137. func addSourceConfKeys(plgName string, configurations YamlConfigurations) (err error) {
  138. ConfigManager.lock.Lock()
  139. defer ConfigManager.lock.Unlock()
  140. configOperatorKey := fmt.Sprintf(SourceCfgOperatorKeyTemplate, plgName)
  141. var cfgOps conf.ConfigOperator
  142. var found bool
  143. cfgOps, found = ConfigManager.cfgOperators[configOperatorKey]
  144. if !found {
  145. cfgOps = conf.NewConfigOperatorForSource(plgName)
  146. ConfigManager.cfgOperators[configOperatorKey] = cfgOps
  147. }
  148. cfgOps.LoadConfContent(configurations)
  149. err = cfgOps.SaveCfgToFile()
  150. if err != nil {
  151. return fmt.Errorf(`%s.%v`, configOperatorKey, err)
  152. }
  153. return nil
  154. }
  155. func AddSourceConfKey(plgName, confKey, language string, content []byte) error {
  156. ConfigManager.lock.Lock()
  157. defer ConfigManager.lock.Unlock()
  158. configOperatorKey := fmt.Sprintf(SourceCfgOperatorKeyTemplate, plgName)
  159. reqField := make(map[string]interface{})
  160. err := json.Unmarshal(content, &reqField)
  161. if nil != err {
  162. return fmt.Errorf(`%s%s.%v`, getMsg(language, source, "type_conversion_fail"), plgName, err)
  163. }
  164. var cfgOps conf.ConfigOperator
  165. var found bool
  166. cfgOps, found = ConfigManager.cfgOperators[configOperatorKey]
  167. if !found {
  168. cfgOps = conf.NewConfigOperatorForSource(plgName)
  169. ConfigManager.cfgOperators[configOperatorKey] = cfgOps
  170. }
  171. if err := cfgOps.AddConfKey(confKey, reqField); err != nil {
  172. return err
  173. }
  174. err = cfgOps.SaveCfgToFile()
  175. if err != nil {
  176. return fmt.Errorf(`%s%s.%v`, getMsg(language, source, "write_data_fail"), configOperatorKey, err)
  177. }
  178. return nil
  179. }
  180. func AddSinkConfKey(plgName, confKey, language string, content []byte) error {
  181. ConfigManager.lock.Lock()
  182. defer ConfigManager.lock.Unlock()
  183. configOperatorKey := fmt.Sprintf(SinkCfgOperatorKeyTemplate, plgName)
  184. reqField := make(map[string]interface{})
  185. err := json.Unmarshal(content, &reqField)
  186. if nil != err {
  187. return fmt.Errorf(`%s%s.%v`, getMsg(language, sink, "type_conversion_fail"), plgName, err)
  188. }
  189. var cfgOps conf.ConfigOperator
  190. var found bool
  191. cfgOps, found = ConfigManager.cfgOperators[configOperatorKey]
  192. if !found {
  193. cfgOps = conf.NewConfigOperatorForSink(plgName)
  194. ConfigManager.cfgOperators[configOperatorKey] = cfgOps
  195. }
  196. if err := cfgOps.AddConfKey(confKey, reqField); err != nil {
  197. return err
  198. }
  199. err = cfgOps.SaveCfgToFile()
  200. if err != nil {
  201. return fmt.Errorf(`%s%s.%v`, getMsg(language, sink, "write_data_fail"), configOperatorKey, err)
  202. }
  203. return nil
  204. }
  205. func addSinkConfKeys(plgName string, cf YamlConfigurations) error {
  206. ConfigManager.lock.Lock()
  207. defer ConfigManager.lock.Unlock()
  208. configOperatorKey := fmt.Sprintf(SinkCfgOperatorKeyTemplate, plgName)
  209. var cfgOps conf.ConfigOperator
  210. var found bool
  211. cfgOps, found = ConfigManager.cfgOperators[configOperatorKey]
  212. if !found {
  213. cfgOps = conf.NewConfigOperatorForSink(plgName)
  214. ConfigManager.cfgOperators[configOperatorKey] = cfgOps
  215. }
  216. cfgOps.LoadConfContent(cf)
  217. err := cfgOps.SaveCfgToFile()
  218. if err != nil {
  219. return fmt.Errorf(`%s.%v`, configOperatorKey, err)
  220. }
  221. return nil
  222. }
  223. func AddConnectionConfKey(plgName, confKey, language string, content []byte) error {
  224. ConfigManager.lock.Lock()
  225. defer ConfigManager.lock.Unlock()
  226. configOperatorKey := fmt.Sprintf(ConnectionCfgOperatorKeyTemplate, plgName)
  227. reqField := make(map[string]interface{})
  228. err := json.Unmarshal(content, &reqField)
  229. if nil != err {
  230. return fmt.Errorf(`%s%s.%v`, getMsg(language, source, "type_conversion_fail"), plgName, err)
  231. }
  232. var cfgOps conf.ConfigOperator
  233. var found bool
  234. cfgOps, found = ConfigManager.cfgOperators[configOperatorKey]
  235. if !found {
  236. cfgOps = conf.NewConfigOperatorForConnection(plgName)
  237. ConfigManager.cfgOperators[configOperatorKey] = cfgOps
  238. }
  239. if err := cfgOps.AddConfKey(confKey, reqField); err != nil {
  240. return err
  241. }
  242. err = cfgOps.SaveCfgToFile()
  243. if err != nil {
  244. return fmt.Errorf(`%s%s.%v`, getMsg(language, source, "write_data_fail"), configOperatorKey, err)
  245. }
  246. return nil
  247. }
  248. func addConnectionConfKeys(plgName string, cf YamlConfigurations) error {
  249. ConfigManager.lock.Lock()
  250. defer ConfigManager.lock.Unlock()
  251. configOperatorKey := fmt.Sprintf(ConnectionCfgOperatorKeyTemplate, plgName)
  252. var cfgOps conf.ConfigOperator
  253. var found bool
  254. cfgOps, found = ConfigManager.cfgOperators[configOperatorKey]
  255. if !found {
  256. cfgOps = conf.NewConfigOperatorForConnection(plgName)
  257. ConfigManager.cfgOperators[configOperatorKey] = cfgOps
  258. }
  259. cfgOps.LoadConfContent(cf)
  260. err := cfgOps.SaveCfgToFile()
  261. if err != nil {
  262. return fmt.Errorf(`%s.%v`, configOperatorKey, err)
  263. }
  264. return nil
  265. }
  266. func GetResources(language string) (b []byte, err error) {
  267. ConfigManager.lock.RLock()
  268. defer ConfigManager.lock.RUnlock()
  269. var srcResources []map[string]string
  270. var sinkResources []map[string]string
  271. for key, ops := range ConfigManager.cfgOperators {
  272. if strings.HasPrefix(key, ConnectionCfgOperatorKeyPrefix) {
  273. continue
  274. }
  275. if strings.HasPrefix(key, SourceCfgOperatorKeyPrefix) {
  276. plugin := strings.TrimPrefix(key, SourceCfgOperatorKeyPrefix)
  277. resourceIds := ops.GetUpdatableConfKeys()
  278. if len(resourceIds) > 0 {
  279. item := map[string]string{}
  280. for _, v := range resourceIds {
  281. item[v] = plugin
  282. }
  283. srcResources = append(srcResources, item)
  284. }
  285. continue
  286. }
  287. if strings.HasPrefix(key, SinkCfgOperatorKeyPrefix) {
  288. plugin := strings.TrimPrefix(key, SinkCfgOperatorKeyPrefix)
  289. resourceIds := ops.GetUpdatableConfKeys()
  290. if len(resourceIds) > 0 {
  291. item := map[string]string{}
  292. for _, v := range resourceIds {
  293. item[v] = plugin
  294. }
  295. sinkResources = append(sinkResources, item)
  296. }
  297. continue
  298. }
  299. }
  300. result := map[string]interface{}{}
  301. result["sources"] = srcResources
  302. result["sinks"] = sinkResources
  303. if b, err = json.Marshal(result); nil != err {
  304. return nil, fmt.Errorf(`%s%v`, getMsg(language, source, "json_marshal_fail"), result)
  305. } else {
  306. return b, err
  307. }
  308. }
  309. func ResetConfigs() {
  310. ConfigManager.lock.Lock()
  311. defer ConfigManager.lock.Unlock()
  312. for _, ops := range ConfigManager.cfgOperators {
  313. ops.ClearConfKeys()
  314. _ = ops.SaveCfgToFile()
  315. }
  316. }
  317. type YamlConfigurations map[string]map[string]interface{}
  318. type YamlConfigurationSet struct {
  319. Sources map[string]string `json:"sources"`
  320. Sinks map[string]string `json:"sinks"`
  321. Connections map[string]string `json:"connections"`
  322. }
  323. func GetConfigurations() YamlConfigurationSet {
  324. ConfigManager.lock.RLock()
  325. defer ConfigManager.lock.RUnlock()
  326. result := YamlConfigurationSet{
  327. Sources: map[string]string{},
  328. Sinks: map[string]string{},
  329. Connections: map[string]string{},
  330. }
  331. srcResources := map[string]string{}
  332. sinkResources := map[string]string{}
  333. connectionResources := map[string]string{}
  334. for key, ops := range ConfigManager.cfgOperators {
  335. if strings.HasPrefix(key, ConnectionCfgOperatorKeyPrefix) {
  336. plugin := strings.TrimPrefix(key, ConnectionCfgOperatorKeyPrefix)
  337. cfs := ops.CopyUpdatableConfContent()
  338. if len(cfs) > 0 {
  339. jsonByte, _ := json.Marshal(cfs)
  340. connectionResources[plugin] = string(jsonByte)
  341. }
  342. continue
  343. }
  344. if strings.HasPrefix(key, SourceCfgOperatorKeyPrefix) {
  345. plugin := strings.TrimPrefix(key, SourceCfgOperatorKeyPrefix)
  346. cfs := ops.CopyUpdatableConfContent()
  347. if len(cfs) > 0 {
  348. jsonByte, _ := json.Marshal(cfs)
  349. srcResources[plugin] = string(jsonByte)
  350. }
  351. continue
  352. }
  353. if strings.HasPrefix(key, SinkCfgOperatorKeyPrefix) {
  354. plugin := strings.TrimPrefix(key, SinkCfgOperatorKeyPrefix)
  355. cfs := ops.CopyUpdatableConfContent()
  356. if len(cfs) > 0 {
  357. jsonByte, _ := json.Marshal(cfs)
  358. sinkResources[plugin] = string(jsonByte)
  359. }
  360. continue
  361. }
  362. }
  363. result.Sources = srcResources
  364. result.Sinks = sinkResources
  365. result.Connections = connectionResources
  366. return result
  367. }
  368. type YamlConfigurationKeys struct {
  369. Sources map[string][]string
  370. Sinks map[string][]string
  371. }
  372. func GetConfigurationsFor(yaml YamlConfigurationKeys) YamlConfigurationSet {
  373. ConfigManager.lock.RLock()
  374. defer ConfigManager.lock.RUnlock()
  375. sourcesConfigKeys := yaml.Sources
  376. sinksConfigKeys := yaml.Sinks
  377. result := YamlConfigurationSet{
  378. Sources: map[string]string{},
  379. Sinks: map[string]string{},
  380. Connections: map[string]string{},
  381. }
  382. srcResources := map[string]string{}
  383. sinkResources := map[string]string{}
  384. connectionResources := map[string]string{}
  385. for key, ops := range ConfigManager.cfgOperators {
  386. if strings.HasPrefix(key, ConnectionCfgOperatorKeyPrefix) {
  387. plugin := strings.TrimPrefix(key, ConnectionCfgOperatorKeyPrefix)
  388. cfs := ops.CopyUpdatableConfContent()
  389. if len(cfs) > 0 {
  390. jsonByte, _ := json.Marshal(cfs)
  391. connectionResources[plugin] = string(jsonByte)
  392. }
  393. continue
  394. }
  395. if strings.HasPrefix(key, SourceCfgOperatorKeyPrefix) {
  396. plugin := strings.TrimPrefix(key, SourceCfgOperatorKeyPrefix)
  397. keys, ok := sourcesConfigKeys[plugin]
  398. if ok {
  399. cfs := ops.CopyUpdatableConfContentFor(keys)
  400. if len(cfs) > 0 {
  401. jsonByte, _ := json.Marshal(cfs)
  402. srcResources[plugin] = string(jsonByte)
  403. }
  404. }
  405. continue
  406. }
  407. if strings.HasPrefix(key, SinkCfgOperatorKeyPrefix) {
  408. plugin := strings.TrimPrefix(key, SinkCfgOperatorKeyPrefix)
  409. keys, ok := sinksConfigKeys[plugin]
  410. if ok {
  411. cfs := ops.CopyUpdatableConfContentFor(keys)
  412. if len(cfs) > 0 {
  413. jsonByte, _ := json.Marshal(cfs)
  414. sinkResources[plugin] = string(jsonByte)
  415. }
  416. }
  417. continue
  418. }
  419. }
  420. result.Sources = srcResources
  421. result.Sinks = sinkResources
  422. result.Connections = connectionResources
  423. return result
  424. }
  425. func GetConfigurationStatus() YamlConfigurationSet {
  426. result := YamlConfigurationSet{
  427. Sources: map[string]string{},
  428. Sinks: map[string]string{},
  429. Connections: map[string]string{},
  430. }
  431. all, err := ConfigManager.sourceConfigStatusDb.All()
  432. if err == nil {
  433. result.Sources = all
  434. }
  435. all, err = ConfigManager.sinkConfigStatusDb.All()
  436. if err == nil {
  437. result.Sinks = all
  438. }
  439. all, err = ConfigManager.connectionConfigStatusDb.All()
  440. if err == nil {
  441. result.Connections = all
  442. }
  443. return result
  444. }
  445. func LoadConfigurations(configSets YamlConfigurationSet) YamlConfigurationSet {
  446. configResponse := YamlConfigurationSet{
  447. Sources: map[string]string{},
  448. Sinks: map[string]string{},
  449. Connections: map[string]string{},
  450. }
  451. srcResources := configSets.Sources
  452. sinkResources := configSets.Sinks
  453. connectionResources := configSets.Connections
  454. _ = ConfigManager.sourceConfigStatusDb.Clean()
  455. _ = ConfigManager.sinkConfigStatusDb.Clean()
  456. _ = ConfigManager.connectionConfigStatusDb.Clean()
  457. for key, val := range srcResources {
  458. configs := YamlConfigurations{}
  459. err := json.Unmarshal(cast.StringToBytes(val), &configs)
  460. if err != nil {
  461. _ = ConfigManager.sourceConfigStatusDb.Set(key, err.Error())
  462. configResponse.Sources[key] = err.Error()
  463. continue
  464. }
  465. err = addSourceConfKeys(key, configs)
  466. if err != nil {
  467. _ = ConfigManager.sourceConfigStatusDb.Set(key, err.Error())
  468. configResponse.Sources[key] = err.Error()
  469. continue
  470. }
  471. }
  472. for key, val := range sinkResources {
  473. configs := YamlConfigurations{}
  474. err := json.Unmarshal(cast.StringToBytes(val), &configs)
  475. if err != nil {
  476. _ = ConfigManager.sinkConfigStatusDb.Set(key, err.Error())
  477. configResponse.Sinks[key] = err.Error()
  478. continue
  479. }
  480. err = addSinkConfKeys(key, configs)
  481. if err != nil {
  482. _ = ConfigManager.sinkConfigStatusDb.Set(key, err.Error())
  483. configResponse.Sinks[key] = err.Error()
  484. continue
  485. }
  486. }
  487. for key, val := range connectionResources {
  488. configs := YamlConfigurations{}
  489. err := json.Unmarshal(cast.StringToBytes(val), &configs)
  490. if err != nil {
  491. _ = ConfigManager.connectionConfigStatusDb.Set(key, err.Error())
  492. configResponse.Connections[key] = err.Error()
  493. continue
  494. }
  495. err = addConnectionConfKeys(key, configs)
  496. if err != nil {
  497. _ = ConfigManager.connectionConfigStatusDb.Set(key, err.Error())
  498. configResponse.Connections[key] = err.Error()
  499. continue
  500. }
  501. }
  502. return configResponse
  503. }
  504. func LoadConfigurationsPartial(configSets YamlConfigurationSet) YamlConfigurationSet {
  505. configResponse := YamlConfigurationSet{
  506. Sources: map[string]string{},
  507. Sinks: map[string]string{},
  508. Connections: map[string]string{},
  509. }
  510. srcResources := configSets.Sources
  511. sinkResources := configSets.Sinks
  512. connectionResources := configSets.Connections
  513. for key, val := range srcResources {
  514. configs := YamlConfigurations{}
  515. err := json.Unmarshal(cast.StringToBytes(val), &configs)
  516. if err != nil {
  517. configResponse.Sources[key] = err.Error()
  518. continue
  519. }
  520. err = addSourceConfKeys(key, configs)
  521. if err != nil {
  522. configResponse.Sources[key] = err.Error()
  523. continue
  524. }
  525. }
  526. for key, val := range sinkResources {
  527. configs := YamlConfigurations{}
  528. err := json.Unmarshal(cast.StringToBytes(val), &configs)
  529. if err != nil {
  530. configResponse.Sinks[key] = err.Error()
  531. continue
  532. }
  533. err = addSinkConfKeys(key, configs)
  534. if err != nil {
  535. configResponse.Sinks[key] = err.Error()
  536. continue
  537. }
  538. }
  539. for key, val := range connectionResources {
  540. configs := YamlConfigurations{}
  541. err := json.Unmarshal(cast.StringToBytes(val), &configs)
  542. if err != nil {
  543. configResponse.Connections[key] = err.Error()
  544. continue
  545. }
  546. err = addConnectionConfKeys(key, configs)
  547. if err != nil {
  548. configResponse.Connections[key] = err.Error()
  549. continue
  550. }
  551. }
  552. return configResponse
  553. }