37 Star 396 Fork 71

GVPrancher/rancher

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
pipeline_execution.go 1.77 KB
一键复制 编辑 原始数据 按行查看 历史
phli 提交于 2018-03-09 17:39 . update pipeline conditions
package pipeline
import (
"fmt"
"github.com/pkg/errors"
"github.com/rancher/norman/api/access"
"github.com/rancher/norman/httperror"
"github.com/rancher/norman/types"
"github.com/rancher/types/client/management/v3"
"net/http"
)
type ExecutionHandler struct {
}
func (h ExecutionHandler) ExecutionFormatter(apiContext *types.APIContext, resource *types.RawResource) {
resource.AddAction(apiContext, "rerun")
resource.AddAction(apiContext, "stop")
resource.Links["log"] = apiContext.URLBuilder.Link("log", resource)
}
func (h ExecutionHandler) LinkHandler(apiContext *types.APIContext, next types.RequestHandler) error {
if apiContext.Link == "log" {
return h.log(apiContext)
}
return httperror.NewAPIError(httperror.NotFound, "Link not found")
}
func (h *ExecutionHandler) ActionHandler(actionName string, action *types.Action, apiContext *types.APIContext) error {
switch actionName {
case "rerun":
return h.rerun(apiContext)
case "stop":
return h.stop(apiContext)
}
return httperror.NewAPIError(httperror.InvalidAction, "unsupported action")
}
func (h *ExecutionHandler) rerun(apiContext *types.APIContext) error {
return nil
}
func (h *ExecutionHandler) stop(apiContext *types.APIContext) error {
return nil
}
func (h *ExecutionHandler) log(apiContext *types.APIContext) error {
stage := apiContext.Request.URL.Query().Get("stage")
step := apiContext.Request.URL.Query().Get("step")
if stage == "" || step == "" {
return errors.New("Step index for log is not provided")
}
logID := fmt.Sprintf("%s-%s-%s", apiContext.ID, stage, step)
data := map[string]interface{}{}
if err := access.ByID(apiContext, apiContext.Version, client.PipelineExecutionLogType, logID, &data); err != nil {
return err
}
apiContext.WriteResponse(http.StatusOK, data)
return nil
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/rancher/rancher.git
git@gitee.com:rancher/rancher.git
rancher
rancher
rancher
v2.0.12-rc3

搜索帮助

344bd9b3 5694891 D2dac590 5694891