| 1 | |
package com.ctrip.apollo.metaservice.service; |
| 2 | |
|
| 3 | |
import com.ctrip.apollo.core.ServiceNameConsts; |
| 4 | |
import com.dianping.cat.Cat; |
| 5 | |
import com.netflix.appinfo.InstanceInfo; |
| 6 | |
import com.netflix.discovery.EurekaClient; |
| 7 | |
import com.netflix.discovery.shared.Application; |
| 8 | |
|
| 9 | |
import org.springframework.beans.factory.annotation.Autowired; |
| 10 | |
import org.springframework.stereotype.Service; |
| 11 | |
|
| 12 | |
import java.util.ArrayList; |
| 13 | |
import java.util.List; |
| 14 | |
|
| 15 | |
@Service |
| 16 | 1 | public class DiscoveryService { |
| 17 | |
|
| 18 | |
@Autowired |
| 19 | |
private EurekaClient eurekaClient; |
| 20 | |
|
| 21 | |
public List<InstanceInfo> getConfigServiceInstances() { |
| 22 | 0 | Application application = eurekaClient.getApplication(ServiceNameConsts.APOLLO_CONFIGSERVICE); |
| 23 | 0 | if (application == null) { |
| 24 | 0 | Cat.logEvent("Apollo.EurekaDiscovery.NotFound", ServiceNameConsts.APOLLO_CONFIGSERVICE); |
| 25 | |
} |
| 26 | 0 | return application != null ? application.getInstances() : new ArrayList<>(); |
| 27 | |
} |
| 28 | |
|
| 29 | |
public List<InstanceInfo> getMetaServiceInstances() { |
| 30 | 0 | Application application = eurekaClient.getApplication(ServiceNameConsts.APOLLO_METASERVICE); |
| 31 | 0 | if (application == null) { |
| 32 | 0 | Cat.logEvent("Apollo.EurekaDiscovery.NotFound", ServiceNameConsts.APOLLO_METASERVICE); |
| 33 | |
} |
| 34 | 0 | return application != null ? application.getInstances() : new ArrayList<>(); |
| 35 | |
} |
| 36 | |
|
| 37 | |
public List<InstanceInfo> getAdminServiceInstances() { |
| 38 | 0 | Application application = eurekaClient.getApplication(ServiceNameConsts.APOLLO_ADMINSERVICE); |
| 39 | 0 | if (application == null) { |
| 40 | 0 | Cat.logEvent("Apollo.EurekaDiscovery.NotFound", ServiceNameConsts.APOLLO_ADMINSERVICE); |
| 41 | |
} |
| 42 | 0 | return application != null ? application.getInstances() : new ArrayList<>(); |
| 43 | |
} |
| 44 | |
} |