Search in sources :

Example 1 with InsightsWorkflowConfiguration

use of com.cognizant.devops.platformdal.workflow.InsightsWorkflowConfiguration in project Insights by CognizantOneDevOps.

the class GrafanaPdfServiceImpl method saveGrafanaDashboardConfig.

/**
 * Used to store grafana dashboard configuration
 *
 *@param dasboardDetails
 *@return
 *@throws InsightsCustomException
 */
@Override
public void saveGrafanaDashboardConfig(JsonObject dashboardDetails) throws InsightsCustomException {
    int id = -1;
    WorkflowServiceImpl workflowService = new WorkflowServiceImpl();
    boolean runImmediate = Boolean.TRUE;
    boolean reoccurence = Boolean.FALSE;
    boolean isActive = Boolean.TRUE;
    try {
        String workflowType = WorkflowTaskEnum.WorkflowType.GRAFANADASHBOARDPDFREPORT.getValue();
        JsonElement scheduleType = dashboardDetails.get(SCHEDULE_TYPE);
        String schedule = scheduleType == null ? WorkflowTaskEnum.WorkflowSchedule.ONETIME.name() : scheduleType.getAsString();
        if (!schedule.equals(WorkflowTaskEnum.WorkflowSchedule.ONETIME.name())) {
            reoccurence = Boolean.TRUE;
        }
        String workflowStatus = WorkflowTaskEnum.WorkflowStatus.NOT_STARTED.name();
        String workflowId = WorkflowTaskEnum.WorkflowType.GRAFANADASHBOARDPDFREPORT.getValue() + "_" + InsightsUtils.getCurrentTimeInSeconds();
        boolean emailEnabled = dashboardDetails.has(EMAIL_DETAILS);
        JsonObject emailDetails = null;
        JsonObject emailDetailsJson = null;
        if (emailEnabled) {
            emailDetails = dashboardDetails.get(EMAIL_DETAILS).getAsJsonObject();
            emailDetailsJson = getEmailDetails(emailDetails);
        }
        JsonArray taskList = new JsonArray();
        JsonArray workflowList = workflowService.getTaskList(workflowType);
        log.debug("Grafana task list from table==={}", workflowList);
        for (JsonElement task : workflowList) {
            JsonObject taskJson = task.getAsJsonObject();
            String componentName = task.getAsJsonObject().get("componentName").getAsString();
            if (!(!emailEnabled && componentName.contains("ReportEmailSubscriber"))) {
                taskList.add(workflowService.createTaskJson(taskJson.get(AssessmentReportAndWorkflowConstants.TASK_ID).getAsInt(), taskJson.get("dependency").getAsInt()));
            }
        }
        log.debug("Grafana task list====={}", taskList);
        InsightsWorkflowConfiguration workflowConfig = workflowService.saveWorkflowConfig(workflowId, isActive, reoccurence, schedule, workflowStatus, WorkflowTaskEnum.WorkflowType.GRAFANADASHBOARDPDFREPORT.getValue(), taskList, 0, emailDetailsJson, runImmediate);
        GrafanaDashboardPdfConfig grafanaDashboardConfig = new GrafanaDashboardPdfConfig();
        grafanaDashboardConfig.setDashboardJson(dashboardDetails.toString());
        grafanaDashboardConfig.setTitle(dashboardDetails.get("title").getAsString());
        grafanaDashboardConfig.setPdfType(dashboardDetails.get("pdfType").getAsString());
        grafanaDashboardConfig.setVariables(dashboardDetails.get("variables").getAsString());
        grafanaDashboardConfig.setWorkflowConfig(workflowConfig);
        grafanaDashboardConfig.setSource(dashboardDetails.get("source").getAsString());
        grafanaDashboardConfig.setScheduleType(dashboardDetails.get(SCHEDULE_TYPE) == null ? WorkflowTaskEnum.WorkflowSchedule.ONETIME.name() : dashboardDetails.get(SCHEDULE_TYPE).getAsString());
        grafanaDashboardConfig.setCreatedDate(InsightsUtils.getCurrentTimeInEpochMilliSeconds());
        grafanaUtilities.generateGrafanaToken(dashboardDetails.get(ORGANISATION).getAsInt());
        id = grafanaDashboardConfigDAL.saveGrafanaDashboardConfig(grafanaDashboardConfig);
        log.debug(id);
    } catch (Exception e) {
        throw new InsightsCustomException(e.getMessage());
    }
}
Also used : JsonArray(com.google.gson.JsonArray) GrafanaDashboardPdfConfig(com.cognizant.devops.platformdal.grafana.pdf.GrafanaDashboardPdfConfig) InsightsCustomException(com.cognizant.devops.platformcommons.exception.InsightsCustomException) JsonElement(com.google.gson.JsonElement) InsightsWorkflowConfiguration(com.cognizant.devops.platformdal.workflow.InsightsWorkflowConfiguration) JsonObject(com.google.gson.JsonObject) InsightsCustomException(com.cognizant.devops.platformcommons.exception.InsightsCustomException) WorkflowServiceImpl(com.cognizant.devops.platformservice.workflow.service.WorkflowServiceImpl)

