From 9a70ee54f064434896569d0c7cee69d8ea936b6e Mon Sep 17 00:00:00 2001 From: Alex Huang Date: Thu, 2 Dec 2010 16:05:01 -0800 Subject: [PATCH] portforwarding is working --- .../commands/CreateIpForwardingRuleCmd.java | 2 +- .../commands/CreatePortForwardingRuleCmd.java | 2 +- .../commands/DeletePortForwardingRuleCmd.java | 3 +- .../commands/ListIpForwardingRulesCmd.java | 3 +- .../com/cloud/network/rules/RulesService.java | 34 ++-- console-proxy/.classpath | 18 +- console-viewer/.classpath | 14 +- core/.classpath | 87 ++++----- .../com/cloud/network/NetworkManagerImpl.java | 4 +- .../network/dao/FirewallRulesDaoImpl.java | 3 +- .../cloud/network/rules/FirewallRuleVO.java | 1 + .../network/rules/PortForwardingRuleVO.java | 2 +- .../cloud/network/rules/RulesManagerImpl.java | 173 +++--------------- .../rules/dao/PortForwardingRulesDao.java | 2 + .../rules/dao/PortForwardingRulesDaoImpl.java | 21 +++ .../com/cloud/utils/db/GenericDaoBase.java | 9 +- .../src/com/cloud/utils/db/SqlGenerator.java | 2 +- 17 files changed, 144 insertions(+), 236 deletions(-) diff --git a/api/src/com/cloud/api/commands/CreateIpForwardingRuleCmd.java b/api/src/com/cloud/api/commands/CreateIpForwardingRuleCmd.java index b6af0dbeef6..75ceff90ac4 100644 --- a/api/src/com/cloud/api/commands/CreateIpForwardingRuleCmd.java +++ b/api/src/com/cloud/api/commands/CreateIpForwardingRuleCmd.java @@ -72,7 +72,7 @@ public class CreateIpForwardingRuleCmd extends BaseAsyncCreateCmd { @Override public void execute(){ - PortForwardingRule result = _rulesService.createIpForwardingRuleOnDomr(this.getId()); + PortForwardingRule result = _rulesService.createIpForwardingRuleInDb(ipAddress, virtualMachineId); if (result != null) { FirewallRuleResponse fwResponse = _responseGenerator.createFirewallRuleResponse(result); fwResponse.setResponseName(getName()); diff --git a/api/src/com/cloud/api/commands/CreatePortForwardingRuleCmd.java b/api/src/com/cloud/api/commands/CreatePortForwardingRuleCmd.java index 9917f3eaa2b..1b812eb3730 100644 --- a/api/src/com/cloud/api/commands/CreatePortForwardingRuleCmd.java +++ b/api/src/com/cloud/api/commands/CreatePortForwardingRuleCmd.java @@ -107,7 +107,7 @@ public class CreatePortForwardingRuleCmd extends BaseCmd implements PortForwardi success = _rulesService.applyPortForwardingRules(result.getSourceIpAddress(), callerContext.getAccount()); } finally { if (!success) { - _rulesService.revokePortForwardingRule(result.getId(), true, callerContext.getAccount()); + _rulesService.revokePortForwardingRule(result.getId(), true); } } FirewallRuleResponse fwResponse = _responseGenerator.createFirewallRuleResponse(result); diff --git a/api/src/com/cloud/api/commands/DeletePortForwardingRuleCmd.java b/api/src/com/cloud/api/commands/DeletePortForwardingRuleCmd.java index a29628c2864..ad379fe5269 100644 --- a/api/src/com/cloud/api/commands/DeletePortForwardingRuleCmd.java +++ b/api/src/com/cloud/api/commands/DeletePortForwardingRuleCmd.java @@ -27,7 +27,6 @@ import com.cloud.api.ServerApiException; import com.cloud.api.response.SuccessResponse; import com.cloud.exception.ResourceUnavailableException; import com.cloud.network.rules.PortForwardingRule; -import com.cloud.user.UserContext; @Implementation(description="Deletes a port forwarding rule", responseObject=SuccessResponse.class) public class DeletePortForwardingRuleCmd extends BaseCmd { @@ -61,7 +60,7 @@ public class DeletePortForwardingRuleCmd extends BaseCmd { @Override public void execute() throws ResourceUnavailableException { - PortForwardingRule result = _rulesService.revokePortForwardingRule(id, true, UserContext.current().getAccount()); + PortForwardingRule result = _rulesService.revokePortForwardingRule(id, true); if (result != null) { SuccessResponse response = new SuccessResponse(getName()); this.setResponseObject(response); diff --git a/api/src/com/cloud/api/commands/ListIpForwardingRulesCmd.java b/api/src/com/cloud/api/commands/ListIpForwardingRulesCmd.java index 7554c8b28fb..e481813be97 100644 --- a/api/src/com/cloud/api/commands/ListIpForwardingRulesCmd.java +++ b/api/src/com/cloud/api/commands/ListIpForwardingRulesCmd.java @@ -31,6 +31,7 @@ import com.cloud.api.response.FirewallRuleResponse; import com.cloud.api.response.IpForwardingRuleResponse; import com.cloud.api.response.ListResponse; import com.cloud.network.rules.PortForwardingRule; +import com.cloud.utils.net.Ip; @Implementation(description="List the ip forwarding rules", responseObject=FirewallRuleResponse.class) public class ListIpForwardingRulesCmd extends BaseListCmd { @@ -82,7 +83,7 @@ public class ListIpForwardingRulesCmd extends BaseListCmd { @Override public void execute(){ - List result = _rulesService.searchForIpForwardingRules(this); + List result = _rulesService.searchForIpForwardingRules(new Ip(publicIpAddress), this.getStartIndex(), this.getPageSizeVal()); ListResponse response = new ListResponse(); List ipForwardingResponses = new ArrayList(); for (PortForwardingRule rule : result) { diff --git a/api/src/com/cloud/network/rules/RulesService.java b/api/src/com/cloud/network/rules/RulesService.java index 96d77d18087..a898649cac9 100644 --- a/api/src/com/cloud/network/rules/RulesService.java +++ b/api/src/com/cloud/network/rules/RulesService.java @@ -19,7 +19,6 @@ package com.cloud.network.rules; import java.util.List; -import com.cloud.api.commands.ListIpForwardingRulesCmd; import com.cloud.api.commands.ListPortForwardingRulesCmd; import com.cloud.exception.NetworkRuleConflictException; import com.cloud.exception.ResourceUnavailableException; @@ -27,26 +26,11 @@ import com.cloud.user.Account; import com.cloud.utils.net.Ip; public interface RulesService { - List searchForIpForwardingRules(ListIpForwardingRulesCmd cmd); - - /** - * List port forwarding rules assigned to an ip address - * @param cmd the command object holding the criteria for listing port forwarding rules (the ipAddress) - * @return list of port forwarding rules on the given address, empty list if no rules exist - */ - public List listPortForwardingRules(ListPortForwardingRulesCmd cmd); - + List searchForIpForwardingRules(Ip ip, Long start, Long size); PortForwardingRule createIpForwardingRuleInDb(String ipAddr, long virtualMachineId); - - PortForwardingRule createIpForwardingRuleOnDomr(long ruleId); - boolean deleteIpForwardingRule(Long id); - boolean deletePortForwardingRule(Long id, boolean sysContext); - - boolean applyFirewallRules(Ip ip, Account caller) throws ResourceUnavailableException; - boolean applyNatRules(Ip ip, Account caller) throws ResourceUnavailableException; - boolean applyPortForwardingRules(Ip ip, Account caller) throws ResourceUnavailableException; - + + /** * Creates a port forwarding rule between two ip addresses or between * an ip address and a virtual machine. @@ -57,12 +41,22 @@ public interface RulesService { * @throws NetworkRuleConflictException if conflicts in the network rules are detected. */ PortForwardingRule createPortForwardingRule(PortForwardingRule rule, Long vmId, Account caller) throws NetworkRuleConflictException; + /** * Revokes a port forwarding rule * @param ruleId the id of the rule to revoke. * @param caller * @return */ - PortForwardingRule revokePortForwardingRule(long ruleId, boolean apply, Account caller); + PortForwardingRule revokePortForwardingRule(long ruleId, boolean apply); + /** + * List port forwarding rules assigned to an ip address + * @param cmd the command object holding the criteria for listing port forwarding rules (the ipAddress) + * @return list of port forwarding rules on the given address, empty list if no rules exist + */ + public List listPortForwardingRules(ListPortForwardingRulesCmd cmd); + boolean applyFirewallRules(Ip ip, Account caller) throws ResourceUnavailableException; + boolean applyNatRules(Ip ip) throws ResourceUnavailableException; + boolean applyPortForwardingRules(Ip ip, Account caller) throws ResourceUnavailableException; } diff --git a/console-proxy/.classpath b/console-proxy/.classpath index 0b57db8ad5a..5a34eae6642 100644 --- a/console-proxy/.classpath +++ b/console-proxy/.classpath @@ -1,9 +1,9 @@ - - - - - - - - - + + + + + + + + + diff --git a/console-viewer/.classpath b/console-viewer/.classpath index 19542e73fc0..e8a8d8c0a84 100644 --- a/console-viewer/.classpath +++ b/console-viewer/.classpath @@ -1,7 +1,7 @@ - - - - - - - + + + + + + + diff --git a/core/.classpath b/core/.classpath index f2fff92d833..6f23bda4ba2 100644 --- a/core/.classpath +++ b/core/.classpath @@ -1,43 +1,44 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/server/src/com/cloud/network/NetworkManagerImpl.java b/server/src/com/cloud/network/NetworkManagerImpl.java index e5c764382cf..96b36264d39 100755 --- a/server/src/com/cloud/network/NetworkManagerImpl.java +++ b/server/src/com/cloud/network/NetworkManagerImpl.java @@ -2129,6 +2129,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag return true; } + boolean success = true; Network network = _networkConfigDao.findById(rules.get(0).getNetworkId()); for (NetworkElement ne : _networkElements) { try { @@ -2139,9 +2140,10 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag throw e; } s_logger.warn("Problems with " + ne.getName() + " but pushing on", e); + success = false; } } - return true; + return success; } } diff --git a/server/src/com/cloud/network/dao/FirewallRulesDaoImpl.java b/server/src/com/cloud/network/dao/FirewallRulesDaoImpl.java index d0720ba0de8..28852a35605 100644 --- a/server/src/com/cloud/network/dao/FirewallRulesDaoImpl.java +++ b/server/src/com/cloud/network/dao/FirewallRulesDaoImpl.java @@ -56,10 +56,9 @@ public class FirewallRulesDaoImpl extends GenericDaoBase i IpNotRevokedSearch = createSearchBuilder(); IpNotRevokedSearch.and("ip", IpNotRevokedSearch.entity().getSourceIpAddress(), Op.EQ); - IpNotRevokedSearch.and("state", IpNotRevokedSearch.entity().getSourceIpAddress(), Op.NEQ); + IpNotRevokedSearch.and("state", IpNotRevokedSearch.entity().getState(), Op.NEQ); IpNotRevokedSearch.done(); - } @Override diff --git a/server/src/com/cloud/network/rules/FirewallRuleVO.java b/server/src/com/cloud/network/rules/FirewallRuleVO.java index 51ce6515d93..c09476c54c3 100644 --- a/server/src/com/cloud/network/rules/FirewallRuleVO.java +++ b/server/src/com/cloud/network/rules/FirewallRuleVO.java @@ -56,6 +56,7 @@ public class FirewallRuleVO implements FirewallRule { long accountId; @Column(name="ip_address", updatable=false) + @Enumerated(value=EnumType.ORDINAL) Ip sourceIpAddress; @Column(name="start_port", updatable=false) diff --git a/server/src/com/cloud/network/rules/PortForwardingRuleVO.java b/server/src/com/cloud/network/rules/PortForwardingRuleVO.java index e9112a500fc..80344b04e3d 100644 --- a/server/src/com/cloud/network/rules/PortForwardingRuleVO.java +++ b/server/src/com/cloud/network/rules/PortForwardingRuleVO.java @@ -34,7 +34,7 @@ import com.cloud.utils.net.Ip; @PrimaryKeyJoinColumn(name="id") public class PortForwardingRuleVO extends FirewallRuleVO implements PortForwardingRule { - @Enumerated(value=EnumType.STRING) + @Enumerated(value=EnumType.ORDINAL) @Column(name="dest_ip_address") private Ip destinationIpAddress = null; diff --git a/server/src/com/cloud/network/rules/RulesManagerImpl.java b/server/src/com/cloud/network/rules/RulesManagerImpl.java index 921c7d1e998..28236ae3525 100644 --- a/server/src/com/cloud/network/rules/RulesManagerImpl.java +++ b/server/src/com/cloud/network/rules/RulesManagerImpl.java @@ -25,7 +25,6 @@ import javax.naming.ConfigurationException; import org.apache.log4j.Logger; -import com.cloud.api.commands.ListIpForwardingRulesCmd; import com.cloud.api.commands.ListPortForwardingRulesCmd; import com.cloud.event.EventTypes; import com.cloud.event.EventUtils; @@ -134,7 +133,7 @@ public class RulesManagerImpl implements RulesManager, RulesService, Manager { IPAddressVO ipAddress = _ipAddressDao.findById(ipAddr); Ip dstIp = rule.getDestinationIpAddress(); - long networkId = rule.getNetworkId(); + long networkId; UserVmVO vm = null; Network network = null; if (vmId != null) { @@ -164,6 +163,8 @@ public class RulesManagerImpl implements RulesManager, RulesService, Manager { throw new InvalidParameterValueException("Unable to get the network " + rule.getNetworkId()); } } + + _accountMgr.checkAccess(caller, network); networkId = network.getId(); long accountId = network.getAccountId(); @@ -236,13 +237,24 @@ public class RulesManagerImpl implements RulesManager, RulesService, Manager { } @Override - public PortForwardingRule revokePortForwardingRule(long ruleId, boolean apply, Account caller) { + public PortForwardingRule revokePortForwardingRule(long ruleId, boolean apply) { + UserContext ctx = UserContext.current(); + Account caller = ctx.getAccount(); + PortForwardingRuleVO rule = _forwardingDao.findById(ruleId); if (rule == null) { throw new InvalidParameterValueException("Unable to find " + ruleId); } + _accountMgr.checkAccess(caller, rule); revokeRule(rule, caller); + String description; + String type = EventTypes.EVENT_NET_RULE_DELETE; + String level = EventVO.LEVEL_INFO; + + description = "deleted ip forwarding rule [" + rule.getSourceIpAddress() + ":" + rule.getSourcePortStart() + "]->[" + rule.getDestinationIpAddress() + ":" + rule.getDestinationPortStart() + "] " + rule.getProtocol(); + EventUtils.saveEvent(ctx.getUserId(), rule.getAccountId(), level, type, description); + if (apply) { applyPortForwardingRules(rule.getSourceIpAddress(), true); } @@ -277,24 +289,12 @@ public class RulesManagerImpl implements RulesManager, RulesService, Manager { return null; } - @Override - public PortForwardingRule createIpForwardingRuleOnDomr(long ruleId) { - // TODO Auto-generated method stub - return null; - } - @Override public boolean deleteIpForwardingRule(Long id) { // TODO Auto-generated method stub return false; } - @Override - public boolean deletePortForwardingRule(Long id, boolean sysContext) { - // TODO Auto-generated method stub - return false; - } - @Override public boolean applyPortForwardingRules(Ip ip, boolean continueOnError) { try { @@ -316,24 +316,23 @@ public class RulesManagerImpl implements RulesManager, RulesService, Manager { _accountMgr.checkAccess(caller, rules.toArray(new PortForwardingRuleVO[rules.size()])); } - return _networkMgr.applyRules(ip, rules, continueOnError); + if (!_networkMgr.applyRules(ip, rules, continueOnError)) { + s_logger.debug("Rules are not completely applied"); + return false; + } + + for (PortForwardingRuleVO rule : rules) { + if (rule.getState() == FirewallRule.State.Revoke) { + _forwardingDao.remove(rule.getId()); + } + } + + return true; } @Override - public List searchForIpForwardingRules(ListIpForwardingRulesCmd cmd){ -// String ipAddress = cmd.getPublicIpAddress(); -// Filter searchFilter = new Filter(PortForwardingRuleVO.class, "id", true, cmd.getStartIndex(), cmd.getPageSizeVal()); -// SearchCriteria sc = _firewallRulesDao.createSearchCriteria(); -// -// if (ipAddress != null) { -// sc.addAnd("publicIpAddress", SearchCriteria.Op.EQ, ipAddress); -// } -// -// //search for rules with protocol = nat -// sc.addAnd("protocol", SearchCriteria.Op.EQ, NetUtils.NAT_PROTO); -// -// return _firewallRulesDao.search(sc, searchFilter); - return null; + public List searchForIpForwardingRules(Ip ip, Long start, Long size) { + return _forwardingDao.searchNatRules(ip, start, size); } @@ -344,7 +343,7 @@ public class RulesManagerImpl implements RulesManager, RulesService, Manager { } @Override - public boolean applyNatRules(Ip ip, Account caller) throws ResourceUnavailableException { + public boolean applyNatRules(Ip ip) throws ResourceUnavailableException { // TODO Auto-generated method stub return false; } @@ -678,118 +677,6 @@ public class RulesManagerImpl implements RulesManager, RulesService, Manager { // // @Override @DB // public boolean deletePortForwardingRule(Long id, boolean sysContext) { -// Long ruleId = id; -// Long userId = null; -// Account account = null; -// if(sysContext){ -// userId = User.UID_SYSTEM; -// account = _accountDao.findById(User.UID_SYSTEM); -// }else{ -// userId = UserContext.current().getUserId(); -// account = UserContext.current().getAccount(); -// } -// -// -// //verify input parameters here -// PortForwardingRuleVO rule = _firewallRulesDao.findById(ruleId); -// if (rule == null) { -// throw new InvalidParameterValueException("Unable to find port forwarding rule " + ruleId); -// } -// -// String publicIp = rule.getSourceIpAddress(); -// String privateIp = rule.getDestinationIpAddress(); -// -// IPAddressVO ipAddress = _ipAddressDao.findById(publicIp); -// if (ipAddress == null) { -// throw new InvalidParameterValueException("Unable to find IP address for port forwarding rule " + ruleId); -// } -// -// // although we are not writing these values to the DB, we will check -// // them out of an abundance -// // of caution (may not be warranted) -// String privatePort = rule.getDestinationPort(); -// String publicPort = rule.getSourcePort(); -// if (!NetUtils.isValidPort(publicPort) || !NetUtils.isValidPort(privatePort)) { -// throw new InvalidParameterValueException("Invalid value for port"); -// } -// -// String proto = rule.getProtocol(); -// if (!NetUtils.isValidProto(proto)) { -// throw new InvalidParameterValueException("Invalid protocol"); -// } -// -// Account ruleOwner = _accountDao.findById(ipAddress.getAccountId()); -// if (ruleOwner == null) { -// throw new InvalidParameterValueException("Unable to find owning account for port forwarding rule " + ruleId); -// } -// -// // if an admin account was passed in, or no account was passed in, make sure we honor the accountName/domainId parameters -// if (account != null) { -// if (isAdmin(account.getType())) { -// if (!_domainDao.isChildDomain(account.getDomainId(), ruleOwner.getDomainId())) { -// throw new PermissionDeniedException("Unable to delete port forwarding rule " + ruleId + ", permission denied."); -// } -// } else if (account.getId() != ruleOwner.getId()) { -// throw new PermissionDeniedException("Unable to delete port forwarding rule " + ruleId + ", permission denied."); -// } -// } -// -// Transaction txn = Transaction.currentTxn(); -// boolean locked = false; -// boolean success = false; -// try { -// -// IPAddressVO ipVO = _ipAddressDao.acquireInLockTable(publicIp); -// if (ipVO == null) { -// // throw this exception because hackers can use the api to probe for allocated ips -// throw new PermissionDeniedException("User does not own supplied address"); -// } -// -// locked = true; -// txn.start(); -// List fwdings = _firewallRulesDao.listIPForwardingForUpdate(publicIp, publicPort, proto); -// PortForwardingRuleVO fwRule = null; -// if (fwdings.size() == 0) { -// throw new InvalidParameterValueException("No such rule"); -// } else if (fwdings.size() == 1) { -// fwRule = fwdings.get(0); -// if (fwRule.getDestinationIpAddress().equalsIgnoreCase(privateIp) && fwRule.getDestinationPort().equals(privatePort)) { -// _firewallRulesDao.expunge(fwRule.getId()); -// } else { -// throw new InvalidParameterValueException("No such rule"); -// } -// } else { -// throw new CloudRuntimeException("Multiple matches. Please contact support"); -// } -// fwRule.setEnabled(false); -// success = updateFirewallRule(fwRule, null, null); -// -// String description; -// String type = EventTypes.EVENT_NET_RULE_DELETE; -// String level = EventVO.LEVEL_INFO; -// String ruleName = rule.isForwarding() ? "ip forwarding" : "load balancer"; -// -// if (success) { -// description = "deleted " + ruleName + " rule [" + publicIp + ":" + rule.getSourcePort() + "]->[" + rule.getDestinationIpAddress() + ":" -// + rule.getDestinationPort() + "] " + rule.getProtocol(); -// } else { -// level = EventVO.LEVEL_ERROR; -// description = "Error while deleting " + ruleName + " rule [" + publicIp + ":" + rule.getSourcePort() + "]->[" + rule.getDestinationIpAddress() + ":" -// + rule.getDestinationPort() + "] " + rule.getProtocol(); -// } -// EventUtils.saveEvent(userId, ipAddress.getAccountId(), level, type, description); -// txn.commit(); -// }catch (Exception ex) { -// txn.rollback(); -// s_logger.error("Unexpected exception deleting port forwarding rule " + ruleId, ex); -// return false; -// }finally { -// if (locked) { -// _ipAddressDao.releaseFromLockTable(publicIp); -// } -// txn.close(); -// } -// return success; // } // @Override @DB // public PortForwardingRule createIpForwardingRuleOnDomr(long ruleId) { diff --git a/server/src/com/cloud/network/rules/dao/PortForwardingRulesDao.java b/server/src/com/cloud/network/rules/dao/PortForwardingRulesDao.java index c9d3bcb0d99..83db875deaa 100644 --- a/server/src/com/cloud/network/rules/dao/PortForwardingRulesDao.java +++ b/server/src/com/cloud/network/rules/dao/PortForwardingRulesDao.java @@ -33,4 +33,6 @@ public interface PortForwardingRulesDao extends GenericDao listByIpAndNotRevoked(Ip ip); + + List searchNatRules(Ip ip, Long startIndex, Long pageSize); } diff --git a/server/src/com/cloud/network/rules/dao/PortForwardingRulesDaoImpl.java b/server/src/com/cloud/network/rules/dao/PortForwardingRulesDaoImpl.java index fdea05416ce..2aaefecb3c2 100644 --- a/server/src/com/cloud/network/rules/dao/PortForwardingRulesDaoImpl.java +++ b/server/src/com/cloud/network/rules/dao/PortForwardingRulesDaoImpl.java @@ -23,11 +23,13 @@ import javax.ejb.Local; import com.cloud.network.rules.FirewallRule.State; import com.cloud.network.rules.PortForwardingRuleVO; +import com.cloud.utils.db.Filter; import com.cloud.utils.db.GenericDaoBase; import com.cloud.utils.db.SearchBuilder; import com.cloud.utils.db.SearchCriteria; import com.cloud.utils.db.SearchCriteria.Op; import com.cloud.utils.net.Ip; +import com.cloud.utils.net.NetUtils; @Local(value=PortForwardingRulesDao.class) public class PortForwardingRulesDaoImpl extends GenericDaoBase implements PortForwardingRulesDao { @@ -40,6 +42,9 @@ public class PortForwardingRulesDaoImpl extends GenericDaoBase searchNatRules(Ip ip, Long startIndex, Long pageSize) { + Filter searchFilter = new Filter(PortForwardingRuleVO.class, "id", true, startIndex, pageSize); + SearchCriteria sc = AllFieldsSearch.create(); + + if (ip != null) { + sc.setParameters("ip", ip); + } + + //search for rules with protocol = nat + sc.setParameters("protocol", NetUtils.NAT_PROTO); + + return listBy(sc, searchFilter); + } + } diff --git a/utils/src/com/cloud/utils/db/GenericDaoBase.java b/utils/src/com/cloud/utils/db/GenericDaoBase.java index 1bcdea98b4e..ff21e451611 100755 --- a/utils/src/com/cloud/utils/db/GenericDaoBase.java +++ b/utils/src/com/cloud/utils/db/GenericDaoBase.java @@ -538,7 +538,8 @@ public abstract class GenericDaoBase implements Gene Ip ip = null; if (enumType == EnumType.STRING) { - ip = new Ip(NetUtils.ip2Long(rs.getString(index))); + String s = rs.getString(index); + ip = s == null ? null : new Ip(NetUtils.ip2Long(s)); } else { ip = new Ip(rs.getLong(index)); } @@ -1204,9 +1205,9 @@ public abstract class GenericDaoBase implements Gene return null; // Not sure what to do here. } else if (attr.is(Attribute.Flag.AutoGV)) { - if (attr.columnName == GenericDao.XID_COLUMN) { - UUID.randomUUID().toString(); - } + if (attr.columnName.equals(GenericDao.XID_COLUMN)) { + return UUID.randomUUID().toString(); + } assert (false) : "Auto generation is not supported."; return null; } else if (attr.is(Attribute.Flag.SequenceGV)) { diff --git a/utils/src/com/cloud/utils/db/SqlGenerator.java b/utils/src/com/cloud/utils/db/SqlGenerator.java index 6e53132373d..2db80284faf 100755 --- a/utils/src/com/cloud/utils/db/SqlGenerator.java +++ b/utils/src/com/cloud/utils/db/SqlGenerator.java @@ -227,7 +227,7 @@ public class SqlGenerator { attr = findAttribute(GenericDao.XID_COLUMN); if (attr != null && attr.field.getType() == String.class) { attr.setTrue(Attribute.Flag.DaoGenerated); - attr.setFalse(Attribute.Flag.Insertable); + attr.setTrue(Attribute.Flag.Insertable); attr.setFalse(Attribute.Flag.Updatable); attr.setFalse(Attribute.Flag.TimeStamp); attr.setFalse(Attribute.Flag.Time);