@@ -713,7 +713,7 @@ private List<SecurityGroupRuleVO> authorizeSecurityGroupRule(final Long security
713713 final Integer startPortOrTypeFinal = startPortOrType ;
714714 final Integer endPortOrCodeFinal = endPortOrCode ;
715715 final String protocolFinal = protocol ;
716- return Transaction .execute (new TransactionCallback <List <SecurityGroupRuleVO >>() {
716+ List < SecurityGroupRuleVO > newRules = Transaction .execute (new TransactionCallback <List <SecurityGroupRuleVO >>() {
717717 @ Override
718718 public List <SecurityGroupRuleVO > doInTransaction (TransactionStatus status ) {
719719 // Prevents other threads/management servers from creating duplicate security rules
@@ -756,9 +756,6 @@ public List<SecurityGroupRuleVO> doInTransaction(TransactionStatus status) {
756756 if (s_logger .isDebugEnabled ()) {
757757 s_logger .debug ("Added " + newRules .size () + " rules to security group " + securityGroup .getName ());
758758 }
759- final ArrayList <Long > affectedVms = new ArrayList <Long >();
760- affectedVms .addAll (_securityGroupVMMapDao .listVmIdsBySecurityGroup (securityGroup .getId ()));
761- scheduleRulesetUpdateToHosts (affectedVms , true , null );
762759 return newRules ;
763760 } catch (Exception e ) {
764761 s_logger .warn ("Exception caught when adding security group rules " , e );
@@ -771,6 +768,15 @@ public List<SecurityGroupRuleVO> doInTransaction(TransactionStatus status) {
771768 }
772769 });
773770
771+ try {
772+ final ArrayList <Long > affectedVms = new ArrayList <Long >();
773+ affectedVms .addAll (_securityGroupVMMapDao .listVmIdsBySecurityGroup (securityGroup .getId ()));
774+ scheduleRulesetUpdateToHosts (affectedVms , true , null );
775+ } catch (Exception e ) {
776+ s_logger .debug ("can't update rules on host, ignore" , e );
777+ }
778+
779+ return newRules ;
774780 }
775781
776782 @ Override
@@ -810,7 +816,8 @@ private boolean revokeSecurityGroupRule(final Long id, SecurityRuleType type) {
810816 SecurityGroup securityGroup = _securityGroupDao .findById (rule .getSecurityGroupId ());
811817 _accountMgr .checkAccess (caller , null , true , securityGroup );
812818
813- return Transaction .execute (new TransactionCallback <Boolean >() {
819+ long securityGroupId = rule .getSecurityGroupId ();
820+ Boolean result = Transaction .execute (new TransactionCallback <Boolean >() {
814821 @ Override
815822 public Boolean doInTransaction (TransactionStatus status ) {
816823 SecurityGroupVO groupHandle = null ;
@@ -825,11 +832,7 @@ public Boolean doInTransaction(TransactionStatus status) {
825832
826833 _securityGroupRuleDao .remove (id );
827834 s_logger .debug ("revokeSecurityGroupRule succeeded for security rule id: " + id );
828-
829- final ArrayList <Long > affectedVms = new ArrayList <Long >();
830- affectedVms .addAll (_securityGroupVMMapDao .listVmIdsBySecurityGroup (groupHandle .getId ()));
831- scheduleRulesetUpdateToHosts (affectedVms , true , null );
832-
835+
833836 return true ;
834837 } catch (Exception e ) {
835838 s_logger .warn ("Exception caught when deleting security rules " , e );
@@ -841,6 +844,16 @@ public Boolean doInTransaction(TransactionStatus status) {
841844 }
842845 }
843846 });
847+
848+ try {
849+ final ArrayList <Long > affectedVms = new ArrayList <Long >();
850+ affectedVms .addAll (_securityGroupVMMapDao .listVmIdsBySecurityGroup (securityGroupId ));
851+ scheduleRulesetUpdateToHosts (affectedVms , true , null );
852+ } catch (Exception e ) {
853+ s_logger .debug ("Can't update rules for host, ignore" , e );
854+ }
855+
856+ return result ;
844857 }
845858
846859 @ Override
0 commit comments