CLOUDSTACK-6242: exception handling improvements

Signed-off-by: Daan Hoogland <daan@onecht.net>
This commit is contained in:
Ding Yuan 2014-04-14 17:02:03 -04:00 committed by Daan Hoogland
parent 498cf6183d
commit c031eb7d38
21 changed files with 69 additions and 25 deletions

View File

@ -802,6 +802,7 @@ public class AgentManagerImpl extends ManagerBase implements AgentManager, Handl
* Why this can happen? Ask God not me. I hate there was no piece of comment for code handling race condition. * Why this can happen? Ask God not me. I hate there was no piece of comment for code handling race condition.
* God knew what race condition the code dealt with! * God knew what race condition the code dealt with!
*/ */
s_logger.debug("Caught exception while getting agent's next status", ne);
} }
if (nextStatus == Status.Alert) { if (nextStatus == Status.Alert) {

View File

@ -79,6 +79,7 @@ import com.cloud.cluster.agentlb.dao.HostTransferMapDao;
import com.cloud.cluster.dao.ManagementServerHostDao; import com.cloud.cluster.dao.ManagementServerHostDao;
import com.cloud.exception.AgentUnavailableException; import com.cloud.exception.AgentUnavailableException;
import com.cloud.exception.OperationTimedoutException; import com.cloud.exception.OperationTimedoutException;
import com.cloud.exception.UnsupportedVersionException;
import com.cloud.host.Host; import com.cloud.host.Host;
import com.cloud.host.HostVO; import com.cloud.host.HostVO;
import com.cloud.host.Status; import com.cloud.host.Status;
@ -412,7 +413,9 @@ public class ClusteredAgentManagerImpl extends AgentManagerImpl implements Clust
if (ch == null) { if (ch == null) {
try { try {
logD(bytes, "Unable to route to peer: " + Request.parse(bytes).toString()); logD(bytes, "Unable to route to peer: " + Request.parse(bytes).toString());
} catch (Exception e) { } catch (ClassNotFoundException | UnsupportedVersionException e) {
// Request.parse thrown exception when we try to log it, log as much as we can
logD(bytes, "Unable to route to peer, and Request.parse further caught exception" + e.getMessage());
} }
return false; return false;
} }
@ -430,7 +433,10 @@ public class ClusteredAgentManagerImpl extends AgentManagerImpl implements Clust
} catch (IOException e) { } catch (IOException e) {
try { try {
logI(bytes, "Unable to route to peer: " + Request.parse(bytes).toString() + " due to " + e.getMessage()); logI(bytes, "Unable to route to peer: " + Request.parse(bytes).toString() + " due to " + e.getMessage());
} catch (Exception ex) { } catch (ClassNotFoundException | UnsupportedVersionException ex) {
// Request.parse thrown exception when we try to log it, log as much as we can
logI(bytes, "Unable to route to peer due to" + e.getMessage()
+ ". Also caught exception when parsing request: " + ex.getMessage());
} }
} }
} }

View File

@ -1930,6 +1930,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
throw new CloudRuntimeException("Unable to complete migration for " + vm); throw new CloudRuntimeException("Unable to complete migration for " + vm);
} }
} catch (OperationTimedoutException e) { } catch (OperationTimedoutException e) {
s_logger.debug("Error while checking the vm " + vm + " on host " + dstHostId, e);
} }
migrated = true; migrated = true;
@ -3898,6 +3899,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
throw new CloudRuntimeException("Unable to complete migration for " + vm); throw new CloudRuntimeException("Unable to complete migration for " + vm);
} }
} catch (OperationTimedoutException e) { } catch (OperationTimedoutException e) {
s_logger.debug("Error while checking the vm " + vm + " on host " + dstHostId, e);
} }
migrated = true; migrated = true;

View File

@ -270,7 +270,7 @@ public class EngineDataCenterDaoImpl extends GenericDaoBase<EngineDataCenterVO,
Long dcId = Long.parseLong(tokenOrIdOrName); Long dcId = Long.parseLong(tokenOrIdOrName);
return findById(dcId); return findById(dcId);
} catch (NumberFormatException nfe) { } catch (NumberFormatException nfe) {
s_logger.debug("Cannot parse " + tokenOrIdOrName + " into long. " + nfe);
} }
} }
} }

