bug 7341: introduced search by id and vmId for listIpForwardingRules

status 7341: resolved fixed
This commit is contained in:
kishan 2011-01-19 13:12:41 +05:30
parent 017146f753
commit fa2ae5793a
5 changed files with 35 additions and 8 deletions

View File

@ -42,7 +42,7 @@ public class ListIpForwardingRulesCmd extends BaseListCmd {
//////////////// API parameters /////////////////////
/////////////////////////////////////////////////////
@Parameter(name=ApiConstants.IP_ADDRESS, required=true, type=CommandType.STRING, description="list the rule belonging to this public ip address")
@Parameter(name=ApiConstants.IP_ADDRESS, type=CommandType.STRING, description="list the rule belonging to this public ip address")
private String publicIpAddress;
@Parameter(name=ApiConstants.ACCOUNT, type=CommandType.STRING, description="the account associated with the ip forwarding rule. Must be used with the domainId parameter.")
@ -50,6 +50,12 @@ public class ListIpForwardingRulesCmd extends BaseListCmd {
@Parameter(name=ApiConstants.DOMAIN_ID, type=CommandType.LONG, description="Lists all rules for this id. If used with the account parameter, returns all rules for an account in the specified domain ID.")
private Long domainId;
@Parameter(name=ApiConstants.ID, type=CommandType.LONG, description="Lists rule with the specified ID.")
private Long id;
@Parameter(name=ApiConstants.VIRTUAL_MACHINE_ID, type=CommandType.LONG, description="Lists all rules applied to the specified Vm.")
private Long vmId;
/////////////////////////////////////////////////////
/////////////////// Accessors ///////////////////////
@ -80,9 +86,21 @@ public class ListIpForwardingRulesCmd extends BaseListCmd {
return domainId;
}
@Override
public Long getId() {
return id;
}
public Long getVmId() {
return vmId;
}
@Override
public void execute(){
List<? extends PortForwardingRule> result = _rulesService.searchForIpForwardingRules(new Ip(publicIpAddress), this.getStartIndex(), this.getPageSizeVal());
Ip ip = null;
if(publicIpAddress != null){
ip = new Ip(publicIpAddress);
}
List<? extends PortForwardingRule> result = _rulesService.searchForIpForwardingRules(ip, id, vmId, this.getStartIndex(), this.getPageSizeVal());
ListResponse<IpForwardingRuleResponse> response = new ListResponse<IpForwardingRuleResponse>();
List<IpForwardingRuleResponse> ipForwardingResponses = new ArrayList<IpForwardingRuleResponse>();
for (PortForwardingRule rule : result) {

View File

@ -26,7 +26,7 @@ import com.cloud.user.Account;
import com.cloud.utils.net.Ip;
public interface RulesService {
List<? extends PortForwardingRule> searchForIpForwardingRules(Ip ip, Long start, Long size);
List<? extends PortForwardingRule> searchForIpForwardingRules(Ip ip, Long id, Long vmId, Long start, Long size);
/**
* Creates a port forwarding rule between two ip addresses or between

View File

@ -404,8 +404,8 @@ public class RulesManagerImpl implements RulesManager, RulesService, Manager {
}
@Override
public List<PortForwardingRuleVO> searchForIpForwardingRules(Ip ip, Long start, Long size) {
return _forwardingDao.searchNatRules(ip, start, size);
public List<PortForwardingRuleVO> searchForIpForwardingRules(Ip ip, Long id, Long vmId, Long start, Long size) {
return _forwardingDao.searchNatRules(ip, id, vmId, start, size);
}
@Override

View File

@ -36,7 +36,7 @@ public interface PortForwardingRulesDao extends GenericDao<PortForwardingRuleVO,
List<PortForwardingRuleVO> listByIp(Ip ip);
List<PortForwardingRuleVO> searchNatRules(Ip ip, Long startIndex, Long pageSize);
List<PortForwardingRuleVO> searchNatRules(Ip ip, Long id, Long vmId, Long startIndex, Long pageSize);
List<PortForwardingRuleVO> listByVm(Long vmId);

View File

@ -48,6 +48,7 @@ public class PortForwardingRulesDaoImpl extends GenericDaoBase<PortForwardingRul
AllFieldsSearch.and("ip", AllFieldsSearch.entity().getSourceIpAddress(), Op.EQ);
AllFieldsSearch.and("protocol", AllFieldsSearch.entity().getProtocol(), Op.EQ);
AllFieldsSearch.and("networkId", AllFieldsSearch.entity().getNetworkId(), Op.EQ);
AllFieldsSearch.and("vmId", AllFieldsSearch.entity().getVirtualMachineId(), Op.EQ);
AllFieldsSearch.done();
ApplicationSearch = createSearchBuilder();
@ -103,7 +104,7 @@ public class PortForwardingRulesDaoImpl extends GenericDaoBase<PortForwardingRul
}
@Override
public List<PortForwardingRuleVO> searchNatRules(Ip ip, Long startIndex, Long pageSize) {
public List<PortForwardingRuleVO> searchNatRules(Ip ip, Long id, Long vmId, Long startIndex, Long pageSize) {
Filter searchFilter = new Filter(PortForwardingRuleVO.class, "id", true, startIndex, pageSize);
SearchCriteria<PortForwardingRuleVO> sc = AllFieldsSearch.create();
@ -111,6 +112,14 @@ public class PortForwardingRulesDaoImpl extends GenericDaoBase<PortForwardingRul
sc.setParameters("ip", ip);
}
if (id != null) {
sc.setParameters("id", id);
}
if (vmId != null) {
sc.setParameters("vmId", vmId);
}
//search for rules with protocol = nat
sc.setParameters("protocol", NetUtils.NAT_PROTO);