Search in sources :

Example 1 with EventType

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);
        }
    }
}
Also used : EventType(io.kubernetes.client.informer.EventType) V1ObjectMeta(io.kubernetes.client.openapi.models.V1ObjectMeta) WatchExpiredException(io.kubernetes.client.informer.exception.WatchExpiredException)

Aggregations

EventType (io.kubernetes.client.informer.EventType)1 WatchExpiredException (io.kubernetes.client.informer.exception.WatchExpiredException)1 V1ObjectMeta (io.kubernetes.client.openapi.models.V1ObjectMeta)1