Skip to content

Commit 90f6b8a

Browse files
authored
refactor: improved logging/report mechanism for pipeline (#914)
- improved reporting logging output - enhanced reporting via listeners, so they can be disabled - improved listener model, adding capability for custom reporting
1 parent 8c2290e commit 90f6b8a

24 files changed

Lines changed: 1148 additions & 130 deletions

File tree

cloud/flamingock-cloud/src/main/java/io/flamingock/cloud/planner/CloudExecutionPlanner.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import io.flamingock.internal.util.ThreadSleeper;
2323
import io.flamingock.internal.util.TimeService;
2424
import io.flamingock.internal.common.core.error.FlamingockException;
25+
import io.flamingock.internal.common.core.response.data.PlannerVerdict;
2526
import io.flamingock.cloud.api.request.ExecutionPlanRequest;
2627
import io.flamingock.cloud.api.response.ExecutionPlanResponse;
2728
import io.flamingock.internal.common.core.targets.TargetSystemAuditMarkType;
@@ -35,6 +36,7 @@
3536
import io.flamingock.internal.core.external.store.lock.LockException;
3637
import io.flamingock.internal.core.pipeline.loaded.stage.AbstractLoadedStage;
3738
import io.flamingock.internal.core.pipeline.run.PipelineRun;
39+
import io.flamingock.internal.core.pipeline.run.StageRun;
3840
import io.flamingock.internal.util.log.FlamingockLoggerFactory;
3941
import org.slf4j.Logger;
4042

@@ -102,6 +104,12 @@ public ExecutionPlan getNextExecution(PipelineRun pipelineRun) throws LockExcept
102104
}
103105

104106
if (response.isContinue()) {
107+
//TODO temporally. Remove this
108+
// Server's CONTINUE is authoritative: nothing left to apply for any stage in
109+
// the pipeline. Stamp the planner's UP_TO_DATE verdict on every stage the
110+
// planner hasn't already evaluated this run. No per-change records — the
111+
// server's CONTINUE doesn't carry per-change data and we don't synthesize.
112+
markRemainingStagesUpToDate(pipelineRun);
105113
return ExecutionPlan.CONTINUE();
106114

107115
} else if (response.isExecute()) {
@@ -200,6 +208,22 @@ private ExecutionPlan buildNextExecutionPlan(List<AbstractLoadedStage> loadedSta
200208
);
201209
}
202210

