Fixed Resource Leaks, null dereferences, few other issues reported by coverity

This commit is contained in:
Santhosh Edukulla 2014-07-02 14:08:16 +05:30
parent 4607c26949
commit a600d8408e
22 changed files with 336 additions and 276 deletions

View File

@ -301,27 +301,25 @@ public class VlanDaoImpl extends GenericDaoBase<VlanVO, Long> implements VlanDao
@Override @Override
@DB @DB
public List<VlanVO> searchForZoneWideVlans(long dcId, String vlanType, String vlanId) { public List<VlanVO> searchForZoneWideVlans(long dcId, String vlanType, String vlanId) {
StringBuilder sql = new StringBuilder(FindZoneWideVlans); StringBuilder sql = new StringBuilder(FindZoneWideVlans);
TransactionLegacy txn = TransactionLegacy.currentTxn(); TransactionLegacy txn = TransactionLegacy.currentTxn();
PreparedStatement pstmt = null; List<VlanVO> zoneWideVlans = new ArrayList<VlanVO>();
try { try(PreparedStatement pstmt = txn.prepareStatement(sql.toString());){
pstmt = txn.prepareAutoCloseStatement(sql.toString()); if(pstmt != null) {
pstmt.setLong(1, dcId); pstmt.setLong(1, dcId);
pstmt.setString(2, vlanType); pstmt.setString(2, vlanType);
pstmt.setString(3, vlanId); pstmt.setString(3, vlanId);
try(ResultSet rs = pstmt.executeQuery();) {
ResultSet rs = pstmt.executeQuery();
List<VlanVO> zoneWideVlans = new ArrayList<VlanVO>();
while (rs.next()) { while (rs.next()) {
zoneWideVlans.add(toEntityBean(rs, false)); zoneWideVlans.add(toEntityBean(rs, false));
} }
}catch (SQLException e) {
throw new CloudRuntimeException("searchForZoneWideVlans:Exception:" + e.getMessage(), e);
}
}
return zoneWideVlans; return zoneWideVlans;
} catch (SQLException e) { } catch (SQLException e) {
throw new CloudRuntimeException("Unable to execute " + pstmt.toString(), e); throw new CloudRuntimeException("searchForZoneWideVlans:Exception:" + e.getMessage(), e);
} }
} }

View File

@ -116,25 +116,23 @@ public class StoragePoolWorkDaoImpl extends GenericDaoBase<StoragePoolWorkVO, Lo
@Override @Override
@DB @DB
public List<Long> searchForPoolIdsForPendingWorkJobs(long msId) { public List<Long> searchForPoolIdsForPendingWorkJobs(long msId) {
StringBuilder sql = new StringBuilder(FindPoolIds); StringBuilder sql = new StringBuilder(FindPoolIds);
TransactionLegacy txn = TransactionLegacy.currentTxn(); TransactionLegacy txn = TransactionLegacy.currentTxn();
PreparedStatement pstmt = null;
try {
pstmt = txn.prepareAutoCloseStatement(sql.toString());
pstmt.setLong(1, msId);
ResultSet rs = pstmt.executeQuery();
List<Long> poolIds = new ArrayList<Long>(); List<Long> poolIds = new ArrayList<Long>();
try (PreparedStatement pstmt = txn.prepareStatement(sql.toString());){
if(pstmt != null) {
pstmt.setLong(1, msId);
try (ResultSet rs = pstmt.executeQuery();) {
while (rs.next()) { while (rs.next()) {
poolIds.add(rs.getLong("pool_id")); poolIds.add(rs.getLong("pool_id"));
} }
} catch (SQLException e) {
throw new CloudRuntimeException("searchForPoolIdsForPendingWorkJobs:Exception:" + e.getMessage(), e);
}
}
return poolIds; return poolIds;
} catch (SQLException e) { } catch (SQLException e) {
throw new CloudRuntimeException("Unable to execute " + pstmt.toString(), e); throw new CloudRuntimeException("searchForPoolIdsForPendingWorkJobs:Exception:" + e.getMessage(), e);
} }
} }
} }

View File

