diff --git a/server/src/com/cloud/upgrade/DatabaseUpgradeChecker.java b/server/src/com/cloud/upgrade/DatabaseUpgradeChecker.java
index 9bd7b798bac..d58fb17152c 100644
--- a/server/src/com/cloud/upgrade/DatabaseUpgradeChecker.java
+++ b/server/src/com/cloud/upgrade/DatabaseUpgradeChecker.java
@@ -22,6 +22,8 @@ import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Date;
import java.util.HashMap;
@@ -31,7 +33,9 @@ import org.apache.log4j.Logger;
import com.cloud.cluster.ClusterManagerImpl;
import com.cloud.maint.Version;
import com.cloud.upgrade.dao.DbUpgrade;
-import com.cloud.upgrade.dao.Upgrade217to22;
+import com.cloud.upgrade.dao.Upgrade217to218;
+import com.cloud.upgrade.dao.Upgrade218to22;
+import com.cloud.upgrade.dao.Upgrade218to224DomainVlans;
import com.cloud.upgrade.dao.Upgrade221to222;
import com.cloud.upgrade.dao.Upgrade222to224;
import com.cloud.upgrade.dao.UpgradeSnapshot217to223;
@@ -54,9 +58,8 @@ public class DatabaseUpgradeChecker implements SystemIntegrityChecker {
VersionDao _dao;
public DatabaseUpgradeChecker() {
_dao = ComponentLocator.inject(VersionDaoImpl.class);
- // FIXME: Alena needs to make changes here to add 217 to 218 upgrade.
- _upgradeMap.put("2.1.7", new DbUpgrade[] { new Upgrade217to22(), new Upgrade221to222(), new UpgradeSnapshot217to223(), new Upgrade222to224()});
- _upgradeMap.put("2.1.8", new DbUpgrade[] { new Upgrade217to22(), new Upgrade221to222(), new UpgradeSnapshot217to223(), new Upgrade222to224()});
+ _upgradeMap.put("2.1.7", new DbUpgrade[] { new Upgrade217to218(), new Upgrade218to22(), new Upgrade221to222(), new UpgradeSnapshot217to223(), new Upgrade222to224()});
+ _upgradeMap.put("2.1.8", new DbUpgrade[] { new Upgrade218to22(), new Upgrade221to222(), new UpgradeSnapshot217to223(), new Upgrade222to224(), new Upgrade218to224DomainVlans()});
_upgradeMap.put("2.2.2", new DbUpgrade[] { new Upgrade222to224() });
_upgradeMap.put("2.2.3", new DbUpgrade[] { new Upgrade222to224() });
}
@@ -121,8 +124,30 @@ public class DatabaseUpgradeChecker implements SystemIntegrityChecker {
}
}
upgrade.performDataMigration(conn);
- VersionVO version = new VersionVO(upgrade.getUpgradedVersion());
- _dao.persist(version);
+ boolean upgradeVersion = true;
+
+ if (upgrade.getUpgradedVersion().equals("2.1.8")) {
+ //we don't have VersionDao in 2.1.x
+ upgradeVersion = false;
+ } else if (upgrade.getUpgradedVersion().equals("2.2.4")) {
+ try {
+ //specifically for domain vlan update from 2.1.8 to 2.2.4
+ PreparedStatement pstmt = conn.prepareStatement("SELECT * FROM version WHERE version='2.2.4'");
+ ResultSet rs = pstmt.executeQuery();
+ if (rs.next()){
+ upgradeVersion = false;
+ }
+ } catch (SQLException e) {
+ throw new CloudRuntimeException("Unable to update the version table", e);
+ }
+ }
+
+
+ if (upgradeVersion) {
+ VersionVO version = new VersionVO(upgrade.getUpgradedVersion());
+ _dao.persist(version);
+ }
+
txn.commit();
} finally {
txn.close();
@@ -134,21 +159,24 @@ public class DatabaseUpgradeChecker implements SystemIntegrityChecker {
for (DbUpgrade upgrade : upgrades) {
s_logger.info("Cleanup upgrade " + upgrade.getClass().getSimpleName() + " to upgrade from " + upgrade.getUpgradableVersionRange()[0] + "-" + upgrade.getUpgradableVersionRange()[1] + " to " + upgrade.getUpgradedVersion());
VersionVO version = _dao.findByVersion(upgrade.getUpgradedVersion(), Step.Upgrade);
- Transaction txn = Transaction.open("Cleanup");
- txn.start();
- try {
- File[] scripts = upgrade.getCleanupScripts();
- if (scripts != null) {
- for (File script : scripts) {
- runScript(script);
+
+ if (version != null) {
+ Transaction txn = Transaction.open("Cleanup");
+ txn.start();
+ try {
+ File[] scripts = upgrade.getCleanupScripts();
+ if (scripts != null) {
+ for (File script : scripts) {
+ runScript(script);
+ }
}
+ version.setStep(Step.Complete);
+ version.setUpdated(new Date());
+ _dao.update(version.getId(), version);
+ txn.commit();
+ } finally {
+ txn.close();
}
- version.setStep(Step.Complete);
- version.setUpdated(new Date());
- _dao.update(version.getId(), version);
- txn.commit();
- } finally {
- txn.close();
}
}
}
diff --git a/server/src/com/cloud/upgrade/dao/Upgrade217to218.java b/server/src/com/cloud/upgrade/dao/Upgrade217to218.java
new file mode 100644
index 00000000000..39936222bb8
--- /dev/null
+++ b/server/src/com/cloud/upgrade/dao/Upgrade217to218.java
@@ -0,0 +1,67 @@
+/**
+ * Copyright (C) 2010 Cloud.com, Inc. All rights reserved.
+ *
+ * This software is licensed under the GNU General Public License v3 or later.
+ *
+ * It is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or any later version.
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ *
+ */
+package com.cloud.upgrade.dao;
+
+import java.io.File;
+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");
+ }
+
+ 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)};
+ }
+
+ @Override
+ public void performDataMigration(Connection conn) {
+
+ }
+
+ @Override
+ public File[] getCleanupScripts() {
+ return null;
+ }
+
+ @Override
+ public String[] getUpgradableVersionRange() {
+ return new String[] { "2.1.7", "2.1.7" };
+ }
+
+ @Override
+ public String getUpgradedVersion() {
+ return "2.1.8";
+ }
+
+ @Override
+ public boolean supportsRollingUpgrade() {
+ return false;
+ }
+}
diff --git a/server/src/com/cloud/upgrade/dao/Upgrade217to22.java b/server/src/com/cloud/upgrade/dao/Upgrade218to22.java
similarity index 99%
rename from server/src/com/cloud/upgrade/dao/Upgrade217to22.java
rename to server/src/com/cloud/upgrade/dao/Upgrade218to22.java
index 77fb3dd0f20..45f6bd04fd3 100644
--- a/server/src/com/cloud/upgrade/dao/Upgrade217to22.java
+++ b/server/src/com/cloud/upgrade/dao/Upgrade218to22.java
@@ -34,8 +34,8 @@ import com.cloud.utils.exception.CloudRuntimeException;
import com.cloud.utils.net.NetUtils;
import com.cloud.utils.script.Script;
-public class Upgrade217to22 implements DbUpgrade {
- final static Logger s_logger = Logger.getLogger(Upgrade217to22.class);
+public class Upgrade218to22 implements DbUpgrade {
+ final static Logger s_logger = Logger.getLogger(Upgrade218to22.class);
boolean _basicZone;
@Override
@@ -842,7 +842,6 @@ public class Upgrade217to22 implements DbUpgrade {
boolean isShared = true;
pstmt = conn.prepareStatement("SELECT account_id FROM account_vlan_map WHERE account_id IS NOT NULL AND vlan_db_id=?");
pstmt.setLong(1, vlanId);
- s_logger.debug("query is " + pstmt);
ResultSet accountRs = pstmt.executeQuery();
while(accountRs.next()) {
isShared = false;
@@ -1117,7 +1116,7 @@ public class Upgrade217to22 implements DbUpgrade {
@Override
public String[] getUpgradableVersionRange() {
- return new String[] { "2.1.7", "2.1.7" };
+ return new String[] { "2.1.8", "2.1.8" };
}
@Override
diff --git a/server/src/com/cloud/upgrade/dao/Upgrade218to224DomainVlans.java b/server/src/com/cloud/upgrade/dao/Upgrade218to224DomainVlans.java
new file mode 100644
index 00000000000..2f0812facdf
--- /dev/null
+++ b/server/src/com/cloud/upgrade/dao/Upgrade218to224DomainVlans.java
@@ -0,0 +1,114 @@
+/**
+ * Copyright (C) 2010 Cloud.com, Inc. All rights reserved.
+ *
+ * This software is licensed under the GNU General Public License v3 or later.
+ *
+ * It is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or any later version.
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ *
+ */
+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 java.util.HashMap;
+
+import org.apache.log4j.Logger;
+
+import com.cloud.utils.exception.CloudRuntimeException;
+
+
+public class Upgrade218to224DomainVlans implements DbUpgrade {
+ final static Logger s_logger = Logger.getLogger(Upgrade218to224DomainVlans.class);
+
+ @Override
+ public File[] getPrepareScripts() {
+ return null;
+ }
+
+ @Override
+ public void performDataMigration(Connection conn) {
+ HashMap networkDomainMap = new HashMap();
+ //populate domain_network_ref table
+ try {
+ PreparedStatement pstmt = conn.prepareStatement("SELECT id FROM networks WHERE shared=1 AND traffic_type='Guest' AND guest_type='Direct'");
+ ResultSet rs = pstmt.executeQuery();
+ s_logger.debug("query is " + pstmt);
+ while (rs.next()) {
+ Long networkId = rs.getLong(1);
+ Long vlanId = null;
+ Long domainId = null;
+
+ pstmt = conn.prepareStatement("SELECT id FROM vlan WHERE network_id=? LIMIT 0,1");
+ pstmt.setLong(1, networkId);
+ s_logger.debug("query is " + pstmt);
+ rs = pstmt.executeQuery();
+
+ while (rs.next()) {
+ vlanId = rs.getLong(1);
+ }
+
+ if (vlanId != null) {
+ pstmt = conn.prepareStatement("SELECT domain_id FROM account_vlan_map WHERE domain_id IS NOT NULL AND vlan_db_id=? LIMIT 0,1");
+ pstmt.setLong(1, vlanId);
+ s_logger.debug("query is " + pstmt);
+ rs = pstmt.executeQuery();
+
+ while (rs.next()) {
+ domainId = rs.getLong(1);
+ }
+
+ if (domainId != null) {
+ if (!networkDomainMap.containsKey(networkId)) {
+ networkDomainMap.put(networkId, domainId);
+ }
+ }
+ }
+ }
+
+ //populate domain level networks
+ for (Long networkId : networkDomainMap.keySet()) {
+ pstmt = conn.prepareStatement("INSERT INTO domain_network_ref (network_id, domain_id) VALUES (?, ?)");
+ pstmt.setLong(1, networkId);
+ pstmt.setLong(2, networkDomainMap.get(networkId));
+ pstmt.executeUpdate();
+ }
+
+ rs.close();
+ pstmt.close();
+ } catch (SQLException e) {
+ throw new CloudRuntimeException("Unable to convert 2.1.x domain level vlans to 2.2.x domain level networks", e);
+ }
+ }
+
+ @Override
+ public File[] getCleanupScripts() {
+ return null;
+ }
+
+ @Override
+ public String[] getUpgradableVersionRange() {
+ return new String[] { "2.1.8", "2.1.8" };
+ }
+
+ @Override
+ public String getUpgradedVersion() {
+ return "2.2.4";
+ }
+
+ @Override
+ public boolean supportsRollingUpgrade() {
+ return false;
+ }
+}
diff --git a/server/src/com/cloud/upgrade/dao/Upgrade222to224.java b/server/src/com/cloud/upgrade/dao/Upgrade222to224.java
index a50730446cb..06242844531 100644
--- a/server/src/com/cloud/upgrade/dao/Upgrade222to224.java
+++ b/server/src/com/cloud/upgrade/dao/Upgrade222to224.java
@@ -61,7 +61,12 @@ public class Upgrade222to224 implements DbUpgrade {
@Override
public File[] getCleanupScripts() {
- return null;
+ String file = Script.findScript("", "db/schema-222to224-cleanup.sql");
+ if (file == null) {
+ throw new CloudRuntimeException("Unable to find the upgrade script, schema-222to224-cleanup.sql");
+ }
+
+ return new File[] {new File(file)};
}
private void updateClusterIdInOpHostCapacity(Connection conn){
diff --git a/server/test/com/cloud/upgrade/BasicZone217To224UpgradeTest.java b/server/test/com/cloud/upgrade/BasicZone218To224UpgradeTest.java
similarity index 94%
rename from server/test/com/cloud/upgrade/BasicZone217To224UpgradeTest.java
rename to server/test/com/cloud/upgrade/BasicZone218To224UpgradeTest.java
index 6c0d37beff5..b96093bac2f 100644
--- a/server/test/com/cloud/upgrade/BasicZone217To224UpgradeTest.java
+++ b/server/test/com/cloud/upgrade/BasicZone218To224UpgradeTest.java
@@ -34,8 +34,8 @@ import com.cloud.utils.component.ComponentLocator;
import com.cloud.utils.db.DbTestUtils;
import com.cloud.utils.db.Transaction;
-public class BasicZone217To224UpgradeTest extends TestCase {
- private static final Logger s_logger = Logger.getLogger(BasicZone217To224UpgradeTest.class);
+public class BasicZone218To224UpgradeTest extends TestCase {
+ private static final Logger s_logger = Logger.getLogger(BasicZone218To224UpgradeTest.class);
@Override
@Before
@@ -49,8 +49,8 @@ public class BasicZone217To224UpgradeTest extends TestCase {
}
public void test217to22Upgrade() throws SQLException {
- s_logger.debug("Finding sample data from 2.1.7");
- DbTestUtils.executeScript("PreviousDatabaseSchema/2.1.7/2.1.7_sample_basicZone_SecurityGroups.sql", false, true);
+ s_logger.debug("Finding sample data from 2.1.8");
+ DbTestUtils.executeScript("PreviousDatabaseSchema/2.1.8/2.1.8_sample_basicZone_SecurityGroups.sql", false, true);
Connection conn = Transaction.getStandaloneConnection();
PreparedStatement pstmt;
@@ -60,18 +60,18 @@ public class BasicZone217To224UpgradeTest extends TestCase {
String version = dao.getCurrentVersion();
- if (!version.equals("2.1.7")) {
- s_logger.error("Version returned is not 2.1.7 but " + version);
+ if (!version.equals("2.1.8")) {
+ s_logger.error("Version returned is not 2.1.8 but " + version);
} else {
s_logger.debug("Basic zone test version is " + version);
}
- checker.upgrade("2.1.7", "2.2.4");
+ checker.upgrade("2.1.8", "2.2.4");
conn = Transaction.getStandaloneConnection();
try {
- s_logger.debug("Starting tesing upgrade from 2.1.7 to 2.2.4 for Basic zone...");
+ s_logger.debug("Starting tesing upgrade from 2.1.8 to 2.2.4 for Basic zone...");
//Version check
pstmt = conn.prepareStatement(" SELECT version FROM version ORDER BY id DESC LIMIT 1");
diff --git a/server/test/com/cloud/upgrade/InstanceGroup217To224UpgradeTest.java b/server/test/com/cloud/upgrade/InstanceGroup218To224UpgradeTest.java
similarity index 74%
rename from server/test/com/cloud/upgrade/InstanceGroup217To224UpgradeTest.java
rename to server/test/com/cloud/upgrade/InstanceGroup218To224UpgradeTest.java
index 3d2b731d8ea..b87916bf43e 100644
--- a/server/test/com/cloud/upgrade/InstanceGroup217To224UpgradeTest.java
+++ b/server/test/com/cloud/upgrade/InstanceGroup218To224UpgradeTest.java
@@ -35,8 +35,8 @@ import com.cloud.utils.component.ComponentLocator;
import com.cloud.utils.db.DbTestUtils;
import com.cloud.utils.db.Transaction;
-public class InstanceGroup217To224UpgradeTest extends TestCase {
- private static final Logger s_logger = Logger.getLogger(InstanceGroup217To224UpgradeTest.class);
+public class InstanceGroup218To224UpgradeTest extends TestCase {
+ private static final Logger s_logger = Logger.getLogger(InstanceGroup218To224UpgradeTest.class);
@Override
@Before
@@ -50,8 +50,8 @@ public class InstanceGroup217To224UpgradeTest extends TestCase {
}
public void test217to22Upgrade() throws SQLException {
- s_logger.debug("Finding sample data from 2.1.7");
- DbTestUtils.executeScript("PreviousDatabaseSchema/2.1.7/2.1.7_sample_instanceGroups.sql", false, true);
+ s_logger.debug("Finding sample data from 2.1.8");
+ DbTestUtils.executeScript("PreviousDatabaseSchema/2.1.8/2.1.8_sample_instanceGroups.sql", false, true);
PreparedStatement pstmt;
ResultSet rs;
@@ -61,18 +61,21 @@ public class InstanceGroup217To224UpgradeTest extends TestCase {
String version = dao.getCurrentVersion();
- if (!version.equals("2.1.7")) {
- s_logger.error("Version returned is not 2.1.7 but " + version);
+ if (!version.equals("2.1.8")) {
+ s_logger.error("Version returned is not 2.1.8 but " + version);
} else {
- s_logger.debug("Basic zone test version is " + version);
+ s_logger.debug("Instance group test version is " + version);
}
Long groupNumberVmInstance = 0L;
ArrayList