Search in sources :

Example 61 with InsightsJobFailedException

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

the class ReportGraphDataHandler method fetchKPIData.

@Override
public List<JsonObject> fetchKPIData(String graphQuery, InsightsKPIConfigDTO kpiDefinition, QueryModel model) {
    List<JsonObject> listOfResultJson = new ArrayList<>();
    try {
        long startTime = System.nanoTime();
        log.debug("Worlflow Detail ==== graphQuery with date for KPI {} ==== is === {} ", kpiDefinition.getKpiId(), graphQuery);
        if (!kpiDefinition.getInputDatasource().isEmpty()) {
            graphDBHandler = new GraphDBHandler(kpiDefinition.getInputDatasource());
        }
        List<JsonObject> graphResp = fetchData(graphQuery);
        JsonArray graphJsonResult = graphResp.get(0).getAsJsonArray(AssessmentReportAndWorkflowConstants.RESULTS);
        JsonArray data = graphJsonResult.get(0).getAsJsonObject().getAsJsonArray("data");
        JsonArray columns = graphJsonResult.get(0).getAsJsonObject().getAsJsonArray(AssessmentReportAndWorkflowConstants.COLUMNS);
        log.debug(" Worlflow Detail ==== KPI Id {0}  record return by query ==== {1} ", kpiDefinition.getKpiId(), data.size());
        if (data.size() > 0) {
            listOfResultJson.addAll(creatingResulJsontFromGraphResponce(data, columns, kpiDefinition, model));
        } else {
            log.error("Worlflow Detail ==== No Result Neo4j query returned invalid result for the KPIID {} ", kpiDefinition.getKpiId());
        /*
				 * InsightsStatusProvider.getInstance().createInsightStatusNode(
				 * "Neo4j query returned invalid result for the KPIID " +
				 * kpiDefinition.getKpiId(), PlatformServiceConstants.FAILURE);
				 */
        }
        long processingTime = TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - startTime);
        log.debug("Type=TaskExecution  executionId={} workflowId={} ConfigId={} WorkflowType={} KpiId={} Category={} ProcessingTime={} message={}", kpiDefinition.getExecutionId(), kpiDefinition.getWorkflowId(), kpiDefinition.getReportId(), "-", kpiDefinition.getKpiId(), kpiDefinition.getCategory(), processingTime, "usecasename: " + kpiDefinition.getUsecaseName());
    } catch (Exception e) {
        log.error("Exception while running neo4j operation  ", e);
        log.error("Type=TaskExecution  executionId={} workflowId={} ConfigId={} WorkflowType={} KpiId={} Category={} ProcessingTime={} message={}", kpiDefinition.getExecutionId(), kpiDefinition.getWorkflowId(), kpiDefinition.getReportId(), "-", kpiDefinition.getKpiId(), kpiDefinition.getCategory(), 0, "usecasename: " + kpiDefinition.getUsecaseName() + "Exception while running neo4j operation" + e.getMessage());
        throw new InsightsJobFailedException("Exception while running neo4j operation  " + e.getMessage());
    }
    return listOfResultJson;
}
Also used : GraphDBHandler(com.cognizant.devops.platformcommons.dal.neo4j.GraphDBHandler) JsonArray(com.google.gson.JsonArray) InsightsJobFailedException(com.cognizant.devops.platformreports.exception.InsightsJobFailedException) ArrayList(java.util.ArrayList) JsonObject(com.google.gson.JsonObject) InsightsJobFailedException(com.cognizant.devops.platformreports.exception.InsightsJobFailedException) InsightsCustomException(com.cognizant.devops.platformcommons.exception.InsightsCustomException)

Example 62 with InsightsJobFailedException

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

the class ReportGraphDataHandler method fetchData.

public List<JsonObject> fetchData(String graphQuery) {
    List<JsonObject> graphResp = new ArrayList<>(0);
    try {
        JsonObject response = graphDBHandler.executeCypherQueryForJsonResponse(graphQuery);
        graphResp.add(response);
        parseGraphResponseForError(graphResp.get(0));
    } catch (InsightsCustomException | InsightsJobFailedException e1) {
        throw new InsightsJobFailedException(e1.toString());
    } catch (Exception e) {
        throw new InsightsJobFailedException(e.toString());
    }
    return graphResp;
}
Also used : InsightsJobFailedException(com.cognizant.devops.platformreports.exception.InsightsJobFailedException) InsightsCustomException(com.cognizant.devops.platformcommons.exception.InsightsCustomException) ArrayList(java.util.ArrayList) JsonObject(com.google.gson.JsonObject) InsightsJobFailedException(com.cognizant.devops.platformreports.exception.InsightsJobFailedException) InsightsCustomException(com.cognizant.devops.platformcommons.exception.InsightsCustomException)

Example 63 with InsightsJobFailedException

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

the class InsightsKPIProcessor method processKPI.