211+
/**
212+
* Stamps {@link PlannerVerdict#UP_TO_DATE} on every still-{@code NOT_EVALUATED} stage in the
213+
* pipeline. Called when the cloud server returns {@code CONTINUE} — its verdict is authoritative
214+
* for the whole pipeline. No per-change records are added; the server's CONTINUE payload doesn't
215+
* carry per-change data and we don't synthesize.
216+
*/
217+
private static void markRemainingStagesUpToDate(PipelineRun pipelineRun) {
218+
for (StageRun stageRun : pipelineRun.getStageRuns()) {
219+
if (stageRun.getResult().getPlannerVerdict() == PlannerVerdict.NOT_EVALUATED
220+
&& !stageRun.getState().isFailed()
221+
&& !stageRun.getState().isCompleted()) {
222+
pipelineRun.markStageVerdict(stageRun.getName(), PlannerVerdict.UP_TO_DATE);
223+
}
224+
}
225+
}
226+
203227
static class AuditMarkSnapshot {
204228
private final Collection<TargetSystemAuditMark> marks;
205229
private final Map<String, TargetSystemAuditMarker> markerByChangeId;

core/flamingock-core-commons/src/main/java/io/flamingock/internal/common/core/response/data/ChangeResult.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,10 @@ public boolean isFailed() {
101101
return status == ChangeStatus.FAILED;
102102
}
103103

104+
public boolean isRolledBack() {
105+
return status == ChangeStatus.ROLLED_BACK;
106+
}
107+
104108
public boolean isApplied() {
105109
return status == ChangeStatus.APPLIED;
106110
}
@@ -109,6 +113,10 @@ public boolean isAlreadyApplied() {
109113
return status == ChangeStatus.ALREADY_APPLIED;
110114
}
111115

116+
public boolean isNotReached() {
117+
return status == ChangeStatus.NOT_REACHED;
118+
}
119+
112120
public static Builder builder() {
113121
return new Builder();
114122
}

core/flamingock-core-commons/src/main/java/io/flamingock/internal/common/core/response/data/ChangeStatus.java

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,27 +20,33 @@
2020
*/
2121
public enum ChangeStatus {
2222
/**
23-
* Change was successfully applied.
23+
* Change was successfully applied during this run by the operation.
2424
*/
2525
APPLIED,
2626

2727
/**
28-
* Change was already applied in a previous execution.
28+
* Change was found already applied — either by the executor (SKIP action during this run)
29+
* or by the planner (audit-confirmed without invoking the executor).
2930
*/
3031
ALREADY_APPLIED,
3132

3233
/**
33-
* Change failed during execution.
34+
* Change failed during execution this run.
3435
*/
3536
FAILED,
3637

3738
/**
38-
* Change failed but was successfully rolled back.
39+
* Change failed during execution this run and was successfully rolled back (transactional
40+
* auto-rollback).
3941
*/
4042
ROLLED_BACK,
4143

4244
/**
43-
* Change was not reached due to a prior failure.
45+
* No positive information about this change in this run. Either the operation didn't process
46+
* it (executor stopped on a prior failure, the stage was unreached, etc.) or the planner
47+
* found no audit entry confirming it was applied. Default initial status assigned to every
48+
* loaded change at {@code PipelineRun} construction; writers transition records forward as
49+
* they learn facts.
4450
*/
4551
NOT_REACHED
4652
}

core/flamingock-core-commons/src/main/java/io/flamingock/internal/common/core/response/data/ExecuteResponseData.java

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,15 @@ public class ExecuteResponseData {
3434

3535
// Aggregate counts
3636
private int totalStages;
37+
private int upToDateStages;
38+
private int notReachedStages;
3739
private int completedStages;
3840
private int failedStages;
3941
private int totalChanges;
4042
private int appliedChanges;
4143
private int skippedChanges;
4244
private int failedChanges;
45+
private int notReachedChanges;
4346

4447
// Per-stage breakdown
4548
private List<StageResult> stages;
@@ -54,12 +57,15 @@ private ExecuteResponseData(Builder builder) {
5457
this.endTime = builder.endTime;
5558
this.totalDurationMs = builder.totalDurationMs;
5659
this.totalStages = builder.totalStages;
60+
this.upToDateStages = builder.upToDateStages;
61+
this.notReachedStages = builder.notReachedStages;
5762
this.completedStages = builder.completedStages;
5863
this.failedStages = builder.failedStages;
5964
this.totalChanges = builder.totalChanges;
6065
this.appliedChanges = builder.appliedChanges;
6166
this.skippedChanges = builder.skippedChanges;
6267
this.failedChanges = builder.failedChanges;
68+
this.notReachedChanges = builder.notReachedChanges;
6369
this.stages = builder.stages != null ? builder.stages : new ArrayList<>();
6470
}
6571

@@ -103,6 +109,22 @@ public void setTotalStages(int totalStages) {
103109
this.totalStages = totalStages;
104110
}
105111

112+
public int getUpToDateStages() {
113+
return upToDateStages;
114+
}
115+
116+
public void setUpToDateStages(int upToDateStages) {
117+
this.upToDateStages = upToDateStages;
118+
}
119+
120+
public int getNotReachedStages() {
121+
return notReachedStages;
122+
}
123+
124+
public void setNotReachedStages(int notReachedStages) {
125+
this.notReachedStages = notReachedStages;
126+
}
127+
106128
public int getCompletedStages() {
107129
return completedStages;
108130
}
@@ -151,6 +173,14 @@ public void setFailedChanges(int failedChanges) {
151173
this.failedChanges = failedChanges;
152174
}
153175

176+
public int getNotReachedChanges() {
177+
return notReachedChanges;
178+
}
179+
180+
public void setNotReachedChanges(int notReachedChanges) {
181+
this.notReachedChanges = notReachedChanges;
182+
}
183+
154184
public List<StageResult> getStages() {
155185
return stages;
156186
}
@@ -177,12 +207,15 @@ public static class Builder {
177207
private Instant endTime;
178208
private long totalDurationMs;
179209
private int totalStages;
210+
private int upToDateStages;
211+
private int notReachedStages;
180212
private int completedStages;
181213
private int failedStages;
182214
private int totalChanges;
183215
private int appliedChanges;
184216
private int skippedChanges;
185217
private int failedChanges;
218+
private int notReachedChanges;
186219
private List<StageResult> stages = new ArrayList<>();
187220

188221
public Builder status(ExecutionStatus status) {
@@ -210,6 +243,16 @@ public Builder totalStages(int totalStages) {
210243
return this;
211244
}
212245

246+
public Builder upToDateStages(int upToDateStages) {
247+
this.upToDateStages = upToDateStages;
248+
return this;
249+
}
250+
251+
public Builder notReachedStages(int notReachedStages) {
252+
this.notReachedStages = notReachedStages;
253+
return this;
254+
}
255+
213256
public Builder completedStages(int completedStages) {
214257
this.completedStages = completedStages;
215258
return this;
@@ -240,6 +283,11 @@ public Builder failedChanges(int failedChanges) {
240283
return this;
241284
}
242285

286+
public Builder notReachedChanges(int notReachedChanges) {
287+
this.notReachedChanges = notReachedChanges;
288+
return this;
289+
}
290+
243291
public Builder stages(List<StageResult> stages) {
244292
this.stages = stages;
245293
return this;

0 commit comments

Comments
 (0)