You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by ja...@apache.org on 2014/08/26 14:22:54 UTC
git commit: updated refs/heads/master to cae4124
Repository: cloudstack
Updated Branches:
refs/heads/master 9fb2a760c -> cae4124dc
Fixed few coverity issues
Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/cae4124d
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/cae4124d
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/cae4124d
Branch: refs/heads/master
Commit: cae4124dc66a6d7b962f5d57dfe3afb861dacbc4
Parents: 9fb2a76
Author: Jayapal <ja...@apache.org>
Authored: Wed Aug 20 16:03:10 2014 +0530
Committer: Jayapal <ja...@apache.org>
Committed: Tue Aug 26 17:51:28 2014 +0530
----------------------------------------------------------------------
.../firewall/CreateEgressFirewallRuleCmd.java | 6 +-
.../firewall/ListEgressFirewallRulesCmd.java | 12 +-
.../api/command/user/vm/ListNicsCmd.java | 14 +-
.../com/cloud/upgrade/dao/Upgrade40to41.java | 138 +++++++++++--------
4 files changed, 100 insertions(+), 70 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/cae4124d/api/src/org/apache/cloudstack/api/command/user/firewall/CreateEgressFirewallRuleCmd.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/command/user/firewall/CreateEgressFirewallRuleCmd.java b/api/src/org/apache/cloudstack/api/command/user/firewall/CreateEgressFirewallRuleCmd.java
index 48ee0df..59af693 100644
--- a/api/src/org/apache/cloudstack/api/command/user/firewall/CreateEgressFirewallRuleCmd.java
+++ b/api/src/org/apache/cloudstack/api/command/user/firewall/CreateEgressFirewallRuleCmd.java
@@ -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);
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/cae4124d/api/src/org/apache/cloudstack/api/command/user/firewall/ListEgressFirewallRulesCmd.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/command/user/firewall/ListEgressFirewallRulesCmd.java b/api/src/org/apache/cloudstack/api/command/user/firewall/ListEgressFirewallRulesCmd.java
index e31496e..9e16325 100644
--- a/api/src/org/apache/cloudstack/api/command/user/firewall/ListEgressFirewallRulesCmd.java
+++ b/api/src/org/apache/cloudstack/api/command/user/firewall/ListEgressFirewallRulesCmd.java
@@ -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);
}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/cae4124d/api/src/org/apache/cloudstack/api/command/user/vm/ListNicsCmd.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/command/user/vm/ListNicsCmd.java b/api/src/org/apache/cloudstack/api/command/user/vm/ListNicsCmd.java
index 49402dc..ccec3e6 100644
--- a/api/src/org/apache/cloudstack/api/command/user/vm/ListNicsCmd.java
+++ b/api/src/org/apache/cloudstack/api/command/user/vm/ListNicsCmd.java
@@ -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());
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/cae4124d/engine/schema/src/com/cloud/upgrade/dao/Upgrade40to41.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/upgrade/dao/Upgrade40to41.java b/engine/schema/src/com/cloud/upgrade/dao/Upgrade40to41.java
index 77e2a6f..29bd67e 100644
--- a/engine/schema/src/com/cloud/upgrade/dao/Upgrade40to41.java
+++ b/engine/schema/src/com/cloud/upgrade/dao/Upgrade40to41.java
@@ -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();
-
- if (rsNw.next()) {
- long accountId = rsNw.getLong(1);
- long domainId = rsNw.getLong(2);
-
- //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();
-
- pstmt = conn.prepareStatement("select id from firewall_rules where protocol='all' and network_id=?");
- pstmt.setLong(1, netId);
- rsId = pstmt.executeQuery();
-
- 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 (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);
+
+ try (ResultSet NwAcctDomIdps = NwAcctDomIdpstmt.executeQuery();) {
+ s_logger.debug("Getting account_id, domain_id from networks table: " + NwAcctDomIdpstmt);
+
+ 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);
+ }
+
+ try (PreparedStatement protoAllpstmt = conn.prepareStatement("select id from firewall_rules where protocol='all' and network_id=?");)
+ {
+ protoAllpstmt.setLong(1, netId);
+
+ 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) {
- }
+
}
}
}
+