@ -86,8 +86,8 @@ public class DatabaseCreator {
private static void initDB(String dbPropsFile, String rootPassword, String[] databases, boolean dryRun) { private static void initDB(String dbPropsFile, String rootPassword, String[] databases, boolean dryRun) {
Properties dbProperties = new Properties(); Properties dbProperties = new Properties();
try { try(FileInputStream f_stream = new FileInputStream(new File(dbPropsFile));) {
dbProperties.load(new FileInputStream(new File(dbPropsFile))); dbProperties.load(f_stream);
} catch (IOException e) { } catch (IOException e) {
System.out.println("IOError: unable to load/read db properties file: " + e); System.out.println("IOError: unable to load/read db properties file: " + e);
System.exit(1); System.exit(1);

View File

@ -18,6 +18,7 @@ package com.cloud.usage.dao;
import java.sql.PreparedStatement; import java.sql.PreparedStatement;
import java.sql.ResultSet; import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
@ -25,6 +26,7 @@ import java.util.TimeZone;
import javax.ejb.Local; import javax.ejb.Local;
import com.cloud.exception.CloudException;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
@ -57,20 +59,25 @@ public class UsageIPAddressDaoImpl extends GenericDaoBase<UsageIPAddressVO, Long
@Override @Override
public void update(UsageIPAddressVO usage) { public void update(UsageIPAddressVO usage) {
TransactionLegacy txn = TransactionLegacy.open(TransactionLegacy.USAGE_DB); TransactionLegacy txn = TransactionLegacy.open(TransactionLegacy.USAGE_DB);
PreparedStatement pstmt = null;
try { try {
txn.start(); txn.start();
if (usage.getReleased() != null) { if (usage.getReleased() != null) {
pstmt = txn.prepareAutoCloseStatement(UPDATE_RELEASED); try(PreparedStatement pstmt = txn.prepareStatement(UPDATE_RELEASED);) {
if (pstmt != null) {
pstmt.setString(1, DateUtil.getDateDisplayString(TimeZone.getTimeZone("GMT"), usage.getReleased())); pstmt.setString(1, DateUtil.getDateDisplayString(TimeZone.getTimeZone("GMT"), usage.getReleased()));
pstmt.setLong(2, usage.getAccountId()); pstmt.setLong(2, usage.getAccountId());
pstmt.setString(3, usage.getAddress()); pstmt.setString(3, usage.getAddress());
}
pstmt.executeUpdate(); pstmt.executeUpdate();
}
}catch(SQLException e)
{
throw new CloudException("update:Exception:"+e.getMessage(), e);
}
}
txn.commit(); txn.commit();
} catch (Exception e) { } catch (Exception e) {
txn.rollback(); txn.rollback();
s_logger.warn("Error updating usageIPAddressVO", e); s_logger.error("Error updating usageIPAddressVO:"+e.getMessage(), e);
} finally { } finally {
txn.close(); txn.close();
} }

View File

@ -18,6 +18,7 @@ package com.cloud.usage.dao;
import java.sql.PreparedStatement; import java.sql.PreparedStatement;
import java.sql.ResultSet; import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
@ -25,6 +26,7 @@ import java.util.TimeZone;
import javax.ejb.Local; import javax.ejb.Local;
import com.cloud.exception.CloudException;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
@ -73,20 +75,24 @@ public class UsageLoadBalancerPolicyDaoImpl extends GenericDaoBase<UsageLoadBala
@Override @Override
public void update(UsageLoadBalancerPolicyVO usage) { public void update(UsageLoadBalancerPolicyVO usage) {
TransactionLegacy txn = TransactionLegacy.open(TransactionLegacy.USAGE_DB); TransactionLegacy txn = TransactionLegacy.open(TransactionLegacy.USAGE_DB);
PreparedStatement pstmt = null;
try { try {
txn.start(); txn.start();
if (usage.getDeleted() != null) { if (usage.getDeleted() != null) {
pstmt = txn.prepareAutoCloseStatement(UPDATE_DELETED); try(PreparedStatement pstmt = txn.prepareStatement(UPDATE_DELETED);) {
if (pstmt != null) {
pstmt.setString(1, DateUtil.getDateDisplayString(TimeZone.getTimeZone("GMT"), usage.getDeleted())); pstmt.setString(1, DateUtil.getDateDisplayString(TimeZone.getTimeZone("GMT"), usage.getDeleted()));
pstmt.setLong(2, usage.getAccountId()); pstmt.setLong(2, usage.getAccountId());
pstmt.setLong(3, usage.getId()); pstmt.setLong(3, usage.getId());
}
pstmt.executeUpdate(); pstmt.executeUpdate();
}
}catch (SQLException e) {
throw new CloudException("Error updating UsageLoadBalancerPolicyVO:" + e.getMessage(), e);
}
}
txn.commit(); txn.commit();
} catch (Exception e) { } catch (Exception e) {
txn.rollback(); txn.rollback();
s_logger.warn("Error updating UsageLoadBalancerPolicyVO", e); s_logger.warn("Error updating UsageLoadBalancerPolicyVO"+e.getMessage(), e);
} finally { } finally {
txn.close(); txn.close();
} }

View File

@ -18,6 +18,7 @@ package com.cloud.usage.dao;
import java.sql.PreparedStatement; import java.sql.PreparedStatement;
import java.sql.ResultSet; import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
@ -25,6 +26,7 @@ import java.util.TimeZone;
import javax.ejb.Local; import javax.ejb.Local;
import com.cloud.exception.CloudException;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
@ -56,21 +58,25 @@ public class UsageNetworkOfferingDaoImpl extends GenericDaoBase<UsageNetworkOffe
@Override @Override
public void update(UsageNetworkOfferingVO usage) { public void update(UsageNetworkOfferingVO usage) {
TransactionLegacy txn = TransactionLegacy.open(TransactionLegacy.USAGE_DB); TransactionLegacy txn = TransactionLegacy.open(TransactionLegacy.USAGE_DB);
PreparedStatement pstmt = null;
try { try {
txn.start(); txn.start();
if (usage.getDeleted() != null) { if (usage.getDeleted() != null) {
pstmt = txn.prepareAutoCloseStatement(UPDATE_DELETED); try(PreparedStatement pstmt = txn.prepareStatement(UPDATE_DELETED);) {
if (pstmt != null) {
pstmt.setString(1, DateUtil.getDateDisplayString(TimeZone.getTimeZone("GMT"), usage.getDeleted())); pstmt.setString(1, DateUtil.getDateDisplayString(TimeZone.getTimeZone("GMT"), usage.getDeleted()));
pstmt.setLong(2, usage.getAccountId()); pstmt.setLong(2, usage.getAccountId());
pstmt.setLong(3, usage.getVmInstanceId()); pstmt.setLong(3, usage.getVmInstanceId());
pstmt.setLong(4, usage.getNetworkOfferingId()); pstmt.setLong(4, usage.getNetworkOfferingId());
}
pstmt.executeUpdate(); pstmt.executeUpdate();
}
}catch (SQLException e) {
throw new CloudException("Error updating UsageNetworkOfferingVO:"+e.getMessage(), e);
}
}
txn.commit(); txn.commit();
} catch (Exception e) { } catch (Exception e) {
txn.rollback(); txn.rollback();
s_logger.warn("Error updating UsageNetworkOfferingVO", e); s_logger.warn("Error updating UsageNetworkOfferingVO:"+e.getMessage(), e);
} finally { } finally {
txn.close(); txn.close();
} }

View File

@ -18,6 +18,7 @@ package com.cloud.usage.dao;
import java.sql.PreparedStatement; import java.sql.PreparedStatement;
import java.sql.ResultSet; import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
@ -25,6 +26,7 @@ import java.util.TimeZone;
import javax.ejb.Local; import javax.ejb.Local;
import com.cloud.exception.CloudException;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
@ -73,20 +75,24 @@ public class UsagePortForwardingRuleDaoImpl extends GenericDaoBase<UsagePortForw
@Override @Override
public void update(UsagePortForwardingRuleVO usage) { public void update(UsagePortForwardingRuleVO usage) {
TransactionLegacy txn = TransactionLegacy.open(TransactionLegacy.USAGE_DB); TransactionLegacy txn = TransactionLegacy.open(TransactionLegacy.USAGE_DB);
PreparedStatement pstmt = null;
try { try {
txn.start(); txn.start();
if (usage.getDeleted() != null) { if (usage.getDeleted() != null) {
pstmt = txn.prepareAutoCloseStatement(UPDATE_DELETED); try(PreparedStatement pstmt = txn.prepareStatement(UPDATE_DELETED);) {
if (pstmt != null) {
pstmt.setString(1, DateUtil.getDateDisplayString(TimeZone.getTimeZone("GMT"), usage.getDeleted())); pstmt.setString(1, DateUtil.getDateDisplayString(TimeZone.getTimeZone("GMT"), usage.getDeleted()));
pstmt.setLong(2, usage.getAccountId()); pstmt.setLong(2, usage.getAccountId());
pstmt.setLong(3, usage.getId()); pstmt.setLong(3, usage.getId());
}
pstmt.executeUpdate(); pstmt.executeUpdate();
}
}catch (SQLException e) {
throw new CloudException("Error updating UsagePortForwardingRuleVO:"+e.getMessage(), e);
}
}
txn.commit(); txn.commit();
} catch (Exception e) { } catch (Exception e) {
txn.rollback(); txn.rollback();
s_logger.warn("Error updating UsagePortForwardingRuleVO", e); s_logger.warn("Error updating UsagePortForwardingRuleVO:"+e.getMessage(), e);
} finally { } finally {
txn.close(); txn.close();
} }

View File

@ -18,6 +18,7 @@ package com.cloud.usage.dao;
import java.sql.PreparedStatement; import java.sql.PreparedStatement;
import java.sql.ResultSet; import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
@ -25,6 +26,7 @@ import java.util.TimeZone;
import javax.ejb.Local; import javax.ejb.Local;
import com.cloud.exception.CloudException;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
@ -56,21 +58,25 @@ public class UsageSecurityGroupDaoImpl extends GenericDaoBase<UsageSecurityGroup
@Override @Override
public void update(UsageSecurityGroupVO usage) { public void update(UsageSecurityGroupVO usage) {
TransactionLegacy txn = TransactionLegacy.open(TransactionLegacy.USAGE_DB); TransactionLegacy txn = TransactionLegacy.open(TransactionLegacy.USAGE_DB);
PreparedStatement pstmt = null;
try { try {
txn.start(); txn.start();
if (usage.getDeleted() != null) { if (usage.getDeleted() != null) {
pstmt = txn.prepareAutoCloseStatement(UPDATE_DELETED); try(PreparedStatement pstmt = txn.prepareStatement(UPDATE_DELETED);) {
if (pstmt != null) {
pstmt.setString(1, DateUtil.getDateDisplayString(TimeZone.getTimeZone("GMT"), usage.getDeleted())); pstmt.setString(1, DateUtil.getDateDisplayString(TimeZone.getTimeZone("GMT"), usage.getDeleted()));
pstmt.setLong(2, usage.getAccountId()); pstmt.setLong(2, usage.getAccountId());
pstmt.setLong(3, usage.getVmInstanceId()); pstmt.setLong(3, usage.getVmInstanceId());
pstmt.setLong(4, usage.getSecurityGroupId()); pstmt.setLong(4, usage.getSecurityGroupId());
}
pstmt.executeUpdate(); pstmt.executeUpdate();
}
}catch (SQLException e) {
throw new CloudException("Error updating UsageSecurityGroupVO:"+e.getMessage(), e);
}
}
txn.commit(); txn.commit();
} catch (Exception e) { } catch (Exception e) {
txn.rollback(); txn.rollback();
s_logger.warn("Error updating UsageSecurityGroupVO", e); s_logger.warn("Error updating UsageSecurityGroupVO:"+e.getMessage(), e);
} finally { } finally {
txn.close(); txn.close();
} }
@ -101,11 +107,8 @@ public class UsageSecurityGroupDaoImpl extends GenericDaoBase<UsageSecurityGroup
} }
TransactionLegacy txn = TransactionLegacy.open(TransactionLegacy.USAGE_DB); TransactionLegacy txn = TransactionLegacy.open(TransactionLegacy.USAGE_DB);
PreparedStatement pstmt = null;
try {
int i = 1; int i = 1;
pstmt = txn.prepareAutoCloseStatement(sql); try (PreparedStatement pstmt = txn.prepareStatement(sql);){
if (param1 != null) { if (param1 != null) {
pstmt.setLong(i++, param1); pstmt.setLong(i++, param1);
} }
@ -115,8 +118,7 @@ public class UsageSecurityGroupDaoImpl extends GenericDaoBase<UsageSecurityGroup
pstmt.setString(i++, DateUtil.getDateDisplayString(TimeZone.getTimeZone("GMT"), endDate)); pstmt.setString(i++, DateUtil.getDateDisplayString(TimeZone.getTimeZone("GMT"), endDate));
pstmt.setString(i++, DateUtil.getDateDisplayString(TimeZone.getTimeZone("GMT"), startDate)); pstmt.setString(i++, DateUtil.getDateDisplayString(TimeZone.getTimeZone("GMT"), startDate));
pstmt.setString(i++, DateUtil.getDateDisplayString(TimeZone.getTimeZone("GMT"), endDate)); pstmt.setString(i++, DateUtil.getDateDisplayString(TimeZone.getTimeZone("GMT"), endDate));
try(ResultSet rs = pstmt.executeQuery();) {
ResultSet rs = pstmt.executeQuery();
while (rs.next()) { while (rs.next()) {
//zoneId, account_id, domain_id, vm_instance_id, security_group_id, created, deleted //zoneId, account_id, domain_id, vm_instance_id, security_group_id, created, deleted
Long zoneId = Long.valueOf(rs.getLong(1)); Long zoneId = Long.valueOf(rs.getLong(1));
@ -135,16 +137,17 @@ public class UsageSecurityGroupDaoImpl extends GenericDaoBase<UsageSecurityGroup
if (deletedTS != null) { if (deletedTS != null) {
deletedDate = DateUtil.parseDateString(s_gmtTimeZone, deletedTS); deletedDate = DateUtil.parseDateString(s_gmtTimeZone, deletedTS);
} }
usageRecords.add(new UsageSecurityGroupVO(zoneId, acctId, dId, vmId, sgId, createdDate, deletedDate)); usageRecords.add(new UsageSecurityGroupVO(zoneId, acctId, dId, vmId, sgId, createdDate, deletedDate));
} }
}catch (SQLException e) {
throw new CloudException("Error getting usage records"+e.getMessage(), e);
}
} catch (Exception e) { } catch (Exception e) {
txn.rollback(); txn.rollback();
s_logger.warn("Error getting usage records", e); s_logger.warn("Error getting usage records:"+e.getMessage(), e);
} finally { } finally {
txn.close(); txn.close();
} }
return usageRecords; return usageRecords;
} }
} }

View File

@ -18,6 +18,7 @@ package com.cloud.usage.dao;
import java.sql.PreparedStatement; import java.sql.PreparedStatement;
import java.sql.ResultSet; import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
@ -25,6 +26,7 @@ import java.util.TimeZone;
import javax.ejb.Local; import javax.ejb.Local;
import com.cloud.exception.CloudException;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
@ -91,19 +93,22 @@ public class UsageStorageDaoImpl extends GenericDaoBase<UsageStorageVO, Long> im
@Override @Override
public void removeBy(long accountId, long volId, int storageType) { public void removeBy(long accountId, long volId, int storageType) {
TransactionLegacy txn = TransactionLegacy.open(TransactionLegacy.USAGE_DB); TransactionLegacy txn = TransactionLegacy.open(TransactionLegacy.USAGE_DB);
PreparedStatement pstmt = null;
try { try {
txn.start(); txn.start();
String sql = REMOVE_BY_USERID_STORAGEID; String sql = REMOVE_BY_USERID_STORAGEID;
pstmt = txn.prepareAutoCloseStatement(sql); try( PreparedStatement pstmt = txn.prepareStatement(sql);) {
pstmt.setLong(1, accountId); pstmt.setLong(1, accountId);
pstmt.setLong(2, volId); pstmt.setLong(2, volId);
pstmt.setInt(3, storageType); pstmt.setInt(3, storageType);
pstmt.executeUpdate(); pstmt.executeUpdate();
}catch(SQLException e)
{
throw new CloudException("removeBy:Exception:"+e.getMessage(),e);
}
txn.commit(); txn.commit();
} catch (Exception e) { } catch (Exception e) {
txn.rollback(); txn.rollback();
s_logger.warn("Error removing usageStorageVO", e); s_logger.error("Error removing usageStorageVO", e);
} finally { } finally {
txn.close(); txn.close();
} }
@ -112,21 +117,26 @@ public class UsageStorageDaoImpl extends GenericDaoBase<UsageStorageVO, Long> im
@Override @Override
public void update(UsageStorageVO usage) { public void update(UsageStorageVO usage) {
TransactionLegacy txn = TransactionLegacy.open(TransactionLegacy.USAGE_DB); TransactionLegacy txn = TransactionLegacy.open(TransactionLegacy.USAGE_DB);
PreparedStatement pstmt = null;
try { try {
txn.start(); txn.start();
if (usage.getDeleted() != null) { if (usage.getDeleted() != null) {
pstmt = txn.prepareAutoCloseStatement(UPDATE_DELETED); try(PreparedStatement pstmt = txn.prepareStatement(UPDATE_DELETED);) {
if (pstmt != null) {
pstmt.setString(1, DateUtil.getDateDisplayString(TimeZone.getTimeZone("GMT"), usage.getDeleted())); pstmt.setString(1, DateUtil.getDateDisplayString(TimeZone.getTimeZone("GMT"), usage.getDeleted()));
pstmt.setLong(2, usage.getAccountId()); pstmt.setLong(2, usage.getAccountId());
pstmt.setLong(3, usage.getId()); pstmt.setLong(3, usage.getId());
pstmt.setInt(4, usage.getStorageType()); pstmt.setInt(4, usage.getStorageType());
}
pstmt.executeUpdate(); pstmt.executeUpdate();
}
}catch (SQLException e)
{
throw new CloudException("UsageStorageVO update Error:"+e.getMessage(),e);
}
}
txn.commit(); txn.commit();
} catch (Exception e) { } catch (Exception e) {
txn.rollback(); txn.rollback();
s_logger.warn("Error updating UsageStorageVO", e); s_logger.error("Error updating UsageStorageVO:"+e.getMessage(), e);
} finally { } finally {
txn.close(); txn.close();
} }
@ -157,11 +167,8 @@ public class UsageStorageDaoImpl extends GenericDaoBase<UsageStorageVO, Long> im
} }
TransactionLegacy txn = TransactionLegacy.open(TransactionLegacy.USAGE_DB); TransactionLegacy txn = TransactionLegacy.open(TransactionLegacy.USAGE_DB);
PreparedStatement pstmt = null;
try {
int i = 1; int i = 1;
pstmt = txn.prepareAutoCloseStatement(sql); try (PreparedStatement pstmt = txn.prepareStatement(sql);){
if (param1 != null) { if (param1 != null) {
pstmt.setLong(i++, param1); pstmt.setLong(i++, param1);
} }
@ -172,7 +179,7 @@ public class UsageStorageDaoImpl extends GenericDaoBase<UsageStorageVO, Long> im
pstmt.setString(i++, DateUtil.getDateDisplayString(TimeZone.getTimeZone("GMT"), startDate)); pstmt.setString(i++, DateUtil.getDateDisplayString(TimeZone.getTimeZone("GMT"), startDate));
pstmt.setString(i++, DateUtil.getDateDisplayString(TimeZone.getTimeZone("GMT"), endDate)); pstmt.setString(i++, DateUtil.getDateDisplayString(TimeZone.getTimeZone("GMT"), endDate));
ResultSet rs = pstmt.executeQuery(); try(ResultSet rs = pstmt.executeQuery();) {
while (rs.next()) { while (rs.next()) {
//id, zone_id, account_id, domain_id, storage_type, size, created, deleted //id, zone_id, account_id, domain_id, storage_type, size, created, deleted
Long id = Long.valueOf(rs.getLong(1)); Long id = Long.valueOf(rs.getLong(1));
@ -197,13 +204,16 @@ public class UsageStorageDaoImpl extends GenericDaoBase<UsageStorageVO, Long> im
usageRecords.add(new UsageStorageVO(id, zoneId, acctId, dId, type, sourceId, size, virtualSize, createdDate, deletedDate)); usageRecords.add(new UsageStorageVO(id, zoneId, acctId, dId, type, sourceId, size, virtualSize, createdDate, deletedDate));
} }
} catch (Exception e) { }catch(SQLException e)
{
throw new CloudException("getUsageRecords:"+e.getMessage(),e);
}
}catch (Exception e) {
txn.rollback(); txn.rollback();
s_logger.warn("Error getting usage records", e); s_logger.error("getUsageRecords:Exception:"+e.getMessage(), e);
} finally { } finally {
txn.close(); txn.close();
} }
return usageRecords; return usageRecords;
} }
} }

View File

@ -18,6 +18,7 @@ package com.cloud.usage.dao;
import java.sql.PreparedStatement; import java.sql.PreparedStatement;
import java.sql.ResultSet; import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
@ -25,6 +26,7 @@ import java.util.TimeZone;
import javax.ejb.Local; import javax.ejb.Local;
import com.cloud.exception.CloudException;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
@ -52,20 +54,24 @@ public class UsageVPNUserDaoImpl extends GenericDaoBase<UsageVPNUserVO, Long> im
@Override @Override
public void update(UsageVPNUserVO usage) { public void update(UsageVPNUserVO usage) {
TransactionLegacy txn = TransactionLegacy.open(TransactionLegacy.USAGE_DB); TransactionLegacy txn = TransactionLegacy.open(TransactionLegacy.USAGE_DB);
PreparedStatement pstmt = null;
try { try {
txn.start(); txn.start();
if (usage.getDeleted() != null) { if (usage.getDeleted() != null) {
pstmt = txn.prepareAutoCloseStatement(UPDATE_DELETED); try(PreparedStatement pstmt = txn.prepareStatement(UPDATE_DELETED);) {
if (pstmt != null) {
pstmt.setString(1, DateUtil.getDateDisplayString(TimeZone.getTimeZone("GMT"), usage.getDeleted())); pstmt.setString(1, DateUtil.getDateDisplayString(TimeZone.getTimeZone("GMT"), usage.getDeleted()));
pstmt.setLong(2, usage.getAccountId()); pstmt.setLong(2, usage.getAccountId());
pstmt.setLong(3, usage.getUserId()); pstmt.setLong(3, usage.getUserId());
}
pstmt.executeUpdate(); pstmt.executeUpdate();
}
}catch (SQLException e) {
throw new CloudException("Error updating UsageVPNUserVO"+e.getMessage(), e);
}
}
txn.commit(); txn.commit();
} catch (Exception e) { } catch (Exception e) {
txn.rollback(); txn.rollback();
s_logger.warn("Error updating UsageVPNUserVO", e); s_logger.error("Error updating UsageVPNUserVO:"+e.getMessage(), e);
} finally { } finally {
txn.close(); txn.close();
} }

View File

@ -18,6 +18,7 @@ package com.cloud.usage.dao;
import java.sql.PreparedStatement; import java.sql.PreparedStatement;
import java.sql.ResultSet; import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
@ -25,6 +26,7 @@ import java.util.TimeZone;
import javax.ejb.Local; import javax.ejb.Local;
import com.cloud.exception.CloudException;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
@ -55,18 +57,21 @@ public class UsageVolumeDaoImpl extends GenericDaoBase<UsageVolumeVO, Long> impl
@Override @Override
public void removeBy(long accountId, long volId) { public void removeBy(long accountId, long volId) {
TransactionLegacy txn = TransactionLegacy.open(TransactionLegacy.USAGE_DB); TransactionLegacy txn = TransactionLegacy.open(TransactionLegacy.USAGE_DB);
PreparedStatement pstmt = null;
try { try {
txn.start(); txn.start();
String sql = REMOVE_BY_USERID_VOLID; try(PreparedStatement pstmt = txn.prepareStatement(REMOVE_BY_USERID_VOLID);) {
pstmt = txn.prepareAutoCloseStatement(sql); if (pstmt != null) {
pstmt.setLong(1, accountId); pstmt.setLong(1, accountId);
pstmt.setLong(2, volId); pstmt.setLong(2, volId);
pstmt.executeUpdate(); pstmt.executeUpdate();
}
}catch (SQLException e) {
throw new CloudException("Error removing usageVolumeVO:"+e.getMessage(), e);
}
txn.commit(); txn.commit();
} catch (Exception e) { } catch (Exception e) {
txn.rollback(); txn.rollback();
s_logger.warn("Error removing usageVolumeVO", e); s_logger.warn("Error removing usageVolumeVO:"+e.getMessage(), e);
} finally { } finally {
txn.close(); txn.close();
} }

View File

@ -263,9 +263,8 @@ public class PrimaryDataStoreDaoImpl extends GenericDaoBase<StoragePoolVO, Long>
sql.delete(sql.length() - 4, sql.length()); sql.delete(sql.length() - 4, sql.length());
sql.append(DetailsSqlSuffix); sql.append(DetailsSqlSuffix);
TransactionLegacy txn = TransactionLegacy.currentTxn(); TransactionLegacy txn = TransactionLegacy.currentTxn();
PreparedStatement pstmt = null; try (PreparedStatement pstmt = txn.prepareStatement(sql.toString());){
try { List<StoragePoolVO> pools = new ArrayList<StoragePoolVO>();
pstmt = txn.prepareAutoCloseStatement(sql.toString());
int i = 1; int i = 1;
pstmt.setLong(i++, dcId); pstmt.setLong(i++, dcId);
pstmt.setLong(i++, podId); pstmt.setLong(i++, podId);
@ -274,14 +273,16 @@ public class PrimaryDataStoreDaoImpl extends GenericDaoBase<StoragePoolVO, Long>
pstmt.setLong(i++, clusterId); pstmt.setLong(i++, clusterId);
} }
pstmt.setInt(i++, details.size()); pstmt.setInt(i++, details.size());
ResultSet rs = pstmt.executeQuery(); try(ResultSet rs = pstmt.executeQuery();) {
List<StoragePoolVO> pools = new ArrayList<StoragePoolVO>();
while (rs.next()) { while (rs.next()) {
pools.add(toEntityBean(rs, false)); pools.add(toEntityBean(rs, false));
} }
}catch (SQLException e) {
throw new CloudRuntimeException("Unable to execute :" + e.getMessage(), e);
}
return pools; return pools;
} catch (SQLException e) { } catch (SQLException e) {
throw new CloudRuntimeException("Unable to execute " + pstmt, e); throw new CloudRuntimeException("Unable to execute :" + e.getMessage(), e);
} }
} }
@ -378,21 +379,24 @@ public class PrimaryDataStoreDaoImpl extends GenericDaoBase<StoragePoolVO, Long>
sql.delete(sql.length() - 4, sql.length()); sql.delete(sql.length() - 4, sql.length());
sql.append(ZoneWideDetailsSqlSuffix); sql.append(ZoneWideDetailsSqlSuffix);
TransactionLegacy txn = TransactionLegacy.currentTxn(); TransactionLegacy txn = TransactionLegacy.currentTxn();
PreparedStatement pstmt = null; try (PreparedStatement pstmt = txn.prepareStatement(sql.toString());){
try { List<StoragePoolVO> pools = new ArrayList<StoragePoolVO>();
pstmt = txn.prepareAutoCloseStatement(sql.toString()); if (pstmt != null) {
int i = 1; int i = 1;
pstmt.setLong(i++, dcId); pstmt.setLong(i++, dcId);
pstmt.setString(i++, ScopeType.ZONE.toString()); pstmt.setString(i++, ScopeType.ZONE.toString());
pstmt.setInt(i++, details.size()); pstmt.setInt(i++, details.size());
ResultSet rs = pstmt.executeQuery(); try(ResultSet rs = pstmt.executeQuery();) {
List<StoragePoolVO> pools = new ArrayList<StoragePoolVO>();
while (rs.next()) { while (rs.next()) {
pools.add(toEntityBean(rs, false)); pools.add(toEntityBean(rs, false));
} }
}catch (SQLException e) {
throw new CloudRuntimeException("findZoneWideStoragePoolsByTags:Exception:" + e.getMessage(), e);
}
}
return pools; return pools;
} catch (SQLException e) { } catch (SQLException e) {
throw new CloudRuntimeException("Unable to execute " + pstmt, e); throw new CloudRuntimeException("findZoneWideStoragePoolsByTags:Exception:" + e.getMessage(), e);
} }
} }
} }
@ -400,27 +404,25 @@ public class PrimaryDataStoreDaoImpl extends GenericDaoBase<StoragePoolVO, Long>
@Override @Override
@DB @DB
public List<String> searchForStoragePoolDetails(long poolId, String value) { public List<String> searchForStoragePoolDetails(long poolId, String value) {
StringBuilder sql = new StringBuilder(FindPoolTagDetails); StringBuilder sql = new StringBuilder(FindPoolTagDetails);
TransactionLegacy txn = TransactionLegacy.currentTxn(); TransactionLegacy txn = TransactionLegacy.currentTxn();
PreparedStatement pstmt = null; List<String> tags = new ArrayList<String>();
try { try(PreparedStatement pstmt = txn.prepareStatement(sql.toString());) {
pstmt = txn.prepareAutoCloseStatement(sql.toString()); if (pstmt != null) {
pstmt.setLong(1, poolId); pstmt.setLong(1, poolId);
pstmt.setString(2, value); pstmt.setString(2, value);
try(ResultSet rs = pstmt.executeQuery();) {
ResultSet rs = pstmt.executeQuery();
List<String> tags = new ArrayList<String>();
while (rs.next()) { while (rs.next()) {
tags.add(rs.getString("name")); tags.add(rs.getString("name"));
} }
}catch (SQLException e) {
throw new CloudRuntimeException("searchForStoragePoolDetails:Exception:" + e.getMessage(), e);
}
}
return tags; return tags;
} catch (SQLException e) { } catch (SQLException e) {
throw new CloudRuntimeException("Unable to execute " + pstmt.toString(), e); throw new CloudRuntimeException("searchForStoragePoolDetails:Exception:" + e.getMessage(), e);
} }
} }
@Override @Override

View File

@ -52,7 +52,7 @@ public class StorageCacheRandomAllocator implements StorageCacheAllocator {
} }
List<DataStore> cacheStores = dataStoreMgr.getImageCacheStores(scope); List<DataStore> cacheStores = dataStoreMgr.getImageCacheStores(scope);
if (cacheStores.size() <= 0) { if ((cacheStores == null) || (cacheStores.size() <= 0)) {
s_logger.debug("Can't find staging storage in zone: " + scope.getScopeId()); s_logger.debug("Can't find staging storage in zone: " + scope.getScopeId());
return null; return null;
} }

View File

@ -67,11 +67,14 @@ public class PrimaryDataStoreHelper {
protected StoragePoolHostDao storagePoolHostDao; protected StoragePoolHostDao storagePoolHostDao;
public DataStore createPrimaryDataStore(PrimaryDataStoreParameters params) { public DataStore createPrimaryDataStore(PrimaryDataStoreParameters params) {
if(params == null)
{
throw new InvalidParameterValueException("createPrimaryDataStore: Input params is null, please check");
}
StoragePoolVO dataStoreVO = dataStoreDao.findPoolByUUID(params.getUuid()); StoragePoolVO dataStoreVO = dataStoreDao.findPoolByUUID(params.getUuid());
if (dataStoreVO != null) { if (dataStoreVO != null) {
throw new CloudRuntimeException("duplicate uuid: " + params.getUuid()); throw new CloudRuntimeException("duplicate uuid: " + params.getUuid());
} }
dataStoreVO = new StoragePoolVO(); dataStoreVO = new StoragePoolVO();
dataStoreVO.setStorageProviderName(params.getProviderName()); dataStoreVO.setStorageProviderName(params.getProviderName());
dataStoreVO.setHostAddress(params.getHost()); dataStoreVO.setHostAddress(params.getHost());
@ -114,7 +117,6 @@ public class PrimaryDataStoreHelper {
dataStoreVO.setPath(updatedPath); dataStoreVO.setPath(updatedPath);
} }
String tags = params.getTags(); String tags = params.getTags();
if (tags != null) { if (tags != null) {
String[] tokens = tags.split(","); String[] tokens = tags.split(",");
@ -127,9 +129,7 @@ public class PrimaryDataStoreHelper {
details.put(tag, "true"); details.put(tag, "true");
} }
} }
dataStoreVO = dataStoreDao.persist(dataStoreVO, details); dataStoreVO = dataStoreDao.persist(dataStoreVO, details);
return dataStoreMgr.getDataStore(dataStoreVO.getId(), DataStoreRole.Primary); return dataStoreMgr.getDataStore(dataStoreVO.getId(), DataStoreRole.Primary);
} }

View File

@ -53,15 +53,14 @@ public class ManagementServerHostDaoImpl extends GenericDaoBase<ManagementServer
@Override @Override
public void invalidateRunSession(long id, long runid) { public void invalidateRunSession(long id, long runid) {
TransactionLegacy txn = TransactionLegacy.currentTxn(); TransactionLegacy txn = TransactionLegacy.currentTxn();
PreparedStatement pstmt = null; try (PreparedStatement pstmt = txn.prepareStatement("update mshost set runid=0, state='Down' where id=? and runid=?");){
try { if(pstmt != null) {
pstmt = txn.prepareAutoCloseStatement("update mshost set runid=0, state='Down' where id=? and runid=?");
pstmt.setLong(1, id); pstmt.setLong(1, id);
pstmt.setLong(2, runid); pstmt.setLong(2, runid);
pstmt.executeUpdate(); pstmt.executeUpdate();
}
} catch (SQLException e) { } catch (SQLException e) {
throw new CloudRuntimeException("DB exception on " + pstmt.toString(), e); throw new CloudRuntimeException("invalidateRunSession:Exception:"+ e.getMessage(), e);
} }
} }
@ -82,12 +81,10 @@ public class ManagementServerHostDaoImpl extends GenericDaoBase<ManagementServer
@DB @DB
public void update(long id, long runid, String name, String version, String serviceIP, int servicePort, Date lastUpdate) { public void update(long id, long runid, String name, String version, String serviceIP, int servicePort, Date lastUpdate) {
TransactionLegacy txn = TransactionLegacy.currentTxn(); TransactionLegacy txn = TransactionLegacy.currentTxn();
PreparedStatement pstmt = null;
try { try {
txn.start(); txn.start();
try(PreparedStatement pstmt =
pstmt = txn.prepareStatement("update mshost set name=?, version=?, service_ip=?, service_port=?, last_update=?, removed=null, alert_count=0, runid=?, state=? where id=?");) {
txn.prepareAutoCloseStatement("update mshost set name=?, version=?, service_ip=?, service_port=?, last_update=?, removed=null, alert_count=0, runid=?, state=? where id=?");
pstmt.setString(1, name); pstmt.setString(1, name);
pstmt.setString(2, version); pstmt.setString(2, version);
pstmt.setString(3, serviceIP); pstmt.setString(3, serviceIP);
@ -96,12 +93,18 @@ public class ManagementServerHostDaoImpl extends GenericDaoBase<ManagementServer
pstmt.setLong(6, runid); pstmt.setLong(6, runid);
pstmt.setString(7, ManagementServerHost.State.Up.toString()); pstmt.setString(7, ManagementServerHost.State.Up.toString());
pstmt.setLong(8, id); pstmt.setLong(8, id);
pstmt.executeUpdate(); pstmt.executeUpdate();
}catch(SQLException e)
{
throw new CloudRuntimeException("update:Exception:"+e.getMessage(),e);
}
txn.commit(); txn.commit();
} catch (Exception e) { } catch (RuntimeException e) {
txn.rollback();
s_logger.warn("Unexpected exception, ", e); s_logger.warn("Unexpected exception, ", e);
throw new RuntimeException(e.getMessage(), e); throw new RuntimeException(e.getMessage(), e);
}finally {
txn.close();
} }
} }
@ -109,19 +112,20 @@ public class ManagementServerHostDaoImpl extends GenericDaoBase<ManagementServer
@DB @DB
public boolean remove(Long id) { public boolean remove(Long id) {
TransactionLegacy txn = TransactionLegacy.currentTxn(); TransactionLegacy txn = TransactionLegacy.currentTxn();
try { try {
txn.start(); txn.start();
ManagementServerHostVO msHost = findById(id); ManagementServerHostVO msHost = findById(id);
msHost.setState(ManagementServerHost.State.Down); msHost.setState(ManagementServerHost.State.Down);
super.remove(id); super.remove(id);
txn.commit(); txn.commit();
return true; return true;
} catch (Exception e) { } catch (Exception e) {
txn.rollback();
s_logger.warn("Unexpected exception, ", e); s_logger.warn("Unexpected exception, ", e);
throw new RuntimeException(e.getMessage(), e); throw new CloudRuntimeException("remove:Exception:"+e.getMessage(), e);
}finally
{
txn.close();
} }
} }
@ -129,11 +133,9 @@ public class ManagementServerHostDaoImpl extends GenericDaoBase<ManagementServer
@DB @DB
public void update(long id, long runid, Date lastUpdate) { public void update(long id, long runid, Date lastUpdate) {
TransactionLegacy txn = TransactionLegacy.currentTxn(); TransactionLegacy txn = TransactionLegacy.currentTxn();
PreparedStatement pstmt = null;
try { try {
txn.start(); txn.start();
try( PreparedStatement pstmt = txn.prepareStatement("update mshost set last_update=?, removed=null, alert_count=0 where id=? and runid=?");) {
pstmt = txn.prepareAutoCloseStatement("update mshost set last_update=?, removed=null, alert_count=0 where id=? and runid=?");
pstmt.setString(1, DateUtil.getDateDisplayString(TimeZone.getTimeZone("GMT"), lastUpdate)); pstmt.setString(1, DateUtil.getDateDisplayString(TimeZone.getTimeZone("GMT"), lastUpdate));
pstmt.setLong(2, id); pstmt.setLong(2, id);
pstmt.setLong(3, runid); pstmt.setLong(3, runid);
@ -144,9 +146,16 @@ public class ManagementServerHostDaoImpl extends GenericDaoBase<ManagementServer
if (count < 1) { if (count < 1) {
throw new CloudRuntimeException("Invalid cluster session detected", new ClusterInvalidSessionException("runid " + runid + " is no longer valid")); throw new CloudRuntimeException("Invalid cluster session detected", new ClusterInvalidSessionException("runid " + runid + " is no longer valid"));
} }
} catch (Exception e) { }catch (SQLException e) {
s_logger.warn("Unexpected exception, ", e); throw new CloudRuntimeException("update:Exception:"+e.getMessage(), e);
throw new RuntimeException(e.getMessage(), e); }
} catch (RuntimeException e) {
txn.rollback();
s_logger.warn("update:Exception:"+e.getMessage(), e);
throw new RuntimeException("update:Exception:"+e.getMessage(), e);
}
finally {
txn.close();
} }
} }
@ -170,21 +179,25 @@ public class ManagementServerHostDaoImpl extends GenericDaoBase<ManagementServer
@DB @DB
public int increaseAlertCount(long id) { public int increaseAlertCount(long id) {
TransactionLegacy txn = TransactionLegacy.currentTxn(); TransactionLegacy txn = TransactionLegacy.currentTxn();
PreparedStatement pstmt = null;
int changedRows = 0; int changedRows = 0;
try { try {
txn.start(); txn.start();
try(PreparedStatement pstmt = txn.prepareStatement("update mshost set alert_count=alert_count+1 where id=? and alert_count=0");) {
pstmt = txn.prepareAutoCloseStatement("update mshost set alert_count=alert_count+1 where id=? and alert_count=0");
pstmt.setLong(1, id); pstmt.setLong(1, id);
changedRows = pstmt.executeUpdate(); changedRows = pstmt.executeUpdate();
txn.commit(); }catch (SQLException e)
} catch (Exception e) { {
s_logger.warn("Unexpected exception, ", e); throw new CloudRuntimeException("increaseAlertCount:Exception:"+e.getMessage(),e);
throw new RuntimeException(e.getMessage(), e); }
txn.commit();
} catch (RuntimeException e) {
txn.rollback();
s_logger.warn("increaseAlertCount:Exception:" + e.getMessage(), e);
throw new CloudRuntimeException("increaseAlertCount:Exception:" + e.getMessage(), e);
}finally
{
txn.close();
} }
return changedRows; return changedRows;
} }
@ -211,21 +224,19 @@ public class ManagementServerHostDaoImpl extends GenericDaoBase<ManagementServer
@Override @Override
public void update(long id, long runId, State state, Date lastUpdate) { public void update(long id, long runId, State state, Date lastUpdate) {
TransactionLegacy txn = TransactionLegacy.currentTxn(); TransactionLegacy txn = TransactionLegacy.currentTxn();
PreparedStatement pstmt = null; try (PreparedStatement pstmt = txn.prepareStatement("update mshost set state=?, last_update=? where id=? and runid=?");){
try { if (pstmt != null) {
pstmt = txn.prepareAutoCloseStatement("update mshost set state=?, last_update=? where id=? and runid=?");
pstmt.setString(1, state.toString()); pstmt.setString(1, state.toString());
pstmt.setString(2, DateUtil.getDateDisplayString(TimeZone.getTimeZone("GMT"), lastUpdate)); pstmt.setString(2, DateUtil.getDateDisplayString(TimeZone.getTimeZone("GMT"), lastUpdate));
pstmt.setLong(3, id); pstmt.setLong(3, id);
pstmt.setLong(4, runId); pstmt.setLong(4, runId);
int count = pstmt.executeUpdate(); int count = pstmt.executeUpdate();
if (count < 1) { if (count < 1) {
throw new CloudRuntimeException("Invalid cluster session detected", new ClusterInvalidSessionException("runid " + runId + " is no longer valid")); throw new CloudRuntimeException("Invalid cluster session detected", new ClusterInvalidSessionException("runid " + runId + " is no longer valid"));
} }
}
} catch (SQLException e) { } catch (SQLException e) {
throw new CloudRuntimeException("DB exception on " + pstmt.toString(), e); throw new CloudRuntimeException("update:Exception:" + e.getMessage(), e);
} }
} }
@ -241,22 +252,21 @@ public class ManagementServerHostDaoImpl extends GenericDaoBase<ManagementServer
@Override @Override
public List<Long> listOrphanMsids() { public List<Long> listOrphanMsids() {
List<Long> orphanList = new ArrayList<Long>(); List<Long> orphanList = new ArrayList<Long>();
TransactionLegacy txn = TransactionLegacy.currentTxn(); TransactionLegacy txn = TransactionLegacy.currentTxn();
PreparedStatement pstmt = null; try (PreparedStatement pstmt =
try { txn.prepareStatement("select t.mgmt_server_id from (select mgmt_server_id, count(*) as count from host group by mgmt_server_id) as t WHERE t.count > 0 AND t.mgmt_server_id NOT IN (select msid from mshost)");)
pstmt = {
txn.prepareAutoCloseStatement("select t.mgmt_server_id from (select mgmt_server_id, count(*) as count from host group by mgmt_server_id) as t WHERE t.count > 0 AND t.mgmt_server_id NOT IN (select msid from mshost)"); try(ResultSet rs = pstmt.executeQuery();) {
ResultSet rs = pstmt.executeQuery();
while (rs.next()) { while (rs.next()) {
orphanList.add(rs.getLong(1)); orphanList.add(rs.getLong(1));
} }
} catch (SQLException e) { }catch (SQLException e) {
throw new CloudRuntimeException("DB exception on " + pstmt.toString(), e); throw new CloudRuntimeException("listOrphanMsids:Exception:" + e.getMessage(), e);
} }
return orphanList; return orphanList;
} catch (SQLException e) {
throw new CloudRuntimeException("listOrphanMsids:Exception:" + e.getMessage(), e);
}
} }
@Override @Override

View File

@ -257,7 +257,7 @@ public class DbUtil {
rs = pstmt.executeQuery(); rs = pstmt.executeQuery();
if (rs != null && rs.first()) if (rs != null && rs.first())
return rs.getInt(1) > 0; return rs.getInt(1) > 0;
s_logger.error("RELEASE_LOCK() returns unexpected result : " + rs.getInt(1)); s_logger.error("releaseGlobalLock:RELEASE_LOCK() returns unexpected result");
} catch (SQLException e) { } catch (SQLException e) {
s_logger.error("RELEASE_LOCK() throws exception ", e); s_logger.error("RELEASE_LOCK() throws exception ", e);
} catch (Throwable e) { } catch (Throwable e) {

View File

@ -1486,9 +1486,9 @@ public abstract class GenericDaoBase<T, ID extends Serializable> extends Compone
if (length < str.length()) { if (length < str.length()) {
try { try {
if (attr.is(Attribute.Flag.Encrypted)) { if (attr.is(Attribute.Flag.Encrypted)) {
pstmt.setBytes(j, DBEncryptionUtil.encrypt(str.substring(0, column.length())).getBytes("UTF-8")); pstmt.setBytes(j, DBEncryptionUtil.encrypt(str.substring(0, length)).getBytes("UTF-8"));
} else { } else {
pstmt.setBytes(j, str.substring(0, column.length()).getBytes("UTF-8")); pstmt.setBytes(j, str.substring(0, length).getBytes("UTF-8"));
} }
} catch (UnsupportedEncodingException e) { } catch (UnsupportedEncodingException e) {
// no-way it can't support UTF-8 encoding // no-way it can't support UTF-8 encoding

View File

@ -101,6 +101,10 @@ public class BridgeVifDriver extends VifDriverBase {
} else if (nic.getBroadcastType() == Networks.BroadcastDomainType.Lswitch) { } else if (nic.getBroadcastType() == Networks.BroadcastDomainType.Lswitch) {
throw new InternalErrorException("Nicira NVP Logicalswitches are not supported by the BridgeVifDriver"); throw new InternalErrorException("Nicira NVP Logicalswitches are not supported by the BridgeVifDriver");
} }
if ((vNetId == null)||(protocol == null))
{
throw new InternalErrorException("plug: protocol or vNetId value is null");
}
String trafficLabel = nic.getName(); String trafficLabel = nic.getName();
if (nic.getType() == Networks.TrafficType.Guest) { if (nic.getType() == Networks.TrafficType.Guest) {
Integer networkRateKBps = (nic.getNetworkRateMbps() != null && nic.getNetworkRateMbps().intValue() != -1) ? nic.getNetworkRateMbps().intValue() * 128 : 0; Integer networkRateKBps = (nic.getNetworkRateMbps() != null && nic.getNetworkRateMbps().intValue() != -1) ? nic.getNetworkRateMbps().intValue() * 128 : 0;

View File

@ -61,7 +61,6 @@ public class SamplePrimaryDataStoreLifeCycleImpl implements PrimaryDataStoreLife
@Override @Override
public DataStore initialize(Map<String, Object> dsInfos) { public DataStore initialize(Map<String, Object> dsInfos) {
DataStore store = primaryStoreHelper.createPrimaryDataStore(null); DataStore store = primaryStoreHelper.createPrimaryDataStore(null);
return providerMgr.getPrimaryDataStore(store.getId()); return providerMgr.getPrimaryDataStore(store.getId());
} }

View File

@ -1642,7 +1642,7 @@ public class VolumeApiServiceImpl extends ManagerBase implements VolumeApiServic
try { try {
return orchestrateMigrateVolume(vol.getId(), destPool.getId(), liveMigrateVolume); return orchestrateMigrateVolume(vol.getId(), destPool.getId(), liveMigrateVolume);
} finally { } finally {
if (VmJobEnabled.value()) if ((VmJobEnabled.value())&&(placeHolder != null))
_workJobDao.expunge(placeHolder.getId()); _workJobDao.expunge(placeHolder.getId());
} }

View File

@ -190,7 +190,7 @@ public class TaggedResourceManagerImpl extends ManagerBase implements TaggedReso
accountId = Account.ACCOUNT_ID_SYSTEM; accountId = Account.ACCOUNT_ID_SYSTEM;
} }
if ( ((accountId != null) && (domainId == -1)) || (domainId == null) ) if ((domainId == null) || ((accountId != null) && (domainId.longValue() == -1)))
{ {
domainId = _accountDao.getDomainIdForGivenAccountId(accountId); domainId = _accountDao.getDomainIdForGivenAccountId(accountId);
} }

View File

@ -727,7 +727,7 @@ public class VMSnapshotManagerImpl extends ManagerBase implements VMSnapshotMana
try { try {
return orchestrateDeleteAllVMSnapshots(vmId, type); return orchestrateDeleteAllVMSnapshots(vmId, type);
} finally { } finally {
if (VmJobEnabled.value()) if ( (VmJobEnabled.value()) && (placeHolder != null))
_workJobDao.expunge(placeHolder.getId()); _workJobDao.expunge(placeHolder.getId());
} }