CLOUDSTACK-2441: Fix deleting private gateways while deleting vpc in case multiple private gateways

This commit is contained in:
Jayapal 2013-05-14 16:10:38 +05:30 committed by Kishan Kavala
parent 7d380423b5
commit c94c71b4ce
5 changed files with 49 additions and 9 deletions

View File

@ -16,13 +16,18 @@
// under the License.
package com.cloud.network.vpc.dao;
import com.cloud.network.vpc.VpcGateway;
import com.cloud.network.vpc.VpcGatewayVO;
import com.cloud.utils.db.GenericDao;
import java.util.List;
public interface VpcGatewayDao extends GenericDao<VpcGatewayVO, Long>{
VpcGatewayVO getPrivateGatewayForVpc(long vpcId);
VpcGatewayVO getVpnGatewayForVpc(long vpcId);
Long getNetworkAclIdForPrivateIp(long vpcId, long networkId, String ipaddr);
List<VpcGatewayVO> listByVpcIdAndType(long vpcId, VpcGateway.Type type);
}

View File

@ -27,6 +27,8 @@ import com.cloud.utils.db.GenericDaoBase;
import com.cloud.utils.db.SearchBuilder;
import com.cloud.utils.db.SearchCriteria;
import java.util.List;
@Component
@Local(value = VpcGatewayDao.class)
@DB(txn = false)
@ -76,5 +78,12 @@ public class VpcGatewayDaoImpl extends GenericDaoBase<VpcGatewayVO, Long> implem
}
}
@Override
public List<VpcGatewayVO> listByVpcIdAndType(long vpcId, VpcGateway.Type type) {
SearchCriteria<VpcGatewayVO> sc = AllFieldsSearch.create();
sc.setParameters("vpcId", vpcId);
sc.setParameters("type", type);
return listBy(sc);
}
}

View File

@ -165,4 +165,6 @@ public interface VpcManager extends VpcService{
* @param networkOwner TODO
*/
void validateNtwkOffForNtwkInVpc(Long networkId, long newNtwkOffId, String newCidr, String newNetworkDomain, Vpc vpc, String gateway, Account networkOwner);
List<PrivateGateway> getVpcPrivateGateways(long id);
}

View File

@ -1236,14 +1236,18 @@ public class VpcManagerImpl extends ManagerBase implements VpcManager, VpcProvis
}
//4) Delete private gateway
PrivateGateway gateway = getVpcPrivateGateway(vpcId);
if (gateway != null) {
s_logger.debug("Deleting private gateway " + gateway + " as a part of vpc " + vpcId + " resources cleanup");
if (!deleteVpcPrivateGateway(gateway.getId())) {
success = false;
s_logger.debug("Failed to delete private gateway " + gateway + " as a part of vpc " + vpcId + " resources cleanup");
} else {
s_logger.debug("Deleted private gateway " + gateway + " as a part of vpc " + vpcId + " resources cleanup");
List<PrivateGateway> gateways = getVpcPrivateGateways(vpcId);
if (gateways != null) {
for (PrivateGateway gateway: gateways) {
if (gateway != null) {
s_logger.debug("Deleting private gateway " + gateway + " as a part of vpc " + vpcId + " resources cleanup");
if (!deleteVpcPrivateGateway(gateway.getId())) {
success = false;
s_logger.debug("Failed to delete private gateway " + gateway + " as a part of vpc " + vpcId + " resources cleanup");
} else {
s_logger.debug("Deleted private gateway " + gateway + " as a part of vpc " + vpcId + " resources cleanup");
}
}
}
}
@ -1293,7 +1297,22 @@ public class VpcManagerImpl extends ManagerBase implements VpcManager, VpcProvis
}
}
@Override
public List<PrivateGateway> getVpcPrivateGateways(long id) {
List<VpcGatewayVO> gateways = _vpcGatewayDao.listByVpcIdAndType(id, VpcGateway.Type.Private);
if (gateways != null) {
List<PrivateGateway> pvtGateway = new ArrayList();
for (VpcGatewayVO gateway: gateways) {
pvtGateway.add(getPrivateGatewayProfile(gateway));
}
return pvtGateway;
} else {
return null;
}
}
@Override
public PrivateGateway getVpcPrivateGateway(long id) {
VpcGateway gateway = _vpcGatewayDao.findById(id);

View File

@ -378,4 +378,9 @@ public class MockVpcManagerImpl extends ManagerBase implements VpcManager {
}
@Override
public List<PrivateGateway> getVpcPrivateGateways(long id) {
return null;
}
}