protected int processKPI(InsightsKPIConfigDTO kpiDefinition) {
    try {
        ReportDataHandler kPIQueryDataHandler = ReportDataHandlerFactory.getDataSource(kpiDefinition.getDatasource());
        String graphQuery = kpiDefinition.getdBQuery();
        List<JsonObject> listOfResultJson = new ArrayList<>(0);
        List<QueryModel> queryModelList = new ArrayList<>();
        long startDate;
        long endDate;
        int noOfDays;
        if (kpiDefinition.getSchedule().equals(WorkflowTaskEnum.WorkflowSchedule.ONETIME)) {
            startDate = kpiDefinition.getOneTimeReportStartTime();
            endDate = kpiDefinition.getOneTimeReportEndDate();
            noOfDays = InsightsUtils.getDurationBetweenDates(startDate, endDate).intValue();
        } else {
            startDate = kpiDefinition.getNextRunTime();
            // kpiDefinition.getOneTimeReportEndDate(); /// end date to nextRunTime
            endDate = startDate;
            noOfDays = kpiDefinition.getSchedule().getValue();
        }
        if (kpiDefinition.getCategory().equals(ContentCategory.THRESHOLD.name()) || kpiDefinition.getCategory().equals(ContentCategory.THRESHOLD_RANGE.name()) || kpiDefinition.getCategory().equals(ContentCategory.MINMAX.name()) || kpiDefinition.getCategory().equals(ContentCategory.TREND.name())) {
            getQueryBySchedule(startDate, kpiDefinition.getSchedule(), noOfDays, graphQuery, endDate, queryModelList);
        } else {
            getQueryWithScheduleDates(startDate, kpiDefinition.getSchedule(), graphQuery, endDate, queryModelList);
        }
        log.debug("Worlflow Detail ====  In processKPI for kpiId {} category {} queryModelList {}", kpiDefinition.getKpiId(), kpiDefinition.getCategory(), queryModelList.size());
        long startTime = System.nanoTime();
        for (QueryModel model : queryModelList) {
            if (kpiDefinition.getCategory().equalsIgnoreCase(ReportEngineUtils.PREDICTION)) {
                List<JsonObject> result = kPIQueryDataHandler.fetchKPIData(model.getQuery(), kpiDefinition, model);
                listOfResultJson.addAll(AutoMLPrediction.getPrediction(result, result.get(0).get("columnProperty").getAsJsonArray(), kpiDefinition.getUsecaseName()));
            } else {
                listOfResultJson.addAll(kPIQueryDataHandler.fetchKPIData(model.getQuery(), kpiDefinition, model));
            }
        }
        long processingTime = TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - startTime);
        log.debug("Type=TaskExecution  executionId={} workflowId={} ConfigId={} WorkflowType={} KpiId={} Category={} ProcessingTime={} message={}", kpiDefinition.getExecutionId(), kpiDefinition.getWorkflowId(), kpiDefinition.getReportId(), "-", kpiDefinition.getKpiId(), kpiDefinition.getCategory(), processingTime, " usecasename: " + kpiDefinition.getUsecaseName() + " schedule: " + kpiDefinition.getSchedule());
        ReportDataHandler kPIResultDataHandler = ReportDataHandlerFactory.getDataSource(ApplicationConfigProvider.getInstance().getAssessmentReport().getOutputDatasource());
        log.debug("Worlflow Detail ====  Number of record fetch against kpi Id {} is {}", kpiDefinition.getKpiId(), listOfResultJson.size());
        if (!listOfResultJson.isEmpty()) {
            kPIResultDataHandler.saveData(listOfResultJson);
        } else {
            log.error("Worlflow Detail ====  No result to store in database(neo4j or ES) for job : {} ", kpiConfigDTO.getKpiId());
            return ReportEngineEnum.StatusCode.NO_DATA.getValue();
        }
    } catch (Exception e) {
        log.error("Worlflow Detail ==== Some calculation job failed for kpiID -{} ", kpiDefinition.getKpiId(), e);
        log.error("Type=TaskExecution  executionId={} workflowId={} ConfigId={} WorkflowType={} KpiId={} Category={} ProcessingTime={} message={}", kpiDefinition.getExecutionId(), kpiDefinition.getWorkflowId(), kpiDefinition.getReportId(), "-", kpiDefinition.getKpiId(), kpiDefinition.getCategory(), 0, "usecasename: " + kpiDefinition.getUsecaseName() + "schedule: " + kpiDefinition.getSchedule() + e.getMessage());
        throw new InsightsJobFailedException("Something went wrong with KPI query execution " + e.getMessage());
    }
    return ReportEngineEnum.StatusCode.SUCCESS.getValue();
}
Also used : InsightsJobFailedException(com.cognizant.devops.platformreports.exception.InsightsJobFailedException) ArrayList(java.util.ArrayList) JsonObject(com.google.gson.JsonObject) ReportDataHandler(com.cognizant.devops.platformreports.assessment.dal.ReportDataHandler) QueryModel(com.cognizant.devops.platformreports.assessment.datamodel.QueryModel) 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