This is an automated email from the ASF dual-hosted git repository.
sijie pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/pulsar.git
The following commit(s) were added to refs/heads/master by this push:
new 8a3b3af [go function] fix: go function should parse conf content
first (#4746)
8a3b3af is described below
commit 8a3b3af614545b53afb5d8ff07e4492515112eb4
Author: Rui Fu <[email protected]>
AuthorDate: Mon Jul 22 00:12:32 2019 +0800
[go function] fix: go function should parse conf content first (#4746)
### Motivation
`pulsar-function-go/conf` package apply `instance-conf-path` with default
value `HOME_PATH+github.com/apache/pulsar/pulsar-function-go/conf/conf.yaml`,
once function deployed, the running node may not have the yaml conf file exist,
then go function will panic with `not found conf file` error.
This PR changed the logic of config parsing, parse `confContent` first,
then parse `confFilePath` if `confContent` empty.
---
pulsar-function-go/conf/conf.go | 22 ++++++++++++++++------
1 file changed, 16 insertions(+), 6 deletions(-)
diff --git a/pulsar-function-go/conf/conf.go b/pulsar-function-go/conf/conf.go
index 54a32d3..9254e57 100644
--- a/pulsar-function-go/conf/conf.go
+++ b/pulsar-function-go/conf/conf.go
@@ -87,15 +87,24 @@ func (c *Conf) GetConf() *Conf {
flag.Usage()
}
+ if confContent == "" && confFilePath == "" {
+ log.Errorf("no yaml file or conf content provided")
+ return nil
+ }
+
if confFilePath != "" {
yamlFile, err := ioutil.ReadFile(confFilePath)
- if err != nil {
- log.Errorf("not found conf file, err:%s", err.Error())
+ if err == nil {
+ err = yaml.Unmarshal(yamlFile, c)
+ if err != nil {
+ log.Errorf("unmarshal yaml file error:%s",
err.Error())
+ return nil
+ }
+ } else if err != nil && os.IsNotExist(err) && confContent == ""
{
+ log.Errorf("conf file not found, no config content
provided, err:%s", err.Error())
return nil
- }
- err = yaml.Unmarshal(yamlFile, c)
- if err != nil {
- log.Errorf("unmarshal yaml file error:%s", err.Error())
+ } else if err != nil && !os.IsNotExist(err) {
+ log.Errorf("load conf file failed, err:%s", err.Error())
return nil
}
}
@@ -107,6 +116,7 @@ func (c *Conf) GetConf() *Conf {
return nil
}
}
+
return c
}