2525
2626import org .apache .cloudstack .annotation .AnnotationService ;
2727import org .apache .cloudstack .annotation .dao .AnnotationDao ;
28+ import org .apache .commons .collections .CollectionUtils ;
2829import org .apache .log4j .Logger ;
2930import org .jetbrains .annotations .NotNull ;
3031import org .springframework .stereotype .Component ;
4748import com .cloud .event .ActionEvent ;
4849import com .cloud .event .EventTypes ;
4950import com .cloud .exception .InvalidParameterValueException ;
50- import com .cloud .exception .NetworkRuleConflictException ;
5151import com .cloud .exception .PermissionDeniedException ;
5252import com .cloud .exception .ResourceUnavailableException ;
5353import com .cloud .network .Site2SiteCustomerGateway ;
6363import com .cloud .network .dao .Site2SiteVpnGatewayDao ;
6464import com .cloud .network .dao .Site2SiteVpnGatewayVO ;
6565import com .cloud .network .element .Site2SiteVpnServiceProvider ;
66- import com .cloud .network .vpc .VpcManager ;
6766import com .cloud .network .vpc .VpcVO ;
6867import com .cloud .network .vpc .dao .VpcDao ;
6968import com .cloud .projects .Project .ListProjectResourcesCriteria ;
7069import com .cloud .user .Account ;
7170import com .cloud .user .AccountManager ;
72- import com .cloud .user .dao .AccountDao ;
7371import com .cloud .utils .NumbersUtil ;
7472import com .cloud .utils .Pair ;
7573import com .cloud .utils .Ternary ;
@@ -99,17 +97,12 @@ public class Site2SiteVpnManagerImpl extends ManagerBase implements Site2SiteVpn
9997 @ Inject
10098 IPAddressDao _ipAddressDao ;
10199 @ Inject
102- AccountDao _accountDao ;
103- @ Inject
104100 ConfigurationDao _configDao ;
105101 @ Inject
106- VpcManager _vpcMgr ;
107- @ Inject
108102 AccountManager _accountMgr ;
109103 @ Inject
110104 private AnnotationDao annotationDao ;
111105
112- String _name ;
113106 int _connLimit ;
114107 int _subnetsLimit ;
115108
@@ -256,18 +249,18 @@ public Site2SiteCustomerGateway createCustomerGateway(CreateVpnCustomerGatewayCm
256249
257250 @ Override
258251 @ ActionEvent (eventType = EventTypes .EVENT_S2S_VPN_CONNECTION_CREATE , eventDescription = "creating s2s vpn connection" , create = true )
259- public Site2SiteVpnConnection createVpnConnection (CreateVpnConnectionCmd cmd ) throws NetworkRuleConflictException {
252+ public Site2SiteVpnConnection createVpnConnection (CreateVpnConnectionCmd cmd ) {
260253 Account caller = CallContext .current ().getCallingAccount ();
261254 Account owner = _accountMgr .getAccount (cmd .getEntityOwnerId ());
262255
263256 //Verify that caller can perform actions in behalf of vpc owner
264257 _accountMgr .checkAccess (caller , null , false , owner );
265258
266259 Long customerGatewayId = cmd .getCustomerGatewayId ();
267- Site2SiteCustomerGateway customerGateway = getAndValidateSite2SiteCustomerGateway (customerGatewayId , "Unable to found specified Site to Site VPN customer gateway %s !" , caller );
260+ Site2SiteCustomerGateway customerGateway = getAndValidateSite2SiteCustomerGateway (customerGatewayId , caller );
268261
269262 Long vpnGatewayId = cmd .getVpnGatewayId ();
270- Site2SiteVpnGateway vpnGateway = getAndValidateSite2SiteVpnGateway (vpnGatewayId , "Unable to found specified Site to Site VPN gateway %s !" , caller );
263+ Site2SiteVpnGateway vpnGateway = getAndValidateSite2SiteVpnGateway (vpnGatewayId , caller );
271264
272265 validateVpnConnectionOfTheRightAccount (customerGateway , vpnGateway );
273266 validateVpnConnectionDoesntExist (vpnGatewayId , customerGatewayId );
@@ -316,20 +309,20 @@ public Site2SiteVpnConnection createVpnConnection(CreateVpnConnectionCmd cmd) th
316309 }
317310
318311 @ NotNull
319- private Site2SiteCustomerGateway getAndValidateSite2SiteCustomerGateway (Long customerGatewayId , String errMsg , Account caller ) {
312+ private Site2SiteCustomerGateway getAndValidateSite2SiteCustomerGateway (Long customerGatewayId , Account caller ) {
320313 Site2SiteCustomerGateway customerGateway = _customerGatewayDao .findById (customerGatewayId );
321314 if (customerGateway == null ) {
322- throw new InvalidParameterValueException (String .format (errMsg , customerGatewayId ));
315+ throw new InvalidParameterValueException (String .format ("Unable to found specified Site to Site VPN customer gateway %s !" , customerGatewayId ));
323316 }
324317 _accountMgr .checkAccess (caller , null , false , customerGateway );
325318 return customerGateway ;
326319 }
327320
328321 @ NotNull
329- private Site2SiteVpnGateway getAndValidateSite2SiteVpnGateway (Long vpnGatewayId , String errMsg , Account caller ) {
322+ private Site2SiteVpnGateway getAndValidateSite2SiteVpnGateway (Long vpnGatewayId , Account caller ) {
330323 Site2SiteVpnGateway vpnGateway = _vpnGatewayDao .findById (vpnGatewayId );
331324 if (vpnGateway == null ) {
332- throw new InvalidParameterValueException (String .format (errMsg , vpnGatewayId ));
325+ throw new InvalidParameterValueException (String .format ("Unable to found specified Site to Site VPN gateway %s !" , vpnGatewayId ));
333326 }
334327 _accountMgr .checkAccess (caller , null , false , vpnGateway );
335328 return vpnGateway ;
@@ -361,7 +354,7 @@ private void validatePrerequisiteVpnGateway(Site2SiteVpnGateway vpnGateway) {
361354 public Site2SiteVpnConnection startVpnConnection (long id ) throws ResourceUnavailableException {
362355 Site2SiteVpnConnectionVO conn = _vpnConnectionDao .acquireInLockTable (id );
363356 if (conn == null ) {
364- throw new CloudRuntimeException ("Unable to acquire lock on " + conn );
357+ throw new CloudRuntimeException ("Unable to acquire lock for starting on connection with id " + id );
365358 }
366359 try {
367360 if (conn .getState () != State .Pending && conn .getState () != State .Disconnected ) {
@@ -411,15 +404,15 @@ public boolean deleteCustomerGateway(DeleteVpnCustomerGatewayCmd cmd) {
411404 Account caller = CallContext .current ().getCallingAccount ();
412405
413406 Long id = cmd .getId ();
414- Site2SiteCustomerGateway customerGateway = getAndValidateSite2SiteCustomerGateway (id , "Fail to find customer gateway with %s !" , caller );
407+ Site2SiteCustomerGateway customerGateway = getAndValidateSite2SiteCustomerGateway (id , caller );
415408
416409 return doDeleteCustomerGateway (customerGateway );
417410 }
418411
419412 protected boolean doDeleteCustomerGateway (Site2SiteCustomerGateway gw ) {
420413 long id = gw .getId ();
421414 List <Site2SiteVpnConnectionVO > vpnConnections = _vpnConnectionDao .listByCustomerGatewayId (id );
422- if (vpnConnections != null && vpnConnections . size () != 0 ) {
415+ if (CollectionUtils . isEmpty ( vpnConnections ) ) {
423416 throw new InvalidParameterValueException ("Unable to delete VPN customer gateway with id " + id + " because there is still related VPN connections!" );
424417 }
425418 annotationDao .removeByEntityType (AnnotationService .EntityType .VPN_CUSTOMER_GATEWAY .name (), gw .getUuid ());
@@ -429,7 +422,7 @@ protected boolean doDeleteCustomerGateway(Site2SiteCustomerGateway gw) {
429422
430423 protected void doDeleteVpnGateway (Site2SiteVpnGateway gw ) {
431424 List <Site2SiteVpnConnectionVO > conns = _vpnConnectionDao .listByVpnGatewayId (gw .getId ());
432- if (conns != null && conns . size () != 0 ) {
425+ if (CollectionUtils . isEmpty ( conns ) ) {
433426 throw new InvalidParameterValueException ("Unable to delete VPN gateway " + gw .getId () + " because there is still related VPN connections!" );
434427 }
435428 _vpnGatewayDao .remove (gw .getId ());
@@ -442,7 +435,7 @@ public boolean deleteVpnGateway(DeleteVpnGatewayCmd cmd) {
442435 Account caller = CallContext .current ().getCallingAccount ();
443436
444437 Long id = cmd .getId ();
445- Site2SiteVpnGateway vpnGateway = getAndValidateSite2SiteVpnGateway (id , "Fail to find vpn gateway with %s !" , caller );
438+ Site2SiteVpnGateway vpnGateway = getAndValidateSite2SiteVpnGateway (id , caller );
446439
447440 doDeleteVpnGateway (vpnGateway );
448441 return true ;
@@ -598,7 +591,7 @@ public boolean deleteVpnConnection(DeleteVpnConnectionCmd cmd) throws ResourceUn
598591 private void stopVpnConnection (Long id ) throws ResourceUnavailableException {
599592 Site2SiteVpnConnectionVO conn = _vpnConnectionDao .acquireInLockTable (id );
600593 if (conn == null ) {
601- throw new CloudRuntimeException ("Unable to acquire lock on " + conn );
594+ throw new CloudRuntimeException ("Unable to acquire lock for stopping on connection with id " + id );
602595 }
603596 try {
604597 if (conn .getState () == State .Pending ) {
@@ -659,10 +652,9 @@ public Pair<List<? extends Site2SiteCustomerGateway>, Integer> searchForCustomer
659652 String keyword = cmd .getKeyword ();
660653
661654 Account caller = CallContext .current ().getCallingAccount ();
662- List <Long > permittedAccounts = new ArrayList <Long >();
655+ List <Long > permittedAccounts = new ArrayList <>();
663656
664- Ternary <Long , Boolean , ListProjectResourcesCriteria > domainIdRecursiveListProject = new Ternary <Long , Boolean ,
665- ListProjectResourcesCriteria >(domainId , isRecursive , null );
657+ Ternary <Long , Boolean , ListProjectResourcesCriteria > domainIdRecursiveListProject = new Ternary <>(domainId , isRecursive , null );
666658 _accountMgr .buildACLSearchParameters (caller , id , accountName , cmd .getProjectId (), permittedAccounts , domainIdRecursiveListProject , listAll , false );
667659 domainId = domainIdRecursiveListProject .first ();
668660 isRecursive = domainIdRecursiveListProject .second ();
@@ -687,7 +679,7 @@ public Pair<List<? extends Site2SiteCustomerGateway>, Integer> searchForCustomer
687679 }
688680
689681 Pair <List <Site2SiteCustomerGatewayVO >, Integer > result = _customerGatewayDao .searchAndCount (sc , searchFilter );
690- return new Pair <List <? extends Site2SiteCustomerGateway >, Integer >(result .first (), result .second ());
682+ return new Pair <>(result .first (), result .second ());
691683 }
692684
693685 @ Override
@@ -704,10 +696,9 @@ public Pair<List<? extends Site2SiteVpnGateway>, Integer> searchForVpnGateways(L
704696 long pageSizeVal = cmd .getPageSizeVal ();
705697
706698 Account caller = CallContext .current ().getCallingAccount ();
707- List <Long > permittedAccounts = new ArrayList <Long >();
699+ List <Long > permittedAccounts = new ArrayList <>();
708700
709- Ternary <Long , Boolean , ListProjectResourcesCriteria > domainIdRecursiveListProject = new Ternary <Long , Boolean ,
710- ListProjectResourcesCriteria >(domainId , isRecursive , null );
701+ Ternary <Long , Boolean , ListProjectResourcesCriteria > domainIdRecursiveListProject = new Ternary <>(domainId , isRecursive , null );
711702 _accountMgr .buildACLSearchParameters (caller , id , accountName , cmd .getProjectId (), permittedAccounts , domainIdRecursiveListProject , listAll , false );
712703 domainId = domainIdRecursiveListProject .first ();
713704 isRecursive = domainIdRecursiveListProject .second ();
@@ -737,7 +728,7 @@ public Pair<List<? extends Site2SiteVpnGateway>, Integer> searchForVpnGateways(L
737728 }
738729
739730 Pair <List <Site2SiteVpnGatewayVO >, Integer > result = _vpnGatewayDao .searchAndCount (sc , searchFilter );
740- return new Pair <List <? extends Site2SiteVpnGateway >, Integer >(result .first (), result .second ());
731+ return new Pair <>(result .first (), result .second ());
741732 }
742733
743734 @ Override
@@ -754,10 +745,9 @@ public Pair<List<? extends Site2SiteVpnConnection>, Integer> searchForVpnConnect
754745 long pageSizeVal = cmd .getPageSizeVal ();
755746
756747 Account caller = CallContext .current ().getCallingAccount ();
757- List <Long > permittedAccounts = new ArrayList <Long >();
748+ List <Long > permittedAccounts = new ArrayList <>();
758749
759- Ternary <Long , Boolean , ListProjectResourcesCriteria > domainIdRecursiveListProject = new Ternary <Long , Boolean ,
760- ListProjectResourcesCriteria >(domainId , isRecursive , null );
750+ Ternary <Long , Boolean , ListProjectResourcesCriteria > domainIdRecursiveListProject = new Ternary <>(domainId , isRecursive , null );
761751 _accountMgr .buildACLSearchParameters (caller , id , accountName , cmd .getProjectId (), permittedAccounts , domainIdRecursiveListProject , listAll , false );
762752 domainId = domainIdRecursiveListProject .first ();
763753 isRecursive = domainIdRecursiveListProject .second ();
@@ -791,7 +781,7 @@ public Pair<List<? extends Site2SiteVpnConnection>, Integer> searchForVpnConnect
791781 }
792782
793783 Pair <List <Site2SiteVpnConnectionVO >, Integer > result = _vpnConnectionDao .searchAndCount (sc , searchFilter );
794- return new Pair <List <? extends Site2SiteVpnConnection >, Integer >(result .first (), result .second ());
784+ return new Pair <>(result .first (), result .second ());
795785 }
796786
797787 @ Override
@@ -838,7 +828,7 @@ public void markDisconnectVpnConnByVpc(long vpcId) {
838828
839829 @ Override
840830 public List <Site2SiteVpnConnectionVO > getConnectionsForRouter (DomainRouterVO router ) {
841- List <Site2SiteVpnConnectionVO > conns = new ArrayList <Site2SiteVpnConnectionVO >();
831+ List <Site2SiteVpnConnectionVO > conns = new ArrayList <>();
842832 // One router for one VPC
843833 Long vpcId = router .getVpcId ();
844834 if (router .getVpcId () == null ) {
@@ -851,7 +841,6 @@ public List<Site2SiteVpnConnectionVO> getConnectionsForRouter(DomainRouterVO rou
851841 @ Override
852842 public boolean deleteCustomerGatewayByAccount (long accountId ) {
853843 boolean result = true ;
854- ;
855844 List <Site2SiteCustomerGatewayVO > gws = _customerGatewayDao .listByAccountId (accountId );
856845 for (Site2SiteCustomerGatewayVO gw : gws ) {
857846 result = result & doDeleteCustomerGateway (gw );
@@ -877,15 +866,6 @@ public void reconnectDisconnectedVpnByVpc(Long vpcId) {
877866 }
878867 }
879868
880- public List <Site2SiteVpnServiceProvider > getS2sProviders () {
881- return _s2sProviders ;
882- }
883-
884- @ Inject
885- public void setS2sProviders (List <Site2SiteVpnServiceProvider > s2sProviders ) {
886- _s2sProviders = s2sProviders ;
887- }
888-
889869 @ Override
890870 @ ActionEvent (eventType = EventTypes .EVENT_S2S_VPN_CONNECTION_UPDATE , eventDescription = "creating s2s vpn gateway" , async = true )
891871 public Site2SiteVpnConnection updateVpnConnection (long id , String customId , Boolean forDisplay ) {
0 commit comments