Search in sources :

Example 36 with InsightsJobFailedException

use of com.cognizant.devops.platformreports.exception.InsightsJobFailedException in project Insights by CognizantOneDevOps.

the class ComparisonContentCategoryImpl method getContentFromResult.

/**
 * process KPI result based on comparison category to generate content object
 *
 * @param kpiResultDetailsList
 * @return
 */
public InsightsContentDetail getContentFromResult(List<InsightsKPIResultDetails> kpiResultDetailsList) {
    InsightsContentDetail inferenceContentResult = null;
    try {
        long startTime = System.nanoTime();
        InsightsKPIResultDetails resultFirstData = kpiResultDetailsList.get(0);
        String actualTrend = ReportEngineEnum.KPITrends.NOCHANGE.getValue();
        ReportEngineEnum.KPISentiment sentiment = ReportEngineEnum.KPISentiment.NEUTRAL;
        Map<String, Object> resultValuesMap = resultFirstData.getResults();
        String contentText = "";
        String comparisonField = getResultFieldFromContentDefination();
        Object currentValue = resultFirstData.getResults().get(comparisonField);
        // This condition will be executed if KPI comparison is FALSE
        if (getContentConfig().getCategory() == ReportEngineEnum.ContentCategory.COMPARISON) {
            if (kpiResultDetailsList.size() < 2) {
                return setNeutralContentDetail();
            }
            InsightsKPIResultDetails previousDateData = kpiResultDetailsList.get(1);
            Object previousValue = previousDateData.getResults().get(comparisonField);
            sentiment = getSentiment(previousValue, currentValue, getContentConfig().getExpectedTrend());
            actualTrend = String.valueOf(getActualTrend(getContentConfig().getExpectedTrend(), sentiment));
            resultValuesMap.put("current:" + comparisonField, getResultValueForDisplay(currentValue));
            resultValuesMap.put("previous:" + comparisonField, getResultValueForDisplay(previousValue));
            contentText = getContentText(sentiment.getValue(), resultValuesMap);
        } else if (getContentConfig().getCategory() == ReportEngineEnum.ContentCategory.STANDARD) {
            log.debug("Worlflow Detail ====  record {} value for STANDARD category is  {} ", comparisonField, currentValue);
            if (currentValue != null && (String.valueOf(currentValue).equalsIgnoreCase("0.0") || String.valueOf(currentValue).equalsIgnoreCase("0") || String.valueOf(currentValue).equalsIgnoreCase(""))) {
                contentText = getContentText(ReportEngineUtils.NEUTRAL_MESSAGE_KEY, resultValuesMap);
            } else {
                contentText = getContentText(ReportEngineUtils.STANDARD_MESSAGE_KEY, resultValuesMap);
            }
        }
        if (contentText != null) {
            inferenceContentResult = setContentDetail(resultFirstData, resultValuesMap, sentiment, actualTrend, contentText);
        } else {
            log.debug("Worlflow Detail ====  content text is null in comparison KPI KPIId {} contentId {} result {} ", contentConfigDefinition.getKpiId(), contentConfigDefinition.getContentId(), resultFirstData);
        }
        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());
    } catch (Exception e) {
        log.error(e);
        log.error("Worlflow Detail ====  Error while content processing comparison  KPIId {} contentId {} ", contentConfigDefinition.getKpiId(), contentConfigDefinition.getContentId());
        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() + " Error while content processing comparison " + e.getMessage());
        throw new InsightsJobFailedException("Error while content processing comparison  KPIId {} contentId {} " + e.getMessage());
    }
    return inferenceContentResult;
}
Also used : InsightsKPIResultDetails(com.cognizant.devops.platformreports.assessment.datamodel.InsightsKPIResultDetails) InsightsJobFailedException(com.cognizant.devops.platformreports.exception.InsightsJobFailedException) ReportEngineEnum(com.cognizant.devops.platformreports.assessment.util.ReportEngineEnum) InsightsJobFailedException(com.cognizant.devops.platformreports.exception.InsightsJobFailedException) InsightsContentDetail(com.cognizant.devops.platformreports.assessment.datamodel.InsightsContentDetail)

Example 37 with InsightsJobFailedException

use of com.cognizant.devops.platformreports.exception.InsightsJobFailedException in project Insights by CognizantOneDevOps.

the class MilestoneCommunicationSubscriber method handleTaskExecution.

@Override
public void handleTaskExecution(byte[] body) throws IOException {
    String incomingTaskMessage = new String(body, StandardCharsets.UTF_8);
    log.debug("Worlflow Detail ==== MilestoneCommunicationSubscriber started ... " + "routing key  message handleDelivery ===== {} ", incomingTaskMessage);
    JsonObject incomingTaskMessageJson = JsonUtils.parseStringAsJsonObject(incomingTaskMessage);
    String workflowId = incomingTaskMessageJson.get("workflowId").getAsString();
    String routingKey = MQMessageConstants.MILESTONE_STATUS_QUEUE.replace("_", ".");
    Channel channel;
    try {
        channel = RabbitMQConnectionProvider.getChannel(routingKey, MQMessageConstants.MILESTONE_STATUS_QUEUE, MQMessageConstants.EXCHANGE_NAME, MQMessageConstants.EXCHANGE_TYPE);
        setChannel(channel);
        log.debug("prefetchCount {} for routingKey {} ", ApplicationConfigProvider.getInstance().getMessageQueue().getPrefetchCount(), routingKey);
        Consumer consumer = new DefaultConsumer(channel) {

            @Override
            public void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties, byte[] statusbody) throws IOException {
                try {
                    String incomingStatusMessage = new String(statusbody, StandardCharsets.UTF_8);
                    log.debug(" ROI execution incomingStatusMessage : {}", incomingStatusMessage);
                    JsonObject incomingStatusMessageJson = JsonUtils.parseStringAsJsonObject(incomingStatusMessage);
                    int milestoneId = incomingStatusMessageJson.get("milestoneId").getAsInt();
                    int outcomeId = incomingStatusMessageJson.get("outcomeId").getAsInt();
                    String status = incomingStatusMessageJson.get("status").getAsString();
                    String message = incomingStatusMessageJson.get("message").getAsString();
                    mileStoneConfigDAL.updateMilestoneOutcomeStatus(milestoneId, outcomeId, status, message);
                    MileStoneConfig mileStoneConfig = mileStoneConfigDAL.getMileStoneConfigById(milestoneId);
                    boolean updateFlag = mileStoneConfig.getListOfOutcomes().stream().allMatch(outcome -> outcome.getStatus().equalsIgnoreCase("SUCCESS"));
                    boolean updateErrorFlag = mileStoneConfig.getListOfOutcomes().stream().anyMatch(outcome -> outcome.getStatus().equalsIgnoreCase("ERROR"));
                    if (updateFlag) {
                        mileStoneConfigDAL.updateMilestoneStatus(milestoneId, MilestoneEnum.MilestoneStatus.COMPLETED.name());
                    } else if (updateErrorFlag) {
                        mileStoneConfigDAL.updateMilestoneStatus(milestoneId, MilestoneEnum.MilestoneStatus.ERROR.name());
                    } else {
                        mileStoneConfigDAL.updateMilestoneStatus(milestoneId, MilestoneEnum.MilestoneStatus.IN_PROGRESS.name());
                    }
                    getChannel().basicAck(envelope.getDeliveryTag(), false);
                } catch (Exception e) {
                    log.error("Error : ", e);
                }
            }
        };
        channel.basicConsume(MQMessageConstants.MILESTONE_STATUS_QUEUE, false, routingKey, consumer);
    } catch (Exception e) {
        log.error("Worlflow Detail ==== MilestoneCommunicationSubscriber Completed with error ", e);
        throw new InsightsJobFailedException(e.getMessage());
    }
}
Also used : InsightsJobFailedException(com.cognizant.devops.platformreports.exception.InsightsJobFailedException) DefaultConsumer(com.rabbitmq.client.DefaultConsumer) Consumer(com.rabbitmq.client.Consumer) DefaultConsumer(com.rabbitmq.client.DefaultConsumer) Channel(com.rabbitmq.client.Channel) JsonObject(com.google.gson.JsonObject) MileStoneConfig(com.cognizant.devops.platformdal.milestone.MileStoneConfig) Envelope(com.rabbitmq.client.Envelope) IOException(java.io.IOException) InsightsJobFailedException(com.cognizant.devops.platformreports.exception.InsightsJobFailedException) InsightsCustomException(com.cognizant.devops.platformcommons.exception.InsightsCustomException)

Example 38 with InsightsJobFailedException

use of com.cognizant.devops.platformreports.exception.InsightsJobFailedException in project Insights by CognizantOneDevOps.

the class PDFExecutionSubscriber method handleTaskExecution.

@Override
public void handleTaskExecution(byte[] body) throws IOException {
    try {
        long startTime = System.nanoTime();
        String incomingTaskMessage = new String(body, MQMessageConstants.MESSAGE_ENCODING);
        log.debug("Worlflow Detail ==== PDFExecutionSubscriber started ... routing key  message handleDelivery ===== {} ", incomingTaskMessage);
        assessmentReportDTO = new InsightsAssessmentConfigurationDTO();
        JsonObject incomingTaskMessageJson = JsonUtils.parseStringAsJsonObject(incomingTaskMessage);
        prepareVisualizationJsonBasedOnKPIResult(incomingTaskMessageJson);
        processVisualizationJson();
        setPDFDetailsInEmailHistory(incomingTaskMessageJson);
        log.debug("Worlflow Detail ==== PDFExecutionSubscriber Completed  {} ", incomingTaskMessage);
        InsightsStatusProvider.getInstance().createInsightStatusNode("PDFExecutionSubscriber completed", PlatformServiceConstants.SUCCESS);
        long processingTime = TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - startTime);
        log.debug("Type=TaskExecution  executionId={} workflowId={} ConfigId={} WorkflowType={} KpiId={} Category={} ProcessingTime={} message={}", assessmentReportDTO.getExecutionId(), assessmentReportDTO.getWorkflowId(), assessmentReportDTO.getConfigId(), "-", "-", "-", processingTime, "reportId: " + assessmentReportDTO.getReportId() + "reportName: " + assessmentReportDTO.getReportName() + "VisualizationUtil" + assessmentReportDTO.getVisualizationutil() + "PDFExecutionSubscriber Completed ");
    } catch (InsightsJobFailedException ijfe) {
        log.error("Worlflow Detail ==== PDFExecutionSubscriber Completed with error ", ijfe);
        InsightsStatusProvider.getInstance().createInsightStatusNode("PDFExecutionSubscriber Completed with error " + ijfe.getMessage(), PlatformServiceConstants.FAILURE);
        statusLog = ijfe.getMessage();
        log.error("Type=TaskExecution  executionId={} workflowId={} ConfigId={} WorkflowType={} KpiId={} Category={} ProcessingTime={} message={}", assessmentReportDTO.getExecutionId(), assessmentReportDTO.getWorkflowId(), assessmentReportDTO.getConfigId(), "-", "-", "-", 0, "reportId: " + assessmentReportDTO.getReportId() + "reportName: " + assessmentReportDTO.getReportName() + "VisualizationUtil" + assessmentReportDTO.getVisualizationutil() + "PDFExecutionSubscriber Completed with error " + ijfe.getMessage());
        throw ijfe;
    } catch (Exception e) {
        log.error("Worlflow Detail ==== PDFExecutionSubscriber Completed with error ", e);
        InsightsStatusProvider.getInstance().createInsightStatusNode("PDFExecutionSubscriber Completed with error " + e.getMessage(), PlatformServiceConstants.FAILURE);
        log.error("Type=TaskExecution  executionId={} workflowId={} ConfigId={} WorkflowType={} KpiId={} Category={} ProcessingTime={} message={}", assessmentReportDTO.getExecutionId(), assessmentReportDTO.getWorkflowId(), assessmentReportDTO.getConfigId(), "-", "-", "-", 0, "reportId: " + assessmentReportDTO.getReportId() + "reportName: " + assessmentReportDTO.getReportName() + "VisualizationUtil" + assessmentReportDTO.getVisualizationutil() + "PDFExecutionSubscriber Completed with error " + e.getMessage());
        throw new InsightsJobFailedException(e.getMessage());
    }
}
Also used : InsightsJobFailedException(com.cognizant.devops.platformreports.exception.InsightsJobFailedException) JsonObject(com.google.gson.JsonObject) InsightsAssessmentConfigurationDTO(com.cognizant.devops.platformreports.assessment.datamodel.InsightsAssessmentConfigurationDTO) InsightsJobFailedException(com.cognizant.devops.platformreports.exception.InsightsJobFailedException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException)

Example 39 with InsightsJobFailedException

use of com.cognizant.devops.platformreports.exception.InsightsJobFailedException in project Insights by CognizantOneDevOps.

the class UpshiftAssessmentExecutionSubscriber method handleTaskExecution.

