VPC: CS-15519 - fixed ipAssoc when only zoneId parameter is passed in to the API call

This commit is contained in:
Alena Prokharchyk 2012-07-10 15:14:31 -07:00
parent 2c13b82736
commit 4e5355b192
5 changed files with 19 additions and 12 deletions

View File

@ -176,8 +176,8 @@ public class AssociateIPAddrCmd extends BaseAsyncCreateCmd {
if (accountName != null && domainId != null) {
Account account = _accountService.finalizeOwner(caller, accountName, domainId, projectId);
return account.getId();
} else if (getNetworkId() != null){
Network network = _networkService.getNetwork(getNetworkId());
} else if (networkId != null){
Network network = _networkService.getNetwork(networkId);
return network.getAccountId();
} else if (vpcId != null) {
Vpc vpc = _vpcService.getVpc(getVpcId());
@ -187,7 +187,7 @@ public class AssociateIPAddrCmd extends BaseAsyncCreateCmd {
return vpc.getAccountId();
}
throw new InvalidParameterValueException("Failed to determine ip owner", null);
return caller.getAccountId();
}
@Override

View File

@ -351,7 +351,7 @@ public class ExternalLoadBalancerUsageManagerImpl implements ExternalLoadBalance
long zoneId = zone.getId();
List<NetworkVO> networksForAccount = _networkDao.listBy(accountId, zoneId, Network.GuestType.Isolated);
List<NetworkVO> networksForAccount = _networkDao.listByZoneAndGuestType(accountId, zoneId, Network.GuestType.Isolated, false);
if (networksForAccount == null) {
continue;
}

View File

@ -1015,7 +1015,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
@Override
public List<? extends Network> getIsolatedNetworksOwnedByAccountInZone(long zoneId, Account owner) {
return _networksDao.listBy(owner.getId(), zoneId, Network.GuestType.Isolated);
return _networksDao.listByZoneAndGuestType(owner.getId(), zoneId, Network.GuestType.Isolated, false);
}
@Override
@ -4463,7 +4463,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
@Override
public String getIpOfNetworkElementInVirtualNetwork(long accountId, long dataCenterId) {
List<NetworkVO> virtualNetworks = _networksDao.listBy(accountId, dataCenterId, Network.GuestType.Isolated);
List<NetworkVO> virtualNetworks = _networksDao.listByZoneAndGuestType(accountId, dataCenterId, Network.GuestType.Isolated, false);
if (virtualNetworks.isEmpty()) {
s_logger.trace("Unable to find default Virtual network account id=" + accountId);

View File

@ -31,7 +31,7 @@ public interface NetworkDao extends GenericDao<NetworkVO, Long> {
List<NetworkVO> listBy(long accountId, long dataCenterId, String cidr);
List<NetworkVO> listBy(long accountId, long dataCenterId, Network.GuestType type);
List<NetworkVO> listByZoneAndGuestType(long accountId, long dataCenterId, Network.GuestType type, Boolean isSystem);
NetworkVO persist(NetworkVO network, boolean gc, Map<String, String> serviceProviderMap);

View File

@ -95,6 +95,9 @@ public class NetworkDaoImpl extends GenericDaoBase<NetworkVO, Long> implements N
AllFieldsSearch.and("physicalNetwork", AllFieldsSearch.entity().getPhysicalNetworkId(), Op.EQ);
AllFieldsSearch.and("broadcastUri", AllFieldsSearch.entity().getBroadcastUri(), Op.EQ);
AllFieldsSearch.and("vpcId", AllFieldsSearch.entity().getVpcId(), Op.EQ);
SearchBuilder<NetworkOfferingVO> join1 = _ntwkOffDao.createSearchBuilder();
join1.and("isSystem", join1.entity().isSystemOnly(), Op.EQ);
AllFieldsSearch.join("offerings", join1, AllFieldsSearch.entity().getNetworkOfferingId(), join1.entity().getId(), JoinBuilder.JoinType.INNER);
AllFieldsSearch.done();
AccountSearch = createSearchBuilder();
@ -135,12 +138,11 @@ public class NetworkDaoImpl extends GenericDaoBase<NetworkVO, Long> implements N
CountByZoneAndURI.done();
ZoneSecurityGroupSearch = createSearchBuilder();
ZoneSecurityGroupSearch.and("dataCenterId", ZoneSecurityGroupSearch.entity().getDataCenterId(), Op.EQ);
SearchBuilder<NetworkServiceMapVO> join1 = _ntwkSvcMap.createSearchBuilder();
join1.and("service", join1.entity().getService(), Op.EQ);
ZoneSecurityGroupSearch.join("services", join1, ZoneSecurityGroupSearch.entity().getId(), join1.entity().getNetworkId(), JoinBuilder.JoinType.INNER);
SearchBuilder<NetworkServiceMapVO> offJoin = _ntwkSvcMap.createSearchBuilder();
offJoin.and("service", offJoin.entity().getService(), Op.EQ);
ZoneSecurityGroupSearch.join("services", offJoin, ZoneSecurityGroupSearch.entity().getId(), offJoin.entity().getNetworkId(), JoinBuilder.JoinType.INNER);
ZoneSecurityGroupSearch.done();
CountBy = createSearchBuilder(Integer.class);
@ -191,13 +193,18 @@ public class NetworkDaoImpl extends GenericDaoBase<NetworkVO, Long> implements N
}
@Override
public List<NetworkVO> listBy(long accountId, long dataCenterId, Network.GuestType type) {
public List<NetworkVO> listByZoneAndGuestType(long accountId, long dataCenterId, Network.GuestType type, Boolean isSystem) {
SearchCriteria<NetworkVO> sc = AllFieldsSearch.create();
sc.setParameters("datacenter", dataCenterId);
sc.setParameters("account", accountId);
if (type != null) {
sc.setParameters("guestType", type);
}
if (isSystem != null) {
sc.setJoinParameters("offerings", "isSystem", isSystem);
}
return listBy(sc, null);
}