View File

@ -411,7 +411,7 @@ public class DataCenterDaoImpl extends GenericDaoBase<DataCenterVO, Long> implem
Long dcId = Long.parseLong(tokenOrIdOrName); Long dcId = Long.parseLong(tokenOrIdOrName);
return findById(dcId); return findById(dcId);
} catch (NumberFormatException nfe) { } catch (NumberFormatException nfe) {
s_logger.debug("Cannot parse " + tokenOrIdOrName + " into long. " + nfe);
} }
} }
} }

View File

@ -871,7 +871,7 @@ public class HostDaoImpl extends GenericDaoBase<HostVO, Long> implements HostDao
l.add(info); l.add(info);
} }
} catch (SQLException e) { } catch (SQLException e) {
} catch (Throwable e) { s_logger.debug("SQLException caught", e);
} }
return l; return l;
} }

View File

@ -151,7 +151,7 @@ public class StoragePoolHostDaoImpl extends GenericDaoBase<StoragePoolHostVO, Lo
l.add(new Pair<Long, Integer>(rs.getLong(1), rs.getInt(2))); l.add(new Pair<Long, Integer>(rs.getLong(1), rs.getInt(2)));
} }
} catch (SQLException e) { } catch (SQLException e) {
} catch (Throwable e) { s_logger.debug("SQLException: ", e);
} }
return l; return l;
} }

View File

@ -232,7 +232,7 @@ public class VMTemplateDaoImpl extends GenericDaoBase<VMTemplateVO, Long> implem
l.add(rs.getLong(1)); l.add(rs.getLong(1));
} }
} catch (SQLException e) { } catch (SQLException e) {
} catch (Throwable e) { s_logger.debug("Exception: ", e);
} }
return l; return l;
} }

View File

@ -986,8 +986,9 @@ public class Upgrade2214to30 extends Upgrade30xBase implements DbUpgrade {
pstmt = conn.prepareStatement("ALTER TABLE `cloud`.`networks` DROP COLUMN `switch_to_isolated`"); pstmt = conn.prepareStatement("ALTER TABLE `cloud`.`networks` DROP COLUMN `switch_to_isolated`");
pstmt2Close.add(pstmt); pstmt2Close.add(pstmt);
pstmt.executeUpdate(); pstmt.executeUpdate();
} catch (Exception ex) { } catch (SQLException ex) {
// do nothing here // do nothing here
s_logger.debug("Caught SQLException when trying to drop switch_to_isolated column ", ex);
} }
} catch (SQLException e) { } catch (SQLException e) {

View File

@ -217,7 +217,7 @@ public class ConsoleProxyDaoImpl extends GenericDaoBase<ConsoleProxyVO, Long> im
l.add(new Pair<Long, Integer>(rs.getLong(1), rs.getInt(2))); l.add(new Pair<Long, Integer>(rs.getLong(1), rs.getInt(2)));
} }
} catch (SQLException e) { } catch (SQLException e) {
} catch (Throwable e) { s_logger.debug("Caught SQLException: ", e);
} }
return l; return l;
} }
@ -242,7 +242,7 @@ public class ConsoleProxyDaoImpl extends GenericDaoBase<ConsoleProxyVO, Long> im
l.add(new Pair<Long, Integer>(rs.getLong(1), rs.getInt(2))); l.add(new Pair<Long, Integer>(rs.getLong(1), rs.getInt(2)));
} }
} catch (SQLException e) { } catch (SQLException e) {
} catch (Throwable e) { s_logger.debug("Caught SQLException: ", e);
} }
return l; return l;
} }
@ -261,7 +261,7 @@ public class ConsoleProxyDaoImpl extends GenericDaoBase<ConsoleProxyVO, Long> im
return rs.getInt(1); return rs.getInt(1);
} }
} catch (SQLException e) { } catch (SQLException e) {
} catch (Throwable e) { s_logger.debug("Caught SQLException: ", e);
} }
return 0; return 0;
} }
@ -279,7 +279,7 @@ public class ConsoleProxyDaoImpl extends GenericDaoBase<ConsoleProxyVO, Long> im
return rs.getInt(1); return rs.getInt(1);
} }
} catch (SQLException e) { } catch (SQLException e) {
} catch (Throwable e) { s_logger.debug("Caught SQLException: ", e);
} }
return 0; return 0;
} }
@ -301,7 +301,7 @@ public class ConsoleProxyDaoImpl extends GenericDaoBase<ConsoleProxyVO, Long> im
l.add(info); l.add(info);
} }
} catch (SQLException e) { } catch (SQLException e) {
} catch (Throwable e) { s_logger.debug("Exception: ", e);
} }
return l; return l;
} }
@ -323,7 +323,7 @@ public class ConsoleProxyDaoImpl extends GenericDaoBase<ConsoleProxyVO, Long> im
l.add(rs.getLong(1)); l.add(rs.getLong(1));
} }
} catch (SQLException e) { } catch (SQLException e) {
} catch (Throwable e) { s_logger.debug("Caught SQLException: ", e);
} }
return l; return l;
} }

