本文整理匯總了Java中com.netflix.appinfo.AmazonInfo.MetaDataKey類的典型用法代碼示例。如果您正苦於以下問題:Java MetaDataKey類的具體用法?Java MetaDataKey怎麽用?Java MetaDataKey使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
MetaDataKey類屬於com.netflix.appinfo.AmazonInfo包,在下文中一共展示了MetaDataKey類的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getSupplier
import com.netflix.appinfo.AmazonInfo.MetaDataKey; //導入依賴的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;
}
};
}
示例2: getSupplier
import com.netflix.appinfo.AmazonInfo.MetaDataKey; //導入依賴的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;
}
};
}
示例3: getSupplier
import com.netflix.appinfo.AmazonInfo.MetaDataKey; //導入依賴的package包/類
@Override
public Supplier<List<Host>> getSupplier(final String clusterName) {
return new Supplier<List<Host>>() {
@Override
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>() {
@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;
}
}));
}
else {
LOG.warn("Cluster '{}' found in eureka but has no instances", new Object[]{clusterName});
}
}
return hosts;
}
};
}