test_class.declarator: s_logger = LoggerFactory.getLogger(GlobalLoadBalancingRulesServiceImplTest.class)
test_class.modifier: private static final
test_class.original_string: private static final Logger s_logger = LoggerFactory.getLogger(GlobalLoadBalancingRulesServiceImplTest.class);
test_class.type: Logger
test_class.var_name: s_logger
test_class.file: server/src/test/java/org/apache/cloudstack/region/gslb/GlobalLoadBalancingRulesServiceImplTest.java
test_class.identifier: GlobalLoadBalancingRulesServiceImplTest
test_class.superclass: extends TestCase
test_case.body: @Test
      public void testAssignToGlobalLoadBalancerRule() throws Exception {
  
          s_logger.info("Running tests for AssignToGlobalLoadBalancerRule() service API");
  
          /*
           * TEST 1: given valid gslb rule id, valid lb rule id, and  caller has access to both the rules
           * assignToGlobalLoadBalancerRule service API should succeed
           */
          runAssignToGlobalLoadBalancerRuleTest();
  
          /*
           * TEST 2: given valid gslb rule id, two valid Lb rules but both belong to same zone then
           * assignToGlobalLoadBalancerRule service API should fail
           */
          runAssignToGlobalLoadBalancerRuleTestSameZoneLb();
  
          /*
           * TEST 3: if gslb rule is in revoke state assignToGlobalLoadBalancerRule service API should fail
           */
          runAssignToGlobalLoadBalancerRuleTestRevokedState();
      }
test_case.class_method_signature: GlobalLoadBalancingRulesServiceImplTest.testAssignToGlobalLoadBalancerRule()
test_case.full_signature: @Test public void testAssignToGlobalLoadBalancerRule()
test_case.identifier: testAssignToGlobalLoadBalancerRule
test_case.invocations: info runAssignToGlobalLoadBalancerRuleTest runAssignToGlobalLoadBalancerRuleTestSameZoneLb runAssignToGlobalLoadBalancerRuleTestRevokedState
test_case.modifiers: @Test public
test_case.parameters: ()
test_case.return: void
test_case.signature: void testAssignToGlobalLoadBalancerRule()
focal_class.declarator: s_logger = LoggerFactory.getLogger(GlobalLoadBalancingRulesServiceImpl.class)
focal_class.modifier: private static final
focal_class.original_string: private static final Logger s_logger = LoggerFactory.getLogger(GlobalLoadBalancingRulesServiceImpl.class);
focal_class.type: Logger
focal_class.var_name: s_logger
focal_class.declarator: _accountMgr
focal_class.modifier: @Inject
focal_class.original_string: @Inject
      AccountManager _accountMgr;
focal_class.type: AccountManager
focal_class.var_name: _accountMgr
focal_class.declarator: _gslbRuleDao
focal_class.modifier: @Inject
focal_class.original_string: @Inject
      GlobalLoadBalancerRuleDao _gslbRuleDao;
focal_class.type: GlobalLoadBalancerRuleDao
focal_class.var_name: _gslbRuleDao
focal_class.declarator: _gslbLbMapDao
focal_class.modifier: @Inject
focal_class.original_string: @Inject
      GlobalLoadBalancerLbRuleMapDao _gslbLbMapDao;
focal_class.type: GlobalLoadBalancerLbRuleMapDao
focal_class.var_name: _gslbLbMapDao
focal_class.declarator: _regionDao
focal_class.modifier: @Inject
focal_class.original_string: @Inject
      RegionDao _regionDao;
focal_class.type: RegionDao
focal_class.var_name: _regionDao
focal_class.declarator: _rulesMgr
focal_class.modifier: @Inject
focal_class.original_string: @Inject
      RulesManager _rulesMgr;
focal_class.type: RulesManager
focal_class.var_name: _rulesMgr
focal_class.declarator: _lbDao
focal_class.modifier: @Inject
focal_class.original_string: @Inject
      LoadBalancerDao _lbDao;
focal_class.type: LoadBalancerDao
focal_class.var_name: _lbDao
focal_class.declarator: _networkDao
focal_class.modifier: @Inject
focal_class.original_string: @Inject
      NetworkDao _networkDao;
