Search in sources :

Example 1 with InsightsKPIConfig

use of com.cognizant.devops.platformdal.assessmentreport.InsightsKPIConfig in project Insights by CognizantOneDevOps.

the class WorkflowTestData method saveKpiDefinition.

public int saveKpiDefinition(String kpiDefinition) {
    int kpiId = -1;
    try {
        JsonObject kpiJson = JsonUtils.parseStringAsJsonObject(kpiDefinition);
        InsightsKPIConfig kpiConfig = new InsightsKPIConfig();
        kpiId = kpiJson.get("kpiId").getAsInt();
        InsightsKPIConfig existingConfig = reportConfigDAL.getKPIConfig(kpiId);
        if (existingConfig == null) {
            boolean isActive = kpiJson.get("isActive").getAsBoolean();
            String kpiName = kpiJson.get("name").getAsString();
            String dBQuery = kpiJson.get("DBQuery").getAsString();
            String resultField = kpiJson.get("resultField").getAsString();
            String group = kpiJson.get("group").getAsString();
            String toolName = kpiJson.get("toolName").getAsString();
            String dataSource = kpiJson.get("datasource").getAsString();
            String category = kpiJson.get("category").getAsString();
            String usecase = kpiJson.get("usecase").getAsString();
            String outputDatasource = kpiJson.get("outputDatasource").getAsString();
            kpiConfig.setKpiId(kpiId);
            kpiConfig.setActive(isActive);
            kpiConfig.setKpiName(kpiName);
            kpiConfig.setdBQuery(dBQuery);
            kpiConfig.setResultField(resultField);
            kpiConfig.setToolname(toolName);
            kpiConfig.setGroupName(group);
            kpiConfig.setDatasource(dataSource);
            kpiConfig.setCategory(category);
            kpiConfig.setOutputDatasource(outputDatasource);
            kpiConfig.setUsecase(usecase);
            reportConfigDAL.saveKpiConfig(kpiConfig);
        }
    } catch (Exception e) {
        log.error(e);
    }
    return kpiId;
}
Also used : InsightsKPIConfig(com.cognizant.devops.platformdal.assessmentreport.InsightsKPIConfig) JsonObject(com.google.gson.JsonObject) AddressException(javax.mail.internet.AddressException) InsightsCustomException(com.cognizant.devops.platformcommons.exception.InsightsCustomException)

Example 2 with InsightsKPIConfig

use of com.cognizant.devops.platformdal.assessmentreport.InsightsKPIConfig in project Insights by CognizantOneDevOps.

the class WorkflowTestData method saveReportTemplate.

public int saveReportTemplate(String reportTemplate) {
    int reportId = -1;
    try {
        JsonObject reportJson = JsonUtils.parseStringAsJsonObject(reportTemplate);
        Gson gson = new Gson();
        Set<InsightsReportsKPIConfig> reportsKPIConfigSet = new LinkedHashSet<>();
        reportId = reportJson.get("reportId").getAsInt();
        InsightsAssessmentReportTemplate reportEntity = (InsightsAssessmentReportTemplate) reportConfigDAL.getActiveReportTemplateByReportId(reportId);
        if (reportEntity == null) {
            String reportName = reportJson.get("reportName").getAsString();
            boolean isActive = reportJson.get("isActive").getAsBoolean();
            String description = reportJson.get("description").getAsString();
            String file = reportJson.get("file").getAsString();
            String visualizationutil = reportJson.get("visualizationutil").getAsString();
            reportEntity = new InsightsAssessmentReportTemplate();
            reportEntity.setReportId(reportId);
            reportEntity.setActive(isActive);
            reportEntity.setDescription(description);
            reportEntity.setTemplateName(reportName);
            reportEntity.setFile(file);
            reportEntity.setVisualizationutil(visualizationutil);
            JsonArray kpiConfigArray = reportJson.get("kpiConfigs").getAsJsonArray();
            for (JsonElement eachKpiConfig : kpiConfigArray) {
                JsonObject KpiObject = eachKpiConfig.getAsJsonObject();
                int kpiId = KpiObject.get("kpiId").getAsInt();
                String vConfig = gson.toJson(KpiObject.get("visualizationConfigs").getAsJsonArray());
                InsightsKPIConfig kpiConfig = reportConfigDAL.getKPIConfig(kpiId);
                if (kpiConfig != null) {
                    InsightsReportsKPIConfig reportsKPIConfig = new InsightsReportsKPIConfig();
                    reportsKPIConfig.setKpiConfig(kpiConfig);
                    reportsKPIConfig.setvConfig(vConfig);
                    reportsKPIConfig.setReportTemplateEntity(reportEntity);
                    reportsKPIConfigSet.add(reportsKPIConfig);
                }
            }
            reportEntity.setReportsKPIConfig(reportsKPIConfigSet);
            reportConfigDAL.saveReportConfig(reportEntity);
        }
    } catch (Exception e) {
        log.error(e);
    }
    return reportId;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) InsightsReportsKPIConfig(com.cognizant.devops.platformdal.assessmentreport.InsightsReportsKPIConfig) InsightsAssessmentReportTemplate(com.cognizant.devops.platformdal.assessmentreport.InsightsAssessmentReportTemplate) JsonObject(com.google.gson.JsonObject) Gson(com.google.gson.Gson) AddressException(javax.mail.internet.AddressException) InsightsCustomException(com.cognizant.devops.platformcommons.exception.InsightsCustomException) JsonArray(com.google.gson.JsonArray) JsonElement(com.google.gson.JsonElement) InsightsKPIConfig(com.cognizant.devops.platformdal.assessmentreport.InsightsKPIConfig)

