| /* |
| Licensed to the Apache Software Foundation (ASF) under one or more |
| contributor license agreements. See the NOTICE file distributed with |
| this work for additional information regarding copyright ownership. |
| The ASF licenses this file to You under the Apache License, Version 2.0 |
| (the "License"); you may not use this file except in compliance with |
| the License. You may obtain a copy of the License at |
| |
| http://www.apache.org/licenses/LICENSE-2.0 |
| |
| Unless required by applicable law or agreed to in writing, software |
| distributed under the License is distributed on an "AS IS" BASIS, |
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| See the License for the specific language governing permissions and |
| limitations under the License. |
| */ |
| |
| package api |
| |
| import ( |
| "github.com/apache/devlake/core/errors" |
| coreModels "github.com/apache/devlake/core/models" |
| "github.com/apache/devlake/core/plugin" |
| helper "github.com/apache/devlake/helpers/pluginhelper/api" |
| "github.com/apache/devlake/helpers/srvhelper" |
| "github.com/apache/devlake/plugins/cursor/models" |
| "github.com/apache/devlake/plugins/cursor/tasks" |
| ) |
| |
| // MakeDataSourcePipelinePlanV200 generates the pipeline plan for blueprint v2.0.0. |
| func MakeDataSourcePipelinePlanV200( |
| subtaskMetas []plugin.SubTaskMeta, |
| connectionId uint64, |
| bpScopes []*coreModels.BlueprintScope, |
| ) (coreModels.PipelinePlan, []plugin.Scope, errors.Error) { |
| _, err := dsHelper.ConnSrv.FindByPk(connectionId) |
| if err != nil { |
| return nil, nil, err |
| } |
| scopeDetails, err := dsHelper.ScopeSrv.MapScopeDetails(connectionId, bpScopes) |
| if err != nil { |
| return nil, nil, err |
| } |
| |
| plan, err := makeDataSourcePipelinePlanV200(subtaskMetas, scopeDetails) |
| if err != nil { |
| return nil, nil, err |
| } |
| |
| return plan, nil, nil |
| } |
| |
| func makeDataSourcePipelinePlanV200( |
| subtaskMetas []plugin.SubTaskMeta, |
| scopeDetails []*srvhelper.ScopeDetail[models.CursorScope, models.CursorScopeConfig], |
| ) (coreModels.PipelinePlan, errors.Error) { |
| plan := make(coreModels.PipelinePlan, len(scopeDetails)) |
| for i, scopeDetail := range scopeDetails { |
| stage := plan[i] |
| if stage == nil { |
| stage = coreModels.PipelineStage{} |
| } |
| |
| scope := scopeDetail.Scope |
| task, err := helper.MakePipelinePlanTask( |
| "cursor", |
| subtaskMetas, |
| nil, |
| tasks.CursorOptions{ |
| ConnectionId: scope.ConnectionId, |
| ScopeId: scope.Id, |
| }, |
| ) |
| if err != nil { |
| return nil, err |
| } |
| stage = append(stage, task) |
| plan[i] = stage |
| } |
| return plan, nil |
| } |