mirror of
https://github.com/apache/cloudstack.git
synced 2025-10-26 08:42:29 +01:00
Changes to add 'cluster_id' to 'op_host_capacity' table for Db upgrade from 222 to 224
This commit is contained in:
parent
639a8aca9d
commit
5bbffcaa97
@ -19,7 +19,11 @@ package com.cloud.upgrade.dao;
|
||||
|
||||
import java.io.File;
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
|
||||
import com.cloud.capacity.Capacity;
|
||||
import com.cloud.utils.exception.CloudRuntimeException;
|
||||
import com.cloud.utils.script.Script;
|
||||
|
||||
@ -52,6 +56,7 @@ public class Upgrade222to224 implements DbUpgrade {
|
||||
|
||||
@Override
|
||||
public void performDataMigration(Connection conn) {
|
||||
updateClusterIdInOpHostCapacity(conn);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -59,4 +64,59 @@ public class Upgrade222to224 implements DbUpgrade {
|
||||
return null;
|
||||
}
|
||||
|
||||
private void updateClusterIdInOpHostCapacity(Connection conn){
|
||||
PreparedStatement pstmt = null;
|
||||
ResultSet rs = null;
|
||||
PreparedStatement pstmtUpdate = null;
|
||||
try {
|
||||
//Host and Primary storage capacity types
|
||||
pstmt = conn.prepareStatement("SELECT host_id, capacity_type FROM op_host_capacity WHERE capacity_type IN (0,1,2,3)");
|
||||
rs = pstmt.executeQuery();
|
||||
while (rs.next()) {
|
||||
long hostId = rs.getLong(1);
|
||||
short capacityType = rs.getShort(2);
|
||||
String updateSQLPrefix = "Update op_host_capacity set cluster_id = (select cluster_id from ";
|
||||
String updateSQLSuffix = " where id = ? ) where host_id = ?";
|
||||
String tableName = "host";
|
||||
switch(capacityType){
|
||||
case Capacity.CAPACITY_TYPE_MEMORY:
|
||||
case Capacity.CAPACITY_TYPE_CPU:
|
||||
tableName = "host";
|
||||
break;
|
||||
case Capacity.CAPACITY_TYPE_STORAGE:
|
||||
case Capacity.CAPACITY_TYPE_STORAGE_ALLOCATED:
|
||||
tableName = "storage_pool";
|
||||
break;
|
||||
}
|
||||
pstmtUpdate = conn.prepareStatement(updateSQLPrefix + tableName + updateSQLSuffix);
|
||||
pstmtUpdate.setLong(1, hostId);
|
||||
pstmtUpdate.setLong(2, hostId);
|
||||
pstmtUpdate.executeUpdate();
|
||||
pstmtUpdate.close();
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
throw new CloudRuntimeException("Unable to update the cluster Ids in Op_Host_capacity table", e);
|
||||
}finally{
|
||||
if(pstmtUpdate != null){
|
||||
try{
|
||||
pstmtUpdate.close();
|
||||
}catch (SQLException e) {
|
||||
}
|
||||
}
|
||||
if(rs != null){
|
||||
try{
|
||||
rs.close();
|
||||
}catch (SQLException e) {
|
||||
}
|
||||
}
|
||||
if(pstmt != null){
|
||||
try{
|
||||
pstmt.close();
|
||||
}catch (SQLException e) {
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
6
setup/db/schema-222to224.sql
Normal file
6
setup/db/schema-222to224.sql
Normal file
@ -0,0 +1,6 @@
|
||||
--;
|
||||
-- Schema upgrade from 2.2.2 to 2.2.4;
|
||||
--;
|
||||
ALTER TABLE `cloud`.`op_host_capacity` ADD COLUMN `cluster_id` bigint unsigned AFTER `pod_id`;
|
||||
ALTER TABLE `cloud`.`op_host_capacity` ADD CONSTRAINT `fk_op_host_capacity__cluster_id` FOREIGN KEY `fk_op_host_capacity__cluster_id` (`cluster_id`) REFERENCES `cloud`.`cluster`(`id`) ON DELETE CASCADE;
|
||||
ALTER TABLE `cloud`.`op_host_capacity` ADD INDEX `i_op_host_capacity__cluster_id`(`cluster_id`);
|
||||
Loading…
x
Reference in New Issue
Block a user