mirror of
https://github.com/apache/cloudstack.git
synced 2025-11-02 20:02:29 +01:00
Fixed few coverity patches
NPE in delete firewall rules observed, cherry-picking fix from master. (cherry picked from commit 31a42d2b7a5a9d3dbf10dc680d7e8877ed4e40c6) Signed-off-by: Rohit Yadav <rohit.yadav@shapeblue.com>
This commit is contained in:
parent
1bab1d0855
commit
737edd90dc
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
@ -195,35 +195,36 @@ public class ClusteredAgentManagerImpl extends AgentManagerImpl implements Clust
|
||||
long cutSeconds = (System.currentTimeMillis() >> 10) - getTimeout();
|
||||
List<HostVO> hosts = _hostDao.findAndUpdateDirectAgentToLoad(cutSeconds, LoadSize.value().longValue(), _nodeId);
|
||||
List<HostVO> 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");
|
||||
}
|
||||
|
||||
@ -1641,81 +1641,71 @@ public abstract class GenericDaoBase<T, ID extends Serializable> 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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -82,21 +82,25 @@ public class ApiDiscoveryTest {
|
||||
@Test
|
||||
public void verifyListSingleApi() throws Exception {
|
||||
ListResponse<ApiDiscoveryResponse> responses = (ListResponse<ApiDiscoveryResponse>)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<ApiDiscoveryResponse> responses = (ListResponse<ApiDiscoveryResponse>)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());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -405,13 +405,15 @@ public class NuageVspElement extends AdapterBase implements ConnectivityProvider
|
||||
|
||||
@Override
|
||||
public boolean applyNetworkACLs(Network network, List<? extends NetworkACLItem> 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;
|
||||
}
|
||||
|
||||
|
||||
@ -313,19 +313,19 @@ public class Script implements Callable<String> {
|
||||
|
||||
@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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user