Skip to content

Commit

Permalink
Merge pull request #22 from zucisystems-dev/donut_ut/pipeline_exception
Browse files Browse the repository at this point in the history
Donut ut/pipeline exception
  • Loading branch information
Sanjeeya-Velayutham-ZS0029 authored May 8, 2023
2 parents 5797829 + 4901c4f commit 2f78e12
Show file tree
Hide file tree
Showing 82 changed files with 975 additions and 777 deletions.
11 changes: 11 additions & 0 deletions src/main/java/in/handyman/raven/exception/HandymanException.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
package in.handyman.raven.exception;

import in.handyman.raven.lambda.access.repo.HandymanRepoImpl;
import in.handyman.raven.lambda.doa.audit.ActionExecutionAudit;
import lombok.extern.slf4j.Slf4j;

@Slf4j
public class HandymanException extends RuntimeException {
private final HandymanRepoImpl handymanRepo = new HandymanRepoImpl();

public HandymanException(final String message) {
super(message);
Expand All @@ -9,4 +15,9 @@ public HandymanException(final String message) {
public HandymanException(final String message, final Exception t) {
super(message, t);
}

public HandymanException(final String message, final Exception exception, ActionExecutionAudit actionExecutionAudit) {
super(message, exception);
handymanRepo.insertExceptionLog(actionExecutionAudit, exception, message);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package in.handyman.raven.lambda.access.repo;

import in.handyman.raven.exception.HandymanException;
import in.handyman.raven.lambda.doa.DoaConstant;
import in.handyman.raven.lambda.doa.audit.ActionExecutionAudit;
import in.handyman.raven.lambda.doa.audit.ActionExecutionStatusAudit;
Expand All @@ -10,7 +11,12 @@
import in.handyman.raven.lambda.doa.config.SpwInstanceConfig;
import in.handyman.raven.lambda.doa.config.SpwProcessConfig;
import in.handyman.raven.lambda.doa.config.SpwResourceConfig;
import in.handyman.raven.util.ExceptionUtil;
import in.handyman.raven.util.PropertyHandler;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.jdbi.v3.core.Jdbi;
import org.jdbi.v3.sqlobject.SqlObjectPlugin;
Expand Down Expand Up @@ -382,4 +388,44 @@ public List<SpwResourceConfig> findAllResourceConfigs() {
return repo.findAll();
});
}
public void insertExceptionLog(ActionExecutionAudit actionExecutionAudit, Exception exception, String message) {
HandymanExceptionAuditDetails exceptionAuditDetails = HandymanExceptionAuditDetails.builder()
.groupId(Integer.parseInt(actionExecutionAudit.getContext().get("gen_group_id.group_id")))
.rootPipelineId(actionExecutionAudit.getRootPipelineId())
.rootPipelineName(actionExecutionAudit.getParentPipelineName())
.pipelineName(actionExecutionAudit.getPipelineName())
.actionId(actionExecutionAudit.getActionId())
.actionName(actionExecutionAudit.getActionName())
.exceptionInfo(ExceptionUtil.toString(exception))
.message(message)
.processId(actionExecutionAudit.getProcessId())
.createdBy(actionExecutionAudit.getCreatedBy())
.createdDate(actionExecutionAudit.getCreatedDate())
.lastModifiedBy(actionExecutionAudit.getLastModifiedBy())
.lastModifiedDate(actionExecutionAudit.getLastModifiedDate()).build();
JDBI.useHandle(handle -> handle.createUpdate("INSERT INTO audit.handyman_exception_audit (group_id, root_pipeline_id, root_pipeline_name, pipeline_name, action_id, action_name, exception_Info, message, process_id, created_by, created_date, last_modified_by, last_modified_date) " +
"VALUES(:groupId, :rootPipelineId, :rootPipelineName, :pipelineName, :actionId, :actionName, :exceptionInfo, :message, :processId, :createdBy, :createdDate, :lastModifiedBy, :lastModifiedDate);")
.bindBean(exceptionAuditDetails).execute());
log.info("inserting exception audit details has been completed");

}
@Data
@AllArgsConstructor
@NoArgsConstructor
@Builder
public static class HandymanExceptionAuditDetails {
private Integer groupId;
private Long rootPipelineId;
private String rootPipelineName;
private String pipelineName;
private Long actionId;
private String actionName;
private String exceptionInfo;
private String message;
private Long processId;
private Long createdBy;
private LocalDateTime createdDate;
private Long lastModifiedBy;
private LocalDateTime lastModifiedDate;
}
}
15 changes: 8 additions & 7 deletions src/main/java/in/handyman/raven/lib/AbsentKeyFilterAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

/**
* Auto Generated By Raven
Expand Down Expand Up @@ -80,7 +81,7 @@ private static ElasticsearchClient getElasticsearchClient(String userName, Strin
@Override
public void execute() throws Exception {
try {
log.info(aMarker, "<-------Absent Key Filter Action for {} has been started------->" + absentKeyFilter.getName());
log.info(aMarker, "Absent Key Filter Action for {} has been started" ,absentKeyFilter.getName());

JsonNode sorQuestionList = mapper.readTree(absentKeyFilter.getSorList());
String sorName = sorQuestionList.get("f1").asText();
Expand All @@ -94,11 +95,11 @@ public void execute() throws Exception {
query.matchPhrase(dd -> dd.field("file_path").query(absentKeyFilter.getFilePath()))
)
)), Object.class);
long hitsCount = filterList.hits().total().value();
long hitsCount = Objects.requireNonNull(filterList.hits().total()).value();
if (hitsCount > 0) {
String indexId = filterList.hits().hits().get(0).id();

List<String> filteredSorList = new ArrayList<String>();
List<String> filteredSorList = new ArrayList<>();
for (JsonNode fieldName : sorQuestionList.get("f2")) {
String questionKey = fieldName.asText();
SearchResponse<Object> filteredQuestionList = elasticsearchClient
Expand All @@ -107,7 +108,7 @@ public void execute() throws Exception {
query.matchPhrase(dd -> dd.field("page_content").query(questionKey))).must(query ->
query.matchPhrase(dd -> dd.field("_id").query(indexId)))
)), Object.class);
long questionHitCount = filteredQuestionList.hits().total().value();
long questionHitCount = Objects.requireNonNull(filteredQuestionList.hits().total()).value();
if (questionHitCount > 0) {
filteredSorList.add(questionKey);
}
Expand All @@ -133,11 +134,11 @@ public void execute() throws Exception {
action.getContext().put(absentKeyFilter.getName() + "_response", absentKeyList.toString());
action.getContext().put(absentKeyFilter.getName().concat(".value"), "true");
}
log.info(aMarker, "<-------Absent Key Filter Action for {} has been completed------->" + absentKeyFilter.getName());
log.info(aMarker, "Absent Key Filter Action for {} has been completed" , absentKeyFilter.getName());
} catch (Exception e) {
action.getContext().put(absentKeyFilter.getName().concat(".error"), "true");
log.info(aMarker, "The Exception occurred ", e);
throw new HandymanException("Failed to execute", e);
log.error(aMarker, "The Exception occurred ", e);
throw new HandymanException("Failed to execute", e, action);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,42 +26,43 @@ public class AlphanumericvalidatorAction implements IActionExecution {
private final Alphanumericvalidator alphanumericvalidator;

private final Marker aMarker;
AdapterInterface aplhaNumericAdapter;
private final AdapterInterface alphaNumericAdapter;


public AlphanumericvalidatorAction(final ActionExecutionAudit action, final Logger log,
final Object alphanumericvalidator) {
this.alphanumericvalidator = (Alphanumericvalidator) alphanumericvalidator;
this.action = action;
this.log = log;
this.aplhaNumericAdapter = new AlphaNumericAdapter();
this.alphaNumericAdapter = new AlphaNumericAdapter();
this.aMarker = MarkerFactory.getMarker(" Alphanumericvalidator:" + this.alphanumericvalidator.getName());
}

int getAlphaNumericScore(Validator adapter) {
try {
boolean validator = aplhaNumericAdapter.getValidationModel(adapter.getInputValue(), adapter.getAllowedSpecialChar());
boolean validator = alphaNumericAdapter.getValidationModel(adapter.getInputValue(), adapter.getAllowedSpecialChar());
return validator ? adapter.getThreshold() : 0;
} catch (Exception ex) {
throw new HandymanException("Failed to execute", ex);
log.error("Exception occurred in getting alpha numeric score", ex);
throw new HandymanException("Exception occurred in getting alpha numeric score", ex, action);
}
}

@Override
public void execute() throws Exception {

try {
log.info(aMarker, "<-------Alpha Numeric Count Action for {} has been started------->" + alphanumericvalidator.getName());
AdapterInterface aplhaNumericAdapter = new AlphaNumericAdapter();
boolean validator = aplhaNumericAdapter.getValidationModel(alphanumericvalidator.getInputValue(), alphanumericvalidator.getAllowedSpecialCharacters());
int confidenceScore = validator ? Integer.valueOf(alphanumericvalidator.getThresholdValue()) : 0;
log.info(aMarker, "Alpha Numeric Count Action for {} has been started" , alphanumericvalidator.getName());
AdapterInterface alphaNumericAdapter = new AlphaNumericAdapter();
boolean validator = alphaNumericAdapter.getValidationModel(alphanumericvalidator.getInputValue(), alphanumericvalidator.getAllowedSpecialCharacters());
int confidenceScore = validator ? Integer.parseInt(alphanumericvalidator.getThresholdValue()) : 0;
action.getContext().put("validator.score", String.valueOf(confidenceScore));
log.info(aMarker, "<-------Alpha Numeric Action for {} has been completed------->" + alphanumericvalidator.getName());
log.info(aMarker, "Alpha Numeric Action for {} has been completed" , alphanumericvalidator.getName());

} catch (Exception ex) {
action.getContext().put(alphanumericvalidator.getName().concat(".error"), "true");
log.info(aMarker, "The Exception occurred ", ex);
throw new HandymanException("Failed to execute", ex);
log.error(aMarker, "Exception occurred in alpha numeric validator action ", ex);
throw new HandymanException("Exception occurred in alpha numeric validator action", ex, action);
}
}

Expand Down
15 changes: 8 additions & 7 deletions src/main/java/in/handyman/raven/lib/AlphavalidatorAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public class AlphavalidatorAction implements IActionExecution {
private final Alphavalidator alphavalidator;

private final Marker aMarker;
AdapterInterface alphaAdapter;
private final AdapterInterface alphaAdapter;

public AlphavalidatorAction(final ActionExecutionAudit action, final Logger log,
final Object alphavalidator) {
Expand All @@ -42,22 +42,23 @@ int getAlphaScore(Validator adapter) {
boolean validator = alphaAdapter.getValidationModel(adapter.getInputValue(), adapter.getAllowedSpecialChar());
return validator ? adapter.getThreshold() : 0;
} catch (Exception ex) {
throw new HandymanException("Failed to execute", ex);
log.error("Exception occurred in getting alpha score", ex);
throw new HandymanException("Exception occurred in getting alpha score", ex, action);
}
}

@Override
public void execute() throws Exception {
try {
log.info(aMarker, "Alpha Count Action for {} has been started" + alphavalidator.getName());
log.info(aMarker, "Alpha Count Action for {} has been started" , alphavalidator.getName());
boolean validator = alphaAdapter.getValidationModel(alphavalidator.getInputValue(), alphavalidator.getAllowedSpecialCharacters());
int confidenceScore = validator ? Integer.valueOf(alphavalidator.getThresholdValue()) : 0;
int confidenceScore = validator ? Integer.parseInt(alphavalidator.getThresholdValue()) : 0;
action.getContext().put("validator.score", String.valueOf(confidenceScore));
log.info(aMarker, "<-------Alpha Count Action for {} has been completed------->" + alphavalidator.getName());
log.info(aMarker, "Alpha Count Action for {} has been completed" , alphavalidator.getName());
} catch (Exception ex) {
action.getContext().put(alphavalidator.getName().concat(".error"), "true");
log.info(aMarker, "The Exception occurred ", ex);
throw new HandymanException("Failed to execute", ex);
log.error(aMarker, "The Exception occurred ", ex);
throw new HandymanException("Failed to execute", ex, action);
}
}

Expand Down
24 changes: 13 additions & 11 deletions src/main/java/in/handyman/raven/lib/AssetInfoAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import in.handyman.raven.lambda.doa.audit.ActionExecutionAudit;
import in.handyman.raven.lib.model.AssetInfo;
import in.handyman.raven.util.CommonQueryUtil;
import in.handyman.raven.util.ExceptionUtil;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
Expand Down Expand Up @@ -62,7 +63,7 @@ public AssetInfoAction(final ActionExecutionAudit action, final Logger log,
@Override
public void execute() throws Exception {
try {
log.info(aMarker, "Asset Info Action for {} has been started" + assetInfo.getName());
log.info(aMarker, "Asset Info Action for {} has been started" , assetInfo.getName());

final Jdbi jdbi = ResourceAccess.rdbmsJDBIConn(assetInfo.getResourceConn());
final List<inputResult> tableInfos = new ArrayList<>();
Expand Down Expand Up @@ -96,8 +97,8 @@ public void execute() throws Exception {
log.info(aMarker, "Iterating each file in directory {}", files);
files.forEach(pathList::add);
} catch (IOException e) {
log.error(aMarker, "error occured in directory iteration {}", e);
throw new RuntimeException(e);
log.error(aMarker, "Exception occurred in directory iteration {}", ExceptionUtil.toString(e));
throw new HandymanException("Exception occurred in directory iteration", e, action);
}
pathList.forEach(path -> {
log.info(aMarker, "insert query for each file from dir {}", path);
Expand All @@ -116,8 +117,8 @@ public void execute() throws Exception {
fileInfos.clear();
log.info(aMarker, "cleared batch {}", fileInfos.size());
}
} catch (Throwable t) {
log.error(aMarker, "error in file info for {}", tableInfo, t);
} catch (Exception e) {
log.error(aMarker, "Error in file info for {}", tableInfo, e);
}
});
if (!fileInfos.isEmpty()) {
Expand All @@ -132,9 +133,9 @@ public void execute() throws Exception {
} catch (Exception e) {
action.getContext().put(assetInfo.getName().concat(".error"), "true");
log.error(aMarker, "The Exception occurred ", e);
throw new HandymanException("Failed to execute", e);
throw new HandymanException("Exception occurred in asset info execute", e, action);
}
log.info(aMarker, "Asset Info Action for {} has been completed" + assetInfo.getName());
log.info(aMarker, "Asset Info Action for {} has been completed" , assetInfo.getName());
}

public FileInfo insertQuery(File file) {
Expand All @@ -145,7 +146,8 @@ public FileInfo insertQuery(File file) {
try (InputStream is = Files.newInputStream(Path.of(file.getPath()))) {
sha1Hex = org.apache.commons.codec.digest.DigestUtils.sha1Hex(is);
} catch (IOException e) {
throw new RuntimeException(e);
log.error("Error in reading input stream {}", ExceptionUtil.toString(e));
throw new HandymanException("Error in reading input stream", e, action);
}
log.info(aMarker, "checksum for file {} and its {}", file, sha1Hex);
var fileSize = file.length() / 1024;
Expand All @@ -161,8 +163,8 @@ public FileInfo insertQuery(File file) {
.build();
log.info(aMarker, "File Info Builder {}", fileInfoBuilder);
} catch (Exception ex){
log.error(aMarker, "error occured in builder {}", ex);
throw new HandymanException("Failed to execute {} ", ex);
log.error(aMarker, "error occurred in builder {}", ExceptionUtil.toString(ex));
throw new HandymanException("Failed to execute {} ", ex, action);
}
return fileInfoBuilder;
}
Expand Down Expand Up @@ -206,7 +208,7 @@ void insertSummaryAudit(final Jdbi jdbi, int rowCount, int executeCount, int err
bindBean.execute();
});
} catch (Throwable t) {
log.error(aMarker, "error inserting into batch insert audit {}", t);
log.error(aMarker, "error inserting into batch insert audit {}", t.toString());
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/main/java/in/handyman/raven/lib/AssignAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public AssignAction(final ActionExecutionAudit actionExecutionAudit, final Logge

@Override
public void execute() throws Exception {
log.info(aMarker, "<-------Assign Action for {} has been started------->" + assign.getName());
log.info(aMarker, "Assign Action for {} has been started" , assign.getName());
final String dbSrc = assign.getSource();
log.info(aMarker, " input variables id: {}, name: {}, source-database: {} ", actionExecutionAudit.getActionId(), assign.getName(), dbSrc);
log.debug(aMarker, "Sql input post parameter ingestion \n {}", assign.getValue());
Expand All @@ -56,10 +56,10 @@ public void execute() throws Exception {
}));
});
});
log.info(aMarker, "<-------Assign Action for {} has been Completed------->" + assign.getName());
log.info(aMarker, "Assign Action for {} has been Completed" , assign.getName());
} catch (Exception e) {
log.error(aMarker, "The Exception occurred ", e);
throw new HandymanException("Failed to execute", e);
throw new HandymanException("Failed to execute", e, actionExecutionAudit);
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/main/java/in/handyman/raven/lib/AuthTokenAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public AuthTokenAction(final ActionExecutionAudit action, final Logger log,

@Override
public void execute() throws Exception {
log.info(aMarker, "<-------Auth Token Generation Action for {} has been started------->" + authToken.getName());
log.info(aMarker, "Auth Token Generation Action for {} has been started" , authToken.getName());
final OkHttpClient httpclient = InstanceUtil.createOkHttpClient();

final ObjectNode objectNode = mapper.createObjectNode();
Expand Down Expand Up @@ -84,9 +84,9 @@ public void execute() throws Exception {
} catch (Exception e) {
log.error(aMarker, "The Exception occurred ", e);
action.getContext().put(name + ".isSuccessful", "false");
throw new HandymanException("Failed to execute", e);
throw new HandymanException("Failed to execute", e, action);
}
log.info(aMarker, "<-------Auth Token Generation Action for {} has been completed------->" + authToken.getName());
log.info(aMarker, "Auth Token Generation Action for {} has been completed" , authToken.getName());

}

Expand Down
Loading

0 comments on commit 2f78e12

Please sign in to comment.