Search in sources :

Example 1 with ContentConfigDefinition

use of com.cognizant.devops.platformreports.assessment.datamodel.ContentConfigDefinition in project Insights by CognizantOneDevOps.

the class ReportKPISubscriber method executeContent.

private void executeContent(List<Integer> contentList, List<JsonObject> failedJobs) throws InterruptedException, ExecutionException {
    List<Callable<Integer>> contentListToExecute = new ArrayList<>();
    ReportPostgresDataHandler contentProcessing = new ReportPostgresDataHandler();
    int assessmentId = workflowConfig.getAssessmentConfig().getId();
    String assessmentReportName = workflowConfig.getAssessmentConfig().getAsseementreportname();
    int reportTemplateId = workflowConfig.getAssessmentConfig().getReportTemplateEntity().getReportId();
    for (int contentId : contentList) {
        InsightsContentConfig contentConfig = contentProcessing.getContentConfig(contentId);
        ContentConfigDefinition contentConfigDefinition = contentProcessing.convertJsonToContentConfig(contentConfig);
        log.debug("Type=TaskExecution  executionId={} workflowId={} ConfigId={} WorkflowType={} KpiId={} Category={} ProcessingTime={} message={}", contentConfigDefinition.getExecutionId(), contentConfigDefinition.getWorkflowId(), contentConfigDefinition.getReportId(), "", contentConfigDefinition.getKpiId(), contentConfigDefinition.getCategory(), 0, "ContentId :" + contentConfigDefinition.getContentId() + "ContentName :" + contentConfigDefinition.getContentName() + "action :" + contentConfigDefinition.getAction() + "ContentResult :" + contentConfigDefinition.getNoOfResult());
        if (contentConfigDefinition != null) {
            contentConfigDefinition.setExecutionId(executionId);
            contentConfigDefinition.setSchedule(WorkflowTaskEnum.WorkflowSchedule.valueOf(workflowConfig.getScheduleType()));
            contentConfigDefinition.setWorkflowId(workflowConfig.getWorkflowId());
            contentConfigDefinition.setReportId(reportTemplateId);
            contentConfigDefinition.setAssessmentId(assessmentId);
            contentConfigDefinition.setAssessmentReportName(assessmentReportName);
            contentListToExecute.add(new ContentExecutor(contentConfigDefinition));
        } else {
            log.error("Type=TaskExecution  executionId={} workflowId={} ConfigId={} WorkflowType={} KpiId={} Category={} ProcessingTime={} message={}", contentConfigDefinition.getExecutionId(), contentConfigDefinition.getWorkflowId(), contentConfigDefinition.getReportId(), "-", contentConfigDefinition.getKpiId(), contentConfigDefinition.getCategory(), 0, "ContentId :" + contentConfigDefinition.getContentId() + "ContentName :" + contentConfigDefinition.getContentName() + "action :" + contentConfigDefinition.getAction() + "ContentResult :" + contentConfigDefinition.getNoOfResult() + " Content execution failed");
            throw new InsightsJobFailedException("Content execution failed");
        }
    }
    /* segregate entire content execution list into defined chunks */
    List<List<Callable<Integer>>> contentChunkList = WorkflowThreadPool.getChunk(contentListToExecute, 3);
    /* submit each chunk to threadpool in a loop */
    executeContentChunks(contentChunkList, failedJobs);
}
Also used : ContentExecutor(com.cognizant.devops.platformreports.assessment.content.ContentExecutor) InsightsContentConfig(com.cognizant.devops.platformdal.assessmentreport.InsightsContentConfig) ReportPostgresDataHandler(com.cognizant.devops.platformreports.assessment.dal.ReportPostgresDataHandler) ArrayList(java.util.ArrayList) Callable(java.util.concurrent.Callable) InsightsJobFailedException(com.cognizant.devops.platformreports.exception.InsightsJobFailedException) ArrayList(java.util.ArrayList) List(java.util.List) ContentConfigDefinition(com.cognizant.devops.platformreports.assessment.datamodel.ContentConfigDefinition)

Example 2 with ContentConfigDefinition

use of com.cognizant.devops.platformreports.assessment.datamodel.ContentConfigDefinition in project Insights by CognizantOneDevOps.

the class ReportPostgresDataHandler method convertJsonToContentConfig.