Example 3 with InsightsKPIConfig

use of com.cognizant.devops.platformdal.assessmentreport.InsightsKPIConfig in project Insights by CognizantOneDevOps.

the class ReportKPISubscriber method handleTaskExecution.

@Override
public void handleTaskExecution(byte[] body) throws IOException {
    try {
        long startTime = System.nanoTime();
        List<JsonObject> failedJobs = new ArrayList<>();
        List<InsightsKPIConfig> kpiConfigList = new ArrayList<>();
        List<Integer> contentList = new ArrayList<>();
        String message = new String(body, MQMessageConstants.MESSAGE_ENCODING);
        log.debug("Worlflow Detail ==== ReportKPISubscriber routing key  message handleDelivery ===== {} ", message);
        JsonObject incomingTaskMessage = JsonUtils.parseStringAsJsonObject(message);
        String workflowId = incomingTaskMessage.get("workflowId").getAsString();
        executionId = incomingTaskMessage.get("executionId").getAsLong();
        workflowConfig = workflowDAL.getWorkflowConfigByWorkflowId(workflowId);
        /* kpi and content list */
        boolean isWorkflowTaskRetry = incomingTaskMessage.get(WorkflowUtils.RETRY_JSON_PROPERTY).getAsBoolean();
        if (isWorkflowTaskRetry) {
            /* fill failed kpis and content for execution */
            extractKPIAndContentRetryList(incomingTaskMessage, kpiConfigList, contentList);
            /* execute content */
            executeContent(contentList, failedJobs);
        } else {
            Set<InsightsReportsKPIConfig> reportsKPIConfigSet = workflowConfig.getAssessmentConfig().getReportTemplateEntity().getReportsKPIConfig();
            reportsKPIConfigSet.forEach(reportKpi -> kpiConfigList.add(reportKpi.getKpiConfig()));
        }
        /* Execute Kpi */
        log.debug("Worlflow Detail ==== ReportKPISubscriber before executeKPI  ", kpiConfigList.size());
        executeKPI(kpiConfigList, failedJobs);
        if (!failedJobs.isEmpty()) {
            updateFailedTaskStatusLog(failedJobs);
        }
        long processingTime = TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - startTime);
        log.debug("Type=TaskExecution  executionId={} workflowId={} ConfigId={} WorkflowType={} KpiId={} Category={} ProcessingTime={} message={}", executionId, workflowId, workflowConfig.getAssessmentConfig().getId(), workflowConfig.getWorkflowType(), "-", "-", processingTime, "usecasename: " + "-" + " schedule: " + workflowConfig.getScheduleType());
    } catch (InsightsJobFailedException e) {
        log.error("Worlflow Detail ==== InsightsJobFailedException ==== ", e);
        InsightsStatusProvider.getInstance().createInsightStatusNode("ReportKPI subscriber exception... " + e.getMessage(), PlatformServiceConstants.FAILURE);
        log.error("Type=TaskExecution  executionId={} workflowId={} ConfigId={} WorkflowType={} KpiId={} Category={} ProcessingTime={} message={}", executionId, "-", "-", "-", "-", "-", 0, "Exception: " + e.getMessage());
        throw new InsightsJobFailedException("Some of the Kpi's or Contents failed to execute " + e.getMessage());
    } catch (RejectedExecutionException e) {
        log.error("Worlflow Detail ==== RejectedExecutionException ====  ", e);
        InsightsStatusProvider.getInstance().createInsightStatusNode("ReportKPI subscriber exception " + e.getMessage(), PlatformServiceConstants.FAILURE);
        log.error("Type=TaskExecution  executionId={} workflowId={} ConfigId={} WorkflowType={} KpiId={} Category={} ProcessingTime={} message={}", executionId, "-", "-", "-", "-", "-", 0, "Exception:RejectedExecutionException " + e.getMessage());
        throw new InsightsJobFailedException("some of the Kpi's or Contents failed to execute RejectedExecutionException " + e.getMessage());
    } catch (Exception e) {
        log.error("Worlflow Detail ==== handleTaskExecution ==== ", e);
        InsightsStatusProvider.getInstance().createInsightStatusNode("ReportKPI subscriber exception " + e.getMessage(), PlatformServiceConstants.FAILURE);
        log.error("Type=TaskExecution  executionId={} workflowId={} ConfigId={} WorkflowType={} KpiId={} Category={} ProcessingTime={} message={}", executionId, "-", "-", "-", "-", "-", 0, "Exception:ReportKPI subscriber exception" + e.getMessage());
        throw new InsightsJobFailedException("some of the Kpi's or Contents failed to execute Exception " + e.getMessage());
    }
    log.debug("Worlflow Detail ==== ReportKPISubscriber completed ");
    InsightsStatusProvider.getInstance().createInsightStatusNode("ReportKPISubscriber completed", PlatformServiceConstants.SUCCESS);
}
Also used : InsightsReportsKPIConfig(com.cognizant.devops.platformdal.assessmentreport.InsightsReportsKPIConfig) ArrayList(java.util.ArrayList) JsonObject(com.google.gson.JsonObject) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) InsightsJobFailedException(com.cognizant.devops.platformreports.exception.InsightsJobFailedException) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) InsightsJobFailedException(com.cognizant.devops.platformreports.exception.InsightsJobFailedException) InsightsKPIConfig(com.cognizant.devops.platformdal.assessmentreport.InsightsKPIConfig)

