bug 7389: made ip optinal for list pf rules, all rules for the account will be listed when ip is not available

status 7389: resolved fixed
This commit is contained in:
kishan 2011-01-03 13:47:18 +05:30
parent 6dbf6fe67a
commit 02ae55cc96
4 changed files with 30 additions and 9 deletions

View File

@ -40,7 +40,7 @@ public class ListPortForwardingRulesCmd extends BaseListCmd {
//////////////// API parameters /////////////////////
/////////////////////////////////////////////////////
@Parameter(name=ApiConstants.IP_ADDRESS, type=CommandType.STRING, required=true, description="the IP address of the port forwarding services")
@Parameter(name=ApiConstants.IP_ADDRESS, type=CommandType.STRING, description="the IP address of the port forwarding services")
private String ipAddress;
/////////////////////////////////////////////////////

View File

@ -345,17 +345,22 @@ public class RulesManagerImpl implements RulesManager, RulesService, Manager {
@Override
public List<? extends PortForwardingRule> listPortForwardingRules(ListPortForwardingRulesCmd cmd) {
Ip ipAddress = new Ip(cmd.getIpAddress());
Account caller = UserContext.current().getCaller();
IPAddressVO ipAddressVO = _ipAddressDao.findById(ipAddress);
if (ipAddressVO == null || !ipAddressVO.readyToUse()) {
throw new InvalidParameterValueException("Ip address not ready for port forwarding rules yet: " + ipAddress);
}
List<PortForwardingRuleVO> rules = _forwardingDao.listByIp(ipAddress);
_accountMgr.checkAccess(caller, rules.toArray(new PortForwardingRuleVO[rules.size()]));
List<PortForwardingRuleVO> rules = null;
if(cmd.getIpAddress() != null){
Ip ipAddress = new Ip(cmd.getIpAddress());
IPAddressVO ipAddressVO = _ipAddressDao.findById(ipAddress);
if (ipAddressVO == null || !ipAddressVO.readyToUse()) {
throw new InvalidParameterValueException("Ip address not ready for port forwarding rules yet: " + ipAddress);
}
rules = _forwardingDao.listByIp(ipAddress);
_accountMgr.checkAccess(caller, rules.toArray(new PortForwardingRuleVO[rules.size()]));
} else {
rules = _forwardingDao.listByAccount(caller.getAccountId());
}
return rules;
}

View File

@ -41,4 +41,6 @@ public interface PortForwardingRulesDao extends GenericDao<PortForwardingRuleVO,
List<PortForwardingRuleVO> listByVm(Long vmId);
List<PortForwardingRuleVO> listByNetworkId(long networkId);
List<PortForwardingRuleVO> listByAccount(long accountId);
}

View File

@ -38,6 +38,7 @@ public class PortForwardingRulesDaoImpl extends GenericDaoBase<PortForwardingRul
protected final SearchBuilder<PortForwardingRuleVO> ApplicationSearch;
protected final SearchBuilder<PortForwardingRuleVO> ActiveRulesSearch;
protected final SearchBuilder<PortForwardingRuleVO> AllRulesSearchByVM;
protected final SearchBuilder<PortForwardingRuleVO> ActiveRulesSearchByAccount;
protected PortForwardingRulesDaoImpl() {
super();
@ -61,6 +62,11 @@ public class PortForwardingRulesDaoImpl extends GenericDaoBase<PortForwardingRul
AllRulesSearchByVM = createSearchBuilder();
AllRulesSearchByVM.and("vmId", AllRulesSearchByVM.entity().getVirtualMachineId(), Op.EQ);
AllRulesSearchByVM.done();
ActiveRulesSearchByAccount = createSearchBuilder();
ActiveRulesSearchByAccount.and("accountId", ActiveRulesSearchByAccount.entity().getAccountId(), Op.EQ);
ActiveRulesSearchByAccount.and("state", ActiveRulesSearchByAccount.entity().getState(), Op.NEQ);
ActiveRulesSearchByAccount.done();
}
@Override
@ -117,5 +123,13 @@ public class PortForwardingRulesDaoImpl extends GenericDaoBase<PortForwardingRul
sc.setParameters("networkId", networkId);
return listBy(sc);
}
@Override
public List<PortForwardingRuleVO> listByAccount(long accountId) {
SearchCriteria<PortForwardingRuleVO> sc = ActiveRulesSearchByAccount.create();
sc.setParameters("accountId", accountId);
sc.setParameters("state", State.Revoke);
return listBy(sc);
}
}