mirror of https://github.com/apache/cloudstack.git
Fixed few coverity issues
This commit is contained in:
parent
9fb2a760c6
commit
cae4124dc6
|
|
@ -260,8 +260,10 @@ public class CreateEgressFirewallRuleCmd extends BaseAsyncCreateCmd implements F
|
|||
|
||||
try {
|
||||
FirewallRule result = _firewallService.createEgressFirewallRule(this);
|
||||
setEntityId(result.getId());
|
||||
setEntityUuid(result.getUuid());
|
||||
if (result != null) {
|
||||
setEntityId(result.getId());
|
||||
setEntityUuid(result.getUuid());
|
||||
}
|
||||
} catch (NetworkRuleConflictException ex) {
|
||||
s_logger.info("Network rule conflict: " + ex.getMessage());
|
||||
s_logger.trace("Network Rule Conflict: ", ex);
|
||||
|
|
|
|||
|
|
@ -85,12 +85,14 @@ public class ListEgressFirewallRulesCmd extends ListFirewallRulesCmd {
|
|||
ListResponse<FirewallResponse> response = new ListResponse<FirewallResponse>();
|
||||
List<FirewallResponse> fwResponses = new ArrayList<FirewallResponse>();
|
||||
|
||||
for (FirewallRule fwRule : result.first()) {
|
||||
FirewallResponse ruleData = _responseGenerator.createFirewallResponse(fwRule);
|
||||
ruleData.setObjectName("firewallrule");
|
||||
fwResponses.add(ruleData);
|
||||
if (result != null) {
|
||||
for (FirewallRule fwRule : result.first()) {
|
||||
FirewallResponse ruleData = _responseGenerator.createFirewallResponse(fwRule);
|
||||
ruleData.setObjectName("firewallrule");
|
||||
fwResponses.add(ruleData);
|
||||
}
|
||||
response.setResponses(fwResponses, result.second());
|
||||
}
|
||||
response.setResponses(fwResponses, result.second());
|
||||
response.setResponseName(getCommandName());
|
||||
setResponseObject(response);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -124,11 +124,15 @@ public class ListNicsCmd extends BaseListCmd {
|
|||
try {
|
||||
List<? extends Nic> results = _networkService.listNics(this);
|
||||
ListResponse<NicResponse> response = new ListResponse<NicResponse>();
|
||||
List<NicResponse> resList = new ArrayList<NicResponse>(results.size());
|
||||
for (Nic r : results) {
|
||||
NicResponse resp = _responseGenerator.createNicResponse(r);
|
||||
resp.setObjectName("nic");
|
||||
resList.add(resp);
|
||||
List<NicResponse> resList = null;
|
||||
if (results != null) {
|
||||
resList = new ArrayList<NicResponse>(results.size());
|
||||
for (Nic r : results) {
|
||||
NicResponse resp = _responseGenerator.createNicResponse(r);
|
||||
resp.setObjectName("nic");
|
||||
resList.add(resp);
|
||||
}
|
||||
response.setResponses(resList);
|
||||
}
|
||||
response.setResponses(resList);
|
||||
response.setResponseName(getCommandName());
|
||||
|
|
|
|||
|
|
@ -103,72 +103,94 @@ public class Upgrade40to41 implements DbUpgrade {
|
|||
}
|
||||
|
||||
private void upgradeEgressFirewallRules(Connection conn) {
|
||||
PreparedStatement pstmt = null;
|
||||
ResultSet rs = null;
|
||||
ResultSet rsId = null;
|
||||
ResultSet rsNw = null;
|
||||
try {
|
||||
// update the existing ingress rules traffic type
|
||||
pstmt = conn.prepareStatement("update `cloud`.`firewall_rules` set traffic_type='Ingress' where purpose='Firewall' and ip_address_id is " +
|
||||
"not null and traffic_type is null");
|
||||
s_logger.debug("Updating firewall Ingress rule traffic type: " + pstmt);
|
||||
pstmt.executeUpdate();
|
||||
|
||||
pstmt = conn.prepareStatement("select network_id FROM `cloud`.`ntwk_service_map` where service='Firewall' and provider='VirtualRouter' ");
|
||||
rs = pstmt.executeQuery();
|
||||
while (rs.next()) {
|
||||
long netId = rs.getLong(1);
|
||||
// update the existing ingress rules traffic type
|
||||
try (PreparedStatement updateNwpstmt = conn.prepareStatement("update `cloud`.`firewall_rules` set traffic_type='Ingress' where purpose='Firewall' and ip_address_id is " +
|
||||
"not null and traffic_type is null");)
|
||||
{
|
||||
updateNwpstmt.executeUpdate();
|
||||
s_logger.debug("Updating firewall Ingress rule traffic type: " + updateNwpstmt);
|
||||
} catch (SQLException e) {
|
||||
throw new CloudRuntimeException("Unable to update ingress firewall rules ", e);
|
||||
}
|
||||
|
||||
|
||||
try (PreparedStatement vrNwpstmt = conn.prepareStatement("select network_id FROM `cloud`.`ntwk_service_map` where service='Firewall' and provider='VirtualRouter' ");
|
||||
ResultSet vrNwsRs = vrNwpstmt.executeQuery();
|
||||
) {
|
||||
while (vrNwsRs.next()) {
|
||||
long netId = vrNwsRs.getLong(1);
|
||||
//When upgraded from 2.2.14 to 3.0.6 guest_type is updated to Isolated in the 2214to30 clean up sql. clean up executes
|
||||
//after this. So checking for Isolated OR Virtual
|
||||
pstmt = conn.prepareStatement("select account_id, domain_id FROM `cloud`.`networks` where (guest_type='Isolated' OR " +
|
||||
"guest_type='Virtual') and traffic_type='Guest' and vpc_id is NULL and " +
|
||||
"(state='implemented' OR state='Shutdown') and id=? ");
|
||||
pstmt.setLong(1, netId);
|
||||
s_logger.debug("Getting account_id, domain_id from networks table: " + pstmt);
|
||||
rsNw = pstmt.executeQuery();
|
||||
try (PreparedStatement NwAcctDomIdpstmt = conn.prepareStatement("select account_id, domain_id FROM `cloud`.`networks` where (guest_type='Isolated' OR " +
|
||||
"guest_type='Virtual') and traffic_type='Guest' and vpc_id is NULL and " +
|
||||
"(state='implemented' OR state='Shutdown') and id=? "); ) {
|
||||
NwAcctDomIdpstmt.setLong(1, netId);
|
||||
|
||||
if (rsNw.next()) {
|
||||
long accountId = rsNw.getLong(1);
|
||||
long domainId = rsNw.getLong(2);
|
||||
try (ResultSet NwAcctDomIdps = NwAcctDomIdpstmt.executeQuery();) {
|
||||
s_logger.debug("Getting account_id, domain_id from networks table: " + NwAcctDomIdpstmt);
|
||||
|
||||
//Add new rule for the existing networks
|
||||
s_logger.debug("Adding default egress firewall rule for network " + netId);
|
||||
pstmt = conn.prepareStatement("INSERT INTO firewall_rules (uuid, state, protocol, purpose, account_id, domain_id, network_id, xid, created, traffic_type) VALUES (?, 'Active', 'all', 'Firewall', ?, ?, ?, ?, now(), 'Egress')");
|
||||
pstmt.setString(1, UUID.randomUUID().toString());
|
||||
pstmt.setLong(2, accountId);
|
||||
pstmt.setLong(3, domainId);
|
||||
pstmt.setLong(4, netId);
|
||||
pstmt.setString(5, UUID.randomUUID().toString());
|
||||
s_logger.debug("Inserting default egress firewall rule " + pstmt);
|
||||
pstmt.executeUpdate();
|
||||
if (NwAcctDomIdps.next()) {
|
||||
long accountId = NwAcctDomIdps.getLong(1);
|
||||
long domainId = NwAcctDomIdps.getLong(2);
|
||||
//Add new rule for the existing networks
|
||||
s_logger.debug("Adding default egress firewall rule for network " + netId);
|
||||
try (PreparedStatement fwRulespstmt = conn.prepareStatement("INSERT INTO firewall_rules "+
|
||||
" (uuid, state, protocol, purpose, account_id, domain_id, network_id, xid, created,"
|
||||
+ " traffic_type) VALUES (?, 'Active', 'all', 'Firewall', ?, ?, ?, ?, now(), "
|
||||
+"'Egress')");
|
||||
) {
|
||||
fwRulespstmt.setString(1, UUID.randomUUID().toString());
|
||||
fwRulespstmt.setLong(2, accountId);
|
||||
fwRulespstmt.setLong(3, domainId);
|
||||
fwRulespstmt.setLong(4, netId);
|
||||
fwRulespstmt.setString(5, UUID.randomUUID().toString());
|
||||
s_logger.debug("Inserting default egress firewall rule " + fwRulespstmt);
|
||||
fwRulespstmt.executeUpdate();
|
||||
} catch (SQLException e) {
|
||||
throw new CloudRuntimeException("failed to insert default egress firewall rule ", e);
|
||||
}
|
||||
|
||||
pstmt = conn.prepareStatement("select id from firewall_rules where protocol='all' and network_id=?");
|
||||
pstmt.setLong(1, netId);
|
||||
rsId = pstmt.executeQuery();
|
||||
try (PreparedStatement protoAllpstmt = conn.prepareStatement("select id from firewall_rules where protocol='all' and network_id=?");)
|
||||
{
|
||||
protoAllpstmt.setLong(1, netId);
|
||||
|
||||
long firewallRuleId;
|
||||
if (rsId.next()) {
|
||||
firewallRuleId = rsId.getLong(1);
|
||||
pstmt = conn.prepareStatement("insert into firewall_rules_cidrs (firewall_rule_id,source_cidr) values (?, '0.0.0.0/0')");
|
||||
pstmt.setLong(1, firewallRuleId);
|
||||
s_logger.debug("Inserting rule for cidr 0.0.0.0/0 for the new Firewall rule id=" + firewallRuleId + " with statement " + pstmt);
|
||||
pstmt.executeUpdate();
|
||||
try (ResultSet protoAllRs = protoAllpstmt.executeQuery();) {
|
||||
long firewallRuleId;
|
||||
if (protoAllRs.next()) {
|
||||
firewallRuleId = protoAllRs.getLong(1);
|
||||
|
||||
try (PreparedStatement fwCidrsPstmt = conn.prepareStatement("insert into firewall_rules_cidrs (firewall_rule_id,source_cidr) values (?, '0.0.0.0/0')");) {
|
||||
fwCidrsPstmt.setLong(1, firewallRuleId);
|
||||
s_logger.debug("Inserting rule for cidr 0.0.0.0/0 for the new Firewall rule id=" + firewallRuleId + " with statement " + fwCidrsPstmt);
|
||||
fwCidrsPstmt.executeUpdate();
|
||||
} catch (SQLException e) {
|
||||
throw new CloudRuntimeException("Unable to set egress firewall rules ", e);
|
||||
}
|
||||
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
throw new CloudRuntimeException("Unable to set egress firewall rules ", e);
|
||||
}
|
||||
|
||||
} catch (SQLException e) {
|
||||
throw new CloudRuntimeException("Unable to set egress firewall rules ", e);
|
||||
}
|
||||
|
||||
} //if
|
||||
} catch (SQLException e) {
|
||||
throw new CloudRuntimeException("Unable execute update query ", e);
|
||||
}
|
||||
|
||||
} catch (SQLException e) {
|
||||
throw new CloudRuntimeException("Unable to get account id domainid of networks ", e);
|
||||
}
|
||||
}
|
||||
} //while
|
||||
} catch (SQLException e) {
|
||||
throw new CloudRuntimeException("Unable to set egress firewall rules ", e);
|
||||
} finally {
|
||||
try {
|
||||
if (rs != null) {
|
||||
rs.close();
|
||||
}
|
||||
if (pstmt != null) {
|
||||
pstmt.close();
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue