Search in sources :

Example 6 with InsightsJobFailedException

use of com.cognizant.devops.platformreports.exception.InsightsJobFailedException in project Insights by CognizantOneDevOps.

the class ReportKPISubscriber method executeContent.

private void executeContent(List<Integer> contentList, List<JsonObject> failedJobs) throws InterruptedException, ExecutionException {
    List<Callable<Integer>> contentListToExecute = new ArrayList<>();
    ReportPostgresDataHandler contentProcessing = new ReportPostgresDataHandler();
    int assessmentId = workflowConfig.getAssessmentConfig().getId();
    String assessmentReportName = workflowConfig.getAssessmentConfig().getAsseementreportname();
    int reportTemplateId = workflowConfig.getAssessmentConfig().getReportTemplateEntity().getReportId();
    for (int contentId : contentList) {
        InsightsContentConfig contentConfig = contentProcessing.getContentConfig(contentId);
        ContentConfigDefinition contentConfigDefinition = contentProcessing.convertJsonToContentConfig(contentConfig);
        log.debug("Type=TaskExecution  executionId={} workflowId={} ConfigId={} WorkflowType={} KpiId={} Category={} ProcessingTime={} message={}", contentConfigDefinition.getExecutionId(), contentConfigDefinition.getWorkflowId(), contentConfigDefinition.getReportId(), "", contentConfigDefinition.getKpiId(), contentConfigDefinition.getCategory(), 0, "ContentId :" + contentConfigDefinition.getContentId() + "ContentName :" + contentConfigDefinition.getContentName() + "action :" + contentConfigDefinition.getAction() + "ContentResult :" + contentConfigDefinition.getNoOfResult());
        if (contentConfigDefinition != null) {
            contentConfigDefinition.setExecutionId(executionId);
            contentConfigDefinition.setSchedule(WorkflowTaskEnum.WorkflowSchedule.valueOf(workflowConfig.getScheduleType()));
            contentConfigDefinition.setWorkflowId(workflowConfig.getWorkflowId());
            contentConfigDefinition.setReportId(reportTemplateId);
            contentConfigDefinition.setAssessmentId(assessmentId);
            contentConfigDefinition.setAssessmentReportName(assessmentReportName);
            contentListToExecute.add(new ContentExecutor(contentConfigDefinition));
        } else {
            log.error("Type=TaskExecution  executionId={} workflowId={} ConfigId={} WorkflowType={} KpiId={} Category={} ProcessingTime={} message={}", contentConfigDefinition.getExecutionId(), contentConfigDefinition.getWorkflowId(), contentConfigDefinition.getReportId(), "-", contentConfigDefinition.getKpiId(), contentConfigDefinition.getCategory(), 0, "ContentId :" + contentConfigDefinition.getContentId() + "ContentName :" + contentConfigDefinition.getContentName() + "action :" + contentConfigDefinition.getAction() + "ContentResult :" + contentConfigDefinition.getNoOfResult() + " Content execution failed");
            throw new InsightsJobFailedException("Content execution failed");
        }
    }
    /* segregate entire content execution list into defined chunks */
    List<List<Callable<Integer>>> contentChunkList = WorkflowThreadPool.getChunk(contentListToExecute, 3);
    /* submit each chunk to threadpool in a loop */
    executeContentChunks(contentChunkList, failedJobs);
}
Also used : ContentExecutor(com.cognizant.devops.platformreports.assessment.content.ContentExecutor) InsightsContentConfig(com.cognizant.devops.platformdal.assessmentreport.InsightsContentConfig) ReportPostgresDataHandler(com.cognizant.devops.platformreports.assessment.dal.ReportPostgresDataHandler) ArrayList(java.util.ArrayList) Callable(java.util.concurrent.Callable) InsightsJobFailedException(com.cognizant.devops.platformreports.exception.InsightsJobFailedException) ArrayList(java.util.ArrayList) List(java.util.List) ContentConfigDefinition(com.cognizant.devops.platformreports.assessment.datamodel.ContentConfigDefinition)

Example 7 with InsightsJobFailedException

use of com.cognizant.devops.platformreports.exception.InsightsJobFailedException in project Insights by CognizantOneDevOps.

