portforwarding is working

This commit is contained in:
Alex Huang 2010-12-02 16:05:01 -08:00
parent bb78986ddb
commit 9a70ee54f0
17 changed files with 144 additions and 236 deletions

View File

@ -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());

View File

@ -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);

View File

@ -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);

View File

@ -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<? extends PortForwardingRule> result = _rulesService.searchForIpForwardingRules(this);
List<? extends PortForwardingRule> result = _rulesService.searchForIpForwardingRules(new Ip(publicIpAddress), this.getStartIndex(), this.getPageSizeVal());
ListResponse<IpForwardingRuleResponse> response = new ListResponse<IpForwardingRuleResponse>();
List<IpForwardingRuleResponse> ipForwardingResponses = new ArrayList<IpForwardingRuleResponse>();
for (PortForwardingRule rule : result) {

View File

@ -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<? extends PortForwardingRule> 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<? extends PortForwardingRule> listPortForwardingRules(ListPortForwardingRulesCmd cmd);
List<? extends PortForwardingRule> 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<? extends PortForwardingRule> 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;
}

View File

@ -1,9 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="lib" path="/thirdparty/log4j-1.2.15.jar"/>
<classpathentry kind="lib" path="/thirdparty/gson.jar"/>
<classpathentry combineaccessrules="false" kind="src" path="/console-common"/>
<classpathentry kind="output" path="bin"/>
</classpath>
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="lib" path="/thirdparty/log4j-1.2.15.jar"/>
<classpathentry kind="lib" path="/thirdparty/gson.jar"/>
<classpathentry combineaccessrules="false" kind="src" path="/console"/>
<classpathentry kind="output" path="bin"/>
</classpath>

View File

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry combineaccessrules="false" kind="src" path="/console-common"/>
<classpathentry kind="output" path="bin"/>
</classpath>
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry combineaccessrules="false" kind="src" path="/console"/>
<classpathentry kind="output" path="bin"/>
</classpath>

View File

