Coverage Report - com.ctrip.apollo.biz.eureka.ApolloEurekaClientConfig
 
Classes in this File Line Coverage Branch Coverage Complexity
ApolloEurekaClientConfig
25%
2/8
0%
0/6
6
 
 1  
 package com.ctrip.apollo.biz.eureka;
 2  
 
 3  
 import com.google.common.base.Splitter;
 4  
 import com.google.common.base.Strings;
 5  
 
 6  
 import com.ctrip.apollo.biz.entity.ServerConfig;
 7  
 import com.ctrip.apollo.biz.repository.ServerConfigRepository;
 8  
 
 9  
 import org.springframework.beans.factory.annotation.Autowired;
 10  
 import org.springframework.cloud.netflix.eureka.EurekaClientConfigBean;
 11  
 import org.springframework.context.annotation.Primary;
 12  
 import org.springframework.core.env.Environment;
 13  
 import org.springframework.stereotype.Component;
 14  
 
 15  
 import java.util.List;
 16  
 import java.util.Objects;
 17  
 
 18  
 @Component
 19  
 @Primary
 20  1
 public class ApolloEurekaClientConfig extends EurekaClientConfigBean {
 21  
   static final String EUREKA_URL_CONFIG = "eureka.service.url";
 22  1
   private static final Splitter URL_SPLITTER = Splitter.on(",").omitEmptyStrings();
 23  
 
 24  
   @Autowired
 25  
   private ServerConfigRepository serverConfigRepository;
 26  
 
 27  
   @Autowired
 28  
   private Environment environment;
 29  
 
 30  
   /**
 31  
    * Assert only one zone: defaultZone, but multiple environments.
 32  
    */
 33  
   public List<String> getEurekaServerServiceUrls(String myZone) {
 34  
     //First check if there is any system property override
 35  0
     if (!Strings.isNullOrEmpty(environment.getProperty(EUREKA_URL_CONFIG))) {
 36  0
       return URL_SPLITTER.splitToList(environment.getProperty(EUREKA_URL_CONFIG));
 37  
     }
 38  
 
 39  
     //Second check if it is configured in database
 40  0
     ServerConfig eurekaUrl = serverConfigRepository.findByKey(EUREKA_URL_CONFIG);
 41  
 
 42  0
     if (!Objects.isNull(eurekaUrl) && !Strings.isNullOrEmpty(eurekaUrl.getValue())) {
 43  0
       return URL_SPLITTER.splitToList(eurekaUrl.getValue());
 44  
 
 45  
     }
 46  
 
 47  
     //fallback to default
 48  0
     return super.getEurekaServerServiceUrls(myZone);
 49  
   }
 50  
 
 51  
 }