forked from Azure/blobporter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpipelinefactory.go
189 lines (158 loc) · 6.11 KB
/
pipelinefactory.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
package main
import (
"fmt"
"github.com/Azure/blobporter/pipeline"
"github.com/Azure/blobporter/sources"
"github.com/Azure/blobporter/targets"
"github.com/Azure/blobporter/transfer"
)
func newTransferPipelines(params *validatedParameters) (<-chan sources.FactoryResult, pipeline.TargetPipeline, error) {
fact := newPipelinesFactory(params)
var sourcesp <-chan sources.FactoryResult
var targetp pipeline.TargetPipeline
var err error
targetp, err = fact.newTargetPipeline()
if err != nil {
return nil, nil, err
}
sourcesp, err = fact.newSourcePipelines()
if err != nil {
return nil, nil, err
}
return sourcesp, targetp, nil
}
type pipelinesFactory struct {
source transfer.TransferSegment
target transfer.TransferSegment
def transfer.Definition
valParams *validatedParameters
}
type parseAndValidationRule func() error
func newPipelinesFactory(params *validatedParameters) pipelinesFactory {
s, t := transfer.ParseTransferSegment(params.transferType)
p := pipelinesFactory{source: s, target: t, def: params.transferType, valParams: params}
return p
}
func (p *pipelinesFactory) newTargetPipeline() (pipeline.TargetPipeline, error) {
params, err := p.newTargetParams()
if err != nil {
return nil, err
}
switch p.target {
case transfer.File:
params := params.(targets.FileTargetParams)
return targets.NewFileSystemTargetPipeline(params.Overwrite, params.NumberOfHandlesPerFile), nil
case transfer.BlockBlob:
return targets.NewAzureBlockTargetPipeline(params.(targets.AzureTargetParams)), nil
case transfer.PageBlob:
return targets.NewAzurePageTargetPipeline(params.(targets.AzureTargetParams)), nil
case transfer.Perf:
return targets.NewPerfTargetPipeline(), nil
}
return nil, fmt.Errorf("Invalid target segment:%v", p.target)
}
func (p *pipelinesFactory) newSourcePipelines() (<-chan sources.FactoryResult, error) {
params, err := p.newSourceParams()
if err != nil {
return nil, err
}
switch p.source {
case transfer.File:
params := params.(sources.FileSystemSourceParams)
return sources.NewFileSystemSourcePipelineFactory(¶ms), nil
case transfer.HTTP:
params := params.(sources.HTTPSourceParams)
return sources.NewHTTPSourcePipelineFactory(params), nil
case transfer.S3:
params := params.(sources.S3Params)
return sources.NewS3SourcePipelineFactory(¶ms), nil
case transfer.Blob:
params := params.(sources.AzureBlobParams)
return sources.NewAzBlobSourcePipelineFactory(¶ms), nil
case transfer.Perf:
params := params.(sources.PerfSourceParams)
return sources.NewPerfSourcePipelineFactory(params), nil
}
return nil, fmt.Errorf("Invalid source segment:%v", p.source)
}
func (p *pipelinesFactory) newSourceParams() (interface{}, error) {
switch p.source {
case transfer.File:
return sources.FileSystemSourceParams{
SourcePatterns: p.valParams.sourceURIs,
BlockSize: p.valParams.blockSize,
TargetAliases: p.valParams.targetAliases,
NumOfPartitions: p.valParams.numberOfReaders, //TODO make this more explicit by numofpartitions as param..
SourceParams: sources.SourceParams{
Tracker: p.valParams.tracker,
CalculateMD5: p.valParams.calculateMD5,
UseExactNameMatch: p.valParams.useExactMatch,
FilesPerPipeline: p.valParams.numberOfFilesInBatch,
KeepDirStructure: p.valParams.keepDirStructure}}, nil
case transfer.HTTP:
return sources.HTTPSourceParams{
SourceURIs: p.valParams.sourceURIs,
TargetAliases: p.valParams.targetAliases,
SourceParams: sources.SourceParams{
CalculateMD5: p.valParams.calculateMD5}}, nil
case transfer.S3:
return sources.S3Params{
Bucket: p.valParams.s3Source.bucket,
Prefixes: p.valParams.s3Source.prefixes,
Endpoint: p.valParams.s3Source.endpoint,
PreSignedExpMin: p.valParams.s3Source.preSignedExpMin,
AccessKey: p.valParams.s3Source.accessKey,
SecretKey: p.valParams.s3Source.secretKey,
SourceParams: sources.SourceParams{
Tracker: p.valParams.tracker,
CalculateMD5: p.valParams.calculateMD5,
UseExactNameMatch: p.valParams.useExactMatch,
FilesPerPipeline: p.valParams.numberOfFilesInBatch,
//default to always true so blob names are kept
KeepDirStructure: p.valParams.keepDirStructure}}, nil
case transfer.Blob:
return sources.AzureBlobParams{
Container: p.valParams.blobSource.container,
BlobNames: p.valParams.blobSource.prefixes,
AccountName: p.valParams.blobSource.accountName,
AccountKey: p.valParams.blobSource.accountKey,
BaseBlobURL: p.valParams.blobSource.baseBlobURL,
SasExp: p.valParams.blobSource.sasExpMin,
SourceParams: sources.SourceParams{
Tracker: p.valParams.tracker,
CalculateMD5: p.valParams.calculateMD5,
UseExactNameMatch: p.valParams.useExactMatch,
FilesPerPipeline: p.valParams.numberOfFilesInBatch,
KeepDirStructure: p.valParams.keepDirStructure}}, nil
case transfer.Perf:
return sources.PerfSourceParams{
BlockSize: p.valParams.blockSize,
Definitions: p.valParams.perfSourceDefinitions,
SourceParams: sources.SourceParams{
CalculateMD5: p.valParams.calculateMD5}}, nil
}
return nil, fmt.Errorf("Invalid segment type: %v ", p.source)
}
func (p *pipelinesFactory) newTargetParams() (interface{}, error) {
switch p.target {
case transfer.File:
return targets.FileTargetParams{
Overwrite: true, //set this to always overwrite, TODO, expose this as an option
NumberOfHandlesPerFile: p.valParams.numberOfHandlesPerFile}, nil
case transfer.PageBlob:
return targets.AzureTargetParams{
AccountName: p.valParams.blobTarget.accountName,
AccountKey: p.valParams.blobTarget.accountKey,
Container: p.valParams.blobTarget.container,
BaseBlobURL: p.valParams.blobTarget.baseBlobURL}, nil
case transfer.BlockBlob:
return targets.AzureTargetParams{
AccountName: p.valParams.blobTarget.accountName,
AccountKey: p.valParams.blobTarget.accountKey,
Container: p.valParams.blobTarget.container,
BaseBlobURL: p.valParams.blobTarget.baseBlobURL}, nil
case transfer.Perf:
return nil, nil
}
return nil, fmt.Errorf("Invalid target segment type: %v ", p.target)
}