use of com.cognizant.devops.platformreports.exception.InsightsJobFailedException in project Insights by CognizantOneDevOps.
the class AutoMLSubscriber method handleTaskExecution.
@Override
public void handleTaskExecution(byte[] body) throws IOException {
List<JsonObject> failedJobs = new ArrayList<>();
long startTime = System.nanoTime();
try {
String message = new String(body, StandardCharsets.UTF_8);
JsonObject incomingTaskMessage = JsonUtils.parseStringAsJsonObject(message);
String workflowId = incomingTaskMessage.get("workflowId").getAsString();
executionId = incomingTaskMessage.get("executionId").getAsLong();
workflowConfig = workflowDAL.getWorkflowConfigByWorkflowId(workflowId);
autoMlConfig = autoMlDAL.fetchUseCasesByWorkflowId(workflowId);
if (autoMlConfig != null) {
autoMlConfig.setStatus(AutoMLEnum.Status.IN_PROGRESS.name());
autoMlDAL.updateMLConfig(autoMlConfig);
List<Callable<JsonObject>> mlTaskToExecute = new ArrayList<>();
AutoMLExecutor autoMLExecutor = new AutoMLExecutor(autoMlConfig);
mlTaskToExecute.add(autoMLExecutor);
/* segregate entire automl execution list into defined chunks */
List<List<Callable<JsonObject>>> kpiChunkList = WorkflowThreadPool.getChunk(mlTaskToExecute, 1);
log.debug("Type=TaskExecution executionId={} workflowId={} ConfigId={} WorkflowType={} KpiId={} Category={} ProcessingTime={} message={}", executionId, autoMlConfig.getWorkflowConfig().getWorkflowId(), "-", autoMlConfig.getWorkflowConfig().getWorkflowType(), "-", "-", 0, " ModelId :" + autoMlConfig.getModelId() + " UsecaseName :" + autoMlConfig.getUseCaseName() + " PredictionColumn : " + autoMlConfig.getPredictionColumn() + " PredictionType :" + autoMlConfig.getPredictionType() + " TrainingPercentage : " + autoMlConfig.getTrainingPerc() + " status : " + autoMlConfig.getStatus());
/* submit each chunk to threadpool in a loop */
executeAutoMLChunks(kpiChunkList, failedJobs);
if (!failedJobs.isEmpty()) {
updateFailedTaskStatusLog(failedJobs);
}
}
} catch (InsightsJobFailedException e) {
log.error("Worlflow Detail ==== InsightsJobFailedException ==== ", e);
log.error("Type=TaskExecution executionId={} workflowId={} ConfigId={} WorkflowType={} KpiId={} Category={} ProcessingTime={} message={}", executionId, autoMlConfig.getWorkflowConfig().getWorkflowId(), "-", autoMlConfig.getWorkflowConfig().getWorkflowType(), "-", "-", 0, "ModelId :" + autoMlConfig.getModelId() + " UsecaseName :" + autoMlConfig.getUseCaseName() + " PredictionColumn : " + autoMlConfig.getPredictionColumn() + "predictionType :" + autoMlConfig.getPredictionType() + "trainingPercentage : " + autoMlConfig.getTrainingPerc() + "status : " + autoMlConfig.getStatus() + "Auto ML task failed to execute" + e.getMessage());
throw new InsightsJobFailedException("Auto ML task failed to execute " + e.getMessage());
} catch (Exception e) {
JsonObject response = new JsonObject();
response.addProperty("Status", "Failure");
response.addProperty("errorLog", e.getMessage());
failedJobs.add(response);
updateFailedTaskStatusLog(failedJobs);
log.error("Type=TaskExecution executionId={} workflowId={} ConfigId={} WorkflowType={} KpiId={} Category={} ProcessingTime={} message={}", executionId, autoMlConfig.getWorkflowConfig().getWorkflowId(), "-", autoMlConfig.getWorkflowConfig().getWorkflowType(), "-", "-", 0, "ModelId :" + autoMlConfig.getModelId() + "UsecaseName :" + autoMlConfig.getUseCaseName() + "PredictionColumn : " + autoMlConfig.getPredictionColumn() + "predictionType :" + autoMlConfig.getPredictionType() + "trainingPercentage : " + autoMlConfig.getTrainingPerc() + "status : " + autoMlConfig.getStatus() + e.getMessage());
}
long processingTime = TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - startTime);
log.debug("Worlflow Detail ==== AutoML task completed successfully.");
log.debug("Type=TaskExecution executionId={} workflowId={} ConfigId={} WorkflowType={} KpiId={} Category={} ProcessingTime={} message={}", executionId, autoMlConfig.getWorkflowConfig().getWorkflowId(), "-", autoMlConfig.getWorkflowConfig().getWorkflowType(), "-", "-", processingTime, "ModelId :" + autoMlConfig.getModelId() + "UsecaseName :" + autoMlConfig.getUseCaseName() + "PredictionColumn : " + autoMlConfig.getPredictionColumn() + "predictionType :" + autoMlConfig.getPredictionType() + "trainingPercentage : " + autoMlConfig.getTrainingPerc() + "status : " + autoMlConfig.getStatus() + " AutoML task completed successfully.");
}
use of com.cognizant.devops.platformreports.exception.InsightsJobFailedException in project Insights by CognizantOneDevOps.
the class ReportEmailSubscriber method handleTaskExecution.
@Override
public void handleTaskExecution(byte[] body) throws IOException {
String message = new String(body, MQMessageConstants.MESSAGE_ENCODING);
JsonObject statusObject = null;
JsonObject incomingTaskMessage = JsonUtils.parseStringAsJsonObject(message);
try {
long startTime = System.nanoTime();
log.debug("Workflow Detail ==== ReportEmailSubscriber routing key message handleDelivery {} ===== ", message);
InsightsEmailTemplates emailTemplate = workflowDAL.getEmailTemplateByWorkflowId(incomingTaskMessage.get(AssessmentReportAndWorkflowConstants.WORKFLOW_ID).getAsString());
if (emailTemplate != null) {
mailReportDTO = updateEmailHistoryWithEmailTemplateValues(incomingTaskMessage, emailTemplate);
List<JsonObject> failedJobs = new ArrayList<>();
List<JsonObject> successJobs = new ArrayList<>();
List<Callable<JsonObject>> emailListToExecute = new ArrayList<>();
EmailProcesser emailProcesser = new EmailProcesser(mailReportDTO);
emailListToExecute.add(emailProcesser);
/* segregate entire email execution list into defined chunks */
List<List<Callable<JsonObject>>> emailChunkList = WorkflowThreadPool.getChunk(emailListToExecute, 1);
/* submit each chunk to threadpool in a loop */
executeEmailChunks(emailChunkList, failedJobs, successJobs);
if (!successJobs.isEmpty()) {
updateEmailHistoryWithStatus(incomingTaskMessage.get(AssessmentReportAndWorkflowConstants.EXECUTIONID).getAsLong(), WorkflowTaskEnum.EmailStatus.COMPLETED.name());
InsightsStatusProvider.getInstance().createInsightStatusNode("ReportEmailSubscriberEmail Completed ", PlatformServiceConstants.SUCCESS);
}
if (!failedJobs.isEmpty()) {
statusObject = updateFailedTaskStatusLog(failedJobs);
throw new InsightsJobFailedException("Unable to send an email");
}
long processingTime = TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - startTime);
log.debug("Type=EmailExecution executionId={} workflowId={} ReportName={} mailto={} mailFrom={} ProcessingTime={} message={}", executionId, workflowId, "-", mailReportDTO.getMailTo(), mailReportDTO.getMailFrom(), processingTime, " AttachmentName: " + mailReportDTO.getEmailAttachmentName());
} else {
throw new InsightsJobFailedException("Email template not found!");
}
} catch (InsightsJobFailedException e) {
log.error("Workflow Detail ==== ReportEmailSubscriberEmail Send failed to execute Exception ===== ", e);
updateEmailHistoryWithStatus(incomingTaskMessage.get(AssessmentReportAndWorkflowConstants.EXECUTIONID).getAsLong(), WorkflowTaskEnum.EmailStatus.ERROR.name());
InsightsStatusProvider.getInstance().createInsightStatusNode("ReportEmailSubscriberEmail Completed with error " + e.getMessage(), PlatformServiceConstants.FAILURE);
if (statusObject != null) {
setStatusLog(new Gson().toJson(statusObject));
} else {
setStatusLog(e.getMessage());
}
log.error("Type=EmailExecution executionId={} workflowId={} ReportName={} mailto={} mailFrom={} ProcessingTime={} message={}", executionId, workflowId, "-", mailReportDTO.getMailTo(), mailReportDTO.getMailFrom(), 0, " AttachmentName :" + mailReportDTO.getEmailAttachmentName() + "Failed to send email in ReportEmailSubscriber" + e.getMessage());
throw new InsightsJobFailedException("Failed to send email in ReportEmailSubscriber");
} catch (Exception e) {
log.error("Workflow Detail ==== ReportEmailSubscriberEmail Send failed to execute Exception ===== ", e);
InsightsStatusProvider.getInstance().createInsightStatusNode("ReportEmailSubscriberEmail Completed with error " + e.getMessage(), PlatformServiceConstants.FAILURE);
log.error("Type=EmailExecution executionId={} workflowId={} ReportName={} mailto={} mailFrom={} ProcessingTime={} message={}", executionId, workflowId, "-", mailReportDTO.getMailTo(), mailReportDTO.getMailFrom(), 0, " AttachmentName :" + mailReportDTO.getEmailAttachmentName() + " ReportEmailSubscriberEmail Send failed to execute Exception " + e.getMessage());
}
}
use of com.cognizant.devops.platformreports.exception.InsightsJobFailedException in project Insights by CognizantOneDevOps.
the class ReportEmailSubscriber method collectInfoFromDataBase.
public MailReport collectInfoFromDataBase(JsonObject incomingTaskMessage, InsightsReportVisualizationContainer emailHistory) {
try {
List<InternetAddress> recipientCCAddress = null;
List<InternetAddress> recipientBCCAddress = null;
List<InternetAddress> recipientAddress = null;
InsightsWorkflowConfiguration workflowConfig;
workflowId = incomingTaskMessage.get(AssessmentReportAndWorkflowConstants.WORKFLOW_ID).getAsString();
executionId = incomingTaskMessage.get(AssessmentReportAndWorkflowConstants.EXECUTIONID).getAsLong();
mailReportDTO.setTimeOfReportGeneration(InsightsUtils.insightsTimeXFormat(executionId));
workflowConfig = workflowDAL.getWorkflowConfigByWorkflowId(workflowId);
mailReportDTO.setEmailAttachmentName(emailHistory.getMailAttachmentName());
if (emailHistory.getMailTo() != null) {
String[] recipientList = emailHistory.getMailTo().split(",");
recipientAddress = createRecipientAddress(recipientList);
}
if (emailHistory.getMailCC() != null) {
String[] recipientCCList = emailHistory.getMailCC().split(",");
recipientCCAddress = createRecipientAddress(recipientCCList);
}
if (emailHistory.getMailBCC() != null) {
String[] recipientBCCList = emailHistory.getMailBCC().split(",");
recipientBCCAddress = createRecipientAddress(recipientBCCList);
}
mailReportDTO.setMailTo(recipientAddress);
mailReportDTO.setMailCC(recipientCCAddress);
mailReportDTO.setMailBCC(recipientBCCAddress);
mailReportDTO.setMailFrom(emailHistory.getMailFrom());
mailReportDTO.setSubject(emailHistory.getSubject());
mailReportDTO.setMailBody(emailHistory.getMailBody());
mailReportDTO.setMailAttachment(emailHistory.getAttachmentData());
return mailReportDTO;
} catch (Exception e) {
log.error("Workflow Detail ==== ReportEmailSubscriber Error while creating MailreportDTO ===== ", e);
throw new InsightsJobFailedException("Error while creating MailreportDTO");
}
}
use of com.cognizant.devops.platformreports.exception.InsightsJobFailedException in project Insights by CognizantOneDevOps.
the class ReportEmailSubscriber method updateEmailHistoryWithEmailTemplateValues.
/**
* Method to update values in Email History table
*
* @param incomingTaskMessage
* @param emailTemplate
* @return
*/
private MailReport updateEmailHistoryWithEmailTemplateValues(JsonObject incomingTaskMessage, InsightsEmailTemplates emailTemplate) {
try {
workflowId = incomingTaskMessage.get(AssessmentReportAndWorkflowConstants.WORKFLOW_ID).getAsString();
executionId = incomingTaskMessage.get(AssessmentReportAndWorkflowConstants.EXECUTIONID).getAsLong();
InsightsWorkflowConfiguration workflowConfig = workflowDAL.getWorkflowConfigByWorkflowId(workflowId);
Map<String, String> valuesMap = new HashMap<>();
if (workflowConfig.getAssessmentConfig() != null) {
valuesMap.put("ReportDisplayName", workflowConfig.getAssessmentConfig().getAsseementReportDisplayName());
}
valuesMap.put("TimeOfReportGeneration", InsightsUtils.specficTimeFormat(executionId, "yyyy-MM-dd"));
valuesMap.put("Schedule", workflowConfig.getScheduleType());
StringSubstitutor sub = new StringSubstitutor(valuesMap, "{", "}");
InsightsReportVisualizationContainer emailHistoryConfig = workflowDAL.getEmailExecutionHistoryByExecutionId(incomingTaskMessage.get(AssessmentReportAndWorkflowConstants.EXECUTIONID).getAsLong());
if (emailHistoryConfig != null) {
emailHistoryConfig.setMailFrom(emailTemplate.getMailFrom());
emailHistoryConfig.setMailTo(emailTemplate.getMailTo());
emailHistoryConfig.setMailCC(emailTemplate.getMailCC());
emailHistoryConfig.setMailBCC(emailTemplate.getMailBCC());
if (emailHistoryConfig.getMailBody() == null) {
emailHistoryConfig.setMailBody(sub.replace(emailTemplate.getMailBody()));
}
emailHistoryConfig.setSubject(sub.replace(emailTemplate.getSubject()));
emailHistoryConfig.setStatus(WorkflowTaskEnum.EmailStatus.IN_PROGRESS.toString());
emailHistoryConfig.setMailId(emailTemplate.getId());
workflowDAL.updateEmailExecutionHistory(emailHistoryConfig);
return collectInfoFromDataBase(incomingTaskMessage, emailHistoryConfig);
} else {
throw new InsightsJobFailedException("No record found in Email History table");
}
} catch (InsightsJobFailedException e) {
throw new InsightsJobFailedException(e.getMessage());
} catch (Exception e) {
log.error("Workflow Detail ==== ReportEmailSubscriber Incorrect email format found ===== ", e);
throw new InsightsJobFailedException("Error while updating values to Email History ");
}
}
use of com.cognizant.devops.platformreports.exception.InsightsJobFailedException in project Insights by CognizantOneDevOps.
the class ReportKPISubscriber method handleTaskExecution.
@Override
public void handleTaskExecution(byte[] body) throws IOException {
try {
long startTime = System.nanoTime();
List<JsonObject> failedJobs = new ArrayList<>();
List<InsightsKPIConfig> kpiConfigList = new ArrayList<>();
List<Integer> contentList = new ArrayList<>();
String message = new String(body, MQMessageConstants.MESSAGE_ENCODING);
log.debug("Worlflow Detail ==== ReportKPISubscriber routing key message handleDelivery ===== {} ", message);
JsonObject incomingTaskMessage = JsonUtils.parseStringAsJsonObject(message);
String workflowId = incomingTaskMessage.get("workflowId").getAsString();
executionId = incomingTaskMessage.get("executionId").getAsLong();
workflowConfig = workflowDAL.getWorkflowConfigByWorkflowId(workflowId);
/* kpi and content list */
boolean isWorkflowTaskRetry = incomingTaskMessage.get(WorkflowUtils.RETRY_JSON_PROPERTY).getAsBoolean();
if (isWorkflowTaskRetry) {
/* fill failed kpis and content for execution */
extractKPIAndContentRetryList(incomingTaskMessage, kpiConfigList, contentList);
/* execute content */
executeContent(contentList, failedJobs);
} else {
Set<InsightsReportsKPIConfig> reportsKPIConfigSet = workflowConfig.getAssessmentConfig().getReportTemplateEntity().getReportsKPIConfig();
reportsKPIConfigSet.forEach(reportKpi -> kpiConfigList.add(reportKpi.getKpiConfig()));
}
/* Execute Kpi */
log.debug("Worlflow Detail ==== ReportKPISubscriber before executeKPI ", kpiConfigList.size());
executeKPI(kpiConfigList, failedJobs);
if (!failedJobs.isEmpty()) {
updateFailedTaskStatusLog(failedJobs);
}
long processingTime = TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - startTime);
log.debug("Type=TaskExecution executionId={} workflowId={} ConfigId={} WorkflowType={} KpiId={} Category={} ProcessingTime={} message={}", executionId, workflowId, workflowConfig.getAssessmentConfig().getId(), workflowConfig.getWorkflowType(), "-", "-", processingTime, "usecasename: " + "-" + " schedule: " + workflowConfig.getScheduleType());
} catch (InsightsJobFailedException e) {
log.error("Worlflow Detail ==== InsightsJobFailedException ==== ", e);
InsightsStatusProvider.getInstance().createInsightStatusNode("ReportKPI subscriber exception... " + e.getMessage(), PlatformServiceConstants.FAILURE);
log.error("Type=TaskExecution executionId={} workflowId={} ConfigId={} WorkflowType={} KpiId={} Category={} ProcessingTime={} message={}", executionId, "-", "-", "-", "-", "-", 0, "Exception: " + e.getMessage());
throw new InsightsJobFailedException("Some of the Kpi's or Contents failed to execute " + e.getMessage());
} catch (RejectedExecutionException e) {
log.error("Worlflow Detail ==== RejectedExecutionException ==== ", e);
InsightsStatusProvider.getInstance().createInsightStatusNode("ReportKPI subscriber exception " + e.getMessage(), PlatformServiceConstants.FAILURE);
log.error("Type=TaskExecution executionId={} workflowId={} ConfigId={} WorkflowType={} KpiId={} Category={} ProcessingTime={} message={}", executionId, "-", "-", "-", "-", "-", 0, "Exception:RejectedExecutionException " + e.getMessage());
throw new InsightsJobFailedException("some of the Kpi's or Contents failed to execute RejectedExecutionException " + e.getMessage());
} catch (Exception e) {
log.error("Worlflow Detail ==== handleTaskExecution ==== ", e);
InsightsStatusProvider.getInstance().createInsightStatusNode("ReportKPI subscriber exception " + e.getMessage(), PlatformServiceConstants.FAILURE);
log.error("Type=TaskExecution executionId={} workflowId={} ConfigId={} WorkflowType={} KpiId={} Category={} ProcessingTime={} message={}", executionId, "-", "-", "-", "-", "-", 0, "Exception:ReportKPI subscriber exception" + e.getMessage());
throw new InsightsJobFailedException("some of the Kpi's or Contents failed to execute Exception " + e.getMessage());
}
log.debug("Worlflow Detail ==== ReportKPISubscriber completed ");
InsightsStatusProvider.getInstance().createInsightStatusNode("ReportKPISubscriber completed", PlatformServiceConstants.SUCCESS);
}
Aggregations