the class ReportKPISubscriber method updateFailedTaskStatusLog.

private void updateFailedTaskStatusLog(List<JsonObject> failedJobs) throws InterruptedException, ExecutionException {
    JsonObject statusObject = new JsonObject();
    JsonArray kpiArray = new JsonArray();
    JsonArray contentArray = new JsonArray();
    for (JsonObject failedJob : failedJobs) {
        // JsonObject payload = failedJob
        if (failedJob.has("kpiArray")) {
            failedJob.get("kpiArray").getAsJsonArray().forEach(id -> kpiArray.add(id));
        } else if (failedJob.has(AssessmentReportAndWorkflowConstants.CONTENT_ARRAY)) {
            failedJob.get(AssessmentReportAndWorkflowConstants.CONTENT_ARRAY).getAsJsonArray().forEach(id -> contentArray.add(id));
        }
    }
    statusObject.addProperty("executionId", executionId);
    statusObject.addProperty("workflowId", workflowConfig.getWorkflowId());
    statusObject.add("kpiList", kpiArray);
    statusObject.add(AssessmentReportAndWorkflowConstants.CONTENT_ARRAY, contentArray);
    // statusLog set here which is class variable of WorkflowTaskSubscriberHandler
    statusLog = new Gson().toJson(statusObject);
    log.error("Type=TaskExecution  executionId={} workflowId={} ConfigId={} WorkflowType={} KpiId={} Category={} ProcessingTime={} message={}", executionId, workflowConfig.getWorkflowId(), "-", workflowConfig.getWorkflowType(), "-", "-", 0, "statusLog: " + statusLog);
    throw new InsightsJobFailedException("some of the Kpi's or Contents failed to execute");
}
Also used : JsonArray(com.google.gson.JsonArray) JsonObject(com.google.gson.JsonObject) InsightsContentConfig(com.cognizant.devops.platformdal.assessmentreport.InsightsContentConfig) InsightsWorkflowConfiguration(com.cognizant.devops.platformdal.workflow.InsightsWorkflowConfiguration) TypeToken(com.google.gson.reflect.TypeToken) InsightsWorkflowExecutionHistory(com.cognizant.devops.platformdal.workflow.InsightsWorkflowExecutionHistory) ContentConfigDefinition(com.cognizant.devops.platformreports.assessment.datamodel.ContentConfigDefinition) Callable(java.util.concurrent.Callable) JsonUtils(com.cognizant.devops.platformcommons.core.util.JsonUtils) ArrayList(java.util.ArrayList) WorkflowThreadPool(com.cognizant.devops.platformworkflow.workflowthread.core.WorkflowThreadPool) InsightsJobFailedException(com.cognizant.devops.platformreports.exception.InsightsJobFailedException) Future(java.util.concurrent.Future) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) ContentExecutor(com.cognizant.devops.platformreports.assessment.content.ContentExecutor) Gson(com.google.gson.Gson) WorkflowUtils(com.cognizant.devops.platformworkflow.workflowtask.utils.WorkflowUtils) InsightsKPIConfig(com.cognizant.devops.platformdal.assessmentreport.InsightsKPIConfig) ReportConfigDAL(com.cognizant.devops.platformdal.assessmentreport.ReportConfigDAL) InsightsStatusProvider(com.cognizant.devops.platformworkflow.workflowtask.core.InsightsStatusProvider) InsightsReportsKPIConfig(com.cognizant.devops.platformdal.assessmentreport.InsightsReportsKPIConfig) Set(java.util.Set) IOException(java.io.IOException) WorkflowTaskSubscriberHandler(com.cognizant.devops.platformworkflow.workflowtask.message.factory.WorkflowTaskSubscriberHandler) InsightsKPIConfigDTO(com.cognizant.devops.platformreports.assessment.datamodel.InsightsKPIConfigDTO) ReportPostgresDataHandler(com.cognizant.devops.platformreports.assessment.dal.ReportPostgresDataHandler) WorkflowDAL(com.cognizant.devops.platformdal.workflow.WorkflowDAL) KPIExecutor(com.cognizant.devops.platformreports.assessment.kpi.KPIExecutor) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) List(java.util.List) AssessmentReportAndWorkflowConstants(com.cognizant.devops.platformcommons.constants.AssessmentReportAndWorkflowConstants) PlatformServiceConstants(com.cognizant.devops.platformcommons.constants.PlatformServiceConstants) JsonArray(com.google.gson.JsonArray) Logger(org.apache.logging.log4j.Logger) MQMessageConstants(com.cognizant.devops.platformworkflow.workflowtask.utils.MQMessageConstants) Type(java.lang.reflect.Type) WorkflowTaskEnum(com.cognizant.devops.platformcommons.core.enums.WorkflowTaskEnum) LogManager(org.apache.logging.log4j.LogManager) InsightsJobFailedException(com.cognizant.devops.platformreports.exception.InsightsJobFailedException) JsonObject(com.google.gson.JsonObject) Gson(com.google.gson.Gson)