Example 2 with InsightsWorkflowConfiguration

use of com.cognizant.devops.platformdal.workflow.InsightsWorkflowConfiguration in project Insights by CognizantOneDevOps.

the class GrafanaPdfServiceImpl method updateDashboardPdfConfigStatus.

/**
 * Used to update grafana dashboard configuration status
 *
 *@param dashboardJson
 *@return String
 *@throws InsightsCustomException
 */
@Override
public String updateDashboardPdfConfigStatus(JsonObject dashboardJson) throws InsightsCustomException {
    try {
        int id = dashboardJson.get("id").getAsInt();
        GrafanaDashboardPdfConfig grafanaDashboardPdfConfig = grafanaDashboardConfigDAL.getWorkflowById(id);
        InsightsWorkflowConfiguration workflowConfig = grafanaDashboardPdfConfig.getWorkflowConfig();
        if (dashboardJson.has(AssessmentReportAndWorkflowConstants.STATUS)) {
            String status = dashboardJson.get(AssessmentReportAndWorkflowConstants.STATUS).getAsString();
            workflowConfig.setStatus(status);
            grafanaDashboardPdfConfig.setWorkflowConfig(workflowConfig);
            grafanaDashboardConfigDAL.updateGrafanaDashboardConfig(grafanaDashboardPdfConfig);
        }
        return PlatformServiceConstants.SUCCESS;
    } catch (Exception e) {
        log.error("Error while updating Dashboard status.", e);
        throw new InsightsCustomException(e.getMessage());
    }
}
Also used : GrafanaDashboardPdfConfig(com.cognizant.devops.platformdal.grafana.pdf.GrafanaDashboardPdfConfig) InsightsCustomException(com.cognizant.devops.platformcommons.exception.InsightsCustomException) InsightsWorkflowConfiguration(com.cognizant.devops.platformdal.workflow.InsightsWorkflowConfiguration) InsightsCustomException(com.cognizant.devops.platformcommons.exception.InsightsCustomException)

Example 3 with InsightsWorkflowConfiguration

use of com.cognizant.devops.platformdal.workflow.InsightsWorkflowConfiguration in project Insights by CognizantOneDevOps.

the class WorkflowExecutor method executeWorkflow.

/**
 * Get all ready to run workflow, fetch first workflow task,
 * prepare request message and publish that in RabbitMq
 */
public void executeWorkflow() {
    log.debug(" Worlflow Detail ====  Schedular Inside executeWorkflow  ");
    long startTime = System.nanoTime();
    List<InsightsWorkflowConfiguration> readyToRunWorkflow = workflowProcessing.getReadyToRunWorkFlowConfigs();
    long processingTime = 0;
    if (!readyToRunWorkflow.isEmpty()) {
        for (InsightsWorkflowConfiguration workflowConfig : readyToRunWorkflow) {
            long executionId = System.currentTimeMillis();
            log.debug(" Worlflow Detail ==== workflowid {} executionId {}  ", workflowConfig.getWorkflowId(), executionId);
            InsightsWorkflowTaskSequence firstworkflowTask = workflowProcessing.getWorkflowTaskSequenceByWorkflowId(workflowConfig.getWorkflowId());
            JsonObject mqRequestJson = new JsonObject();
            workflowProcessing.createTaskRequestJson(executionId, workflowConfig.getWorkflowId(), firstworkflowTask.getWorkflowTaskEntity().getTaskId(), firstworkflowTask.getNextTask(), firstworkflowTask.getSequence(), mqRequestJson);
            try {
                Thread.sleep(1);
                log.debug(" Worlflow Detail ==== before publish message executeWorkflow {} ", mqRequestJson);
                workflowProcessing.publishMessageInMQ(firstworkflowTask.getWorkflowTaskEntity().getMqChannel(), mqRequestJson);
                processingTime = TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - startTime);
                log.debug("Type=WorkFlow ExecutionId={}  WorkflowId={}  WorkflowType={} TaskDescription={} TaskMQChannel={} status ={} LastRunTime ={} NextRunTime ={} Schedule={} TaskRetryCount={} isTaskRetry={} processingTime={} message={}", executionId, workflowConfig.getWorkflowId(), workflowConfig.getWorkflowType(), firstworkflowTask.getWorkflowTaskEntity().getDescription(), firstworkflowTask.getWorkflowTaskEntity().getMqChannel(), workflowConfig.getStatus(), workflowConfig.getLastRun(), workflowConfig.getNextRun(), workflowConfig.getScheduleType(), "-", "-", processingTime, "-");
            } catch (WorkflowTaskInitializationException e) {
                log.debug(" Worlflow Detail ====  workflow failed to execute due to MQ exception {}  ", workflowConfig.getWorkflowId());
                InsightsStatusProvider.getInstance().createInsightStatusNode("WorkflowExecutor failed due to exception: " + workflowConfig.getWorkflowId(), PlatformServiceConstants.FAILURE);
                workflowProcessing.updateWorkflowDetails(workflowConfig.getWorkflowId(), WorkflowTaskEnum.WorkflowStatus.TASK_INITIALIZE_ERROR.toString(), false);
                log.error("Type=WorkFlow ExecutionId={}  WorkflowId={}  WorkflowType={} TaskDescription={} TaskMQChannel={} status ={} LastRunTime ={} NextRunTime ={} Schedule={} TaskRetryCount={} isTaskRetry={} processingTime={} message={}", executionId, workflowConfig.getWorkflowId(), workflowConfig.getWorkflowType(), firstworkflowTask.getWorkflowTaskEntity().getDescription(), firstworkflowTask.getWorkflowTaskEntity().getMqChannel(), workflowConfig.getStatus(), workflowConfig.getLastRun(), workflowConfig.getNextRun(), workflowConfig.getScheduleType(), "-", "-", processingTime, e.getMessage());
            } catch (Exception e) {
                log.error(e);
                log.debug(" Worlflow Detail ====  workflow failed to execute due to exception {}  ", workflowConfig.getWorkflowId());
                InsightsStatusProvider.getInstance().createInsightStatusNode("WorkflowExecutor failed due to exception: " + workflowConfig.getWorkflowId(), PlatformServiceConstants.FAILURE);
                workflowProcessing.updateWorkflowDetails(workflowConfig.getWorkflowId(), WorkflowTaskEnum.WorkflowStatus.TASK_INITIALIZE_ERROR.toString(), false);
                log.error("Type=WorkFlow ExecutionId={}  WorkflowId={}  WorkflowType={} TaskDescription={} TaskMQChannel={} status ={} LastRunTime ={} NextRunTime ={} Schedule={} TaskRetryCount={} isTaskRetry={} processingTime={} message={}", executionId, workflowConfig.getWorkflowId(), workflowConfig.getWorkflowType(), firstworkflowTask.getWorkflowTaskEntity().getDescription(), firstworkflowTask.getWorkflowTaskEntity().getMqChannel(), workflowConfig.getStatus(), workflowConfig.getLastRun(), workflowConfig.getNextRun(), workflowConfig.getScheduleType(), "-", "-", processingTime, e.getMessage());
            }
        }
    } else {
        log.debug("Worlflow Detail ==== WorkflowExecutor No reports are currently due for run");
        InsightsStatusProvider.getInstance().createInsightStatusNode(" WorkflowExecutor: No reports are currently due for run ", PlatformServiceConstants.SUCCESS);
    }
}
Also used : InsightsWorkflowTaskSequence(com.cognizant.devops.platformdal.workflow.InsightsWorkflowTaskSequence) InsightsWorkflowConfiguration(com.cognizant.devops.platformdal.workflow.InsightsWorkflowConfiguration) JsonObject(com.google.gson.JsonObject) WorkflowTaskInitializationException(com.cognizant.devops.platformworkflow.workflowtask.exception.WorkflowTaskInitializationException) WorkflowTaskInitializationException(com.cognizant.devops.platformworkflow.workflowtask.exception.WorkflowTaskInitializationException) JobExecutionException(org.quartz.JobExecutionException) InsightsCustomException(com.cognizant.devops.platformcommons.exception.InsightsCustomException)

