final long tempNewVersion = currentVersion + 1; final InstanceInfo tempNewInfo = new InstanceInfo.Builder() .withInstanceInfo(newInfo).withVersion(tempNewVersion).build();
@Override public Observable<Void> register(final InstanceInfo instanceInfo) { logger.debug("Replicated registry entry: {}", instanceInfo); 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); } if (instanceInfoById.containsKey(instanceInfo.getId())) { logger.info("Overwriting existing registration entry for instance {}", instanceInfo.getId()); } InstanceInfo tempNewInfo = new InstanceInfo.Builder() .withInstanceInfo(instanceInfo).withVersion(currentVersion++).build(); return registry.register(tempNewInfo, replicationSource) .ignoreElements() .cast(Void.class) .doOnCompleted(new Action0() { @Override public void call() { instanceInfoById.put(instanceInfo.getId(), instanceInfo); } }); }
@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); } }); }
.withInstanceInfo(instanceInfo).withVersion(tempNewVersion).build();
@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 InstanceInfo fromV1(com.netflix.appinfo.InstanceInfo v1Info) { InstanceInfo.Builder builder = new InstanceInfo.Builder() .withId(v1Info.getAppName() + "_" + v1Info.getId()) // instanceId is not unique for v1Data .withAppGroup(v1Info.getAppGroupName()) .withApp(v1Info.getAppName()) .withAsg(v1Info.getASGName()) .withVipAddress(v1Info.getVIPAddress()) .withSecureVipAddress(v1Info.getSecureVipAddress()) .withPorts(toSet(new ServicePort(v1Info.getPort(), false), new ServicePort(v1Info.getSecurePort(), true))) .withStatus(fromV1(v1Info.getStatus())) .withHomePageUrl(v1Info.getHomePageUrl()) .withStatusPageUrl(v1Info.getStatusPageUrl()) .withHealthCheckUrls(new HashSet<>(v1Info.getHealthCheckUrls())) .withMetaData(v1Info.getMetadata()) .withDataCenterInfo(fromV1(v1Info.getDataCenterInfo())); return builder.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); }
public InstanceInfo build() { return builder().build(); }
private static InstanceInfo randomize(String id, InstanceInfo.Builder builder) { return builder.withId(id).build(); }
protected InstanceInfo buildClientInfo(String name) { return new Builder() .withId("id#" + name) .withApp("app#" + name) .withAppGroup("appGroup#" + name) .withVipAddress("vip#" + name) .withStatus(Status.UP) .withPorts(SampleServicePort.httpPorts()) .withDataCenterInfo(SampleAwsDataCenterInfo.UsEast1a.build()) .build(); } }