當前位置: 首頁>>代碼示例>>Java>>正文


Java MetaDataKey類代碼示例

本文整理匯總了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;
        }
    };
}
 
開發者ID:Netflix,項目名稱:Raigad,代碼行數:70,代碼來源:EurekaHostsSupplier.java

示例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;
        }
    };
}
 
開發者ID:Netflix,項目名稱:staash,代碼行數:52,代碼來源:EurekaAstyanaxHostSupplier.java

示例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;
        }
    };
}
 
開發者ID:Netflix,項目名稱:staash,代碼行數:56,代碼來源:EurekaAstyanaxHostSupplier.java


注:本文中的com.netflix.appinfo.AmazonInfo.MetaDataKey類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。