本文整理汇总了Java中com.netflix.discovery.shared.Application.getInstances方法的典型用法代码示例。如果您正苦于以下问题:Java Application.getInstances方法的具体用法?Java Application.getInstances怎么用?Java Application.getInstances使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.netflix.discovery.shared.Application
的用法示例。
在下文中一共展示了Application.getInstances方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getApplications
import com.netflix.discovery.shared.Application; //导入方法依赖的package包/类
private List<Map<String, Object>> getApplications() {
List<Application> sortedApplications = getRegistry().getSortedApplications();
ArrayList<Map<String, Object>> apps = new ArrayList<>();
for (Application app : sortedApplications) {
LinkedHashMap<String, Object> appData = new LinkedHashMap<>();
apps.add(appData);
appData.put("name", app.getName());
List<Map<String, Object>> instances = new ArrayList<>();
for (InstanceInfo info : app.getInstances()) {
Map<String, Object> instance = new HashMap<>();
instance.put("instanceId", info.getInstanceId());
instance.put("homePageUrl", info.getHomePageUrl());
instance.put("healthCheckUrl", info.getHealthCheckUrl());
instance.put("statusPageUrl", info.getStatusPageUrl());
instance.put("status", info.getStatus().name());
instance.put("metadata", info.getMetadata());
instances.add(instance);
}
appData.put("instances", instances);
}
return apps;
}
示例2: renew
import com.netflix.discovery.shared.Application; //导入方法依赖的package包/类
@Override
public boolean renew(final String appName, final String serverId,
boolean isReplication) {
log("renew " + appName + " serverId " + serverId + ", isReplication {}"
+ isReplication);
List<Application> applications = getSortedApplications();
for (Application input : applications) {
if (input.getName().equals(appName)) {
InstanceInfo instance = null;
for (InstanceInfo info : input.getInstances()) {
if (info.getId().equals(serverId)) {
instance = info;
break;
}
}
publishEvent(new EurekaInstanceRenewedEvent(this, appName, serverId,
instance, isReplication));
break;
}
}
return super.renew(appName, serverId, isReplication);
}
示例3: getApplications
import com.netflix.discovery.shared.Application; //导入方法依赖的package包/类
private List<Map<String, Object>> getApplications() {
List<Application> sortedApplications = getRegistry().getSortedApplications();
ArrayList<Map<String, Object>> apps = new ArrayList<>();
for (Application app : sortedApplications) {
LinkedHashMap<String, Object> appData = new LinkedHashMap<>();
apps.add(appData);
appData.put("name", app.getName());
List<Map<String, String>> instances = new ArrayList<>();
for (InstanceInfo info : app.getInstances()) {
Map<String, String> instance = new HashMap<>();
instance.put("instanceId", info.getInstanceId());
instance.put("homePageUrl", info.getHomePageUrl());
instance.put("healthCheckUrl", info.getHealthCheckUrl());
instance.put("statusPageUrl", info.getStatusPageUrl());
instance.put("status", info.getStatus().name());
instances.add(instance);
}
appData.put("instances", instances);
}
return apps;
}
示例4: getEurekaDetails
import com.netflix.discovery.shared.Application; //导入方法依赖的package包/类
@GET
public Response getEurekaDetails() {
List<EurekaInstanceInfo> instanceInfoList = new ArrayList<EurekaInstanceInfo>();
DiscoveryClient discoveryClient = DiscoveryManager.getInstance().getDiscoveryClient();
if (null != discoveryClient) {
Applications apps = discoveryClient.getApplications();
for (Application app : apps.getRegisteredApplications()) {
for (InstanceInfo inst : app.getInstances()) {
instanceInfoList.add(new EurekaInstanceInfo(inst.getAppName(), inst.getId(), inst.getStatus().name(), inst.getIPAddr(), inst.getHostName()));
}
}
}
GsonBuilder gsonBuilder = new GsonBuilder().serializeNulls();
Gson gson = gsonBuilder.create();
String response = gson.toJson(new KaryonAdminResponse(instanceInfoList));
return Response.ok(response).build();
}
示例5: getConfigServiceInstances
import com.netflix.discovery.shared.Application; //导入方法依赖的package包/类
public List<InstanceInfo> getConfigServiceInstances() {
Application application = eurekaClient.getApplication(Constant.APPLICATION_NAME);
if (application == null) {
LOGGER.error("获取eureka服务失败!");
}
return application != null ? application.getInstances() : new ArrayList<>();
}
示例6: getConfigServiceInstances
import com.netflix.discovery.shared.Application; //导入方法依赖的package包/类
public List<InstanceInfo> getConfigServiceInstances() {
Application application = eurekaClient.getApplication(tmKey);
if (application == null) {
LOGGER.error("获取eureka服务失败!");
}
return application != null ? application.getInstances() : new ArrayList<>();
}
示例7: getConfigServiceInstances
import com.netflix.discovery.shared.Application; //导入方法依赖的package包/类
public List<InstanceInfo> getConfigServiceInstances(String key) {
Application application = eurekaClient.getApplication(key);
if (application == null) {
logger.error("获取eureka服务失败!");
}
return application!=null?application.getInstances():new ArrayList<InstanceInfo>();
}
示例8: getConfigServiceInstances
import com.netflix.discovery.shared.Application; //导入方法依赖的package包/类
public List<InstanceInfo> getConfigServiceInstances() {
Application application = eurekaClient.getApplication(ServiceNameConsts.APOLLO_CONFIGSERVICE);
if (application == null) {
Tracer.logEvent("Apollo.EurekaDiscovery.NotFound", ServiceNameConsts.APOLLO_CONFIGSERVICE);
}
return application != null ? application.getInstances() : Collections.emptyList();
}
示例9: getMetaServiceInstances
import com.netflix.discovery.shared.Application; //导入方法依赖的package包/类
public List<InstanceInfo> getMetaServiceInstances() {
Application application = eurekaClient.getApplication(ServiceNameConsts.APOLLO_METASERVICE);
if (application == null) {
Tracer.logEvent("Apollo.EurekaDiscovery.NotFound", ServiceNameConsts.APOLLO_METASERVICE);
}
return application != null ? application.getInstances() : Collections.emptyList();
}
示例10: getAdminServiceInstances
import com.netflix.discovery.shared.Application; //导入方法依赖的package包/类
public List<InstanceInfo> getAdminServiceInstances() {
Application application = eurekaClient.getApplication(ServiceNameConsts.APOLLO_ADMINSERVICE);
if (application == null) {
Tracer.logEvent("Apollo.EurekaDiscovery.NotFound", ServiceNameConsts.APOLLO_ADMINSERVICE);
}
return application != null ? application.getInstances() : Collections.emptyList();
}
示例11: discoverNodes
import com.netflix.discovery.shared.Application; //导入方法依赖的package包/类
public Iterable<DiscoveryNode> discoverNodes() {
List<DiscoveryNode> nodes = new ArrayList<DiscoveryNode>();
String applicationName = applicationInfoManager.getEurekaInstanceConfig().getAppname();
Application application = null;
for (int i = 0; i < NUM_RETRIES; i++) {
application = eurekaClient.getApplication(applicationName);
if (application != null) {
break;
}
try {
TimeUnit.SECONDS.sleep(DISCOVERY_RETRY_TIMEOUT);
} catch (InterruptedException almostIgnore) {
Thread.currentThread().interrupt();
}
}
if (application != null) {
List<InstanceInfo> instances = application.getInstances();
for (InstanceInfo instance : instances) {
// Only recognize up and running instances
if (instance.getStatus() != InstanceInfo.InstanceStatus.UP) {
continue;
}
InetAddress address = mapAddress(instance);
if (null == address) {
continue;
}
int port = instance.getPort();
Map<String, Object> metadata = (Map) instance.getMetadata();
nodes.add(new SimpleDiscoveryNode(new Address(address, port), metadata));
}
}
return nodes;
}
示例12: getInstancesForApp
import com.netflix.discovery.shared.Application; //导入方法依赖的package包/类
/**
* Private helper that fetches the Instances for each application.
* @param serviceId
* @return List<Instance>
* @throws Exception
*/
@Override
protected List<Instance> getInstancesForApp(String serviceId) throws Exception {
List<Instance> instances = new ArrayList<>();
log.info("Fetching instances for app: " + serviceId);
Application app = eurekaClient.getApplication(serviceId);
if (app == null) {
log.warn("Eureka returned null for app: " + serviceId);
return instances;
}
try {
List<InstanceInfo> instancesForApp = app.getInstances();
if (instancesForApp != null) {
log.info("Received instance list for app: " + serviceId + ", size="
+ instancesForApp.size());
for (InstanceInfo iInfo : instancesForApp) {
Instance instance = marshall(iInfo);
if (instance != null) {
instances.add(instance);
}
}
}
}
catch (Exception e) {
log.warn("Failed to retrieve instances from Eureka", e);
}
return instances;
}
示例13: getSocketAddressForNode
import com.netflix.discovery.shared.Application; //导入方法依赖的package包/类
/**
* Returns the socket address of a given MemcachedNode.
*
* @param node - The MemcachedNode which we're interested in
* @return The socket address of the given node format is of the following
* format "publicHostname/privateIp:port" (ex -
ec2-174-129-159-31.compute-1.amazonaws.com/10.125.47.114:11211)
*/
@Override
protected String getSocketAddressForNode(MemcachedNode node) {
String result = socketAddresses.get(node);
if(result == null) {
final SocketAddress socketAddress = node.getSocketAddress();
if(socketAddress instanceof InetSocketAddress) {
final InetSocketAddress isa = (InetSocketAddress)socketAddress;
if(poolManager.getDiscoveryClient() != null ) {
final DiscoveryClient mgr = poolManager.getDiscoveryClient();
final Application app = mgr.getApplication(appId);
if(app != null) {
final List<InstanceInfo> instances = app.getInstances();
for(InstanceInfo info : instances) {
final String hostName = info.getHostName();
if(hostName.equalsIgnoreCase(isa.getHostName())) {
final String ip = info.getIPAddr();
String port = info.getMetadata().get("evcache.port");
if(port == null) port = "11211";
result = hostName + '/' + ip + ':' + port;
break;
}
}
} else {
result = ((InetSocketAddress)socketAddress).getHostName() + '/' + ((InetSocketAddress)socketAddress).getAddress().getHostAddress() + ":11211";
}
} else {
result = ((InetSocketAddress)socketAddress).getHostName() + '/' + ((InetSocketAddress)socketAddress).getAddress().getHostAddress() + ":11211";
}
} else {
result=String.valueOf(socketAddress);
if (result.startsWith("/")) {
result = result.substring(1);
}
}
socketAddresses.put(node, result);
}
return result;
}
示例14: getSupplier
import com.netflix.discovery.shared.Application; //导入方法依赖的package包/类
@Override
public Supplier<List<Host>> getSupplier(final String clusterName)
{
return new Supplier<List<Host>>() {
@Override
public List<Host> get() {
if (discoveryClient == null) {
LOG.error("Discovery client cannot be null");
throw new RuntimeException("EurekaHostsSupplier needs a non-null DiscoveryClient");
}
LOG.debug("Raigad fetching instance list for app: " + clusterName);
Application app = discoveryClient.getApplication(clusterName.toUpperCase());
List<Host> hosts = new ArrayList<Host>();
if (app == null) {
LOG.warn("Cluster '{}' not found in eureka", clusterName);
return hosts;
}
List<InstanceInfo> ins = app.getInstances();
if (ins == null || ins.isEmpty()) {
LOG.warn("Cluster '{}' found in eureka but has no instances", clusterName);
return hosts;
}
hosts = Lists.newArrayList(Collections2.transform(
Collections2.filter(ins, new Predicate<InstanceInfo>() {
@Override
public boolean apply(InstanceInfo input) {
return input.getStatus() == InstanceInfo.InstanceStatus.UP;
}
}), new Function<InstanceInfo, Host>() {
@Override
public Host apply(InstanceInfo info) {
String[] parts = StringUtils.split(
StringUtils.split(info.getHostName(), ".")[0], '-');
Host host = new Host(info.getHostName(), info.getPort())
.addAlternateIpAddress(
StringUtils.join(new String[] { parts[1], parts[2], parts[3],
parts[4] }, "."))
.addAlternateIpAddress(info.getIPAddr())
.setId(info.getId());
try {
if (info.getDataCenterInfo() instanceof AmazonInfo) {
AmazonInfo amazonInfo = (AmazonInfo)info.getDataCenterInfo();
host.setRack(amazonInfo.get(MetaDataKey.availabilityZone));
}
}
catch (Throwable t) {
LOG.error("Error getting rack for host " + host.getName(), t);
}
return host;
}
}));
LOG.debug("Raigad found hosts from eureka - num hosts: " + hosts.size());
return hosts;
}
};
}
示例15: getSupplier
import com.netflix.discovery.shared.Application; //导入方法依赖的package包/类
public Supplier<List<Host>> getSupplier(final String clusterName) {
return new Supplier<List<Host>>() {
public List<Host> get() {
Application app = eurekaClient.getApplication(clusterName.toUpperCase());
List<Host> hosts = Lists.newArrayList();
if (app == null) {
LOG.warn("Cluster '{}' not found in eureka", new Object[]{clusterName});
}
else {
List<InstanceInfo> ins = app.getInstances();
if (ins != null && !ins.isEmpty()) {
hosts = Lists.newArrayList(Collections2.transform(
Collections2.filter(ins, new Predicate<InstanceInfo>() {
public boolean apply(InstanceInfo input) {
return input.getStatus() == InstanceInfo.InstanceStatus.UP;
}
}), new Function<InstanceInfo, Host>() {
public Host apply(InstanceInfo info) {
String[] parts = StringUtils.split(
StringUtils.split(info.getHostName(), ".")[0], '-');
Host host = new Host(info.getHostName(), info.getPort())
.addAlternateIpAddress(
StringUtils.join(new String[] { parts[1], parts[2], parts[3],
parts[4] }, "."))
.addAlternateIpAddress(info.getIPAddr())
.setId(info.getId());
try {
if (info.getDataCenterInfo() instanceof AmazonInfo) {
AmazonInfo amazonInfo = (AmazonInfo)info.getDataCenterInfo();
host.setRack(amazonInfo.get(MetaDataKey.availabilityZone));
}
}
catch (Throwable t) {
LOG.error("Error getting rack for host " + host.getName(), t);
}
return host;
}
}));
}
else {
LOG.warn("Cluster '{}' found in eureka but has no instances", new Object[]{clusterName});
}
}
return hosts;
}
};
}