List<LbaasServerData> add = Lists.newArrayList();
Map<Long, LbaasServerData> remove = Maps.newHashMap(dbMap);
for (LbaasServerData mapping : requests) {
LbaasServerData db = rawToDbMap.get(mapping);
if (db == null) {
add.add(mapping);
} else {
remove.remove(db.getId());
}
}
Set<LbaasServerData> dirtyServers = Sets.newHashSet();
for (LbaasServerData a : add) {
log.info("Add LB: {}", a);
LbaasServerData.Builder b = LbaasServerData.newBuilder(a);
LbaasServerData created = collection.create(b);
dirtyServers.add(created);
}
for (LbaasServerData r : remove.values()) {
log.info("Remove LB: {}", r);
LbaasServerData deleted = collection.delete(r.getId());
if (deleted == null) {
throw new IllegalStateException("Did not find server during delete");
}