Example 4 with InsightsWorkflowConfiguration

use of com.cognizant.devops.platformdal.workflow.InsightsWorkflowConfiguration in project Insights by CognizantOneDevOps.

the class WorkflowRetryExecutor method retryWorkflowWithoutHistory.

/**
 * Get all retry record, if Workflow in error state and has none of the tasks
 * completed or failed
 */
private void retryWorkflowWithoutHistory() {
    log.debug(" Worlflow Detail ====  Inside WorkflowRetryExecutor retryWorkflowWithoutHistory ");
    List<InsightsWorkflowConfiguration> readyToRetryWorkflow = workflowProcessing.getReadyToRetryWorkflows();
    log.debug(" Worlflow Detail ==== retryWorkflowWithoutHistory {} ", readyToRetryWorkflow.size());
    if (!readyToRetryWorkflow.isEmpty()) {
        for (InsightsWorkflowConfiguration workflowConfig : readyToRetryWorkflow) {
            long executionId = System.currentTimeMillis();
            long startTime = System.nanoTime();
            log.debug(" Worlflow Detail ==== retryWorkflowWithoutHistory executionId {}  ", executionId);
            InsightsWorkflowTaskSequence firstworkflowTask = workflowProcessing.getWorkflowTaskSequenceByWorkflowId(workflowConfig.getWorkflowId());
            JsonObject mqRequestJson = new JsonObject();
            workflowProcessing.createTaskRequestJson(executionId, workflowConfig.getWorkflowId(), firstworkflowTask.getWorkflowTaskEntity().getTaskId(), firstworkflowTask.getNextTask(), firstworkflowTask.getSequence(), mqRequestJson);
            try {
                Thread.sleep(1);
                log.debug(" Worlflow Detail ==== before publish message retryWorkflowWithoutHistory {} ", mqRequestJson);
                workflowProcessing.publishMessageInMQ(firstworkflowTask.getWorkflowTaskEntity().getMqChannel(), mqRequestJson);
                long processingTime = TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - startTime);
                log.debug("Type=WorkFlow ExecutionId={}  WorkflowId={}  WorkflowType={} status ={}" + " LastRunTime ={} NextRunTime ={} Schedule ={}   TaskDescription={}  TaskMQChannel={} " + "TaskRetryCount={} RetryType ={}  processingTime={} message={}", executionId, workflowConfig.getWorkflowId(), workflowConfig.getWorkflowType(), "-", workflowConfig.getLastRun(), workflowConfig.getNextRun(), workflowConfig.getScheduleType(), firstworkflowTask.getWorkflowTaskEntity().getDescription(), firstworkflowTask.getWorkflowTaskEntity().getMqChannel(), "-", "WorkflowWithoutHistory", processingTime, "-");
            } catch (WorkflowTaskInitializationException | InterruptedException e) {
                log.debug("Type=WorkFlow ExecutionId={}  WorkflowId={}  WorkflowType={} " + " status ={} LastRunTime ={} NextRunTime ={} Schedule ={}   TaskDescription={} " + " TaskMQChannel={} TaskRetryCount={} RetryType ={}  processingTime={} message={}", executionId, workflowConfig.getWorkflowId(), workflowConfig.getWorkflowType(), "-", workflowConfig.getLastRun(), workflowConfig.getNextRun(), workflowConfig.getScheduleType(), firstworkflowTask.getWorkflowTaskEntity().getDescription(), firstworkflowTask.getWorkflowTaskEntity().getMqChannel(), "-", "WorkflowWithoutHistory", 0, e.getMessage());
                log.debug(" Worlflow Detail ==== retryWorkflowWithoutHistory workflow failed to execute due to MQ exception {}  ", workflowConfig.getWorkflowId());
                InsightsStatusProvider.getInstance().createInsightStatusNode("In WorkflowRetryExecutor,retryWorkflowWithoutHistory failed due to exception. WorkflowId: " + workflowConfig.getWorkflowId(), PlatformServiceConstants.FAILURE);
                log.debug("Type=WorkFlow ExecutionId={}  WorkflowId={}  WorkflowType={} " + " status ={} LastRunTime ={} NextRunTime ={} Schedule ={}   TaskDescription={}  TaskMQChannel={} " + "TaskRetryCount={} RetryType ={}  processingTime={} message={}", executionId, workflowConfig.getWorkflowId(), workflowConfig.getWorkflowType(), "Failure", workflowConfig.getLastRun(), workflowConfig.getNextRun(), workflowConfig.getScheduleType(), firstworkflowTask.getWorkflowTaskEntity().getDescription(), firstworkflowTask.getWorkflowTaskEntity().getMqChannel(), "-", "WorkflowWithoutHistory", 0, e.getMessage());
            }
        }
    } else {
        log.debug("Worlflow Detail ====  WorkflowRetryExecutor No retry workflows are currently on due to run");
    }
}
Also used : InsightsWorkflowTaskSequence(com.cognizant.devops.platformdal.workflow.InsightsWorkflowTaskSequence) InsightsWorkflowConfiguration(com.cognizant.devops.platformdal.workflow.InsightsWorkflowConfiguration) JsonObject(com.google.gson.JsonObject) WorkflowTaskInitializationException(com.cognizant.devops.platformworkflow.workflowtask.exception.WorkflowTaskInitializationException)

