mirror of
https://github.com/apache/cloudstack.git
synced 2025-10-26 08:42:29 +01:00
move db migration to script
This commit is contained in:
parent
e393e15f7a
commit
4f2790c09b
@ -18,8 +18,6 @@
|
||||
|
||||
package com.cloud.storage.snapshot;
|
||||
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
@ -111,8 +109,6 @@ import com.cloud.vm.dao.UserVmDao;
|
||||
@Local(value={SnapshotManager.class, SnapshotService.class})
|
||||
public class SnapshotManagerImpl implements SnapshotManager, SnapshotService, Manager {
|
||||
private static final Logger s_logger = Logger.getLogger(SnapshotManagerImpl.class);
|
||||
private static final String GET_LAST_ID = "SELECT id FROM cloud.snapshots ORDER BY id DESC LIMIT 1";
|
||||
private static final String UPDATE_SNAPSHOT_SEQ = "UPDATE cloud.sequence SET value=? WHERE name='snapshots_seq'";
|
||||
|
||||
@Inject protected HostDao _hostDao;
|
||||
@Inject protected UserVmDao _vmDao;
|
||||
@ -1150,40 +1146,6 @@ public class SnapshotManagerImpl implements SnapshotManager, SnapshotService, Ma
|
||||
return _snapshotDao.getNextInSequence(Long.class, "id");
|
||||
}
|
||||
|
||||
private Long _getLastId() {
|
||||
Transaction txn = Transaction.open(Transaction.CLOUD_DB);
|
||||
PreparedStatement pstmt = null;
|
||||
String sql = GET_LAST_ID;
|
||||
try {
|
||||
pstmt = txn.prepareAutoCloseStatement(sql);
|
||||
ResultSet rs = pstmt.executeQuery();
|
||||
if (rs.next()) {
|
||||
return Long.valueOf(rs.getLong(1));
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
s_logger.error("error getting last id", ex);
|
||||
}
|
||||
return 1l;
|
||||
}
|
||||
|
||||
private void _updateSnapshotSeq(Long seq) {
|
||||
Transaction txn = Transaction.open(Transaction.CLOUD_DB);
|
||||
try {
|
||||
txn.start();
|
||||
String sql = UPDATE_SNAPSHOT_SEQ;
|
||||
PreparedStatement pstmt = null;
|
||||
pstmt = txn.prepareAutoCloseStatement(sql);
|
||||
pstmt.setLong(1, seq.longValue());
|
||||
pstmt.execute();
|
||||
txn.commit();
|
||||
} catch (Exception ex) {
|
||||
txn.rollback();
|
||||
String msg = "error seting snapshots_seq to " + seq;
|
||||
s_logger.error(msg, ex);
|
||||
throw new CloudRuntimeException(msg, ex);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean configure(String name, Map<String, Object> params) throws ConfigurationException {
|
||||
_name = name;
|
||||
@ -1203,14 +1165,6 @@ public class SnapshotManagerImpl implements SnapshotManager, SnapshotService, Ma
|
||||
_totalRetries = NumbersUtil.parseInt(configDao.getValue("total.retries"), 4);
|
||||
_pauseInterval = 2*NumbersUtil.parseInt(configDao.getValue("ping.interval"), 60);
|
||||
|
||||
Long lastId = _getLastId();
|
||||
if ( lastId == null ) {
|
||||
String msg = "Can not get last id of snapshots";
|
||||
s_logger.error(msg);
|
||||
throw new CloudRuntimeException(msg);
|
||||
}
|
||||
s_logger.info("Set shapshot sequence to " + (lastId + 1));
|
||||
_updateSnapshotSeq( lastId + 1 );
|
||||
s_logger.info("Snapshot Manager is configured.");
|
||||
|
||||
return true;
|
||||
|
||||
@ -17,5 +17,6 @@ INSERT INTO vm_template (id, unique_name, name, public, created, type, hvm, bits
|
||||
Update configuration set name='storage.max.volume.size' where name='max.volume.size.mb';
|
||||
INSERT INTO sequence (name, value)
|
||||
VALUES ('snapshots_seq', '1')
|
||||
UPDATE cloud.sequence SET value=IF((SELECT COUNT(*) FROM cloud.snapshots) > 0, (SELECT max(id) FROM cloud.snapshots) + 1, 1) WHERE name='snapshots_seq'
|
||||
|
||||
COMMIT;
|
||||
|
||||
@ -1,2 +1,3 @@
|
||||
INSERT INTO sequence (name, value)
|
||||
VALUES ('snapshots_seq', '1')
|
||||
UPDATE cloud.sequence SET value=IF((SELECT COUNT(*) FROM cloud.snapshots) > 0, (SELECT max(id) FROM cloud.snapshots) + 1, 1) WHERE name='snapshots_seq'
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user