1313 * See the License for the specific language governing permissions and
1414 * limitations under the License.
1515 */
16- package io .flamingock .internal .core .operation . execute ;
16+ package io .flamingock .internal .core .operation ;
1717
1818import io .flamingock .internal .common .core .error .FlamingockException ;
19+ import io .flamingock .internal .common .core .error .PendingChangesException ;
1920import io .flamingock .internal .common .core .response .data .ErrorInfo ;
2021import io .flamingock .internal .common .core .response .data .ExecuteResponseData ;
2122import io .flamingock .internal .common .core .response .data .StageResult ;
2627import io .flamingock .internal .core .event .model .impl .StageCompletedEvent ;
2728import io .flamingock .internal .core .event .model .impl .StageFailedEvent ;
2829import io .flamingock .internal .core .event .model .impl .StageStartedEvent ;
29- import io .flamingock .internal .core .operation .Operation ;
30- import io .flamingock .internal .core .operation .OperationException ;
30+ import io .flamingock .internal .core .operation .execute . ExecuteArgs ;
31+ import io .flamingock .internal .core .operation .execute . ExecuteResult ;
3132import io .flamingock .internal .core .operation .result .ExecutionResultBuilder ;
3233import io .flamingock .internal .core .pipeline .execution .ExecutableStage ;
3334import io .flamingock .internal .core .pipeline .execution .ExecutionContext ;
4849import java .util .List ;
4950
5051/**
51- * Executes the pipeline and returns structured result data.
52+ * Common execution flow for Apply and Validate operations
5253 */
53- public class ExecuteOperation implements Operation <ExecuteArgs , ExecuteResult > {
54+ public abstract class AbstractPipelineTraverseOperation implements Operation <ExecuteArgs , ExecuteResult > {
5455
5556 private static final Logger logger = FlamingockLoggerFactory .getLogger ("PipelineRunner" );
5657
@@ -66,15 +67,15 @@ public class ExecuteOperation implements Operation<ExecuteArgs, ExecuteResult> {
6667
6768 private final OrphanExecutionContext orphanExecutionContext ;
6869
69- private final Runnable finalizer ;
70+ protected final Runnable finalizer ;
7071
71- public ExecuteOperation (RunnerId runnerId ,
72- ExecutionPlanner executionPlanner ,
73- StageExecutor stageExecutor ,
74- OrphanExecutionContext orphanExecutionContext ,
75- EventPublisher eventPublisher ,
76- boolean throwExceptionIfCannotObtainLock ,
77- Runnable finalizer ) {
72+ public AbstractPipelineTraverseOperation (RunnerId runnerId ,
73+ ExecutionPlanner executionPlanner ,
74+ StageExecutor stageExecutor ,
75+ OrphanExecutionContext orphanExecutionContext ,
76+ EventPublisher eventPublisher ,
77+ boolean throwExceptionIfCannotObtainLock ,
78+ Runnable finalizer ) {
7879 this .runnerId = runnerId ;
7980 this .executionPlanner = executionPlanner ;
8081 this .stageExecutor = stageExecutor ;
@@ -84,19 +85,19 @@ public ExecuteOperation(RunnerId runnerId,
8485 this .finalizer = finalizer ;
8586 }
8687
88+ protected abstract boolean validateOnlyMode ();
8789
8890 @ Override
8991 public ExecuteResult execute (ExecuteArgs args ) {
9092 ExecuteResponseData result ;
9193 try {
9294 result = this .execute (args .getPipeline ());
9395 } catch (OperationException operationException ) {
94- result = operationException .getResult ();
9596 throw operationException ;
9697 } catch (Throwable throwable ) {
9798 throw processAndGetFlamingockException (throwable , null );
9899 } finally {
99- finalizer .run ();
100+ this . finalizer .run ();
100101 }
101102 return new ExecuteResult (result );
102103 }
@@ -130,6 +131,9 @@ private ExecuteResponseData execute(LoadedPipeline pipeline) throws FlamingockEx
130131 execution .validate ();
131132
132133 if (execution .isExecutionRequired ()) {
134+ if (validateOnlyMode ()) {
135+ throw new PendingChangesException ();
136+ }
133137 execution .applyOnEach ((executionId , lock , executableStage ) -> {
134138 StageResult stageResult = runStage (executionId , lock , executableStage );
135139 resultBuilder .addStage (stageResult );
@@ -208,5 +212,4 @@ private FlamingockException processAndGetFlamingockException(Throwable exception
208212 eventPublisher .publish (new PipelineFailedEvent (flamingockException ));
209213 return flamingockException ;
210214 }
211-
212215}
0 commit comments