use of com.netflix.appinfo.InstanceInfo in project eureka by Netflix.
the class ElasticNetworkInterfaceBinder method alreadyBound.
public boolean alreadyBound() throws MalformedURLException {
InstanceInfo myInfo = applicationInfoManager.getInfo();
String myInstanceId = ((AmazonInfo) myInfo.getDataCenterInfo()).get(AmazonInfo.MetaDataKey.instanceId);
AmazonEC2 ec2Service = getEC2Service();
List<InstanceNetworkInterface> instanceNetworkInterfaces = instanceData(myInstanceId, ec2Service).getNetworkInterfaces();
List<String> candidateIPs = getCandidateIps();
for (String ip : candidateIPs) {
for (InstanceNetworkInterface ini : instanceNetworkInterfaces) {
if (ip.equals(ini.getPrivateIpAddress())) {
logger.info("My instance {} seems to be already associated with the ip {}", myInstanceId, ip);
return true;
}
}
}
return false;
}
use of com.netflix.appinfo.InstanceInfo in project eureka by Netflix.
the class ElasticNetworkInterfaceBinder method getCandidateIps.
/**
* Based on shouldUseDnsForFetchingServiceUrls configuration, either retrieves candidates from dns records or from
* configuration properties.
*
*
*/
public List<String> getCandidateIps() throws MalformedURLException {
InstanceInfo myInfo = applicationInfoManager.getInfo();
String myZone = ((AmazonInfo) myInfo.getDataCenterInfo()).get(AmazonInfo.MetaDataKey.availabilityZone);
Collection<String> candidates = clientConfig.shouldUseDnsForFetchingServiceUrls() ? getIPsForZoneFromDNS(myZone) : getIPsForZoneFromConfig(myZone);
if (candidates == null || candidates.size() == 0) {
throw new RuntimeException("Could not get any ips from the pool for zone :" + myZone);
}
List<String> ips = Lists.newArrayList();
for (String candidate : candidates) {
String host = new URL(candidate).getHost();
if (InetAddresses.isInetAddress(host)) {
ips.add(host);
} else {
// ip-172-31-55-172.ec2.internal -> ip-172-31-55-172
String firstPartOfHost = Splitter.on(".").splitToList(host).get(0);
// ip-172-31-55-172 -> [172,31,55,172]
List<String> noIpPrefix = Splitter.on("-").splitToList(firstPartOfHost).subList(1, 5);
// [172,31,55,172] -> 172.31.55.172
String ip = Joiner.on(".").join(noIpPrefix);
if (InetAddresses.isInetAddress(ip)) {
ips.add(ip);
} else {
throw new IllegalArgumentException("Illegal internal hostname " + host + " translated to '" + ip + "'");
}
}
}
return ips;
}
use of com.netflix.appinfo.InstanceInfo in project eureka by Netflix.
the class PeerAwareInstanceRegistryImpl method updateRenewalThreshold.
/**
* Updates the <em>renewal threshold</em> based on the current number of
* renewals. The threshold is a percentage as specified in
* {@link EurekaServerConfig#getRenewalPercentThreshold()} of renewals
* received per minute {@link #getNumOfRenewsInLastMin()}.
*/
private void updateRenewalThreshold() {
try {
Applications apps = eurekaClient.getApplications();
int count = 0;
for (Application app : apps.getRegisteredApplications()) {
for (InstanceInfo instance : app.getInstances()) {
if (this.isRegisterable(instance)) {
++count;
}
}
}
synchronized (lock) {
// current expected threshold of if the self preservation is disabled.
if ((count * 2) > (serverConfig.getRenewalPercentThreshold() * numberOfRenewsPerMinThreshold) || (!this.isSelfPreservationModeEnabled())) {
this.expectedNumberOfRenewsPerMin = count * 2;
this.numberOfRenewsPerMinThreshold = (int) ((count * 2) * serverConfig.getRenewalPercentThreshold());
}
}
logger.info("Current renewal threshold is : {}", numberOfRenewsPerMinThreshold);
} catch (Throwable e) {
logger.error("Cannot update renewal threshold", e);
}
}
use of com.netflix.appinfo.InstanceInfo in project eureka by Netflix.
the class PeerAwareInstanceRegistryImpl method replicateInstanceActionsToPeers.
/**
* Replicates all instance changes to peer eureka nodes except for
* replication traffic to this node.
*
*/
private void replicateInstanceActionsToPeers(Action action, String appName, String id, InstanceInfo info, InstanceStatus newStatus, PeerEurekaNode node) {
try {
InstanceInfo infoFromRegistry = null;
CurrentRequestVersion.set(Version.V2);
switch(action) {
case Cancel:
node.cancel(appName, id);
break;
case Heartbeat:
InstanceStatus overriddenStatus = overriddenInstanceStatusMap.get(id);
infoFromRegistry = getInstanceByAppAndId(appName, id, false);
node.heartbeat(appName, id, infoFromRegistry, overriddenStatus, false);
break;
case Register:
node.register(info);
break;
case StatusUpdate:
infoFromRegistry = getInstanceByAppAndId(appName, id, false);
node.statusUpdate(appName, id, newStatus, infoFromRegistry);
break;
case DeleteStatusOverride:
infoFromRegistry = getInstanceByAppAndId(appName, id, false);
node.deleteStatusOverride(appName, id, infoFromRegistry);
break;
}
} catch (Throwable t) {
logger.error("Cannot replicate information to {} for action {}", node.getServiceUrl(), action.name(), t);
}
}
use of com.netflix.appinfo.InstanceInfo in project eureka by Netflix.
the class ResponseCacheImpl method getApplicationsForVip.
private static Applications getApplicationsForVip(Key key, AbstractInstanceRegistry registry) {
Object[] args = { key.getEntityType(), key.getName(), key.getVersion(), key.getType() };
logger.debug("Retrieving applications from registry for key : {} {} {} {}", args);
Applications toReturn = new Applications();
Applications applications = registry.getApplications();
for (Application application : applications.getRegisteredApplications()) {
Application appToAdd = null;
for (InstanceInfo instanceInfo : application.getInstances()) {
String vipAddress;
if (Key.EntityType.VIP.equals(key.getEntityType())) {
vipAddress = instanceInfo.getVIPAddress();
} else if (Key.EntityType.SVIP.equals(key.getEntityType())) {
vipAddress = instanceInfo.getSecureVipAddress();
} else {
// should not happen, but just in case.
continue;
}
if (null != vipAddress) {
String[] vipAddresses = vipAddress.split(",");
Arrays.sort(vipAddresses);
if (Arrays.binarySearch(vipAddresses, key.getName()) >= 0) {
if (null == appToAdd) {
appToAdd = new Application(application.getName());
toReturn.addApplication(appToAdd);
}
appToAdd.addInstance(instanceInfo);
}
}
}
}
toReturn.setAppsHashCode(toReturn.getReconcileHashCode());
args = new Object[] { key.getEntityType(), key.getName(), key.getVersion(), key.getType(), toReturn.getReconcileHashCode() };
logger.debug("Retrieved applications from registry for key : {} {} {} {}, reconcile hashcode: {}", args);
return toReturn;
}
Aggregations