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();
}
Aggregations