[FIX] fix the error that rainbondfile repeat an error

This commit is contained in:
goodrain 2018-02-27 22:01:37 +08:00
parent 52927093c5
commit aad2615ae8
3 changed files with 45 additions and 8 deletions

View File

@ -19,13 +19,14 @@
package exector
import (
"fmt"
"context"
"fmt"
"github.com/Sirupsen/logrus"
"github.com/ghodss/yaml"
"github.com/goodrain/rainbond/pkg/builder/parser"
"github.com/goodrain/rainbond/pkg/event"
"github.com/pquerna/ffjson/ffjson"
"github.com/ghodss/yaml"
)
//ServiceCheckInput 任务输入数据
@ -46,9 +47,9 @@ type ServiceCheckInput struct {
//ServiceCheckResult 应用检测结果
type ServiceCheckResult struct {
//检测状态 Success Failure
CheckStatus string `json:"check_status"`
CheckStatus string `json:"check_status"`
ErrorInfos parser.ParseErrorList `json:"error_infos"`
ServiceInfo []parser.ServiceInfo `json:"service_info"`
ServiceInfo []parser.ServiceInfo `json:"service_info"`
}
//CreateResult 创建检测结果
@ -94,7 +95,7 @@ func (e *exectorManager) serviceCheck(in []byte) {
y, err := yaml.JSONToYAML([]byte(input.SourceBody))
if err != nil {
logrus.Errorf("json bytes format is error, %s", input.SourceBody)
logger.Error("dockercompose文件格式不正确。", map[string]string{"step": "callback", "status":"failure"})
logger.Error("dockercompose文件格式不正确。", map[string]string{"step": "callback", "status": "failure"})
return
}
pr = parser.CreateDockerComposeParse(string(y), e.DockerClient, logger)
@ -126,7 +127,9 @@ func (e *exectorManager) serviceCheck(in []byte) {
logrus.Errorf("mashal servicecheck value error, %v", err)
logger.Error("格式化检测结果失败。", map[string]string{"step": "callback", "status": "failure"})
}
_, err = e.EtcdCli.Put(context.TODO(), k, string(vj))
ctx, cancel := context.WithCancel(context.Background())
_, err = e.EtcdCli.Put(ctx, k, string(vj))
cancel()
if err != nil {
logrus.Errorf("put servicecheck k %s into etcd error, %v", k, err)
logger.Error("存储检测结果失败。", map[string]string{"step": "callback", "status": "failure"})

View File

@ -69,7 +69,6 @@ func CreateSourceCodeParse(source string, logger event.Logger) Parser {
}
//Parse 获取代码 解析代码 检验代码
//eg. git ssh://git@gr5042d6.7804f67d.ali-sh-s1.goodrain.net:20905/root/test.git master root password
func (d *SourceCodeParse) Parse() ParseErrorList {
if d.source == "" {
d.logger.Error("源码检查输入参数错误", map[string]string{"step": "parse"})
@ -202,8 +201,9 @@ func (d *SourceCodeParse) Parse() ParseErrorList {
if err != nil {
if err == code.ErrRainbondFileNotFound {
d.errappend(ErrorAndSolve(NegligibleError, "rainbondfile未定义", "可以参考文档说明配置此文件定义应用属性"))
} else {
d.errappend(ErrorAndSolve(NegligibleError, "rainbondfile定义格式有误", "可以参考文档说明配置此文件定义应用属性"))
}
d.errappend(ErrorAndSolve(NegligibleError, "rainbondfile定义格式有误", "可以参考文档说明配置此文件定义应用属性"))
}
//判断对象目录
var buildPath = cacheDir

View File

@ -19,8 +19,11 @@
package parser
import (
"encoding/json"
"fmt"
"testing"
"github.com/goodrain/rainbond/pkg/builder/sources"
)
func TestParseDockerfileInfo(t *testing.T) {
@ -36,3 +39,34 @@ func TestParseDockerfileInfo(t *testing.T) {
parse.parseDockerfileInfo("./Dockerfile")
fmt.Println(parse.GetServiceInfo())
}
//ServiceCheckResult 应用检测结果
type ServiceCheckResult struct {
//检测状态 Success Failure
CheckStatus string `json:"check_status"`
ErrorInfos ParseErrorList `json:"error_infos"`
ServiceInfo []ServiceInfo `json:"service_info"`
}
func TestSourceCode(t *testing.T) {
sc := sources.CodeSourceInfo{
ServerType: "",
RepositoryURL: "http://code.goodrain.com/goodrain/goodrain_web.git",
Branch: "master",
User: "barnett",
Password: "5258423Zqg",
}
b, _ := json.Marshal(sc)
p := CreateSourceCodeParse(string(b), nil)
err := p.Parse()
if err != nil && err.IsFatalError() {
t.Fatal(err)
}
re := ServiceCheckResult{
CheckStatus: "Failure",
ErrorInfos: err,
ServiceInfo: p.GetServiceInfo(),
}
body, _ := json.Marshal(re)
fmt.Printf("%s \n", string(body))
}