Search in sources :

Example 41 with InsightsJobFailedException

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

the class KPIExecutor method call.

@Override
public JsonObject call() throws Exception {
    JsonObject response = new JsonObject();
    JsonArray failedjobs = new JsonArray();
    int kpiId = ReportEngineEnum.StatusCode.ERROR.getValue();
    long startTime = System.nanoTime();
    try {
        kpiId = executeKPIJob(_kpiConfigDTO);
        log.debug("Type=TaskExecution  executionId={} workflowId={} ConfigId={} WorkflowType={} KpiId={} Category={} ProcessingTime={} message={}", _kpiConfigDTO.getExecutionId(), _kpiConfigDTO.getWorkflowId(), _kpiConfigDTO.getReportId(), "-", _kpiConfigDTO.getKpiId(), _kpiConfigDTO.getCategory(), 0, "usecasename: " + _kpiConfigDTO.getUsecaseName() + "schedule: " + _kpiConfigDTO.getSchedule());
    } catch (InsightsJobFailedException e) {
        response.addProperty(STATUS, "Failure");
        failedjobs.add(_kpiConfigDTO.getKpiId());
        response.add("kpiArray", failedjobs);
        log.debug("Type=TaskExecution  executionId={} workflowId={} ConfigId={} WorkflowType={} KpiId={} Category={} ProcessingTime={} message={}", _kpiConfigDTO.getExecutionId(), _kpiConfigDTO.getWorkflowId(), _kpiConfigDTO.getReportId(), "-", _kpiConfigDTO.getKpiId(), _kpiConfigDTO.getCategory(), 0, "usecasename: " + _kpiConfigDTO.getUsecaseName() + "schedule: " + _kpiConfigDTO.getSchedule());
    }
    if (kpiId != ReportEngineEnum.StatusCode.ERROR.getValue()) {
        ReportConfigDAL reportConfigAL = new ReportConfigDAL();
        List<InsightsContentConfig> contentConfigList = reportConfigAL.getActiveContentConfigByKPIId(_kpiConfigDTO.getKpiId());
        if (!contentConfigList.isEmpty()) {
            /* Execute content on the same thread */
            failedjobs = ContentExecutor.executeContentJob(contentConfigList, _kpiConfigDTO);
        }
        /* If none of the kpi or content is failed then simply return Status as success */
        if (failedjobs.size() > 0) {
            response.addProperty(STATUS, "Failure");
            response.add("contentArray", failedjobs);
        } else {
            response.addProperty(STATUS, "Success");
        }
        long processingTime = TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - startTime);
        log.debug("Type=TaskExecution  executionId={} workflowId={} ConfigId={} WorkflowType={} KpiId={} Category={} ProcessingTime={} message={}", _kpiConfigDTO.getExecutionId(), _kpiConfigDTO.getWorkflowId(), _kpiConfigDTO.getReportId(), "-", _kpiConfigDTO.getKpiId(), _kpiConfigDTO.getCategory(), processingTime, "usecasename: " + _kpiConfigDTO.getUsecaseName() + " schedule: " + _kpiConfigDTO.getSchedule());
    }
    return response;
}
Also used : JsonArray(com.google.gson.JsonArray) InsightsJobFailedException(com.cognizant.devops.platformreports.exception.InsightsJobFailedException) InsightsContentConfig(com.cognizant.devops.platformdal.assessmentreport.InsightsContentConfig) ReportConfigDAL(com.cognizant.devops.platformdal.assessmentreport.ReportConfigDAL) JsonObject(com.google.gson.JsonObject)

Example 42 with InsightsJobFailedException

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

the class FusionChartHandler method createPDFDirectory.

private void createPDFDirectory(InsightsAssessmentConfigurationDTO assessmentReportDTO) {
    try {
        long startTime = System.nanoTime();
        String folderName = assessmentReportDTO.getAsseementreportname() + "_" + assessmentReportDTO.getExecutionId();
        assessmentReportDTO.setPdfReportFolderName(folderName);
        String reportExecutionFile = AssessmentReportAndWorkflowConstants.REPORT_PDF_EXECUTION_RESOLVED_PATH + folderName;
        assessmentReportDTO.setPdfReportDirPath(reportExecutionFile);
        setReportExecutionFolder(assessmentReportDTO);
        long processingTime = TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - startTime);
        log.debug("Type=TaskExecution  executionId={} workflowId={} ConfigId={} WorkflowType={} KpiId={} Category={} ProcessingTime={} message={}", assessmentReportDTO.getExecutionId(), assessmentReportDTO.getWorkflowId(), assessmentReportDTO.getConfigId(), "-", "-", "-", processingTime, "reportId: " + assessmentReportDTO.getReportId() + "reportName: " + assessmentReportDTO.getReportName() + "Foldername" + folderName);
    } catch (Exception e) {
        log.error(e);
        log.debug("Type=TaskExecution  executionId={} workflowId={} ConfigId={} WorkflowType={} KpiId={} Category={} ProcessingTime={} message={}", assessmentReportDTO.getExecutionId(), assessmentReportDTO.getWorkflowId(), assessmentReportDTO.getConfigId(), "-", "-", "-", 0, "reportId: " + assessmentReportDTO.getReportId() + "reportName: " + assessmentReportDTO.getReportName() + "Unable to create pdf execution directory" + e.getMessage());
        throw new InsightsJobFailedException("Unable to create pdf execution directory, message == " + e.getMessage());
    }
}
Also used : InsightsJobFailedException(com.cognizant.devops.platformreports.exception.InsightsJobFailedException) NoSuchFileException(java.nio.file.NoSuchFileException) InsightsJobFailedException(com.cognizant.devops.platformreports.exception.InsightsJobFailedException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) InsightsCustomException(com.cognizant.devops.platformcommons.exception.InsightsCustomException)

