gaborgsomogyi commented on code in PR #363:
URL:
https://github.com/apache/flink-kubernetes-operator/pull/363#discussion_r963607902
##########
flink-kubernetes-operator/src/main/java/org/apache/flink/kubernetes/operator/utils/EventRecorder.java:
##########
@@ -69,34 +70,35 @@ public static EventRecorder create(
KubernetesClient client, Collection<FlinkResourceListener>
listeners) {
BiConsumer<AbstractFlinkResource<?, ?>, Event> biConsumer =
- (resource, event) ->
- listeners.forEach(
- listener -> {
- var ctx =
- new
FlinkResourceListener.ResourceEventContext() {
- @Override
- public Event getEvent() {
- return event;
- }
-
- @Override
- public
AbstractFlinkResource<?, ?>
- getFlinkResource() {
- return resource;
- }
-
- @Override
- public KubernetesClient
getKubernetesClient() {
- return client;
- }
- };
-
- if (resource instanceof FlinkDeployment) {
- listener.onDeploymentEvent(ctx);
- } else {
- listener.onSessionJobEvent(ctx);
- }
- });
+ (resource, event) -> {
+ var ctx =
+ new FlinkResourceListener.ResourceEventContext() {
+ @Override
+ public Event getEvent() {
+ return event;
+ }
+
+ @Override
+ public AbstractFlinkResource<?, ?>
getFlinkResource() {
+ return resource;
+ }
+
+ @Override
+ public KubernetesClient getKubernetesClient() {
+ return client;
+ }
+ };
+ listeners.forEach(
+ listener -> {
+ if (resource instanceof FlinkDeployment) {
Review Comment:
Unrelated: instead of this `instanceof` I would personally add event
specific function implementations.
##########
flink-kubernetes-operator/src/main/java/org/apache/flink/kubernetes/operator/utils/StatusRecorder.java:
##########
@@ -196,6 +197,7 @@ public Instant getTimestamp() {
listener.onSessionJobStatusUpdate(ctx);
}
});
+ ListenerUtils.logContext(ctx);
Review Comment:
Not sure why we need to add this to `ListenerUtils`. If @gyfora pointed this
out in the jira then +1 to inline it here :)
##########
flink-kubernetes-operator/src/main/java/org/apache/flink/kubernetes/operator/listener/ListenerUtils.java:
##########
@@ -134,4 +138,32 @@ private static Set<Tuple2<String, String>>
findEnabledListeners(Configuration co
}
return result;
}
+
+ public static <R extends AbstractFlinkResource<?, S>, S extends
CommonStatus<?>>
+ void logContext(FlinkResourceListener.StatusUpdateContext<R, S>
ctx) {
+ LOG.info(format(ctx.getNewStatus()));
+ }
+
+ public static <R extends AbstractFlinkResource<?, ?>> void logContext(
+ FlinkResourceListener.ResourceEventContext<R> ctx) {
+ LOG.info(format(ctx.getEvent()));
+ }
+
+ private static String format(@NonNull CommonStatus<?> status) {
+ return String.format(
+ ">>> Status | %-7s | %-15s | %s ",
+ StringUtils.isEmpty(status.getError()) ? "Info" : "Error",
+ status.getLifecycleState(),
+ StringUtils.isEmpty(status.getError())
+ ? status.getLifecycleState().getDescription()
+ : status.getError());
+ }
+
+ private static String format(@NonNull Event event) {
+ return String.format(
+ ">>> Event | %-7s | %-15s | %s",
+ event.getType().equals("Normal") ? "Info" : event.getType(),
Review Comment:
Nit: printing a custom String w/ fixed length may end-up in truncate.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]