@@ -796,12 +796,16 @@ public void doInTransactionWithoutResult(final TransactionStatus status) {
796796 Long templateId = getRegisteredTemplateId (hypervisorAndTemplateName );
797797 if (templateId != null ) {
798798 VMTemplateVO templateVO = vmTemplateDao .findById (templateId );
799- TemplateDataStoreVO templateDataStoreVO = templateDataStoreDao .findByTemplate (templateId , DataStoreRole .Image );
800- String installPath = templateDataStoreVO .getInstallPath ();
801- if (validateIfSeeded (storeUrlAndId .first (), installPath , nfsVersion )) {
802- continue ;
803- } else if (templateVO != null ) {
799+ TemplateDataStoreVO templateDataStoreVO = templateDataStoreDao .findByStoreTemplate (storeUrlAndId .second (), templateId );
800+ if (templateDataStoreVO != null ) {
801+ String installPath = templateDataStoreVO .getInstallPath ();
802+ if (validateIfSeeded (storeUrlAndId .first (), installPath , nfsVersion )) {
803+ continue ;
804+ }
805+ }
806+ if (templateVO != null ) {
804807 registerTemplate (hypervisorAndTemplateName , storeUrlAndId , templateVO , templateDataStoreVO , filePath );
808+ updateRegisteredTemplateDetails (templateId , hypervisorAndTemplateName );
805809 continue ;
806810 }
807811 }
@@ -825,6 +829,11 @@ public void doInTransactionWithoutResult(final TransactionStatus status) {
825829 }
826830
827831 private void updateRegisteredTemplateDetails (Long templateId , Map .Entry <Hypervisor .HypervisorType , String > hypervisorAndTemplateName ) {
832+ Pair <Hypervisor .HypervisorType , String > entry = new Pair <>(hypervisorAndTemplateName .getKey (), hypervisorAndTemplateName .getValue ());
833+ updateRegisteredTemplateDetails (templateId , entry );
834+ }
835+
836+ private void updateRegisteredTemplateDetails (Long templateId , Pair <Hypervisor .HypervisorType , String > hypervisorAndTemplateName ) {
828837 VMTemplateVO templateVO = vmTemplateDao .findById (templateId );
829838 templateVO .setTemplateType (Storage .TemplateType .SYSTEM );
830839 boolean updated = vmTemplateDao .update (templateVO .getId (), templateVO );
@@ -834,11 +843,11 @@ private void updateRegisteredTemplateDetails(Long templateId, Map.Entry<Hypervis
834843 throw new CloudRuntimeException (errMsg );
835844 }
836845
837- updateSystemVMEntries (templateId , hypervisorAndTemplateName .getKey ());
846+ updateSystemVMEntries (templateId , hypervisorAndTemplateName .first ());
838847
839848 // Change value of global configuration parameter router.template.* for the corresponding hypervisor and minreq.sysvmtemplate.version for the ACS version
840849 Map <String , String > configParams = new HashMap <>();
841- configParams .put (RouterTemplateConfigurationNames .get (hypervisorAndTemplateName .getKey ()), hypervisorAndTemplateName .getValue ());
850+ configParams .put (RouterTemplateConfigurationNames .get (hypervisorAndTemplateName .first ()), hypervisorAndTemplateName .second ());
842851 configParams .put ("minreq.sysvmtemplate.version" , getSystemVmTemplateVersion ());
843852 updateConfigurationParams (configParams );
844853 }
0 commit comments