Example 4 with InsightsKPIConfig

use of com.cognizant.devops.platformdal.assessmentreport.InsightsKPIConfig in project Insights by CognizantOneDevOps.

the class AssesmentReportServiceImpl method getKPIlistOfReportTemplate.

/**
 * Fetch all the KPI List of the selected report template.
 *
 * @param configId
 * @return
 * @throws InsightsCustomException
 */
public JsonArray getKPIlistOfReportTemplate(String configId) throws InsightsCustomException {
    try {
        int id = Integer.parseInt(configId);
        List<InsightsKPIConfig> listofkpis = reportConfigDAL.getKpiConfigByTemplateReportId(id);
        JsonArray jsonarray = new JsonArray();
        for (InsightsKPIConfig kpiDetail : listofkpis) {
            JsonObject jsonobject = new JsonObject();
            jsonobject.addProperty(AssessmentReportAndWorkflowConstants.KPIID, kpiDetail.getKpiId());
            jsonobject.addProperty("kpiName", kpiDetail.getKpiName());
            jsonarray.add(jsonobject);
        }
        return jsonarray;
    } catch (Exception e) {
        log.error("Error while deleting assesment report.", e);
        throw new InsightsCustomException(e.toString());
    }
}
Also used : JsonArray(com.google.gson.JsonArray) InsightsCustomException(com.cognizant.devops.platformcommons.exception.InsightsCustomException) InsightsKPIConfig(com.cognizant.devops.platformdal.assessmentreport.InsightsKPIConfig) JsonObject(com.google.gson.JsonObject) NoResultException(javax.persistence.NoResultException) FileNotFoundException(java.io.FileNotFoundException) InsightsCustomException(com.cognizant.devops.platformcommons.exception.InsightsCustomException) IOException(java.io.IOException)

Example 5 with InsightsKPIConfig

use of com.cognizant.devops.platformdal.assessmentreport.InsightsKPIConfig in project Insights by CognizantOneDevOps.

