1616// under the License.
1717package com .cloud .upgrade .dao ;
1818
19+ import com .cloud .upgrade .SystemVmTemplateRegistration ;
1920import com .cloud .utils .exception .CloudRuntimeException ;
2021
2122import java .io .InputStream ;
2223import java .sql .Connection ;
2324
24- public class Upgrade41900to41910 implements DbUpgrade {
25+ public class Upgrade41900to41910 extends DbUpgradeAbstractImpl implements DbUpgrade , DbUpgradeSystemVmTemplate {
26+ private SystemVmTemplateRegistration systemVmTemplateRegistration ;
2527
2628 @ Override
2729 public String [] getUpgradableVersionRange () {
28- return new String [] {"4.19.0.0" , "4.19.1.0" };
30+ return new String []{"4.19.0.0" , "4.19.1.0" };
2931 }
3032
3133 @ Override
@@ -46,11 +48,12 @@ public InputStream[] getPrepareScripts() {
4648 throw new CloudRuntimeException ("Unable to find " + scriptFile );
4749 }
4850
49- return new InputStream [] {script };
51+ return new InputStream []{script };
5052 }
5153
5254 @ Override
5355 public void performDataMigration (Connection conn ) {
56+ addIndexes (conn );
5457 }
5558
5659 @ Override
@@ -61,6 +64,25 @@ public InputStream[] getCleanupScripts() {
6164 throw new CloudRuntimeException ("Unable to find " + scriptFile );
6265 }
6366
64- return new InputStream [] {script };
67+ return new InputStream []{script };
68+ }
69+
70+ private void addIndexes (Connection conn ) {
71+ DbUpgradeUtils .addIndexIfNeeded (conn , "vm_stats" , "vm_id" );
72+ }
73+
74+ @ Override
75+ public void updateSystemVmTemplates (Connection conn ) {
76+ logger .debug ("Updating System Vm template IDs" );
77+ initSystemVmTemplateRegistration ();
78+ try {
79+ systemVmTemplateRegistration .updateSystemVmTemplates (conn );
80+ } catch (Exception e ) {
81+ throw new CloudRuntimeException ("Failed to find / register SystemVM template(s)" );
82+ }
83+ }
84+
85+ private void initSystemVmTemplateRegistration () {
86+ systemVmTemplateRegistration = new SystemVmTemplateRegistration ("" );
6587 }
6688}
0 commit comments