1010import io .micrometer .core .instrument .MeterRegistry ;
1111import io .micrometer .core .instrument .Timer ;
1212import java .util .List ;
13- import java .util .concurrent .atomic .AtomicReference ;
1413import lombok .extern .slf4j .Slf4j ;
1514import org .apache .commons .lang3 .StringUtils ;
1615import org .pf4j .PluginManager ;
@@ -71,8 +70,8 @@ void process(BuildRequest request)
7170 try
7271 {
7372 log .info ("Starting processing for request: serviceName={}, commitId={}" , request .getServiceName (), request .getCommitId ());
74- final AtomicReference < DataSet > dataSet = new AtomicReference <>( BuildMapper .makeDataSet (request ) );
75- log .debug ("Initial DataSet created from request: {}" , dataSet . get () );
73+ DataSet dataSet = BuildMapper .makeDataSet (request );
74+ log .debug ("Initial DataSet created from request: {}" , dataSet );
7675 String plugin = request .getPlugin ();
7776
7877 if (StringUtils .isNotBlank (plugin ))
@@ -111,7 +110,7 @@ void process(BuildRequest request)
111110
112111
113112 private void runDependencies (
114- final AtomicReference < DataSet > dataSet , final String plugin , final List <String > defaultPipeline )
113+ DataSet dataSet , final String plugin , final List <String > defaultPipeline )
115114 {
116115 for (final String defaultPipelinePlugin : defaultPipeline )
117116 {
@@ -127,31 +126,33 @@ private void runDependencies(
127126 }
128127
129128
130- void runPlugin (String plugin , AtomicReference < DataSet > dataSet )
129+ void runPlugin (String plugin , DataSet dataSet )
131130 {
132- pluginManager .getExtensions (SauronExtension .class , plugin ).forEach (pluginExtension -> {
131+ for (SauronExtension pluginExtension : pluginManager .getExtensions (SauronExtension .class , plugin ))
132+ {
133133 try
134134 {
135135 MDC .put ("sauron.pluginId" , plugin );
136- MDC .put ("sauron.serviceName" , dataSet .get ().getServiceName ());
137- MDC .put ("sauron.commitId" , dataSet .get ().getCommitId ());
138- MDC .put ("sauron.buildId" , dataSet .get ().getBuildId ());
139- log .debug ("Applying pluginId: {}. Processing service {} - {}. DataSet BEFORE plugin execution: {}" , plugin , dataSet .get ().getServiceName (), dataSet .get ().getCommitId (), dataSet .get ());
140-
141- DataSet newDataSet = getTimerBuilder ("sauron.plugin.execution.time" )
136+ MDC .put ("sauron.serviceName" , dataSet .getServiceName ());
137+ MDC .put ("sauron.commitId" , dataSet .getCommitId ());
138+ MDC .put ("sauron.buildId" , dataSet .getBuildId ());
139+ log .debug ("Applying pluginId: {}. Processing service {} - {}. DataSet BEFORE plugin execution: {}" , plugin , dataSet .getServiceName (), dataSet .getCommitId (),
140+ dataSet );
141+
142+ final DataSet dataSetForLambda = dataSet ;
143+ dataSet = getTimerBuilder ("sauron.plugin.execution.time" )
142144 .tag ("plugin" , plugin )
143- .tag ("service" , dataSet .get ().getServiceName ())
144- .tag ("commit" , dataSet .get ().getCommitId ())
145- .register (meterRegistry ).record (() -> pluginExtension .apply (pluginsProperties , dataSet .get ()));
146- dataSet .set (newDataSet );
145+ .tag ("service" , dataSet .getServiceName ())
146+ .tag ("commit" , dataSet .getCommitId ())
147+ .register (meterRegistry ).record (() -> pluginExtension .apply (pluginsProperties , dataSetForLambda ));
147148
148149 meterRegistry .counter ("sauron.plugin.executions.total" , "plugin" , plugin , "result" , "success" ).increment ();
149- log .debug ("PluginId: {} applied. Processing service {} - {}. DataSet AFTER plugin execution: {}" , plugin , dataSet .get (). getServiceName (), dataSet .get (). getCommitId (), dataSet . get () );
150+ log .debug ("PluginId: {} applied. Processing service {} - {}. DataSet AFTER plugin execution: {}" , plugin , dataSet .getServiceName (), dataSet .getCommitId (), dataSet );
150151 }
151152 catch (final Exception ex )
152153 {
153154 meterRegistry .counter ("sauron.plugin.executions.total" , "plugin" , plugin , "result" , "failure" ).increment ();
154- log .error ("Error in plugin '{}' for serviceName={}, commitId={}. DataSet at time of failure: {}" , plugin , dataSet .get (). getServiceName (), dataSet .get (). getCommitId (), dataSet . get () , ex );
155+ log .error ("Error in plugin '{}' for serviceName={}, commitId={}. DataSet at time of failure: {}" , plugin , dataSet .getServiceName (), dataSet .getCommitId (), dataSet , ex );
155156 }
156157 finally
157158 {
@@ -160,7 +161,7 @@ void runPlugin(String plugin, AtomicReference<DataSet> dataSet)
160161 MDC .remove ("sauron.commitId" );
161162 MDC .remove ("sauron.buildId" );
162163 }
163- });
164+ }
164165 }
165166
166167
0 commit comments