@@ -3,13 +3,12 @@ package api
33import (
44 "context"
55 "fmt"
6+ "github.com/indeedeng/iwf/service/common/blobstore"
67 "net/http"
78 "os"
89 "strings"
910 "time"
1011
11- "github.com/aws/aws-sdk-go-v2/aws"
12- "github.com/aws/aws-sdk-go-v2/service/s3"
1312 "github.com/google/uuid"
1413 "github.com/indeedeng/iwf/config"
1514 "github.com/indeedeng/iwf/service/common/event"
@@ -31,39 +30,26 @@ import (
3130)
3231
3332type serviceImpl struct {
34- client uclient.UnifiedClient
35- s3Client * s3.Client
36- s3PathPrefix string // it's recommended to be the Temporal namespace or Cadence domain + "/"
37- activeStorage * config.BlobStorageConfig
38- taskQueue string
39- logger log.Logger
40- config config.Config
33+ client uclient.UnifiedClient
34+ store blobstore.BlobStore
35+ taskQueue string
36+ logger log.Logger
37+ config config.Config
4138}
4239
4340func (s * serviceImpl ) Close () {
4441 s .client .Close ()
4542}
4643
4744func NewApiService (
48- cfg config.Config , client uclient.UnifiedClient , taskQueue string , logger log.Logger , s3Client * s3. Client , s3PathPrefix string ,
45+ cfg config.Config , client uclient.UnifiedClient , taskQueue string , logger log.Logger , store blobstore. BlobStore ,
4946) (ApiService , error ) {
50- // get the first active storage
51- var activeStorage * config.BlobStorageConfig
52- for _ , storage := range cfg .ExternalStorage .SupportedStorages {
53- if storage .Status == config .StorageStatusActive {
54- activeStorage = & storage
55- break
56- }
57- }
58-
5947 return & serviceImpl {
60- client : client ,
61- s3Client : s3Client ,
62- s3PathPrefix : s3PathPrefix ,
63- activeStorage : activeStorage ,
64- taskQueue : taskQueue ,
65- logger : logger ,
66- config : cfg ,
48+ client : client ,
49+ store : store ,
50+ taskQueue : taskQueue ,
51+ logger : logger ,
52+ config : cfg ,
6753 }, nil
6854}
6955
@@ -172,18 +158,15 @@ func (s *serviceImpl) ApiV1WorkflowStartPost(
172158 // 2. if it is, upload the input to S3
173159 uuid := uuid .New ().String ()
174160 yyyymmdd := time .Now ().Format ("20060102" )
175- // namespace/yymmdd/workflowId/uuid
176- objectKey := fmt .Sprintf ("%s%s/%s/%s" , s .s3PathPrefix , yyyymmdd , req .GetWorkflowId (), uuid )
177- err := putObject (ctx , s .s3Client ,
178- s .activeStorage .S3Bucket ,
179- objectKey ,
180- * input .StateInput .Data )
161+ // yymmdd/workflowId/uuid
162+ objectKey := fmt .Sprintf ("%s/%s/%s" , yyyymmdd , req .GetWorkflowId (), uuid )
163+ storeId , err := s .store .WriteObject (ctx , objectKey , input .StateInput .GetData ())
181164 if err != nil {
182165 return nil , s .handleError (err , WorkflowStartApiPath , req .GetWorkflowId ())
183166 }
184167 // 3. replace the input with the S3 object
185168 newStateInput := iwfidl.EncodedObject {
186- ExtStoreId : iwfidl .PtrString (s . activeStorage . StorageId ),
169+ ExtStoreId : iwfidl .PtrString (storeId ),
187170 ExtPath : iwfidl .PtrString (objectKey ),
188171 Encoding : iwfidl .PtrString (* input .StateInput .Encoding ),
189172 }
@@ -225,16 +208,6 @@ func (s *serviceImpl) ApiV1WorkflowStartPost(
225208 }, nil
226209}
227210
228- func putObject (ctx context.Context , client * s3.Client , bucketName string , key , content string ) error {
229- _ , err := client .PutObject (ctx , & s3.PutObjectInput {
230- Bucket : aws .String (bucketName ),
231- Key : aws .String (key ),
232- Body : strings .NewReader (content ),
233- ContentType : aws .String ("application/json" ),
234- })
235- return err
236- }
237-
238211func overrideWorkflowConfig (configOverride iwfidl.WorkflowConfig , workflowConfig * iwfidl.WorkflowConfig ) {
239212 if configOverride .ExecutingStateIdMode != nil {
240213 workflowConfig .ExecutingStateIdMode = configOverride .ExecutingStateIdMode
0 commit comments