@@ -85,15 +85,15 @@ func (i *imlLogModule) Save(ctx context.Context, driver string, input *log_dto.S
8585 cfg = & tmp
8686 }
8787 return i .transaction .Transaction (ctx , func (txCtx context.Context ) error {
88- err := i .service .UpdateLogSource (ctx , driver , & log.Save {
88+ err := i .service .UpdateLogSource (txCtx , driver , & log.Save {
8989 ID : input .ID ,
9090 Cluster : & input .Cluster ,
9191 Config : cfg ,
9292 })
9393 if err != nil {
9494 return err
9595 }
96- info , err := i .service .GetLogSource (ctx , driver )
96+ info , err := i .service .GetLogSource (txCtx , driver )
9797 if err != nil {
9898 return err
9999 }
@@ -102,10 +102,11 @@ func (i *imlLogModule) Save(ctx context.Context, driver string, input *log_dto.S
102102 return err
103103 }
104104
105- client , err := i .clusterService .GatewayClient (ctx , input .Cluster )
105+ client , err := i .clusterService .GatewayClient (txCtx , input .Cluster )
106106 if err != nil {
107107 return err
108108 }
109+ defer client .Close (txCtx )
109110 dynamicClient , err := client .Dynamic (driver )
110111 if err != nil {
111112 return err
@@ -118,7 +119,7 @@ func (i *imlLogModule) Save(ctx context.Context, driver string, input *log_dto.S
118119 for k , v := range c {
119120 attr [k ] = v
120121 }
121- err = dynamicClient .Online (ctx , & gateway.DynamicRelease {
122+ err = dynamicClient .Online (txCtx , & gateway.DynamicRelease {
122123 BasicItem : & gateway.BasicItem {
123124 ID : driver ,
124125 Description : "collect access log" ,
@@ -159,3 +160,53 @@ func (i *imlLogModule) Get(ctx context.Context, driver string) (*log_dto.LogSour
159160 UpdateAt : auto .TimeLabel (info .UpdateAt ),
160161 }, nil
161162}
163+
164+ func (i * imlLogModule ) initGateway (ctx context.Context , clusterId string , clientDriver gateway.IClientDriver ) error {
165+ drivers := log_driver .Drivers ()
166+ if len (drivers ) < 1 {
167+ return nil
168+ }
169+
170+ for _ , driver := range drivers {
171+ factory , has := log_driver .GetFactory (driver )
172+ if ! has {
173+ continue
174+ }
175+ info , err := i .service .GetLogSource (ctx , driver )
176+ if err != nil {
177+ continue
178+ }
179+ d , c , err := factory .Create (info .Config )
180+ if err != nil {
181+ continue
182+ }
183+
184+ dynamicClient , err := clientDriver .Dynamic (driver )
185+ if err != nil {
186+ continue
187+ }
188+ attr := make (map [string ]interface {})
189+ attr ["driver" ] = driver
190+ attr ["formatter" ] = logFormatter
191+ attr ["labels" ] = labels
192+ attr ["method" ] = "POST"
193+ for k , v := range c {
194+ attr [k ] = v
195+ }
196+ err = dynamicClient .Online (ctx , & gateway.DynamicRelease {
197+ BasicItem : & gateway.BasicItem {
198+ ID : driver ,
199+ Description : "collect access log" ,
200+ Version : time .Now ().Format ("20060102150405" ),
201+ Resource : gateway .ProfessionOutput ,
202+ },
203+ Attr : attr ,
204+ })
205+ if err != nil {
206+ continue
207+ }
208+ log_driver .SetDriver (driver , d )
209+ }
210+
211+ return nil
212+ }
0 commit comments