@Override protected String getValue(InstanceInfo data) { return data.getId(); } }
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); } }
@Override public boolean matches(Object item) { if (!(item instanceof InstanceInfo)) { return false; } InstanceInfo target = (InstanceInfo) item; return target.equals(expectedValue); }
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(); }
@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) .withInstanceId(String.format("i-%s-%08d", baseName, cidx)) .withPublicHostName(publicAddress.getHostName()) .withPublicIPv4(publicAddress.getIpAddress()) .withPrivateHostName(privateAddress.getHostName()) .withPrivateIPv4(privateAddress.getIpAddress()) .build(); return new InstanceInfo.Builder() .withId("id#" + name) .withApp(template.getApp()) .withAppGroup(template.getAppGroup()) .withAsg(template.getAsg()) .withHealthCheckUrls(template.getHealthCheckUrls()) .withHomePageUrl(template.getHomePageUrl()) .withPorts(template.getPorts()) .withSecureVipAddress(template.getSecureVipAddress()) .withStatus(template.getStatus()) .withStatusPageUrl(template.getStatusPageUrl()) .withVipAddress(template.getVipAddress()) .withMetaData(template.getMetaData()) .withDataCenterInfo(dataCenter) .build(); }
@Override public JsonElement serialize(InstanceInfo instanceInfo, Type typeOfSrc, JsonSerializationContext context) { JsonObject result = new JsonObject(); if (AwsDataCenterInfo.class.isAssignableFrom(instanceInfo.getDataCenterInfo().getClass())) { final AwsDataCenterInfo dataCenterInfo = (AwsDataCenterInfo) instanceInfo.getDataCenterInfo(); result.addProperty("instId", dataCenterInfo.getInstanceId()); if(dataCenterInfo.getPublicAddress() != null) { result.addProperty("ip", dataCenterInfo.getPublicAddress().getIpAddress()); result.addProperty("hostname", dataCenterInfo.getPublicAddress().getHostName()); } result.addProperty("zone", dataCenterInfo.getZone()); result.addProperty("reg", dataCenterInfo.getRegion()); } result.addProperty("appId", instanceInfo.getApp()); result.addProperty("status", instanceInfo.getStatus().name()); result.addProperty("vip", instanceInfo.getVipAddress()); return result; } }
@Override protected String getValue(InstanceInfo data) { return data.getApp(); } }
/** * 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 { InstanceInfo updatedInfo = cached.applyDelta(delta); idVsInstance.put(updatedInfo.getId(), updatedInfo); notification = new ModifyNotification(updatedInfo, Collections.singleton(delta)); } return notification; }
for (InstanceInfo instanceInfo : latestV1Instances) { totalCount.incrementAndGet(); newSnapshot.put(instanceInfo.getId(), instanceInfo); if (currentSnapshot.containsKey(instanceInfo.getId())) { InstanceInfo older = currentSnapshot.get(instanceInfo.getId()); if (!older.equals(instanceInfo)) { registry.register(instanceInfo, selfSource); updateCount.incrementAndGet();
pauseableSubject.onNext(addNotification); } else { Set<Delta<?>> delta = newSnapshot.getData().diffOlder(currSnapshot.getData()); if (!delta.isEmpty()) { ChangeNotification<InstanceInfo> modifyNotification pauseableSubject.onNext(modifyNotification); } else { logger.debug("No-change update for {}#{}", currSnapshot.getSource(), currSnapshot.getData().getId());
private static Set<Delta<?>> diff(InstanceInfo oldInstanceInfo, InstanceInfo newInstanceInfo) { if (oldInstanceInfo == null || newInstanceInfo == null) { return null; } if (!oldInstanceInfo.getId().equals(newInstanceInfo.getId())) { return null; } Set<Delta<?>> deltas = new HashSet<Delta<?>>(); for (InstanceInfoField.Name fieldName : InstanceInfoField.Name.values()) { InstanceInfoField<Object> field = InstanceInfoField.forName(fieldName); Object oldValue = field.getValue(oldInstanceInfo); Object newValue = field.getValue(newInstanceInfo); if (!equalsNullable(oldValue, newValue)) { // there is a difference Delta<?> delta = new Delta.Builder() .withId(newInstanceInfo.getId()) .withDelta(field, newValue) .build(); deltas.add(delta); } } return deltas; }
@Override public String getValue(InstanceInfo instanceInfo) { return instanceInfo.getVipAddress(); } });
@Override public InstanceInfo.Status getValue(InstanceInfo instanceInfo) { return instanceInfo.getStatus(); } });
public static Iterator<ServiceEndpoint> iteratorFrom(final InstanceInfo instanceInfo) { final List<NetworkAddress> addresses = instanceInfo.getDataCenterInfo().getAddresses(); final HashSet<ServicePort> ports = instanceInfo.getPorts(); if (ports == null || ports.isEmpty() || addresses == null || addresses.isEmpty()) { return Collections.emptyIterator();
@Override public DataCenterInfo getValue(InstanceInfo instanceInfo) { return instanceInfo.getDataCenterInfo(); } });
@Override public Map<String,String> getValue(InstanceInfo instanceInfo) { return instanceInfo.getMetaData(); } });
@Override public String getValue(InstanceInfo instanceInfo) { return instanceInfo.getApp(); } });
.withId(lastInstanceInfo.getId()) .withDelta(field, value) .build(); lastInstanceInfo = lastInstanceInfo.applyDelta(delta);
snapshot = newSnapshot; Set<Delta<?>> delta = newSnapshot.getData().diffOlder(currSnapshot.getData()); if (!delta.isEmpty()) { ChangeNotification<InstanceInfo> modifyNotification pauseableSubject.onNext(modifyNotification); } else { logger.debug("No-change update for {}#{}", currSnapshot.getSource(), currSnapshot.getData().getId());
@Override protected String getValue(InstanceInfo data) { return data.getVipAddress(); } }