@ -1,43 +1,44 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry combineaccessrules="false" kind="src" path="/utils"/>
<classpathentry kind="lib" path="/thirdparty/xmlrpc-common-3.1.3.jar"/>
<classpathentry kind="lib" path="/thirdparty/xmlrpc-client-3.1.3.jar"/>
<classpathentry kind="lib" path="/thirdparty/log4j-1.2.15.jar"/>
<classpathentry kind="lib" path="/thirdparty/cglib-nodep-2.2.jar"/>
<classpathentry kind="lib" path="/thirdparty/commons-dbcp-1.2.2.jar"/>
<classpathentry kind="lib" path="/thirdparty/commons-pool-1.4.jar"/>
<classpathentry kind="lib" path="/thirdparty/ehcache-1.5.0.jar"/>
<classpathentry kind="lib" path="/thirdparty/junit-4.8.1.jar"/>
<classpathentry kind="lib" path="/thirdparty/trilead-ssh2-build213.jar"/>
<classpathentry kind="lib" path="/thirdparty/commons-httpclient-3.1.jar"/>
<classpathentry kind="lib" path="/thirdparty/commons-codec-1.4.jar"/>
<classpathentry combineaccessrules="false" kind="src" path="/api"/>
<classpathentry kind="lib" path="/thirdparty/vmware-apputils.jar"/>
<classpathentry kind="lib" path="/thirdparty/vmware-credstore.jar"/>
<classpathentry kind="lib" path="/thirdparty/vmware-lib-activation.jar"/>
<classpathentry kind="lib" path="/thirdparty/vmware-lib-axis.jar"/>
<classpathentry kind="lib" path="/thirdparty/vmware-lib-jaxen-core.jar"/>
<classpathentry kind="lib" path="/thirdparty/vmware-lib-jaxen-jdom.jar"/>
<classpathentry kind="lib" path="/thirdparty/vmware-lib-jaxen.license"/>
<classpathentry kind="lib" path="/thirdparty/vmware-lib-jaxen.readme"/>
<classpathentry kind="lib" path="/thirdparty/vmware-lib-jaxrpc.jar"/>
<classpathentry kind="lib" path="/thirdparty/vmware-lib-jdom.jar"/>
<classpathentry kind="lib" path="/thirdparty/vmware-lib-mailapi.jar"/>
<classpathentry kind="lib" path="/thirdparty/vmware-lib-saxpath.jar"/>
<classpathentry kind="lib" path="/thirdparty/vmware-lib-smtp.jar"/>
<classpathentry kind="lib" path="/thirdparty/vmware-lib-wbem.jar"/>
<classpathentry kind="lib" path="/thirdparty/vmware-lib-xalan.jar"/>
<classpathentry kind="lib" path="/thirdparty/vmware-lib-xalan.license"/>
<classpathentry kind="lib" path="/thirdparty/vmware-lib-xalan.readme"/>
<classpathentry kind="lib" path="/thirdparty/vmware-lib-xerces.jar"/>
<classpathentry kind="lib" path="/thirdparty/vmware-lib-xerces.readme"/>
<classpathentry kind="lib" path="/thirdparty/vmware-lib-xml-apis.jar"/>
<classpathentry kind="lib" path="/thirdparty/vmware-vim.jar"/>
<classpathentry kind="lib" path="/thirdparty/vmware-vim25.jar"/>
<classpathentry kind="lib" path="/thirdparty/gson.jar"/>
<classpathentry kind="lib" path="/thirdparty/xenserver-5.6.0-1.jar" sourcepath="/thirdparty/XenServerJava"/>
<classpathentry kind="output" path="bin"/>
</classpath>
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="src" path="test"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry combineaccessrules="false" kind="src" path="/utils"/>
<classpathentry kind="lib" path="/thirdparty/xmlrpc-common-3.1.3.jar"/>
<classpathentry kind="lib" path="/thirdparty/xmlrpc-client-3.1.3.jar"/>
<classpathentry kind="lib" path="/thirdparty/log4j-1.2.15.jar"/>
<classpathentry kind="lib" path="/thirdparty/cglib-nodep-2.2.jar"/>
<classpathentry kind="lib" path="/thirdparty/commons-dbcp-1.2.2.jar"/>
<classpathentry kind="lib" path="/thirdparty/commons-pool-1.4.jar"/>
<classpathentry kind="lib" path="/thirdparty/ehcache-1.5.0.jar"/>
<classpathentry kind="lib" path="/thirdparty/junit-4.8.1.jar"/>
<classpathentry kind="lib" path="/thirdparty/trilead-ssh2-build213.jar"/>
<classpathentry kind="lib" path="/thirdparty/commons-httpclient-3.1.jar"/>
<classpathentry kind="lib" path="/thirdparty/commons-codec-1.4.jar"/>
<classpathentry combineaccessrules="false" kind="src" path="/api"/>
<classpathentry kind="lib" path="/thirdparty/vmware-apputils.jar"/>
<classpathentry kind="lib" path="/thirdparty/vmware-credstore.jar"/>
<classpathentry kind="lib" path="/thirdparty/vmware-lib-activation.jar"/>
<classpathentry kind="lib" path="/thirdparty/vmware-lib-axis.jar"/>
<classpathentry kind="lib" path="/thirdparty/vmware-lib-jaxen-core.jar"/>
<classpathentry kind="lib" path="/thirdparty/vmware-lib-jaxen-jdom.jar"/>
<classpathentry kind="lib" path="/thirdparty/vmware-lib-jaxen.license"/>
<classpathentry kind="lib" path="/thirdparty/vmware-lib-jaxen.readme"/>
<classpathentry kind="lib" path="/thirdparty/vmware-lib-jaxrpc.jar"/>
<classpathentry kind="lib" path="/thirdparty/vmware-lib-jdom.jar"/>
<classpathentry kind="lib" path="/thirdparty/vmware-lib-mailapi.jar"/>
<classpathentry kind="lib" path="/thirdparty/vmware-lib-saxpath.jar"/>
<classpathentry kind="lib" path="/thirdparty/vmware-lib-smtp.jar"/>
<classpathentry kind="lib" path="/thirdparty/vmware-lib-wbem.jar"/>
<classpathentry kind="lib" path="/thirdparty/vmware-lib-xalan.jar"/>
<classpathentry kind="lib" path="/thirdparty/vmware-lib-xalan.license"/>
<classpathentry kind="lib" path="/thirdparty/vmware-lib-xalan.readme"/>
<classpathentry kind="lib" path="/thirdparty/vmware-lib-xerces.jar"/>
<classpathentry kind="lib" path="/thirdparty/vmware-lib-xerces.readme"/>
<classpathentry kind="lib" path="/thirdparty/vmware-lib-xml-apis.jar"/>
<classpathentry kind="lib" path="/thirdparty/vmware-vim.jar"/>
<classpathentry kind="lib" path="/thirdparty/vmware-vim25.jar"/>
<classpathentry kind="lib" path="/thirdparty/gson.jar"/>
<classpathentry kind="lib" path="/thirdparty/xenserver-5.6.0-1.jar" sourcepath="/thirdparty/XenServerJava"/>
<classpathentry kind="output" path="bin"/>
</classpath>

