mirror of
https://github.com/apache/cloudstack.git
synced 2025-11-02 20:02:29 +01:00
CLOUDSTACK-2517: fixed private gateway creation. Following fixes went in:
1) Only PrivateNetworkGuru handles network creation for the private gateway. Exluded Guest Network Guru from this list (was mistakenly included as a part of merge for Nicira integration) 2) Pass vpc_id to createNetwork call when the network is created as a part of private gateway creation 3) Fixed VPC restart when there are multiple private gateways present (have to grab all the private gateways when creating nic profiles for the VPC router that is being re-created) 4) 41-42 db upgarde: set vpc_id for the private networks of the existing VPCs
This commit is contained in:
parent
73030f4372
commit
9f59c618e2
@ -113,4 +113,6 @@ public interface NetworkDao extends GenericDao<NetworkVO, Long> , StateDao<State
|
||||
List<NetworkVO> listRedundantNetworks();
|
||||
|
||||
List<NetworkVO> listByAclId(long aclId);
|
||||
|
||||
int getNonSystemNetworkCountByVpcId(long vpcId);
|
||||
}
|
||||
|
||||
@ -162,6 +162,9 @@ public class NetworkDaoImpl extends GenericDaoBase<NetworkVO, Long> implements N
|
||||
CountBy.and("offeringId", CountBy.entity().getNetworkOfferingId(), Op.EQ);
|
||||
CountBy.and("vpcId", CountBy.entity().getVpcId(), Op.EQ);
|
||||
CountBy.and("removed", CountBy.entity().getRemoved(), Op.NULL);
|
||||
SearchBuilder<NetworkOfferingVO> ntwkOffJoin = _ntwkOffDao.createSearchBuilder();
|
||||
ntwkOffJoin.and("isSystem", ntwkOffJoin.entity().isSystemOnly(), Op.EQ);
|
||||
CountBy.join("offerings", ntwkOffJoin, CountBy.entity().getNetworkOfferingId(), ntwkOffJoin.entity().getId(), JoinBuilder.JoinType.INNER);
|
||||
CountBy.done();
|
||||
|
||||
PhysicalNetworkSearch = createSearchBuilder();
|
||||
@ -627,4 +630,14 @@ public class NetworkDaoImpl extends GenericDaoBase<NetworkVO, Long> implements N
|
||||
|
||||
return listBy(sc, null);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int getNonSystemNetworkCountByVpcId(long vpcId) {
|
||||
SearchCriteria<Integer> sc = CountBy.create();
|
||||
sc.setParameters("vpcId", vpcId);
|
||||
sc.setJoinParameters("offerings", "isSystem", false);
|
||||
List<Integer> results = customSearch(sc, null);
|
||||
return results.get(0);
|
||||
}
|
||||
}
|
||||
|
||||
@ -74,6 +74,7 @@ public class Upgrade410to420 implements DbUpgrade {
|
||||
upgradePhysicalNtwksWithInternalLbProvider(conn);
|
||||
updateNetworkACLs(conn);
|
||||
addHostDetailsIndex(conn);
|
||||
updateNetworksForPrivateGateways(conn);
|
||||
}
|
||||
|
||||
private void updateSystemVmTemplates(Connection conn) {
|
||||
@ -564,7 +565,6 @@ public class Upgrade410to420 implements DbUpgrade {
|
||||
|
||||
|
||||
private void upgradeDefaultVpcOffering(Connection conn) {
|
||||
|
||||
PreparedStatement pstmt = null;
|
||||
ResultSet rs = null;
|
||||
|
||||
@ -678,4 +678,29 @@ public class Upgrade410to420 implements DbUpgrade {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void updateNetworksForPrivateGateways(Connection conn) {
|
||||
|
||||
PreparedStatement pstmt = null;
|
||||
ResultSet rs = null;
|
||||
|
||||
try {
|
||||
//1) get all non removed gateways
|
||||
pstmt = conn.prepareStatement("SELECT network_id, vpc_id FROM `cloud`.`vpc_gateways` WHERE type='Private' AND removed IS null");
|
||||
rs = pstmt.executeQuery();
|
||||
while (rs.next()) {
|
||||
Long networkId = rs.getLong(1);
|
||||
Long vpcId = rs.getLong(2);
|
||||
//2) Update networks with vpc_id if its set to NULL
|
||||
pstmt = conn.prepareStatement("UPDATE `cloud`.`networks` set vpc_id=? where id=? and vpc_id is NULL and removed is NULL");
|
||||
pstmt.setLong(1, vpcId);
|
||||
pstmt.setLong(2, networkId);
|
||||
pstmt.executeUpdate();
|
||||
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
throw new CloudRuntimeException("Failed to update private networks with VPC id.", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -3813,7 +3813,7 @@ public class NetworkServiceImpl extends ManagerBase implements NetworkService {
|
||||
if (privateNetwork == null) {
|
||||
//create Guest network
|
||||
privateNetwork = _networkMgr.createGuestNetwork(ntwkOff.getId(), networkName, displayText, gateway, cidr, vlan,
|
||||
null, owner, null, pNtwk, pNtwk.getDataCenterId(), ACLType.Account, null, null, null, null, true);
|
||||
null, owner, null, pNtwk, pNtwk.getDataCenterId(), ACLType.Account, null, vpcId, null, null, true);
|
||||
|
||||
s_logger.debug("Created private network " + privateNetwork);
|
||||
} else {
|
||||
|
||||
@ -83,7 +83,7 @@ public class ExternalGuestNetworkGuru extends GuestNetworkGuru {
|
||||
if (networkType == NetworkType.Advanced
|
||||
&& isMyTrafficType(offering.getTrafficType())
|
||||
&& offering.getGuestType() == Network.GuestType.Isolated
|
||||
&& isMyIsolationMethod(physicalNetwork)) {
|
||||
&& isMyIsolationMethod(physicalNetwork) && !offering.isSystemOnly()) {
|
||||
return true;
|
||||
} else {
|
||||
s_logger.trace("We only take care of Guest networks of type "
|
||||
|
||||
@ -1236,12 +1236,14 @@ public class VpcVirtualNetworkApplianceManagerImpl extends VirtualNetworkApplian
|
||||
//1) allocate nic for control and source nat public ip
|
||||
networks = super.createRouterNetworks(owner, isRedundant, plan, null, sourceNatIp);
|
||||
|
||||
//2) allocate nic for private gateway if needed
|
||||
PrivateGateway privateGateway = _vpcMgr.getVpcPrivateGateway(vpcId);
|
||||
if (privateGateway != null) {
|
||||
NicProfile privateNic = createPrivateNicProfileForGateway(privateGateway);
|
||||
Network privateNetwork = _networkModel.getNetwork(privateGateway.getNetworkId());
|
||||
networks.add(new Pair<NetworkVO, NicProfile>((NetworkVO) privateNetwork, privateNic));
|
||||
//2) allocate nic for private gateways if needed
|
||||
List<PrivateGateway> privateGateways = _vpcMgr.getVpcPrivateGateways(vpcId);
|
||||
if (privateGateways != null && !privateGateways.isEmpty()) {
|
||||
for (PrivateGateway privateGateway : privateGateways) {
|
||||
NicProfile privateNic = createPrivateNicProfileForGateway(privateGateway);
|
||||
Network privateNetwork = _networkModel.getNetwork(privateGateway.getNetworkId());
|
||||
networks.add(new Pair<NetworkVO, NicProfile>((NetworkVO) privateNetwork, privateNic));
|
||||
}
|
||||
}
|
||||
|
||||
//3) allocate nic for guest gateway if needed
|
||||
|
||||
@ -166,5 +166,5 @@ public interface VpcManager extends VpcService{
|
||||
*/
|
||||
void validateNtwkOffForNtwkInVpc(Long networkId, long newNtwkOffId, String newCidr, String newNetworkDomain, Vpc vpc, String gateway, Account networkOwner);
|
||||
|
||||
List<PrivateGateway> getVpcPrivateGateways(long id);
|
||||
List<PrivateGateway> getVpcPrivateGateways(long vpcId);
|
||||
}
|
||||
|
||||
@ -711,8 +711,9 @@ public class VpcManagerImpl extends ManagerBase implements VpcManager, VpcProvis
|
||||
public boolean destroyVpc(Vpc vpc, Account caller, Long callerUserId) throws ConcurrentOperationException, ResourceUnavailableException {
|
||||
s_logger.debug("Destroying vpc " + vpc);
|
||||
|
||||
//don't allow to delete vpc if it's in use by existing networks
|
||||
int networksCount = _ntwkDao.getNetworkCountByVpcId(vpc.getId());
|
||||
//don't allow to delete vpc if it's in use by existing non system networks (system networks are networks of a private gateway of the VPC,
|
||||
//and they will get removed as a part of VPC cleanup
|
||||
int networksCount = _ntwkDao.getNonSystemNetworkCountByVpcId(vpc.getId());
|
||||
if (networksCount > 0) {
|
||||
throw new InvalidParameterValueException("Can't delete VPC " + vpc + " as its used by " + networksCount + " networks");
|
||||
}
|
||||
@ -1235,7 +1236,7 @@ public class VpcManagerImpl extends ManagerBase implements VpcManager, VpcProvis
|
||||
return false;
|
||||
}
|
||||
|
||||
//4) Delete private gateway
|
||||
//4) Delete private gateways
|
||||
List<PrivateGateway> gateways = getVpcPrivateGateways(vpcId);
|
||||
if (gateways != null) {
|
||||
for (PrivateGateway gateway: gateways) {
|
||||
@ -1299,8 +1300,8 @@ public class VpcManagerImpl extends ManagerBase implements VpcManager, VpcProvis
|
||||
|
||||
|
||||
@Override
|
||||
public List<PrivateGateway> getVpcPrivateGateways(long id) {
|
||||
List<VpcGatewayVO> gateways = _vpcGatewayDao.listByVpcIdAndType(id, VpcGateway.Type.Private);
|
||||
public List<PrivateGateway> getVpcPrivateGateways(long vpcId) {
|
||||
List<VpcGatewayVO> gateways = _vpcGatewayDao.listByVpcIdAndType(vpcId, VpcGateway.Type.Private);
|
||||
|
||||
if (gateways != null) {
|
||||
List<PrivateGateway> pvtGateway = new ArrayList();
|
||||
|
||||
@ -379,7 +379,7 @@ public class MockVpcManagerImpl extends ManagerBase implements VpcManager {
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<PrivateGateway> getVpcPrivateGateways(long id) {
|
||||
public List<PrivateGateway> getVpcPrivateGateways(long vpcId) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@ -367,4 +367,9 @@ public class MockNetworkDaoImpl extends GenericDaoBase<NetworkVO, Long> implemen
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int getNonSystemNetworkCountByVpcId(long vpcId) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user