Skip to content

Commit 633cc6d

Browse files
committed
DB upgrade path for 42000to42100
1 parent a5c11bc commit 633cc6d

File tree

6 files changed

+134
-8
lines changed

6 files changed

+134
-8
lines changed

api/src/main/java/org/apache/cloudstack/api/command/user/backup/DeleteBackupScheduleCmd.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public class DeleteBackupScheduleCmd extends BaseCmd {
5454
@Parameter(name = ApiConstants.VIRTUAL_MACHINE_ID,
5555
type = CommandType.UUID,
5656
entityType = UserVmResponse.class,
57-
required = false,
57+
required = true,
5858
description = "ID of the VM")
5959
private Long vmId;
6060

@@ -73,7 +73,7 @@ public Long getVmId() {
7373
@Override
7474
public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException, NetworkRuleConflictException {
7575
try {
76-
boolean result = backupManager.deleteBackupSchedule(vmId);
76+
boolean result = backupManager.deleteBackupSchedule(getVmId());
7777
if (result) {
7878
SuccessResponse response = new SuccessResponse(getCommandName());
7979
response.setResponseName(getCommandName());

engine/schema/src/main/java/com/cloud/upgrade/DatabaseUpgradeChecker.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@
8888
import com.cloud.upgrade.dao.Upgrade41810to41900;
8989
import com.cloud.upgrade.dao.Upgrade41900to41910;
9090
import com.cloud.upgrade.dao.Upgrade41910to42000;
91+
import com.cloud.upgrade.dao.Upgrade42000to42100;
9192
import com.cloud.upgrade.dao.Upgrade420to421;
9293
import com.cloud.upgrade.dao.Upgrade421to430;
9394
import com.cloud.upgrade.dao.Upgrade430to440;
@@ -230,6 +231,7 @@ public DatabaseUpgradeChecker() {
230231
.next("4.18.1.0", new Upgrade41810to41900())
231232
.next("4.19.0.0", new Upgrade41900to41910())
232233
.next("4.19.1.0", new Upgrade41910to42000())
234+
.next("4.20.0.0", new Upgrade42000to42100())
233235
.build();
234236
}
235237

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
// Licensed to the Apache Software Foundation (ASF) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The ASF licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
package com.cloud.upgrade.dao;
18+
19+
import java.io.InputStream;
20+
import java.sql.Connection;
21+
22+
import com.cloud.upgrade.SystemVmTemplateRegistration;
23+
import com.cloud.utils.exception.CloudRuntimeException;
24+
25+
public class Upgrade42000to42100 extends DbUpgradeAbstractImpl implements DbUpgrade, DbUpgradeSystemVmTemplate {
26+
private SystemVmTemplateRegistration systemVmTemplateRegistration;
27+
28+
@Override
29+
public String[] getUpgradableVersionRange() {
30+
return new String[] {"4.20.0.0", "4.21.0.0"};
31+
}
32+
33+
@Override
34+
public String getUpgradedVersion() {
35+
return "4.21.0.0";
36+
}
37+
38+
@Override
39+
public boolean supportsRollingUpgrade() {
40+
return false;
41+
}
42+
43+
@Override
44+
public InputStream[] getPrepareScripts() {
45+
final String scriptFile = "META-INF/db/schema-42000to42100.sql";
46+
final InputStream script = Thread.currentThread().getContextClassLoader().getResourceAsStream(scriptFile);
47+
if (script == null) {
48+
throw new CloudRuntimeException("Unable to find " + scriptFile);
49+
}
50+
51+
return new InputStream[] {script};
52+
}
53+
54+
@Override
55+
public void performDataMigration(Connection conn) {
56+
}
57+
58+
@Override
59+
public InputStream[] getCleanupScripts() {
60+
final String scriptFile = "META-INF/db/schema-42000to42100-cleanup.sql";
61+
final InputStream script = Thread.currentThread().getContextClassLoader().getResourceAsStream(scriptFile);
62+
if (script == null) {
63+
throw new CloudRuntimeException("Unable to find " + scriptFile);
64+
}
65+
66+
return new InputStream[] {script};
67+
}
68+
69+
private void initSystemVmTemplateRegistration() {
70+
systemVmTemplateRegistration = new SystemVmTemplateRegistration("");
71+
}
72+
73+
@Override
74+
public void updateSystemVmTemplates(Connection conn) {
75+
logger.debug("Updating System Vm template IDs");
76+
initSystemVmTemplateRegistration();
77+
try {
78+
systemVmTemplateRegistration.updateSystemVmTemplates(conn);
79+
} catch (Exception e) {
80+
throw new CloudRuntimeException("Failed to find / register SystemVM template(s)");
81+
}
82+
}
83+
}

engine/schema/src/main/resources/META-INF/db/schema-41910to42000.sql

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -412,8 +412,6 @@ CREATE TABLE `cloud`.`backup_repository` (
412412
ALTER TABLE `cloud`.`backup_schedule` DROP FOREIGN KEY fk_backup_schedule__vm_id;
413413
ALTER TABLE `cloud`.`backup_schedule` DROP INDEX vm_id;
414414
ALTER TABLE `cloud`.`backup_schedule` ADD CONSTRAINT fk_backup_schedule__vm_id FOREIGN KEY (vm_id) REFERENCES vm_instance(id) ON DELETE CASCADE;
415-
ALTER TABLE `cloud`.`backup_schedule` ADD COLUMN `max_backups` int(8) default NULL COMMENT 'maximum number of backups to maintain';
416-
ALTER TABLE `cloud`.`backups` ADD COLUMN `backup_interval_type` int(5) COMMENT 'type of backup, e.g. manual, recurring - hourly, daily, weekly or monthly';
417415

418416
-- Add volume details to the backups table to keep track of the volumes being backed up
419417
CALL `cloud`.`IDEMPOTENT_ADD_COLUMN`('cloud.backups', 'backed_volumes', 'text DEFAULT NULL COMMENT "details of backed-up volumes" ');
@@ -427,7 +425,3 @@ INSERT IGNORE INTO `cloud`.`guest_os_hypervisor` (uuid, hypervisor_type, hypervi
427425

428426
CALL `cloud`.`IDEMPOTENT_ADD_COLUMN`('cloud.vm_instance', 'delete_protection', 'boolean DEFAULT FALSE COMMENT "delete protection for vm" ');
429427
CALL `cloud`.`IDEMPOTENT_ADD_COLUMN`('cloud.volumes', 'delete_protection', 'boolean DEFAULT FALSE COMMENT "delete protection for volumes" ');
430-
431-
--- TODO: Move to 42000to42100.sql
432-
-- Add Backup related settings to a new Subgroup
433-
INSERT INTO `cloud`.`configuration_subgroup` (`name`, `keywords`, `precedence`, `group_id`) VALUES ('Backup', NULL, 5, (SELECT id FROM `cloud`.`configuration_group` WHERE `name` = 'Storage'));
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
-- Licensed to the Apache Software Foundation (ASF) under one
2+
-- or more contributor license agreements. See the NOTICE file
3+
-- distributed with this work for additional information
4+
-- regarding copyright ownership. The ASF licenses this file
5+
-- to you under the Apache License, Version 2.0 (the
6+
-- "License"); you may not use this file except in compliance
7+
-- with the License. You may obtain a copy of the License at
8+
--
9+
-- http://www.apache.org/licenses/LICENSE-2.0
10+
--
11+
-- Unless required by applicable law or agreed to in writing,
12+
-- software distributed under the License is distributed on an
13+
-- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
-- KIND, either express or implied. See the License for the
15+
-- specific language governing permissions and limitations
16+
-- under the License.
17+
18+
--;
19+
-- Schema upgrade cleanup from 4.20.0.0 to 4.21.0.0
20+
--;
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
-- Licensed to the Apache Software Foundation (ASF) under one
2+
-- or more contributor license agreements. See the NOTICE file
3+
-- distributed with this work for additional information
4+
-- regarding copyright ownership. The ASF licenses this file
5+
-- to you under the Apache License, Version 2.0 (the
6+
-- "License"); you may not use this file except in compliance
7+
-- with the License. You may obtain a copy of the License at
8+
--
9+
-- http://www.apache.org/licenses/LICENSE-2.0
10+
--
11+
-- Unless required by applicable law or agreed to in writing,
12+
-- software distributed under the License is distributed on an
13+
-- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
-- KIND, either express or implied. See the License for the
15+
-- specific language governing permissions and limitations
16+
-- under the License.
17+
18+
--;
19+
-- Schema upgrade from 4.20.0.0 to 4.21.0.0
20+
--;
21+
22+
-- Add columns max_backup and backup_interval_type to backup table
23+
ALTER TABLE `cloud`.`backup_schedule` ADD COLUMN `max_backups` int(8) default NULL COMMENT 'maximum number of backups to maintain';
24+
ALTER TABLE `cloud`.`backups` ADD COLUMN `backup_interval_type` int(5) COMMENT 'type of backup, e.g. manual, recurring - hourly, daily, weekly or monthly';
25+
26+
-- Add Backup related settings to a new Subgroup
27+
INSERT INTO `cloud`.`configuration_subgroup` (`name`, `keywords`, `precedence`, `group_id`) VALUES ('Backup', NULL, 5, (SELECT id FROM `cloud`.`configuration_group` WHERE `name` = 'Storage'));

0 commit comments

Comments
 (0)