Search in sources :

Example 56 with InsightsJobFailedException

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

the class ThresholdContentCategoryImpl method averageInferenceResult.

/**
 * Process KPI result to create content text using average method
 *
 * @param inferenceResults
 * @return
 */
private InsightsContentDetail averageInferenceResult(List<InsightsKPIResultDetails> inferenceResults) {
    long startTime = System.nanoTime();
    Map<String, Object> resultValuesMap = new HashMap<>();
    InsightsContentDetail inferenceContentResult = null;
    String comparisonField = getResultFieldFromContentDefination();
    InsightsKPIResultDetails resultDetailObj = inferenceResults.get(0);
    try {
        ReportEngineEnum.KPISentiment sentiment = ReportEngineEnum.KPISentiment.NEUTRAL;
        String actaulDirection = "Neutral";
        Double avgValue = inferenceResults.stream().mapToDouble((result -> (Double) result.getResults().get(comparisonField))).average().getAsDouble();
        if (getContentConfig().getDirectionOfThreshold() == ReportEngineEnum.DirectionOfThreshold.BELOW) {
            actaulDirection = (avgValue < getContentConfig().getThreshold()) ? AssessmentReportAndWorkflowConstants.BELOW : AssessmentReportAndWorkflowConstants.ABOVE;
        } else {
            actaulDirection = (avgValue > getContentConfig().getThreshold()) ? AssessmentReportAndWorkflowConstants.ABOVE : AssessmentReportAndWorkflowConstants.BELOW;
        }
        sentiment = getContentConfig().getDirectionOfThreshold().name().equalsIgnoreCase(actaulDirection) ? ReportEngineEnum.KPISentiment.POSITIVE : ReportEngineEnum.KPISentiment.NEGATIVE;
        resultValuesMap.put(AssessmentReportAndWorkflowConstants.ACTUALDIRECTION, actaulDirection);
        resultValuesMap.put("result", avgValue);
        addTimeValueinResult(resultValuesMap, contentConfigDefinition.getSchedule());
        String inferenceText = null;
        if (avgValue == 0.0) {
            inferenceText = getContentText(ReportEngineUtils.NEUTRAL_MESSAGE_KEY, resultValuesMap);
        } else {
            inferenceText = getContentText(ReportEngineUtils.STANDARD_MESSAGE_KEY, resultValuesMap);
        }
        if (inferenceText != null) {
            inferenceContentResult = setContentDetail(resultDetailObj, resultValuesMap, sentiment, "", inferenceText);
        } else {
            log.debug("Worlflow Detail ====   inference text is null for average threshold KPIId {} contentId {} result {} ", getContentConfig().getKpiId(), getContentConfig().getContentId(), resultDetailObj);
        }
        long processingTime = TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - startTime);
        log.debug("Type=TaskExecution  executionId={} workflowId={} ConfigId={} WorkflowType={} KpiId={} Category={} ProcessingTime={} message={}", contentConfigDefinition.getExecutionId(), contentConfigDefinition.getWorkflowId(), contentConfigDefinition.getReportId(), "-", contentConfigDefinition.getKpiId(), contentConfigDefinition.getCategory(), processingTime, "ContentId :" + contentConfigDefinition.getContentId() + "ContentName :" + contentConfigDefinition.getContentName() + "action :" + contentConfigDefinition.getAction() + "ContentResult :" + contentConfigDefinition.getNoOfResult());
    } catch (Exception e) {
        log.error(e);
        log.error(" Error while content processing for average threshold KPIId {} contentId {} ", getContentConfig().getKpiId(), getContentConfig().getContentId());
        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() + "Exception while running neo4j operation" + e.getMessage());
        throw new InsightsJobFailedException("Exception while running neo4j operation {} " + e.getMessage());
    }
    return inferenceContentResult;
}
Also used : ContentConfigDefinition(com.cognizant.devops.platformreports.assessment.datamodel.ContentConfigDefinition) HashMap(java.util.HashMap) WorkflowSchedule(com.cognizant.devops.platformcommons.core.enums.WorkflowTaskEnum.WorkflowSchedule) InsightsContentDetail(com.cognizant.devops.platformreports.assessment.datamodel.InsightsContentDetail) ArrayList(java.util.ArrayList) TimeUnit(java.util.concurrent.TimeUnit) InsightsJobFailedException(com.cognizant.devops.platformreports.exception.InsightsJobFailedException) List(java.util.List) AssessmentReportAndWorkflowConstants(com.cognizant.devops.platformcommons.constants.AssessmentReportAndWorkflowConstants) Logger(org.apache.logging.log4j.Logger) InsightsKPIResultDetails(com.cognizant.devops.platformreports.assessment.datamodel.InsightsKPIResultDetails) Map(java.util.Map) ReportEngineUtils(com.cognizant.devops.platformreports.assessment.util.ReportEngineUtils) LogManager(org.apache.logging.log4j.LogManager) ReportEngineEnum(com.cognizant.devops.platformreports.assessment.util.ReportEngineEnum) HashMap(java.util.HashMap) ReportEngineEnum(com.cognizant.devops.platformreports.assessment.util.ReportEngineEnum) InsightsJobFailedException(com.cognizant.devops.platformreports.exception.InsightsJobFailedException) InsightsKPIResultDetails(com.cognizant.devops.platformreports.assessment.datamodel.InsightsKPIResultDetails) InsightsJobFailedException(com.cognizant.devops.platformreports.exception.InsightsJobFailedException) InsightsContentDetail(com.cognizant.devops.platformreports.assessment.datamodel.InsightsContentDetail)

Example 57 with InsightsJobFailedException

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

the class AutoMLSubscriber method updateFailedTaskStatusLog.

private void updateFailedTaskStatusLog(List<JsonObject> failedJobs) {
    long startTime = System.nanoTime();
    JsonObject statusObject = new JsonObject();
    JsonArray errorLog = new JsonArray();
    failedJobs.forEach(failedJob -> errorLog.add(failedJob.get("errorLog").getAsString()));
    statusObject.addProperty("executionId", executionId);
    statusObject.addProperty("workflowId", workflowConfig.getWorkflowId());
    statusObject.add("errorLog", errorLog);
    autoMlConfig.setStatus(AutoMLEnum.Status.ERROR.name());
    autoMlDAL.updateMLConfig(autoMlConfig);
    // statusLog set here which is class variable of WorkflowTaskSubscriberHandler
    statusLog = new Gson().toJson(statusObject);
    long processingTime = TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - startTime);
    log.error("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 failed to execute ");
    throw new InsightsJobFailedException("AutoML task failed to execute  " + statusLog);
}
Also used : JsonArray(com.google.gson.JsonArray) InsightsJobFailedException(com.cognizant.devops.platformreports.exception.InsightsJobFailedException) JsonObject(com.google.gson.JsonObject) Gson(com.google.gson.Gson)

Example 58 with InsightsJobFailedException

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

the class SystemNotificationDetailSubscriber method createEmailHTML.

/**
 * Method to create Email HTML
 *
 * @param idDataMap
 * @return String
 */
private String createEmailHTML(Map<String, String> idDataMap) {
    try {
        File mailTemplate = new File(getClass().getClassLoader().getResource("mailTemplate.html").getFile());
        String template = new String(Files.readAllBytes(mailTemplate.toPath()));
        String validTemplate = ValidationUtils.cleanXSS(template);
        Document document = Jsoup.parse(validTemplate, StandardCharsets.UTF_8.name());
        return createComponentTable(idDataMap, document);
    } catch (Exception e) {
        log.error("Worlflow Detail ==== Error creating HTML body for email");
        throw new InsightsJobFailedException("Worlflow Detail ==== Error creating HTML body for email");
    }
}
Also used : InsightsJobFailedException(com.cognizant.devops.platformreports.exception.InsightsJobFailedException) Document(org.jsoup.nodes.Document) File(java.io.File) InsightsJobFailedException(com.cognizant.devops.platformreports.exception.InsightsJobFailedException) IOException(java.io.IOException)

Example 59 with InsightsJobFailedException

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

the class ReportElasticSearchDataHandler method saveContentResult.

@Override
public void saveContentResult(JsonObject contentResult) {
    try {
        log.debug("Worlflow Detail ==== In ES,  saveContentResult started ");
        List<JsonObject> rows = new ArrayList<>();
        rows.add(contentResult);
        String indexName = ReportEngineUtils.ES_CONTENT_RESULT_INDEX;
        deoES.saveESResult(indexName.toLowerCase(), rows);
        log.debug("Worlflow Detail ==== In ES,  saveContentResult completed ");
    } catch (Exception e) {
        log.error("Error while saving Content Result record {}", e.getMessage());
        throw new InsightsJobFailedException("Error while saving neo4j record {} " + e.getMessage());
    }
}
Also used : InsightsJobFailedException(com.cognizant.devops.platformreports.exception.InsightsJobFailedException) ArrayList(java.util.ArrayList) JsonObject(com.google.gson.JsonObject) InsightsJobFailedException(com.cognizant.devops.platformreports.exception.InsightsJobFailedException)

Example 60 with InsightsJobFailedException

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

the class ReportElasticSearchDataHandler method saveData.

@Override
public void saveData(List<JsonObject> resultList) {
    try {
        String indexName = ReportEngineUtils.ES_KPI_RESULT_INDEX;
        deoES.saveESResult(indexName.toLowerCase(), resultList);
    } catch (Exception e) {
        log.error("Error while saving saving KPI record {}", e.getMessage());
        throw new InsightsJobFailedException("Error while saving neo4j record  " + e.getMessage());
    }
}
Also used : InsightsJobFailedException(com.cognizant.devops.platformreports.exception.InsightsJobFailedException) 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