public ContentConfigDefinition convertJsonToContentConfig(InsightsContentConfig contentDBConfig) {
    ContentConfigDefinition contentConfig = null;
    try {
        long startTime = System.nanoTime();
        ObjectMapper oMapper = new ObjectMapper();
        JsonNode contentNode = oMapper.readTree(contentDBConfig.getContentJson());
        if (contentNode.isObject()) {
            Map<String, Object> configMap = new HashMap<>();
            for (Iterator<Map.Entry<String, JsonNode>> it = contentNode.fields(); it.hasNext(); ) {
                Map.Entry<String, JsonNode> field = it.next();
                String key = field.getKey();
                JsonNode valueResponse = field.getValue();
                Object value = ReportEngineUtils.getNodeValue(key, valueResponse);
                configMap.put(key, value);
            }
            if (!configMap.isEmpty()) {
                contentConfig = oMapper.convertValue(configMap, ContentConfigDefinition.class);
                contentConfig.setContentId(contentDBConfig.getContentId());
                contentConfig.setKpiId(contentDBConfig.getKpiConfig().getKpiId());
                if (configMap.get("action") != null) {
                    contentConfig.setAction(ReportEngineEnum.ExecutionActions.valueOf(String.valueOf(configMap.get("action"))));
                }
                if (configMap.get("directionOfThreshold") != null) {
                    contentConfig.setDirectionOfThreshold(ReportEngineEnum.DirectionOfThreshold.valueOf(String.valueOf(configMap.get("directionOfThreshold"))));
                }
                contentConfig.setCategory(ReportEngineEnum.ContentCategory.valueOf(contentDBConfig.getCategory()));
                long processingTime = TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - startTime);
                log.debug("Type=TaskExecution  executionId={} workflowId={} ConfigId={} WorkflowType={} KpiId={} Category={} ProcessingTime={} message={}", "-", "-", "-", "-", contentDBConfig.getKpiConfig().getId(), "-", processingTime, "ContentId :" + contentDBConfig.getId() + "ContentName :" + contentDBConfig.getContentName() + "Category :" + contentDBConfig.getCategory());
            }
        }
    } catch (Exception e) {
        log.error(e);
        log.error("Type=TaskExecution  executionId={} workflowId={} ConfigId={} WorkflowType={} KpiId={} Category={} ProcessingTime={} message={}", "-", "-", "-", "-", contentDBConfig.getKpiConfig().getId(), "-", 0, "ContentId :" + contentDBConfig.getId() + "ContentName :" + contentDBConfig.getContentName() + "Category :" + contentDBConfig.getCategory() + e.getMessage());
    }
    return contentConfig;
}
Also used : HashMap(java.util.HashMap) JsonNode(com.fasterxml.jackson.databind.JsonNode) ContentConfigDefinition(com.cognizant.devops.platformreports.assessment.datamodel.ContentConfigDefinition) HashMap(java.util.HashMap) Map(java.util.Map) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 3 with ContentConfigDefinition

use of com.cognizant.devops.platformreports.assessment.datamodel.ContentConfigDefinition in project Insights by CognizantOneDevOps.

the class ContentExecutor method executeContentJob.

public static JsonArray executeContentJob(List<InsightsContentConfig> contentConfigList, InsightsKPIConfigDTO kpiConfigDTO) {
    long startTime = System.nanoTime();
    ReportPostgresDataHandler contentProcessing = new ReportPostgresDataHandler();
    AssessmentReportContentProcesser contentProcessor = new AssessmentReportContentProcesser();
    JsonArray failedContentJobs = new JsonArray();
    for (InsightsContentConfig contentConfig : contentConfigList) {
        try {
            ContentConfigDefinition contentConfigDefinition = contentProcessing.convertJsonToContentConfig(contentConfig);
            if (contentConfigDefinition != null) {
                contentConfigDefinition.setExecutionId(kpiConfigDTO.getExecutionId());
                contentConfigDefinition.setSchedule(kpiConfigDTO.getSchedule());
                contentConfigDefinition.setWorkflowId(kpiConfigDTO.getWorkflowId());
                contentConfigDefinition.setReportId(kpiConfigDTO.getReportId());
                contentConfigDefinition.setAssessmentId(kpiConfigDTO.getAssessmentId());
                contentConfigDefinition.setAssessmentReportName(kpiConfigDTO.getAssessmentReportName());
                contentProcessor.executeContentData(contentConfigDefinition);
                long processingTime = TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - startTime);
                log.debug("Type=TaskExecution  executionId={} workflowId={} ConfigId={} WorkflowType={} KpiId={} Category={} ProcessingTime={} message={}", contentConfigDefinition.getExecutionId(), contentConfigDefinition.getWorkflowId(), contentConfigDefinition.getReportId(), "-", contentConfigDefinition.getKpiId(), contentConfigDefinition.getCategory(), processingTime, " ContentId :" + contentConfigDefinition.getContentId() + " ContentName :" + contentConfigDefinition.getContentName() + " action :" + contentConfigDefinition.getAction() + " ContentResult :" + contentConfigDefinition.getNoOfResult());
            } else {
                throw new InsightsJobFailedException("Content execution failed");
            }
        } catch (InsightsJobFailedException e) {
            failedContentJobs.add(contentConfig.getContentId());
        }
    }
    return failedContentJobs;
}
Also used : JsonArray(com.google.gson.JsonArray) InsightsJobFailedException(com.cognizant.devops.platformreports.exception.InsightsJobFailedException) InsightsContentConfig(com.cognizant.devops.platformdal.assessmentreport.InsightsContentConfig) ReportPostgresDataHandler(com.cognizant.devops.platformreports.assessment.dal.ReportPostgresDataHandler) ContentConfigDefinition(com.cognizant.devops.platformreports.assessment.datamodel.ContentConfigDefinition)

Aggregations

ContentConfigDefinition (com.cognizant.devops.platformreports.assessment.datamodel.ContentConfigDefinition)3 InsightsContentConfig (com.cognizant.devops.platformdal.assessmentreport.InsightsContentConfig)2 ReportPostgresDataHandler (com.cognizant.devops.platformreports.assessment.dal.ReportPostgresDataHandler)2 InsightsJobFailedException (com.cognizant.devops.platformreports.exception.InsightsJobFailedException)2 ContentExecutor (com.cognizant.devops.platformreports.assessment.content.ContentExecutor)1 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 JsonArray (com.google.gson.JsonArray)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 Callable (java.util.concurrent.Callable)1