1515import java .util .function .Function ;
1616import java .util .stream .Collectors ;
1717
18+ import oracle .kubernetes .operator .logging .LoggingFacade ;
19+ import oracle .kubernetes .operator .logging .LoggingFactory ;
20+ import oracle .kubernetes .operator .logging .MessageKeys ;
21+
1822/**
1923 * ContainerResolver based on {@link ThreadLocal}.
2024 * <p>
3438 * </pre>
3539 */
3640public class ThreadLocalContainerResolver extends ContainerResolver {
41+ private static final LoggingFacade LOGGER = LoggingFactory .getLogger ("Operator" , "Operator" );
42+
3743 private ThreadLocal <Container > containerThreadLocal = new ThreadLocal <Container >() {
3844 @ Override
3945 protected Container initialValue () {
@@ -78,6 +84,15 @@ ScheduledExecutorService wrapExecutor(final Container container, final Scheduled
7884 Container old = enterContainer (container );
7985 try {
8086 x .run ();
87+ } catch (RuntimeException runtime ) {
88+ LOGGER .severe (MessageKeys .EXCEPTION , runtime );
89+ throw runtime ;
90+ } catch (Error error ) {
91+ LOGGER .severe (MessageKeys .EXCEPTION , error );
92+ throw error ;
93+ } catch (Throwable throwable ) {
94+ LOGGER .severe (MessageKeys .EXCEPTION , throwable );
95+ throw new RuntimeException (throwable );
8196 } finally {
8297 exitContainer (old );
8398 }
@@ -89,6 +104,15 @@ ScheduledExecutorService wrapExecutor(final Container container, final Scheduled
89104 Container old = enterContainer (container );
90105 try {
91106 return x .call ();
107+ } catch (RuntimeException runtime ) {
108+ LOGGER .severe (MessageKeys .EXCEPTION , runtime );
109+ throw runtime ;
110+ } catch (Error error ) {
111+ LOGGER .severe (MessageKeys .EXCEPTION , error );
112+ throw error ;
113+ } catch (Throwable throwable ) {
114+ LOGGER .severe (MessageKeys .EXCEPTION , throwable );
115+ throw new RuntimeException (throwable );
92116 } finally {
93117 exitContainer (old );
94118 }
0 commit comments