4343import eu .openanalytics .containerproxy .spec .expression .SpecExpressionContext ;
4444import eu .openanalytics .containerproxy .spec .expression .SpecExpressionResolver ;
4545import eu .openanalytics .containerproxy .util .ProxyMappingManager ;
46+ import org .slf4j .Logger ;
47+ import org .slf4j .LoggerFactory ;
4648import org .springframework .context .ApplicationEventPublisher ;
4749import org .springframework .core .env .Environment ;
4850import org .springframework .data .util .Pair ;
7981public class ProxyService {
8082
8183 public static final String PROPERTY_STOP_PROXIES_ON_SHUTDOWN = "proxy.stop-proxies-on-shutdown" ;
82- private final StructuredLogger log = StructuredLogger .create (getClass ());
84+ private final Logger log = LoggerFactory .getLogger (getClass ());
85+ private final StructuredLogger slog = new StructuredLogger (log );
8386 private final Set <String > actionsInProgress = new HashSet <>();
8487 @ Inject
8588 protected IProxyTestStrategy testStrategy ;
@@ -120,7 +123,7 @@ public void shutdown() {
120123 try {
121124 proxyDispatcherService .getDispatcher (proxy .getSpecId ()).stopProxy (proxy );
122125 } catch (Exception exception ) {
123- exception . printStackTrace ( );
126+ log . error ( "Error during shutdown" , exception );
124127 }
125128 }
126129 }
@@ -290,7 +293,7 @@ public Command startProxy(Authentication user, ProxySpec spec, List<RuntimeValue
290293 Proxy result = startOrResumeProxy (user , currentProxy , proxyStartupLog );
291294
292295 if (result != null ) {
293- log .info (result , "Proxy activated" );
296+ slog .info (result , "Proxy activated" );
294297 applicationEventPublisher .publishEvent (new ProxyStartEvent (result , proxyStartupLog .succeeded ()));
295298
296299 // final check to see if the app was stopped
@@ -325,7 +328,7 @@ public Command stopProxy(Authentication user, Proxy proxy, boolean ignoreAccessC
325328 }
326329
327330 if (user != null && !ignoreAccessControl ) {
328- log .info (proxy , "Proxy being stopped by user " + user .getName ());
331+ slog .info (proxy , "Proxy being stopped by user " + user .getName ());
329332 }
330333
331334 Proxy stoppingProxy = proxy .withStatus (ProxyStatus .Stopping );
@@ -338,14 +341,14 @@ public Command stopProxy(Authentication user, Proxy proxy, boolean ignoreAccessC
338341 try {
339342 proxyDispatcherService .getDispatcher (proxy .getSpecId ()).stopProxy (stoppedProxy , proxyStopReason );
340343 } catch (Throwable t ) {
341- log .error (stoppedProxy , t , "Failed to stop proxy" );
344+ slog .error (stoppedProxy , t , "Failed to stop proxy" );
342345 }
343346 try {
344347 proxyStore .removeProxy (stoppedProxy );
345348 } catch (Throwable t ) {
346- log .error (stoppedProxy , t , "Failed to remove proxy" );
349+ slog .error (stoppedProxy , t , "Failed to remove proxy" );
347350 }
348- log .info (stoppedProxy , "Proxy released" );
351+ slog .info (stoppedProxy , "Proxy released" );
349352
350353 applicationEventPublisher .publishEvent (new ProxyStopEvent (stoppedProxy , proxyStopReason ));
351354 });
@@ -358,12 +361,12 @@ public Command pauseProxy(Authentication user, Proxy proxy, boolean ignoreAccess
358361 }
359362
360363 if (!proxyDispatcherService .getDispatcher (proxy .getSpecId ()).supportsPause ()) {
361- log .warn (proxy , "Trying to pause a proxy when the backend does not support pausing apps" );
364+ slog .warn (proxy , "Trying to pause a proxy when the backend does not support pausing apps" );
362365 throw new IllegalArgumentException ("Trying to pause a proxy when the backend does not support pausing apps" );
363366 }
364367
365368 if (user != null && !ignoreAccessControl ) {
366- log .info (proxy , "Proxy being paused by user " + user .getName ());
369+ slog .info (proxy , "Proxy being paused by user " + user .getName ());
367370 }
368371
369372 Proxy stoppingProxy = proxy .withStatus (ProxyStatus .Pausing );
@@ -377,10 +380,10 @@ public Command pauseProxy(Authentication user, Proxy proxy, boolean ignoreAccess
377380 proxyDispatcherService .getDispatcher (pausingProxy .getSpecId ()).pauseProxy (pausingProxy );
378381 Proxy pausedProxy = pausingProxy .withStatus (ProxyStatus .Paused );
379382 proxyStore .updateProxy (pausedProxy );
380- log .info (pausedProxy , "Proxy paused" );
383+ slog .info (pausedProxy , "Proxy paused" );
381384 applicationEventPublisher .publishEvent (new ProxyPauseEvent (pausedProxy ));
382385 } catch (Throwable t ) {
383- log .error (pausingProxy , t , "Failed to pause proxy " );
386+ slog .error (pausingProxy , t , "Failed to pause proxy " );
384387 }
385388 });
386389 }
@@ -392,7 +395,7 @@ public Command resumeProxy(Authentication user, Proxy proxy, Map<String, String>
392395 }
393396
394397 if (!proxyDispatcherService .getDispatcher (proxy .getSpecId ()).supportsPause ()) {
395- log .warn (proxy , "Trying to resume a proxy when the backend does not support pausing apps" );
398+ slog .warn (proxy , "Trying to resume a proxy when the backend does not support pausing apps" );
396399 throw new IllegalArgumentException ("Trying to resume a proxy when the backend does not support pausing apps" );
397400 }
398401
@@ -405,7 +408,7 @@ public Command resumeProxy(Authentication user, Proxy proxy, Map<String, String>
405408 Proxy result = startOrResumeProxy (user , parameterizedProxy , null );
406409
407410 if (result != null ) {
408- log .info (result , "Proxy resumed" );
411+ slog .info (result , "Proxy resumed" );
409412 applicationEventPublisher .publishEvent (new ProxyResumeEvent (result ));
410413
411414 // final check to see if the app was stopped
@@ -450,7 +453,7 @@ private Pair<ProxySpec, Proxy> prepareProxyForStart(Authentication user, Proxy p
450453
451454 return Pair .of (spec , proxy );
452455 } catch (Throwable t ) {
453- log .warn (proxy , t , "Failed to prepare proxy for start" );
456+ slog .warn (proxy , t , "Failed to prepare proxy for start" );
454457 throw new ProxyFailedToStartException ("Container failed to start" , t , proxy );
455458 }
456459 }
@@ -463,28 +466,28 @@ private Proxy startOrResumeProxy(Authentication user, Proxy proxy, ProxyStartupL
463466 spec = r .getFirst ();
464467 proxy = r .getSecond ();
465468 if (proxy .getStatus () == ProxyStatus .New ) {
466- log .info (proxy , "Starting proxy" );
469+ slog .info (proxy , "Starting proxy" );
467470 proxy = proxyDispatcherService .getDispatcher (spec .getId ()).startProxy (user , proxy , spec , proxyStartupLog );
468471 } else if (proxy .getStatus () == ProxyStatus .Resuming ) {
469- log .info (proxy , "Resuming proxy" );
472+ slog .info (proxy , "Resuming proxy" );
470473 proxy = proxyDispatcherService .getDispatcher (spec .getId ()).resumeProxy (user , proxy , spec );
471474 } else {
472475 throw new ContainerProxyException ("Cannot start or resume proxy because status is invalid" );
473476 }
474477 } catch (ProxyFailedToStartException t ) {
475- log .warn (t .getProxy (), t , "Proxy failed to start" );
478+ slog .warn (t .getProxy (), t , "Proxy failed to start" );
476479 try {
477480 proxyDispatcherService .getDispatcher (spec .getId ()).stopProxy (t .getProxy ());
478481 } catch (Throwable t2 ) {
479482 // log error, but ignore it otherwise
480483 // most important is that we remove the proxy from memory
481- log .warn (t .getProxy (), t , "Error while stopping failed proxy" );
484+ slog .warn (t .getProxy (), t , "Error while stopping failed proxy" );
482485 }
483486 proxyStore .removeProxy (t .getProxy ());
484487 applicationEventPublisher .publishEvent (new ProxyStartFailedEvent (t .getProxy ()));
485488 throw new ContainerProxyException ("Container failed to start" , t );
486489 } catch (Throwable t ) {
487- log .warn (proxy , t , "Proxy failed to start" );
490+ slog .warn (proxy , t , "Proxy failed to start" );
488491 proxyStore .removeProxy (proxy );
489492 applicationEventPublisher .publishEvent (new ProxyStartFailedEvent (proxy ));
490493 throw new ContainerProxyException ("Container failed to start" , t );
@@ -500,11 +503,11 @@ private Proxy startOrResumeProxy(Authentication user, Proxy proxy, ProxyStartupL
500503 } catch (Throwable t ) {
501504 // log error, but ignore it otherwise
502505 // most important is that we remove the proxy from memory
503- log .warn (proxy , t , "Error while stopping failed proxy" );
506+ slog .warn (proxy , t , "Error while stopping failed proxy" );
504507 }
505508 proxyStore .removeProxy (proxy );
506509 applicationEventPublisher .publishEvent (new ProxyStartFailedEvent (proxy ));
507- log .warn (proxy , "Container did not respond in time" );
510+ slog .warn (proxy , "Container did not respond in time" );
508511 throw new ContainerProxyException ("Container did not respond in time" );
509512 }
510513
@@ -534,7 +537,7 @@ private boolean cleanupIfPendingAppWasStopped(Proxy startingProxy) {
534537 if (proxy == null || proxy .getStatus ().equals (ProxyStatus .Stopped )
535538 || proxy .getStatus ().equals (ProxyStatus .Stopping )) {
536539 proxyDispatcherService .getDispatcher (startingProxy .getSpecId ()).stopProxy (startingProxy );
537- log .info (startingProxy , "Pending proxy cleaned up" );
540+ slog .info (startingProxy , "Pending proxy cleaned up" );
538541 return true ;
539542 }
540543 return false ;
@@ -551,7 +554,7 @@ public void addExistingProxy(Proxy proxy) {
551554
552555 setupProxy (proxy );
553556
554- log .info (proxy , "Existing Proxy re-activated" );
557+ slog .info (proxy , "Existing Proxy re-activated" );
555558 }
556559
557560 /**
0 commit comments