Skip to content

Commit 66b7063

Browse files
committed
refactor: WIP
1 parent 779e3fd commit 66b7063

11 files changed

Lines changed: 386 additions & 44 deletions

File tree

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

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,11 @@ public class ExecuteResponseData {
3434

3535
// Aggregate counts
3636
private int totalStages;
37+
private int reachedStages;
3738
private int completedStages;
3839
private int failedStages;
3940
private int totalChanges;
41+
private int reachedChanges;
4042
private int appliedChanges;
4143
private int skippedChanges;
4244
private int failedChanges;
@@ -54,9 +56,11 @@ private ExecuteResponseData(Builder builder) {
5456
this.endTime = builder.endTime;
5557
this.totalDurationMs = builder.totalDurationMs;
5658
this.totalStages = builder.totalStages;
59+
this.reachedStages = builder.reachedStages;
5760
this.completedStages = builder.completedStages;
5861
this.failedStages = builder.failedStages;
5962
this.totalChanges = builder.totalChanges;
63+
this.reachedChanges = builder.reachedChanges;
6064
this.appliedChanges = builder.appliedChanges;
6165
this.skippedChanges = builder.skippedChanges;
6266
this.failedChanges = builder.failedChanges;
@@ -103,6 +107,14 @@ public void setTotalStages(int totalStages) {
103107
this.totalStages = totalStages;
104108
}
105109

110+
public int getReachedStages() {
111+
return reachedStages;
112+
}
113+
114+
public void setReachedStages(int reachedStages) {
115+
this.reachedStages = reachedStages;
116+
}
117+
106118
public int getCompletedStages() {
107119
return completedStages;
108120
}
@@ -127,6 +139,14 @@ public void setTotalChanges(int totalChanges) {
127139
this.totalChanges = totalChanges;
128140
}
129141

142+
public int getReachedChanges() {
143+
return reachedChanges;
144+
}
145+
146+
public void setReachedChanges(int reachedChanges) {
147+
this.reachedChanges = reachedChanges;
148+
}
149+
130150
public int getAppliedChanges() {
131151
return appliedChanges;
132152
}
@@ -177,9 +197,11 @@ public static class Builder {
177197
private Instant endTime;
178198
private long totalDurationMs;
179199
private int totalStages;
200+
private int reachedStages;
180201
private int completedStages;
181202
private int failedStages;
182203
private int totalChanges;
204+
private int reachedChanges;
183205
private int appliedChanges;
184206
private int skippedChanges;
185207
private int failedChanges;
@@ -210,6 +232,11 @@ public Builder totalStages(int totalStages) {
210232
return this;
211233
}
212234

235+
public Builder reachedStages(int reachedStages) {
236+
this.reachedStages = reachedStages;
237+
return this;
238+
}
239+
213240
public Builder completedStages(int completedStages) {
214241
this.completedStages = completedStages;
215242
return this;
@@ -225,6 +252,11 @@ public Builder totalChanges(int totalChanges) {
225252
return this;
226253
}
227254

255+
public Builder reachedChanges(int reachedChanges) {
256+
this.reachedChanges = reachedChanges;
257+
return this;
258+
}
259+
228260
public Builder appliedChanges(int appliedChanges) {
229261
this.appliedChanges = appliedChanges;
230262
return this;

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

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,11 @@ public static String summary(ExecuteResponseData result) {
6161
result.getFailedStages(),
6262
result.getTotalStages(),
6363
String.join(", ", failedStageNames));
64+
} else if (result.getStatus() == ExecutionStatus.NO_CHANGES) {
65+
return String.format(
66+
"Flamingock execution: no changes — %d stage(s) already up to date; duration=%dms",
67+
result.getTotalStages(),
68+
result.getTotalDurationMs());
6469
} else {
6570
headline = String.format(
6671
"Flamingock execution completed: %d stage(s)",
@@ -98,25 +103,48 @@ public static String report(ExecuteResponseData result) {
98103

99104
sb.append(" Stages: ")
100105
.append(result.getTotalStages()).append(" total — ")
106+
.append(result.getReachedStages()).append(" reached, ")
101107
.append(result.getCompletedStages()).append(" completed, ")
102108
.append(result.getFailedStages()).append(" failed")
103109
.append(NEWLINE);
104110
sb.append(" Changes: ")
105111
.append(result.getTotalChanges()).append(" total — ")
112+
.append(result.getReachedChanges()).append(" reached, ")
106113
.append(result.getAppliedChanges()).append(" applied, ")
107114
.append(result.getSkippedChanges()).append(" skipped, ")
108115
.append(result.getFailedChanges()).append(" failed")
109116
.append(NEWLINE);
110117

118+
// Per-stage breakdown: only stages the executor actually opened. Stages the planner
119+
// short-circuited past are surfaced separately in the "Not reached" section below (when
120+
// the coverage is partial — a fully up-to-date run shows neither, the headline carries it).
111121
List<StageResult> stages = nonNullStages(result);
112-
if (!stages.isEmpty()) {
122+
List<StageResult> reached = stages.stream()
123+
.filter(StageResult::isWasExecuted)
124+
.collect(Collectors.toList());
125+
if (!reached.isEmpty()) {
113126
sb.append(NEWLINE).append(" Per-stage breakdown:").append(NEWLINE).append(NEWLINE);
114-
for (StageResult stage : stages) {
127+
for (StageResult stage : reached) {
115128
appendStageBlock(sb, stage);
116129
sb.append(NEWLINE);
117130
}
118131
}
119132

133+
// "Not reached" only appears when there's a partial: some stages ran, some didn't. The
134+
// all-up-to-date case (0 reached) is communicated by the NO_CHANGES headline alone.
135+
List<StageResult> notReached = stages.stream()
136+
.filter(s -> !s.isWasExecuted())
137+
.collect(Collectors.toList());
138+
if (!notReached.isEmpty() && result.getReachedStages() > 0) {
139+
sb.append(NEWLINE).append(" Not reached (").append(notReached.size()).append("):").append(NEWLINE);
140+
for (StageResult stage : notReached) {
141+
String name = stage.getStageName() != null ? stage.getStageName() : "(unnamed)";
142+
sb.append(" - ").append(name)
143+
.append(" (").append(stage.getTotalChanges()).append(" changes)").append(NEWLINE);
144+
}
145+
sb.append(NEWLINE);
146+
}
147+
120148
sb.append(LINE);
121149
return sb.toString();
122150
}
@@ -208,7 +236,9 @@ private static String statusLabel(ExecuteResponseData result) {
208236
if (status == null) {
209237
return "UNKNOWN";
210238
}
211-
return status.name();
239+
// Render the enum name with underscores replaced by spaces so the headline reads naturally
240+
// ("NO CHANGES" rather than "NO_CHANGES").
241+
return status.name().replace('_', ' ');
212242
}
213243

214244
private static boolean isFailedStatus(ExecutionStatus status) {

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

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,21 @@ public class StageResult {
2929
private long durationMs;
3030
private List<ChangeResult> changes;
3131

32+
/**
33+
* True if the executor was invoked on this stage during the run. False for stages the planner
34+
* short-circuited past (e.g. nothing to do per audit, or skipped because an earlier block
35+
* aborted). Drives the reporter's "reached" vs "total" split — see {@code ExecutionReportFormatter}.
36+
*/
37+
private boolean wasExecuted;
38+
39+
/**
40+
* Structural change count from the loaded pipeline — total changes declared on this stage,
41+
* regardless of how many were actually evaluated this run. Populated by
42+
* {@code PipelineRun.toResponse()} for every stage so the reporter can render
43+
* "Not reached" rows with accurate "(N changes)" counts even when {@link #changes} is empty.
44+
*/
45+
private int totalChanges;
46+
3247
public StageResult() {
3348
this.changes = new ArrayList<>();
3449
this.state = StageState.NOT_STARTED;
@@ -40,6 +55,8 @@ private StageResult(Builder builder) {
4055
this.state = builder.state != null ? builder.state : StageState.NOT_STARTED;
4156
this.durationMs = builder.durationMs;
4257
this.changes = builder.changes != null ? builder.changes : new ArrayList<>();
58+
this.wasExecuted = builder.wasExecuted;
59+
this.totalChanges = builder.totalChanges;
4360
}
4461

4562
public String getStageId() {
@@ -82,6 +99,22 @@ public void setChanges(List<ChangeResult> changes) {
8299
this.changes = changes;
83100
}
84101

102+
public boolean isWasExecuted() {
103+
return wasExecuted;
104+
}
105+
106+
public void setWasExecuted(boolean wasExecuted) {
107+
this.wasExecuted = wasExecuted;
108+
}
109+
110+
public int getTotalChanges() {
111+
return totalChanges;
112+
}
113+
114+
public void setTotalChanges(int totalChanges) {
115+
this.totalChanges = totalChanges;
116+
}
117+
85118
public boolean isFailed() {
86119
return state.isFailed();
87120
}
@@ -122,7 +155,9 @@ public static Builder builder(StageResult source) {
122155
.stageName(source.stageName)
123156
.state(source.state)
124157
.durationMs(source.durationMs)
125-
.changes(new ArrayList<>(source.changes));
158+
.changes(new ArrayList<>(source.changes))
159+
.wasExecuted(source.wasExecuted)
160+
.totalChanges(source.totalChanges);
126161
}
127162

128163
public static class Builder {
@@ -131,6 +166,8 @@ public static class Builder {
131166
private StageState state;
132167
private long durationMs;
133168
private List<ChangeResult> changes = new ArrayList<>();
169+
private boolean wasExecuted;
170+
private int totalChanges;
134171

135172
public Builder stageId(String stageId) {
136173
this.stageId = stageId;
@@ -165,6 +202,16 @@ public Builder addChange(ChangeResult change) {
165202
return this;
166203
}
167204

205+
public Builder wasExecuted(boolean wasExecuted) {
206+
this.wasExecuted = wasExecuted;
207+
return this;
208+
}
209+
210+
public Builder totalChanges(int totalChanges) {
211+
this.totalChanges = totalChanges;
212+
return this;
213+
}
214+
168215
public StageResult build() {
169216
return new StageResult(this);
170217
}

0 commit comments

Comments
 (0)