use of io.kubernetes.client.informer.EventType in project java by kubernetes-client.
the class ReflectorRunnable method watchHandler.
private void watchHandler(Watchable<ApiType> watch) {
while (watch.hasNext()) {
io.kubernetes.client.util.Watch.Response<ApiType> item = watch.next();
Optional<EventType> eventType = EventType.findByType(item.type);
if (!eventType.isPresent()) {
log.error("unrecognized event {}", item);
continue;
}
if (eventType.get() == EventType.ERROR) {
if (item.status != null && item.status.getCode() == HttpURLConnection.HTTP_GONE) {
log.info("ResourceVersion {} and Watch connection expired: {} , will retry w/o resourceVersion next time", getRelistResourceVersion(), item.status.getMessage());
isLastSyncResourceVersionUnavailable = true;
throw new WatchExpiredException();
} else {
String errorMessage = String.format("got ERROR event and its status: %s", item.status.toString());
log.error(errorMessage);
throw new RuntimeException(errorMessage);
}
}
ApiType obj = item.object;
V1ObjectMeta meta = obj.getMetadata();
String newResourceVersion = meta.getResourceVersion();
switch(eventType.get()) {
case ADDED:
store.add(obj);
break;
case MODIFIED:
store.update(obj);
break;
case DELETED:
store.delete(obj);
break;
case BOOKMARK:
break;
}
lastSyncResourceVersion = newResourceVersion;
if (log.isDebugEnabled()) {
log.debug("{}#Receiving resourceVersion {}", apiTypeClass, lastSyncResourceVersion);
}
}
}
Aggregations