Example 8 with InsightsJobFailedException

use of com.cognizant.devops.platformreports.exception.InsightsJobFailedException in project Insights by CognizantOneDevOps.

the class SystemNotificationDetailSubscriber method setDetailsInEmailHistory.

/**
 * Method to save Email details in Email History table
 *
 * @param incomingTaskMessageJson
 * @param mailBody
 */
private void setDetailsInEmailHistory(JsonObject incomingTaskMessageJson, String mailBody) {
    try {
        InsightsReportVisualizationContainer emailHistoryConfig = new InsightsReportVisualizationContainer();
        emailHistoryConfig.setExecutionId(incomingTaskMessageJson.get("executionId").getAsLong());
        emailHistoryConfig.setStatus(WorkflowTaskEnum.EmailStatus.NOT_STARTED.name());
        emailHistoryConfig.setWorkflowConfig(incomingTaskMessageJson.get("workflowId").getAsString());
        emailHistoryConfig.setMailBody(mailBody);
        emailHistoryConfig.setMailAttachmentName("");
        workflowDAL.saveEmailExecutionHistory(emailHistoryConfig);
    } catch (Exception e) {
        log.error("Worlflow Detail ==== Error setting Email details in Email History table");
        throw new InsightsJobFailedException("Worlflow Detail ==== Error setting Email details in Email History table");
    }
}
Also used : InsightsJobFailedException(com.cognizant.devops.platformreports.exception.InsightsJobFailedException) InsightsReportVisualizationContainer(com.cognizant.devops.platformdal.assessmentreport.InsightsReportVisualizationContainer) InsightsJobFailedException(com.cognizant.devops.platformreports.exception.InsightsJobFailedException) IOException(java.io.IOException)

Example 9 with InsightsJobFailedException

use of com.cognizant.devops.platformreports.exception.InsightsJobFailedException in project Insights by CognizantOneDevOps.

the class SystemNotificationDetailSubscriber method handleTaskExecution.

