5555import org .apache .cloudstack .storage .datastore .db .TemplateDataStoreDao ;
5656import org .apache .cloudstack .storage .datastore .db .TemplateDataStoreVO ;
5757import org .apache .commons .codec .digest .DigestUtils ;
58+ import org .apache .commons .lang3 .StringUtils ;
5859import org .apache .log4j .Logger ;
5960import org .ini4j .Ini ;
6061
@@ -120,6 +121,8 @@ public class SystemVmTemplateRegistration {
120121 @ Inject
121122 ConfigurationDao configurationDao ;
122123
124+ private String systemVmTemplateVersion ;
125+
123126 public SystemVmTemplateRegistration () {
124127 dataCenterDao = new DataCenterDaoImpl ();
125128 vmTemplateDao = new VMTemplateDaoImpl ();
@@ -131,6 +134,21 @@ public SystemVmTemplateRegistration() {
131134 configurationDao = new ConfigurationDaoImpl ();
132135 }
133136
137+ /**
138+ * Convenience constructor method to use when there is no system VM template change for a new version.
139+ */
140+ public SystemVmTemplateRegistration (String systemVmTemplateVersion ) {
141+ this ();
142+ this .systemVmTemplateVersion = systemVmTemplateVersion ;
143+ }
144+
145+ public String getSystemVmTemplateVersion () {
146+ if (StringUtils .isEmpty (systemVmTemplateVersion )) {
147+ return String .format ("%s.%s" , CS_MAJOR_VERSION , CS_TINY_VERSION );
148+ }
149+ return systemVmTemplateVersion ;
150+ }
151+
134152 private static class SystemVMTemplateDetails {
135153 Long id ;
136154 String uuid ;
@@ -658,7 +676,7 @@ public void registerTemplate(Pair<Hypervisor.HypervisorType, String> hypervisorA
658676 hypervisorImageFormat .get (hypervisor ), hypervisorGuestOsMap .get (hypervisor ), storeUrlAndId .second (), null , filePath , true );
659677 Map <String , String > configParams = new HashMap <>();
660678 configParams .put (RouterTemplateConfigurationNames .get (hypervisorAndTemplateName .first ()), hypervisorAndTemplateName .second ());
661- configParams .put ("minreq.sysvmtemplate.version" , CS_MAJOR_VERSION + "." + CS_TINY_VERSION );
679+ configParams .put ("minreq.sysvmtemplate.version" , getSystemVmTemplateVersion () );
662680 updateConfigurationParams (configParams );
663681 updateSystemVMEntries (templateId , hypervisorAndTemplateName .first ());
664682 } catch (Exception e ) {
@@ -809,7 +827,7 @@ private void updateRegisteredTemplateDetails(Long templateId, Map.Entry<Hypervis
809827 // Change value of global configuration parameter router.template.* for the corresponding hypervisor and minreq.sysvmtemplate.version for the ACS version
810828 Map <String , String > configParams = new HashMap <>();
811829 configParams .put (RouterTemplateConfigurationNames .get (hypervisorAndTemplateName .getKey ()), hypervisorAndTemplateName .getValue ());
812- configParams .put ("minreq.sysvmtemplate.version" , CS_MAJOR_VERSION + "." + CS_TINY_VERSION );
830+ configParams .put ("minreq.sysvmtemplate.version" , getSystemVmTemplateVersion () );
813831 updateConfigurationParams (configParams );
814832 }
815833
@@ -854,11 +872,11 @@ public void doInTransactionWithoutResult(final TransactionStatus status) {
854872 registerTemplates (hypervisorsListInUse );
855873 break ;
856874 } catch (final Exception e ) {
857- throw new CloudRuntimeException (String .format ("%s.%s %s SystemVm template not found. Cannot upgrade system Vms" , CS_MAJOR_VERSION , CS_TINY_VERSION , hypervisorAndTemplateName .getKey ()));
875+ throw new CloudRuntimeException (String .format ("%s %s SystemVm template not found. Cannot upgrade system Vms" , getSystemVmTemplateVersion () , hypervisorAndTemplateName .getKey ()));
858876 }
859877 } else {
860- LOGGER .warn (String .format ("%s.%s %s SystemVm template not found. Cannot upgrade system Vms hypervisor is not used, so not failing upgrade" ,
861- CS_MAJOR_VERSION , CS_TINY_VERSION , hypervisorAndTemplateName .getKey ()));
878+ LOGGER .warn (String .format ("%s %s SystemVm template not found. Cannot upgrade system Vms hypervisor is not used, so not failing upgrade" ,
879+ getSystemVmTemplateVersion () , hypervisorAndTemplateName .getKey ()));
862880 // Update the latest template URLs for corresponding hypervisor
863881 VMTemplateVO templateVO = vmTemplateDao .findLatestTemplateByTypeAndHypervisor (hypervisorAndTemplateName .getKey (), Storage .TemplateType .SYSTEM );
864882 if (templateVO != null ) {
0 commit comments