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