@Override
public void handleTaskExecution(byte[] body) throws IOException {
    try {
        long startTime = System.nanoTime();
        String incomingTaskMessage = new String(body, StandardCharsets.UTF_8);
        JsonObject incomingTaskMessageJson = JsonUtils.parseStringAsJsonObject(incomingTaskMessage);
        String workflowId = incomingTaskMessageJson.get("workflowId").getAsString();
        executionId = incomingTaskMessageJson.get("executionId").getAsLong();
        workflowConfig = workflowDAL.getWorkflowConfigByWorkflowId(workflowId);
        String htmlDataComponentResponseBuffer = componentHTML(healthUtil.getDataComponentStatus(), "Data Component");
        String htmlServiceResponseBuffer = componentHTML(healthUtil.getServiceStatus(), "Services");
        String htmlAgentResponseBuffer = getAgentHTML();
        Map<String, String> idDataMap = new LinkedHashMap<>();
        idDataMap.put("table_agent", htmlAgentResponseBuffer);
        idDataMap.put("table_services", htmlServiceResponseBuffer);
        idDataMap.put("table_data_components", htmlDataComponentResponseBuffer);
        String mailHTML = createEmailHTML(idDataMap);
        Map<String, String> valuesMap = new HashMap<>();
        valuesMap.put("date", InsightsUtils.specficTimeFormat(incomingTaskMessageJson.get("executionId").getAsLong(), "yyyy-MM-dd"));
        StringSubstitutor sub = new StringSubstitutor(valuesMap, "{", "}");
        mailHTML = sub.replace(mailHTML);
        setDetailsInEmailHistory(incomingTaskMessageJson, mailHTML);
        InsightsStatusProvider.getInstance().createInsightStatusNode("SystemNotificationDetailSubscriber completed", PlatformServiceConstants.SUCCESS);
        long processingTime = TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - startTime);
        log.debug("Type=TaskExecution  executionId={} workflowId={} ConfigId={} WorkflowType={} KpiId={} Category={} ProcessingTime={} message={}", executionId, workflowConfig.getWorkflowId(), "-", workflowConfig.getWorkflowType(), "-", "-", processingTime, "-");
    } catch (InsightsJobFailedException ijfe) {
        log.error("Worlflow Detail ==== SystemNotificationDetail Subscriber Completed with error ", ijfe);
        InsightsStatusProvider.getInstance().createInsightStatusNode("SystemNotificationDetail Completed with error " + ijfe.getMessage(), PlatformServiceConstants.FAILURE);
        log.error("Type=TaskExecution  executionId={} workflowId={} ConfigId={} WorkflowType={} KpiId={} Category={} ProcessingTime={} message={}", executionId, workflowConfig.getWorkflowId(), "-", workflowConfig.getWorkflowType(), "-", "-", 0, workflowConfig.getStatus() + "SystemNotificationDetail Subscriber Completed with error" + ijfe.getMessage());
        statusLog = ijfe.getMessage();
        throw ijfe;
    } catch (Exception e) {
        log.error("Worlflow Detail ==== SystemNotificationDetail Subscriber Completed with error ", e);
        InsightsStatusProvider.getInstance().createInsightStatusNode("SystemNotificationDetail Completed with error " + e.getMessage(), PlatformServiceConstants.FAILURE);
        log.error("Type=TaskExecution  executionId={} workflowId={} ConfigId={} WorkflowType={} KpiId={} Category={} ProcessingTime={} message={}", executionId, workflowConfig.getWorkflowId(), "-", workflowConfig.getWorkflowType(), "-", "-", 0, workflowConfig.getStatus() + "SystemNotificationDetail Subscriber Completed with error" + e.getMessage());
        throw new InsightsJobFailedException(e.getMessage());
    }
}
Also used : InsightsJobFailedException(com.cognizant.devops.platformreports.exception.InsightsJobFailedException) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) StringSubstitutor(org.apache.commons.text.StringSubstitutor) JsonObject(com.google.gson.JsonObject) InsightsJobFailedException(com.cognizant.devops.platformreports.exception.InsightsJobFailedException) IOException(java.io.IOException) LinkedHashMap(java.util.LinkedHashMap)

Example 10 with InsightsJobFailedException

use of com.cognizant.devops.platformreports.exception.InsightsJobFailedException in project Insights by CognizantOneDevOps.

the class AssessmentReportContentProcesser method executeContentData.

/**
 * Used to process content based on KPI Result, It either fetch record from DB
 * or from file Make a method to directly process content in case any kpi is
 * successful but their any content is failed so we in such cases we need to run
 * content only.
 */
