use of com.netflix.titus.runtime.connector.kubernetes.fabric8io.model.PodUpdatedEvent in project titus-control-plane by Netflix.
the class DefaultFabric8IOConnector method kubeInformerEvents.
private Flux<PodEvent> kubeInformerEvents() {
return Flux.create(sink -> {
ResourceEventHandler<Pod> handler = new ResourceEventHandler<Pod>() {
@Override
public void onAdd(Pod pod) {
Stopwatch stopwatch = Stopwatch.createStarted();
try {
String taskId = pod.getMetadata().getName();
Pod old = pods.get(taskId);
pods = pods.plus(taskId, pod);
PodEvent podEvent;
if (old != null) {
podEvent = PodEvent.onUpdate(old, pod, findNode(pod));
// metrics.onUpdate(pod);
} else {
podEvent = PodEvent.onAdd(pod);
// metrics.onAdd(pod);
}
sink.next(podEvent);
logger.info("Pod Added: pod={}, sequenceNumber={}", formatPodEssentials(pod), podEvent.getSequenceNumber());
logger.debug("complete pod data: {}", pod);
} finally {
logger.info("Pod informer onAdd: pod={}, elapsedMs={}", pod.getMetadata().getName(), stopwatch.elapsed().toMillis());
}
}
@Override
public void onUpdate(Pod oldPod, Pod newPod) {
Stopwatch stopwatch = Stopwatch.createStarted();
try {
String taskId = newPod.getMetadata().getName();
pods = pods.plus(taskId, newPod);
PodUpdatedEvent podEvent = PodEvent.onUpdate(oldPod, newPod, findNode(newPod));
sink.next(podEvent);
logger.info("Pod Updated: old={}, new={}, sequenceNumber={}", formatPodEssentials(oldPod), formatPodEssentials(newPod), podEvent.getSequenceNumber());
logger.debug("Complete pod data: old={}, new={}", oldPod, newPod);
} finally {
logger.info("Pod informer onUpdate: pod={}, elapsedMs={}", newPod.getMetadata().getName(), stopwatch.elapsed().toMillis());
}
}
@Override
public void onDelete(Pod pod, boolean deletedFinalStateUnknown) {
Stopwatch stopwatch = Stopwatch.createStarted();
try {
String taskId = pod.getMetadata().getName();
pods = pods.minus(taskId);
PodDeletedEvent podEvent = PodEvent.onDelete(pod, deletedFinalStateUnknown, findNode(pod));
sink.next(podEvent);
logger.info("Pod Deleted: {}, deletedFinalStateUnknown={}, sequenceNumber={}", formatPodEssentials(pod), deletedFinalStateUnknown, podEvent.getSequenceNumber());
logger.debug("complete pod data: {}", pod);
} finally {
logger.info("Pod informer onDelete: pod={}, elapsedMs={}", pod.getMetadata().getName(), stopwatch.elapsed().toMillis());
}
}
};
this.getPodInformer().addEventHandler(handler);
// A listener cannot be removed from shared informer.
// sink.onCancel(() -> ???);
});
}
Aggregations