View File

@ -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;
}
}

View File

@ -56,10 +56,9 @@ public class FirewallRulesDaoImpl extends GenericDaoBase<FirewallRuleVO, Long> 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

View File

@ -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)

View File

@ -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;

View File

@ -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<PortForwardingRuleVO> searchForIpForwardingRules(ListIpForwardingRulesCmd cmd){
// String ipAddress = cmd.getPublicIpAddress();
// Filter searchFilter = new Filter(PortForwardingRuleVO.class, "id", true, cmd.getStartIndex(), cmd.getPageSizeVal());
// SearchCriteria<PortForwardingRuleVO> 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<PortForwardingRuleVO> 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<PortForwardingRuleVO> 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) {

View File

@ -33,4 +33,6 @@ public interface PortForwardingRulesDao extends GenericDao<PortForwardingRuleVO,
* @return List of PortForwardingRuleVO
*/
List<PortForwardingRuleVO> listByIpAndNotRevoked(Ip ip);
List<PortForwardingRuleVO> searchNatRules(Ip ip, Long startIndex, Long pageSize);
}

View File

@ -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<PortForwardingRuleVO, Long> implements PortForwardingRulesDao {
@ -40,6 +42,9 @@ public class PortForwardingRulesDaoImpl extends GenericDaoBase<PortForwardingRul
super();
AllFieldsSearch = createSearchBuilder();
AllFieldsSearch.and("id", AllFieldsSearch.entity().getId(), Op.EQ);
AllFieldsSearch.and("state", AllFieldsSearch.entity().getState(), Op.EQ);
AllFieldsSearch.and("ip", AllFieldsSearch.entity().getSourceIpAddress(), Op.EQ);
AllFieldsSearch.and("proto", AllFieldsSearch.entity().getProtocol(), Op.EQ);
AllFieldsSearch.done();
ApplicationSearch = createSearchBuilder();
@ -69,4 +74,20 @@ public class PortForwardingRulesDaoImpl extends GenericDaoBase<PortForwardingRul
return listBy(sc, null);
}
@Override
public List<PortForwardingRuleVO> searchNatRules(Ip ip, Long startIndex, Long pageSize) {
Filter searchFilter = new Filter(PortForwardingRuleVO.class, "id", true, startIndex, pageSize);
SearchCriteria<PortForwardingRuleVO> 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);
}
}

View File

@ -538,7 +538,8 @@ public abstract class GenericDaoBase<T, ID extends Serializable> 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<T, ID extends Serializable> 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)) {

View File

@ -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);