View File

@ -195,7 +195,7 @@ public class SecondaryStorageVmDaoImpl extends GenericDaoBase<SecondaryStorageVm
l.add(rs.getLong(1)); l.add(rs.getLong(1));
} }
} catch (SQLException e) { } catch (SQLException e) {
} catch (Throwable e) { s_logger.debug("Caught SQLException: ", e);
} }
return l; return l;
} }

View File

@ -224,7 +224,7 @@ public class DataObjectManagerImpl implements DataObjectManager {
try { try {
objectInDataStoreMgr.update(destData, ObjectInDataStoreStateMachine.Event.OperationFailed); objectInDataStoreMgr.update(destData, ObjectInDataStoreStateMachine.Event.OperationFailed);
} catch (Exception e1) { } catch (Exception e1) {
s_logger.debug("failed to further change state to OperationFailed", e1);
} }
CreateCmdResult res = new CreateCmdResult(null, null); CreateCmdResult res = new CreateCmdResult(null, null);
res.setResult("Failed to change state: " + e.toString()); res.setResult("Failed to change state: " + e.toString());
@ -234,7 +234,7 @@ public class DataObjectManagerImpl implements DataObjectManager {
try { try {
objectInDataStoreMgr.update(destData, ObjectInDataStoreStateMachine.Event.OperationFailed); objectInDataStoreMgr.update(destData, ObjectInDataStoreStateMachine.Event.OperationFailed);
} catch (Exception e1) { } catch (Exception e1) {
s_logger.debug("failed to further change state to OperationFailed", e1);
} }
CreateCmdResult res = new CreateCmdResult(null, null); CreateCmdResult res = new CreateCmdResult(null, null);
res.setResult("Failed to change state: " + e.toString()); res.setResult("Failed to change state: " + e.toString());
@ -272,6 +272,7 @@ public class DataObjectManagerImpl implements DataObjectManager {
try { try {
objectInDataStoreMgr.update(destObj, ObjectInDataStoreStateMachine.Event.OperationFailed); objectInDataStoreMgr.update(destObj, ObjectInDataStoreStateMachine.Event.OperationFailed);
} catch (Exception e1) { } catch (Exception e1) {
s_logger.debug("failed to further change state to OperationFailed", e1);
} }
CreateCmdResult res = new CreateCmdResult(null, null); CreateCmdResult res = new CreateCmdResult(null, null);
res.setResult("Failed to update copying state: " + e.toString()); res.setResult("Failed to update copying state: " + e.toString());
@ -281,6 +282,7 @@ public class DataObjectManagerImpl implements DataObjectManager {
try { try {
objectInDataStoreMgr.update(destObj, ObjectInDataStoreStateMachine.Event.OperationFailed); objectInDataStoreMgr.update(destObj, ObjectInDataStoreStateMachine.Event.OperationFailed);
} catch (Exception e1) { } catch (Exception e1) {
s_logger.debug("failed to further change state to OperationFailed", e1);
} }
CreateCmdResult res = new CreateCmdResult(null, null); CreateCmdResult res = new CreateCmdResult(null, null);
res.setResult("Failed to update copying state: " + e.toString()); res.setResult("Failed to update copying state: " + e.toString());

View File

@ -33,12 +33,15 @@ import java.util.jar.JarEntry;
import java.util.jar.JarInputStream; import java.util.jar.JarInputStream;
import org.apache.commons.io.IOUtils; import org.apache.commons.io.IOUtils;
import org.apache.log4j.Logger;
// //
// Finding classes in a given package code is taken and modified from // Finding classes in a given package code is taken and modified from
// Credit: http://internna.blogspot.com/2007/11/java-5-retrieving-all-classes-from.html // Credit: http://internna.blogspot.com/2007/11/java-5-retrieving-all-classes-from.html
// //
public class OnwireClassRegistry { public class OnwireClassRegistry {
private static final Logger s_logger = Logger.getLogger(OnwireClassRegistry.class);
private List<String> packages = new ArrayList<String>(); private List<String> packages = new ArrayList<String>();
private final Map<String, Class<?>> registry = new HashMap<String, Class<?>>(); private final Map<String, Class<?>> registry = new HashMap<String, Class<?>>();
@ -121,6 +124,7 @@ public class OnwireClassRegistry {
} }
} }
} catch (IOException e) { } catch (IOException e) {
s_logger.debug("Encountered IOException", e);
} catch (ClassNotFoundException e) { } catch (ClassNotFoundException e) {
} }
return classes; return classes;
@ -137,6 +141,7 @@ public class OnwireClassRegistry {
classes.add(clazz); classes.add(clazz);
} catch (ClassNotFoundException e) { } catch (ClassNotFoundException e) {
} catch (Exception e) { } catch (Exception e) {
s_logger.debug("Encountered unexpect exception! ", e);
} }
} else { } else {
File f = new File(directory.getPath() + "/" + file); File f = new File(directory.getPath() + "/" + file);

View File

@ -255,6 +255,7 @@ public class XcpServerDiscoverer extends DiscovererBase implements Discoverer, L
try { try {
Session.logout(conn); Session.logout(conn);
} catch (Exception e) { } catch (Exception e) {
s_logger.debug("Caught exception during logout", e);
} }
conn.dispose(); conn.dispose();
conn = null; conn = null;

View File

@ -21,6 +21,8 @@ import java.io.FileInputStream;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
import java.io.IOException; import java.io.IOException;
import java.net.URL; import java.net.URL;
import java.security.KeyManagementException;
import java.security.NoSuchAlgorithmException;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.Properties; import java.util.Properties;
@ -90,7 +92,10 @@ public class XenServerConnectionPool {
} }
}; };
HttpsURLConnection.setDefaultHostnameVerifier(hv); HttpsURLConnection.setDefaultHostnameVerifier(hv);
} catch (Exception e) { } catch (NoSuchAlgorithmException e) {
//ignore this
} catch (KeyManagementException e) {
s_logger.debug("Init SSLContext failed ", e);
} }
} }
@ -228,6 +233,7 @@ public class XenServerConnectionPool {
try{ try{
Session.logout(conn); Session.logout(conn);
} catch (Exception e) { } catch (Exception e) {
s_logger.debug("Caught exception during logout", e);
} }
conn.dispose(); conn.dispose();
} }

View File

@ -982,7 +982,7 @@ public class XenServerStorageProcessor implements StorageProcessor {
try { try {
Thread.sleep(5000); Thread.sleep(5000);
} catch (Exception e) { } catch (InterruptedException e) {
} }
TemplateObjectTO newVol = new TemplateObjectTO(); TemplateObjectTO newVol = new TemplateObjectTO();

View File

@ -137,7 +137,10 @@ public class SolidFirePrimaryDataStoreLifeCycle implements PrimaryDataStoreLifeC
if (clusterDefaultMinIops != null && clusterDefaultMinIops.trim().length() > 0) { if (clusterDefaultMinIops != null && clusterDefaultMinIops.trim().length() > 0) {
lClusterDefaultMinIops = Long.parseLong(clusterDefaultMinIops); lClusterDefaultMinIops = Long.parseLong(clusterDefaultMinIops);
} }
} catch (Exception ex) { } catch (NumberFormatException ex) {
s_logger.warn("Cannot parse the setting of " + SolidFireUtil.CLUSTER_DEFAULT_MIN_IOPS +
", using default value: " + lClusterDefaultMinIops +
". Exception: " + ex);
} }
try { try {
@ -146,7 +149,10 @@ public class SolidFirePrimaryDataStoreLifeCycle implements PrimaryDataStoreLifeC
if (clusterDefaultMaxIops != null && clusterDefaultMaxIops.trim().length() > 0) { if (clusterDefaultMaxIops != null && clusterDefaultMaxIops.trim().length() > 0) {
lClusterDefaultMaxIops = Long.parseLong(clusterDefaultMaxIops); lClusterDefaultMaxIops = Long.parseLong(clusterDefaultMaxIops);
} }
} catch (Exception ex) { } catch (NumberFormatException ex) {
s_logger.warn("Cannot parse the setting of " + SolidFireUtil.CLUSTER_DEFAULT_MAX_IOPS +
", using default value: " + lClusterDefaultMaxIops +
". Exception: " + ex);
} }
try { try {
@ -155,7 +161,10 @@ public class SolidFirePrimaryDataStoreLifeCycle implements PrimaryDataStoreLifeC
if (clusterDefaultBurstIopsPercentOfMaxIops != null && clusterDefaultBurstIopsPercentOfMaxIops.trim().length() > 0) { if (clusterDefaultBurstIopsPercentOfMaxIops != null && clusterDefaultBurstIopsPercentOfMaxIops.trim().length() > 0) {
fClusterDefaultBurstIopsPercentOfMaxIops = Float.parseFloat(clusterDefaultBurstIopsPercentOfMaxIops); fClusterDefaultBurstIopsPercentOfMaxIops = Float.parseFloat(clusterDefaultBurstIopsPercentOfMaxIops);
} }
} catch (Exception ex) { } catch (NumberFormatException ex) {
s_logger.warn("Cannot parse the setting of " + SolidFireUtil.CLUSTER_DEFAULT_BURST_IOPS_PERCENT_OF_MAX_IOPS +
", using default value: " + fClusterDefaultBurstIopsPercentOfMaxIops +
". Exception: " + ex);
} }
if (lClusterDefaultMinIops > lClusterDefaultMaxIops) { if (lClusterDefaultMinIops > lClusterDefaultMaxIops) {

View File

@ -1591,6 +1591,7 @@ public class ResourceManagerImpl extends ManagerBase implements ResourceManager,
dcId = Long.parseLong(dataCenter); dcId = Long.parseLong(dataCenter);
dc = _dcDao.findById(dcId); dc = _dcDao.findById(dcId);
} catch (final NumberFormatException e) { } catch (final NumberFormatException e) {
s_logger.debug("Cannot parse " + dataCenter + " into Long.");
} }
} }
if (dc == null) { if (dc == null) {
@ -1604,6 +1605,7 @@ public class ResourceManagerImpl extends ManagerBase implements ResourceManager,
final long podId = Long.parseLong(pod); final long podId = Long.parseLong(pod);
p = _podDao.findById(podId); p = _podDao.findById(podId);
} catch (final NumberFormatException e) { } catch (final NumberFormatException e) {
s_logger.debug("Cannot parse " + pod + " into Long.");
} }
} }
/* /*

View File

@ -464,6 +464,7 @@ public class ConfigurationServerImpl extends ManagerBase implements Configuratio
PreparedStatement stmt = txn.prepareAutoCloseStatement(insertSql); PreparedStatement stmt = txn.prepareAutoCloseStatement(insertSql);
stmt.executeUpdate(); stmt.executeUpdate();
} catch (SQLException ex) { } catch (SQLException ex) {
s_logger.debug("Caught SQLException when inserting system account ", ex);
} }
// insert system user // insert system user
insertSql = "INSERT INTO `cloud`.`user` (id, uuid, username, password, account_id, firstname, lastname, created, user.default)" insertSql = "INSERT INTO `cloud`.`user` (id, uuid, username, password, account_id, firstname, lastname, created, user.default)"
@ -473,6 +474,7 @@ public class ConfigurationServerImpl extends ManagerBase implements Configuratio
PreparedStatement stmt = txn.prepareAutoCloseStatement(insertSql); PreparedStatement stmt = txn.prepareAutoCloseStatement(insertSql);
stmt.executeUpdate(); stmt.executeUpdate();
} catch (SQLException ex) { } catch (SQLException ex) {
s_logger.debug("Caught SQLException when inserting system user ", ex);
} }
// insert admin user, but leave the account disabled until we set a // insert admin user, but leave the account disabled until we set a
@ -489,6 +491,7 @@ public class ConfigurationServerImpl extends ManagerBase implements Configuratio
PreparedStatement stmt = txn.prepareAutoCloseStatement(insertSql); PreparedStatement stmt = txn.prepareAutoCloseStatement(insertSql);
stmt.executeUpdate(); stmt.executeUpdate();
} catch (SQLException ex) { } catch (SQLException ex) {
s_logger.debug("Caught SQLException when creating admin account ", ex);
} }
// now insert the user // now insert the user
@ -499,6 +502,7 @@ public class ConfigurationServerImpl extends ManagerBase implements Configuratio
PreparedStatement stmt = txn.prepareAutoCloseStatement(insertSql); PreparedStatement stmt = txn.prepareAutoCloseStatement(insertSql);
stmt.executeUpdate(); stmt.executeUpdate();
} catch (SQLException ex) { } catch (SQLException ex) {
s_logger.debug("Caught SQLException when inserting user ", ex);
} }
try { try {
@ -508,8 +512,9 @@ public class ConfigurationServerImpl extends ManagerBase implements Configuratio
PreparedStatement stmt = txn.prepareAutoCloseStatement(checkSql); PreparedStatement stmt = txn.prepareAutoCloseStatement(checkSql);
stmt.executeQuery(); stmt.executeQuery();
tableName = "network_group"; tableName = "network_group";
} catch (Exception ex) { } catch (SQLException ex) {
// if network_groups table exists, create the default security group there // if network_groups table exists, create the default security group there
s_logger.debug("Caught SQLException: no network_group ", ex);
} }
insertSql = "SELECT * FROM " + tableName + " where account_id=2 and name='default'"; insertSql = "SELECT * FROM " + tableName + " where account_id=2 and name='default'";

View File

@ -77,6 +77,7 @@ public class ConsoleProxyThumbnailHandler implements HttpHandler {
width = Integer.parseInt(ws); width = Integer.parseInt(ws);
height = Integer.parseInt(hs); height = Integer.parseInt(hs);
} catch (NumberFormatException ex) { } catch (NumberFormatException ex) {
s_logger.debug("Cannot parse width: " + ws + " or height: " + hs, ex);
} }
width = Math.min(width, 800); width = Math.min(width, 800);
height = Math.min(height, 600); height = Math.min(height, 600);

View File

@ -20,6 +20,7 @@
package com.cloud.utils.net; package com.cloud.utils.net;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.lang.reflect.Array; import java.lang.reflect.Array;
import java.math.BigInteger; import java.math.BigInteger;
@ -172,7 +173,8 @@ public class NetUtils {
} }
line = output.readLine(); line = output.readLine();
} }
} catch (Exception e) { } catch (IOException e) {
s_logger.debug("Caught IOException", e);
} }
return null; return null;
} else { } else {
@ -425,7 +427,8 @@ public class NetUtils {
try { try {
byte[] mac = nic.getHardwareAddress(); byte[] mac = nic.getHardwareAddress();
result[1] = byte2Mac(mac); result[1] = byte2Mac(mac);
} catch (Exception e) { } catch (SocketException e) {
s_logger.debug("Caught exception when trying to get the mac address ", e);
} }
result[2] = prefix2Netmask(addr.getNetworkPrefixLength()); result[2] = prefix2Netmask(addr.getNetworkPrefixLength());