@Override
public void handleTaskExecution(byte[] body) throws IOException {
    try {
        long startTime = System.nanoTime();
        String incomingTaskMessage = new String(body, StandardCharsets.UTF_8);
        log.debug("Worlflow Detail ==== UpshiftAssessmentExecutionSubscriber started ... " + "routing key  message handleDelivery ===== {} ", incomingTaskMessage);
        JsonObject incomingTaskMessageJson = JsonUtils.parseStringAsJsonObject(incomingTaskMessage);
        String workflowId = incomingTaskMessageJson.get("workflowId").getAsString();
        long executionId = incomingTaskMessageJson.get("executionId").getAsLong();
        workflowConfig = workflowDAL.getWorkflowConfigByWorkflowId(workflowId);
        log.debug("Worlflow Detail ==== scheduleType {} ", workflowConfig.getScheduleType());
        assessmentReportDTO = new InsightsAssessmentConfigurationDTO();
        assessmentReportDTO.setIncomingTaskMessageJson(incomingTaskMessage);
        assessmentReportDTO.setAsseementreportname(WorkflowTaskEnum.WorkflowType.UPSHIFTASSESSMENT.getValue());
        assessmentReportDTO.setExecutionId(executionId);
        assessmentReportDTO.setWorkflowId(workflowId);
        BaseDataProcessor chartHandler = ReportDataProcessHandlerFactory.getDataHandler("UPSHIFTASSESSMENT");
        chartHandler.processJson(assessmentReportDTO);
        long processingTime = TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - startTime);
        log.debug("Type=TaskExecution  executionId={} workflowId={} ConfigId={} WorkflowType={} KpiId={} Category={} ProcessingTime={} message={}", executionId, workflowId, assessmentReportDTO.getReportId(), workflowConfig.getWorkflowType(), "-", "-", processingTime, "Schedule :" + workflowConfig.getScheduleType() + "ReportName :" + assessmentReportDTO.getReportName() + "UpshiftAssessmentExecutionSubscriber Block");
    } catch (Exception e) {
        log.error("Worlflow Detail ==== GrafanaPDFExecutionSubscriber Completed with error ", e);
        log.error("Type=TaskExecution  executionId={} workflowId={} ConfigId={} WorkflowType={} KpiId={} Category={} ProcessingTime={} message={}", assessmentReportDTO.getExecutionId(), assessmentReportDTO.getWorkflowId(), assessmentReportDTO.getReportId(), workflowConfig.getWorkflowType(), "-", "-", 0, "Schedule :" + workflowConfig.getScheduleType() + "ReportName :" + assessmentReportDTO.getReportName() + "GrafanaPDFExecutionSubscriber Completed with error" + e.getMessage());
        throw new InsightsJobFailedException(e.getMessage());
    }
}
Also used : BaseDataProcessor(com.cognizant.devops.platformreports.assessment.dataprocess.BaseDataProcessor) InsightsJobFailedException(com.cognizant.devops.platformreports.exception.InsightsJobFailedException) JsonObject(com.google.gson.JsonObject) InsightsAssessmentConfigurationDTO(com.cognizant.devops.platformreports.assessment.datamodel.InsightsAssessmentConfigurationDTO) TimeoutException(java.util.concurrent.TimeoutException) IOException(java.io.IOException) InsightsJobFailedException(com.cognizant.devops.platformreports.exception.InsightsJobFailedException) InsightsCustomException(com.cognizant.devops.platformcommons.exception.InsightsCustomException)

Example 40 with InsightsJobFailedException

use of com.cognizant.devops.platformreports.exception.InsightsJobFailedException in project Insights by CognizantOneDevOps.

the class UpshiftAssessmentHandler method processJson.

/**
 * Process the stored json based on the type of data
 * @param assessmentReportDTO
 */
