func TestGetNameToNodeInfo(t *testing.T) { pipeline, err := parse.NewParser().ParsePipeline("../parse/testdata/basic", "") require.NoError(t, err) nodes := pps.GetNameToNode(pipeline) nodeInfos, err := getNameToNodeInfo(nodes) require.NoError(t, err) require.Equal(t, []string{"bar-node"}, nodeInfos["baz-node-bar-in-bar-out-in"].Parents) }
func (r *runner) Start(pipelineSource *pps.PipelineSource) (string, error) { dirPath, pipeline, err := r.sourcer.GetDirPathAndPipeline(pipelineSource) if err != nil { return "", err } pipelineRunID := strings.Replace(uuid.NewV4().String(), "-", "", -1) pipelineRun := &pps.PipelineRun{ Id: pipelineRunID, Pipeline: pipeline, PipelineSource: pipelineSource, } if err := r.storeClient.AddPipelineRun(pipelineRun); err != nil { return "", err } protolog.Info( &AddedPipelineRun{ PipelineRun: pipelineRun, }, ) nameToNode := pps.GetNameToNode(pipeline) nameToDockerService := pps.GetNameToDockerService(pipeline) nameToNodeInfo, err := getNameToNodeInfo(nameToNode) if err != nil { return "", err } nameToNodeFunc := make(map[string]func() error) for name, node := range nameToNode { nodeFunc, err := r.getNodeFunc( pipelineRunID, name, node, nameToDockerService, dirPath, 1, ) if err != nil { return "", err } nameToNodeFunc[name] = nodeFunc } run, err := r.grapher.Build( nameToNodeInfo, nameToNodeFunc, ) if err != nil { return "", err } if err := r.storeClient.AddPipelineRunStatus(pipelineRunID, pps.PipelineRunStatusType_PIPELINE_RUN_STATUS_TYPE_STARTED); err != nil { return "", err } go func() { if err := run.Do(); err != nil { if storeErr := r.storeClient.AddPipelineRunStatus(pipelineRunID, pps.PipelineRunStatusType_PIPELINE_RUN_STATUS_TYPE_ERROR); storeErr != nil { protolog.Errorln(storeErr.Error()) } } else { if storeErr := r.storeClient.AddPipelineRunStatus(pipelineRunID, pps.PipelineRunStatusType_PIPELINE_RUN_STATUS_TYPE_SUCCESS); storeErr != nil { protolog.Errorln(storeErr.Error()) } } }() return pipelineRunID, nil }