@@ -1149,7 +1149,7 @@ protected int getUpdatedPriority(Network guestNetwork, List<DomainRouterVO> rout
11491149 /*
11501150 * Ovm won't support any system. So we have to choose a partner cluster in the same pod to start domain router for us
11511151 */
1152- private HypervisorType getAClusterToStartDomainRouterForOvm (long podId ) {
1152+ private HypervisorType getClusterToStartDomainRouterForOvm (long podId ) {
11531153 List <ClusterVO > clusters = _clusterDao .listByPodId (podId );
11541154 for (ClusterVO cv : clusters ) {
11551155 if (cv .getHypervisorType () == HypervisorType .Ovm || cv .getHypervisorType () == HypervisorType .BareMetal ) {
@@ -1176,7 +1176,7 @@ private HypervisorType getAClusterToStartDomainRouterForOvm(long podId) {
11761176 }
11771177
11781178 @ DB
1179- protected List <DomainRouterVO > findOrCreateVirtualRouters (Network guestNetwork , DeployDestination dest , Account owner , boolean isRedundant ) throws ConcurrentOperationException , InsufficientCapacityException {
1179+ protected List <DomainRouterVO > findOrDeployVirtualRouters (Network guestNetwork , DeployDestination dest , Account owner , boolean isRedundant , Map < Param , Object > params ) throws ConcurrentOperationException , InsufficientCapacityException , ResourceUnavailableException {
11801180
11811181 Network network = _networkDao .acquireInLockTable (guestNetwork .getId ());
11821182 if (network == null ) {
@@ -1195,11 +1195,12 @@ protected List<DomainRouterVO> findOrCreateVirtualRouters(Network guestNetwork,
11951195 return null ;
11961196 }
11971197 List <DomainRouterVO > routers ;
1198+ Long podId = null ;
11981199 if (publicNetwork ) {
11991200 routers = _routerDao .listByNetworkAndRole (guestNetwork .getId (), Role .VIRTUAL_ROUTER );
12001201 } else {
12011202 if (isPodBased ) {
1202- Long podId = dest .getPod ().getId ();
1203+ podId = dest .getPod ().getId ();
12031204 routers = _routerDao .listByNetworkAndPodAndRole (guestNetwork .getId (), podId , Role .VIRTUAL_ROUTER );
12041205 plan = new DataCenterDeployment (dcId , podId , null , null , null , null );
12051206 } else {
@@ -1314,11 +1315,27 @@ protected List<DomainRouterVO> findOrCreateVirtualRouters(Network guestNetwork,
13141315
13151316 //Router is the network element, we don't know the hypervisor type yet.
13161317 //Try to allocate the domR twice using diff hypervisors, and when failed both times, throw the exception up
1317- List <HypervisorType > supportedHypervisors = _resourceMgr .getSupportedHypervisorTypes (dest .getDataCenter ().getId ());
1318+ List <HypervisorType > supportedHypervisors = new ArrayList <HypervisorType >();
1319+
1320+ if (dest .getCluster () != null ) {
1321+ if (dest .getCluster ().getHypervisorType () == HypervisorType .Ovm ) {
1322+ supportedHypervisors .add (getClusterToStartDomainRouterForOvm (dest .getCluster ().getPodId ()));
1323+ } else {
1324+ supportedHypervisors .add (dest .getCluster ().getHypervisorType ());
1325+ }
1326+ } else {
1327+ supportedHypervisors = _resourceMgr .getSupportedHypervisorTypes (dest .getDataCenter ().getId (), true , podId );
1328+ }
1329+
13181330 if (supportedHypervisors .isEmpty ()) {
1331+ if (podId != null ) {
1332+ throw new InsufficientServerCapacityException ("Unable to create virtual router, there are no clusters in the pod " , Pod .class , podId );
1333+ }
13191334 throw new InsufficientServerCapacityException ("Unable to create virtual router, there are no clusters in the zone " , DataCenter .class , dest .getDataCenter ().getId ());
13201335 }
1321- int retry = 0 ;
1336+
1337+ int allocateRetry = 0 ;
1338+ int startRetry = 0 ;
13221339 for (HypervisorType hType : supportedHypervisors ) {
13231340 try {
13241341 s_logger .debug ("Allocating the domR with the hypervisor type " + hType );
@@ -1339,17 +1356,34 @@ protected List<DomainRouterVO> findOrCreateVirtualRouters(Network guestNetwork,
13391356 template .getGuestOSId (), owner .getDomainId (), owner .getId (), guestNetwork .getId (), isRedundant , 0 , false , RedundantState .UNKNOWN , offerHA , false );
13401357 router .setRole (Role .VIRTUAL_ROUTER );
13411358 router = _itMgr .allocate (router , template , routerOffering , networks , plan , null , owner );
1342- break ;
13431359 } catch (InsufficientCapacityException ex ) {
1344- if (retry < 2 ) {
1360+ if (allocateRetry < 2 ) {
13451361 s_logger .debug ("Failed to allocate the domR with hypervisor type " + hType + ", retrying one more time" );
1362+ continue ;
13461363 } else {
13471364 throw ex ;
13481365 }
13491366 } finally {
1350- retry ++;
1367+ allocateRetry ++;
1368+ }
1369+
1370+ try {
1371+ router = startVirtualRouter (router , _accountMgr .getSystemUser (), _accountMgr .getSystemAccount (), params );
1372+ break ;
1373+ } catch (InsufficientCapacityException ex ) {
1374+ if (startRetry < 2 ) {
1375+ s_logger .debug ("Failed to start the domR " + router + " with hypervisor type " + hType + ", destroying it and recreating one more time" );
1376+ //destroy the router
1377+ destroyRouter (router .getId ());
1378+ continue ;
1379+ } else {
1380+ throw ex ;
1381+ }
1382+ } finally {
1383+ startRetry ++;
13511384 }
13521385 }
1386+
13531387 routers .add (router );
13541388
13551389 // Creating stats entry for router
@@ -1373,7 +1407,8 @@ protected List<DomainRouterVO> findOrCreateVirtualRouters(Network guestNetwork,
13731407
13741408 private DomainRouterVO startVirtualRouter (DomainRouterVO router , User user , Account caller , Map <Param , Object > params ) throws StorageUnavailableException , InsufficientCapacityException ,
13751409 ConcurrentOperationException , ResourceUnavailableException {
1376- if (router .getRole () != Role .VIRTUAL_ROUTER || !router .getIsRedundantRouter ()) {
1410+
1411+ if (router .getRole () != Role .VIRTUAL_ROUTER || !router .getIsRedundantRouter ()) {
13771412 return this .start (router , user , caller , params , null );
13781413 }
13791414
@@ -1451,7 +1486,7 @@ public List<DomainRouterVO> deployVirtualRouter(Network guestNetwork, DeployDest
14511486 + guestNetwork ;
14521487 assert guestNetwork .getTrafficType () == TrafficType .Guest ;
14531488
1454- List <DomainRouterVO > routers = findOrCreateVirtualRouters (guestNetwork , dest , owner , isRedundant );
1489+ List <DomainRouterVO > routers = findOrDeployVirtualRouters (guestNetwork , dest , owner , isRedundant , params );
14551490 List <DomainRouterVO > runningRouters = null ;
14561491
14571492 if (routers != null ) {
0 commit comments