Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public Result writeEntry(AuditEntry auditEntry) {
.execute();
return Result.OK();
} catch (Throwable throwable) {
logger.error("Error writing audit [{}] :\n{}", auditEntry.getTaskId(), throwable.toString());
logger.debug("Error writing audit [{}] :\n{}", auditEntry.getTaskId(), throwable.toString());
return new Result.Error(throwable);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,6 @@
public class FlamingockException extends RuntimeException {


public FlamingockException() {
super();
}

public FlamingockException(Throwable cause) {
super(cause);
}
Expand All @@ -34,16 +30,12 @@ public FlamingockException(String message) {
super(message);
}

public FlamingockException(String formattedMessage, Object... args) {
super(String.format(formattedMessage, args));
}

public FlamingockException(Throwable cause, String formattedMessage, Object... args) {
this(String.format(formattedMessage, args), cause);
public FlamingockException(String message, Throwable cause) {
super(message, cause);
}

public FlamingockException(Throwable cause, String message) {
super(message, cause);
public FlamingockException(String message, Object... args) {
super(String.format(message, args));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ public static ChangeAction resolve(AuditEntry auditEntry) {
return MANUAL_INTERVENTION;
}

case MANUAL_MARKED_AS_ROLLED_BACK:
case FAILED:
if (txStrategy == null || txStrategy == AuditTxType.NON_TX) {
if (auditEntry.getRecoveryStrategy().isAlwaysRetry()) {
Expand All @@ -85,6 +84,7 @@ public static ChangeAction resolve(AuditEntry auditEntry) {
return APPLY;
}

case MANUAL_MARKED_AS_ROLLED_BACK:
case ROLLED_BACK:
log.debug("Change[{}] in state='{}}' (TxType={}}) -> Action={}} | Reason: {}",
auditEntry.getTaskId(), status, txStrategy, APPLY,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,17 @@

public class StageExecutionException extends FlamingockException {

private final StageSummary summary;


public StageExecutionException(StageSummary summary) {
super("\n\n" + summary.getPretty() + "\n");
this.summary = summary;
public static StageExecutionException fromExisting(Throwable exception, StageSummary summary) {
Throwable cause = exception.getCause();
return (exception instanceof FlamingockException) && cause != null
? new StageExecutionException(cause, summary)
: new StageExecutionException(exception, summary);
}

public StageExecutionException(Throwable throwable, StageSummary summary) {
super(throwable);
private final StageSummary summary;

private StageExecutionException(Throwable cause, StageSummary summary) {
super(cause);
this.summary = summary;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
import io.flamingock.internal.core.store.lock.Lock;
import io.flamingock.internal.core.targets.TargetSystemManager;
import io.flamingock.internal.core.task.executable.ExecutableTask;
import io.flamingock.internal.core.task.navigation.FailedChangeProcessResult;
import io.flamingock.internal.core.task.navigation.navigator.ChangeProcessResult;
import io.flamingock.internal.core.task.navigation.navigator.ChangeProcessStrategy;
import io.flamingock.internal.core.task.navigation.navigator.ChangeProcessStrategyFactory;
import io.flamingock.internal.core.transaction.TransactionWrapper;
Expand Down Expand Up @@ -78,39 +80,37 @@ public Output executeStage(ExecutableStage executableStage,
.map(changeProcessFactory::setChange)
.map(ChangeProcessStrategyFactory::build)
.map(ChangeProcessStrategy::applyChange)
.peek(taskSummary -> {
summary.addSummary(taskSummary);
if (taskSummary.isFailed()) {
.peek(result -> {
summary.addSummary(result.getSummary());
if (result.isFailed()) {
logger.error("Change failed [change={} stage={}]",
taskSummary.getId(), stageName);
result.getChangeId(), stageName);
} else {
logger.debug("Change completed successfully [change={} stage={}]",
taskSummary.getId(), stageName);
result.getChangeId(), stageName);
}
})
.filter(TaskSummary::isFailed)
.filter(ChangeProcessResult::isFailed)
.findFirst()
.ifPresent(failed -> {
.map(processResult -> (FailedChangeProcessResult)processResult)
.ifPresent(failedResult -> {
Duration stageDuration = Duration.between(stageStart, LocalDateTime.now());
logger.error("Stage execution failed [stage={} duration={} failed_change={}]",
stageName, formatDuration(stageDuration), failed.getId());
throw new StageExecutionException(summary);
logger.debug("Stage execution failed [stage={} duration={} failed_change={}]",
stageName, formatDuration(stageDuration), failedResult.getChangeId());
throw StageExecutionException.fromExisting(failedResult.getException(), summary);
});

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

} catch (StageExecutionException stageExecutionException) {
Duration stageDuration = Duration.between(stageStart, LocalDateTime.now());
logger.error("Stage execution failed [stage={} duration={}]",
stageName, formatDuration(stageDuration));
throw stageExecutionException;
} catch (Throwable throwable) {
Duration stageDuration = Duration.between(stageStart, LocalDateTime.now());
logger.error("Stage execution failed with unexpected error [stage={} duration={} error={}]",
logger.debug("Stage execution failed with unexpected error [stage={} duration={} error={}]",
stageName, formatDuration(stageDuration), throwable.getMessage(), throwable);
throw new StageExecutionException(throwable, summary);
throw StageExecutionException.fromExisting(throwable, summary);
}

return new Output(summary);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,17 @@

public class PipelineExecutionException extends FlamingockException {

private final PipelineSummary summary;
public static PipelineExecutionException fromExisting(Throwable exception, PipelineSummary summary) {
Throwable cause = exception.getCause();
return (exception instanceof FlamingockException) && cause != null
? new PipelineExecutionException(cause, summary)
: new PipelineExecutionException(exception, summary);
}

private final PipelineSummary summary;

public PipelineExecutionException(PipelineSummary summary) {
super("\n\n" + summary.getPretty() + "\n");
this.summary = summary;
}

public PipelineExecutionException(Throwable throwable, PipelineSummary summary) {
private PipelineExecutionException(Throwable throwable, PipelineSummary summary) {
super(throwable);
this.summary = summary;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,7 @@
*/
package io.flamingock.internal.core.runner;

import io.flamingock.internal.util.id.RunnerId;
import io.flamingock.internal.common.core.error.FlamingockException;
import io.flamingock.internal.core.plan.ExecutionPlan;
import io.flamingock.internal.core.plan.ExecutionPlanner;
import io.flamingock.internal.core.store.lock.Lock;
import io.flamingock.internal.core.store.lock.LockException;
import io.flamingock.internal.core.event.EventPublisher;
import io.flamingock.internal.core.event.model.impl.PipelineCompletedEvent;
import io.flamingock.internal.core.event.model.impl.PipelineFailedEvent;
Expand All @@ -29,13 +24,18 @@
import io.flamingock.internal.core.event.model.impl.StageFailedEvent;
import io.flamingock.internal.core.event.model.impl.StageStartedEvent;
import io.flamingock.internal.core.pipeline.execution.ExecutableStage;
import io.flamingock.internal.core.pipeline.loaded.stage.AbstractLoadedStage;
import io.flamingock.internal.core.pipeline.loaded.LoadedPipeline;
import io.flamingock.internal.core.pipeline.execution.ExecutionContext;
import io.flamingock.internal.core.pipeline.execution.OrphanExecutionContext;
import io.flamingock.internal.core.pipeline.execution.StageExecutionException;
import io.flamingock.internal.core.pipeline.execution.StageExecutor;
import io.flamingock.internal.core.pipeline.execution.StageSummary;
import io.flamingock.internal.core.pipeline.loaded.LoadedPipeline;
import io.flamingock.internal.core.pipeline.loaded.stage.AbstractLoadedStage;
import io.flamingock.internal.core.plan.ExecutionPlan;
import io.flamingock.internal.core.plan.ExecutionPlanner;
import io.flamingock.internal.core.store.lock.Lock;
import io.flamingock.internal.core.store.lock.LockException;
import io.flamingock.internal.util.id.RunnerId;
import io.flamingock.internal.util.log.FlamingockLoggerFactory;
import org.slf4j.Logger;

Expand Down Expand Up @@ -82,6 +82,15 @@ public PipelineRunner(RunnerId runnerId,
this.finalizer = finalizer;
}

private static List<AbstractLoadedStage> validateAndGetExecutableStages(LoadedPipeline pipeline) {
pipeline.validate();
List<AbstractLoadedStage> stages = new ArrayList<>();
if (pipeline.getSystemStage().isPresent()) {
stages.add(pipeline.getSystemStage().get());
}
stages.addAll(pipeline.getStages());
return stages;
}

private void run(LoadedPipeline pipeline) throws FlamingockException {

Expand All @@ -93,7 +102,7 @@ private void run(LoadedPipeline pipeline) throws FlamingockException {
// Validate execution plan for manual intervention requirements
// This centralized validation ensures both community and cloud paths are validated
execution.validate();

if (pipelineSummary == null) {
pipelineSummary = new PipelineSummary(execution.getPipeline());
}
Expand All @@ -111,7 +120,7 @@ private void run(LoadedPipeline pipeline) throws FlamingockException {
eventPublisher.publish(new StageFailedEvent(exception));
eventPublisher.publish(new PipelineFailedEvent(exception));
if (throwExceptionIfCannotObtainLock) {
logger.error("Required process lock not acquired - ABORTING OPERATION", exception);
logger.debug("Required process lock not acquired - ABORTING OPERATION", exception);
throw exception;
} else {
logger.warn("Process lock not acquired but throwExceptionIfCannotObtainLock=false - CONTINUING WITHOUT LOCK", exception);
Expand All @@ -121,7 +130,7 @@ private void run(LoadedPipeline pipeline) throws FlamingockException {
//if it's a StageExecutionException, we can safely assume the stage started its
//execution, therefor the pipelinesSummary is initialised
requireNonNull(pipelineSummary).merge(e.getSummary());
throw new PipelineExecutionException(pipelineSummary);
throw PipelineExecutionException.fromExisting(e.getCause(), pipelineSummary);
}
} while (true);

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

private static List<AbstractLoadedStage> validateAndGetExecutableStages(LoadedPipeline pipeline) {
pipeline.validate();
List<AbstractLoadedStage> stages = new ArrayList<>();
if(pipeline.getSystemStage().isPresent()) {
stages.add(pipeline.getSystemStage().get());
}
stages.addAll(pipeline.getStages());
return stages;
}


private StageSummary runStage(String executionId, Lock lock, ExecutableStage executableStage) {
try {
return startStage(executionId, lock, executableStage);
Expand All @@ -164,12 +162,24 @@ private StageSummary startStage(String executionId, Lock lock, ExecutableStage e
return executionOutput.getSummary();
}

private FlamingockException processAndGetFlamingockException(Throwable generalException) throws FlamingockException {
FlamingockException exception = generalException instanceof FlamingockException ? (FlamingockException) generalException : new FlamingockException(generalException);
logger.error("Error executing the process. ABORTED OPERATION", exception);
eventPublisher.publish(new StageFailedEvent(exception));
eventPublisher.publish(new PipelineFailedEvent(exception));
return exception;
private FlamingockException processAndGetFlamingockException(Throwable exception) throws FlamingockException {
FlamingockException flamingockException;
if (exception instanceof PipelineExecutionException) {
PipelineExecutionException pipelineException = (PipelineExecutionException) exception;
if (pipelineException.getCause() instanceof FlamingockException) {
flamingockException = (FlamingockException) pipelineException.getCause();
} else {
flamingockException = (PipelineExecutionException) exception;
}
} else if (exception instanceof FlamingockException) {
flamingockException = (FlamingockException) exception;
} else {
flamingockException = new FlamingockException(exception);
}
logger.debug("Error executing the process. ABORTED OPERATION", exception);
eventPublisher.publish(new StageFailedEvent(flamingockException));
eventPublisher.publish(new PipelineFailedEvent(flamingockException));
return flamingockException;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import javax.inject.Named;
import java.lang.reflect.Constructor;
import java.lang.reflect.Executable;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.lang.reflect.Parameter;
import java.util.ArrayList;
Expand Down Expand Up @@ -118,7 +119,14 @@ public Object executeMethodWithParameters(Object instance, Method method, Object
try {
return method.invoke(instance, parameters);
} catch (Exception e) {
throw new RuntimeException(e);
if(e instanceof FlamingockException) {
throw (FlamingockException)e;
} else {
throw e instanceof InvocationTargetException
? new FlamingockException(((InvocationTargetException)e).getTargetException())
: new FlamingockException(e);

}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public class MissingInjectedParameterException extends FlamingockException {
private final String name;

public MissingInjectedParameterException(Class<?> wrongParameter, String name) {
super();
super(buildMessage(wrongParameter, name));
this.wrongParameter = wrongParameter;
this.name = name;
}
Expand All @@ -37,12 +37,11 @@ public String getName() {
return name;
}

@Override
public String getMessage() {
private static String buildMessage(Class<?> wrongParameter, String name) {


StringBuilder sb = new StringBuilder("Wrong parameter[")
.append(getWrongParameter().getSimpleName())
.append(wrongParameter.getSimpleName())
.append("]");
if (name != null) {
sb.append(" with name: ")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ public Builder setAutoRollbackStep(CompleteAutoRolledBackStep rolledBackStep) {
private void setResult(TaskStep taskStep) {
if (taskStep instanceof FailedWithErrorStep) {
executionResult = ExecutionResult.FAILED;
error = ((FailedWithErrorStep) taskStep).getError();
error = ((FailedWithErrorStep) taskStep).getMainError();
} else {
executionResult = ExecutionResult.SUCCESS;
error = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ protected void waitForLock(LocalDateTime expiresAt) {
TimeUtil.millisToMinutes(sleepingMillis));
Thread.sleep(sleepingMillis);
} catch (InterruptedException ex) {
logger.error("ERROR acquiring the lock", ex);
logger.warn("ERROR acquiring the lock", ex);
Thread.currentThread().interrupt();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,4 @@ public LockException(String s) {
super(s);
}

public LockException() {
super();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ public TargetSystemOps getTargetSystem(String id) {
"Change requires a valid targetSystem. Found: [%s]. Available target systems: [%s]",
id, availableTargetSystems
);
logger.error(message);
logger.debug(message);
throw new FlamingockException(message);
} else {
AbstractTargetSystem<?> targetSystem = targetSystemMap.get(id);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
package io.flamingock.internal.core.task.executable;

import io.flamingock.internal.common.core.error.ChangeExecutionException;
import io.flamingock.internal.core.runtime.ExecutionRuntime;
import io.flamingock.internal.core.task.loaded.AbstractReflectionLoadedTask;
import io.flamingock.internal.common.core.recovery.action.ChangeAction;
Expand Down Expand Up @@ -75,7 +76,11 @@ public void execute(ExecutionRuntime executionRuntime) {

protected void executeInternal(ExecutionRuntime executionRuntime, Method method ) {
Object instance = executionRuntime.getInstance(descriptor.getConstructor());
executionRuntime.executeMethodWithInjectedDependencies(instance, method);
try {
executionRuntime.executeMethodWithInjectedDependencies(instance, method);
} catch (Throwable ex) {
throw new ChangeExecutionException(ex.getMessage(), this.getId(), ex);
}
}

@Override
Expand Down
Loading
Loading