Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
afcdbc4
CLOUDSTACK-8656: log initialisation logging
DaanHoogland Aug 3, 2015
e8a00ed
CLOUDSTACK-8656: try-with-resource in vmsd reader
DaanHoogland Aug 3, 2015
27960b4
CLOUDSTACK-8656: console logging on asserted exceptions
DaanHoogland Aug 4, 2015
b060c66
CLOUDSTACK-8656: dummy main removed
DaanHoogland Aug 4, 2015
ea88691
CLOUDSTACK-8656: messages about classloader issues in ipc framwork
DaanHoogland Aug 4, 2015
55df067
CLOUDSTACK-8656: try-with resource on socket channel
DaanHoogland Aug 4, 2015
ed6e261
CLOUDSTACK-8656: t-w-r on socket channel
DaanHoogland Aug 4, 2015
21fd2b9
CLOUDSTACK-8656: config file closing should not throw an exception
DaanHoogland Aug 4, 2015
87fb099
CLOUDSTACK-8656: return false from equals if not the same class
DaanHoogland Aug 4, 2015
a0ba7d3
CLOUDSTACK-8656: log in case we are on a platform not supporting UTF8
DaanHoogland Aug 4, 2015
6fa8b75
CLOUDSTACK-8656: reporting ignored exceptions in server
DaanHoogland Aug 4, 2015
c053475
CLOUDSTACK-8656: network related exception logging
DaanHoogland Aug 4, 2015
f203acc
CLOUDSTACK-8656: exception is the rule for some tests
DaanHoogland Aug 14, 2015
3229d96
CLOUDSTACK-8656: move cli test tool to separate file
DaanHoogland Aug 14, 2015
4213a22
CLOUDSTACK-8656: message about invalid number from store
DaanHoogland Aug 14, 2015
08e6e16
CLOUDSTACK-8656: message about timed buffer logging
DaanHoogland Aug 14, 2015
6227c44
CLOUDSTACK-8656: unnecessary close construct removed
DaanHoogland Aug 14, 2015
6c7ab8a
CLOUDSTACK-8656: deal with empty SQLException catch block by try-w-r
DaanHoogland Aug 14, 2015
a923abf
CLOUDSTACK-8656: try-w-r instead of clunckey close-except
DaanHoogland Aug 14, 2015
6f2f81c
CLOUDSTACK-8656: try-w-r removes need for empty catch block
DaanHoogland Aug 14, 2015
de2d78b
CLOUDSTACK-8656: logging ignored exceptions
DaanHoogland Aug 14, 2015
2eee6aa
CLOUDSTACK-8656: validate the throwing of ServerApiException
DaanHoogland Aug 14, 2015
07bee31
CLOUDSTACK-8656: restructure tests to ensure exception throwing
DaanHoogland Aug 14, 2015
882de20
CLOUDSTACK-8656: reorganise sychronized block
DaanHoogland Aug 14, 2015
bb8facc
CLOUDSTACK-8656: restructure of tests
DaanHoogland Aug 14, 2015
237f922
CLOUDSTACK-8656: removed unused classes
DaanHoogland Aug 14, 2015
384a2e9
CLOUDSTACK-8656: class in json specified not found
DaanHoogland Aug 14, 2015
adcd0c0
CLOUDSTACK-8656: use catch block for validation
DaanHoogland Aug 14, 2015
b6f1d29
CLOUDSTACK-8656: more logging instead of sysout
DaanHoogland Aug 14, 2015
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 1 addition & 10 deletions engine/schema/src/com/cloud/upgrade/dao/Upgrade40to41.java
Original file line number Diff line number Diff line change
Expand Up @@ -82,23 +82,14 @@ private void updateRegionEntries(Connection conn) {
if (regionId != null) {
region_id = Integer.parseInt(regionId);
}
PreparedStatement pstmt = null;
try {
try (PreparedStatement pstmt = conn.prepareStatement("update `cloud`.`region` set id = ?");) {
//Update regionId in region table
s_logger.debug("Updating region table with Id: " + region_id);
pstmt = conn.prepareStatement("update `cloud`.`region` set id = ?");
pstmt.setInt(1, region_id);
pstmt.executeUpdate();

} catch (SQLException e) {
throw new CloudRuntimeException("Error while updating region entries", e);
} finally {
try {
if (pstmt != null) {
pstmt.close();
}
} catch (SQLException e) {
}
}
}

Expand Down
286 changes: 79 additions & 207 deletions engine/schema/src/com/cloud/upgrade/dao/Upgrade410to420.java

Large diffs are not rendered by default.

175 changes: 76 additions & 99 deletions engine/schema/src/com/cloud/upgrade/dao/Upgrade420to421.java
Original file line number Diff line number Diff line change
Expand Up @@ -131,137 +131,114 @@ private void updateOverprovisioningPerVm(Connection conn) {

private void upgradeResourceCount(Connection conn) {
s_logger.debug("upgradeResourceCount start");
PreparedStatement pstmt1 = null;
PreparedStatement pstmt2 = null;
PreparedStatement pstmt3 = null;
PreparedStatement pstmt4 = null;
PreparedStatement pstmt5 = null;
ResultSet rsAccount = null;
ResultSet rsCount = null;
try {
pstmt1 = conn.prepareStatement("select id, domain_id FROM `cloud`.`account` where removed is NULL ");
rsAccount = pstmt1.executeQuery();
String sqlSelectAccountIds = "select id, domain_id FROM `cloud`.`account` where removed is NULL ";
String sqlSelectOfferingTotals = "SELECT SUM(service_offering.cpu), SUM(service_offering.ram_size)"
+ " FROM `cloud`.`vm_instance`, `cloud`.`service_offering`"
+ " WHERE vm_instance.service_offering_id = service_offering.id AND vm_instance.account_id = ?"
+ " AND vm_instance.removed is NULL"
+ " AND vm_instance.vm_type='User' AND state not in ('Destroyed', 'Error', 'Expunging')";
String sqlSelectTotalVolumeSize =
"SELECT sum(size) FROM `cloud`.`volumes` WHERE account_id= ?"
+ " AND (path is not NULL OR state in ('Allocated')) AND removed is NULL"
+ " AND instance_id IN (SELECT id FROM `cloud`.`vm_instance` WHERE vm_type='User')";
String sqlSelectTotalPathlessVolumeSize =
"SELECT sum(size) FROM `cloud`.`volumes` WHERE account_id= ?"
+ " AND path is NULL AND state not in ('Allocated') AND removed is NULL";
String sqlSelectTotalSnapshotSize = "SELECT sum(size) FROM `cloud`.`snapshots` WHERE account_id= ? AND removed is NULL";
String sqlSelectTotalTemplateStoreSize = "SELECT sum(template_store_ref.size) FROM `cloud`.`template_store_ref`,`cloud`.`vm_template` WHERE account_id = ?"
+ " AND template_store_ref.template_id = vm_template.id AND download_state = 'DOWNLOADED' AND destroyed = false AND removed is NULL";
String sqlSelectDomainIds = "select id FROM `cloud`.`domain`";
String sqlSelectAccountCount = "select account.domain_id,sum(resource_count.count) from `cloud`.`account` left join `cloud`.`resource_count` on account.id=resource_count.account_id "
+ "where resource_count.type=? group by account.domain_id;";

try (
PreparedStatement pstmtSelectAccountIds = conn.prepareStatement(sqlSelectAccountIds);
PreparedStatement pstmtSelectOfferingTotals = conn.prepareStatement(sqlSelectOfferingTotals);
PreparedStatement pstmtSelectTotalVolumeSize = conn.prepareStatement(sqlSelectTotalVolumeSize);
PreparedStatement pstmtSelectTotalPathlessVolumeSize = conn.prepareStatement(sqlSelectTotalPathlessVolumeSize);
PreparedStatement pstmtSelectTotalSnapshotSize = conn.prepareStatement(sqlSelectTotalSnapshotSize);
PreparedStatement pstmtSelectTotalTemplateStoreSize = conn.prepareStatement(sqlSelectTotalTemplateStoreSize);
PreparedStatement pstmtSelectDomainIds = conn.prepareStatement(sqlSelectDomainIds);
PreparedStatement pstmtSelectAccountCount = conn.prepareStatement(sqlSelectAccountCount);
ResultSet rsAccount = pstmtSelectAccountIds.executeQuery();
) {
while (rsAccount.next()) {
long account_id = rsAccount.getLong(1);
long domain_id = rsAccount.getLong(2);
// 1. update cpu,memory for all accounts
pstmt2 =
conn.prepareStatement("SELECT SUM(service_offering.cpu), SUM(service_offering.ram_size)" + " FROM `cloud`.`vm_instance`, `cloud`.`service_offering`"
+ " WHERE vm_instance.service_offering_id = service_offering.id AND vm_instance.account_id = ?" + " AND vm_instance.removed is NULL"
+ " AND vm_instance.vm_type='User' AND state not in ('Destroyed', 'Error', 'Expunging')");
pstmt2.setLong(1, account_id);
rsCount = pstmt2.executeQuery();
if (rsCount.next()) {
upgradeResourceCountforAccount(conn, account_id, domain_id, "cpu", rsCount.getLong(1));
upgradeResourceCountforAccount(conn, account_id, domain_id, "memory", rsCount.getLong(2));
} else {
upgradeResourceCountforAccount(conn, account_id, domain_id, "cpu", 0L);
upgradeResourceCountforAccount(conn, account_id, domain_id, "memory", 0L);
pstmtSelectOfferingTotals.setLong(1, account_id);
try (ResultSet rsOfferingTotals = pstmtSelectOfferingTotals.executeQuery();) {
if (rsOfferingTotals.next()) {
upgradeResourceCountforAccount(conn, account_id, domain_id, "cpu", rsOfferingTotals.getLong(1));
upgradeResourceCountforAccount(conn, account_id, domain_id, "memory", rsOfferingTotals.getLong(2));
} else {
upgradeResourceCountforAccount(conn, account_id, domain_id, "cpu", 0L);
upgradeResourceCountforAccount(conn, account_id, domain_id, "memory", 0L);
}
}
rsCount.close();

// 2. update primary_storage for all accounts
pstmt3 =
conn.prepareStatement("SELECT sum(size) FROM `cloud`.`volumes` WHERE account_id= ?"
+ " AND (path is not NULL OR state in ('Allocated')) AND removed is NULL"
+ " AND instance_id IN (SELECT id FROM `cloud`.`vm_instance` WHERE vm_type='User')");
pstmt3.setLong(1, account_id);
rsCount = pstmt3.executeQuery();
if (rsCount.next()) {
upgradeResourceCountforAccount(conn, account_id, domain_id, "primary_storage", rsCount.getLong(1));
} else {
upgradeResourceCountforAccount(conn, account_id, domain_id, "primary_storage", 0L);
pstmtSelectTotalVolumeSize.setLong(1, account_id);
try (ResultSet rsTotalVolumeSize = pstmtSelectTotalVolumeSize.executeQuery();) {
if (rsTotalVolumeSize.next()) {
upgradeResourceCountforAccount(conn, account_id, domain_id, "primary_storage", rsTotalVolumeSize.getLong(1));
} else {
upgradeResourceCountforAccount(conn, account_id, domain_id, "primary_storage", 0L);
}
}
rsCount.close();

// 3. update secondary_storage for all accounts
long totalVolumesSize = 0;
long totalSnapshotsSize = 0;
long totalTemplatesSize = 0;
pstmt4 =
conn.prepareStatement("SELECT sum(size) FROM `cloud`.`volumes` WHERE account_id= ?"
+ " AND path is NULL AND state not in ('Allocated') AND removed is NULL");
pstmt4.setLong(1, account_id);
rsCount = pstmt4.executeQuery();
if (rsCount.next()) {
totalVolumesSize = rsCount.getLong(1);
pstmtSelectTotalPathlessVolumeSize.setLong(1, account_id);
try (ResultSet rsTotalPathlessVolumeSize = pstmtSelectTotalPathlessVolumeSize.executeQuery();) {
if (rsTotalPathlessVolumeSize.next()) {
totalVolumesSize = rsTotalPathlessVolumeSize.getLong(1);
}
}
rsCount.close();
pstmt4.close();

pstmt4 = conn.prepareStatement("SELECT sum(size) FROM `cloud`.`snapshots` WHERE account_id= ? AND removed is NULL");
pstmt4.setLong(1, account_id);
rsCount = pstmt4.executeQuery();
if (rsCount.next()) {
totalSnapshotsSize = rsCount.getLong(1);
pstmtSelectTotalSnapshotSize.setLong(1, account_id);
try (ResultSet rsTotalSnapshotSize = pstmtSelectTotalSnapshotSize.executeQuery();) {
if (rsTotalSnapshotSize.next()) {
totalSnapshotsSize = rsTotalSnapshotSize.getLong(1);
}
}
rsCount.close();
pstmt4.close();

pstmt4 =
conn.prepareStatement("SELECT sum(template_store_ref.size) FROM `cloud`.`template_store_ref`,`cloud`.`vm_template` WHERE account_id = ?"
+ " AND template_store_ref.template_id = vm_template.id AND download_state = 'DOWNLOADED' AND destroyed = false AND removed is NULL");
pstmt4.setLong(1, account_id);
rsCount = pstmt4.executeQuery();
if (rsCount.next()) {
totalTemplatesSize = rsCount.getLong(1);
pstmtSelectTotalTemplateStoreSize.setLong(1, account_id);
try (ResultSet rsTotalTemplateStoreSize = pstmtSelectTotalTemplateStoreSize.executeQuery();) {
if (rsTotalTemplateStoreSize.next()) {
totalTemplatesSize = rsTotalTemplateStoreSize.getLong(1);
}
}
upgradeResourceCountforAccount(conn, account_id, domain_id, "secondary_storage", totalVolumesSize + totalSnapshotsSize + totalTemplatesSize);
}
rsAccount.close();

// 4. upgrade cpu,memory,primary_storage,secondary_storage for domains
String resource_types[] = {"cpu", "memory", "primary_storage", "secondary_storage"};
pstmt5 = conn.prepareStatement("select id FROM `cloud`.`domain`");
rsAccount = pstmt5.executeQuery();
while (rsAccount.next()) {
long domain_id = rsAccount.getLong(1);
for (int count = 0; count < resource_types.length; count++) {
String resource_type = resource_types[count];
upgradeResourceCountforDomain(conn, domain_id, resource_type, 0L); // reset value to 0 before statistics
try (ResultSet rsDomainIds = pstmtSelectDomainIds.executeQuery();) {
while (rsDomainIds.next()) {
long domain_id = rsDomainIds.getLong(1);
for (int count = 0; count < resource_types.length; count++) {
String resource_type = resource_types[count];
upgradeResourceCountforDomain(conn, domain_id, resource_type, 0L); // reset value to 0 before statistics
}
}
}
for (int count = 0; count < resource_types.length; count++) {
String resource_type = resource_types[count];
pstmt5 =
conn.prepareStatement("select account.domain_id,sum(resource_count.count) from `cloud`.`account` left join `cloud`.`resource_count` on account.id=resource_count.account_id "
+ "where resource_count.type=? group by account.domain_id;");
pstmt5.setString(1, resource_type);
rsCount = pstmt5.executeQuery();
while (rsCount.next()) {
long domain_id = rsCount.getLong(1);
long resource_count = rsCount.getLong(2);
upgradeResourceCountforDomain(conn, domain_id, resource_type, resource_count);
pstmtSelectAccountCount.setString(1, resource_type);
try (ResultSet rsAccountCount = pstmtSelectAccountCount.executeQuery();) {
while (rsAccountCount.next()) {
long domain_id = rsAccountCount.getLong(1);
long resource_count = rsAccountCount.getLong(2);
upgradeResourceCountforDomain(conn, domain_id, resource_type, resource_count);
}
}
}
s_logger.debug("upgradeResourceCount finish");
} catch (SQLException e) {
throw new CloudRuntimeException("Unable to upgrade resource count (cpu,memory,primary_storage,secondary_storage) ", e);
} finally {
try {
if (rsAccount != null) {
rsAccount.close();
}
if (rsCount != null) {
rsCount.close();
}
if (pstmt1 != null) {
pstmt1.close();
}
if (pstmt2 != null) {
pstmt2.close();
}
if (pstmt3 != null) {
pstmt3.close();
}
if (pstmt4 != null) {
pstmt4.close();
}
if (pstmt5 != null) {
pstmt5.close();
}
} catch (SQLException e) {
}
}
}

Expand Down
38 changes: 8 additions & 30 deletions engine/schema/src/com/cloud/upgrade/dao/Upgrade442to450.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@

import com.cloud.hypervisor.Hypervisor;
import com.cloud.utils.crypt.DBEncryptionUtil;

import org.apache.log4j.Logger;

import com.cloud.utils.exception.CloudRuntimeException;
Expand Down Expand Up @@ -76,31 +77,20 @@ public void performDataMigration(Connection conn) {
}

private void updateMaxRouterSizeConfig(Connection conn) {
PreparedStatement updatePstmt = null;
try {
String sqlUpdateConfig = "UPDATE `cloud`.`configuration` SET value=? WHERE name='router.ram.size' AND category='Hidden'";
try (PreparedStatement updatePstmt = conn.prepareStatement(sqlUpdateConfig);){
String encryptedValue = DBEncryptionUtil.encrypt("256");
updatePstmt = conn.prepareStatement("UPDATE `cloud`.`configuration` SET value=? WHERE name='router.ram.size' AND category='Hidden'");
updatePstmt.setBytes(1, encryptedValue.getBytes("UTF-8"));
updatePstmt.executeUpdate();
} catch (SQLException e) {
throw new CloudRuntimeException("Unable to upgrade max ram size of router in config.", e);
} catch (UnsupportedEncodingException e) {
throw new CloudRuntimeException("Unable encrypt configuration values ", e);
} finally {
try {
if (updatePstmt != null) {
updatePstmt.close();
}
} catch (SQLException e) {
}
}
s_logger.debug("Done updating router.ram.size config to 256");
}

private void upgradeMemoryOfVirtualRoutervmOffering(Connection conn) {
PreparedStatement updatePstmt = null;
PreparedStatement selectPstmt = null;
ResultSet selectResultSet = null;
int newRamSize = 256; //256MB
long serviceOfferingId = 0;

Expand All @@ -109,10 +99,11 @@ private void upgradeMemoryOfVirtualRoutervmOffering(Connection conn) {
* We should not update/modify any user-defined offering.
*/

try {
selectPstmt = conn.prepareStatement("SELECT id FROM `cloud`.`service_offering` WHERE vm_type='domainrouter'");
updatePstmt = conn.prepareStatement("UPDATE `cloud`.`service_offering` SET ram_size=? WHERE id=?");
selectResultSet = selectPstmt.executeQuery();
try (
PreparedStatement selectPstmt = conn.prepareStatement("SELECT id FROM `cloud`.`service_offering` WHERE vm_type='domainrouter'");
PreparedStatement updatePstmt = conn.prepareStatement("UPDATE `cloud`.`service_offering` SET ram_size=? WHERE id=?");
ResultSet selectResultSet = selectPstmt.executeQuery();
) {
if(selectResultSet.next()) {
serviceOfferingId = selectResultSet.getLong("id");
}
Expand All @@ -122,19 +113,6 @@ private void upgradeMemoryOfVirtualRoutervmOffering(Connection conn) {
updatePstmt.executeUpdate();
} catch (SQLException e) {
throw new CloudRuntimeException("Unable to upgrade ram_size of service offering for domain router. ", e);
} finally {
try {
if (selectPstmt != null) {
selectPstmt.close();
}
if (selectResultSet != null) {
selectResultSet.close();
}
if (updatePstmt != null) {
updatePstmt.close();
}
} catch (SQLException e) {
}
}
s_logger.debug("Done upgrading RAM for service offering of domain router to " + newRamSize);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,15 +134,4 @@ private HttpClient getHttpClient() {
return s_client;
}

// for test purpose only
public static void main(final String[] args) {
/*
ClusterServiceServletImpl service = new ClusterServiceServletImpl("http://localhost:9090/clusterservice", 300);
try {
String result = service.execute("test", 1, "{ p1:v1, p2:v2 }", true);
System.out.println(result);
} catch (RemoteException e) {
}
*/
}
}
23 changes: 7 additions & 16 deletions framework/db/src/com/cloud/utils/db/ConnectionConcierge.java
Original file line number Diff line number Diff line change
Expand Up @@ -142,26 +142,17 @@ public void unregister(String name) {
}

protected String testValidity(String name, Connection conn) {
PreparedStatement pstmt = null;
try {
if (conn != null) {
synchronized (conn) {
pstmt = conn.prepareStatement("SELECT 1");
if (conn != null) {
synchronized (conn) {
try (PreparedStatement pstmt = conn.prepareStatement("SELECT 1");) {
pstmt.executeQuery();
}
}
return null;
} catch (Throwable th) {
s_logger.error("Unable to keep the db connection for " + name, th);
return th.toString();
} finally {
if (pstmt != null) {
try {
pstmt.close();
} catch (SQLException e) {
} catch (Throwable th) {
s_logger.error("Unable to keep the db connection for " + name, th);
return th.toString();
}
}
}
return null;
}

@Override
Expand Down
Loading