@@ -190,11 +190,29 @@ export class ArtModelService {
190190 const { nasMountPoints, ossMountPoints, role, vpcConfig, modelConfig, region } = params ;
191191 try {
192192 const devClient = await initClient ( this . inputs , this . region , 'fun-art' ) ;
193- const { files } = modelConfig ;
193+ const { files, upgrade } = modelConfig ;
194194 if ( _ . isEmpty ( files ) ) {
195195 logger . info ( '[Remove-model] No files specified for removal.' ) ;
196196 return ;
197197 }
198+ let allRemovePromises = [ ] ;
199+ if ( ! _ . isEmpty ( upgrade ) ) {
200+ logger . info ( '[Remove-model] Upgrade model, only support once model.' ) ;
201+ const removeUpgradePromises = Object . keys ( upgrade ) . map ( ( key ) =>
202+ this . _removeUpgradeSingleFile ( devClient , upgrade [ key ] , key , {
203+ name,
204+ nasMountPoints,
205+ ossMountPoints : processedOssMountPoints ,
206+ role,
207+ vpcConfig,
208+ modelConfig,
209+ region,
210+ timeout : modelConfig ?. timeout ,
211+ } ) ,
212+ ) ;
213+ // 将升级文件删除任务添加到总的任务列表中
214+ allRemovePromises = allRemovePromises . concat ( removeUpgradePromises ) ;
215+ }
198216 const processedOssMountPoints = extractOssMountDir ( ossMountPoints ) ;
199217
200218 // 将异步操作重构为并行处理
@@ -210,8 +228,10 @@ export class ArtModelService {
210228 timeout : modelConfig ?. timeout ,
211229 } ) ,
212230 ) ;
231+ // 将删除任务也添加到总的任务列表中
232+ allRemovePromises = allRemovePromises . concat ( removePromises ) ;
213233
214- const removeResults = await Promise . all ( removePromises ) ;
234+ const removeResults = await Promise . all ( allRemovePromises ) ;
215235
216236 // 统计成功和失败的数量
217237 const successfulRemovals = removeResults . filter ( ( result ) => result . success ) ;
@@ -261,27 +281,58 @@ export class ArtModelService {
261281 timeout : number ;
262282 } ,
263283 ) {
264- const { name, nasMountPoints, ossMountPoints, role, vpcConfig, modelConfig, region, timeout } =
265- config ;
284+ const { nasMountPoints, ossMountPoints, modelConfig } = config ;
285+
286+ let filepath : string ;
287+ const uri = file . target ?. uri || modelConfig . target . uri ;
288+ const path = file . target ?. path || '' ;
289+ const fileName = file . source ?. path || 'unknown' ;
290+
291+ // 判断uri是否为nas://auto或oss://auto
292+ if ( uri . startsWith ( 'nas://auto' ) && nasMountPoints ?. length > 0 ) {
293+ const { mountDir } = nasMountPoints [ 0 ] ;
294+ filepath = `${ mountDir } /${ path } ` ;
295+ } else if ( uri . startsWith ( 'oss://auto' ) && ossMountPoints ?. length > 0 ) {
296+ const { mountDir } = ossMountPoints [ 0 ] ;
297+ filepath = `${ mountDir } /${ path } ` ;
298+ } else {
299+ // 直接拼接uri和path
300+ let normalizedUri = uri . endsWith ( '/' ) ? uri . slice ( 0 , - 1 ) : uri ;
301+ normalizedUri = normalizedUri . replace ( / ^ ( n a s | o s s | f i l e ) : \/ \/ / , '/' ) ;
302+ filepath = `${ normalizedUri } /${ path } ` ;
303+ }
304+
305+ return this . _removeFileWithRetry ( devClient , filepath , fileName , config ) ;
306+ }
307+
308+ private async _removeUpgradeSingleFile (
309+ devClient : DevClient ,
310+ path : string ,
311+ version : string ,
312+ config : {
313+ name : string ;
314+ nasMountPoints : any [ ] ;
315+ ossMountPoints : any [ ] ;
316+ role : string ;
317+ vpcConfig : any ;
318+ modelConfig : any ;
319+ region : string ;
320+ timeout : number ;
321+ } ,
322+ ) {
323+ const fileName = version || 'unknown' ;
266324
325+ return this . _removeFileWithRetry ( devClient , path , fileName , config ) ;
326+ }
327+
328+ private async _removeFileWithRetry (
329+ devClient : DevClient ,
330+ filepath : string ,
331+ fileName : string ,
332+ config : any ,
333+ ) : Promise < any > {
267334 try {
268- let filepath ;
269- const uri = file . target ?. uri || modelConfig . target . uri ;
270- const path = file . target ?. path || '' ;
271-
272- // 判断uri是否为nas://auto或oss://auto
273- if ( uri . startsWith ( 'nas://auto' ) && nasMountPoints ?. length > 0 ) {
274- const { mountDir } = nasMountPoints [ 0 ] ;
275- filepath = `${ mountDir } /${ path } ` ;
276- } else if ( uri . startsWith ( 'oss://auto' ) && ossMountPoints ?. length > 0 ) {
277- const { mountDir } = ossMountPoints [ 0 ] ;
278- filepath = `${ mountDir } /${ path } ` ;
279- } else {
280- // 直接拼接uri和path
281- let normalizedUri = uri . endsWith ( '/' ) ? uri . slice ( 0 , - 1 ) : uri ;
282- normalizedUri = normalizedUri . replace ( / ^ ( n a s | o s s | f i l e ) : \/ \/ / , '/' ) ;
283- filepath = `${ normalizedUri } /${ path } ` ;
284- }
335+ const { name, nasMountPoints, ossMountPoints, role, vpcConfig, region, timeout } = config ;
285336
286337 const fileManagerRmRequest = new $Dev20230714 . FileManagerRmRequest ( {
287338 filepath,
@@ -296,17 +347,10 @@ export class ArtModelService {
296347 } ) ,
297348 } ) ;
298349
299- const result = await retryFileManagerRm (
300- devClient ,
301- fileManagerRmRequest ,
302- file . source . path ,
303- 3 ,
304- 30 ,
305- ) ;
350+ const result = await retryFileManagerRm ( devClient , fileManagerRmRequest , fileName , 3 , 30 ) ;
306351
307352 return result ;
308353 } catch ( error ) {
309- const fileName = file . source ?. path || 'unknown' ;
310354 logger . error ( `[Remove-model] Error removing file ${ fileName } : ${ error . message } ` ) ;
311355 logger . error ( `[Remove-model] Error details:` , error . stack || error ) ;
312356 return {
0 commit comments