Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -41,4 +41,12 @@ default void postProcessing(DataFlowInstance dataFlowInstance,
default boolean shouldThrowException() {
return false;
}

default boolean shouldThrowExceptionInBeforeExecute() {
return false;
}

default boolean shouldThrowExceptionInAfterExecute() {
return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ public static enum ErrorCode {
NO_BUILDER_FOUND_FOR_NAME,
INSTANTIATION_FAILURE,
BUILDER_RESOLUTION_CONFLICT_FOR_DATA,
BUILDER_EXECUTION_ERROR
BUILDER_EXECUTION_ERROR,
BUILDER_PRE_EXECUTION_ERROR,
BUILDER_POST_EXECUTION_ERROR
}

private final ErrorCode errorCode;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,12 @@ public DataContainer call() throws Exception {
try {
listener.beforeExecute(dataBuilderContext, dataFlowInstance, builderMeta, dataDelta, responseData);
} catch (Throwable t) {
logger.error("Error running pre-execution execution listener: ", t);
final String errorMessage = "Error running pre-execution execution listener: ";
logger.error(errorMessage, t);
if (listener.shouldThrowExceptionInBeforeExecute()) {
throw new DataBuilderFrameworkException(DataBuilderFrameworkException.ErrorCode.BUILDER_PRE_EXECUTION_ERROR,
errorMessage + t.getMessage(), t);
}
}
}
try {
Expand All @@ -236,7 +241,12 @@ public DataContainer call() throws Exception {
try {
listener.afterExecute(dataBuilderContext, dataFlowInstance, builderMeta, dataDelta, responseData, response);
} catch (Throwable t) {
logger.error("Error running post-execution listener: ", t);
final String errorMessage = "Error running post-execution execution listener: ";
logger.error(errorMessage, t);
if (listener.shouldThrowExceptionInAfterExecute()) {
throw new DataBuilderFrameworkException(DataBuilderFrameworkException.ErrorCode.BUILDER_POST_EXECUTION_ERROR,
errorMessage + t.getMessage(), t);
}
}
}
if(null != response) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,12 @@ public DataContainer call() throws Exception {
try {
listener.beforeExecute(dataBuilderContext, dataFlowInstance, builderMeta, dataDelta, responseData);
} catch (Throwable t) {
logger.error("Error running pre-execution execution listener: ", t);
final String errorMessage = "Error running pre-execution execution listener: ";
logger.error(errorMessage, t);
if (listener.shouldThrowExceptionInBeforeExecute()) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Exact same code is getting repeated at three places. Create a method like, handleExceptionInBeforeExecute() in utils and use that at all the places.
Same can be done for afterExecute as well.

throw new DataBuilderFrameworkException(DataBuilderFrameworkException.ErrorCode.BUILDER_PRE_EXECUTION_ERROR,
errorMessage + t.getMessage(), t);
}
}
}
try {
Expand All @@ -255,7 +260,12 @@ public DataContainer call() throws Exception {
try {
listener.afterExecute(dataBuilderContext, dataFlowInstance, builderMeta, dataDelta, responseData, response);
} catch (Throwable t) {
logger.error("Error running post-execution listener: ", t);
final String errorMessage = "Error running post-execution execution listener: ";
logger.error(errorMessage, t);
if (listener.shouldThrowExceptionInAfterExecute()) {
throw new DataBuilderFrameworkException(DataBuilderFrameworkException.ErrorCode.BUILDER_POST_EXECUTION_ERROR,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add test cases for both the changes

errorMessage + t.getMessage(), t);
}
}
}
if(null != response) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,12 @@ protected DataExecutionResponse run(DataBuilderContext dataBuilderContext,
try {
listener.beforeExecute(dataBuilderContext, dataFlowInstance, builderMeta, dataDelta, responseData);
} catch (Throwable t) {
logger.error("Error running pre-execution execution listener: ", t);
final String errorMessage = "Error running pre-execution execution listener: ";
logger.error(errorMessage, t);
if (listener.shouldThrowExceptionInBeforeExecute()) {
throw new DataBuilderFrameworkException(DataBuilderFrameworkException.ErrorCode.BUILDER_PRE_EXECUTION_ERROR,
errorMessage + t.getMessage(), t);
}
}
}
try {
Expand All @@ -86,13 +91,17 @@ protected DataExecutionResponse run(DataBuilderContext dataBuilderContext,
newlyGeneratedData.add(response.getData());
}
}
//logger.debug("Ran " + builderMeta.getName());
processedBuilders.add(builderMeta);
for (DataBuilderExecutionListener listener : dataBuilderExecutionListener) {
try {
listener.afterExecute(dataBuilderContext, dataFlowInstance, builderMeta, dataDelta, responseData, response);
} catch (Throwable t) {
logger.error("Error running post-execution listener: ", t);
final String errorMessage = "Error running post-execution execution listener: ";
logger.error(errorMessage, t);
if (listener.shouldThrowExceptionInAfterExecute()) {
throw new DataBuilderFrameworkException(DataBuilderFrameworkException.ErrorCode.BUILDER_POST_EXECUTION_ERROR,
errorMessage + t.getMessage(), t);
}
}
}

Expand Down