@Override
public void processJson(InsightsAssessmentConfigurationDTO assessmentReportDTO) {
    JsonElement element = null;
    UpshiftAssessmentConfig upshiftAssessmentConfig = upshiftAssessmentConfigDAL.fetchUpshiftAssessmentDetailsByWorkflowId(assessmentReportDTO.getWorkflowId());
    try {
        long startTime = System.nanoTime();
        byte[] upshiftFileBytes = upshiftAssessmentConfig.getFile();
        String uuid = upshiftAssessmentConfig.getUpshiftUuid();
        String fileString = new String(upshiftFileBytes, StandardCharsets.ISO_8859_1);
        Map<?, ?> map = gson.fromJson(fileString, Map.class);
        List<JsonObject> dataList = new ArrayList<>();
        JsonObject primaryKey = new JsonObject();
        String primKey = String.valueOf(System.currentTimeMillis());
        primaryKey.addProperty("insightsTime", primKey);
        primaryKey.addProperty("toolName", "UPSHIFT");
        primaryKey.addProperty("categoryName", "INSIGHTSUPSHIFT");
        primaryKey.addProperty("jenkinsExecutionId", upshiftAssessmentConfig.getJenkinsExecId());
        dataList.add(primaryKey);
        if (createNode("DATA", dataList)) {
            flag = Boolean.FALSE;
        }
        for (Map.Entry<?, ?> entry : map.entrySet()) {
            element = JsonUtils.parseString(gson.toJson(entry.getValue()));
            if (element.isJsonPrimitive() && updateNode(primKey, entry.getKey().toString(), element.getAsString())) {
                flag = Boolean.FALSE;
            } else if (element.isJsonObject()) {
                createObjectNode(uuid, primKey, entry.getKey().toString(), element.getAsJsonObject());
            } else if (element.isJsonArray()) {
                parseJsonArray(uuid, primKey, entry.getKey().toString(), element.getAsJsonArray());
            }
        }
        log.debug("Completed processing of upshift report: {}", upshiftAssessmentConfig.getFileName());
        log.debug("Total nodes created: {}", numOfNodes);
        updateReportStatus(upshiftAssessmentConfig);
        long processingTime = TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - startTime);
        log.debug("Type=TaskExecution  executionId={} workflowId={} ConfigId={} WorkflowType={} KpiId={} Category={} ProcessingTime={} message={}", assessmentReportDTO.getExecutionId(), assessmentReportDTO.getWorkflowId(), assessmentReportDTO.getReportId(), upshiftAssessmentConfig.getWorkflowConfig().getWorkflowType(), "-", "-", processingTime, "UpshiftUuid :" + upshiftAssessmentConfig.getUpshiftUuid() + "CreatedDate :" + upshiftAssessmentConfig.getCreatedDate() + "UpdatedDate :" + upshiftAssessmentConfig.getUpdatedDate() + "fileName :" + upshiftAssessmentConfig.getFileName() + "status :" + upshiftAssessmentConfig.getStatus() + "Completed processing of upshift report");
    } catch (Exception e) {
        log.error(e.getStackTrace());
        log.error("Type=TaskExecution  executionId={} workflowId={} ConfigId={} WorkflowType={} KpiId={} Category={} ProcessingTime={} message={}", assessmentReportDTO.getExecutionId(), assessmentReportDTO.getWorkflowId(), assessmentReportDTO.getReportId(), upshiftAssessmentConfig.getWorkflowConfig().getWorkflowType(), "-", "-", 0, "UpshiftUuid :" + upshiftAssessmentConfig.getUpshiftUuid() + "CreatedDate :" + upshiftAssessmentConfig.getCreatedDate() + "UpdatedDate :" + upshiftAssessmentConfig.getUpdatedDate() + "fileName :" + upshiftAssessmentConfig.getFileName() + "status :" + upshiftAssessmentConfig.getStatus() + element.getAsString() + e.getMessage());
        throw new InsightsJobFailedException(e.getMessage());
    }
}
Also used : ArrayList(java.util.ArrayList) InsightsJobFailedException(com.cognizant.devops.platformreports.exception.InsightsJobFailedException) InsightsCustomException(com.cognizant.devops.platformcommons.exception.InsightsCustomException) InsightsJobFailedException(com.cognizant.devops.platformreports.exception.InsightsJobFailedException) UpshiftAssessmentConfig(com.cognizant.devops.platformdal.upshiftassessment.UpshiftAssessmentConfig) Map(java.util.Map)

Aggregations

InsightsJobFailedException (com.cognizant.devops.platformreports.exception.InsightsJobFailedException)63 IOException (java.io.IOException)31 JsonObject (com.google.gson.JsonObject)29 InsightsCustomException (com.cognizant.devops.platformcommons.exception.InsightsCustomException)21 ArrayList (java.util.ArrayList)16 File (java.io.File)14 JsonArray (com.google.gson.JsonArray)12 HashMap (java.util.HashMap)11 InsightsKPIResultDetails (com.cognizant.devops.platformreports.assessment.datamodel.InsightsKPIResultDetails)8 List (java.util.List)8 InsightsContentDetail (com.cognizant.devops.platformreports.assessment.datamodel.InsightsContentDetail)7 ReportEngineEnum (com.cognizant.devops.platformreports.assessment.util.ReportEngineEnum)7 ExecutionException (java.util.concurrent.ExecutionException)7 ContentConfigDefinition (com.cognizant.devops.platformreports.assessment.datamodel.ContentConfigDefinition)6 InsightsAssessmentConfigurationDTO (com.cognizant.devops.platformreports.assessment.datamodel.InsightsAssessmentConfigurationDTO)5 FileNotFoundException (java.io.FileNotFoundException)5 NoSuchFileException (java.nio.file.NoSuchFileException)5 Map (java.util.Map)5 InsightsContentConfig (com.cognizant.devops.platformdal.assessmentreport.InsightsContentConfig)4 InsightsReportVisualizationContainer (com.cognizant.devops.platformdal.assessmentreport.InsightsReportVisualizationContainer)4