7272import com .cloud .vm .VirtualMachine ;
7373import com .cloud .vm .VirtualMachineProfile ;
7474
75- @ Local (value = {NetworkElement .class , FirewallServiceProvider .class , DhcpServiceProvider .class , UserDataServiceProvider .class , StaticNatServiceProvider .class ,
75+ @ Local (value = { NetworkElement .class , FirewallServiceProvider .class , DhcpServiceProvider .class , UserDataServiceProvider .class , StaticNatServiceProvider .class ,
7676 LoadBalancingServiceProvider .class , PortForwardingServiceProvider .class , IpDeployer .class , VpcProvider .class , Site2SiteVpnServiceProvider .class ,
77- NetworkACLServiceProvider .class })
77+ NetworkACLServiceProvider .class })
7878public class VpcVirtualRouterElement extends VirtualRouterElement implements VpcProvider , Site2SiteVpnServiceProvider , NetworkACLServiceProvider {
7979 private static final Logger s_logger = Logger .getLogger (VpcVirtualRouterElement .class );
8080 @ Inject
@@ -133,18 +133,13 @@ protected boolean canHandle(final Network network, final Service service) {
133133
134134 @ Override
135135 public boolean implementVpc (final Vpc vpc , final DeployDestination dest , final ReservationContext context ) throws ConcurrentOperationException , ResourceUnavailableException ,
136- InsufficientCapacityException {
136+ InsufficientCapacityException {
137137
138138 Map <VirtualMachineProfile .Param , Object > params = new HashMap <VirtualMachineProfile .Param , Object >(1 );
139139 params .put (VirtualMachineProfile .Param .ReProgramGuestNetworks , true );
140140
141- RouterDeploymentDefinition routerDeploymentDefinition =
142- routerDeploymentDefinitionBuilder .create ()
143- .setVpc (vpc )
144- .setDeployDestination (dest )
145- .setAccountOwner (_accountMgr .getAccount (vpc .getAccountId ()))
146- .setParams (params )
147- .build ();
141+ RouterDeploymentDefinition routerDeploymentDefinition = routerDeploymentDefinitionBuilder .create ().setVpc (vpc ).setDeployDestination (dest )
142+ .setAccountOwner (_accountMgr .getAccount (vpc .getAccountId ())).setParams (params ).build ();
148143
149144 routerDeploymentDefinition .deployVirtualRouter ();
150145
@@ -165,8 +160,8 @@ public boolean shutdownVpc(final Vpc vpc, final ReservationContext context) thro
165160 }
166161
167162 @ Override
168- public boolean implement (final Network network , final NetworkOffering offering , final DeployDestination dest , final ReservationContext context ) throws ResourceUnavailableException ,
169- ConcurrentOperationException , InsufficientCapacityException {
163+ public boolean implement (final Network network , final NetworkOffering offering , final DeployDestination dest , final ReservationContext context )
164+ throws ResourceUnavailableException , ConcurrentOperationException , InsufficientCapacityException {
170165
171166 Long vpcId = network .getVpcId ();
172167 if (vpcId == null ) {
@@ -183,13 +178,8 @@ public boolean implement(final Network network, final NetworkOffering offering,
183178 Map <VirtualMachineProfile .Param , Object > params = new HashMap <VirtualMachineProfile .Param , Object >(1 );
184179 params .put (VirtualMachineProfile .Param .ReProgramGuestNetworks , true );
185180
186- RouterDeploymentDefinition routerDeploymentDefinition =
187- routerDeploymentDefinitionBuilder .create ()
188- .setVpc (vpc )
189- .setDeployDestination (dest )
190- .setAccountOwner (_accountMgr .getAccount (vpc .getAccountId ()))
191- .setParams (params )
192- .build ();
181+ RouterDeploymentDefinition routerDeploymentDefinition = routerDeploymentDefinitionBuilder .create ().setVpc (vpc ).setDeployDestination (dest )
182+ .setAccountOwner (_accountMgr .getAccount (vpc .getAccountId ())).setParams (params ).build ();
193183
194184 List <DomainRouterVO > routers = routerDeploymentDefinition .deployVirtualRouter ();
195185
@@ -202,7 +192,7 @@ public boolean implement(final Network network, final NetworkOffering offering,
202192 }
203193
204194 DomainRouterVO router = routers .get (0 );
205- //Add router to guest network if needed
195+ // Add router to guest network if needed
206196 if (!_networkMdl .isVmPartOfNetwork (router .getId (), network .getId ())) {
207197 Map <VirtualMachineProfile .Param , Object > paramsForRouter = new HashMap <VirtualMachineProfile .Param , Object >(1 );
208198 if (network .getState () == State .Setup ) {
@@ -238,13 +228,8 @@ public boolean prepare(final Network network, final NicProfile nic, final Virtua
238228 Map <VirtualMachineProfile .Param , Object > params = new HashMap <VirtualMachineProfile .Param , Object >(1 );
239229 params .put (VirtualMachineProfile .Param .ReProgramGuestNetworks , true );
240230
241- RouterDeploymentDefinition routerDeploymentDefinition =
242- routerDeploymentDefinitionBuilder .create ()
243- .setVpc (vpc )
244- .setDeployDestination (dest )
245- .setAccountOwner (_accountMgr .getAccount (vpc .getAccountId ()))
246- .setParams (params )
247- .build ();
231+ RouterDeploymentDefinition routerDeploymentDefinition = routerDeploymentDefinitionBuilder .create ().setVpc (vpc ).setDeployDestination (dest )
232+ .setAccountOwner (_accountMgr .getAccount (vpc .getAccountId ())).setParams (params ).build ();
248233 List <DomainRouterVO > routers = routerDeploymentDefinition .deployVirtualRouter ();
249234
250235 if (routers == null || routers .size () == 0 ) {
@@ -256,7 +241,7 @@ public boolean prepare(final Network network, final NicProfile nic, final Virtua
256241 }
257242
258243 DomainRouterVO router = routers .get (0 );
259- //Add router to guest network if needed
244+ // Add router to guest network if needed
260245 if (!_networkMdl .isVmPartOfNetwork (router .getId (), network .getId ())) {
261246 Map <VirtualMachineProfile .Param , Object > paramsForRouter = new HashMap <VirtualMachineProfile .Param , Object >(1 );
262247 // need to reprogram guest network if it comes in a setup state
@@ -285,12 +270,12 @@ public boolean shutdown(final Network network, final ReservationContext context,
285270
286271 List <? extends VirtualRouter > routers = _routerDao .listByVpcId (vpcId );
287272 for (VirtualRouter router : routers ) {
288- //1) Check if router is already a part of the network
273+ // 1) Check if router is already a part of the network
289274 if (!_networkMdl .isVmPartOfNetwork (router .getId (), network .getId ())) {
290275 s_logger .debug ("Router " + router + " is not a part the network " + network );
291276 continue ;
292277 }
293- //2) Call unplugNics in the network service
278+ // 2) Call unplugNics in the network service
294279 success = success && _vpcRouterMgr .removeVpcRouterFromGuestNetwork (router , network , false );
295280 if (!success ) {
296281 s_logger .warn ("Failed to unplug nic in network " + network + " for virtual router " + router );
@@ -313,12 +298,12 @@ public boolean destroy(final Network config, final ReservationContext context) t
313298
314299 List <? extends VirtualRouter > routers = _routerDao .listByVpcId (vpcId );
315300 for (VirtualRouter router : routers ) {
316- //1) Check if router is already a part of the network
301+ // 1) Check if router is already a part of the network
317302 if (!_networkMdl .isVmPartOfNetwork (router .getId (), config .getId ())) {
318303 s_logger .debug ("Router " + router + " is not a part the network " + config );
319304 continue ;
320305 }
321- //2) Call unplugNics in the network service
306+ // 2) Call unplugNics in the network service
322307 success = success && _vpcRouterMgr .removeVpcRouterFromGuestNetwork (router , config , false );
323308 if (!success ) {
324309 s_logger .warn ("Failed to unplug nic in network " + config + " for virtual router " + router );
@@ -349,10 +334,10 @@ private static Map<Service, Map<Capability, String>> setCapabilities() {
349334 vpnCapabilities .put (Capability .VpnTypes , "s2svpn" );
350335 capabilities .put (Service .Vpn , vpnCapabilities );
351336
352- //remove firewall capability
337+ // remove firewall capability
353338 capabilities .remove (Service .Firewall );
354339
355- //add network ACL capability
340+ // add network ACL capability
356341 Map <Capability , String > networkACLCapabilities = new HashMap <Capability , String >();
357342 networkACLCapabilities .put (Capability .SupportedProtocols , "tcp,udp,icmp" );
358343 capabilities .put (Service .NetworkACL , networkACLCapabilities );
@@ -374,8 +359,7 @@ public boolean createPrivateGateway(final PrivateGateway gateway) throws Concurr
374359
375360 List <DomainRouterVO > routers = _vpcRouterMgr .getVpcRouters (gateway .getVpcId ());
376361 if (routers == null || routers .isEmpty ()) {
377- s_logger .debug (getName () + " element doesn't need to create Private gateway on the backend; VPC virtual " + "router doesn't exist in the vpc id=" +
378- gateway .getVpcId ());
362+ s_logger .debug (getName () + " element doesn't need to create Private gateway on the backend; VPC virtual " + "router doesn't exist in the vpc id=" + gateway .getVpcId ());
379363 return true ;
380364 }
381365
@@ -384,7 +368,7 @@ public boolean createPrivateGateway(final PrivateGateway gateway) throws Concurr
384368 }
385369
386370 VirtualRouter router = routers .get (0 );
387-
371+
388372 DataCenterVO dcVO = _dcDao .findById (gateway .getZoneId ());
389373 NetworkTopology networkTopology = networkTopologyContext .retrieveNetworkTopology (dcVO );
390374
@@ -400,7 +384,7 @@ public boolean createPrivateGateway(final PrivateGateway gateway) throws Concurr
400384 return false ;
401385 }
402386 } else {
403- s_logger .debug ("Failed to setup private gateway " + gateway );
387+ s_logger .debug ("Failed to setup private gateway " + gateway );
404388 return false ;
405389 }
406390 return true ;
@@ -415,8 +399,7 @@ public boolean deletePrivateGateway(final PrivateGateway gateway) throws Concurr
415399
416400 List <DomainRouterVO > routers = _vpcRouterMgr .getVpcRouters (gateway .getVpcId ());
417401 if (routers == null || routers .isEmpty ()) {
418- s_logger .debug (getName () + " element doesn't need to delete Private gateway on the backend; VPC virtual " + "router doesn't exist in the vpc id=" +
419- gateway .getVpcId ());
402+ s_logger .debug (getName () + " element doesn't need to delete Private gateway on the backend; VPC virtual " + "router doesn't exist in the vpc id=" + gateway .getVpcId ());
420403 return true ;
421404 }
422405
@@ -441,8 +424,8 @@ public boolean applyIps(final Network network, final List<? extends PublicIpAddr
441424 if (canHandle ) {
442425 List <DomainRouterVO > routers = _routerDao .listByNetworkAndRole (network .getId (), Role .VIRTUAL_ROUTER );
443426 if (routers == null || routers .isEmpty ()) {
444- s_logger .debug (getName () + " element doesn't need to associate ip addresses on the backend; VPC virtual " + "router doesn't exist in the network " +
445- network .getId ());
427+ s_logger .debug (getName () + " element doesn't need to associate ip addresses on the backend; VPC virtual " + "router doesn't exist in the network "
428+ + network .getId ());
446429 return true ;
447430 }
448431
@@ -460,8 +443,7 @@ public boolean applyNetworkACLs(final Network network, final List<? extends Netw
460443 if (canHandle (network , Service .NetworkACL )) {
461444 List <DomainRouterVO > routers = _routerDao .listByNetworkAndRole (network .getId (), Role .VIRTUAL_ROUTER );
462445 if (routers == null || routers .isEmpty ()) {
463- s_logger .debug ("Virtual router elemnt doesn't need to apply firewall rules on the backend; virtual " + "router doesn't exist in the network " +
464- network .getId ());
446+ s_logger .debug ("Virtual router elemnt doesn't need to apply firewall rules on the backend; virtual " + "router doesn't exist in the network " + network .getId ());
465447 return true ;
466448 }
467449
@@ -514,8 +496,7 @@ public boolean applyACLItemsToPrivateGw(final PrivateGateway gateway, final List
514496
515497 List <DomainRouterVO > routers = _vpcRouterMgr .getVpcRouters (gateway .getVpcId ());
516498 if (routers == null || routers .isEmpty ()) {
517- s_logger .debug ("Virtual router element doesn't need to apply network acl rules on the backend; virtual " + "router doesn't exist in the network " +
518- network .getId ());
499+ s_logger .debug ("Virtual router element doesn't need to apply network acl rules on the backend; virtual " + "router doesn't exist in the network " + network .getId ());
519500 return true ;
520501 }
521502
@@ -549,8 +530,8 @@ public boolean startSite2SiteVpn(final Site2SiteVpnConnection conn) throws Resou
549530
550531 List <DomainRouterVO > routers = _vpcRouterMgr .getVpcRouters (ip .getVpcId ());
551532 if (routers == null || routers .size () != 1 ) {
552- throw new ResourceUnavailableException ("Cannot enable site-to-site VPN on the backend; virtual router doesn't exist in the vpc " + ip .getVpcId (),
553- DataCenter . class , vpc .getZoneId ());
533+ throw new ResourceUnavailableException ("Cannot enable site-to-site VPN on the backend; virtual router doesn't exist in the vpc " + ip .getVpcId (), DataCenter . class ,
534+ vpc .getZoneId ());
554535 }
555536
556537 return _vpcRouterMgr .startSite2SiteVpn (conn , routers .get (0 ));
@@ -576,8 +557,8 @@ public boolean stopSite2SiteVpn(final Site2SiteVpnConnection conn) throws Resour
576557
577558 List <DomainRouterVO > routers = _vpcRouterMgr .getVpcRouters (ip .getVpcId ());
578559 if (routers == null || routers .size () != 1 ) {
579- throw new ResourceUnavailableException ("Cannot enable site-to-site VPN on the backend; virtual router doesn't exist in the vpc " + ip .getVpcId (),
580- DataCenter . class , vpc .getZoneId ());
560+ throw new ResourceUnavailableException ("Cannot enable site-to-site VPN on the backend; virtual router doesn't exist in the vpc " + ip .getVpcId (), DataCenter . class ,
561+ vpc .getZoneId ());
581562 }
582563
583564 return _vpcRouterMgr .stopSite2SiteVpn (conn , routers .get (0 ));
@@ -594,7 +575,12 @@ public String[] applyVpnUsers(final RemoteAccessVpn vpn, final List<? extends Vp
594575 s_logger .debug ("Cannot apply vpn users on the backend; virtual router doesn't exist in the network " + vpn .getVpcId ());
595576 return null ;
596577 }
597- return _vpcRouterMgr .applyVpnUsers (vpn , users , routers .get (0 ));
578+
579+ Network network = _networkDao .findById (vpn .getNetworkId ());
580+ DataCenterVO dcVO = _dcDao .findById (network .getDataCenterId ());
581+ NetworkTopology networkTopology = networkTopologyContext .retrieveNetworkTopology (dcVO );
582+
583+ return networkTopology .applyVpnUsers (vpn , users , routers .get (0 ));
598584 }
599585
600586 @ Override
0 commit comments