Commit d008d355 authored by 梦良's avatar 梦良

提交

parent b5373929
......@@ -7,3 +7,4 @@ EnableDocs = true
sqlconn =
nameSpace = paas
configPath = /etc/kubeconfig/config
defaultCredentialName = k2admin
\ No newline at end of file
This diff is collapsed.
......@@ -82,32 +82,31 @@ func (c *JobController) GetJobList() {
getAllJobUrl := BaseURL + "/blue/rest/organizations/jenkins/pipelines/"
req, _ := http.NewRequest("GET", getAllJobUrl, nil)
req.SetBasicAuth("admin", "K2pass!")
getAllJobRes, err := httpClient.Do(req)
if err != nil {
errorLogger.Println(err)
//if loginRes.StatusCode == http.StatusFound{
// infoLogger.Println(loginRes.Location())
//}
errorLogger.Println("调用获取所有job接口失败:", err.Error())
errorResponseDto.Message = "获取所有job失败"
c.Data["json"] = errorResponseDto
c.ServeJSON()
return
}
infoLogger.Println(getAllJobRes)
getAllJobResByte, err := ioutil.ReadAll(getAllJobRes.Body)
if err != nil {
errorLogger.Printf("解析调用登录接口返回参数失败:%s", err.Error())
//errorResponseDto.Message = utils.GetI18nLang(lang,
// "getUserAllNameSpaces_parseCallInterfaceToGetUserAllNameSpacesResultFail")
//c.Data["json"] = errorResponseDto
//c.ServeJSON()
//return
errorLogger.Printf("解析调用获取所有job接口返回参数失败:%s", err.Error())
errorResponseDto.Message = "解析调用获取所有job接口返回参数失败"
c.Data["json"] = errorResponseDto
c.ServeJSON()
return
}
//infoLogger.Printf("调用登录接口返回值:%s", string(reqByte))
var resMap []map[string]interface{}
if err := json.Unmarshal(getAllJobResByte, &resMap); err != nil {
errorLogger.Println("解析获取所有job接口返回数据失败:", err.Error())
errorResponseDto.Message = "解析获取所有job接口返回数据失败"
c.Data["json"] = errorResponseDto
c.ServeJSON()
return
}
totalRecords := len(resMap)
......@@ -170,13 +169,10 @@ func (c *JobController) GetJobList() {
infoLogger.Println("job lastBuildUserName:", lastBuildUserName)
endTime := latestRunMap["endTime"].(string)
infoLogger.Println("job endTime:", endTime)
endTimeStr = utils.ParseDate(endTime, false)
infoLogger.Println("job endTime:", endTime, " ", endTimeStr)
durationInMillis := int64(latestRunMap["durationInMillis"].(float64))
durationInMillisTimeStr, _ = utils.ParseMilliSecondsDateToString(lang, durationInMillis)
infoLogger.Println("job durationInMillis:", durationInMillis, " ", durationInMillisTimeStr)
}
......@@ -644,14 +640,14 @@ func (c *JobController) CreatePipelineJob() {
//执行创建job
execCreatePipelineJobRes := ExecCreatePipelineJob(requestDto.JobName)
if execCreatePipelineJobRes.Status == 300 {
errorLogger.Printf("执行创建%s job失败:%s", jobName, execCreatePipelineJobRes.Message)
errorLogger.Printf("执行创建job:%s失败:%s", jobName, execCreatePipelineJobRes.Message)
responseDto.Message = execCreatePipelineJobRes.Message
c.Data["json"] = responseDto
c.ServeJSON()
return
}
infoLogger.Printf("执行配置%s job", jobName)
infoLogger.Printf("执行配置job:%s", jobName)
//执行配置job
......@@ -696,17 +692,16 @@ func ExecCreatePipelineJob(jobName string) dto.BaseResponseDto {
url.QueryEscape(string(paramsByte))
infoLogger.Println(paramsStr)
req, _ := http.NewRequest("POST", createUrl+"?"+paramsStr, nil)
req.SetBasicAuth("admin", "K2pass!")
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
createRes, err := httpClient.Do(req)
if err != nil {
errorLogger.Printf("执行创建%s job失败:%s", jobName, err.Error())
errorLogger.Printf("执行创建job:%s失败:%s", jobName, err.Error())
responseDto.Message = "执行创建job失败"
return responseDto
}
infoLogger.Printf("执行创建%s job返回结果:%v", jobName, createRes)
infoLogger.Printf("执行创建job:%s返回结果:%v", jobName, createRes)
errorRes := createRes.Header.Get("X-Error")
infoLogger.Printf("返回错误信息:%s", errorRes)
if errorRes != "" && strings.Contains(errorRes, "A job already exists with the name "+jobName) {
......@@ -717,7 +712,7 @@ func ExecCreatePipelineJob(jobName string) dto.BaseResponseDto {
responseDto.Message = "执行创建job失败"
return responseDto
}
infoLogger.Printf("执行创建%s job成功", jobName)
infoLogger.Printf("执行创建job:%s成功", jobName)
responseDto.Status = 200
responseDto.Message = "成功"
......@@ -744,7 +739,7 @@ func (c *JobController) StartRunPipelineJob() {
c.ServeJSON()
return
}
infoLogger.Println("启动构建job请求参数: ", requestDto)
infoLogger.Println("启动运行job请求参数: ", requestDto)
jobName := requestDto.JobName
if strings.TrimSpace(jobName) == "" {
errorLogger.Println("job名称不能为空")
......@@ -765,22 +760,21 @@ func (c *JobController) StartRunPipelineJob() {
}
req, _ := http.NewRequest("POST", buildUrl, nil)
req.SetBasicAuth("admin", "K2pass!")
req.Header.Set("Content-Type", "application/json;charset=utf-8")
startRes, err := httpClient.Do(req)
if err != nil {
errorLogger.Println(err)
errorLogger.Printf("启动构建%s job失败:%s", jobName, err.Error())
responseDto.Message = "启动构建job失败"
errorLogger.Printf("启动运行job:%s失败:%s", jobName, err.Error())
responseDto.Message = "启动运行job失败"
c.Data["json"] = responseDto
c.ServeJSON()
return
}
infoLogger.Printf("启动构建%sjob 返回状态码:%s", jobName, startRes.Status)
infoLogger.Printf("启动运行job:%s返回状态码:%s", jobName, startRes.Status)
if startRes.StatusCode != http.StatusFound {
responseDto.Message = "启动构建job失败"
responseDto.Message = "启动运行job失败"
if startRes.StatusCode == http.StatusNotFound {
responseDto.Message = "job不存在"
}
......@@ -788,7 +782,7 @@ func (c *JobController) StartRunPipelineJob() {
c.ServeJSON()
return
}
infoLogger.Printf("启动构建%s job成功", jobName)
infoLogger.Printf("启动运行job:%s成功", jobName)
responseDto.Status = 200
responseDto.Message = "成功"
......@@ -840,19 +834,17 @@ func (c *JobController) DeletePipelineJob() {
}
req, _ := http.NewRequest("POST", buildUrl, nil)
req.SetBasicAuth("admin", "K2pass!")
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
deleteRes, err := httpClient.Do(req)
if err != nil {
errorLogger.Println(err)
errorLogger.Printf("执行删除%s job失败:%s", jobName, err.Error())
errorLogger.Printf("执行删除job:%s失败:%s", jobName, err.Error())
responseDto.Message = "执行删除job失败"
c.Data["json"] = responseDto
c.ServeJSON()
return
}
infoLogger.Printf("执行删除%s job返回状态码:%s", jobName, deleteRes.Status)
infoLogger.Printf("执行删除job:%s返回状态码:%s", jobName, deleteRes.Status)
if deleteRes.StatusCode != http.StatusFound {
responseDto.Message = "执行删除job失败"
if deleteRes.StatusCode == http.StatusNotFound {
......@@ -862,7 +854,7 @@ func (c *JobController) DeletePipelineJob() {
c.ServeJSON()
return
}
infoLogger.Printf("执行删除%s job成功", jobName)
infoLogger.Printf("执行删除job:%s成功", jobName)
responseDto.Status = 200
responseDto.Message = "成功"
......
package dto
type GetCredentialsResponseDto struct {
JobName string `json:"jobName"` //job 名称
LastStatus string `json:"lastStatus"` //最近状态
LastBuildUserName string `json:"lastBuildUserName"` //最近构建人名称
Description string `json:"description"` //描述信息
LastUpdateTime string `json:"lastUpdateTime"` //最近更新时间即最近job结束时间
DurationInMillis string `json:"durationInMillis"` //上次持续时间
type GetAllCredentialsResultResponseDto struct {
CredentialId string `json:"credentialId"` //凭据id
CredentialName string `json:"credentialName"` //凭据名称
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment