diff --git a/api/src/org/apache/cloudstack/api/command/admin/network/UpdatePhysicalNetworkCmd.java b/api/src/org/apache/cloudstack/api/command/admin/network/UpdatePhysicalNetworkCmd.java index 8e29c393813..ed3fa97ce7a 100644 --- a/api/src/org/apache/cloudstack/api/command/admin/network/UpdatePhysicalNetworkCmd.java +++ b/api/src/org/apache/cloudstack/api/command/admin/network/UpdatePhysicalNetworkCmd.java @@ -97,9 +97,11 @@ public class UpdatePhysicalNetworkCmd extends BaseAsyncCmd { @Override public void execute() { PhysicalNetwork result = _networkService.updatePhysicalNetwork(getId(), getNetworkSpeed(), getTags(), getVlan(), getState()); - PhysicalNetworkResponse response = _responseGenerator.createPhysicalNetworkResponse(result); - response.setResponseName(getCommandName()); - this.setResponseObject(response); + if (result != null) { + PhysicalNetworkResponse response = _responseGenerator.createPhysicalNetworkResponse(result); + response.setResponseName(getCommandName()); + this.setResponseObject(response); + } } @Override diff --git a/api/src/org/apache/cloudstack/api/command/user/firewall/DeleteFirewallRuleCmd.java b/api/src/org/apache/cloudstack/api/command/user/firewall/DeleteFirewallRuleCmd.java index f8d1c18329a..0f100124610 100644 --- a/api/src/org/apache/cloudstack/api/command/user/firewall/DeleteFirewallRuleCmd.java +++ b/api/src/org/apache/cloudstack/api/command/user/firewall/DeleteFirewallRuleCmd.java @@ -113,7 +113,10 @@ public class DeleteFirewallRuleCmd extends BaseAsyncCmd { @Override public Long getSyncObjId() { - return _firewallService.getFirewallRule(id).getNetworkId(); + FirewallRule fwlrule = _firewallService.getFirewallRule(id); + if (fwlrule != null) + return fwlrule.getNetworkId(); + return null; } @Override diff --git a/api/src/org/apache/cloudstack/api/command/user/vpn/UpdateVpnGatewayCmd.java b/api/src/org/apache/cloudstack/api/command/user/vpn/UpdateVpnGatewayCmd.java index 66c59ad9f1b..bbe820a83c4 100644 --- a/api/src/org/apache/cloudstack/api/command/user/vpn/UpdateVpnGatewayCmd.java +++ b/api/src/org/apache/cloudstack/api/command/user/vpn/UpdateVpnGatewayCmd.java @@ -85,8 +85,10 @@ public class UpdateVpnGatewayCmd extends BaseAsyncCustomIdCmd { @Override public void execute() { Site2SiteVpnGateway result = _s2sVpnService.updateVpnGateway(id, this.getCustomId(), getDisplay()); - Site2SiteVpnGatewayResponse response = _responseGenerator.createSite2SiteVpnGatewayResponse(result); - response.setResponseName(getCommandName()); + if (result != null) { + Site2SiteVpnGatewayResponse response = _responseGenerator.createSite2SiteVpnGatewayResponse(result); + response.setResponseName(getCommandName()); + } } @Override diff --git a/engine/orchestration/src/com/cloud/agent/manager/ClusteredAgentManagerImpl.java b/engine/orchestration/src/com/cloud/agent/manager/ClusteredAgentManagerImpl.java index 93d675fa999..4045feda8ff 100755 --- a/engine/orchestration/src/com/cloud/agent/manager/ClusteredAgentManagerImpl.java +++ b/engine/orchestration/src/com/cloud/agent/manager/ClusteredAgentManagerImpl.java @@ -194,35 +194,36 @@ public class ClusteredAgentManagerImpl extends AgentManagerImpl implements Clust long cutSeconds = (System.currentTimeMillis() >> 10) - getTimeout(); List hosts = _hostDao.findAndUpdateDirectAgentToLoad(cutSeconds, LoadSize.value().longValue(), _nodeId); List appliances = _hostDao.findAndUpdateApplianceToLoad(cutSeconds, _nodeId); - hosts.addAll(appliances); - if (hosts != null && hosts.size() > 0) { - s_logger.debug("Found " + hosts.size() + " unmanaged direct hosts, processing connect for them..."); - for (HostVO host : hosts) { - try { - AgentAttache agentattache = findAttache(host.getId()); - if (agentattache != null) { - // already loaded, skip - if (agentattache.forForward()) { - if (s_logger.isInfoEnabled()) { - s_logger.info(host + " is detected down, but we have a forward attache running, disconnect this one before launching the host"); + if (hosts != null) { + hosts.addAll(appliances); + if (hosts.size() > 0) { + s_logger.debug("Found " + hosts.size() + " unmanaged direct hosts, processing connect for them..."); + for (HostVO host : hosts) { + try { + AgentAttache agentattache = findAttache(host.getId()); + if (agentattache != null) { + // already loaded, skip + if (agentattache.forForward()) { + if (s_logger.isInfoEnabled()) { + s_logger.info(host + " is detected down, but we have a forward attache running, disconnect this one before launching the host"); + } + removeAgent(agentattache, Status.Disconnected); + } else { + continue; } - removeAgent(agentattache, Status.Disconnected); - } else { - continue; } - } - if (s_logger.isDebugEnabled()) { - s_logger.debug("Loading directly connected host " + host.getId() + "(" + host.getName() + ")"); + if (s_logger.isDebugEnabled()) { + s_logger.debug("Loading directly connected host " + host.getId() + "(" + host.getName() + ")"); + } + loadDirectlyConnectedHost(host, false); + } catch (Throwable e) { + s_logger.warn(" can not load directly connected host " + host.getId() + "(" + host.getName() + ") due to ", e); } - loadDirectlyConnectedHost(host, false); - } catch (Throwable e) { - s_logger.warn(" can not load directly connected host " + host.getId() + "(" + host.getName() + ") due to ", e); } } } - if (s_logger.isTraceEnabled()) { s_logger.trace("End scanning directly connected hosts"); } diff --git a/framework/db/src/com/cloud/utils/db/GenericDaoBase.java b/framework/db/src/com/cloud/utils/db/GenericDaoBase.java index 4c474044380..e75646a79fa 100755 --- a/framework/db/src/com/cloud/utils/db/GenericDaoBase.java +++ b/framework/db/src/com/cloud/utils/db/GenericDaoBase.java @@ -1641,81 +1641,71 @@ public abstract class GenericDaoBase extends Compone @SuppressWarnings("unchecked") protected void loadCollection(T entity, Attribute attr) { EcInfo ec = (EcInfo)attr.attache; - TransactionLegacy txn = TransactionLegacy.currentTxn(); - ResultSet rs = null; - PreparedStatement pstmt = null; - try { - pstmt = txn.prepareStatement(ec.selectSql); + try(PreparedStatement pstmt = txn.prepareStatement(ec.selectSql);) + { pstmt.setObject(1, _idField.get(entity)); - rs = pstmt.executeQuery(); - ArrayList lst = new ArrayList(); - if (ec.targetClass == Integer.class) { - while (rs.next()) { - lst.add(rs.getInt(1)); + try(ResultSet rs = pstmt.executeQuery();) + { + ArrayList lst = new ArrayList(); + if (ec.targetClass == Integer.class) { + while (rs.next()) { + lst.add(rs.getInt(1)); + } + } else if (ec.targetClass == Long.class) { + while (rs.next()) { + lst.add(rs.getLong(1)); + } + } else if (ec.targetClass == String.class) { + while (rs.next()) { + lst.add(rs.getString(1)); + } + } else if (ec.targetClass == Short.class) { + while (rs.next()) { + lst.add(rs.getShort(1)); + } + } else if (ec.targetClass == Date.class) { + while (rs.next()) { + lst.add(DateUtil.parseDateString(s_gmtTimeZone, rs.getString(1))); + } + } else if (ec.targetClass == Boolean.class) { + while (rs.next()) { + lst.add(rs.getBoolean(1)); + } + } else { + assert (false) : "You'll need to add more classeses"; } - } else if (ec.targetClass == Long.class) { - while (rs.next()) { - lst.add(rs.getLong(1)); + if (ec.rawClass == null) { + Object[] array = (Object[]) Array.newInstance(ec.targetClass); + lst.toArray(array); + try { + attr.field.set(entity, array); + } catch (IllegalArgumentException e) { + throw new CloudRuntimeException("Come on we screen for this stuff, don't we?", e); + } catch (IllegalAccessException e) { + throw new CloudRuntimeException("Come on we screen for this stuff, don't we?", e); + } + } else { + try { + Collection coll = (Collection) ec.rawClass.newInstance(); + coll.addAll(lst); + attr.field.set(entity, coll); + } catch (IllegalAccessException e) { + throw new CloudRuntimeException("Come on we screen for this stuff, don't we?", e); + } catch (InstantiationException e) { + throw new CloudRuntimeException("Never should happen", e); + } } - } else if (ec.targetClass == String.class) { - while (rs.next()) { - lst.add(rs.getString(1)); - } - } else if (ec.targetClass == Short.class) { - while (rs.next()) { - lst.add(rs.getShort(1)); - } - } else if (ec.targetClass == Date.class) { - while (rs.next()) { - lst.add(DateUtil.parseDateString(s_gmtTimeZone, rs.getString(1))); - } - } else if (ec.targetClass == Boolean.class) { - while (rs.next()) { - lst.add(rs.getBoolean(1)); - } - } else { - assert (false) : "You'll need to add more classeses"; } - - if (ec.rawClass == null) { - Object[] array = (Object[])Array.newInstance(ec.targetClass); - lst.toArray(array); - try { - attr.field.set(entity, array); - } catch (IllegalArgumentException e) { - throw new CloudRuntimeException("Come on we screen for this stuff, don't we?", e); - } catch (IllegalAccessException e) { - throw new CloudRuntimeException("Come on we screen for this stuff, don't we?", e); - } - } else { - try { - Collection coll = (Collection)ec.rawClass.newInstance(); - coll.addAll(lst); - attr.field.set(entity, coll); - } catch (IllegalAccessException e) { - throw new CloudRuntimeException("Come on we screen for this stuff, don't we?", e); - } catch (InstantiationException e) { - throw new CloudRuntimeException("Never should happen", e); - } + catch (SQLException e) { + throw new CloudRuntimeException("loadCollection: Exception : " +e.getMessage(), e); } } catch (SQLException e) { - throw new CloudRuntimeException("Error executing " + pstmt, e); + throw new CloudRuntimeException("loadCollection: Exception : " +e.getMessage(), e); } catch (IllegalArgumentException e) { - throw new CloudRuntimeException("Error executing " + pstmt, e); + throw new CloudRuntimeException("loadCollection: Exception : " +e.getMessage(), e); } catch (IllegalAccessException e) { - throw new CloudRuntimeException("Error executing " + pstmt, e); - } finally { - try { - if (rs != null) { - rs.close(); - } - if (pstmt != null) { - pstmt.close(); - } - } catch (SQLException e) { - s_logger.error("Why are we getting an exception at close? ", e); - } + throw new CloudRuntimeException("loadCollection: Exception : " +e.getMessage(), e); } } diff --git a/plugins/api/discovery/test/org/apache/cloudstack/discovery/ApiDiscoveryTest.java b/plugins/api/discovery/test/org/apache/cloudstack/discovery/ApiDiscoveryTest.java index 30cb0bc87ae..49bf5a55dc5 100644 --- a/plugins/api/discovery/test/org/apache/cloudstack/discovery/ApiDiscoveryTest.java +++ b/plugins/api/discovery/test/org/apache/cloudstack/discovery/ApiDiscoveryTest.java @@ -82,21 +82,25 @@ public class ApiDiscoveryTest { @Test public void verifyListSingleApi() throws Exception { ListResponse responses = (ListResponse)s_discoveryService.listApis(testUser, testApiName); - ApiDiscoveryResponse response = responses.getResponses().get(0); - assertTrue("No. of response items should be one", responses.getCount() == 1); - assertEquals("Error in api name", testApiName, response.getName()); - assertEquals("Error in api description", testApiDescription, response.getDescription()); - assertEquals("Error in api since", testApiSince, response.getSince()); - assertEquals("Error in api isAsync", testApiAsync, response.getAsync()); + if (responses != null) { + ApiDiscoveryResponse response = responses.getResponses().get(0); + assertTrue("No. of response items should be one", responses.getCount() == 1); + assertEquals("Error in api name", testApiName, response.getName()); + assertEquals("Error in api description", testApiDescription, response.getDescription()); + assertEquals("Error in api since", testApiSince, response.getSince()); + assertEquals("Error in api isAsync", testApiAsync, response.getAsync()); + } } @Test public void verifyListApis() throws Exception { ListResponse responses = (ListResponse)s_discoveryService.listApis(testUser, null); - assertTrue("No. of response items > 1", responses.getCount() == 1); - for (ApiDiscoveryResponse response : responses.getResponses()) { - assertFalse("API name is empty", response.getName().isEmpty()); - assertFalse("API description is empty", response.getDescription().isEmpty()); + if (responses != null) { + assertTrue("No. of response items > 1", responses.getCount().intValue() == 1); + for (ApiDiscoveryResponse response : responses.getResponses()) { + assertFalse("API name is empty", response.getName().isEmpty()); + assertFalse("API description is empty", response.getDescription().isEmpty()); + } } } } diff --git a/plugins/network-elements/nuage-vsp/src/com/cloud/network/element/NuageVspElement.java b/plugins/network-elements/nuage-vsp/src/com/cloud/network/element/NuageVspElement.java index 06f9733fc0e..e777268e424 100644 --- a/plugins/network-elements/nuage-vsp/src/com/cloud/network/element/NuageVspElement.java +++ b/plugins/network-elements/nuage-vsp/src/com/cloud/network/element/NuageVspElement.java @@ -405,13 +405,15 @@ public class NuageVspElement extends AdapterBase implements ConnectivityProvider @Override public boolean applyNetworkACLs(Network network, List rules) throws ResourceUnavailableException { - s_logger.debug("Handling applyNetworkACLs for network " + network.getName() + " with " + rules.size() + " Network ACLs"); if (rules == null || rules.isEmpty()) { s_logger.debug("No rules to apply. So, delete all the existing ACL in VSP from Subnet with uuid " + network.getUuid()); } else { s_logger.debug("New rules has to applied. So, delete all the existing ACL in VSP from Subnet with uuid " + network.getUuid()); } - applyACLRules(network, rules, true); + if (rules != null) { + s_logger.debug("Handling applyNetworkACLs for network " + network.getName() + " with " + rules.size() + " Network ACLs"); + applyACLRules(network, rules, true); + } return true; } diff --git a/utils/src/com/cloud/utils/script/Script.java b/utils/src/com/cloud/utils/script/Script.java index 9713b144851..49734ae808a 100755 --- a/utils/src/com/cloud/utils/script/Script.java +++ b/utils/src/com/cloud/utils/script/Script.java @@ -313,19 +313,19 @@ public class Script implements Callable { @Override public void run() { - done = false; - try { - result = interpreter.interpret(reader); - } catch (IOException ex) { - result = stackTraceAsString(ex); - } catch (Exception ex) { - result = stackTraceAsString(ex); - } finally { - synchronized (this) { - done = true; - notifyAll(); + synchronized(this) { + done = false; + try { + result = interpreter.interpret(reader); + } catch (IOException ex) { + result = stackTraceAsString(ex); + } catch (Exception ex) { + result = stackTraceAsString(ex); + } finally { + done = true; + notifyAll(); + IOUtils.closeQuietly(reader); } - IOUtils.closeQuietly(reader); } }