CLOUDSTACK-10012: Load SQL schema scripts from JAR (#2247)

Load SQL schema scripts from the uber/fat JAR. This also removes the setup/db/db directory from centos packaging.
This commit is contained in:
Marc-Aurèle Brothier 2017-12-19 07:41:38 +01:00 committed by Rohit Yadav
parent 49be7eecd2
commit a372040798
153 changed files with 587 additions and 800 deletions

View File

@ -584,7 +584,7 @@
</copy>
<copy overwrite="true" todir="${basedir}/target/utilities/scripts/db">
<fileset dir="${basedir}/../setup/db">
<include name="**/*"/>
<include name="*"/>
</fileset>
<filterchain>
<filterreader classname="org.apache.tools.ant.filters.ReplaceTokens">

View File

@ -85,10 +85,9 @@ import org.apache.commons.lang.StringUtils;
import org.apache.log4j.Logger;
import javax.inject.Inject;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.Arrays;
@ -453,20 +452,17 @@ public class DatabaseUpgradeChecker implements SystemIntegrityChecker {
availableVersions = ImmutableList.copyOf(sortedVersions);
}
protected void runScript(Connection conn, File file) {
protected void runScript(Connection conn, InputStream file) {
try (FileReader reader = new FileReader(file);) {
try (InputStreamReader reader = new InputStreamReader(file)) {
ScriptRunner runner = new ScriptRunner(conn, false, true);
runner.runScript(reader);
} catch (FileNotFoundException e) {
s_logger.error("Unable to find upgrade script: " + file.getAbsolutePath(), e);
throw new CloudRuntimeException("Unable to find upgrade script: " + file.getAbsolutePath(), e);
} catch (IOException e) {
s_logger.error("Unable to read upgrade script: " + file.getAbsolutePath(), e);
throw new CloudRuntimeException("Unable to read upgrade script: " + file.getAbsolutePath(), e);
s_logger.error("Unable to read upgrade script", e);
throw new CloudRuntimeException("Unable to read upgrade script", e);
} catch (SQLException e) {
s_logger.error("Unable to execute upgrade script: " + file.getAbsolutePath(), e);
throw new CloudRuntimeException("Unable to execute upgrade script: " + file.getAbsolutePath(), e);
s_logger.error("Unable to execute upgrade script", e);
throw new CloudRuntimeException("Unable to execute upgrade script", e);
}
}
@ -555,9 +551,9 @@ public class DatabaseUpgradeChecker implements SystemIntegrityChecker {
s_logger.error(errorMessage, e);
throw new CloudRuntimeException(errorMessage, e);
}
File[] scripts = upgrade.getPrepareScripts();
InputStream[] scripts = upgrade.getPrepareScripts();
if (scripts != null) {
for (File script : scripts) {
for (InputStream script : scripts) {
runScript(conn, script);
}
}
@ -591,11 +587,11 @@ public class DatabaseUpgradeChecker implements SystemIntegrityChecker {
throw new CloudRuntimeException("Unable to cleanup the database", e);
}
File[] scripts = upgrade.getCleanupScripts();
InputStream[] scripts = upgrade.getCleanupScripts();
if (scripts != null) {
for (File script : scripts) {
for (InputStream script : scripts) {
runScript(conn, script);
s_logger.debug("Cleanup script " + script.getAbsolutePath() + " is executed successfully");
s_logger.debug("Cleanup script " + upgrade.getClass().getSimpleName() + " is executed successfully");
}
}
txn.commit();
@ -681,8 +677,8 @@ public class DatabaseUpgradeChecker implements SystemIntegrityChecker {
}
@Override
public File[] getPrepareScripts() {
return new File[0];
public InputStream[] getPrepareScripts() {
return new InputStream[0];
}
@Override
@ -691,8 +687,8 @@ public class DatabaseUpgradeChecker implements SystemIntegrityChecker {
}
@Override
public File[] getCleanupScripts() {
return new File[0];
public InputStream[] getCleanupScripts() {
return new InputStream[0];
}
}

View File

@ -16,7 +16,7 @@
// under the License.
package com.cloud.upgrade.dao;
import java.io.File;
import java.io.InputStream;
import java.sql.Connection;
public interface DbUpgrade {
@ -30,16 +30,12 @@ public interface DbUpgrade {
* @return the script to prepare the database schema for the
* data migration step.
*/
File[] getPrepareScripts();
InputStream[] getPrepareScripts();
/**
* Performs the actual data migration.
*/
void performDataMigration(Connection conn);
/**
*
* @return
*/
File[] getCleanupScripts();
InputStream[] getCleanupScripts();
}

View File

@ -16,27 +16,27 @@
// under the License.
package com.cloud.upgrade.dao;
import java.io.File;
import java.io.InputStream;
import java.sql.Connection;
import com.cloud.utils.exception.CloudRuntimeException;
import com.cloud.utils.script.Script;
public class Upgrade217to218 implements DbUpgrade {
@Override
public File[] getPrepareScripts() {
String schemaFile = Script.findScript("", "db/schema-217to218.sql");
if (schemaFile == null) {
throw new CloudRuntimeException("Unable to find the upgrade script, schema-217to218.sql");
public InputStream[] getPrepareScripts() {
final String scriptFile = "META-INF/db/schema-217to218.sql";
final InputStream script = Thread.currentThread().getContextClassLoader().getResourceAsStream(scriptFile);
if (script == null) {
throw new CloudRuntimeException("Unable to find " + scriptFile);
}
final String dataFile = "META-INF/db/data-217to218.sql";
final InputStream data = Thread.currentThread().getContextClassLoader().getResourceAsStream(dataFile);
if (data == null) {
throw new CloudRuntimeException("Unable to find " + dataFile);
}
String dataFile = Script.findScript("", "db/data-217to218.sql");
if (dataFile == null) {
throw new CloudRuntimeException("Unable to find the upgrade script, data-217to218.sql");
}
return new File[] {new File(schemaFile), new File(dataFile)};
return new InputStream[] {script, data};
}
@Override
@ -45,7 +45,7 @@ public class Upgrade217to218 implements DbUpgrade {
}
@Override
public File[] getCleanupScripts() {
public InputStream[] getCleanupScripts() {
return null;
}

View File

@ -16,8 +16,8 @@
// under the License.
package com.cloud.upgrade.dao;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.StringReader;
import java.sql.Connection;
import java.sql.PreparedStatement;
@ -44,20 +44,20 @@ import com.cloud.utils.DateUtil;
import com.cloud.utils.NumbersUtil;
import com.cloud.utils.exception.CloudRuntimeException;
import com.cloud.utils.net.NetUtils;
import com.cloud.utils.script.Script;
public class Upgrade218to22 implements DbUpgrade {
final static Logger s_logger = Logger.getLogger(Upgrade218to22.class);
boolean _basicZone;
@Override
public File[] getPrepareScripts() {
String file = Script.findScript("", "db/schema-21to22.sql");
if (file == null) {
throw new CloudRuntimeException("Unable to find the upgrade script, schema-21to22.sql");
public InputStream[] getPrepareScripts() {
final String scriptFile = "META-INF/db/schema-21to22.sql";
final InputStream script = Thread.currentThread().getContextClassLoader().getResourceAsStream(scriptFile);
if (script == null) {
throw new CloudRuntimeException("Unable to find " + scriptFile);
}
return new File[] {new File(file)};
return new InputStream[] {script};
}
protected void upgradeStoragePools(Connection conn) {
@ -768,10 +768,6 @@ public class Upgrade218to22 implements DbUpgrade {
}
}
/**
* @param conn
* @throws SQLException
*/
private void updateDatacenterWithServices(Connection conn) throws SQLException {
try (PreparedStatement updateDataCenter =
conn.prepareStatement("UPDATE data_center SET networktype=?, dns_provider=?, gateway_provider=?, firewall_provider=?, dhcp_provider=?, lb_provider=?, vpn_provider=?, userdata_provider=?");) {
@ -812,11 +808,6 @@ public class Upgrade218to22 implements DbUpgrade {
}
}
/**
* @param conn
* @return
* @throws SQLException
*/
private ArrayList<Object[]> retrieveDataCenters(Connection conn) throws SQLException {
PreparedStatement selectDcData = conn.prepareStatement("SELECT id, guest_network_cidr, domain FROM data_center");
ResultSet dcData = selectDcData.executeQuery();
@ -833,11 +824,6 @@ public class Upgrade218to22 implements DbUpgrade {
return dcs;
}
/**
* @return
* @throws SQLException
* @throws CloudRuntimeException
*/
private long retrieveNetworkOfferingId(Connection conn, String type) throws SQLException, CloudRuntimeException {
long networkOfferingId;
try (
@ -855,14 +841,6 @@ public class Upgrade218to22 implements DbUpgrade {
}
}
/**
* @param conn
* @param managementNetworkOfferingId
* @param controlNetworkOfferingId
* @param storageNetworkOfferingId
* @param dc
* @throws SQLException
*/
private void updateBasicNetworkingDataCenter(Connection conn, long managementNetworkOfferingId, long controlNetworkOfferingId, long storageNetworkOfferingId, Object[] dc)
throws SQLException {
Long dcId = (Long)dc[0];
@ -892,13 +870,6 @@ public class Upgrade218to22 implements DbUpgrade {
updateConsoleProxies(conn, dcId, mgmtNetworkId, controlNetworkId, basicDefaultDirectNetworkId, "Basic");
}
/**
* @param conn
* @param dcId
* @param controlNetworkId
* @param basicDefaultDirectNetworkId
* @throws SQLException
*/
private void retrieveAndUpdateDomainRouters(Connection conn, Long dcId, long controlNetworkId, long basicDefaultDirectNetworkId) throws SQLException {
try (PreparedStatement selectVmInstanceData =
conn.prepareStatement("SELECT vm_instance.id, vm_instance.domain_id, vm_instance.account_id, domain_router.gateway, domain_router.guest_ip_address, domain_router.domain, domain_router.dns1, domain_router.dns2, domain_router.vnet FROM vm_instance INNER JOIN domain_router ON vm_instance.id=domain_router.id WHERE vm_instance.removed IS NULL AND vm_instance.type='DomainRouter' AND vm_instance.data_center_id=?");) {
@ -917,12 +888,6 @@ public class Upgrade218to22 implements DbUpgrade {
}
}
/**
* @param conn
* @param dcId
* @param networkId
* @throws SQLException
*/
private void updateVlanWithNetworkForDataCenter(Connection conn, Long dcId, long networkId) throws SQLException {
try (PreparedStatement selectVlanId = conn.prepareStatement("SELECT id FROM vlan WHERE vlan_type='DirectAttached' AND data_center_id=?");) {
selectVlanId.setLong(1, dcId);
@ -936,16 +901,6 @@ public class Upgrade218to22 implements DbUpgrade {
}
}
/**
* @param conn
* @param managementNetworkOfferingId
* @param publicNetworkOfferingId
* @param controlNetworkOfferingId
* @param storageNetworkOfferingId
* @param dc
* @throws SQLException
* @throws CloudRuntimeException
*/
private void updateAdvancedNetworkingDataCenter(Connection conn, long managementNetworkOfferingId, long publicNetworkOfferingId, long controlNetworkOfferingId,
long storageNetworkOfferingId, Object[] dc) throws SQLException, CloudRuntimeException {
Long dcId = (Long)dc[0];
@ -984,11 +939,6 @@ public class Upgrade218to22 implements DbUpgrade {
updateConsoleProxies(conn, dcId, mgmtNetworkId, controlNetworkId, publicNetworkId, "Advanced");
}
/**
* @param dcId
* @return
* @throws SQLException
*/
private ArrayList<Object[]> retrieveRouters(Connection conn, Long dcId) throws SQLException {
ArrayList<Object[]> routers = new ArrayList<Object[]>();
try (PreparedStatement selectRouterData =
@ -1012,28 +962,12 @@ public class Upgrade218to22 implements DbUpgrade {
return routers;
}
/**
* @param conn
* @param dc
* @param dcId
* @param controlNetworkId
* @param publicNetworkId
* @param routers
* @throws SQLException
*/
private void updateRouters(Connection conn, Object[] dc, Long dcId, long controlNetworkId, long publicNetworkId, ArrayList<Object[]> routers) throws SQLException {
for (Object[] router : routers) {
updateRouter(conn, dc, dcId, controlNetworkId, publicNetworkId, router);
}
}
/**
* @param conn
* @param dcId
* @param controlNetworkId
* @param basicDefaultDirectNetworkId
* @param routers
* @throws SQLException
*/
private void updateRouters(Connection conn, Long dcId, long controlNetworkId, long basicDefaultDirectNetworkId, ArrayList<Object[]> routers) throws SQLException {
for (Object[] router : routers) {
s_logger.debug("Updating domR with network id in basic zone id=" + dcId);
@ -1043,16 +977,6 @@ public class Upgrade218to22 implements DbUpgrade {
}
}
/**
* @param conn
* @param dc
* @param dcId
* @param controlNetworkId
* @param publicNetworkId
* @param router
* @throws SQLException
*/
private void updateRouter(Connection conn, Object[] dc, Long dcId, long controlNetworkId, long publicNetworkId, Object[] router) throws SQLException {
String vnet = (String)router[7];
String reservationId = null;
@ -1077,11 +1001,6 @@ public class Upgrade218to22 implements DbUpgrade {
upgradeDomR(conn, dcId, (Long)router[0], publicNetworkId, virtualNetworkId, controlNetworkId, "Advanced", vnet);
}
/**
* @param router
* @param virtualNetworkId
* @throws SQLException
*/
private void updateNetworkForRouter(Connection conn, Object[] router, long virtualNetworkId) throws SQLException {
try (PreparedStatement updateDomainRouter = conn.prepareStatement("UPDATE domain_router SET network_id = ? WHERE id = ? ");) {
updateDomainRouter.setLong(1, virtualNetworkId);
@ -1091,12 +1010,6 @@ public class Upgrade218to22 implements DbUpgrade {
s_logger.debug("Network inserted for " + router[0] + " id = " + virtualNetworkId);
}
/**
* @param conn
* @param dc
* @param dcId
* @throws SQLException
*/
private void createDirectNetworks(Connection conn, Object[] dc, Long dcId) throws SQLException {
// Create direct networks
try (PreparedStatement selectVlanData = conn.prepareStatement("SELECT id, vlan_id, vlan_gateway, vlan_netmask FROM vlan WHERE vlan_type='DirectAttached' AND data_center_id=?");) {
@ -1122,17 +1035,6 @@ public class Upgrade218to22 implements DbUpgrade {
}
}
/**
* @param conn
* @param dc
* @param dcId
* @param vlanNetworkMap
* @param vlanId
* @param tag
* @param gateway
* @param cidr
* @throws SQLException
*/
private void retrieveAccountDataAndCreateNetwork(Connection conn, Object[] dc, Long dcId, HashMap<String, Long> vlanNetworkMap, long vlanId, String tag, String gateway,
String cidr) throws SQLException {
Long accountId = 1L;
@ -1156,12 +1058,6 @@ public class Upgrade218to22 implements DbUpgrade {
}
}
/**
* @param accountId
* @param domainId
* @return
* @throws SQLException
*/
private Long retrieveDomainId(Connection conn,Long accountId) throws SQLException {
try (PreparedStatement pstmt = conn.prepareStatement("SELECT domain_id FROM account WHERE id=?");) {
pstmt.setLong(1, accountId);
@ -1175,11 +1071,6 @@ public class Upgrade218to22 implements DbUpgrade {
}
}
/**
* @param basicDefaultDirectNetworkId
* @param vlanId
* @throws SQLException
*/
private void updateVlanNetworkForTag(Connection conn, long basicDefaultDirectNetworkId, long vlanId) throws SQLException {
try (PreparedStatement pstmt = conn.prepareStatement("UPDATE vlan SET network_id=? WHERE id=?");) {
pstmt.setLong(1, basicDefaultDirectNetworkId);
@ -1188,22 +1079,10 @@ public class Upgrade218to22 implements DbUpgrade {
}
}
/**
* @param vlanNetworkMap
* @param vlanId
* @param tag
* @throws SQLException
*/
private void updateNetworkInVlanTableforTag(Connection conn, HashMap<String, Long> vlanNetworkMap, long vlanId, String tag) throws SQLException {
updateVlanNetworkForTag(conn, vlanId, vlanNetworkMap.get(tag));
}
/**
* @param conn
* @param dcId
* @return
* @throws SQLException
*/
private ArrayList<Object[]> retrieveDhcpServers(Connection conn, Long dcId) throws SQLException {
// Create DHCP domRs - Direct networks
try (PreparedStatement pstmt =
@ -1222,15 +1101,6 @@ public class Upgrade218to22 implements DbUpgrade {
}
}
/**
* @param conn
* @param dcId
* @param controlNetworkId
* @param routerId
* @param directIp
* @throws SQLException
* @throws CloudRuntimeException
*/
private void updateDhcpServerData(Connection conn, Long dcId, long controlNetworkId, Long routerId, String directIp) throws SQLException, CloudRuntimeException {
try (
PreparedStatement pstmt =
@ -1257,13 +1127,6 @@ public class Upgrade218to22 implements DbUpgrade {
}
}
/**
* @param conn
* @param directNetworkId
* @return
* @throws SQLException
* @throws CloudRuntimeException
*/
private String retrieveGateway(Connection conn, Long directNetworkId) throws SQLException, CloudRuntimeException {
try (PreparedStatement selectGateway = conn.prepareStatement("SELECT gateway from networks where id=?");) {
selectGateway.setLong(1, directNetworkId);
@ -1277,11 +1140,6 @@ public class Upgrade218to22 implements DbUpgrade {
}
}
/**
* @param routerId
* @param directNetworkId
* @throws SQLException
*/
private void updateDomainRouter(Connection conn, Long routerId, Long directNetworkId) throws SQLException {
try (PreparedStatement updateDomainRouter = conn.prepareStatement("UPDATE domain_router SET network_id = ? WHERE id = ? ");) {
updateDomainRouter.setLong(1, directNetworkId);
@ -1290,14 +1148,6 @@ public class Upgrade218to22 implements DbUpgrade {
}
}
/**
* @param conn
* @param dcId
* @param mgmtNetworkId
* @param controlNetworkId
* @param publicNetworkId
* @throws SQLException
*/
private void updateConsoleProxies(Connection conn, Long dcId, long mgmtNetworkId, long controlNetworkId, long publicNetworkId, String networkingType) throws SQLException {
// Upgrade ConsoleProxy
try (PreparedStatement selectInstanceIds = conn.prepareStatement("SELECT vm_instance.id FROM vm_instance WHERE removed IS NULL AND type='ConsoleProxy' AND data_center_id=?");) {
@ -2299,13 +2149,14 @@ public class Upgrade218to22 implements DbUpgrade {
}
@Override
public File[] getCleanupScripts() {
String file = Script.findScript("", "db/schema-21to22-cleanup.sql");
if (file == null) {
throw new CloudRuntimeException("Unable to find the upgrade script, schema-21to22-cleanup.sql");
public InputStream[] getCleanupScripts() {
final String scriptFile = "META-INF/db/schema-21to22-cleanup.sql";
final InputStream script = Thread.currentThread().getContextClassLoader().getResourceAsStream(scriptFile);
if (script == null) {
throw new CloudRuntimeException("Unable to find " + scriptFile);
}
return new File[] {new File(file)};
return new InputStream[] {script};
}
@Override

View File

@ -16,7 +16,7 @@
// under the License.
package com.cloud.upgrade.dao;
import java.io.File;
import java.io.InputStream;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
@ -31,7 +31,7 @@ public class Upgrade218to224DomainVlans implements DbUpgrade {
final static Logger s_logger = Logger.getLogger(Upgrade218to224DomainVlans.class);
@Override
public File[] getPrepareScripts() {
public InputStream[] getPrepareScripts() {
return null;
}
@ -93,7 +93,7 @@ public class Upgrade218to224DomainVlans implements DbUpgrade {
}
@Override
public File[] getCleanupScripts() {
public InputStream[] getCleanupScripts() {
return null;
}

View File

@ -16,26 +16,23 @@
// under the License.
package com.cloud.upgrade.dao;
import java.io.File;
import java.io.InputStream;
import java.sql.Connection;
import java.sql.PreparedStatement;
import com.cloud.utils.exception.CloudRuntimeException;
import com.cloud.utils.script.Script;
public class Upgrade218to22Premium extends Upgrade218to22 {
@Override
public File[] getPrepareScripts() {
File[] scripts = super.getPrepareScripts();
File[] newScripts = new File[2];
newScripts[0] = scripts[0];
String file = Script.findScript("", "db/schema-21to22-premium.sql");
if (file == null) {
throw new CloudRuntimeException("Unable to find the upgrade script, schema-21to22-premium.sql");
public InputStream[] getPrepareScripts() {
InputStream[] newScripts = new InputStream[2];
newScripts[0] = super.getPrepareScripts()[0];
final String scriptFile = "META-INF/db/schema-21to22-premium.sql";
final InputStream script = Thread.currentThread().getContextClassLoader().getResourceAsStream(scriptFile);
if (script == null) {
throw new CloudRuntimeException("Unable to find " + scriptFile);
}
newScripts[1] = new File(file);
newScripts[1] = script;
return newScripts;
}
@ -47,15 +44,6 @@ public class Upgrade218to22Premium extends Upgrade218to22 {
updateUsageIpAddress(conn);
}
@Override
public File[] getCleanupScripts() {
File[] scripts = super.getCleanupScripts();
File[] newScripts = new File[1];
// Change the array to 2 when you add in the scripts for premium.
newScripts[0] = scripts[0];
return newScripts;
}
private void updateUserStats(Connection conn) {
try ( // update device_id information
PreparedStatement pstmt = conn.prepareStatement(

View File

@ -16,16 +16,12 @@
// under the License.
package com.cloud.upgrade.dao;
import java.io.File;
import java.io.InputStream;
import java.sql.Connection;
import org.apache.log4j.Logger;
import com.cloud.utils.exception.CloudRuntimeException;
import com.cloud.utils.script.Script;
public class Upgrade2210to2211 implements DbUpgrade {
final static Logger s_logger = Logger.getLogger(Upgrade2210to2211.class);
@Override
public String[] getUpgradableVersionRange() {
@ -43,13 +39,14 @@ public class Upgrade2210to2211 implements DbUpgrade {
}
@Override
public File[] getPrepareScripts() {
String script = Script.findScript("", "db/schema-2210to2211.sql");
public InputStream[] getPrepareScripts() {
final String scriptFile = "META-INF/db/schema-2210to2211.sql";
final InputStream script = Thread.currentThread().getContextClassLoader().getResourceAsStream(scriptFile);
if (script == null) {
throw new CloudRuntimeException("Unable to find db/schema-2210to2211.sql");
throw new CloudRuntimeException("Unable to find " + scriptFile);
}
return new File[] {new File(script)};
return new InputStream[] {script};
}
@Override
@ -57,7 +54,7 @@ public class Upgrade2210to2211 implements DbUpgrade {
}
@Override
public File[] getCleanupScripts() {
public InputStream[] getCleanupScripts() {
return null;
}

View File

@ -16,7 +16,7 @@
// under the License.
package com.cloud.upgrade.dao;
import java.io.File;
import java.io.InputStream;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
@ -27,7 +27,6 @@ import java.util.List;
import org.apache.log4j.Logger;
import com.cloud.utils.exception.CloudRuntimeException;
import com.cloud.utils.script.Script;
public class Upgrade2211to2212 implements DbUpgrade {
final static Logger s_logger = Logger.getLogger(Upgrade2211to2212.class);
@ -48,13 +47,14 @@ public class Upgrade2211to2212 implements DbUpgrade {
}
@Override
public File[] getPrepareScripts() {
String script = Script.findScript("", "db/schema-2211to2212.sql");
public InputStream[] getPrepareScripts() {
final String scriptFile = "META-INF/db/schema-2211to2212.sql";
final InputStream script = Thread.currentThread().getContextClassLoader().getResourceAsStream(scriptFile);
if (script == null) {
throw new CloudRuntimeException("Unable to find db/schema-2211to2212.sql");
throw new CloudRuntimeException("Unable to find " + scriptFile);
}
return new File[] {new File(script)};
return new InputStream[] {script};
}
@Override
@ -63,7 +63,7 @@ public class Upgrade2211to2212 implements DbUpgrade {
}
@Override
public File[] getCleanupScripts() {
public InputStream[] getCleanupScripts() {
return null;
}

View File

@ -16,40 +16,26 @@
// under the License.
package com.cloud.upgrade.dao;
import java.io.File;
import java.sql.Connection;
import java.io.InputStream;
import org.apache.log4j.Logger;
import com.cloud.utils.exception.CloudRuntimeException;
import com.cloud.utils.script.Script;
public class Upgrade2211to2212Premium extends Upgrade2211to2212 {
final static Logger s_logger = Logger.getLogger(Upgrade2211to2212Premium.class);
@Override
public File[] getPrepareScripts() {
File[] scripts = super.getPrepareScripts();
File[] newScripts = new File[2];
newScripts[0] = scripts[0];
String file = Script.findScript("", "db/schema-2211to2212-premium.sql");
if (file == null) {
throw new CloudRuntimeException("Unable to find the upgrade script, schema-2211to2212-premium.sql");
public InputStream[] getPrepareScripts() {
InputStream[] newScripts = new InputStream[2];
newScripts[0] = super.getPrepareScripts()[0];
final String scriptFile = "META-INF/db/schema-2211to2212-premium.sql";
final InputStream script = Thread.currentThread().getContextClassLoader().getResourceAsStream(scriptFile);
if (script == null) {
throw new CloudRuntimeException("Unable to find " + scriptFile);
}
newScripts[1] = new File(file);
newScripts[1] = script;
return newScripts;
}
@Override
public void performDataMigration(Connection conn) {
super.performDataMigration(conn);
}
@Override
public File[] getCleanupScripts() {
return null;
}
}

Some files were not shown because too many files have changed in this diff Show More