|
25 | 25 | import com.cloud.utils.exception.CloudRuntimeException; |
26 | 26 |
|
27 | 27 | public class Upgrade42020to42030 extends DbUpgradeAbstractImpl implements DbUpgrade, DbUpgradeSystemVmTemplate { |
28 | | - |
29 | | - private static String SELECT_TEMPLATE = "SELECT `name` FROM `cloud`.`email_template` WHERE `name`=\"backup_report_template\";"; |
30 | | - private static String INSERT_TEMPLATE = "INSERT INTO `cloud`.`email_template` (name, template) VALUES (\"backup_report_template\", \'<h1>Backup report</h1>\n" + |
31 | | - "<p>Backup storage usage increase for the environment during the period is ${storageUsage} GiB.</p>\n" + |
32 | | - "\n" + |
33 | | - "<#list backupReportDomainResponseList as domain>\n" + |
34 | | - "<hr>\n" + |
35 | | - "<h2>Domain ${domain.domainName}</h2>\n" + |
36 | | - "<p>Backup storage usage increase for the domain ${domain.domainName} is ${domain.storageUsage} GiB.</p>\n" + |
37 | | - "\n" + |
38 | | - " <#list domain.backupReportAccountResponseList as account>\n" + |
39 | | - " <hr>\n" + |
40 | | - " <#if account.accountName??>\n" + |
41 | | - " <h3>Account ${account.accountName}</h3>\n" + |
42 | | - " <p>Backup storage usage increase for the account ${account.accountName} is ${account.storageUsage} GiB.</p> \n" + |
43 | | - " <#else>\n" + |
44 | | - " <h3>Project ${account.projectName}</h3>\n" + |
45 | | - " <p>Backup storage usage increase for the project ${account.projectName} is ${account.storageUsage} GiB.</p>\n" + |
46 | | - " </#if>\n" + |
47 | | - " \n" + |
48 | | - "\n" + |
49 | | - " <#list account.successfulBackups>\n" + |
50 | | - " <p>Successfully created backups for the ${(account.accountName??)?then(\"project\",\"account\")}:</p>\n" + |
51 | | - " <ul>\n" + |
52 | | - " <#items as backup>\n" + |
53 | | - " <li>Backup ${backup.name!\"without name\"} with ID ${backup.id} of VM ${backup.vmName} with ID ${backup.vmId} was created at ${backup.date?datetime};</li>\n" + |
54 | | - " </#items>\n" + |
55 | | - " </ul>\n" + |
56 | | - " </#list>\n" + |
57 | | - "\n" + |
58 | | - " <#list account.failedBackups>\n" + |
59 | | - " <p>Failed backups for the ${(account.accountName??)?then(\"project\",\"account\")}:</p>\n" + |
60 | | - " <ul>\n" + |
61 | | - "\n" + |
62 | | - " <#items as backup>\n" + |
63 | | - " <li>Backup ${backup.name!\"without name\"} with ID ${backup.id} of VM ${backup.vmName} with ID ${backup.vmId} failed at ${(backup.date?datetime)!\"unable to get date\"};\n" + |
64 | | - "\n" + |
65 | | - " <#if backup.failureReason?? || backup.logid??>\n" + |
66 | | - " <ul> \n" + |
67 | | - " <#if backup.failureReason??>\n" + |
68 | | - " <li>Due to ${backup.failureReason}</li> \n" + |
69 | | - " </#if> \n" + |
70 | | - " <#if backup.logid??>\n" + |
71 | | - " <li>With logid:${backup.logid}</li>\n" + |
72 | | - " </#if>\n" + |
73 | | - " </ul>\n" + |
74 | | - " </#if>\n" + |
75 | | - " </#items>\n" + |
76 | | - "\n" + |
77 | | - " </ul>\n" + |
78 | | - " </#list>\n" + |
79 | | - "\n" + |
80 | | - " <#list account.deletedBackups>\n" + |
81 | | - " <p>Removed backups for the ${(account.accountName??)?then(\"project\",\"account\")}:</p> \n" + |
82 | | - " <ul>\n" + |
83 | | - " <#items as backup>\n" + |
84 | | - " <li>Backup ${backup.name} with ID ${backup.id} of VM ${backup.vmName} with ID ${backup.vmId} was created at ${(backup.date?datetime)!\"unable to get date\"} and deleted at ${backup.removed?datetime};</li>\n" + |
85 | | - " </#items>\n" + |
86 | | - " </ul> \n" + |
87 | | - " </#list>\n" + |
88 | | - " </#list>\n" + |
89 | | - "</#list>\n" + |
90 | | - "\n" + |
91 | | - "<#list backupScheduleResponseList>\n" + |
92 | | - "<hr>\n" + |
93 | | - "<h1>Scheduled backups</h1>\n" + |
94 | | - "\n" + |
95 | | - "<table>\n" + |
96 | | - "<thead>\n" + |
97 | | - "<tr>\n" + |
98 | | - "<th>VM</th>\n" + |
99 | | - "<th>ID</th>\n" + |
100 | | - "<th>Scheduled date</th>\n" + |
101 | | - "<th>Schedule ID</th>\n" + |
102 | | - "</tr>\n" + |
103 | | - "</thead>\n" + |
104 | | - "<tbody> \n" + |
105 | | - " <#items as schedule>\n" + |
106 | | - " <tr>\n" + |
107 | | - " <td>${schedule.vmName}</td>\n" + |
108 | | - " <td>${schedule.vmId}</td>\n" + |
109 | | - " <td>${schedule.schedule}</td>\n" + |
110 | | - " <td>${schedule.id}</td>\n" + |
111 | | - " </tr>\n" + |
112 | | - " </#items>\n" + |
113 | | - "</tbody>\n" + |
114 | | - "</table>\n" + |
115 | | - "</#list>\n\')"; |
116 | | - |
117 | 28 | @Override |
118 | 29 | public String[] getUpgradableVersionRange() { |
119 | 30 | return new String[]{"4.20.2.0", "4.20.3.0"}; |
@@ -142,29 +53,6 @@ public InputStream[] getPrepareScripts() { |
142 | 53 |
|
143 | 54 | @Override |
144 | 55 | public void performDataMigration(Connection conn) { |
145 | | - insertBackupReportEmailTemplate(conn); |
146 | | - } |
147 | | - |
148 | | - private void insertBackupReportEmailTemplate(Connection conn) { |
149 | | - try (PreparedStatement pstmt = conn.prepareStatement(SELECT_TEMPLATE)) { |
150 | | - ResultSet result = pstmt.executeQuery(); |
151 | | - if (result.next()) { |
152 | | - logger.debug("Email template for backup_report_template is already on the database."); |
153 | | - return; |
154 | | - } |
155 | | - } catch (SQLException e) { |
156 | | - String message = String.format("Unable to retrieve email templates due to [%s].", e.getMessage()); |
157 | | - logger.error(message, e); |
158 | | - throw new CloudRuntimeException(message, e); |
159 | | - } |
160 | | - |
161 | | - try (PreparedStatement pstmt = conn.prepareStatement(INSERT_TEMPLATE)) { |
162 | | - pstmt.executeUpdate(); |
163 | | - } catch (SQLException e) { |
164 | | - String message = String.format("Unable to insert email template for backup_report_template due to [%s].", e.getMessage()); |
165 | | - logger.error(message, e); |
166 | | - throw new CloudRuntimeException(message, e); |
167 | | - } |
168 | 56 | } |
169 | 57 |
|
170 | 58 | @Override |
|
0 commit comments