2727import org .apache .cloudstack .engine .subsystem .api .storage .DataMotionStrategy ;
2828import org .apache .cloudstack .engine .subsystem .api .storage .DataObject ;
2929import org .apache .cloudstack .engine .subsystem .api .storage .DataObjectType ;
30+ import org .apache .cloudstack .engine .subsystem .api .storage .DataStore ;
3031import org .apache .cloudstack .engine .subsystem .api .storage .DataStoreManager ;
3132
3233import org .apache .cloudstack .engine .subsystem .api .storage .EndPoint ;
3839import org .apache .cloudstack .storage .command .CopyCommand ;
3940import org .apache .cloudstack .storage .datastore .db .PrimaryDataStoreDao ;
4041import org .apache .cloudstack .storage .datastore .db .StoragePoolVO ;
42+ import org .apache .cloudstack .storage .datastore .db .TemplateDataStoreDao ;
43+ import org .apache .cloudstack .storage .datastore .db .TemplateDataStoreVO ;
4144import org .apache .log4j .Logger ;
4245import org .springframework .stereotype .Component ;
4346
@@ -124,7 +127,7 @@ public class AncientDataMotionStrategy implements DataMotionStrategy {
124127 @ Inject
125128 DataStoreManager dataStoreMgr ;
126129 @ Inject
127- VMTemplateHostDao templateHostDao ;
130+ TemplateDataStoreDao templateStoreDao ;
128131 @ Inject DiskOfferingDao diskOfferingDao ;
129132 @ Inject VMTemplatePoolDao templatePoolDao ;
130133 @ Inject
@@ -319,7 +322,7 @@ protected Answer copyFromSnapshot(DataObject snapObj, DataObject volObj) {
319322 protected Answer cloneVolume (DataObject template , DataObject volume ) {
320323 CopyCommand cmd = new CopyCommand (template .getTO (), volume .getTO (), 0 );
321324 StoragePool pool = (StoragePool )volume .getDataStore ();
322-
325+
323326 try {
324327 Answer answer = storageMgr .sendToPool (pool , null , cmd );
325328 return answer ;
@@ -399,7 +402,7 @@ public Void copyAsync(DataObject srcData, DataObject destData,
399402 answer = copyFromSnapshot (srcData , destData );
400403 } else if (srcData .getType () == DataObjectType .SNAPSHOT
401404 && destData .getType () == DataObjectType .TEMPLATE ) {
402- answer = createTemplateFromSnashot (srcData , destData );
405+ answer = createTemplateFromSnapshot (srcData , destData );
403406 } else if (srcData .getType () == DataObjectType .VOLUME
404407 && destData .getType () == DataObjectType .TEMPLATE ) {
405408 answer = createTemplateFromVolume (srcData , destData );
@@ -425,7 +428,7 @@ public Void copyAsync(DataObject srcData, DataObject destData,
425428 }
426429
427430 @ DB
428- protected Answer createTemplateFromSnashot (DataObject srcData ,
431+ protected Answer createTemplateFromSnapshot (DataObject srcData ,
429432 DataObject destData ) {
430433 long snapshotId = srcData .getId ();
431434 SnapshotVO snapshot = snapshotDao .findById (snapshotId );
@@ -434,8 +437,11 @@ protected Answer createTemplateFromSnashot(DataObject srcData,
434437 + srcData .getId ());
435438 }
436439 Long zoneId = snapshot .getDataCenterId ();
440+ DataStore secStore = destData .getDataStore ();
441+ /*
437442 HostVO secondaryStorageHost = this.templateMgr
438443 .getSecondaryStorageHost(zoneId);
444+ */
439445 String secondaryStorageURL = snapshotMgr
440446 .getSecondaryStorageURL (snapshot );
441447 VMTemplateVO template = this .templateDao .findById (destData .getId ());
@@ -536,13 +542,12 @@ protected Answer createTemplateFromSnashot(DataObject srcData,
536542 origTemplateInstallPath , template .getId (), name ,
537543 _createprivatetemplatefromsnapshotwait );
538544
539- return sendCommand (cmd , pool , template .getId (), dcId ,
540- secondaryStorageHost .getId ());
545+ return sendCommand (cmd , pool , template .getId (), dcId , secStore );
541546 }
542547
543548 @ DB
544549 protected Answer sendCommand (Command cmd , StoragePool pool ,
545- long templateId , long zoneId , long hostId ) {
550+ long templateId , long zoneId , DataStore secStore ) {
546551
547552 CreatePrivateTemplateAnswer answer = null ;
548553 try {
@@ -573,7 +578,7 @@ protected Answer sendCommand(Command cmd, StoragePool pool,
573578 }
574579
575580 String checkSum = this .templateMgr
576- .getChecksum (hostId , answer .getPath ());
581+ .getChecksum (secStore , answer .getPath ());
577582
578583 Transaction txn = Transaction .currentTxn ();
579584
@@ -584,15 +589,15 @@ protected Answer sendCommand(Command cmd, StoragePool pool,
584589
585590 // add template zone ref for this template
586591 templateDao .addTemplateToZone (privateTemplate , zoneId );
587- VMTemplateHostVO templateHostVO = new VMTemplateHostVO ( hostId ,
592+ TemplateDataStoreVO templateHostVO = new TemplateDataStoreVO ( secStore . getId () ,
588593 privateTemplate .getId ());
589594 templateHostVO .setDownloadPercent (100 );
590595 templateHostVO .setDownloadState (Status .DOWNLOADED );
591596 templateHostVO .setInstallPath (answer .getPath ());
592597 templateHostVO .setLastUpdated (new Date ());
593598 templateHostVO .setSize (answer .getVirtualSize ());
594599 templateHostVO .setPhysicalSize (answer .getphysicalSize ());
595- templateHostDao .persist (templateHostVO );
600+ templateStoreDao .persist (templateHostVO );
596601 txn .close ();
597602 return answer ;
598603 }
@@ -609,13 +614,8 @@ private Answer createTemplateFromVolume(DataObject srcObj,
609614
610615 String vmName = this .volumeMgr .getVmNameOnVolume (volume );
611616 Long zoneId = volume .getDataCenterId ();
612- HostVO secondaryStorageHost = this .templateMgr
613- .getSecondaryStorageHost (zoneId );
614- if (secondaryStorageHost == null ) {
615- throw new CloudRuntimeException (
616- "Can not find the secondary storage for zoneId " + zoneId );
617- }
618- String secondaryStorageURL = secondaryStorageHost .getStorageUrl ();
617+ DataStore secStore = destObj .getDataStore ();
618+ String secondaryStorageURL = secStore .getUri ();
619619 VMTemplateVO template = this .templateDao .findById (destObj .getId ());
620620 StoragePool pool = (StoragePool ) this .dataStoreMgr .getDataStore (
621621 volume .getPoolId (), DataStoreRole .Primary );
@@ -630,8 +630,7 @@ private Answer createTemplateFromVolume(DataObject srcObj,
630630 template .getName (), template .getUniqueName (), volume .getPath (),
631631 vmName , _createprivatetemplatefromvolumewait );
632632
633- return sendCommand (cmd , pool , template .getId (), zoneId ,
634- secondaryStorageHost .getId ());
633+ return sendCommand (cmd , pool , template .getId (), zoneId , secStore );
635634 }
636635
637636 private HostVO getSecHost (long volumeId , long dcId ) {
0 commit comments