1616// under the License.
1717package com .cloud .upgrade .dao ;
1818
19+ import com .cloud .upgrade .SystemVmTemplateRegistration ;
1920import com .cloud .utils .exception .CloudRuntimeException ;
21+ import org .apache .log4j .Logger ;
2022
2123import java .io .InputStream ;
2224import java .sql .Connection ;
2325
24- public class Upgrade41900to41910 implements DbUpgrade {
26+ public class Upgrade41900to41910 implements DbUpgrade , DbUpgradeSystemVmTemplate {
27+ final static Logger LOG = Logger .getLogger (Upgrade41900to41910 .class );
28+ private SystemVmTemplateRegistration systemVmTemplateRegistration ;
2529
2630 @ Override
2731 public String [] getUpgradableVersionRange () {
28- return new String [] {"4.19.0.0" , "4.19.1.0" };
32+ return new String []{"4.19.0.0" , "4.19.1.0" };
2933 }
3034
3135 @ Override
@@ -46,11 +50,12 @@ public InputStream[] getPrepareScripts() {
4650 throw new CloudRuntimeException ("Unable to find " + scriptFile );
4751 }
4852
49- return new InputStream [] {script };
53+ return new InputStream []{script };
5054 }
5155
5256 @ Override
5357 public void performDataMigration (Connection conn ) {
58+ addIndexes (conn );
5459 }
5560
5661 @ Override
@@ -61,6 +66,26 @@ public InputStream[] getCleanupScripts() {
6166 throw new CloudRuntimeException ("Unable to find " + scriptFile );
6267 }
6368
64- return new InputStream [] {script };
69+ return new InputStream []{script };
70+ }
71+
72+ private void initSystemVmTemplateRegistration () {
73+ systemVmTemplateRegistration = new SystemVmTemplateRegistration ("" );
74+ }
75+
76+ @ Override
77+ public void updateSystemVmTemplates (Connection conn ) {
78+ LOG .debug ("Updating System Vm template IDs" );
79+ initSystemVmTemplateRegistration ();
80+ try {
81+ systemVmTemplateRegistration .updateSystemVmTemplates (conn );
82+ } catch (Exception e ) {
83+ throw new CloudRuntimeException ("Failed to find / register SystemVM template(s)" );
84+ }
85+ }
86+
87+ private void addIndexes (Connection conn ) {
88+ DbUpgradeUtils .addIndexIfNeeded (conn , "vm_stats" , "vm_id" , "timestamp" );
89+ DbUpgradeUtils .addIndexIfNeeded (conn , "vm_stats" , "timestamp" );
6590 }
6691}
0 commit comments