focal_class.type: NetworkDao
focal_class.var_name: _networkDao
focal_class.declarator: _globalConfigDao
focal_class.modifier: @Inject
focal_class.original_string: @Inject
      ConfigurationDao _globalConfigDao;
focal_class.type: ConfigurationDao
focal_class.var_name: _globalConfigDao
focal_class.declarator: _ipAddressDao
focal_class.modifier: @Inject
focal_class.original_string: @Inject
      IPAddressDao _ipAddressDao;
focal_class.type: IPAddressDao
focal_class.var_name: _ipAddressDao
focal_class.declarator: _agentMgr
focal_class.modifier: @Inject
focal_class.original_string: @Inject
      AgentManager _agentMgr;
focal_class.type: AgentManager
focal_class.var_name: _agentMgr
focal_class.declarator: _gslbProviders
focal_class.modifier: protected
focal_class.original_string: protected List<GslbServiceProvider> _gslbProviders;
focal_class.type: List<GslbServiceProvider>
focal_class.var_name: _gslbProviders
focal_class.file: server/src/main/java/org/apache/cloudstack/region/gslb/GlobalLoadBalancingRulesServiceImpl.java
focal_class.identifier: GlobalLoadBalancingRulesServiceImpl
focal_class.interfaces: implements GlobalLoadBalancingRulesService
focal_class.class_method_signature: GlobalLoadBalancingRulesServiceImpl.setGslbServiceProviders(List<GslbServiceProvider> providers)
focal_class.full_signature: public void setGslbServiceProviders(List<GslbServiceProvider> providers)
focal_class.identifier: setGslbServiceProviders
focal_class.modifiers: public
focal_class.parameters: (List<GslbServiceProvider> providers)
focal_class.return: void
focal_class.signature: void setGslbServiceProviders(List<GslbServiceProvider> providers)
focal_class.class_method_signature: GlobalLoadBalancingRulesServiceImpl.createGlobalLoadBalancerRule(CreateGlobalLoadBalancerRuleCmd newRule)
focal_class.full_signature: @Override @DB @ActionEvent(eventType = EventTypes.EVENT_GLOBAL_LOAD_BALANCER_CREATE, eventDescription = "creating global load " + "balancer rule", create = true) public GlobalLoadBalancerRule createGlobalLoadBalancerRule(CreateGlobalLoadBalancerRuleCmd newRule)
focal_class.identifier: createGlobalLoadBalancerRule
focal_class.modifiers: @Override @DB @ActionEvent(eventType = EventTypes.EVENT_GLOBAL_LOAD_BALANCER_CREATE, eventDescription = "creating global load " + "balancer rule", create = true) public
focal_class.parameters: (CreateGlobalLoadBalancerRuleCmd newRule)
focal_class.return: GlobalLoadBalancerRule
focal_class.signature: GlobalLoadBalancerRule createGlobalLoadBalancerRule(CreateGlobalLoadBalancerRuleCmd newRule)
focal_class.class_method_signature: GlobalLoadBalancingRulesServiceImpl.assignToGlobalLoadBalancerRule(AssignToGlobalLoadBalancerRuleCmd assignToGslbCmd)
focal_class.full_signature: @Override @DB @ActionEvent(eventType = EventTypes.EVENT_ASSIGN_TO_GLOBAL_LOAD_BALANCER_RULE, eventDescription = "Assigning a load balancer rule to global load balancer rule", async = true) public boolean assignToGlobalLoadBalancerRule(AssignToGlobalLoadBalancerRuleCmd assignToGslbCmd)
focal_class.identifier: assignToGlobalLoadBalancerRule
focal_class.modifiers: @Override @DB @ActionEvent(eventType = EventTypes.EVENT_ASSIGN_TO_GLOBAL_LOAD_BALANCER_RULE, eventDescription = "Assigning a load balancer rule to global load balancer rule", async = true) public
focal_class.parameters: (AssignToGlobalLoadBalancerRuleCmd assignToGslbCmd)
focal_class.return: boolean
focal_class.signature: boolean assignToGlobalLoadBalancerRule(AssignToGlobalLoadBalancerRuleCmd assignToGslbCmd)
focal_class.class_method_signature: GlobalLoadBalancingRulesServiceImpl.removeFromGlobalLoadBalancerRule(RemoveFromGlobalLoadBalancerRuleCmd removeFromGslbCmd)
focal_class.full_signature: @Override @DB @ActionEvent(eventType = EventTypes.EVENT_REMOVE_FROM_GLOBAL_LOAD_BALANCER_RULE, eventDescription = "Removing a load balancer rule to be part of global load balancer rule") public boolean removeFromGlobalLoadBalancerRule(RemoveFromGlobalLoadBalancerRuleCmd removeFromGslbCmd)
focal_class.identifier: removeFromGlobalLoadBalancerRule
focal_class.modifiers: @Override @DB @ActionEvent(eventType = EventTypes.EVENT_REMOVE_FROM_GLOBAL_LOAD_BALANCER_RULE, eventDescription = "Removing a load balancer rule to be part of global load balancer rule") public
focal_class.parameters: (RemoveFromGlobalLoadBalancerRuleCmd removeFromGslbCmd)
focal_class.return: boolean
focal_class.signature: boolean removeFromGlobalLoadBalancerRule(RemoveFromGlobalLoadBalancerRuleCmd removeFromGslbCmd)
focal_class.class_method_signature: GlobalLoadBalancingRulesServiceImpl.deleteGlobalLoadBalancerRule(DeleteGlobalLoadBalancerRuleCmd deleteGslbCmd)
focal_class.full_signature: @Override @ActionEvent(eventType = EventTypes.EVENT_GLOBAL_LOAD_BALANCER_DELETE, eventDescription = "Delete global load balancer rule") public boolean deleteGlobalLoadBalancerRule(DeleteGlobalLoadBalancerRuleCmd deleteGslbCmd)
focal_class.identifier: deleteGlobalLoadBalancerRule
focal_class.modifiers: @Override @ActionEvent(eventType = EventTypes.EVENT_GLOBAL_LOAD_BALANCER_DELETE, eventDescription = "Delete global load balancer rule") public
focal_class.parameters: (DeleteGlobalLoadBalancerRuleCmd deleteGslbCmd)
focal_class.return: boolean
focal_class.signature: boolean deleteGlobalLoadBalancerRule(DeleteGlobalLoadBalancerRuleCmd deleteGslbCmd)
focal_class.class_method_signature: GlobalLoadBalancingRulesServiceImpl.revokeGslbRule(final long gslbRuleId, Account caller)
focal_class.full_signature: @DB private void revokeGslbRule(final long gslbRuleId, Account caller)
focal_class.identifier: revokeGslbRule
focal_class.modifiers: @DB private
focal_class.parameters: (final long gslbRuleId, Account caller)
focal_class.return: void
focal_class.signature: void revokeGslbRule(final long gslbRuleId, Account caller)
focal_class.class_method_signature: GlobalLoadBalancingRulesServiceImpl.updateGlobalLoadBalancerRule(UpdateGlobalLoadBalancerRuleCmd updateGslbCmd)
focal_class.full_signature: @Override public GlobalLoadBalancerRule updateGlobalLoadBalancerRule(UpdateGlobalLoadBalancerRuleCmd updateGslbCmd)
focal_class.identifier: updateGlobalLoadBalancerRule
focal_class.modifiers: @Override public
focal_class.parameters: (UpdateGlobalLoadBalancerRuleCmd updateGslbCmd)
focal_class.return: GlobalLoadBalancerRule
focal_class.signature: GlobalLoadBalancerRule updateGlobalLoadBalancerRule(UpdateGlobalLoadBalancerRuleCmd updateGslbCmd)
focal_class.class_method_signature: GlobalLoadBalancingRulesServiceImpl.listGlobalLoadBalancerRule(ListGlobalLoadBalancerRuleCmd listGslbCmd)
focal_class.full_signature: @Override public List<GlobalLoadBalancerRule> listGlobalLoadBalancerRule(ListGlobalLoadBalancerRuleCmd listGslbCmd)
focal_class.identifier: listGlobalLoadBalancerRule
focal_class.modifiers: @Override public
focal_class.parameters: (ListGlobalLoadBalancerRuleCmd listGslbCmd)
focal_class.return: List<GlobalLoadBalancerRule>
focal_class.signature: List<GlobalLoadBalancerRule> listGlobalLoadBalancerRule(ListGlobalLoadBalancerRuleCmd listGslbCmd)
focal_class.class_method_signature: GlobalLoadBalancingRulesServiceImpl.listSiteLoadBalancers(long gslbRuleId)
focal_class.full_signature: @Override public List<LoadBalancer> listSiteLoadBalancers(long gslbRuleId)
focal_class.identifier: listSiteLoadBalancers
focal_class.modifiers: @Override public
focal_class.parameters: (long gslbRuleId)
focal_class.return: List<LoadBalancer>
focal_class.signature: List<LoadBalancer> listSiteLoadBalancers(long gslbRuleId)
focal_class.class_method_signature: GlobalLoadBalancingRulesServiceImpl.applyGlobalLoadBalancerRuleConfig(long gslbRuleId, boolean revoke)
focal_class.full_signature: private boolean applyGlobalLoadBalancerRuleConfig(long gslbRuleId, boolean revoke)
focal_class.identifier: applyGlobalLoadBalancerRuleConfig
focal_class.modifiers: private
focal_class.parameters: (long gslbRuleId, boolean revoke)
focal_class.return: boolean
focal_class.signature: boolean applyGlobalLoadBalancerRuleConfig(long gslbRuleId, boolean revoke)
focal_class.class_method_signature: GlobalLoadBalancingRulesServiceImpl.revokeAllGslbRulesForAccount(com.cloud.user.Account caller, long accountId)
focal_class.full_signature: @Override public boolean revokeAllGslbRulesForAccount(com.cloud.user.Account caller, long accountId)
focal_class.identifier: revokeAllGslbRulesForAccount
focal_class.modifiers: @Override public
focal_class.parameters: (com.cloud.user.Account caller, long accountId)
focal_class.return: boolean
focal_class.signature: boolean revokeAllGslbRulesForAccount(com.cloud.user.Account caller, long accountId)
focal_class.class_method_signature: GlobalLoadBalancingRulesServiceImpl.checkGslbServiceEnabledInZone(long zoneId, long physicalNetworkId)
focal_class.full_signature: private boolean checkGslbServiceEnabledInZone(long zoneId, long physicalNetworkId)
focal_class.identifier: checkGslbServiceEnabledInZone
focal_class.modifiers: private
focal_class.parameters: (long zoneId, long physicalNetworkId)
focal_class.return: boolean
focal_class.signature: boolean checkGslbServiceEnabledInZone(long zoneId, long physicalNetworkId)
focal_class.class_method_signature: GlobalLoadBalancingRulesServiceImpl.lookupGslbServiceProvider()
focal_class.full_signature: protected GslbServiceProvider lookupGslbServiceProvider()
focal_class.identifier: lookupGslbServiceProvider
focal_class.modifiers: protected
focal_class.parameters: ()
focal_class.return: GslbServiceProvider
focal_class.signature: GslbServiceProvider lookupGslbServiceProvider()
focal_class.class_method_signature: GlobalLoadBalancingRulesServiceImpl.findById(long gslbRuleId)
focal_class.full_signature: @Override public GlobalLoadBalancerRule findById(long gslbRuleId)
focal_class.identifier: findById
focal_class.modifiers: @Override public
focal_class.parameters: (long gslbRuleId)
focal_class.return: GlobalLoadBalancerRule
focal_class.signature: GlobalLoadBalancerRule findById(long gslbRuleId)
focal_method.body: @Override
      @DB
      @ActionEvent(eventType = EventTypes.EVENT_ASSIGN_TO_GLOBAL_LOAD_BALANCER_RULE,
                   eventDescription = "Assigning a load balancer rule to global load balancer rule",
                   async = true)
      public boolean assignToGlobalLoadBalancerRule(AssignToGlobalLoadBalancerRuleCmd assignToGslbCmd) {
  
          CallContext ctx = CallContext.current();
          Account caller = ctx.getCallingAccount();
  
          final long gslbRuleId = assignToGslbCmd.getGlobalLoadBalancerRuleId();
          final GlobalLoadBalancerRuleVO gslbRule = _gslbRuleDao.findById(gslbRuleId);
          if (gslbRule == null) {
              throw new InvalidParameterValueException("Invalid global load balancer rule id: " + gslbRuleId);
          }
  
          _accountMgr.checkAccess(caller, SecurityChecker.AccessType.OperateEntry, true, gslbRule);
  
          if (gslbRule.getState() == GlobalLoadBalancerRule.State.Revoke) {
              throw new InvalidParameterValueException("global load balancer rule id: " + gslbRule.getUuid() + " is in revoked state");
          }
  
          final List<Long> newLbRuleIds = assignToGslbCmd.getLoadBalancerRulesIds();
          if (newLbRuleIds == null || newLbRuleIds.isEmpty()) {
              throw new InvalidParameterValueException("empty list of load balancer rule Ids specified to be assigned" + " global load balancer rule");
          }
  
          List<Long> oldLbRuleIds = new ArrayList<Long>();
          List<Long> oldZones = new ArrayList<Long>();
          List<Long> newZones = new ArrayList<Long>(oldZones);
          List<Pair<Long, Long>> physcialNetworks = new ArrayList<Pair<Long, Long>>();
  
          // get the list of load balancer rules id's that are assigned currently to GSLB rule and corresponding zone id's
          List<GlobalLoadBalancerLbRuleMapVO> gslbLbMapVos = _gslbLbMapDao.listByGslbRuleId(gslbRuleId);
          if (gslbLbMapVos != null) {
              for (GlobalLoadBalancerLbRuleMapVO gslbLbMapVo : gslbLbMapVos) {
                  LoadBalancerVO loadBalancer = _lbDao.findById(gslbLbMapVo.getLoadBalancerId());
                  Network network = _networkDao.findById(loadBalancer.getNetworkId());
                  oldZones.add(network.getDataCenterId());
                  oldLbRuleIds.add(gslbLbMapVo.getLoadBalancerId());
              }
          }
  
          /* check each of the load balancer rule id passed in the 'AssignToGlobalLoadBalancerRuleCmd' command is
           *     valid ID
           *     caller has access to the rule
           *     check rule is not revoked
           *     no two rules are in same zone
           *     rule is not already assigned to gslb rule
           */
          for (Long lbRuleId : newLbRuleIds) {
  
              LoadBalancerVO loadBalancer = _lbDao.findById(lbRuleId);
              if (loadBalancer == null) {
                  throw new InvalidParameterValueException("Specified load balancer rule ID does not exist.");
              }
  
              _accountMgr.checkAccess(caller, null, true, loadBalancer);
  
              if (gslbRule.getAccountId() != loadBalancer.getAccountId()) {
                  throw new InvalidParameterValueException("GSLB rule and load balancer rule does not belong to same account");
              }
  
              if (loadBalancer.getState() == LoadBalancer.State.Revoke) {
                  throw new InvalidParameterValueException("Load balancer ID " + loadBalancer.getUuid() + " is in revoke state");
              }
  
              if (oldLbRuleIds != null && oldLbRuleIds.contains(loadBalancer.getId())) {
                  throw new InvalidParameterValueException("Load balancer ID " + loadBalancer.getUuid() + " is already assigned");
              }
  
              Network network = _networkDao.findById(loadBalancer.getNetworkId());
  
              if (oldZones != null && oldZones.contains(network.getDataCenterId()) || newZones != null && newZones.contains(network.getDataCenterId())) {
                  throw new InvalidParameterValueException("Load balancer rule specified should be in unique zone");
              }
  
              newZones.add(network.getDataCenterId());
              physcialNetworks.add(new Pair<Long, Long>(network.getDataCenterId(), network.getPhysicalNetworkId()));
          }
  
          // for each of the physical network check if GSLB service provider configured
          for (Pair<Long, Long> physicalNetwork : physcialNetworks) {
              if (!checkGslbServiceEnabledInZone(physicalNetwork.first(), physicalNetwork.second())) {
                  throw new InvalidParameterValueException("GSLB service is not enabled in the Zone:" + physicalNetwork.first() + " and physical network " +
                      physicalNetwork.second());
              }
          }
  
          final Map<Long, Long> lbRuleWeightMap = assignToGslbCmd.getLoadBalancerRuleWeightMap();
  
          Transaction.execute(new TransactionCallbackNoReturn() {
              @Override
              public void doInTransactionWithoutResult(TransactionStatus status) {
                  // persist the mapping for the new Lb rule that needs to assigned to a gslb rule
                  for (Long lbRuleId : newLbRuleIds) {
                      GlobalLoadBalancerLbRuleMapVO newGslbLbMap = new GlobalLoadBalancerLbRuleMapVO();
                      newGslbLbMap.setGslbLoadBalancerId(gslbRuleId);
                      newGslbLbMap.setLoadBalancerId(lbRuleId);
                      if (lbRuleWeightMap != null && lbRuleWeightMap.get(lbRuleId) != null) {
                          newGslbLbMap.setWeight(lbRuleWeightMap.get(lbRuleId));
                      }
                      _gslbLbMapDao.persist(newGslbLbMap);
                  }
  
                  // mark the gslb rule state as add
                  if (gslbRule.getState() == GlobalLoadBalancerRule.State.Staged || gslbRule.getState() == GlobalLoadBalancerRule.State.Active) {
                      gslbRule.setState(GlobalLoadBalancerRule.State.Add);
                      _gslbRuleDao.update(gslbRule.getId(), gslbRule);
                  }
              }
          });
  
          boolean success = false;
          try {
              s_logger.debug("Configuring gslb rule configuration on the gslb service providers in the participating zones");
  
              // apply the gslb rule on to the back end gslb service providers on zones participating in gslb
              if (!applyGlobalLoadBalancerRuleConfig(gslbRuleId, false)) {
                  s_logger.warn("Failed to add load balancer rules " + newLbRuleIds + " to global load balancer rule id " + gslbRuleId);
                  CloudRuntimeException ex = new CloudRuntimeException("Failed to add load balancer rules to GSLB rule ");
                  throw ex;
              }
  
              // on success set state to Active
              gslbRule.setState(GlobalLoadBalancerRule.State.Active);
              _gslbRuleDao.update(gslbRule.getId(), gslbRule);
  
              success = true;
  
          } catch (ResourceUnavailableException e) {
              throw new CloudRuntimeException("Failed to apply new GSLB configuration while assigning new LB rules to GSLB rule.");
          }
  
          return success;
      }
