@Override public void call() { instanceInfoById.put(newInfo.getId(), newInfo); } });
@Override public void onNext(InstanceInfo instanceInfo) { totalCount.incrementAndGet(); newSnapshot.put(instanceInfo.getId(), instanceInfo); if (currentSnapshot.containsKey(instanceInfo.getId())) { InstanceInfo older = currentSnapshot.get(instanceInfo.getId()); if (!older.equals(instanceInfo)) { Set<Delta<?>> deltas = older.diffNewer(instanceInfo); registry.update(instanceInfo, deltas); updateCount.incrementAndGet(); } } else { registry.register(instanceInfo); registerCount.incrementAndGet(); } } });
private void refresh() { final Map<String, InstanceInfo> regCache = registryCache.getCache(); List<RegistryItem> registryItemsCurrent = new ArrayList<>(); for (Map.Entry<String, InstanceInfo> instanceInfo : regCache.entrySet()) { registryItemsCurrent.add(new RegistryItem(instanceInfo.getKey(), instanceInfo.getValue().getApp(), instanceInfo.getValue().getVipAddress(), instanceInfo.getValue().getStatus().name())); } if (isCurrentSnapshotSafeToRefresh(registryItemsCurrent.size())) { registryItemsRef.set(registryItemsCurrent); } }
private static String extractInstanceId(InstanceInfo instanceInfo) { if (instanceInfo != null && instanceInfo.getDataCenterInfo() != null && AwsDataCenterInfo.class.isAssignableFrom(instanceInfo.getDataCenterInfo().getClass())) { final AwsDataCenterInfo dataCenterInfo = (AwsDataCenterInfo) instanceInfo.getDataCenterInfo(); return dataCenterInfo.getInstanceId(); } return instanceInfo.getId(); }
/** * For an UpdateInstanceInfo msg, * - if it does not exist in cache, we ignore this message as we do not have enough information to restore it * - if it exist in cache but is different, this is a modify notification to the store. * We only apply changes to cached instance if it has a version number GREATER THAN the cached * version number. */ @SuppressWarnings("unchecked") private ChangeNotification<InstanceInfo> updateMessageToChangeNotification(UpdateInstanceInfo msg) { ModifyNotification<InstanceInfo> notification = null; Delta delta = msg.getDelta(); InstanceInfo cached = idVsInstance.get(delta.getId()); if (cached == null) { if (logger.isWarnEnabled()) { logger.warn("Update notification received for non-existent instance id " + delta.getId()); } } else if (delta.getVersion() <= cached.getVersion()) { logger.debug("Skipping <= version of the delta. Cached: {}, Delta: {}", cached, delta); } else { InstanceInfo updatedInfo = cached.applyDelta(delta); idVsInstance.put(updatedInfo.getId(), updatedInfo); notification = new ModifyNotification(updatedInfo, Collections.singleton(delta)); } return notification; }
/** * For an AddInstance msg, * - if it does not exist in cache, this is an Add Notification to the store * - if it exist in cache but had a different version, this is a modify notification to the store. * For simplicity we treat this as an add if the new msg have a GREATER version number, * and ignore it otherwise */ private ChangeNotification<InstanceInfo> addMessageToChangeNotification(AddInstance msg) { ChangeNotification<InstanceInfo> notification = null; InstanceInfo incoming = msg.getInstanceInfo(); InstanceInfo cached = idVsInstance.get(incoming.getId()); if (cached == null) { idVsInstance.put(incoming.getId(), incoming); notification = new ChangeNotification<>(ChangeNotification.Kind.Add, incoming); } else if (incoming.getVersion() <= cached.getVersion()) { logger.debug("Skipping <= version of the instanceInfo. Cached: {}, Incoming: {}", cached, incoming); } else { logger.debug("Received newer version of an existing instanceInfo as Add"); idVsInstance.put(incoming.getId(), incoming); notification = new ChangeNotification<>(ChangeNotification.Kind.Add, incoming); } return notification; }
if (prev != null && prev.getVersion() > data.getVersion()) { return Observable.just(Status.AddExpired); snapshot = newSnapshot; Set<Delta<?>> delta = newSnapshot.getData().diffOlder(currSnapshot.getData()); if (!delta.isEmpty()) { ChangeNotification<InstanceInfo> modifyNotification notificationSubject.onNext(modifyNotification); } else { logger.debug("No-change update for {}#{}", currSnapshot.getSource(), currSnapshot.getData().getId());
@Override public Observable<Void> update(final InstanceInfo newInfo) { logger.debug("Updating existing registry entry. New info= {}", newInfo); if (STATES.Opened != state.get()) { return Observable.error(state.get() == STATES.Closed ? CHANNEL_CLOSED_EXCEPTION : IDLE_STATE_EXCEPTION); } if (replicationLoop) { return Observable.error(REPLICATION_LOOP_EXCEPTION); } InstanceInfo currentInfo = instanceInfoById.get(newInfo.getId()); if (currentInfo == null) { logger.info("Replication update request for non-existing entry {}; handling it as an initial registration", newInfo.getId()); return register(newInfo); } InstanceInfo tempNewInfo = new InstanceInfo.Builder() .withInstanceInfo(newInfo).withVersion(currentVersion++).build(); Set<Delta<?>> deltas = tempNewInfo.diffOlder(currentInfo); logger.debug("Set of InstanceInfo modified fields: {}", deltas); return registry.update(tempNewInfo, deltas, replicationSource) .ignoreElements() .cast(Void.class) .doOnCompleted(new Action0() { @Override public void call() { instanceInfoById.put(newInfo.getId(), newInfo); } }); }
@Override public InstanceInfo next() { int cidx = idx.incrementAndGet(); String name = baseName + '_' + cidx; NetworkAddress publicAddress = publicAddresses.next(); NetworkAddress privateAddress = privateAddresses.next(); DataCenterInfo dataCenter = new AwsDataCenterInfo.Builder() .withAwsDataCenter(templateDataCenter) .withPublicHostName(publicAddress.getHostName()) .withPublicIPv4(publicAddress.getIpAddress()) .withPrivateHostName(privateAddress.getHostName()) .withPrivateIPv4(privateAddress.getIpAddress()) .build(); return new InstanceInfo.Builder() .withId("id#" + name) .withApp("app#" + baseName) .withAppGroup("group#" + baseName) .withAsg("asg#" + baseName) .withHealthCheckUrls(template.getHealthCheckUrls()) .withHomePageUrl(template.getHomePageUrl()) .withPorts(template.getPorts()) .withSecureVipAddress("vipSecure#" + name) .withStatus(template.getStatus()) .withStatusPageUrl(template.getStatusPageUrl()) .withVipAddress("vip#" + baseName) .withMetaData(template.getMetaData()) .withDataCenterInfo(dataCenter) .build(); }
@Override public boolean matches(Object item) { if (!(item instanceof InstanceInfo)) { return false; } // Versions may be different InstanceInfo target = (InstanceInfo) item; if (!expectSameVersion) { target = new Builder() .withInstanceInfo(target) .withVersion(expectedValue.getVersion()) .build(); } return target.equals(expectedValue); }
private void publishEurekaServerStatus() { final Map<String, InstanceInfo> regCache = registryCache.getCache(); List<InstanceInfo> eurekaInstances = new ArrayList<>(); for (Map.Entry<String, InstanceInfo> instanceInfo : regCache.entrySet()) { if (instanceInfo.getValue().getApp().toLowerCase().startsWith("eureka")) { eurekaInstances.add(instanceInfo.getValue()); } } registryBehaviorSubject.onNext(eurekaInstances); }
@Override public boolean equals(Object o) { if (this == o) return true; if (!(o instanceof AuditRecord)) return false; AuditRecord that = (AuditRecord) o; if (time != that.time) return false; if (userTriggered != that.userTriggered) return false; if (auditServerId != null ? !auditServerId.equals(that.auditServerId) : that.auditServerId != null) return false; if (deltas != null ? !deltas.equals(that.deltas) : that.deltas != null) return false; if (instanceInfo != null ? !instanceInfo.equals(that.instanceInfo) : that.instanceInfo != null) return false; if (modificationType != that.modificationType) return false; return true; }
@Override public Interest<InstanceInfo> build() { return Interests.forVips(SampleInstanceInfo.ZuulServer.build().getVipAddress()); } },
public static Iterator<InstanceInfo> collectionOf(final String baseName, final InstanceInfo template) { final AwsDataCenterInfo templateDataCenter = (AwsDataCenterInfo) template.getDataCenterInfo(); final AtomicInteger idx = new AtomicInteger(); final Iterator<NetworkAddress> publicAddresses = SampleNetworkAddress.collectionOfIPv4("20.20", baseName + ".public.net", null);
.withId(lastInstanceInfo.getId()) .withVersion(lastInstanceInfo.getVersion()) .withDelta(field, value) .build(); lastInstanceInfo = lastInstanceInfo.applyDelta(delta);
Builder newBuilder() { return new Builder() .withId(this.baseInstanceInfo.getId()) .withVersion(this.baseInstanceInfo.getVersion() + 1); } }
@Override public Interest<InstanceInfo> build() { return Interests.forApplications(SampleInstanceInfo.ZuulServer.build().getApp()); } },
@Override public Interest<InstanceInfo> build() { return Interests.forApplications(SampleInstanceInfo.DiscoveryServer.build().getVipAddress()); } },
@Override public void call() { instanceInfoById.put(instanceInfo.getId(), instanceInfo); } });
@Override public Interest<InstanceInfo> build() { return Interests.forApplications(SampleInstanceInfo.DiscoveryServer.build().getApp()); } },