mirror of
https://github.com/apache/cloudstack.git
synced 2025-11-03 04:12:31 +01:00
db upgrade for multiple secondary storages
This commit is contained in:
parent
44a0fff2ec
commit
2fdedfa14a
@ -36,5 +36,6 @@ public interface SnapshotDao extends GenericDao<SnapshotVO, Long> {
|
||||
long updateSnapshotVersion(long volumeId, String from, String to);
|
||||
List<SnapshotVO> listByVolumeIdVersion(long volumeId, String version);
|
||||
Long getSecHostId(long volumeId);
|
||||
long updateSnapshotSecHost(long dcId, long secHostId);
|
||||
|
||||
}
|
||||
|
||||
@ -40,6 +40,7 @@ public class SnapshotDaoImpl extends GenericDaoBase<SnapshotVO, Long> implements
|
||||
private static final String GET_LAST_SNAPSHOT = "SELECT id FROM snapshots where volume_id = ? AND id != ? AND path IS NOT NULL ORDER BY created DESC";
|
||||
private static final String UPDATE_SNAPSHOT_VERSION = "UPDATE snapshots SET version = ? WHERE volume_id = ? AND version = ?";
|
||||
private static final String GET_SECHOST_ID = "SELECT sechost_id FROM snapshots where volume_id = ? AND backup_snap_id IS NOT NULL AND sechost_id IS NOT NULL LIMIT 1";
|
||||
private static final String UPDATE_SECHOST_ID = "UPDATE snapshots SET sechost_id = ? WHERE data_center_id = ?";
|
||||
|
||||
private final SearchBuilder<SnapshotVO> VolumeIdSearch;
|
||||
private final SearchBuilder<SnapshotVO> VolumeIdTypeSearch;
|
||||
@ -183,4 +184,21 @@ public class SnapshotDaoImpl extends GenericDaoBase<SnapshotVO, Long> implements
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long updateSnapshotSecHost(long dcId, long secHostId) {
|
||||
Transaction txn = Transaction.currentTxn();
|
||||
PreparedStatement pstmt = null;
|
||||
String sql = UPDATE_SECHOST_ID;
|
||||
try {
|
||||
pstmt = txn.prepareAutoCloseStatement(sql);
|
||||
pstmt.setLong(1, secHostId);
|
||||
pstmt.setLong(2, dcId);
|
||||
pstmt.executeUpdate();
|
||||
return 1;
|
||||
} catch (Exception ex) {
|
||||
s_logger.error("error set secondary storage host id", ex);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
@ -19,11 +19,24 @@ package com.cloud.upgrade.dao;
|
||||
|
||||
import java.io.File;
|
||||
import java.sql.Connection;
|
||||
import java.util.List;
|
||||
|
||||
import com.cloud.dc.DataCenterVO;
|
||||
import com.cloud.dc.dao.DataCenterDao;
|
||||
import com.cloud.host.HostVO;
|
||||
import com.cloud.host.dao.HostDao;
|
||||
import com.cloud.storage.dao.SnapshotDao;
|
||||
import com.cloud.utils.component.Inject;
|
||||
import com.cloud.utils.exception.CloudRuntimeException;
|
||||
import com.cloud.utils.script.Script;
|
||||
|
||||
public class Upgrade225to226 implements DbUpgrade {
|
||||
@Inject
|
||||
protected SnapshotDao _snapshotDao;
|
||||
@Inject
|
||||
protected HostDao _hostDao;
|
||||
@Inject
|
||||
protected DataCenterDao _dcDao;
|
||||
|
||||
@Override
|
||||
public String[] getUpgradableVersionRange() {
|
||||
@ -52,6 +65,11 @@ public class Upgrade225to226 implements DbUpgrade {
|
||||
|
||||
@Override
|
||||
public void performDataMigration(Connection conn) {
|
||||
List<DataCenterVO> dcs = _dcDao.listAll();
|
||||
for ( DataCenterVO dc : dcs ) {
|
||||
HostVO host = _hostDao.findSecondaryStorageHost(dc.getId());
|
||||
_snapshotDao.updateSnapshotSecHost(dc.getId(), host.getId());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -94,3 +94,19 @@ CREATE TABLE `cloud`.`op_host_transfer` (
|
||||
CONSTRAINT `fk_op_host_transfer__future_mgmt_server_id` FOREIGN KEY `fk_op_host_transfer__future_mgmt_server_id`(`future_mgmt_server_id`) REFERENCES `mshost`(`msid`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
|
||||
|
||||
|
||||
ALTER TABLE `cloud`.`snapshots` ADD COLUMN `swift_id` bigint unsigned;
|
||||
ALTER TABLE `cloud`.`snapshots` ADD COLUMN `swift_name` varchar(255);
|
||||
ALTER TABLE `cloud`.`snapshots` ADD COLUMN `sechost_id` bigint unsigned;
|
||||
|
||||
|
||||
CREATE TABLE `cloud`.`swift` (
|
||||
`id` bigint unsigned NOT NULL AUTO_INCREMENT,
|
||||
`hostname` varchar(255),
|
||||
`account` varchar(255) COMMENT ' account in swift',
|
||||
`username` varchar(255) COMMENT ' username in swift',
|
||||
`token` varchar(255) COMMENT 'token for this user',
|
||||
PRIMARY KEY (`id`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
|
||||
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user