@@ -95,7 +95,8 @@ protected Answer execute(CopyCommand cmd) {
9595 } else if (srcData .getObjectType () == DataObjectType .TEMPLATE ) {
9696 // sync template from NFS cache to S3 in NFS migration to S3 case
9797 storageManager .createOvaForTemplate ((TemplateObjectTO )srcData );
98- } else if (srcData .getObjectType () == DataObjectType .SNAPSHOT && destData .getObjectType () == DataObjectType .SNAPSHOT ) {
98+ } else if (srcData .getObjectType () == DataObjectType .SNAPSHOT ) {
99+ // pack ova first
99100 // sync snapshot from NFS cache to S3 in NFS migration to S3 case
100101 String parentPath = storageResource .getRootDir (srcDataStore .getUrl ());
101102 SnapshotObjectTO snap = (SnapshotObjectTO )srcData ;
@@ -104,27 +105,28 @@ protected Answer execute(CopyCommand cmd) {
104105 String name = path .substring (index + 1 );
105106 String snapDir = path .substring (0 , index );
106107 storageManager .createOva (parentPath + File .separator + snapDir , name );
107- } else if (srcData .getObjectType () == DataObjectType .SNAPSHOT && destData .getObjectType () == DataObjectType .TEMPLATE ) {
108- //create template from snapshot on src at first, then copy it to s3
109- TemplateObjectTO cacheTemplate = (TemplateObjectTO )destData ;
110- cacheTemplate .setDataStore (srcDataStore );
111- CopyCmdAnswer answer = (CopyCmdAnswer )processor .createTemplateFromSnapshot (cmd );
112- if (!answer .getResult ()) {
113- return answer ;
108+ if (destData .getObjectType () == DataObjectType .TEMPLATE ) {
109+ //create template from snapshot on src at first, then copy it to s3
110+ TemplateObjectTO cacheTemplate = (TemplateObjectTO )destData ;
111+ cacheTemplate .setDataStore (srcDataStore );
112+ CopyCmdAnswer answer = (CopyCmdAnswer )processor .createTemplateFromSnapshot (cmd );
113+ if (!answer .getResult ()) {
114+ return answer ;
115+ }
116+ cacheTemplate .setDataStore (destDataStore );
117+ TemplateObjectTO template = (TemplateObjectTO )answer .getNewData ();
118+ template .setDataStore (srcDataStore );
119+ CopyCommand newCmd = new CopyCommand (template , destData , cmd .getWait (), cmd .executeInSequence ());
120+ Answer result = storageResource .defaultAction (newCmd );
121+ //clean up template data on staging area
122+ try {
123+ DeleteCommand deleteCommand = new DeleteCommand (template );
124+ storageResource .defaultAction (deleteCommand );
125+ } catch (Exception e ) {
126+ s_logger .debug ("Failed to clean up staging area:" , e );
127+ }
128+ return result ;
114129 }
115- cacheTemplate .setDataStore (destDataStore );
116- TemplateObjectTO template = (TemplateObjectTO )answer .getNewData ();
117- template .setDataStore (srcDataStore );
118- CopyCommand newCmd = new CopyCommand (template , destData , cmd .getWait (), cmd .executeInSequence ());
119- Answer result = storageResource .defaultAction (newCmd );
120- //clean up template data on staging area
121- try {
122- DeleteCommand deleteCommand = new DeleteCommand (template );
123- storageResource .defaultAction (deleteCommand );
124- } catch (Exception e ) {
125- s_logger .debug ("Failed to clean up staging area:" , e );
126- }
127- return result ;
128130 }
129131 needDelegation = true ;
130132 }
0 commit comments