|
| 1 | +/* |
| 2 | +Licensed to the Apache Software Foundation (ASF) under one or more |
| 3 | +contributor license agreements. See the NOTICE file distributed with |
| 4 | +this work for additional information regarding copyright ownership. |
| 5 | +The ASF licenses this file to You under the Apache License, Version 2.0 |
| 6 | +(the "License"); you may not use this file except in compliance with |
| 7 | +the License. You may obtain a copy of the License at |
| 8 | +
|
| 9 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | +
|
| 11 | +Unless required by applicable law or agreed to in writing, software |
| 12 | +distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | +See the License for the specific language governing permissions and |
| 15 | +limitations under the License. |
| 16 | +*/ |
| 17 | + |
| 18 | +package api |
| 19 | + |
| 20 | +import ( |
| 21 | + "github.com/apache/incubator-devlake/core/errors" |
| 22 | + coreModels "github.com/apache/incubator-devlake/core/models" |
| 23 | + "github.com/apache/incubator-devlake/core/plugin" |
| 24 | + helper "github.com/apache/incubator-devlake/helpers/pluginhelper/api" |
| 25 | + "github.com/apache/incubator-devlake/helpers/srvhelper" |
| 26 | + "github.com/apache/incubator-devlake/plugins/q_dev/models" |
| 27 | + "github.com/apache/incubator-devlake/plugins/q_dev/tasks" |
| 28 | +) |
| 29 | + |
| 30 | +func MakeDataSourcePipelinePlanV200( |
| 31 | + subtaskMetas []plugin.SubTaskMeta, |
| 32 | + connectionId uint64, |
| 33 | + bpScopes []*coreModels.BlueprintScope, |
| 34 | +) (coreModels.PipelinePlan, []plugin.Scope, errors.Error) { |
| 35 | + // load connection and scope from the db |
| 36 | + connection, err := dsHelper.ConnSrv.FindByPk(connectionId) |
| 37 | + if err != nil { |
| 38 | + return nil, nil, err |
| 39 | + } |
| 40 | + scopeDetails, err := dsHelper.ScopeSrv.MapScopeDetails(connectionId, bpScopes) |
| 41 | + if err != nil { |
| 42 | + return nil, nil, err |
| 43 | + } |
| 44 | + |
| 45 | + plan, err := makeDataSourcePipelinePlanV200(subtaskMetas, scopeDetails, connection) |
| 46 | + if err != nil { |
| 47 | + return nil, nil, err |
| 48 | + } |
| 49 | + scopes, err := makeScopesV200(scopeDetails, connection) |
| 50 | + if err != nil { |
| 51 | + return nil, nil, err |
| 52 | + } |
| 53 | + |
| 54 | + return plan, scopes, nil |
| 55 | +} |
| 56 | + |
| 57 | +func makeDataSourcePipelinePlanV200( |
| 58 | + subtaskMetas []plugin.SubTaskMeta, |
| 59 | + scopeDetails []*srvhelper.ScopeDetail[models.QDevS3Slice, srvhelper.NoScopeConfig], |
| 60 | + connection *models.QDevConnection, |
| 61 | +) (coreModels.PipelinePlan, errors.Error) { |
| 62 | + plan := make(coreModels.PipelinePlan, len(scopeDetails)) |
| 63 | + for i, scopeDetail := range scopeDetails { |
| 64 | + s3Slice := scopeDetail.Scope |
| 65 | + stage := plan[i] |
| 66 | + if stage == nil { |
| 67 | + stage = coreModels.PipelineStage{} |
| 68 | + } |
| 69 | + |
| 70 | + // construct task options for q_dev |
| 71 | + op := &tasks.QDevOptions{ |
| 72 | + ConnectionId: s3Slice.ConnectionId, |
| 73 | + S3Prefix: s3Slice.Prefix, |
| 74 | + } |
| 75 | + |
| 76 | + // Pass empty entities array to enable all subtasks |
| 77 | + task, err := helper.MakePipelinePlanTask("q_dev", subtaskMetas, []string{}, op) |
| 78 | + if err != nil { |
| 79 | + return nil, err |
| 80 | + } |
| 81 | + stage = append(stage, task) |
| 82 | + plan[i] = stage |
| 83 | + } |
| 84 | + return plan, nil |
| 85 | +} |
| 86 | + |
| 87 | +func makeScopesV200( |
| 88 | + scopeDetails []*srvhelper.ScopeDetail[models.QDevS3Slice, srvhelper.NoScopeConfig], |
| 89 | + connection *models.QDevConnection, |
| 90 | +) ([]plugin.Scope, errors.Error) { |
| 91 | + scopes := make([]plugin.Scope, 0) |
| 92 | + // For Q Developer metrics, we don't need to create domain layer scopes |
| 93 | + // The data is collected and stored directly in the tool layer |
| 94 | + return scopes, nil |
| 95 | +} |
0 commit comments