Example 5 with InsightsWorkflowConfiguration

use of com.cognizant.devops.platformdal.workflow.InsightsWorkflowConfiguration in project Insights by CognizantOneDevOps.

the class WorkflowTest method testWrongTaskStatusUpdate.

// if workflow task is not initialized or subscribed properly
@Test(priority = 5)
public void testWrongTaskStatusUpdate() {
    try {
        InsightsWorkflowConfiguration workflowConfig = workflowDAL.getWorkflowConfigByWorkflowId(WorkflowIdWrongTask);
        Assert.assertEquals(workflowConfig.getStatus(), "TASK_INITIALIZE_ERROR");
        Assert.assertTrue(workflowConfig.getNextRun() == nextRunDaily);
    } catch (AssertionError e) {
        Assert.fail(e.getMessage());
    }
}
Also used : InsightsWorkflowConfiguration(com.cognizant.devops.platformdal.workflow.InsightsWorkflowConfiguration) PlatformWorkflowApplicationTest(com.cognizant.devops.platformworkflow.workflowtask.utils.PlatformWorkflowApplicationTest) Test(org.testng.annotations.Test)

Aggregations

InsightsWorkflowConfiguration (com.cognizant.devops.platformdal.workflow.InsightsWorkflowConfiguration)55 InsightsCustomException (com.cognizant.devops.platformcommons.exception.InsightsCustomException)23 JsonObject (com.google.gson.JsonObject)17 Test (org.testng.annotations.Test)16 IOException (java.io.IOException)12 JsonArray (com.google.gson.JsonArray)11 InsightsWorkflowTaskSequence (com.cognizant.devops.platformdal.workflow.InsightsWorkflowTaskSequence)9 InsightsAssessmentConfiguration (com.cognizant.devops.platformdal.assessmentreport.InsightsAssessmentConfiguration)7 InsightsAssessmentReportTemplate (com.cognizant.devops.platformdal.assessmentreport.InsightsAssessmentReportTemplate)6 InsightsEmailTemplates (com.cognizant.devops.platformdal.assessmentreport.InsightsEmailTemplates)6 WorkflowTaskInitializationException (com.cognizant.devops.platformworkflow.workflowtask.exception.WorkflowTaskInitializationException)6 InsightsReportVisualizationContainer (com.cognizant.devops.platformdal.assessmentreport.InsightsReportVisualizationContainer)5 GrafanaDashboardPdfConfig (com.cognizant.devops.platformdal.grafana.pdf.GrafanaDashboardPdfConfig)5 PlatformWorkflowApplicationTest (com.cognizant.devops.platformworkflow.workflowtask.utils.PlatformWorkflowApplicationTest)5 JsonElement (com.google.gson.JsonElement)5 InsightsWorkflowExecutionHistory (com.cognizant.devops.platformdal.workflow.InsightsWorkflowExecutionHistory)4 InsightsWorkflowTask (com.cognizant.devops.platformdal.workflow.InsightsWorkflowTask)4 WorkflowServiceImpl (com.cognizant.devops.platformservice.workflow.service.WorkflowServiceImpl)4 AddressException (javax.mail.internet.AddressException)4 NoResultException (javax.persistence.NoResultException)4