Example 43 with InsightsJobFailedException

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

the class FusionChartHandler method generatePDF.

@Override
public void generatePDF(InsightsAssessmentConfigurationDTO assessmentReportDTO) {
    try {
        long startTime = System.nanoTime();
        createPDFDirectory(assessmentReportDTO);
        JsonArray finalTemplateJson = generateChartsConfig(assessmentReportDTO);
        modifyHtmlTemplate(assessmentReportDTO);
        InsightsReportPdfTableConfig insightsReportPdfTableConfig = processHtmlTableWithOpenPDF(assessmentReportDTO);
        exportPDFFile(finalTemplateJson, assessmentReportDTO, insightsReportPdfTableConfig);
        long processingTime = TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - startTime);
        log.debug("Type=TaskExecution  executionId={} workflowId={} ConfigId={} WorkflowType={} KpiId={} Category={} ProcessingTime={} message={}", assessmentReportDTO.getExecutionId(), assessmentReportDTO.getWorkflowId(), assessmentReportDTO.getConfigId(), "-", "-", "-", processingTime, "reportId: " + assessmentReportDTO.getReportId() + "reportName: " + assessmentReportDTO.getReportName() + "VisualizationUtil" + assessmentReportDTO.getVisualizationutil());
    } catch (Exception e) {
        log.error(e);
        log.error("Type=TaskExecution  executionId={} workflowId={} ConfigId={} WorkflowType={} KpiId={} Category={} ProcessingTime={} message={}", assessmentReportDTO.getExecutionId(), assessmentReportDTO.getWorkflowId(), assessmentReportDTO.getConfigId(), "-", "-", "-", 0, "reportId: " + assessmentReportDTO.getReportId() + "reportName: " + assessmentReportDTO.getReportName() + "VisualizationUtil" + assessmentReportDTO.getVisualizationutil() + e.getMessage());
        throw new InsightsJobFailedException(e.getMessage());
    }
}
Also used : JsonArray(com.google.gson.JsonArray) InsightsReportPdfTableConfig(com.cognizant.devops.platformreports.assessment.datamodel.InsightsReportPdfTableConfig) InsightsJobFailedException(com.cognizant.devops.platformreports.exception.InsightsJobFailedException) NoSuchFileException(java.nio.file.NoSuchFileException) InsightsJobFailedException(com.cognizant.devops.platformreports.exception.InsightsJobFailedException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) InsightsCustomException(com.cognizant.devops.platformcommons.exception.InsightsCustomException)

Example 44 with InsightsJobFailedException

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

the class FusionChartHandler method generateChartsConfig.

