本文整理汇总了Java中com.netflix.appinfo.InstanceInfo.getDataCenterInfo方法的典型用法代码示例。如果您正苦于以下问题:Java InstanceInfo.getDataCenterInfo方法的具体用法?Java InstanceInfo.getDataCenterInfo怎么用?Java InstanceInfo.getDataCenterInfo使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.netflix.appinfo.InstanceInfo
的用法示例。
在下文中一共展示了InstanceInfo.getDataCenterInfo方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: populateInstanceInfo
import com.netflix.appinfo.InstanceInfo; //导入方法依赖的package包/类
private void populateInstanceInfo(Map<String, Object> model, StatusInfo statusInfo) {
InstanceInfo instanceInfo = statusInfo.getInstanceInfo();
Map<String, String> instanceMap = new HashMap<>();
instanceMap.put("ipAddr", instanceInfo.getIPAddr());
instanceMap.put("status", instanceInfo.getStatus().toString());
if (instanceInfo.getDataCenterInfo().getName() == DataCenterInfo.Name.Amazon) {
AmazonInfo info = (AmazonInfo) instanceInfo.getDataCenterInfo();
instanceMap.put("availability-zone",
info.get(AmazonInfo.MetaDataKey.availabilityZone));
instanceMap.put("public-ipv4", info.get(AmazonInfo.MetaDataKey.publicIpv4));
instanceMap.put("instance-id", info.get(AmazonInfo.MetaDataKey.instanceId));
instanceMap.put("public-hostname",
info.get(AmazonInfo.MetaDataKey.publicHostname));
instanceMap.put("ami-id", info.get(AmazonInfo.MetaDataKey.amiId));
instanceMap.put("instance-type",
info.get(AmazonInfo.MetaDataKey.instanceType));
}
model.put("instanceInfo", instanceMap);
}
示例2: buildHost
import com.netflix.appinfo.InstanceInfo; //导入方法依赖的package包/类
static Host buildHost(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(AmazonInfo.MetaDataKey.availabilityZone));
}
}
catch (Throwable t) {
logger.error("Error getting rack for host " + host.getName(), t);
}
return host;
}
示例3: marshall
import com.netflix.appinfo.InstanceInfo; //导入方法依赖的package包/类
/**
* Private helper that marshals the information from each instance into something that
* Turbine can understand. Override this method for your own implementation for
* parsing Eureka info.
* @param instanceInfo
* @return Instance
*/
Instance marshall(InstanceInfo instanceInfo) {
String hostname = instanceInfo.getHostName();
final String managementPort = instanceInfo.getMetadata().get("management.port");
String port = managementPort == null ? String.valueOf(instanceInfo.getPort()) : managementPort;
String cluster = getClusterName(instanceInfo);
Boolean status = parseInstanceStatus(instanceInfo.getStatus());
if (hostname != null && cluster != null && status != null) {
Instance instance = getInstance(hostname, port, cluster, status);
Map<String, String> metadata = instanceInfo.getMetadata();
boolean securePortEnabled = instanceInfo.isPortEnabled(InstanceInfo.PortType.SECURE);
String securePort = String.valueOf(instanceInfo.getSecurePort());
addMetadata(instance, hostname, port, securePortEnabled, securePort, metadata);
// add amazon metadata
String asgName = instanceInfo.getASGName();
if (asgName != null) {
instance.getAttributes().put(ASG_KEY, asgName);
}
DataCenterInfo dcInfo = instanceInfo.getDataCenterInfo();
if (dcInfo != null && dcInfo.getName().equals(DataCenterInfo.Name.Amazon)) {
AmazonInfo amznInfo = (AmazonInfo) dcInfo;
instance.getAttributes().putAll(amznInfo.getMetadata());
}
return instance;
}
else {
return null;
}
}