2525
2626import javax .inject .Inject ;
2727
28+ import org .apache .log4j .Logger ;
29+ import org .springframework .stereotype .Component ;
30+
31+ import com .amazonaws .services .storagegateway .model .ChapInfo ;
32+
2833import org .apache .cloudstack .engine .cloud .entity .api .VolumeEntity ;
2934import org .apache .cloudstack .engine .subsystem .api .storage .CopyCommandResult ;
3035import org .apache .cloudstack .engine .subsystem .api .storage .CreateCmdResult ;
31- import org .apache .cloudstack .engine .subsystem .api .storage .DataMotionService ;
3236import org .apache .cloudstack .engine .subsystem .api .storage .DataObject ;
3337import org .apache .cloudstack .engine .subsystem .api .storage .DataStore ;
38+ import org .apache .cloudstack .engine .subsystem .api .storage .DataStoreDriver ;
3439import org .apache .cloudstack .engine .subsystem .api .storage .EndPoint ;
35- import org .apache .cloudstack .engine .subsystem .api .storage .EndPointSelector ;
36- import org .apache .cloudstack .engine .subsystem .api .storage .ObjectInDataStoreStateMachine ;
3740import org .apache .cloudstack .engine .subsystem .api .storage .Scope ;
38- import org .apache .cloudstack .engine .subsystem .api .storage .ObjectInDataStoreStateMachine .Event ;
39- import org .apache .cloudstack .engine .subsystem .api .storage .DataStoreDriver ;
40- import org .apache .cloudstack .engine .subsystem .api .storage .PrimaryDataStoreDriver ;
41- import org .apache .cloudstack .engine .subsystem .api .storage .SnapshotInfo ;
42- import org .apache .cloudstack .engine .subsystem .api .storage .TemplateInfo ;
43- import org .apache .cloudstack .engine .subsystem .api .storage .ChapInfo ;
44- import org .apache .cloudstack .engine .subsystem .api .storage .VolumeDataFactory ;
4541import org .apache .cloudstack .engine .subsystem .api .storage .VolumeInfo ;
46- import org .apache .cloudstack .engine .subsystem .api .storage .VolumeService ;
4742import org .apache .cloudstack .framework .async .AsyncCallFuture ;
4843import org .apache .cloudstack .framework .async .AsyncCallbackDispatcher ;
4944import org .apache .cloudstack .framework .async .AsyncCompletionCallback ;
50- import org .apache .cloudstack .framework .async .AsyncRpcContext ;
5145import org .apache .cloudstack .framework .config .dao .ConfigurationDao ;
52- import org .apache .cloudstack .storage .command .CommandResult ;
53- import org .apache .cloudstack .storage .command .DeleteCommand ;
5446import org .apache .cloudstack .storage .datastore .DataObjectManager ;
5547import org .apache .cloudstack .storage .datastore .ObjectInDataStoreManager ;
5648import org .apache .cloudstack .storage .datastore .PrimaryDataStore ;
5749import org .apache .cloudstack .storage .datastore .PrimaryDataStoreProviderManager ;
58- import org .apache .cloudstack .storage .datastore .db . VolumeDataStoreDao ;
59- import org .apache .cloudstack .storage .datastore . db . VolumeDataStoreVO ;
60- import org .apache .cloudstack .storage .to . VolumeObjectTO ;
61-
62- import org .apache .log4j . Logger ;
63- import org .springframework . stereotype . Component ;
50+ import org .apache .cloudstack .storage .datastore .VolumeDataFactory ;
51+ import org .apache .cloudstack .storage .endpoint . EndPointSelector ;
52+ import org .apache .cloudstack .storage .image . TemplateInfo ;
53+ import org . apache . cloudstack . storage . motion . DataMotionService ;
54+ import org .apache .cloudstack . storage . snapshot . SnapshotInfo ;
55+ import org .apache . cloudstack . storage . volume . db . VolumeVO ;
6456
6557import com .cloud .agent .api .Answer ;
66- import com .cloud .agent .api .storage .ListVolumeAnswer ;
67- import com .cloud .agent .api .storage .ListVolumeCommand ;
6858import com .cloud .agent .api .to .VirtualMachineTO ;
69- import com .cloud .alert .AlertManager ;
7059import com .cloud .configuration .Config ;
7160import com .cloud .configuration .Resource .ResourceType ;
7261import com .cloud .event .EventTypes ;
7362import com .cloud .event .UsageEventUtils ;
7463import com .cloud .exception .ConcurrentOperationException ;
7564import com .cloud .exception .ResourceAllocationException ;
7665import com .cloud .host .Host ;
77- import com .cloud .storage .DataStoreRole ;
78- import com .cloud .storage .ScopeType ;
7966import com .cloud .storage .StoragePool ;
80- import com .cloud .storage .VMTemplateStoragePoolVO ;
8167import com .cloud .storage .VMTemplateStorageResourceAssoc ;
8268import com .cloud .storage .VMTemplateStorageResourceAssoc .Status ;
83- import com .cloud .storage .Volume .State ;
8469import com .cloud .storage .Volume ;
85- import com .cloud .storage .VolumeVO ;
86- import com .cloud .storage .dao .VMTemplatePoolDao ;
87- import com .cloud .storage .dao .VolumeDao ;
70+ import com .cloud .storage .Volume .State ;
8871import com .cloud .storage .snapshot .SnapshotManager ;
89- import com .cloud .storage .template .TemplateProp ;
9072import com .cloud .user .AccountManager ;
9173import com .cloud .user .ResourceLimitService ;
9274import com .cloud .utils .NumbersUtil ;
@@ -504,6 +486,7 @@ protected Void createVolumeFromBaseImageCallBack(
504486 AsyncCallbackDispatcher <VolumeServiceImpl , CopyCommandResult > callback ,
505487 CreateVolumeFromBaseImageContext <VolumeApiResult > context ) {
506488 DataObject vo = context .vo ;
489+ DataObject tmplOnPrimary = context .templateOnStore ;
507490 CopyCommandResult result = callback .getResult ();
508491 VolumeApiResult volResult = new VolumeApiResult ((VolumeObject ) vo );
509492
@@ -512,8 +495,32 @@ protected Void createVolumeFromBaseImageCallBack(
512495 } else {
513496 vo .processEvent (Event .OperationFailed );
514497 volResult .setResult (result .getResult ());
498+ // hack for Vmware: host is down, previously download template to the host needs to be re-downloaded, so we need to reset
499+ // template_spool_ref entry here to NOT_DOWNLOADED and Allocated state
500+ Answer ans = result .getAnswer ();
501+ if ( ans != null && ans instanceof CopyCmdAnswer && ans .getDetails ().contains ("request template reload" )){
502+ if (tmplOnPrimary != null ){
503+ s_logger .info ("Reset template_spool_ref entry so that vmware template can be reloaded in next try" );
504+ VMTemplateStoragePoolVO templatePoolRef = _tmpltPoolDao .findByPoolTemplate (tmplOnPrimary .getDataStore ().getId (), tmplOnPrimary .getId ());
505+ if (templatePoolRef != null ) {
506+ long templatePoolRefId = templatePoolRef .getId ();
507+ templatePoolRef = _tmpltPoolDao .acquireInLockTable (templatePoolRefId , 1200 );
508+ if (templatePoolRef == null ) {
509+ s_logger .warn ("Reset Template State On Pool failed - unable to lock TemplatePoolRef " + templatePoolRefId );
510+ }
511+
512+ try {
513+ templatePoolRef .setDownloadState (VMTemplateStorageResourceAssoc .Status .NOT_DOWNLOADED );
514+ templatePoolRef .setState (ObjectInDataStoreStateMachine .State .Allocated );
515+ _tmpltPoolDao .update (templatePoolRefId , templatePoolRef );
516+ } finally {
517+ _tmpltPoolDao .releaseFromLockTable (templatePoolRefId );
518+ }
519+ }
520+ }
521+ }
515522 }
516-
523+
517524 AsyncCallFuture <VolumeApiResult > future = context .getFuture ();
518525 future .complete (volResult );
519526 return null ;
0 commit comments