@@ -260,7 +260,13 @@ public boolean assignToGlobalLoadBalancerRule(AssignToGlobalLoadBalancerRuleCmd
260260 s_logger .debug ("Configuring gslb rule configuration on the gslb service providers in the participating zones" );
261261
262262 // apply the gslb rule on to the back end gslb service providers on zones participating in gslb
263- applyGlobalLoadBalancerRuleConfig (gslbRuleId , false );
263+ if (!applyGlobalLoadBalancerRuleConfig (gslbRuleId , false )) {
264+ s_logger .warn ("Failed to add load balancer rules " + newLbRuleIds + " to global load balancer rule id "
265+ + gslbRuleId );
266+ CloudRuntimeException ex = new CloudRuntimeException (
267+ "Failed to add load balancer rules to GSLB rule " );
268+ throw ex ;
269+ }
264270
265271 // on success set state to Active
266272 gslbRule .setState (GlobalLoadBalancerRule .State .Active );
@@ -269,7 +275,7 @@ public boolean assignToGlobalLoadBalancerRule(AssignToGlobalLoadBalancerRuleCmd
269275 success = true ;
270276
271277 } catch (ResourceUnavailableException e ) {
272- throw new CloudRuntimeException ("Failed to apply gslb config " );
278+ throw new CloudRuntimeException ("Failed to apply new GSLB configuration while assigning new LB rules to GSLB rule. " );
273279 }
274280
275281 return success ;
@@ -359,11 +365,28 @@ public boolean removeFromGlobalLoadBalancerRule(RemoveFromGlobalLoadBalancerRule
359365 s_logger .debug ("Attempting to configure global load balancer rule configuration on the gslb service providers " );
360366
361367 // apply the gslb rule on to the back end gslb service providers
362- applyGlobalLoadBalancerRuleConfig (gslbRuleId , false );
368+ if (!applyGlobalLoadBalancerRuleConfig (gslbRuleId , false )) {
369+ s_logger .warn ("Failed to remove load balancer rules " + lbRuleIdsToremove + " from global load balancer rule id "
370+ + gslbRuleId );
371+ CloudRuntimeException ex = new CloudRuntimeException (
372+ "Failed to remove load balancer rule ids from GSLB rule " );
373+ throw ex ;
374+ }
363375
364- // on success set state to Active
376+ txn .start ();
377+
378+ // remove the mappings of gslb rule to Lb rule that are in revoked state
379+ for (Long lbRuleId : lbRuleIdsToremove ) {
380+ GlobalLoadBalancerLbRuleMapVO removeGslbLbMap = _gslbLbMapDao .findByGslbRuleIdAndLbRuleId (gslbRuleId , lbRuleId );
381+ _gslbLbMapDao .remove (removeGslbLbMap .getId ());
382+ }
383+
384+ // on success set state back to Active
365385 gslbRule .setState (GlobalLoadBalancerRule .State .Active );
366386 _gslbRuleDao .update (gslbRule .getId (), gslbRule );
387+
388+ txn .commit ();
389+
367390 success = true ;
368391 } catch (ResourceUnavailableException e ) {
369392 throw new CloudRuntimeException ("Failed to update removed load balancer details from gloabal load balancer" );
@@ -402,8 +425,16 @@ private void revokeGslbRule(long gslbRuleId, Account caller) {
402425
403426 _accountMgr .checkAccess (caller , SecurityChecker .AccessType .ModifyEntry , true , gslbRule );
404427
405- if (gslbRule .getState () == GlobalLoadBalancerRule .State .Revoke ) {
406- throw new InvalidParameterValueException ("global load balancer rule id: " + gslbRuleId + " is already in revoked state" );
428+ if (gslbRule .getState () == com .cloud .region .ha .GlobalLoadBalancerRule .State .Staged ) {
429+ if (s_logger .isDebugEnabled ()) {
430+ s_logger .debug ("Rule Id: " + gslbRuleId + " is still in Staged state so just removing it." );
431+ }
432+ _gslbRuleDao .remove (gslbRuleId );
433+ return ;
434+ } else if (gslbRule .getState () == GlobalLoadBalancerRule .State .Add || gslbRule .getState () == GlobalLoadBalancerRule .State .Active ) {
435+ //mark the GSlb rule to be in revoke state
436+ gslbRule .setState (GlobalLoadBalancerRule .State .Revoke );
437+ _gslbRuleDao .update (gslbRuleId , gslbRule );
407438 }
408439
409440 Transaction txn = Transaction .currentTxn ();
@@ -418,10 +449,6 @@ private void revokeGslbRule(long gslbRuleId, Account caller) {
418449 }
419450 }
420451
421- //mark the GSlb rule to be in revoke state
422- gslbRule .setState (GlobalLoadBalancerRule .State .Revoke );
423- _gslbRuleDao .update (gslbRuleId , gslbRule );
424-
425452 txn .commit ();
426453
427454 boolean success = false ;
0 commit comments