mirror of https://github.com/apache/cloudstack.git
Fix dependency problem. Extract and unify router deployment stuff
Conflicts: server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java
This commit is contained in:
parent
bca81b0573
commit
705ced3a84
|
|
@ -190,6 +190,8 @@
|
|||
class="com.cloud.network.router.NetworkGeneralHelper" />
|
||||
<bean id="vpcVirtualNetworkHelper"
|
||||
class="com.cloud.network.router.VpcVirtualNetworkHelperImpl" />
|
||||
<bean id="routerDeploymentManager"
|
||||
class="com.cloud.network.router.RouterDeploymentManager" />
|
||||
|
||||
|
||||
<bean id="ApiAsyncJobDispatcher" class="com.cloud.api.ApiAsyncJobDispatcher">
|
||||
|
|
|
|||
|
|
@ -69,6 +69,7 @@ import com.cloud.network.dao.VirtualRouterProviderDao;
|
|||
import com.cloud.network.lb.LoadBalancingRule;
|
||||
import com.cloud.network.lb.LoadBalancingRule.LbStickinessPolicy;
|
||||
import com.cloud.network.lb.LoadBalancingRulesManager;
|
||||
import com.cloud.network.router.RouterDeploymentDefinition;
|
||||
import com.cloud.network.router.VirtualRouter;
|
||||
import com.cloud.network.router.VirtualRouter.Role;
|
||||
import com.cloud.network.router.VpcVirtualNetworkApplianceManager;
|
||||
|
|
@ -196,9 +197,11 @@ NetworkMigrationResponder, AggregatedCommandExecutor {
|
|||
Map<VirtualMachineProfile.Param, Object> params = new HashMap<VirtualMachineProfile.Param, Object>(1);
|
||||
params.put(VirtualMachineProfile.Param.ReProgramGuestNetworks, true);
|
||||
|
||||
List<DomainRouterVO> routers = _routerMgr.deployVirtualRouterInGuestNetwork(network, dest,
|
||||
_accountMgr.getAccount(network.getAccountId()), params,
|
||||
offering.getRedundantRouter());
|
||||
RouterDeploymentDefinition routerDeploymentDefinition =
|
||||
new RouterDeploymentDefinition(network, dest,_accountMgr.getAccount(network.getAccountId()),
|
||||
params, offering.getRedundantRouter());
|
||||
List<DomainRouterVO> routers = _routerMgr.deployVirtualRouter(routerDeploymentDefinition);
|
||||
|
||||
int routerCounts = 1;
|
||||
if (offering.getRedundantRouter()) {
|
||||
routerCounts = 2;
|
||||
|
|
@ -230,11 +233,12 @@ NetworkMigrationResponder, AggregatedCommandExecutor {
|
|||
return false;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
VirtualMachineProfile uservm = vm;
|
||||
RouterDeploymentDefinition routerDeploymentDefinition =
|
||||
new RouterDeploymentDefinition(network, dest,_accountMgr.getAccount(network.getAccountId()),
|
||||
vm.getParameters(), offering.getRedundantRouter());
|
||||
List<DomainRouterVO> routers =
|
||||
_routerMgr.deployVirtualRouterInGuestNetwork(network, dest, _accountMgr.getAccount(network.getAccountId()), uservm.getParameters(),
|
||||
offering.getRedundantRouter());
|
||||
_routerMgr.deployVirtualRouter(routerDeploymentDefinition);
|
||||
|
||||
if (routers == null || routers.size() == 0) {
|
||||
throw new ResourceUnavailableException("Can't find at least one running router!", DataCenter.class, network.getDataCenterId());
|
||||
}
|
||||
|
|
|
|||
|
|
@ -47,6 +47,7 @@ import com.cloud.network.VpnUser;
|
|||
import com.cloud.network.dao.IPAddressDao;
|
||||
import com.cloud.network.dao.NetworkDao;
|
||||
import com.cloud.network.dao.Site2SiteVpnGatewayDao;
|
||||
import com.cloud.network.router.RouterDeploymentDefinition;
|
||||
import com.cloud.network.router.VirtualRouter;
|
||||
import com.cloud.network.router.VirtualRouter.Role;
|
||||
import com.cloud.network.router.VpcVirtualNetworkApplianceManager;
|
||||
|
|
@ -131,7 +132,9 @@ public class VpcVirtualRouterElement extends VirtualRouterElement implements Vpc
|
|||
Map<VirtualMachineProfile.Param, Object> params = new HashMap<VirtualMachineProfile.Param, Object>(1);
|
||||
params.put(VirtualMachineProfile.Param.ReProgramGuestNetworks, true);
|
||||
|
||||
_vpcRouterMgr.deployVirtualRouterInVpc(vpc, dest, _accountMgr.getAccount(vpc.getAccountId()), params);
|
||||
RouterDeploymentDefinition routerDeploymentDefinition =
|
||||
new RouterDeploymentDefinition(vpc, dest, _accountMgr.getAccount(vpc.getAccountId()), params, false);
|
||||
_vpcRouterMgr.deployVirtualRouter(routerDeploymentDefinition);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
@ -168,7 +171,9 @@ public class VpcVirtualRouterElement extends VirtualRouterElement implements Vpc
|
|||
Map<VirtualMachineProfile.Param, Object> params = new HashMap<VirtualMachineProfile.Param, Object>(1);
|
||||
params.put(VirtualMachineProfile.Param.ReProgramGuestNetworks, true);
|
||||
|
||||
List<DomainRouterVO> routers = _vpcRouterMgr.deployVirtualRouterInVpc(vpc, dest, _accountMgr.getAccount(vpc.getAccountId()), params);
|
||||
RouterDeploymentDefinition routerDeploymentDefinition =
|
||||
new RouterDeploymentDefinition(vpc, dest, _accountMgr.getAccount(vpc.getAccountId()), params, false);
|
||||
List<DomainRouterVO> routers = _vpcRouterMgr.deployVirtualRouter(routerDeploymentDefinition);
|
||||
if ((routers == null) || (routers.size() == 0)) {
|
||||
throw new ResourceUnavailableException("Can't find at least one running router!", DataCenter.class, network.getDataCenterId());
|
||||
}
|
||||
|
|
@ -213,7 +218,9 @@ public class VpcVirtualRouterElement extends VirtualRouterElement implements Vpc
|
|||
if (vm.getType() == VirtualMachine.Type.User) {
|
||||
Map<VirtualMachineProfile.Param, Object> params = new HashMap<VirtualMachineProfile.Param, Object>(1);
|
||||
params.put(VirtualMachineProfile.Param.ReProgramGuestNetworks, true);
|
||||
List<DomainRouterVO> routers = _vpcRouterMgr.deployVirtualRouterInVpc(vpc, dest, _accountMgr.getAccount(vpc.getAccountId()), params);
|
||||
RouterDeploymentDefinition routerDeploymentDefinition =
|
||||
new RouterDeploymentDefinition(vpc, dest, _accountMgr.getAccount(vpc.getAccountId()), params, false);
|
||||
List<DomainRouterVO> routers = _vpcRouterMgr.deployVirtualRouter(routerDeploymentDefinition);
|
||||
if ((routers == null) || (routers.size() == 0)) {
|
||||
throw new ResourceUnavailableException("Can't find at least one running router!", DataCenter.class, network.getDataCenterId());
|
||||
}
|
||||
|
|
|
|||
|
|
@ -393,10 +393,8 @@ public class NetworkGeneralHelper {
|
|||
|
||||
|
||||
// @Override
|
||||
public DomainRouterVO deployRouter(Account owner,
|
||||
DeployDestination dest, DeploymentPlan plan,
|
||||
Map<Param, Object> params, boolean isRedundant,
|
||||
VirtualRouterProvider vrProvider, long svcOffId, Long vpcId,
|
||||
public DomainRouterVO deployRouter(final RouterDeploymentDefinition routerDeploymentDefinition,
|
||||
VirtualRouterProvider vrProvider, long svcOffId,
|
||||
LinkedHashMap<Network, List<? extends NicProfile>> networks,
|
||||
boolean startRouter, List<HypervisorType> supportedHypervisors)
|
||||
throws InsufficientAddressCapacityException,
|
||||
|
|
@ -404,10 +402,12 @@ public class NetworkGeneralHelper {
|
|||
StorageUnavailableException, ResourceUnavailableException {
|
||||
|
||||
final ServiceOfferingVO routerOffering = _serviceOfferingDao.findById(svcOffId);
|
||||
final DeployDestination dest = routerDeploymentDefinition.getDest();
|
||||
final Account owner = routerDeploymentDefinition.getOwner();
|
||||
|
||||
// Router is the network element, we don't know the hypervisor type yet.
|
||||
// Try to allocate the domR twice using diff hypervisors, and when failed both times, throw the exception up
|
||||
final List<HypervisorType> hypervisors = getHypervisors(dest, plan, supportedHypervisors);
|
||||
final List<HypervisorType> hypervisors = getHypervisors(routerDeploymentDefinition, supportedHypervisors);
|
||||
|
||||
int allocateRetry = 0;
|
||||
int startRetry = 0;
|
||||
|
|
@ -449,19 +449,18 @@ public class NetworkGeneralHelper {
|
|||
|
||||
boolean offerHA = routerOffering.getOfferHA();
|
||||
/* We don't provide HA to redundant router VMs, admin should own it all, and redundant router themselves are HA */
|
||||
if (isRedundant) {
|
||||
if (routerDeploymentDefinition.isRedundant()) {
|
||||
offerHA = false;
|
||||
}
|
||||
|
||||
router =
|
||||
new DomainRouterVO(id, routerOffering.getId(), vrProvider.getId(),
|
||||
VirtualMachineName.getRouterName(id, VirtualNwStatus.instance), template.getId(), template.getHypervisorType(),
|
||||
template.getGuestOSId(), owner.getDomainId(), owner.getId(), isRedundant, 0, false, RedundantState.UNKNOWN,
|
||||
offerHA, false, vpcId);
|
||||
router = new DomainRouterVO(id, routerOffering.getId(), vrProvider.getId(),
|
||||
VirtualMachineName.getRouterName(id, VirtualNwStatus.instance), template.getId(), template.getHypervisorType(),
|
||||
template.getGuestOSId(), owner.getDomainId(), owner.getId(), routerDeploymentDefinition.isRedundant(), 0,
|
||||
false, RedundantState.UNKNOWN, offerHA, false, routerDeploymentDefinition.getVpc().getId());
|
||||
router.setDynamicallyScalable(template.isDynamicallyScalable());
|
||||
router.setRole(Role.VIRTUAL_ROUTER);
|
||||
router = _routerDao.persist(router);
|
||||
_itMgr.allocate(router.getInstanceName(), template, routerOffering, networks, plan, null);
|
||||
_itMgr.allocate(router.getInstanceName(), template, routerOffering, networks, routerDeploymentDefinition.getPlan(), null);
|
||||
router = _routerDao.findById(router.getId());
|
||||
} catch (final InsufficientCapacityException ex) {
|
||||
if (allocateRetry < 2 && iter.hasNext()) {
|
||||
|
|
@ -476,7 +475,7 @@ public class NetworkGeneralHelper {
|
|||
|
||||
if (startRouter) {
|
||||
try {
|
||||
router = startVirtualRouter(router, _accountMgr.getSystemUser(), _accountMgr.getSystemAccount(), params);
|
||||
router = startVirtualRouter(router, _accountMgr.getSystemUser(), _accountMgr.getSystemAccount(), routerDeploymentDefinition.getParams());
|
||||
break;
|
||||
} catch (final InsufficientCapacityException ex) {
|
||||
if (startRetry < 2 && iter.hasNext()) {
|
||||
|
|
@ -499,8 +498,9 @@ public class NetworkGeneralHelper {
|
|||
return router;
|
||||
}
|
||||
|
||||
protected List<HypervisorType> getHypervisors(final DeployDestination dest, final DeploymentPlan plan, final List<HypervisorType> supportedHypervisors)
|
||||
protected List<HypervisorType> getHypervisors(final RouterDeploymentDefinition routerDeploymentDefinition, final List<HypervisorType> supportedHypervisors)
|
||||
throws InsufficientServerCapacityException {
|
||||
final DeployDestination dest = routerDeploymentDefinition.getDest();
|
||||
List<HypervisorType> hypervisors = new ArrayList<HypervisorType>();
|
||||
|
||||
if (dest.getCluster() != null) {
|
||||
|
|
@ -515,7 +515,7 @@ public class NetworkGeneralHelper {
|
|||
hypervisors.add(defaults);
|
||||
} else {
|
||||
//if there is no default hypervisor, get it from the cluster
|
||||
hypervisors = _resourceMgr.getSupportedHypervisorTypes(dest.getDataCenter().getId(), true, plan.getPodId());
|
||||
hypervisors = _resourceMgr.getSupportedHypervisorTypes(dest.getDataCenter().getId(), true, routerDeploymentDefinition.getPodId());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -530,9 +530,9 @@ public class NetworkGeneralHelper {
|
|||
|
||||
if (hypervisors.isEmpty()) {
|
||||
final String errMsg = (hTypesStr.capacity() > 0) ? "supporting hypervisors " + hTypesStr.toString() : "";
|
||||
if (plan.getPodId() != null) {
|
||||
if (routerDeploymentDefinition.getPodId() != null) {
|
||||
throw new InsufficientServerCapacityException("Unable to create virtual router, " + "there are no clusters in the pod " + errMsg, Pod.class,
|
||||
plan.getPodId());
|
||||
routerDeploymentDefinition.getPodId());
|
||||
}
|
||||
throw new InsufficientServerCapacityException("Unable to create virtual router, " + "there are no clusters in the zone " + errMsg, DataCenter.class,
|
||||
dest.getDataCenter().getId());
|
||||
|
|
@ -564,16 +564,19 @@ public class NetworkGeneralHelper {
|
|||
}
|
||||
|
||||
final String errMsg =
|
||||
"Cannot find an available cluster in Pod " + podId + " to start domain router for Ovm. \n Ovm won't support any system vm including domain router, " +
|
||||
"please make sure you have a cluster with hypervisor type of any of xenserver/KVM/Vmware in the same pod" +
|
||||
" with Ovm cluster. And there is at least one host in UP status in that cluster.";
|
||||
new StringBuilder("Cannot find an available cluster in Pod ")
|
||||
.append(podId)
|
||||
.append(" to start domain router for Ovm. \n Ovm won't support any system vm including domain router, ")
|
||||
.append("please make sure you have a cluster with hypervisor type of any of xenserver/KVM/Vmware in the same pod")
|
||||
.append(" with Ovm cluster. And there is at least one host in UP status in that cluster.")
|
||||
.toString();
|
||||
throw new CloudRuntimeException(errMsg);
|
||||
}
|
||||
|
||||
|
||||
// @Override
|
||||
public LinkedHashMap<Network, List<? extends NicProfile>> createRouterNetworks(
|
||||
Account owner, boolean isRedundant, DeploymentPlan plan,
|
||||
final RouterDeploymentDefinition routerDeploymentDefinition,
|
||||
Network guestNetwork, Pair<Boolean, PublicIp> publicNetwork)
|
||||
throws ConcurrentOperationException,
|
||||
InsufficientAddressCapacityException {
|
||||
|
|
@ -595,7 +598,7 @@ public class NetworkGeneralHelper {
|
|||
if (!setupPublicNetwork) {
|
||||
final Nic placeholder = _networkModel
|
||||
.getPlaceholderNicForRouter(guestNetwork,
|
||||
plan.getPodId());
|
||||
routerDeploymentDefinition.getPodId());
|
||||
if (guestNetwork.getCidr() != null) {
|
||||
if (placeholder != null
|
||||
&& placeholder.getIp4Address() != null) {
|
||||
|
|
@ -651,7 +654,7 @@ public class NetworkGeneralHelper {
|
|||
final NicProfile gatewayNic = new NicProfile(defaultNetworkStartIp,
|
||||
defaultNetworkStartIpv6);
|
||||
if (setupPublicNetwork) {
|
||||
if (isRedundant) {
|
||||
if (routerDeploymentDefinition.isRedundant()) {
|
||||
gatewayNic.setIp4Address(_ipAddrMgr.acquireGuestIpAddress(
|
||||
guestNetwork, null));
|
||||
} else {
|
||||
|
|
@ -679,7 +682,7 @@ public class NetworkGeneralHelper {
|
|||
.getSystemAccountNetworkOfferings(NetworkOffering.SystemControlNetwork);
|
||||
NetworkOffering controlOffering = offerings.get(0);
|
||||
Network controlConfig = _networkMgr.setupNetwork(VirtualNwStatus.account,
|
||||
controlOffering, plan, null, null, false).get(0);
|
||||
controlOffering, routerDeploymentDefinition.getPlan(), null, null, false).get(0);
|
||||
networks.put(controlConfig, new ArrayList<NicProfile>());
|
||||
// 3) Public network
|
||||
if (setupPublicNetwork) {
|
||||
|
|
@ -716,8 +719,8 @@ public class NetworkGeneralHelper {
|
|||
.getSystemAccountNetworkOfferings(
|
||||
NetworkOffering.SystemPublicNetwork).get(0);
|
||||
final List<? extends Network> publicNetworks = _networkMgr
|
||||
.setupNetwork(VirtualNwStatus.account, publicOffering, plan, null,
|
||||
null, false);
|
||||
.setupNetwork(VirtualNwStatus.account, publicOffering, routerDeploymentDefinition.getPlan(),
|
||||
null, null, false);
|
||||
final String publicIp = defaultNic.getIp4Address();
|
||||
// We want to use the identical MAC address for RvR on public
|
||||
// interface if possible
|
||||
|
|
|
|||
|
|
@ -0,0 +1,93 @@
|
|||
package com.cloud.network.router;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import com.cloud.deploy.DeployDestination;
|
||||
import com.cloud.deploy.DeploymentPlan;
|
||||
import com.cloud.network.Network;
|
||||
import com.cloud.network.vpc.Vpc;
|
||||
import com.cloud.user.Account;
|
||||
import com.cloud.vm.VirtualMachineProfile.Param;
|
||||
|
||||
public class RouterDeploymentDefinition {
|
||||
|
||||
protected Vpc vpc;
|
||||
protected Network guestNetwork;
|
||||
protected DeployDestination dest;
|
||||
protected Account owner;
|
||||
protected Map<Param, Object> params;
|
||||
protected boolean isRedundant;
|
||||
protected DeploymentPlan plan;
|
||||
|
||||
public RouterDeploymentDefinition(Vpc vpc, DeployDestination dest,
|
||||
Account owner, Map<Param, Object> params,
|
||||
boolean isRedundant) {
|
||||
|
||||
this.vpc = vpc;
|
||||
this.dest = dest;
|
||||
this.owner = owner;
|
||||
this.params = params;
|
||||
this.isRedundant = isRedundant;
|
||||
}
|
||||
|
||||
public RouterDeploymentDefinition(Network guestNetwork, DeployDestination dest,
|
||||
Account owner, Map<Param, Object> params, boolean isRedundant) {
|
||||
|
||||
this.guestNetwork = guestNetwork;
|
||||
this.dest = dest;
|
||||
this.owner = owner;
|
||||
this.params = params;
|
||||
this.isRedundant = isRedundant;
|
||||
}
|
||||
|
||||
public Vpc getVpc() {
|
||||
return vpc;
|
||||
}
|
||||
public void setVpc(Vpc vpc) {
|
||||
this.vpc = vpc;
|
||||
}
|
||||
public Network getGuestNetwork() {
|
||||
return guestNetwork;
|
||||
}
|
||||
public void setGuestNetwork(Network guestNetwork) {
|
||||
this.guestNetwork = guestNetwork;
|
||||
}
|
||||
public DeployDestination getDest() {
|
||||
return dest;
|
||||
}
|
||||
public void setDest(DeployDestination dest) {
|
||||
this.dest = dest;
|
||||
}
|
||||
public Account getOwner() {
|
||||
return owner;
|
||||
}
|
||||
public void setOwner(Account owner) {
|
||||
this.owner = owner;
|
||||
}
|
||||
public Map<Param, Object> getParams() {
|
||||
return params;
|
||||
}
|
||||
public void setParams(Map<Param, Object> params) {
|
||||
this.params = params;
|
||||
}
|
||||
public boolean isRedundant() {
|
||||
return isRedundant;
|
||||
}
|
||||
public void setRedundant(boolean isRedundant) {
|
||||
this.isRedundant = isRedundant;
|
||||
}
|
||||
public DeploymentPlan getPlan() {
|
||||
return plan;
|
||||
}
|
||||
public void setPlan(DeploymentPlan plan) {
|
||||
this.plan = plan;
|
||||
}
|
||||
|
||||
public boolean isVpcRouter() {
|
||||
return this.vpc != null;
|
||||
}
|
||||
public Long getPodId() {
|
||||
return this.plan.getPodId();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,271 @@
|
|||
package com.cloud.network.router;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.TreeSet;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import org.apache.cloudstack.engine.orchestration.service.NetworkOrchestrationService;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import com.cloud.dc.dao.VlanDao;
|
||||
import com.cloud.deploy.DataCenterDeployment;
|
||||
import com.cloud.deploy.DeploymentPlan;
|
||||
import com.cloud.exception.ConcurrentOperationException;
|
||||
import com.cloud.exception.InsufficientAddressCapacityException;
|
||||
import com.cloud.exception.InsufficientCapacityException;
|
||||
import com.cloud.exception.InsufficientServerCapacityException;
|
||||
import com.cloud.exception.ResourceUnavailableException;
|
||||
import com.cloud.exception.StorageUnavailableException;
|
||||
import com.cloud.network.IpAddress;
|
||||
import com.cloud.network.Network;
|
||||
import com.cloud.network.NetworkModel;
|
||||
import com.cloud.network.Networks.BroadcastDomainType;
|
||||
import com.cloud.network.Networks.IsolationType;
|
||||
import com.cloud.network.PhysicalNetwork;
|
||||
import com.cloud.network.PhysicalNetworkServiceProvider;
|
||||
import com.cloud.network.VirtualRouterProvider;
|
||||
import com.cloud.network.VirtualRouterProvider.Type;
|
||||
import com.cloud.network.addr.PublicIp;
|
||||
import com.cloud.network.dao.IPAddressDao;
|
||||
import com.cloud.network.dao.IPAddressVO;
|
||||
import com.cloud.network.dao.PhysicalNetworkDao;
|
||||
import com.cloud.network.dao.PhysicalNetworkServiceProviderDao;
|
||||
import com.cloud.network.dao.VirtualRouterProviderDao;
|
||||
import com.cloud.network.vpc.PrivateGateway;
|
||||
import com.cloud.network.vpc.Vpc;
|
||||
import com.cloud.network.vpc.VpcManager;
|
||||
import com.cloud.network.vpc.dao.VpcDao;
|
||||
import com.cloud.network.vpc.dao.VpcOfferingDao;
|
||||
import com.cloud.offering.NetworkOffering;
|
||||
import com.cloud.service.ServiceOfferingVO;
|
||||
import com.cloud.utils.Pair;
|
||||
import com.cloud.utils.db.DB;
|
||||
import com.cloud.utils.exception.CloudRuntimeException;
|
||||
import com.cloud.utils.net.NetUtils;
|
||||
import com.cloud.vm.DomainRouterVO;
|
||||
import com.cloud.vm.NicProfile;
|
||||
|
||||
public class RouterDeploymentManager {
|
||||
|
||||
private static final Logger logger = Logger.getLogger(RouterDeploymentManager.class);
|
||||
|
||||
@Inject
|
||||
VpcDao vpcDao;
|
||||
@Inject
|
||||
VpcOfferingDao vpcOffDao;
|
||||
@Inject
|
||||
PhysicalNetworkDao pNtwkDao;
|
||||
@Inject
|
||||
VpcManager vpcMgr;
|
||||
@Inject
|
||||
PhysicalNetworkServiceProviderDao physicalProviderDao;
|
||||
@Inject
|
||||
VlanDao vlanDao;
|
||||
@Inject
|
||||
IPAddressDao ipAddressDao;
|
||||
@Inject
|
||||
NetworkOrchestrationService networkMgr;
|
||||
@Inject
|
||||
NetworkModel networkModel;
|
||||
@Inject
|
||||
VirtualRouterProviderDao vrProviderDao;
|
||||
|
||||
@Inject
|
||||
protected NetworkGeneralHelper nwHelper;
|
||||
@Inject
|
||||
protected VpcVirtualNetworkHelperImpl vpcHelper;
|
||||
|
||||
|
||||
protected ServiceOfferingVO _offering;
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////
|
||||
// Non-VPC behavior
|
||||
///////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////
|
||||
// VPC Specific behavior
|
||||
///////////////////////////////////////////////////////////////////////
|
||||
|
||||
public List<DomainRouterVO> deployVirtualRouterInVpc(final RouterDeploymentDefinition routerDeploymentDefinition)
|
||||
throws InsufficientCapacityException,
|
||||
ConcurrentOperationException, ResourceUnavailableException {
|
||||
|
||||
List<DomainRouterVO> routers = this.findOrDeployVirtualRouterInVpc(routerDeploymentDefinition);
|
||||
|
||||
return this.nwHelper.startRouters(routerDeploymentDefinition.getParams(), routers);
|
||||
}
|
||||
|
||||
@DB
|
||||
protected List<DomainRouterVO> findOrDeployVirtualRouterInVpc(final RouterDeploymentDefinition routerDeploymentDefinition)
|
||||
throws ConcurrentOperationException, InsufficientCapacityException, ResourceUnavailableException {
|
||||
|
||||
final Vpc vpc = routerDeploymentDefinition.getVpc();
|
||||
logger.debug("Deploying Virtual Router in VPC " + vpc);
|
||||
Vpc vpcLock = vpcDao.acquireInLockTable(vpc.getId());
|
||||
if (vpcLock == null) {
|
||||
throw new ConcurrentOperationException("Unable to lock vpc " + vpc.getId());
|
||||
}
|
||||
|
||||
//1) Get deployment plan and find out the list of routers
|
||||
Pair<DeploymentPlan, List<DomainRouterVO>> planAndRouters = getDeploymentPlanAndRouters(routerDeploymentDefinition);
|
||||
DeploymentPlan plan = planAndRouters.first();
|
||||
List<DomainRouterVO> routers = planAndRouters.second();
|
||||
try {
|
||||
//2) Return routers if exist
|
||||
if (routers.size() >= 1) {
|
||||
return routers;
|
||||
}
|
||||
|
||||
Long offeringId = vpcOffDao.findById(vpc.getVpcOfferingId()).getServiceOfferingId();
|
||||
if (offeringId == null) {
|
||||
offeringId = _offering.getId();
|
||||
}
|
||||
//3) Deploy Virtual Router
|
||||
List<? extends PhysicalNetwork> pNtwks = pNtwkDao.listByZone(vpc.getZoneId());
|
||||
|
||||
VirtualRouterProvider vpcVrProvider = null;
|
||||
|
||||
for (PhysicalNetwork pNtwk : pNtwks) {
|
||||
PhysicalNetworkServiceProvider provider = physicalProviderDao.findByServiceProvider(pNtwk.getId(), Type.VPCVirtualRouter.toString());
|
||||
if (provider == null) {
|
||||
throw new CloudRuntimeException("Cannot find service provider " + Type.VPCVirtualRouter.toString() + " in physical network " + pNtwk.getId());
|
||||
}
|
||||
vpcVrProvider = vrProviderDao.findByNspIdAndType(provider.getId(), Type.VPCVirtualRouter);
|
||||
if (vpcVrProvider != null) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
PublicIp sourceNatIp = vpcMgr.assignSourceNatIpAddressToVpc(routerDeploymentDefinition.getOwner(), vpc);
|
||||
|
||||
DomainRouterVO router = deployVpcRouter(routerDeploymentDefinition, vpcVrProvider, offeringId, sourceNatIp);
|
||||
routers.add(router);
|
||||
|
||||
} finally {
|
||||
// TODO Should we do this after the pre or after the whole??
|
||||
if (vpcLock != null) {
|
||||
vpcDao.releaseFromLockTable(vpc.getId());
|
||||
}
|
||||
}
|
||||
return routers;
|
||||
}
|
||||
|
||||
protected Pair<DeploymentPlan, List<DomainRouterVO>> getDeploymentPlanAndRouters(final RouterDeploymentDefinition routerDeploymentDefinition) {
|
||||
long dcId = routerDeploymentDefinition.getDest().getDataCenter().getId();
|
||||
|
||||
DeploymentPlan plan = new DataCenterDeployment(dcId);
|
||||
List<DomainRouterVO> routers = this.vpcHelper.getVpcRouters(routerDeploymentDefinition.getVpc().getId());
|
||||
|
||||
return new Pair<DeploymentPlan, List<DomainRouterVO>>(plan, routers);
|
||||
}
|
||||
|
||||
|
||||
protected DomainRouterVO deployVpcRouter(final RouterDeploymentDefinition routerDeploymentDefinition, VirtualRouterProvider vrProvider,
|
||||
long svcOffId, PublicIp sourceNatIp) throws ConcurrentOperationException, InsufficientAddressCapacityException,
|
||||
InsufficientServerCapacityException, InsufficientCapacityException, StorageUnavailableException, ResourceUnavailableException {
|
||||
|
||||
LinkedHashMap<Network, List<? extends NicProfile>> networks = createVpcRouterNetworks(routerDeploymentDefinition,
|
||||
new Pair<Boolean, PublicIp>(true, sourceNatIp), routerDeploymentDefinition.getVpc().getId());
|
||||
|
||||
DomainRouterVO router =
|
||||
this.nwHelper.deployRouter(routerDeploymentDefinition, vrProvider, svcOffId, networks, true, vpcMgr.getSupportedVpcHypervisors());
|
||||
|
||||
return router;
|
||||
}
|
||||
|
||||
protected LinkedHashMap<Network, List<? extends NicProfile>> createVpcRouterNetworks(final RouterDeploymentDefinition routerDeploymentDefinition,
|
||||
Pair<Boolean, PublicIp> sourceNatIp, long vpcId)
|
||||
throws ConcurrentOperationException, InsufficientAddressCapacityException {
|
||||
|
||||
LinkedHashMap<Network, List<? extends NicProfile>> networks = new LinkedHashMap<Network, List<? extends NicProfile>>(4);
|
||||
|
||||
TreeSet<String> publicVlans = new TreeSet<String>();
|
||||
publicVlans.add(sourceNatIp.second().getVlanTag());
|
||||
|
||||
//1) allocate nic for control and source nat public ip
|
||||
networks = this.nwHelper.createRouterNetworks(routerDeploymentDefinition, null, sourceNatIp);
|
||||
|
||||
|
||||
//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 = this.vpcHelper.createPrivateNicProfileForGateway(privateGateway);
|
||||
Network privateNetwork = networkModel.getNetwork(privateGateway.getNetworkId());
|
||||
networks.put(privateNetwork, new ArrayList<NicProfile>(Arrays.asList(privateNic)));
|
||||
}
|
||||
}
|
||||
|
||||
//3) allocate nic for guest gateway if needed
|
||||
List<? extends Network> guestNetworks = vpcMgr.getVpcNetworks(vpcId);
|
||||
for (Network guestNetwork : guestNetworks) {
|
||||
if (networkModel.isPrivateGateway(guestNetwork.getId())) {
|
||||
continue;
|
||||
}
|
||||
if (guestNetwork.getState() == Network.State.Implemented || guestNetwork.getState() == Network.State.Setup) {
|
||||
NicProfile guestNic = createGuestNicProfileForVpcRouter(guestNetwork);
|
||||
networks.put(guestNetwork, new ArrayList<NicProfile>(Arrays.asList(guestNic)));
|
||||
}
|
||||
}
|
||||
|
||||
//4) allocate nic for additional public network(s)
|
||||
List<IPAddressVO> ips = ipAddressDao.listByAssociatedVpc(vpcId, false);
|
||||
List<NicProfile> publicNics = new ArrayList<NicProfile>();
|
||||
Network publicNetwork = null;
|
||||
for (IPAddressVO ip : ips) {
|
||||
PublicIp publicIp = PublicIp.createFromAddrAndVlan(ip, vlanDao.findById(ip.getVlanId()));
|
||||
if ((ip.getState() == IpAddress.State.Allocated || ip.getState() == IpAddress.State.Allocating) && vpcMgr.isIpAllocatedToVpc(ip) &&
|
||||
!publicVlans.contains(publicIp.getVlanTag())) {
|
||||
logger.debug("Allocating nic for router in vlan " + publicIp.getVlanTag());
|
||||
NicProfile publicNic = new NicProfile();
|
||||
publicNic.setDefaultNic(false);
|
||||
publicNic.setIp4Address(publicIp.getAddress().addr());
|
||||
publicNic.setGateway(publicIp.getGateway());
|
||||
publicNic.setNetmask(publicIp.getNetmask());
|
||||
publicNic.setMacAddress(publicIp.getMacAddress());
|
||||
publicNic.setBroadcastType(BroadcastDomainType.Vlan);
|
||||
publicNic.setBroadcastUri(BroadcastDomainType.Vlan.toUri(publicIp.getVlanTag()));
|
||||
publicNic.setIsolationUri(IsolationType.Vlan.toUri(publicIp.getVlanTag()));
|
||||
NetworkOffering publicOffering = networkModel.getSystemAccountNetworkOfferings(NetworkOffering.SystemPublicNetwork).get(0);
|
||||
if (publicNetwork == null) {
|
||||
List<? extends Network> publicNetworks = networkMgr.setupNetwork(VirtualNwStatus.account,
|
||||
publicOffering, routerDeploymentDefinition.getPlan(), null, null, false);
|
||||
publicNetwork = publicNetworks.get(0);
|
||||
}
|
||||
publicNics.add(publicNic);
|
||||
publicVlans.add(publicIp.getVlanTag());
|
||||
}
|
||||
}
|
||||
if (publicNetwork != null) {
|
||||
if (networks.get(publicNetwork) != null) {
|
||||
List<NicProfile> publicNicProfiles = (List<NicProfile>)networks.get(publicNetwork);
|
||||
publicNicProfiles.addAll(publicNics);
|
||||
networks.put(publicNetwork, publicNicProfiles);
|
||||
} else {
|
||||
networks.put(publicNetwork, publicNics);
|
||||
}
|
||||
}
|
||||
|
||||
return networks;
|
||||
}
|
||||
|
||||
protected NicProfile createGuestNicProfileForVpcRouter(Network guestNetwork) {
|
||||
NicProfile guestNic = new NicProfile();
|
||||
guestNic.setIp4Address(guestNetwork.getGateway());
|
||||
guestNic.setBroadcastUri(guestNetwork.getBroadcastUri());
|
||||
guestNic.setBroadcastType(guestNetwork.getBroadcastDomainType());
|
||||
guestNic.setIsolationUri(guestNetwork.getBroadcastUri());
|
||||
guestNic.setMode(guestNetwork.getMode());
|
||||
String gatewayCidr = guestNetwork.getCidr();
|
||||
guestNic.setNetmask(NetUtils.getCidrNetmask(gatewayCidr));
|
||||
|
||||
return guestNic;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -17,7 +17,6 @@
|
|||
package com.cloud.network.router;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.cloudstack.framework.config.ConfigKey;
|
||||
|
||||
|
|
@ -98,8 +97,8 @@ public interface VirtualNetworkApplianceManager extends Manager, VirtualNetworkA
|
|||
boolean saveUserDataToRouter(Network network, NicProfile nic, VirtualMachineProfile profile, List<? extends VirtualRouter> routers)
|
||||
throws ResourceUnavailableException;
|
||||
|
||||
List<DomainRouterVO> deployVirtualRouterInGuestNetwork(Network guestNetwork, DeployDestination dest, Account owner, Map<VirtualMachineProfile.Param, Object> params,
|
||||
boolean isRedundant) throws InsufficientCapacityException, ResourceUnavailableException, ConcurrentOperationException;
|
||||
List<DomainRouterVO> deployVirtualRouter(RouterDeploymentDefinition routerDeploymentDefinition)
|
||||
throws InsufficientCapacityException, ResourceUnavailableException, ConcurrentOperationException;
|
||||
|
||||
boolean startRemoteAccessVpn(Network network, RemoteAccessVpn vpn, List<? extends VirtualRouter> routers) throws ResourceUnavailableException;
|
||||
|
||||
|
|
|
|||
|
|
@ -403,6 +403,8 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
|
|||
|
||||
@Inject
|
||||
protected NetworkGeneralHelper nwHelper;
|
||||
@Inject
|
||||
protected RouterDeploymentManager routerDeploymentManager;
|
||||
|
||||
int _routerRamSize;
|
||||
int _routerCpuMHz;
|
||||
|
|
@ -1538,8 +1540,11 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
|
|||
}
|
||||
|
||||
@DB
|
||||
protected List<DomainRouterVO> findOrDeployVirtualRouterInGuestNetwork(final Network guestNetwork, final DeployDestination dest, Account owner, final boolean isRedundant,
|
||||
final Map<Param, Object> params) throws ConcurrentOperationException, InsufficientCapacityException, ResourceUnavailableException {
|
||||
protected List<DomainRouterVO> findOrDeployVirtualRouterInGuestNetwork(final RouterDeploymentDefinition routerDeploymentDefinition) throws ConcurrentOperationException,
|
||||
InsufficientCapacityException, ResourceUnavailableException {
|
||||
|
||||
final Network guestNetwork = routerDeploymentDefinition.getGuestNetwork();
|
||||
final DeployDestination dest = routerDeploymentDefinition.getDest();
|
||||
|
||||
List<DomainRouterVO> routers = new ArrayList<DomainRouterVO>();
|
||||
final Network lock = _networkDao.acquireInLockTable(guestNetwork.getId(), NetworkOrchestrationService.NetworkLockTimeout.value());
|
||||
|
|
@ -1607,7 +1612,7 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
|
|||
|
||||
// 2) Figure out required routers count
|
||||
int routerCount = 1;
|
||||
if (isRedundant) {
|
||||
if (routerDeploymentDefinition.isRedundant()) {
|
||||
routerCount = 2;
|
||||
// Check current redundant routers, if possible(all routers
|
||||
// are stopped), reset the priority
|
||||
|
|
@ -1639,7 +1644,7 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
|
|||
}
|
||||
|
||||
if (_networkModel.isNetworkSystem(guestNetwork) || guestNetwork.getGuestType() == Network.GuestType.Shared) {
|
||||
owner = _accountMgr.getAccount(Account.ACCOUNT_ID_SYSTEM);
|
||||
routerDeploymentDefinition.setOwner(_accountMgr.getAccount(Account.ACCOUNT_ID_SYSTEM));
|
||||
}
|
||||
|
||||
// Check if public network has to be set on VR
|
||||
|
|
@ -1647,7 +1652,7 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
|
|||
if (_networkModel.isProviderSupportServiceInNetwork(guestNetwork.getId(), Service.SourceNat, Provider.VirtualRouter)) {
|
||||
publicNetwork = true;
|
||||
}
|
||||
if (isRedundant && !publicNetwork) {
|
||||
if (routerDeploymentDefinition.isRedundant() && !publicNetwork) {
|
||||
s_logger.error("Didn't support redundant virtual router without public network!");
|
||||
return null;
|
||||
}
|
||||
|
|
@ -1659,18 +1664,19 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
|
|||
|
||||
PublicIp sourceNatIp = null;
|
||||
if (publicNetwork) {
|
||||
sourceNatIp = _ipAddrMgr.assignSourceNatIpAddressToGuestNetwork(owner, guestNetwork);
|
||||
sourceNatIp = _ipAddrMgr.assignSourceNatIpAddressToGuestNetwork(routerDeploymentDefinition.getOwner(), guestNetwork);
|
||||
}
|
||||
|
||||
// 3) deploy virtual router(s)
|
||||
final int count = routerCount - destRouters.size();
|
||||
final DeploymentPlan plan = planAndRouters.first();
|
||||
routerDeploymentDefinition.setPlan(plan);
|
||||
for (int i = 0; i < count; i++) {
|
||||
LinkedHashMap<Network, List<? extends NicProfile>> networks = createRouterNetworks(owner, isRedundant, plan, guestNetwork, new Pair<Boolean, PublicIp>(
|
||||
final LinkedHashMap<Network, List<? extends NicProfile>> networks = createRouterNetworks(routerDeploymentDefinition, new Pair<Boolean, PublicIp>(
|
||||
publicNetwork, sourceNatIp));
|
||||
// don't start the router as we are holding the network lock
|
||||
// that needs to be released at the end of router allocation
|
||||
final DomainRouterVO router = nwHelper.deployRouter(owner, destination, plan, params, isRedundant, vrProvider, offeringId, null, networks, false, null);
|
||||
final DomainRouterVO router = nwHelper.deployRouter(routerDeploymentDefinition, vrProvider, offeringId, networks, false, null);
|
||||
|
||||
if (router != null) {
|
||||
_routerDao.addRouterToGuestNetwork(router, guestNetwork);
|
||||
|
|
@ -1707,9 +1713,10 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
|
|||
return _podDao.search(sc, null);
|
||||
}
|
||||
|
||||
protected LinkedHashMap<Network, List<? extends NicProfile>> createRouterNetworks(final Account owner, final boolean isRedundant, final DeploymentPlan plan,
|
||||
final Network guestNetwork, final Pair<Boolean, PublicIp> publicNetwork) throws ConcurrentOperationException, InsufficientAddressCapacityException {
|
||||
protected LinkedHashMap<Network, List<? extends NicProfile>> createRouterNetworks(final RouterDeploymentDefinition routerDeploymentDefinition,
|
||||
final Pair<Boolean, PublicIp> publicNetwork) throws ConcurrentOperationException, InsufficientAddressCapacityException {
|
||||
|
||||
final Network guestNetwork = routerDeploymentDefinition.getGuestNetwork();
|
||||
boolean setupPublicNetwork = false;
|
||||
if (publicNetwork != null) {
|
||||
setupPublicNetwork = publicNetwork.first();
|
||||
|
|
@ -1723,7 +1730,7 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
|
|||
s_logger.debug("Adding nic for Virtual Router in Guest network " + guestNetwork);
|
||||
String defaultNetworkStartIp = null, defaultNetworkStartIpv6 = null;
|
||||
if (!setupPublicNetwork) {
|
||||
final Nic placeholder = _networkModel.getPlaceholderNicForRouter(guestNetwork, plan.getPodId());
|
||||
final Nic placeholder = _networkModel.getPlaceholderNicForRouter(guestNetwork, routerDeploymentDefinition.getPodId());
|
||||
if (guestNetwork.getCidr() != null) {
|
||||
if (placeholder != null && placeholder.getIp4Address() != null) {
|
||||
s_logger.debug("Requesting ipv4 address " + placeholder.getIp4Address() + " stored in placeholder nic for the network " + guestNetwork);
|
||||
|
|
@ -1757,7 +1764,7 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
|
|||
|
||||
final NicProfile gatewayNic = new NicProfile(defaultNetworkStartIp, defaultNetworkStartIpv6);
|
||||
if (setupPublicNetwork) {
|
||||
if (isRedundant) {
|
||||
if (routerDeploymentDefinition.isRedundant()) {
|
||||
gatewayNic.setIp4Address(_ipAddrMgr.acquireGuestIpAddress(guestNetwork, null));
|
||||
} else {
|
||||
gatewayNic.setIp4Address(guestNetwork.getGateway());
|
||||
|
|
@ -1778,9 +1785,9 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
|
|||
|
||||
// 2) Control network
|
||||
s_logger.debug("Adding nic for Virtual Router in Control network ");
|
||||
List<? extends NetworkOffering> offerings = _networkModel.getSystemAccountNetworkOfferings(NetworkOffering.SystemControlNetwork);
|
||||
NetworkOffering controlOffering = offerings.get(0);
|
||||
Network controlConfig = _networkMgr.setupNetwork(_systemAcct, controlOffering, plan, null, null, false).get(0);
|
||||
final List<? extends NetworkOffering> offerings = _networkModel.getSystemAccountNetworkOfferings(NetworkOffering.SystemControlNetwork);
|
||||
final NetworkOffering controlOffering = offerings.get(0);
|
||||
final Network controlConfig = _networkMgr.setupNetwork(_systemAcct, controlOffering, routerDeploymentDefinition.getPlan(), null, null, false).get(0);
|
||||
networks.put(controlConfig, new ArrayList<NicProfile>());
|
||||
// 3) Public network
|
||||
if (setupPublicNetwork) {
|
||||
|
|
@ -1809,7 +1816,7 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
|
|||
defaultNic.setDeviceId(2);
|
||||
}
|
||||
final NetworkOffering publicOffering = _networkModel.getSystemAccountNetworkOfferings(NetworkOffering.SystemPublicNetwork).get(0);
|
||||
final List<? extends Network> publicNetworks = _networkMgr.setupNetwork(_systemAcct, publicOffering, plan, null, null, false);
|
||||
final List<? extends Network> publicNetworks = _networkMgr.setupNetwork(_systemAcct, publicOffering, routerDeploymentDefinition.getPlan(), null, null, false);
|
||||
final String publicIp = defaultNic.getIp4Address();
|
||||
// We want to use the identical MAC address for RvR on public
|
||||
// interface if possible
|
||||
|
|
@ -1846,12 +1853,12 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
|
|||
}
|
||||
|
||||
@Override
|
||||
public List<DomainRouterVO> deployVirtualRouterInGuestNetwork(final Network guestNetwork, final DeployDestination dest, final Account owner, final Map<Param, Object> params,
|
||||
final boolean isRedundant) throws InsufficientCapacityException, ConcurrentOperationException, ResourceUnavailableException {
|
||||
public List<DomainRouterVO> deployVirtualRouter(final RouterDeploymentDefinition routerDeploymentDefinition) throws InsufficientCapacityException,
|
||||
ConcurrentOperationException, ResourceUnavailableException {
|
||||
|
||||
final List<DomainRouterVO> routers = findOrDeployVirtualRouterInGuestNetwork(guestNetwork, dest, owner, isRedundant, params);
|
||||
final List<DomainRouterVO> routers = findOrDeployVirtualRouterInGuestNetwork(routerDeploymentDefinition);
|
||||
|
||||
return nwHelper.startRouters(params, routers);
|
||||
return nwHelper.startRouters(routerDeploymentDefinition.getParams(), routers);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -17,11 +17,8 @@
|
|||
package com.cloud.network.router;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import com.cloud.deploy.DeployDestination;
|
||||
import com.cloud.exception.ConcurrentOperationException;
|
||||
import com.cloud.exception.InsufficientCapacityException;
|
||||
import com.cloud.exception.ResourceUnavailableException;
|
||||
import com.cloud.network.Network;
|
||||
import com.cloud.network.RemoteAccessVpn;
|
||||
|
|
@ -31,42 +28,10 @@ import com.cloud.network.VpnUser;
|
|||
import com.cloud.network.vpc.NetworkACLItem;
|
||||
import com.cloud.network.vpc.PrivateGateway;
|
||||
import com.cloud.network.vpc.StaticRouteProfile;
|
||||
import com.cloud.network.vpc.Vpc;
|
||||
import com.cloud.user.Account;
|
||||
import com.cloud.vm.DomainRouterVO;
|
||||
import com.cloud.vm.VirtualMachineProfile.Param;
|
||||
|
||||
public interface VpcVirtualNetworkApplianceManager extends VirtualNetworkApplianceManager, VpcVirtualNetworkApplianceService {
|
||||
|
||||
/**
|
||||
*
|
||||
* @param vpc
|
||||
* @param dest
|
||||
* @param owner
|
||||
* @param params
|
||||
* @param isRedundant
|
||||
* @return
|
||||
* @throws InsufficientCapacityException
|
||||
* @throws ConcurrentOperationException
|
||||
* @throws ResourceUnavailableException
|
||||
*/
|
||||
List<DomainRouterVO> deployVirtualRouterInVpc(Vpc vpc, DeployDestination dest, Account owner, Map<Param, Object> params, boolean isRedundant) throws InsufficientCapacityException,
|
||||
ConcurrentOperationException, ResourceUnavailableException;
|
||||
|
||||
/**
|
||||
*
|
||||
* @param vpc
|
||||
* @param dest
|
||||
* @param owner
|
||||
* @param params
|
||||
* @return
|
||||
* @throws InsufficientCapacityException
|
||||
* @throws ConcurrentOperationException
|
||||
* @throws ResourceUnavailableException
|
||||
*/
|
||||
List<DomainRouterVO> deployVirtualRouterInVpc(Vpc vpc, DeployDestination dest, Account owner, Map<Param, Object> params) throws InsufficientCapacityException,
|
||||
ConcurrentOperationException, ResourceUnavailableException;
|
||||
|
||||
/**
|
||||
*
|
||||
* @param network
|
||||
|
|
|
|||
|
|
@ -19,14 +19,11 @@ package com.cloud.network.router;
|
|||
|
||||
import java.net.URI;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.TreeSet;
|
||||
|
||||
import javax.ejb.Local;
|
||||
import javax.inject.Inject;
|
||||
|
|
@ -54,33 +51,24 @@ import com.cloud.agent.api.to.NetworkACLTO;
|
|||
import com.cloud.agent.manager.Commands;
|
||||
import com.cloud.dc.DataCenter;
|
||||
import com.cloud.dc.DataCenterVO;
|
||||
import com.cloud.deploy.DataCenterDeployment;
|
||||
import com.cloud.deploy.DeployDestination;
|
||||
import com.cloud.deploy.DeploymentPlan;
|
||||
import com.cloud.exception.AgentUnavailableException;
|
||||
import com.cloud.exception.ConcurrentOperationException;
|
||||
import com.cloud.exception.InsufficientAddressCapacityException;
|
||||
import com.cloud.exception.InsufficientCapacityException;
|
||||
import com.cloud.exception.InsufficientServerCapacityException;
|
||||
import com.cloud.exception.OperationTimedoutException;
|
||||
import com.cloud.exception.ResourceUnavailableException;
|
||||
import com.cloud.exception.StorageUnavailableException;
|
||||
import com.cloud.network.IpAddress;
|
||||
import com.cloud.network.Network;
|
||||
import com.cloud.network.Network.Provider;
|
||||
import com.cloud.network.Network.Service;
|
||||
import com.cloud.network.NetworkService;
|
||||
import com.cloud.network.Networks.AddressFormat;
|
||||
import com.cloud.network.Networks.BroadcastDomainType;
|
||||
import com.cloud.network.Networks.IsolationType;
|
||||
import com.cloud.network.Networks.TrafficType;
|
||||
import com.cloud.network.PhysicalNetwork;
|
||||
import com.cloud.network.PhysicalNetworkServiceProvider;
|
||||
import com.cloud.network.PublicIpAddress;
|
||||
import com.cloud.network.RemoteAccessVpn;
|
||||
import com.cloud.network.Site2SiteVpnConnection;
|
||||
import com.cloud.network.VirtualRouterProvider;
|
||||
import com.cloud.network.VirtualRouterProvider.Type;
|
||||
import com.cloud.network.VpcVirtualNetworkApplianceService;
|
||||
import com.cloud.network.VpnUser;
|
||||
import com.cloud.network.addr.PublicIp;
|
||||
|
|
@ -112,11 +100,9 @@ import com.cloud.network.vpc.dao.VpcDao;
|
|||
import com.cloud.network.vpc.dao.VpcGatewayDao;
|
||||
import com.cloud.network.vpc.dao.VpcOfferingDao;
|
||||
import com.cloud.network.vpn.Site2SiteVpnManager;
|
||||
import com.cloud.offering.NetworkOffering;
|
||||
import com.cloud.user.Account;
|
||||
import com.cloud.user.UserStatisticsVO;
|
||||
import com.cloud.utils.Pair;
|
||||
import com.cloud.utils.db.DB;
|
||||
import com.cloud.utils.db.EntityManager;
|
||||
import com.cloud.utils.exception.CloudRuntimeException;
|
||||
import com.cloud.utils.net.NetUtils;
|
||||
|
|
@ -174,7 +160,9 @@ public class VpcVirtualNetworkApplianceManagerImpl extends VirtualNetworkApplian
|
|||
@Inject
|
||||
protected NetworkGeneralHelper nwHelper;
|
||||
@Inject
|
||||
protected VpcVirtualNetworkHelper vpcHelper;
|
||||
protected VpcVirtualNetworkHelperImpl vpcHelper;
|
||||
@Inject
|
||||
protected RouterDeploymentManager routerDeploymentManager;
|
||||
|
||||
@Override
|
||||
public boolean configure(final String name, final Map<String, Object> params) throws ConfigurationException {
|
||||
|
|
@ -183,79 +171,10 @@ public class VpcVirtualNetworkApplianceManagerImpl extends VirtualNetworkApplian
|
|||
}
|
||||
|
||||
@Override
|
||||
public List<DomainRouterVO> deployVirtualRouterInVpc(Vpc vpc, DeployDestination dest, Account owner,
|
||||
Map<Param, Object> params) throws InsufficientCapacityException,
|
||||
public List<DomainRouterVO> deployVirtualRouter(final RouterDeploymentDefinition routerDeploymentDefinition)
|
||||
throws InsufficientCapacityException,
|
||||
ConcurrentOperationException, ResourceUnavailableException {
|
||||
return this.deployVirtualRouterInVpc(vpc, dest, owner, params, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<DomainRouterVO> deployVirtualRouterInVpc(Vpc vpc, DeployDestination dest, Account owner,
|
||||
Map<Param, Object> params, final boolean isRedundant) throws InsufficientCapacityException,
|
||||
ConcurrentOperationException, ResourceUnavailableException {
|
||||
return this.vpcHelper.deployVirtualRouterInVpc(vpc, dest, owner, params, isRedundant);
|
||||
}
|
||||
|
||||
@DB
|
||||
protected List<DomainRouterVO> findOrDeployVirtualRouterInVpc(Vpc vpc, DeployDestination dest, Account owner, Map<Param, Object> params)
|
||||
throws ConcurrentOperationException, InsufficientCapacityException, ResourceUnavailableException {
|
||||
|
||||
s_logger.debug("Deploying Virtual Router in VPC " + vpc);
|
||||
Vpc vpcLock = _vpcDao.acquireInLockTable(vpc.getId());
|
||||
if (vpcLock == null) {
|
||||
throw new ConcurrentOperationException("Unable to lock vpc " + vpc.getId());
|
||||
}
|
||||
|
||||
//1) Get deployment plan and find out the list of routers
|
||||
Pair<DeploymentPlan, List<DomainRouterVO>> planAndRouters = getDeploymentPlanAndRouters(vpc.getId(), dest);
|
||||
DeploymentPlan plan = planAndRouters.first();
|
||||
List<DomainRouterVO> routers = planAndRouters.second();
|
||||
try {
|
||||
//2) Return routers if exist
|
||||
if (routers.size() >= 1) {
|
||||
return routers;
|
||||
}
|
||||
|
||||
Long offeringId = _vpcOffDao.findById(vpc.getVpcOfferingId()).getServiceOfferingId();
|
||||
if (offeringId == null) {
|
||||
offeringId = _offering.getId();
|
||||
}
|
||||
//3) Deploy Virtual Router
|
||||
List<? extends PhysicalNetwork> pNtwks = _pNtwkDao.listByZone(vpc.getZoneId());
|
||||
|
||||
VirtualRouterProvider vpcVrProvider = null;
|
||||
|
||||
for (PhysicalNetwork pNtwk : pNtwks) {
|
||||
PhysicalNetworkServiceProvider provider = _physicalProviderDao.findByServiceProvider(pNtwk.getId(), Type.VPCVirtualRouter.toString());
|
||||
if (provider == null) {
|
||||
throw new CloudRuntimeException("Cannot find service provider " + Type.VPCVirtualRouter.toString() + " in physical network " + pNtwk.getId());
|
||||
}
|
||||
vpcVrProvider = _vrProviderDao.findByNspIdAndType(provider.getId(), Type.VPCVirtualRouter);
|
||||
if (vpcVrProvider != null) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
PublicIp sourceNatIp = _vpcMgr.assignSourceNatIpAddressToVpc(owner, vpc);
|
||||
|
||||
DomainRouterVO router = deployVpcRouter(owner, dest, plan, params, false, vpcVrProvider, offeringId, vpc.getId(), sourceNatIp);
|
||||
routers.add(router);
|
||||
|
||||
} finally {
|
||||
if (vpcLock != null) {
|
||||
_vpcDao.releaseFromLockTable(vpc.getId());
|
||||
}
|
||||
}
|
||||
return routers;
|
||||
}
|
||||
|
||||
protected Pair<DeploymentPlan, List<DomainRouterVO>> getDeploymentPlanAndRouters(long vpcId, DeployDestination dest) {
|
||||
long dcId = dest.getDataCenter().getId();
|
||||
|
||||
DeploymentPlan plan = new DataCenterDeployment(dcId);
|
||||
List<DomainRouterVO> routers = getVpcRouters(vpcId);
|
||||
|
||||
return new Pair<DeploymentPlan, List<DomainRouterVO>>(plan, routers);
|
||||
return this.routerDeploymentManager.deployVirtualRouterInVpc(routerDeploymentDefinition);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -337,17 +256,6 @@ public class VpcVirtualNetworkApplianceManagerImpl extends VirtualNetworkApplian
|
|||
return result;
|
||||
}
|
||||
|
||||
protected DomainRouterVO deployVpcRouter(Account owner, DeployDestination dest, DeploymentPlan plan, Map<Param, Object> params, boolean isRedundant,
|
||||
VirtualRouterProvider vrProvider, long svcOffId, Long vpcId, PublicIp sourceNatIp) throws ConcurrentOperationException, InsufficientAddressCapacityException,
|
||||
InsufficientServerCapacityException, InsufficientCapacityException, StorageUnavailableException, ResourceUnavailableException {
|
||||
|
||||
LinkedHashMap<Network, List<? extends NicProfile>> networks = createVpcRouterNetworks(owner, isRedundant, plan, new Pair<Boolean, PublicIp>(true, sourceNatIp),vpcId);
|
||||
DomainRouterVO router =
|
||||
nwHelper.deployRouter(owner, dest, plan, params, isRedundant, vrProvider, svcOffId, vpcId, networks, true, _vpcMgr.getSupportedVpcHypervisors());
|
||||
|
||||
return router;
|
||||
}
|
||||
|
||||
protected boolean setupVpcGuestNetwork(Network network, VirtualRouter router, boolean add, NicProfile guestNic) throws ConcurrentOperationException,
|
||||
ResourceUnavailableException {
|
||||
|
||||
|
|
@ -921,7 +829,7 @@ public class VpcVirtualNetworkApplianceManagerImpl extends VirtualNetworkApplian
|
|||
boolean result = true;
|
||||
try {
|
||||
Network network = _networkModel.getNetwork(gateway.getNetworkId());
|
||||
NicProfile requested = createPrivateNicProfileForGateway(gateway);
|
||||
NicProfile requested = this.vpcHelper.createPrivateNicProfileForGateway(gateway);
|
||||
|
||||
if (!nwHelper.checkRouterVersion(router)) {
|
||||
s_logger.warn("Router requires upgrade. Unable to send command to router: " + router.getId());
|
||||
|
|
@ -1182,130 +1090,6 @@ public class VpcVirtualNetworkApplianceManagerImpl extends VirtualNetworkApplian
|
|||
}
|
||||
}
|
||||
|
||||
protected LinkedHashMap<Network, List<? extends NicProfile>> createVpcRouterNetworks(Account owner, boolean isRedundant, DeploymentPlan plan, Pair<Boolean, PublicIp> sourceNatIp,
|
||||
long vpcId) throws ConcurrentOperationException, InsufficientAddressCapacityException {
|
||||
|
||||
TreeSet<String> publicVlans = new TreeSet<String>();
|
||||
publicVlans.add(sourceNatIp.second().getVlanTag());
|
||||
|
||||
//1) allocate nic for control and source nat public ip
|
||||
LinkedHashMap<Network, List<? extends NicProfile>> networks = super.createRouterNetworks(owner, isRedundant, plan, null, sourceNatIp);
|
||||
|
||||
//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.put(privateNetwork, new ArrayList<NicProfile>(Arrays.asList(privateNic)));
|
||||
}
|
||||
}
|
||||
|
||||
//3) allocate nic for guest gateway if needed
|
||||
List<? extends Network> guestNetworks = _vpcMgr.getVpcNetworks(vpcId);
|
||||
for (Network guestNetwork : guestNetworks) {
|
||||
if (_networkModel.isPrivateGateway(guestNetwork.getId())) {
|
||||
continue;
|
||||
}
|
||||
if (guestNetwork.getState() == Network.State.Implemented || guestNetwork.getState() == Network.State.Setup) {
|
||||
NicProfile guestNic = createGuestNicProfileForVpcRouter(guestNetwork);
|
||||
networks.put(guestNetwork, new ArrayList<NicProfile>(Arrays.asList(guestNic)));
|
||||
}
|
||||
}
|
||||
|
||||
//4) allocate nic for additional public network(s)
|
||||
List<IPAddressVO> ips = _ipAddressDao.listByAssociatedVpc(vpcId, false);
|
||||
List<NicProfile> publicNics = new ArrayList<NicProfile>();
|
||||
Network publicNetwork = null;
|
||||
for (IPAddressVO ip : ips) {
|
||||
PublicIp publicIp = PublicIp.createFromAddrAndVlan(ip, _vlanDao.findById(ip.getVlanId()));
|
||||
if ((ip.getState() == IpAddress.State.Allocated || ip.getState() == IpAddress.State.Allocating) && _vpcMgr.isIpAllocatedToVpc(ip) &&
|
||||
!publicVlans.contains(publicIp.getVlanTag())) {
|
||||
s_logger.debug("Allocating nic for router in vlan " + publicIp.getVlanTag());
|
||||
NicProfile publicNic = new NicProfile();
|
||||
publicNic.setDefaultNic(false);
|
||||
publicNic.setIp4Address(publicIp.getAddress().addr());
|
||||
publicNic.setGateway(publicIp.getGateway());
|
||||
publicNic.setNetmask(publicIp.getNetmask());
|
||||
publicNic.setMacAddress(publicIp.getMacAddress());
|
||||
publicNic.setBroadcastType(BroadcastDomainType.Vlan);
|
||||
publicNic.setBroadcastUri(BroadcastDomainType.Vlan.toUri(publicIp.getVlanTag()));
|
||||
publicNic.setIsolationUri(IsolationType.Vlan.toUri(publicIp.getVlanTag()));
|
||||
NetworkOffering publicOffering = _networkModel.getSystemAccountNetworkOfferings(NetworkOffering.SystemPublicNetwork).get(0);
|
||||
if (publicNetwork == null) {
|
||||
List<? extends Network> publicNetworks = _networkMgr.setupNetwork(_systemAcct, publicOffering, plan, null, null, false);
|
||||
publicNetwork = publicNetworks.get(0);
|
||||
}
|
||||
publicNics.add(publicNic);
|
||||
publicVlans.add(publicIp.getVlanTag());
|
||||
}
|
||||
}
|
||||
if (publicNetwork != null) {
|
||||
if (networks.get(publicNetwork) != null) {
|
||||
List<NicProfile> publicNicProfiles = (List<NicProfile>)networks.get(publicNetwork);
|
||||
publicNicProfiles.addAll(publicNics);
|
||||
networks.put(publicNetwork, publicNicProfiles);
|
||||
} else {
|
||||
networks.put(publicNetwork, publicNics);
|
||||
}
|
||||
}
|
||||
|
||||
return networks;
|
||||
}
|
||||
|
||||
@DB
|
||||
protected NicProfile createPrivateNicProfileForGateway(VpcGateway privateGateway) {
|
||||
Network privateNetwork = _networkModel.getNetwork(privateGateway.getNetworkId());
|
||||
PrivateIpVO ipVO = _privateIpDao.allocateIpAddress(privateNetwork.getDataCenterId(), privateNetwork.getId(), privateGateway.getIp4Address());
|
||||
if (ipVO == null) {
|
||||
throw new CloudRuntimeException("Unable to assign a private IP for private gateway " + privateGateway.getUuid());
|
||||
}
|
||||
Nic privateNic = _nicDao.findByIp4AddressAndNetworkId(ipVO.getIpAddress(), privateNetwork.getId());
|
||||
|
||||
NicProfile privateNicProfile = new NicProfile();
|
||||
|
||||
if (privateNic != null) {
|
||||
VirtualMachine vm = _vmDao.findById(privateNic.getInstanceId());
|
||||
privateNicProfile =
|
||||
new NicProfile(privateNic, privateNetwork, privateNic.getBroadcastUri(), privateNic.getIsolationUri(), _networkModel.getNetworkRate(
|
||||
privateNetwork.getId(), vm.getId()), _networkModel.isSecurityGroupSupportedInNetwork(privateNetwork), _networkModel.getNetworkTag(
|
||||
vm.getHypervisorType(), privateNetwork));
|
||||
} else {
|
||||
String netmask = NetUtils.getCidrNetmask(privateNetwork.getCidr());
|
||||
PrivateIpAddress ip =
|
||||
new PrivateIpAddress(ipVO, privateNetwork.getBroadcastUri().toString(), privateNetwork.getGateway(), netmask,
|
||||
NetUtils.long2Mac(NetUtils.createSequenceBasedMacAddress(ipVO.getMacAddress())));
|
||||
|
||||
URI netUri = BroadcastDomainType.fromString(ip.getBroadcastUri());
|
||||
privateNicProfile.setIp4Address(ip.getIpAddress());
|
||||
privateNicProfile.setGateway(ip.getGateway());
|
||||
privateNicProfile.setNetmask(ip.getNetmask());
|
||||
privateNicProfile.setIsolationUri(netUri);
|
||||
privateNicProfile.setBroadcastUri(netUri);
|
||||
// can we solve this in setBroadcastUri()???
|
||||
// or more plugable construct is desirable
|
||||
privateNicProfile.setBroadcastType(BroadcastDomainType.getSchemeValue(netUri));
|
||||
privateNicProfile.setFormat(AddressFormat.Ip4);
|
||||
privateNicProfile.setReservationId(String.valueOf(ip.getBroadcastUri()));
|
||||
privateNicProfile.setMacAddress(ip.getMacAddress());
|
||||
}
|
||||
|
||||
return privateNicProfile;
|
||||
}
|
||||
|
||||
protected NicProfile createGuestNicProfileForVpcRouter(Network guestNetwork) {
|
||||
NicProfile guestNic = new NicProfile();
|
||||
guestNic.setIp4Address(guestNetwork.getGateway());
|
||||
guestNic.setBroadcastUri(guestNetwork.getBroadcastUri());
|
||||
guestNic.setBroadcastType(guestNetwork.getBroadcastDomainType());
|
||||
guestNic.setIsolationUri(guestNetwork.getBroadcastUri());
|
||||
guestNic.setMode(guestNetwork.getMode());
|
||||
String gatewayCidr = guestNetwork.getCidr();
|
||||
guestNic.setNetmask(NetUtils.getCidrNetmask(gatewayCidr));
|
||||
|
||||
return guestNic;
|
||||
}
|
||||
|
||||
protected Pair<Map<String, PublicIpAddress>, Map<String, PublicIpAddress>> getNicsToChangeOnRouter(final List<? extends PublicIpAddress> publicIps,
|
||||
VirtualRouter router) {
|
||||
//1) check which nics need to be plugged/unplugged and plug/unplug them
|
||||
|
|
|
|||
|
|
@ -1,27 +0,0 @@
|
|||
package com.cloud.network.router;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import com.cloud.deploy.DeployDestination;
|
||||
import com.cloud.exception.ConcurrentOperationException;
|
||||
import com.cloud.exception.InsufficientCapacityException;
|
||||
import com.cloud.exception.ResourceUnavailableException;
|
||||
import com.cloud.network.vpc.Vpc;
|
||||
import com.cloud.network.vpc.VpcGateway;
|
||||
import com.cloud.user.Account;
|
||||
import com.cloud.vm.DomainRouterVO;
|
||||
import com.cloud.vm.NicProfile;
|
||||
import com.cloud.vm.VirtualMachineProfile.Param;
|
||||
|
||||
public interface VpcVirtualNetworkHelper {
|
||||
|
||||
List<DomainRouterVO> deployVirtualRouterInVpc(Vpc vpc,
|
||||
DeployDestination dest, Account owner, Map<Param, Object> params, boolean isRedundant)
|
||||
throws InsufficientCapacityException, ConcurrentOperationException,
|
||||
ResourceUnavailableException;
|
||||
|
||||
NicProfile createPrivateNicProfileForGateway(VpcGateway privateGateway);
|
||||
|
||||
List<DomainRouterVO> getVpcRouters(long vpcId);
|
||||
}
|
||||
|
|
@ -18,79 +18,45 @@ package com.cloud.network.router;
|
|||
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.TreeSet;
|
||||
|
||||
import javax.ejb.Local;
|
||||
import javax.inject.Inject;
|
||||
import javax.persistence.EntityManager;
|
||||
|
||||
import org.apache.cloudstack.engine.orchestration.service.NetworkOrchestrationService;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import com.cloud.dc.dao.DataCenterDao;
|
||||
import com.cloud.dc.dao.VlanDao;
|
||||
import com.cloud.deploy.DataCenterDeployment;
|
||||
import com.cloud.deploy.DeployDestination;
|
||||
import com.cloud.deploy.DeploymentPlan;
|
||||
import com.cloud.exception.ConcurrentOperationException;
|
||||
import com.cloud.exception.InsufficientAddressCapacityException;
|
||||
import com.cloud.exception.InsufficientCapacityException;
|
||||
import com.cloud.exception.InsufficientServerCapacityException;
|
||||
import com.cloud.exception.ResourceUnavailableException;
|
||||
import com.cloud.exception.StorageUnavailableException;
|
||||
import com.cloud.network.IpAddress;
|
||||
import com.cloud.network.Network;
|
||||
import com.cloud.network.NetworkModel;
|
||||
import com.cloud.network.NetworkService;
|
||||
import com.cloud.network.Networks.AddressFormat;
|
||||
import com.cloud.network.Networks.BroadcastDomainType;
|
||||
import com.cloud.network.Networks.IsolationType;
|
||||
import com.cloud.network.PhysicalNetwork;
|
||||
import com.cloud.network.PhysicalNetworkServiceProvider;
|
||||
import com.cloud.network.VirtualRouterProvider;
|
||||
import com.cloud.network.VirtualRouterProvider.Type;
|
||||
import com.cloud.network.addr.PublicIp;
|
||||
import com.cloud.network.dao.FirewallRulesDao;
|
||||
import com.cloud.network.dao.IPAddressDao;
|
||||
import com.cloud.network.dao.IPAddressVO;
|
||||
import com.cloud.network.dao.NetworkDao;
|
||||
import com.cloud.network.dao.PhysicalNetworkDao;
|
||||
import com.cloud.network.dao.PhysicalNetworkServiceProviderDao;
|
||||
import com.cloud.network.dao.Site2SiteVpnConnectionDao;
|
||||
import com.cloud.network.dao.Site2SiteVpnGatewayDao;
|
||||
import com.cloud.network.dao.VirtualRouterProviderDao;
|
||||
import com.cloud.network.vpc.NetworkACLItemDao;
|
||||
import com.cloud.network.vpc.NetworkACLManager;
|
||||
import com.cloud.network.vpc.PrivateGateway;
|
||||
import com.cloud.network.vpc.PrivateIpAddress;
|
||||
import com.cloud.network.vpc.PrivateIpVO;
|
||||
import com.cloud.network.vpc.Vpc;
|
||||
import com.cloud.network.vpc.VpcGateway;
|
||||
import com.cloud.network.vpc.VpcManager;
|
||||
import com.cloud.network.vpc.dao.PrivateIpDao;
|
||||
import com.cloud.network.vpc.dao.StaticRouteDao;
|
||||
import com.cloud.network.vpc.dao.VpcDao;
|
||||
import com.cloud.network.vpc.dao.VpcGatewayDao;
|
||||
import com.cloud.network.vpc.dao.VpcOfferingDao;
|
||||
import com.cloud.offering.NetworkOffering;
|
||||
import com.cloud.server.ConfigurationServer;
|
||||
import com.cloud.service.ServiceOfferingVO;
|
||||
import com.cloud.user.Account;
|
||||
import com.cloud.utils.Pair;
|
||||
import com.cloud.utils.db.DB;
|
||||
import com.cloud.utils.exception.CloudRuntimeException;
|
||||
import com.cloud.utils.db.EntityManager;
|
||||
import com.cloud.utils.net.NetUtils;
|
||||
import com.cloud.vm.DomainRouterVO;
|
||||
import com.cloud.vm.Nic;
|
||||
import com.cloud.vm.NicProfile;
|
||||
import com.cloud.vm.VirtualMachine;
|
||||
import com.cloud.vm.VirtualMachineProfile.Param;
|
||||
import com.cloud.vm.dao.DomainRouterDao;
|
||||
import com.cloud.vm.dao.NicDao;
|
||||
import com.cloud.vm.dao.VMInstanceDao;
|
||||
|
|
@ -98,19 +64,11 @@ import com.cloud.vm.dao.VMInstanceDao;
|
|||
|
||||
@Component
|
||||
// This will not be a public service anymore, but a helper for the only public service
|
||||
@Local(value = {VpcVirtualNetworkHelper.class})
|
||||
public class VpcVirtualNetworkHelperImpl implements VpcVirtualNetworkHelper {
|
||||
//implements VpcVirtualNetworkApplianceManager {
|
||||
@Local(value = {VpcVirtualNetworkHelperImpl.class})
|
||||
public class VpcVirtualNetworkHelperImpl {
|
||||
|
||||
private static final Logger s_logger = Logger.getLogger(VpcVirtualNetworkHelperImpl.class);
|
||||
String _name;
|
||||
@Inject
|
||||
VpcDao _vpcDao;
|
||||
@Inject
|
||||
VpcOfferingDao _vpcOffDao;
|
||||
@Inject
|
||||
PhysicalNetworkDao _pNtwkDao;
|
||||
@Inject
|
||||
NetworkService _ntwkService;
|
||||
@Inject
|
||||
NetworkACLManager _networkACLMgr;
|
||||
|
|
@ -159,193 +117,15 @@ public class VpcVirtualNetworkHelperImpl implements VpcVirtualNetworkHelper {
|
|||
@Inject
|
||||
VirtualRouterProviderDao _vrProviderDao;
|
||||
|
||||
protected ServiceOfferingVO _offering;
|
||||
|
||||
protected NetworkGeneralHelper nwHelper = new NetworkGeneralHelper();
|
||||
|
||||
|
||||
@Override
|
||||
public List<DomainRouterVO> deployVirtualRouterInVpc(Vpc vpc, DeployDestination dest, Account owner,
|
||||
Map<Param, Object> params, boolean isRedundant)
|
||||
throws InsufficientCapacityException,
|
||||
ConcurrentOperationException, ResourceUnavailableException {
|
||||
|
||||
List<DomainRouterVO> routers = findOrDeployVirtualRouterInVpc(vpc, dest, owner, params, isRedundant);
|
||||
|
||||
return this.nwHelper.startRouters(params, routers);
|
||||
}
|
||||
|
||||
@DB
|
||||
protected List<DomainRouterVO> findOrDeployVirtualRouterInVpc(Vpc vpc, DeployDestination dest, Account owner,
|
||||
Map<Param, Object> params, boolean isRedundant)
|
||||
throws ConcurrentOperationException, InsufficientCapacityException, ResourceUnavailableException {
|
||||
|
||||
s_logger.debug("Deploying Virtual Router in VPC " + vpc);
|
||||
Vpc vpcLock = _vpcDao.acquireInLockTable(vpc.getId());
|
||||
if (vpcLock == null) {
|
||||
throw new ConcurrentOperationException("Unable to lock vpc " + vpc.getId());
|
||||
}
|
||||
|
||||
//1) Get deployment plan and find out the list of routers
|
||||
Pair<DeploymentPlan, List<DomainRouterVO>> planAndRouters = getDeploymentPlanAndRouters(vpc.getId(), dest);
|
||||
DeploymentPlan plan = planAndRouters.first();
|
||||
List<DomainRouterVO> routers = planAndRouters.second();
|
||||
try {
|
||||
//2) Return routers if exist
|
||||
if (routers.size() >= 1) {
|
||||
return routers;
|
||||
}
|
||||
|
||||
Long offeringId = _vpcOffDao.findById(vpc.getVpcOfferingId()).getServiceOfferingId();
|
||||
if (offeringId == null) {
|
||||
offeringId = _offering.getId();
|
||||
}
|
||||
//3) Deploy Virtual Router
|
||||
List<? extends PhysicalNetwork> pNtwks = _pNtwkDao.listByZone(vpc.getZoneId());
|
||||
|
||||
VirtualRouterProvider vpcVrProvider = null;
|
||||
|
||||
for (PhysicalNetwork pNtwk : pNtwks) {
|
||||
PhysicalNetworkServiceProvider provider = _physicalProviderDao.findByServiceProvider(pNtwk.getId(), Type.VPCVirtualRouter.toString());
|
||||
if (provider == null) {
|
||||
throw new CloudRuntimeException("Cannot find service provider " + Type.VPCVirtualRouter.toString() + " in physical network " + pNtwk.getId());
|
||||
}
|
||||
vpcVrProvider = _vrProviderDao.findByNspIdAndType(provider.getId(), Type.VPCVirtualRouter);
|
||||
if (vpcVrProvider != null) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
PublicIp sourceNatIp = _vpcMgr.assignSourceNatIpAddressToVpc(owner, vpc);
|
||||
|
||||
DomainRouterVO router = deployVpcRouter(owner, dest, plan, params, isRedundant, vpcVrProvider, offeringId, vpc.getId(), sourceNatIp);
|
||||
routers.add(router);
|
||||
|
||||
} finally {
|
||||
// TODO Should we do this after the pre or after the whole??
|
||||
if (vpcLock != null) {
|
||||
_vpcDao.releaseFromLockTable(vpc.getId());
|
||||
}
|
||||
}
|
||||
return routers;
|
||||
}
|
||||
|
||||
protected Pair<DeploymentPlan, List<DomainRouterVO>> getDeploymentPlanAndRouters(long vpcId, DeployDestination dest) {
|
||||
long dcId = dest.getDataCenter().getId();
|
||||
|
||||
DeploymentPlan plan = new DataCenterDeployment(dcId);
|
||||
List<DomainRouterVO> routers = getVpcRouters(vpcId);
|
||||
|
||||
return new Pair<DeploymentPlan, List<DomainRouterVO>>(plan, routers);
|
||||
}
|
||||
|
||||
|
||||
protected DomainRouterVO deployVpcRouter(Account owner, DeployDestination dest, DeploymentPlan plan, Map<Param, Object> params, boolean isRedundant,
|
||||
VirtualRouterProvider vrProvider, long svcOffId, Long vpcId, PublicIp sourceNatIp) throws ConcurrentOperationException, InsufficientAddressCapacityException,
|
||||
InsufficientServerCapacityException, InsufficientCapacityException, StorageUnavailableException, ResourceUnavailableException {
|
||||
|
||||
LinkedHashMap<Network, List<? extends NicProfile>> networks = createVpcRouterNetworks(owner, isRedundant, plan, new Pair<Boolean, PublicIp>(true, sourceNatIp),vpcId);
|
||||
|
||||
DomainRouterVO router =
|
||||
this.nwHelper.deployRouter(owner, dest, plan, params, isRedundant, vrProvider, svcOffId, vpcId, networks, true, _vpcMgr.getSupportedVpcHypervisors());
|
||||
|
||||
return router;
|
||||
}
|
||||
|
||||
protected LinkedHashMap<Network, List<? extends NicProfile>> createVpcRouterNetworks(Account owner, boolean isRedundant, DeploymentPlan plan, Pair<Boolean, PublicIp> sourceNatIp,
|
||||
long vpcId) throws ConcurrentOperationException, InsufficientAddressCapacityException {
|
||||
|
||||
LinkedHashMap<Network, List<? extends NicProfile>> networks = new LinkedHashMap<Network, List<? extends NicProfile>>(4);
|
||||
|
||||
TreeSet<String> publicVlans = new TreeSet<String>();
|
||||
publicVlans.add(sourceNatIp.second().getVlanTag());
|
||||
|
||||
//1) allocate nic for control and source nat public ip
|
||||
networks = this.nwHelper.createRouterNetworks(owner, isRedundant, plan, null, sourceNatIp);
|
||||
|
||||
|
||||
//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.put(privateNetwork, new ArrayList<NicProfile>(Arrays.asList(privateNic)));
|
||||
}
|
||||
}
|
||||
|
||||
//3) allocate nic for guest gateway if needed
|
||||
List<? extends Network> guestNetworks = _vpcMgr.getVpcNetworks(vpcId);
|
||||
for (Network guestNetwork : guestNetworks) {
|
||||
if (_networkModel.isPrivateGateway(guestNetwork.getId())) {
|
||||
continue;
|
||||
}
|
||||
if (guestNetwork.getState() == Network.State.Implemented || guestNetwork.getState() == Network.State.Setup) {
|
||||
NicProfile guestNic = createGuestNicProfileForVpcRouter(guestNetwork);
|
||||
networks.put(guestNetwork, new ArrayList<NicProfile>(Arrays.asList(guestNic)));
|
||||
}
|
||||
}
|
||||
|
||||
//4) allocate nic for additional public network(s)
|
||||
List<IPAddressVO> ips = _ipAddressDao.listByAssociatedVpc(vpcId, false);
|
||||
List<NicProfile> publicNics = new ArrayList<NicProfile>();
|
||||
Network publicNetwork = null;
|
||||
for (IPAddressVO ip : ips) {
|
||||
PublicIp publicIp = PublicIp.createFromAddrAndVlan(ip, _vlanDao.findById(ip.getVlanId()));
|
||||
if ((ip.getState() == IpAddress.State.Allocated || ip.getState() == IpAddress.State.Allocating) && _vpcMgr.isIpAllocatedToVpc(ip) &&
|
||||
!publicVlans.contains(publicIp.getVlanTag())) {
|
||||
s_logger.debug("Allocating nic for router in vlan " + publicIp.getVlanTag());
|
||||
NicProfile publicNic = new NicProfile();
|
||||
publicNic.setDefaultNic(false);
|
||||
publicNic.setIp4Address(publicIp.getAddress().addr());
|
||||
publicNic.setGateway(publicIp.getGateway());
|
||||
publicNic.setNetmask(publicIp.getNetmask());
|
||||
publicNic.setMacAddress(publicIp.getMacAddress());
|
||||
publicNic.setBroadcastType(BroadcastDomainType.Vlan);
|
||||
publicNic.setBroadcastUri(BroadcastDomainType.Vlan.toUri(publicIp.getVlanTag()));
|
||||
publicNic.setIsolationUri(IsolationType.Vlan.toUri(publicIp.getVlanTag()));
|
||||
NetworkOffering publicOffering = _networkModel.getSystemAccountNetworkOfferings(NetworkOffering.SystemPublicNetwork).get(0);
|
||||
if (publicNetwork == null) {
|
||||
List<? extends Network> publicNetworks = _networkMgr.setupNetwork(VirtualNwStatus.account,
|
||||
publicOffering, plan, null, null, false);
|
||||
publicNetwork = publicNetworks.get(0);
|
||||
}
|
||||
publicNics.add(publicNic);
|
||||
publicVlans.add(publicIp.getVlanTag());
|
||||
}
|
||||
}
|
||||
if (publicNetwork != null) {
|
||||
if (networks.get(publicNetwork) != null) {
|
||||
List<NicProfile> publicNicProfiles = (List<NicProfile>)networks.get(publicNetwork);
|
||||
publicNicProfiles.addAll(publicNics);
|
||||
networks.put(publicNetwork, publicNicProfiles);
|
||||
} else {
|
||||
networks.put(publicNetwork, publicNics);
|
||||
}
|
||||
}
|
||||
|
||||
return networks;
|
||||
}
|
||||
|
||||
protected NicProfile createGuestNicProfileForVpcRouter(Network guestNetwork) {
|
||||
NicProfile guestNic = new NicProfile();
|
||||
guestNic.setIp4Address(guestNetwork.getGateway());
|
||||
guestNic.setBroadcastUri(guestNetwork.getBroadcastUri());
|
||||
guestNic.setBroadcastType(guestNetwork.getBroadcastDomainType());
|
||||
guestNic.setIsolationUri(guestNetwork.getBroadcastUri());
|
||||
guestNic.setMode(guestNetwork.getMode());
|
||||
String gatewayCidr = guestNetwork.getCidr();
|
||||
guestNic.setNetmask(NetUtils.getCidrNetmask(gatewayCidr));
|
||||
|
||||
return guestNic;
|
||||
}
|
||||
|
||||
@Override
|
||||
//@Override
|
||||
public List<DomainRouterVO> getVpcRouters(long vpcId) {
|
||||
return _routerDao.listByVpcId(vpcId);
|
||||
}
|
||||
|
||||
@Override
|
||||
//@Override
|
||||
@DB
|
||||
public NicProfile createPrivateNicProfileForGateway(VpcGateway privateGateway) {
|
||||
Network privateNetwork = _networkModel.getNetwork(privateGateway.getNetworkId());
|
||||
|
|
|
|||
|
|
@ -39,6 +39,7 @@ import com.cloud.network.Site2SiteVpnConnection;
|
|||
import com.cloud.network.VpcVirtualNetworkApplianceService;
|
||||
import com.cloud.network.VpnUser;
|
||||
import com.cloud.network.lb.LoadBalancingRule;
|
||||
import com.cloud.network.router.RouterDeploymentDefinition;
|
||||
import com.cloud.network.router.VirtualRouter;
|
||||
import com.cloud.network.router.VpcVirtualNetworkApplianceManager;
|
||||
import com.cloud.network.rules.FirewallRule;
|
||||
|
|
@ -46,14 +47,12 @@ import com.cloud.network.rules.StaticNat;
|
|||
import com.cloud.network.vpc.NetworkACLItem;
|
||||
import com.cloud.network.vpc.PrivateGateway;
|
||||
import com.cloud.network.vpc.StaticRouteProfile;
|
||||
import com.cloud.network.vpc.Vpc;
|
||||
import com.cloud.user.Account;
|
||||
import com.cloud.user.User;
|
||||
import com.cloud.utils.component.ManagerBase;
|
||||
import com.cloud.vm.DomainRouterVO;
|
||||
import com.cloud.vm.NicProfile;
|
||||
import com.cloud.vm.VirtualMachineProfile;
|
||||
import com.cloud.vm.VirtualMachineProfile.Param;
|
||||
|
||||
@Component
|
||||
@Local(value = {VpcVirtualNetworkApplianceManager.class, VpcVirtualNetworkApplianceService.class})
|
||||
|
|
@ -98,8 +97,8 @@ public class MockVpcVirtualNetworkApplianceManager extends ManagerBase implement
|
|||
* @see com.cloud.network.router.VirtualNetworkApplianceManager#deployVirtualRouterInGuestNetwork(com.cloud.network.Network, com.cloud.deploy.DeployDestination, com.cloud.user.Account, java.util.Map, boolean)
|
||||
*/
|
||||
@Override
|
||||
public List<DomainRouterVO> deployVirtualRouterInGuestNetwork(final Network guestNetwork, final DeployDestination dest, final Account owner, final Map<Param, Object> params,
|
||||
final boolean isRedundant) throws InsufficientCapacityException, ResourceUnavailableException, ConcurrentOperationException {
|
||||
public List<DomainRouterVO> deployVirtualRouter(final RouterDeploymentDefinition routerDeploymentDefinition)
|
||||
throws InsufficientCapacityException, ResourceUnavailableException, ConcurrentOperationException {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
|
@ -329,16 +328,6 @@ public class MockVpcVirtualNetworkApplianceManager extends ManagerBase implement
|
|||
return false;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see com.cloud.network.router.VpcVirtualNetworkApplianceManager#deployVirtualRouterInVpc(com.cloud.network.vpc.Vpc, com.cloud.deploy.DeployDestination, com.cloud.user.Account, java.util.Map)
|
||||
*/
|
||||
@Override
|
||||
public List<DomainRouterVO> deployVirtualRouterInVpc(final Vpc vpc, final DeployDestination dest, final Account owner, final Map<Param, Object> params) throws InsufficientCapacityException,
|
||||
ConcurrentOperationException, ResourceUnavailableException {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean applyNetworkACLs(final Network network, final List<? extends NetworkACLItem> rules, final List<? extends VirtualRouter> routers, final boolean privateGateway)
|
||||
throws ResourceUnavailableException {
|
||||
|
|
@ -447,13 +436,4 @@ public class MockVpcVirtualNetworkApplianceManager extends ManagerBase implement
|
|||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<DomainRouterVO> deployVirtualRouterInVpc(final Vpc vpc,
|
||||
final DeployDestination dest, final Account owner, final Map<Param, Object> params,
|
||||
final boolean isRedundant) throws InsufficientCapacityException,
|
||||
ConcurrentOperationException, ResourceUnavailableException {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue