@@ -2332,21 +2332,46 @@ public void moveAllVmDiskFiles(DatastoreMO destDsMo, String destDsDir, boolean f
23322332 vmdkDescriptor = getVmdkFileInfo (fileItem .first ());
23332333
23342334 logger .info ("Move VM disk file " + srcFile .getPath () + " to " + destFile .getPath ());
2335- srcDsMo . moveDatastoreFile (fileItem .first (), dcMo .getMor (), destDsMo .getMor (), destFile .getPath (), dcMo .getMor (), true );
2335+ moveDatastoreFile (srcDsMo , fileItem .first (), dcMo .getMor (), destDsMo .getMor (), destFile .getPath (), dcMo .getMor (), true );
23362336
23372337 if (vmdkDescriptor != null ) {
23382338 String vmdkBaseFileName = vmdkDescriptor .first ().getBaseFileName ();
23392339 String baseFilePath = srcFile .getCompanionPath (vmdkBaseFileName );
23402340 destFile = new DatastoreFile (destDsMo .getName (), destDsDir , vmdkBaseFileName );
23412341
23422342 logger .info ("Move VM disk file " + baseFilePath + " to " + destFile .getPath ());
2343- srcDsMo . moveDatastoreFile (baseFilePath , dcMo .getMor (), destDsMo .getMor (), destFile .getPath (), dcMo .getMor (), true );
2343+ moveDatastoreFile (srcDsMo , baseFilePath , dcMo .getMor (), destDsMo .getMor (), destFile .getPath (), dcMo .getMor (), true );
23442344 }
23452345 }
23462346 }
23472347 }
23482348 }
23492349
2350+ private boolean moveDatastoreFile (final DatastoreMO dsMo , String srcFilePath , ManagedObjectReference morSrcDc , ManagedObjectReference morDestDs ,
2351+ String destFilePath , ManagedObjectReference morDestDc , boolean forceOverwrite ) throws Exception {
2352+ final int retry = 20 ;
2353+ int retryAttempt = 0 ;
2354+ while (++retryAttempt <= retry ) {
2355+ try {
2356+ logger .debug (String .format ("Move datastore file %s, attempt #%d" , srcFilePath , retryAttempt ));
2357+ return dsMo .moveDatastoreFile (srcFilePath , morSrcDc , morDestDs , destFilePath , morDestDc , forceOverwrite );
2358+ } catch (Exception e ) {
2359+ logger .info (String .format ("Got exception while moving datastore file %s " , srcFilePath ), e );
2360+ if (e .getMessage () != null && e .getMessage ().contains ("Unable to access file" )) {
2361+ logger .debug (String .format ("Failed to move datastore file %s. Retrying" , srcFilePath ));
2362+ try {
2363+ Thread .sleep (1000 );
2364+ } catch (InterruptedException ie ) {
2365+ logger .debug (String .format ("Waiting to move datastore file %s been interrupted: " , srcFilePath ));
2366+ }
2367+ } else {
2368+ throw e ;
2369+ }
2370+ }
2371+ }
2372+ return false ;
2373+ }
2374+
23502375 public int getPvScsiDeviceControllerKeyNoException () throws Exception {
23512376 List <VirtualDevice > devices = (List <VirtualDevice >)_context .getVimClient ().
23522377 getDynamicProperty (_mor , "config.hardware.device" );
0 commit comments