Search in sources :

Example 1 with ReportDataHandler

use of com.cognizant.devops.platformreports.assessment.dal.ReportDataHandler 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

ReportDataHandler (com.cognizant.devops.platformreports.assessment.dal.ReportDataHandler)1 QueryModel (com.cognizant.devops.platformreports.assessment.datamodel.QueryModel)1 InsightsJobFailedException (com.cognizant.devops.platformreports.exception.InsightsJobFailedException)1 JsonObject (com.google.gson.JsonObject)1 ArrayList (java.util.ArrayList)1