public void executeContentData(ContentConfigDefinition inferenceContentConfigDefinition) {
    try {
        long startTime = System.nanoTime();
        BaseContentCategoryImpl baseContentAction;
        if (inferenceContentConfigDefinition.getCategory() == ReportEngineEnum.ContentCategory.COMPARISON || inferenceContentConfigDefinition.getCategory() == ReportEngineEnum.ContentCategory.STANDARD) {
            baseContentAction = new ComparisonContentCategoryImpl(inferenceContentConfigDefinition);
        } else if (inferenceContentConfigDefinition.getCategory() == ReportEngineEnum.ContentCategory.THRESHOLD) {
            baseContentAction = new ThresholdContentCategoryImpl(inferenceContentConfigDefinition);
        } else if (inferenceContentConfigDefinition.getCategory() == ReportEngineEnum.ContentCategory.THRESHOLD_RANGE) {
            baseContentAction = new ThresholdRangeCategoryImpl(inferenceContentConfigDefinition);
        } else if (inferenceContentConfigDefinition.getCategory() == ReportEngineEnum.ContentCategory.MINMAX) {
            baseContentAction = new MinMaxCategoryImpl(inferenceContentConfigDefinition);
        } else if (inferenceContentConfigDefinition.getCategory() == ReportEngineEnum.ContentCategory.TREND) {
            baseContentAction = new TrendCategoryImpl(inferenceContentConfigDefinition);
        } else {
            log.error("Worlflow Detail ====  No content category executer defined for contentId {}", inferenceContentConfigDefinition.getContentId());
            throw new InsightsJobFailedException("Worlflow Detail ====  No content category executer defined");
        }
        baseContentAction.generateContent();
        long processingTime = TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - startTime);
        log.debug("Type=TaskExecution  executionId={} workflowId={} ConfigId={} WorkflowType={} KpiId={} Category={} ProcessingTime={} message={}", inferenceContentConfigDefinition.getExecutionId(), inferenceContentConfigDefinition.getWorkflowId(), inferenceContentConfigDefinition.getReportId(), "-", inferenceContentConfigDefinition.getKpiId(), inferenceContentConfigDefinition.getCategory(), processingTime, " ContentId :" + inferenceContentConfigDefinition.getContentId() + " ContentName :" + inferenceContentConfigDefinition.getContentName() + " action :" + inferenceContentConfigDefinition.getAction() + " ContentResult :" + inferenceContentConfigDefinition.getNoOfResult());
    } catch (InsightsJobFailedException e) {
        log.error("Worlflow Detail ====  Exception while execution content Id %d KPI Id {} exception {} ", inferenceContentConfigDefinition.getContentId(), inferenceContentConfigDefinition.getKpiId(), e);
        log.error("Type=TaskExecution  executionId={} workflowId={} ConfigId={} WorkflowType={} KpiId={} Category={} ProcessingTime={} message={}", inferenceContentConfigDefinition.getExecutionId(), inferenceContentConfigDefinition.getWorkflowId(), inferenceContentConfigDefinition.getReportId(), "-", inferenceContentConfigDefinition.getKpiId(), inferenceContentConfigDefinition.getCategory(), 0, "ContentId :" + inferenceContentConfigDefinition.getContentId() + "ContentName :" + inferenceContentConfigDefinition.getContentName() + "action :" + inferenceContentConfigDefinition.getAction() + "ContentResult :" + inferenceContentConfigDefinition.getNoOfResult() + "Exception while execution content Id " + e.getMessage());
        throw new InsightsJobFailedException("Exception while execution content Id");
    }
}
Also used : InsightsJobFailedException(com.cognizant.devops.platformreports.exception.InsightsJobFailedException)

Aggregations

InsightsJobFailedException (com.cognizant.devops.platformreports.exception.InsightsJobFailedException)63 IOException (java.io.IOException)31 JsonObject (com.google.gson.JsonObject)29 InsightsCustomException (com.cognizant.devops.platformcommons.exception.InsightsCustomException)21 ArrayList (java.util.ArrayList)16 File (java.io.File)14 JsonArray (com.google.gson.JsonArray)12 HashMap (java.util.HashMap)11 InsightsKPIResultDetails (com.cognizant.devops.platformreports.assessment.datamodel.InsightsKPIResultDetails)8 List (java.util.List)8 InsightsContentDetail (com.cognizant.devops.platformreports.assessment.datamodel.InsightsContentDetail)7 ReportEngineEnum (com.cognizant.devops.platformreports.assessment.util.ReportEngineEnum)7 ExecutionException (java.util.concurrent.ExecutionException)7 ContentConfigDefinition (com.cognizant.devops.platformreports.assessment.datamodel.ContentConfigDefinition)6 InsightsAssessmentConfigurationDTO (com.cognizant.devops.platformreports.assessment.datamodel.InsightsAssessmentConfigurationDTO)5 FileNotFoundException (java.io.FileNotFoundException)5 NoSuchFileException (java.nio.file.NoSuchFileException)5 Map (java.util.Map)5 InsightsContentConfig (com.cognizant.devops.platformdal.assessmentreport.InsightsContentConfig)4 InsightsReportVisualizationContainer (com.cognizant.devops.platformdal.assessmentreport.InsightsReportVisualizationContainer)4