focal_method.class_method_signature: GlobalLoadBalancingRulesServiceImpl.assignToGlobalLoadBalancerRule(AssignToGlobalLoadBalancerRuleCmd assignToGslbCmd)
focal_method.full_signature: @Override @DB @ActionEvent(eventType = EventTypes.EVENT_ASSIGN_TO_GLOBAL_LOAD_BALANCER_RULE, eventDescription = "Assigning a load balancer rule to global load balancer rule", async = true) public boolean assignToGlobalLoadBalancerRule(AssignToGlobalLoadBalancerRuleCmd assignToGslbCmd)
focal_method.identifier: assignToGlobalLoadBalancerRule
focal_method.invocations: current getCallingAccount getGlobalLoadBalancerRuleId findById checkAccess getState getUuid getLoadBalancerRulesIds isEmpty listByGslbRuleId findById getLoadBalancerId findById getNetworkId add getDataCenterId add getLoadBalancerId findById checkAccess getAccountId getAccountId getState getUuid contains getId getUuid findById getNetworkId contains getDataCenterId contains getDataCenterId add getDataCenterId add getDataCenterId getPhysicalNetworkId checkGslbServiceEnabledInZone first second first second getLoadBalancerRuleWeightMap execute setGslbLoadBalancerId setLoadBalancerId get setWeight get persist getState getState setState update getId debug applyGlobalLoadBalancerRuleConfig warn setState update getId
focal_method.modifiers: @Override @DB @ActionEvent(eventType = EventTypes.EVENT_ASSIGN_TO_GLOBAL_LOAD_BALANCER_RULE, eventDescription = "Assigning a load balancer rule to global load balancer rule", async = true) public
focal_method.parameters: (AssignToGlobalLoadBalancerRuleCmd assignToGslbCmd)
focal_method.return: boolean
focal_method.signature: boolean assignToGlobalLoadBalancerRule(AssignToGlobalLoadBalancerRuleCmd assignToGslbCmd)