Skip to content

Commit e962915

Browse files
authored
feat: logs improvement (#711)
1 parent b42b1a2 commit e962915

File tree

43 files changed

+435
-190
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+435
-190
lines changed

cloud/flamingock-cloud/src/main/java/io/flamingock/cloud/audit/HtttpAuditWriter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ public Result writeEntry(AuditEntry auditEntry) {
7676
.execute();
7777
return Result.OK();
7878
} catch (Throwable throwable) {
79-
logger.error("Error writing audit [{}] :\n{}", auditEntry.getTaskId(), throwable.toString());
79+
logger.debug("Error writing audit [{}] :\n{}", auditEntry.getTaskId(), throwable.toString());
8080
return new Result.Error(throwable);
8181
}
8282

core/flamingock-core-commons/src/main/java/io/flamingock/internal/common/core/error/FlamingockException.java

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,6 @@
2222
public class FlamingockException extends RuntimeException {
2323

2424

25-
public FlamingockException() {
26-
super();
27-
}
28-
2925
public FlamingockException(Throwable cause) {
3026
super(cause);
3127
}
@@ -34,16 +30,12 @@ public FlamingockException(String message) {
3430
super(message);
3531
}
3632

37-
public FlamingockException(String formattedMessage, Object... args) {
38-
super(String.format(formattedMessage, args));
39-
}
40-
41-
public FlamingockException(Throwable cause, String formattedMessage, Object... args) {
42-
this(String.format(formattedMessage, args), cause);
33+
public FlamingockException(String message, Throwable cause) {
34+
super(message, cause);
4335
}
4436

45-
public FlamingockException(Throwable cause, String message) {
46-
super(message, cause);
37+
public FlamingockException(String message, Object... args) {
38+
super(String.format(message, args));
4739
}
4840

4941
}

core/flamingock-core-commons/src/main/java/io/flamingock/internal/common/core/recovery/action/ChangeActionResolver.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@ public static ChangeAction resolve(AuditEntry auditEntry) {
6464
return MANUAL_INTERVENTION;
6565
}
6666

67-
case MANUAL_MARKED_AS_ROLLED_BACK:
6867
case FAILED:
6968
if (txStrategy == null || txStrategy == AuditTxType.NON_TX) {
7069
if (auditEntry.getRecoveryStrategy().isAlwaysRetry()) {
@@ -85,6 +84,7 @@ public static ChangeAction resolve(AuditEntry auditEntry) {
8584
return APPLY;
8685
}
8786

87+
case MANUAL_MARKED_AS_ROLLED_BACK:
8888
case ROLLED_BACK:
8989
log.debug("Change[{}] in state='{}}' (TxType={}}) -> Action={}} | Reason: {}",
9090
auditEntry.getTaskId(), status, txStrategy, APPLY,

core/flamingock-core/src/main/java/io/flamingock/internal/core/pipeline/execution/StageExecutionException.java

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,17 @@
1919

2020
public class StageExecutionException extends FlamingockException {
2121

22-
private final StageSummary summary;
23-
24-
25-
public StageExecutionException(StageSummary summary) {
26-
super("\n\n" + summary.getPretty() + "\n");
27-
this.summary = summary;
22+
public static StageExecutionException fromExisting(Throwable exception, StageSummary summary) {
23+
Throwable cause = exception.getCause();
24+
return (exception instanceof FlamingockException) && cause != null
25+
? new StageExecutionException(cause, summary)
26+
: new StageExecutionException(exception, summary);
2827
}
2928

30-
public StageExecutionException(Throwable throwable, StageSummary summary) {
31-
super(throwable);
29+
private final StageSummary summary;
30+
31+
private StageExecutionException(Throwable cause, StageSummary summary) {
32+
super(cause);
3233
this.summary = summary;
3334
}
3435

core/flamingock-core/src/main/java/io/flamingock/internal/core/pipeline/execution/StageExecutor.java

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
import io.flamingock.internal.core.store.lock.Lock;
2424
import io.flamingock.internal.core.targets.TargetSystemManager;
2525
import io.flamingock.internal.core.task.executable.ExecutableTask;
26+
import io.flamingock.internal.core.task.navigation.FailedChangeProcessResult;
27+
import io.flamingock.internal.core.task.navigation.navigator.ChangeProcessResult;
2628
import io.flamingock.internal.core.task.navigation.navigator.ChangeProcessStrategy;
2729
import io.flamingock.internal.core.task.navigation.navigator.ChangeProcessStrategyFactory;
2830
import io.flamingock.internal.core.transaction.TransactionWrapper;
@@ -78,39 +80,37 @@ public Output executeStage(ExecutableStage executableStage,
7880
.map(changeProcessFactory::setChange)
7981
.map(ChangeProcessStrategyFactory::build)
8082
.map(ChangeProcessStrategy::applyChange)
81-
.peek(taskSummary -> {
82-
summary.addSummary(taskSummary);
83-
if (taskSummary.isFailed()) {
83+
.peek(result -> {
84+
summary.addSummary(result.getSummary());
85+
if (result.isFailed()) {
8486
logger.error("Change failed [change={} stage={}]",
85-
taskSummary.getId(), stageName);
87+
result.getChangeId(), stageName);
8688
} else {
8789
logger.debug("Change completed successfully [change={} stage={}]",
88-
taskSummary.getId(), stageName);
90+
result.getChangeId(), stageName);
8991
}
9092
})
91-
.filter(TaskSummary::isFailed)
93+
.filter(ChangeProcessResult::isFailed)
9294
.findFirst()
93-
.ifPresent(failed -> {
95+
.map(processResult -> (FailedChangeProcessResult)processResult)
96+
.ifPresent(failedResult -> {
9497
Duration stageDuration = Duration.between(stageStart, LocalDateTime.now());
95-
logger.error("Stage execution failed [stage={} duration={} failed_change={}]",
96-
stageName, formatDuration(stageDuration), failed.getId());
97-
throw new StageExecutionException(summary);
98+
logger.debug("Stage execution failed [stage={} duration={} failed_change={}]",
99+
stageName, formatDuration(stageDuration), failedResult.getChangeId());
100+
throw StageExecutionException.fromExisting(failedResult.getException(), summary);
98101
});
99102

100103
Duration stageDuration = Duration.between(stageStart, LocalDateTime.now());
101104
logger.info("Stage execution completed successfully [stage={} duration={} tasks={}]",
102105
stageName, formatDuration(stageDuration), taskCount);
103106

104107
} catch (StageExecutionException stageExecutionException) {
105-
Duration stageDuration = Duration.between(stageStart, LocalDateTime.now());
106-
logger.error("Stage execution failed [stage={} duration={}]",
107-
stageName, formatDuration(stageDuration));
108108
throw stageExecutionException;
109109
} catch (Throwable throwable) {
110110
Duration stageDuration = Duration.between(stageStart, LocalDateTime.now());
111-
logger.error("Stage execution failed with unexpected error [stage={} duration={} error={}]",
111+
logger.debug("Stage execution failed with unexpected error [stage={} duration={} error={}]",
112112
stageName, formatDuration(stageDuration), throwable.getMessage(), throwable);
113-
throw new StageExecutionException(throwable, summary);
113+
throw StageExecutionException.fromExisting(throwable, summary);
114114
}
115115

116116
return new Output(summary);

core/flamingock-core/src/main/java/io/flamingock/internal/core/runner/PipelineExecutionException.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,17 @@
1919

2020
public class PipelineExecutionException extends FlamingockException {
2121

22-
private final PipelineSummary summary;
22+
public static PipelineExecutionException fromExisting(Throwable exception, PipelineSummary summary) {
23+
Throwable cause = exception.getCause();
24+
return (exception instanceof FlamingockException) && cause != null
25+
? new PipelineExecutionException(cause, summary)
26+
: new PipelineExecutionException(exception, summary);
27+
}
2328

29+
private final PipelineSummary summary;
2430

25-
public PipelineExecutionException(PipelineSummary summary) {
26-
super("\n\n" + summary.getPretty() + "\n");
27-
this.summary = summary;
28-
}
2931

30-
public PipelineExecutionException(Throwable throwable, PipelineSummary summary) {
32+
private PipelineExecutionException(Throwable throwable, PipelineSummary summary) {
3133
super(throwable);
3234
this.summary = summary;
3335
}

core/flamingock-core/src/main/java/io/flamingock/internal/core/runner/PipelineRunner.java

Lines changed: 37 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,7 @@
1515
*/
1616
package io.flamingock.internal.core.runner;
1717

18-
import io.flamingock.internal.util.id.RunnerId;
1918
import io.flamingock.internal.common.core.error.FlamingockException;
20-
import io.flamingock.internal.core.plan.ExecutionPlan;
21-
import io.flamingock.internal.core.plan.ExecutionPlanner;
22-
import io.flamingock.internal.core.store.lock.Lock;
23-
import io.flamingock.internal.core.store.lock.LockException;
2419
import io.flamingock.internal.core.event.EventPublisher;
2520
import io.flamingock.internal.core.event.model.impl.PipelineCompletedEvent;
2621
import io.flamingock.internal.core.event.model.impl.PipelineFailedEvent;
@@ -29,13 +24,18 @@
2924
import io.flamingock.internal.core.event.model.impl.StageFailedEvent;
3025
import io.flamingock.internal.core.event.model.impl.StageStartedEvent;
3126
import io.flamingock.internal.core.pipeline.execution.ExecutableStage;
32-
import io.flamingock.internal.core.pipeline.loaded.stage.AbstractLoadedStage;
33-
import io.flamingock.internal.core.pipeline.loaded.LoadedPipeline;
3427
import io.flamingock.internal.core.pipeline.execution.ExecutionContext;
3528
import io.flamingock.internal.core.pipeline.execution.OrphanExecutionContext;
3629
import io.flamingock.internal.core.pipeline.execution.StageExecutionException;
3730
import io.flamingock.internal.core.pipeline.execution.StageExecutor;
3831
import io.flamingock.internal.core.pipeline.execution.StageSummary;
32+
import io.flamingock.internal.core.pipeline.loaded.LoadedPipeline;
33+
import io.flamingock.internal.core.pipeline.loaded.stage.AbstractLoadedStage;
34+
import io.flamingock.internal.core.plan.ExecutionPlan;
35+
import io.flamingock.internal.core.plan.ExecutionPlanner;
36+
import io.flamingock.internal.core.store.lock.Lock;
37+
import io.flamingock.internal.core.store.lock.LockException;
38+
import io.flamingock.internal.util.id.RunnerId;
3939
import io.flamingock.internal.util.log.FlamingockLoggerFactory;
4040
import org.slf4j.Logger;
4141

@@ -82,6 +82,15 @@ public PipelineRunner(RunnerId runnerId,
8282
this.finalizer = finalizer;
8383
}
8484

85+
private static List<AbstractLoadedStage> validateAndGetExecutableStages(LoadedPipeline pipeline) {
86+
pipeline.validate();
87+
List<AbstractLoadedStage> stages = new ArrayList<>();
88+
if (pipeline.getSystemStage().isPresent()) {
89+
stages.add(pipeline.getSystemStage().get());
90+
}
91+
stages.addAll(pipeline.getStages());
92+
return stages;
93+
}
8594

8695
private void run(LoadedPipeline pipeline) throws FlamingockException {
8796

@@ -93,7 +102,7 @@ private void run(LoadedPipeline pipeline) throws FlamingockException {
93102
// Validate execution plan for manual intervention requirements
94103
// This centralized validation ensures both community and cloud paths are validated
95104
execution.validate();
96-
105+
97106
if (pipelineSummary == null) {
98107
pipelineSummary = new PipelineSummary(execution.getPipeline());
99108
}
@@ -111,7 +120,7 @@ private void run(LoadedPipeline pipeline) throws FlamingockException {
111120
eventPublisher.publish(new StageFailedEvent(exception));
112121
eventPublisher.publish(new PipelineFailedEvent(exception));
113122
if (throwExceptionIfCannotObtainLock) {
114-
logger.error("Required process lock not acquired - ABORTING OPERATION", exception);
123+
logger.debug("Required process lock not acquired - ABORTING OPERATION", exception);
115124
throw exception;
116125
} else {
117126
logger.warn("Process lock not acquired but throwExceptionIfCannotObtainLock=false - CONTINUING WITHOUT LOCK", exception);
@@ -121,7 +130,7 @@ private void run(LoadedPipeline pipeline) throws FlamingockException {
121130
//if it's a StageExecutionException, we can safely assume the stage started its
122131
//execution, therefor the pipelinesSummary is initialised
123132
requireNonNull(pipelineSummary).merge(e.getSummary());
124-
throw new PipelineExecutionException(pipelineSummary);
133+
throw PipelineExecutionException.fromExisting(e.getCause(), pipelineSummary);
125134
}
126135
} while (true);
127136

@@ -131,17 +140,6 @@ private void run(LoadedPipeline pipeline) throws FlamingockException {
131140
eventPublisher.publish(new PipelineCompletedEvent());
132141
}
133142

134-
private static List<AbstractLoadedStage> validateAndGetExecutableStages(LoadedPipeline pipeline) {
135-
pipeline.validate();
136-
List<AbstractLoadedStage> stages = new ArrayList<>();
137-
if(pipeline.getSystemStage().isPresent()) {
138-
stages.add(pipeline.getSystemStage().get());
139-
}
140-
stages.addAll(pipeline.getStages());
141-
return stages;
142-
}
143-
144-
145143
private StageSummary runStage(String executionId, Lock lock, ExecutableStage executableStage) {
146144
try {
147145
return startStage(executionId, lock, executableStage);
@@ -164,12 +162,24 @@ private StageSummary startStage(String executionId, Lock lock, ExecutableStage e
164162
return executionOutput.getSummary();
165163
}
166164

167-
private FlamingockException processAndGetFlamingockException(Throwable generalException) throws FlamingockException {
168-
FlamingockException exception = generalException instanceof FlamingockException ? (FlamingockException) generalException : new FlamingockException(generalException);
169-
logger.error("Error executing the process. ABORTED OPERATION", exception);
170-
eventPublisher.publish(new StageFailedEvent(exception));
171-
eventPublisher.publish(new PipelineFailedEvent(exception));
172-
return exception;
165+
private FlamingockException processAndGetFlamingockException(Throwable exception) throws FlamingockException {
166+
FlamingockException flamingockException;
167+
if (exception instanceof PipelineExecutionException) {
168+
PipelineExecutionException pipelineException = (PipelineExecutionException) exception;
169+
if (pipelineException.getCause() instanceof FlamingockException) {
170+
flamingockException = (FlamingockException) pipelineException.getCause();
171+
} else {
172+
flamingockException = (PipelineExecutionException) exception;
173+
}
174+
} else if (exception instanceof FlamingockException) {
175+
flamingockException = (FlamingockException) exception;
176+
} else {
177+
flamingockException = new FlamingockException(exception);
178+
}
179+
logger.debug("Error executing the process. ABORTED OPERATION", exception);
180+
eventPublisher.publish(new StageFailedEvent(flamingockException));
181+
eventPublisher.publish(new PipelineFailedEvent(flamingockException));
182+
return flamingockException;
173183
}
174184

175185
@Override

core/flamingock-core/src/main/java/io/flamingock/internal/core/runtime/ExecutionRuntime.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
import javax.inject.Named;
3737
import java.lang.reflect.Constructor;
3838
import java.lang.reflect.Executable;
39+
import java.lang.reflect.InvocationTargetException;
3940
import java.lang.reflect.Method;
4041
import java.lang.reflect.Parameter;
4142
import java.util.ArrayList;
@@ -118,7 +119,14 @@ public Object executeMethodWithParameters(Object instance, Method method, Object
118119
try {
119120
return method.invoke(instance, parameters);
120121
} catch (Exception e) {
121-
throw new RuntimeException(e);
122+
if(e instanceof FlamingockException) {
123+
throw (FlamingockException)e;
124+
} else {
125+
throw e instanceof InvocationTargetException
126+
? new FlamingockException(((InvocationTargetException)e).getTargetException())
127+
: new FlamingockException(e);
128+
129+
}
122130
}
123131
}
124132

core/flamingock-core/src/main/java/io/flamingock/internal/core/runtime/MissingInjectedParameterException.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public class MissingInjectedParameterException extends FlamingockException {
2424
private final String name;
2525

2626
public MissingInjectedParameterException(Class<?> wrongParameter, String name) {
27-
super();
27+
super(buildMessage(wrongParameter, name));
2828
this.wrongParameter = wrongParameter;
2929
this.name = name;
3030
}
@@ -37,12 +37,11 @@ public String getName() {
3737
return name;
3838
}
3939

40-
@Override
41-
public String getMessage() {
40+
private static String buildMessage(Class<?> wrongParameter, String name) {
4241

4342

4443
StringBuilder sb = new StringBuilder("Wrong parameter[")
45-
.append(getWrongParameter().getSimpleName())
44+
.append(wrongParameter.getSimpleName())
4645
.append("]");
4746
if (name != null) {
4847
sb.append(" with name: ")

core/flamingock-core/src/main/java/io/flamingock/internal/core/store/audit/domain/RuntimeContext.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ public Builder setAutoRollbackStep(CompleteAutoRolledBackStep rolledBackStep) {
139139
private void setResult(TaskStep taskStep) {
140140
if (taskStep instanceof FailedWithErrorStep) {
141141
executionResult = ExecutionResult.FAILED;
142-
error = ((FailedWithErrorStep) taskStep).getError();
142+
error = ((FailedWithErrorStep) taskStep).getMainError();
143143
} else {
144144
executionResult = ExecutionResult.SUCCESS;
145145
error = null;

0 commit comments

Comments
 (0)