@@ -19,7 +19,6 @@ package azurefile
19
19
import (
20
20
"fmt"
21
21
"os"
22
- "os/exec"
23
22
"strconv"
24
23
"strings"
25
24
"sync"
@@ -35,15 +34,6 @@ const (
35
34
tagKeyValueDelimiter = "="
36
35
)
37
36
38
- type AzcopyJobState string
39
-
40
- const (
41
- AzcopyJobError AzcopyJobState = "Error"
42
- AzcopyJobNotFound AzcopyJobState = "NotFound"
43
- AzcopyJobRunning AzcopyJobState = "Running"
44
- AzcopyJobCompleted AzcopyJobState = "Completed"
45
- )
46
-
47
37
// lockMap used to lock on entries
48
38
type lockMap struct {
49
39
sync.Mutex
@@ -275,87 +265,3 @@ func replaceWithMap(str string, m map[string]string) string {
275
265
}
276
266
return str
277
267
}
278
-
279
- // getAzcopyJob get the azcopy job status if job existed
280
- func getAzcopyJob (dstFileshare string ) (AzcopyJobState , string , error ) {
281
- cmdStr := fmt .Sprintf ("azcopy jobs list | grep %s -B 3" , dstFileshare )
282
- // cmd output example:
283
- // JobId: ed1c3833-eaff-fe42-71d7-513fb065a9d9
284
- // Start Time: Monday, 07-Aug-23 03:29:54 UTC
285
- // Status: Completed (or Cancelled, InProgress)
286
- // Command: copy https://{accountName}.file.core.windows.net/{srcFileshare}{SAStoken} https://{accountName}.file.core.windows.net/{dstFileshare}{SAStoken} --recursive --check-length=false
287
- // --
288
- // JobId: b598cce3-9aa9-9640-7793-c2bf3c385a9a
289
- // Start Time: Wednesday, 09-Aug-23 09:09:03 UTC
290
- // Status: Cancelled
291
- // Command: copy https://{accountName}.file.core.windows.net/{srcFileshare}{SAStoken} https://{accountName}.file.core.windows.net/{dstFileshare}{SAStoken} --recursive --check-length=false
292
- out , err := exec .Command ("sh" , "-c" , cmdStr ).CombinedOutput ()
293
- // if grep command returns nothing, the exec will return exit status 1 error, so filter this error
294
- if err != nil && err .Error () != "exit status 1" {
295
- klog .Warningf ("failed to get azcopy job with error: %v, jobState: %v" , err , AzcopyJobError )
296
- return AzcopyJobError , "" , fmt .Errorf ("couldn't list jobs in azcopy %v" , err )
297
- }
298
- jobid , jobState , err := parseAzcopyJobList (string (out ), dstFileshare )
299
- if err != nil || jobState == AzcopyJobError {
300
- klog .Warningf ("failed to get azcopy job with error: %v, jobState: %v" , err , jobState )
301
- return AzcopyJobError , "" , fmt .Errorf ("couldn't parse azcopy job list in azcopy %v" , err )
302
- }
303
- if jobState == AzcopyJobCompleted {
304
- return jobState , "100.0" , err
305
- }
306
- if jobid == "" {
307
- return jobState , "" , err
308
- }
309
- cmdPercentStr := fmt .Sprintf ("azcopy jobs show %s | grep Percent" , jobid )
310
- // cmd out example:
311
- // Percent Complete (approx): 100.0
312
- summary , err := exec .Command ("sh" , "-c" , cmdPercentStr ).CombinedOutput ()
313
- if err != nil {
314
- klog .Warningf ("failed to get azcopy job with error: %v, jobState: %v" , err , AzcopyJobError )
315
- return AzcopyJobError , "" , fmt .Errorf ("couldn't show jobs summary in azcopy %v" , err )
316
- }
317
- jobState , percent , err := parseAzcopyJobShow (string (summary ))
318
- if err != nil || jobState == AzcopyJobError {
319
- klog .Warningf ("failed to get azcopy job with error: %v, jobState: %v" , err , jobState )
320
- return AzcopyJobError , "" , fmt .Errorf ("couldn't parse azcopy job show in azcopy %v" , err )
321
- }
322
- return jobState , percent , nil
323
- }
324
-
325
- func parseAzcopyJobList (joblist string , dstFileShareName string ) (string , AzcopyJobState , error ) {
326
- jobid := ""
327
- jobSegments := strings .Split (joblist , "JobId: " )
328
- if len (jobSegments ) < 2 {
329
- return jobid , AzcopyJobNotFound , nil
330
- }
331
- jobSegments = jobSegments [1 :]
332
- for _ , job := range jobSegments {
333
- segments := strings .Split (job , "\n " )
334
- if len (segments ) < 4 {
335
- return jobid , AzcopyJobError , fmt .Errorf ("error parsing jobs list: %s" , job )
336
- }
337
- statusSegments := strings .Split (segments [2 ], ": " )
338
- if len (statusSegments ) < 2 {
339
- return jobid , AzcopyJobError , fmt .Errorf ("error parsing jobs list status: %s" , segments [2 ])
340
- }
341
- status := statusSegments [1 ]
342
- switch status {
343
- case "InProgress" :
344
- jobid = segments [0 ]
345
- case "Completed" :
346
- return jobid , AzcopyJobCompleted , nil
347
- }
348
- }
349
- if jobid == "" {
350
- return jobid , AzcopyJobNotFound , nil
351
- }
352
- return jobid , AzcopyJobRunning , nil
353
- }
354
-
355
- func parseAzcopyJobShow (jobshow string ) (AzcopyJobState , string , error ) {
356
- segments := strings .Split (jobshow , ": " )
357
- if len (segments ) < 2 {
358
- return AzcopyJobError , "" , fmt .Errorf ("error parsing jobs summary: %s in Percent Complete (approx)" , jobshow )
359
- }
360
- return AzcopyJobRunning , strings .ReplaceAll (segments [1 ], "\n " , "" ), nil
361
- }
0 commit comments