the class AssesmentReportServiceImpl method updateKpiDefinition.

/**
 * Used to update individual KPI definition
 *
 * @param registerkpiJson
 * @return
 * @throws InsightsCustomException
 */
public int updateKpiDefinition(JsonObject updatekpiJson) throws InsightsCustomException {
    int kpiId = -1;
    try {
        kpiId = updatekpiJson.get(AssessmentReportAndWorkflowConstants.KPIID).getAsInt();
        InsightsKPIConfig kpiExistingConfig = reportConfigDAL.getKPIConfig(kpiId);
        if (kpiExistingConfig == null) {
            throw new InsightsCustomException("While update, KPI definition not exists");
        } else {
            boolean isActive = updatekpiJson.get(AssessmentReportAndWorkflowConstants.ISACTIVE).getAsBoolean();
            String kpiName = updatekpiJson.get("name").getAsString();
            String dBQuery = updatekpiJson.get("DBQuery").getAsString();
            String resultField = updatekpiJson.get("resultField").getAsString();
            String group = updatekpiJson.get("group").getAsString();
            String toolName = updatekpiJson.get("toolName").getAsString();
            String dataSource = updatekpiJson.get(AssessmentReportAndWorkflowConstants.DATASOURCE).getAsString();
            String category = updatekpiJson.get(AssessmentReportAndWorkflowConstants.CATEGORY).getAsString();
            String usecase = updatekpiJson.get("usecase").getAsString();
            String outputDatasource = updatekpiJson.get(AssessmentReportAndWorkflowConstants.OUTPUTDATASOURCE).getAsString();
            dBQuery = dBQuery.replace("#", "<").replace("~", ">");
            kpiExistingConfig.setKpiId(kpiId);
            kpiExistingConfig.setActive(isActive);
            kpiExistingConfig.setKpiName(kpiName);
            kpiExistingConfig.setdBQuery(dBQuery);
            kpiExistingConfig.setResultField(resultField);
            kpiExistingConfig.setToolname(toolName);
            kpiExistingConfig.setGroupName(group);
            kpiExistingConfig.setDatasource(dataSource);
            kpiExistingConfig.setCategory(category);
            kpiExistingConfig.setUsecase(usecase);
            kpiExistingConfig.setOutputDatasource(outputDatasource);
            reportConfigDAL.updateKpiConfig(kpiExistingConfig);
        }
    } catch (Exception e) {
        log.error(e);
        throw new InsightsCustomException(e.getMessage());
    }
    return kpiId;
}
Also used : InsightsCustomException(com.cognizant.devops.platformcommons.exception.InsightsCustomException) InsightsKPIConfig(com.cognizant.devops.platformdal.assessmentreport.InsightsKPIConfig) NoResultException(javax.persistence.NoResultException) FileNotFoundException(java.io.FileNotFoundException) InsightsCustomException(com.cognizant.devops.platformcommons.exception.InsightsCustomException) IOException(java.io.IOException)

Aggregations

InsightsKPIConfig (com.cognizant.devops.platformdal.assessmentreport.InsightsKPIConfig)22 InsightsCustomException (com.cognizant.devops.platformcommons.exception.InsightsCustomException)17 IOException (java.io.IOException)14 JsonObject (com.google.gson.JsonObject)11 NoResultException (javax.persistence.NoResultException)9 FileNotFoundException (java.io.FileNotFoundException)8 InsightsContentConfig (com.cognizant.devops.platformdal.assessmentreport.InsightsContentConfig)6 InsightsReportsKPIConfig (com.cognizant.devops.platformdal.assessmentreport.InsightsReportsKPIConfig)6 JsonArray (com.google.gson.JsonArray)6 Gson (com.google.gson.Gson)5 JsonElement (com.google.gson.JsonElement)5 InsightsAssessmentReportTemplate (com.cognizant.devops.platformdal.assessmentreport.InsightsAssessmentReportTemplate)4 ArrayList (java.util.ArrayList)4 LinkedHashSet (java.util.LinkedHashSet)4 InsightsJobFailedException (com.cognizant.devops.platformreports.exception.InsightsJobFailedException)3 AddressException (javax.mail.internet.AddressException)3 HashMap (java.util.HashMap)2 ExecutionException (java.util.concurrent.ExecutionException)2 RejectedExecutionException (java.util.concurrent.RejectedExecutionException)2 Test (org.testng.annotations.Test)2