private JsonArray generateChartsConfig(InsightsAssessmentConfigurationDTO assessmentReportDTO) throws IOException {
    JsonArray finalTemplateJson = new JsonArray();
    String templateJsonPath = assessmentReportDTO.getPdfReportDirPath() + File.separator + assessmentReportDTO.getReportFilePath() + ".json";
    try {
        String json = new String(Files.readAllBytes(Paths.get(new File(templateJsonPath).getCanonicalPath()).toAbsolutePath()));
        JsonArray pdfTemplateJsonArray = JsonUtils.parseStringAsJsonArray(json);
        Map<String, JsonObject> templateJsonObjMap = loadTemplateJson(pdfTemplateJsonArray);
        Map<String, String> contentMap = new HashMap<>();
        Map<String, List<String>> kpiContentMap = new HashMap<>();
        Map<String, JsonArray> tableJsonObjMap = new HashMap<>();
        JsonArray kpiResultArray = assessmentReportDTO.getVisualizationResult();
        for (JsonElement element : kpiResultArray) {
            boolean isTable = false;
            JsonObject eachKpiResult = element.getAsJsonObject();
            String kpiId = eachKpiResult.get("kpiId").getAsString();
            JsonArray kpiVisualizationArray = eachKpiResult.get("visualizationresult").getAsJsonArray();
            log.debug("Worlflow Detail ====  generateChartsConfig for kpi {} kpiVisualizationArray  {} ", kpiId, kpiVisualizationArray);
            for (JsonElement eachElement : kpiVisualizationArray) {
                JsonObject eachVisualizationResult = eachElement.getAsJsonObject();
                String vType = eachVisualizationResult.get("vType").getAsString();
                JsonArray fromkpiResultArray = eachVisualizationResult.get("KpiResult").getAsJsonArray();
                JsonObject visualizationObjectFromTemplateJson = templateJsonObjMap.get(vType);
                // add KPi Data
                if (visualizationObjectFromTemplateJson != null && !vType.startsWith("table")) {
                    JsonObject toObject = getChartJsonFromVisualizationJson(fromkpiResultArray, visualizationObjectFromTemplateJson);
                    finalTemplateJson.add(toObject);
                } else if (vType.startsWith("table") && fromkpiResultArray.size() > 0) {
                    isTable = true;
                    String caption = "";
                    if (templateJsonObjMap.containsKey(vType)) {
                        caption = templateJsonObjMap.get(vType).getAsJsonObject().get(AssessmentReportAndWorkflowConstants.CAPTION).getAsString();
                    }
                    fromkpiResultArray.get(0).getAsJsonObject().addProperty(AssessmentReportAndWorkflowConstants.CAPTION, caption);
                    fromkpiResultArray.get(0).getAsJsonObject().addProperty("kpiId", kpiId);
                    fromkpiResultArray.get(0).getAsJsonObject().addProperty("kpiId", kpiId);
                    tableJsonObjMap.put(vType, fromkpiResultArray);
                } else {
                    log.debug("Worlflow Detail ==== For KPI id {} , No template found for vType {}  or Kpi Result is empty {} ", kpiId, vType, fromkpiResultArray.size());
                }
            }
            extractContentDataFromVisualizationResponse(contentMap, eachKpiResult, kpiId, kpiContentMap, isTable);
        }
        assessmentReportDTO.setTableJsonObjMap(tableJsonObjMap);
        assessmentReportDTO.setContentMap(contentMap);
        assessmentReportDTO.setKpiContentMap(kpiContentMap);
    } catch (NoSuchFileException e) {
        log.error("Worlflow Detail ==== unable to create charts config report template json file not found", e);
        throw new InsightsJobFailedException(" Unable to generate PDF, report template json file not found " + assessmentReportDTO.getReportFilePath() + ".json");
    } catch (Exception e) {
        log.error("Worlflow Detail ==== unable to create charts config ", e);
        throw new InsightsJobFailedException(" unable to create charts config " + e);
    }
    return finalTemplateJson;
}
Also used : HashMap(java.util.HashMap) NoSuchFileException(java.nio.file.NoSuchFileException) JsonObject(com.google.gson.JsonObject) NoSuchFileException(java.nio.file.NoSuchFileException) InsightsJobFailedException(com.cognizant.devops.platformreports.exception.InsightsJobFailedException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) InsightsCustomException(com.cognizant.devops.platformcommons.exception.InsightsCustomException) JsonArray(com.google.gson.JsonArray) InsightsJobFailedException(com.cognizant.devops.platformreports.exception.InsightsJobFailedException) JsonElement(com.google.gson.JsonElement) ArrayList(java.util.ArrayList) List(java.util.List) File(java.io.File)

Example 45 with InsightsJobFailedException

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

the class GrafanaPDFHandler method createPDFDirectory.

/**
 * Method to create PDF execution directory.
 *
 * @param assessmentReportDTO
 */
private void createPDFDirectory(InsightsAssessmentConfigurationDTO assessmentReportDTO) {
    try {
        String folderName = WorkflowType.GRAFANADASHBOARDPDFREPORT + "_" + assessmentReportDTO.getExecutionId();
        assessmentReportDTO.setPdfReportFolderName(folderName);
        String reportExecutionFile = AssessmentReportAndWorkflowConstants.REPORT_PDF_EXECUTION_RESOLVED_PATH + folderName;
        assessmentReportDTO.setPdfReportDirPath(reportExecutionFile);
        File reportExecutionFolder = new File(reportExecutionFile);
        reportExecutionFolder.mkdir();
    } catch (Exception e) {
        log.error(e);
        throw new InsightsJobFailedException("Unable to create pdf execution directory, message == {} " + e.getMessage());
    }
}
Also used : InsightsJobFailedException(com.cognizant.devops.platformreports.exception.InsightsJobFailedException) File(java.io.File) InsightsJobFailedException(com.cognizant.devops.platformreports.exception.InsightsJobFailedException) IOException(java.io.IOException)

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