Search in sources :

Example 1 with InsightsWorkflowExecutionHistory

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

the class WorkflowTest method testStatusUpdateWith2Task.

@Test(priority = 6)
public void testStatusUpdateWith2Task() {
    try {
        InsightsWorkflowConfiguration workflowConfig = workflowDAL.getWorkflowConfigByWorkflowId(WorkflowIdWith2Task);
        Assert.assertEquals(workflowConfig.getStatus(), "ERROR");
        int task1 = getTaskId(mqChannel);
        List<InsightsWorkflowExecutionHistory> executionHistory = workflowDAL.getWorkflowExecutionHistoryRecordsByWorkflowId(WorkflowIdWith2Task);
        if (executionHistory.size() > 0) {
            for (InsightsWorkflowExecutionHistory eachExecutionRecord : executionHistory) {
                if (eachExecutionRecord.getCurrenttask() == task1) {
                    Assert.assertEquals(eachExecutionRecord.getTaskStatus(), "COMPLETED");
                } else {
                    Assert.assertEquals(eachExecutionRecord.getTaskStatus(), "ERROR");
                }
            }
        }
    } catch (AssertionError e) {
        Assert.fail(e.getMessage());
    }
}
Also used : InsightsWorkflowConfiguration(com.cognizant.devops.platformdal.workflow.InsightsWorkflowConfiguration) InsightsWorkflowExecutionHistory(com.cognizant.devops.platformdal.workflow.InsightsWorkflowExecutionHistory) PlatformWorkflowApplicationTest(com.cognizant.devops.platformworkflow.workflowtask.utils.PlatformWorkflowApplicationTest) Test(org.testng.annotations.Test)

Example 2 with InsightsWorkflowExecutionHistory

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

the class WorkflowTest method testWorkflowRetryCount.

@Test(priority = 7)
public void testWorkflowRetryCount() throws InterruptedException {
    try {
        WorkflowRetryExecutor retryExecutor = new WorkflowRetryExecutor();
        retryExecutor.retryWorkflows();
        Thread.sleep(1000);
        List<InsightsWorkflowExecutionHistory> executionHistory = workflowDAL.getWorkflowExecutionHistoryRecordsByWorkflowId(failWorkflowId);
        if (executionHistory.size() > 0) {
            for (InsightsWorkflowExecutionHistory eachExecutionRecord : executionHistory) {
                Assert.assertTrue(eachExecutionRecord.getRetryCount() > 0);
                Assert.assertEquals(eachExecutionRecord.getTaskStatus(), "ERROR");
            }
        }
    } catch (AssertionError e) {
        Assert.fail(e.getMessage());
    }
}
Also used : WorkflowRetryExecutor(com.cognizant.devops.platformworkflow.workflowtask.core.WorkflowRetryExecutor) InsightsWorkflowExecutionHistory(com.cognizant.devops.platformdal.workflow.InsightsWorkflowExecutionHistory) PlatformWorkflowApplicationTest(com.cognizant.devops.platformworkflow.workflowtask.utils.PlatformWorkflowApplicationTest) Test(org.testng.annotations.Test)

Example 3 with InsightsWorkflowExecutionHistory

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

the class WorkflowServiceTestData method updateWorkflowExecutionHistory.

public int updateWorkflowExecutionHistory(String workflowId, int taskId) {
    InsightsWorkflowConfiguration workflowConfig = workflowConfigDAL.getWorkflowConfigByWorkflowId(workflowId);
    InsightsWorkflowExecutionHistory historyConfig = new InsightsWorkflowExecutionHistory();
    historyConfig.setCurrenttask(taskId);
    historyConfig.setExecutionId(System.currentTimeMillis());
    historyConfig.setWorkflowConfig(workflowConfig);
    historyConfig.setTaskStatus(WorkflowTaskEnum.WorkflowStatus.NOT_STARTED.toString());
    historyConfig.setStatusLog("Testing");
    int historyId = workflowConfigDAL.saveTaskworkflowExecutionHistory(historyConfig);
    return historyId;
}
Also used : InsightsWorkflowConfiguration(com.cognizant.devops.platformdal.workflow.InsightsWorkflowConfiguration) InsightsWorkflowExecutionHistory(com.cognizant.devops.platformdal.workflow.InsightsWorkflowExecutionHistory)

Example 4 with InsightsWorkflowExecutionHistory

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

the class WorkflowRetryExecutor method retryWorkflowWithCompletedTask.

/**
 * Gell all rerty record if Workflow in error state and atleast one of the tasks
 * is completed and none is in error state
 */
private void retryWorkflowWithCompletedTask() {
    log.debug(" Worlflow Detail ====  Inside WorkflowRetryExecutor retryWorkflowWithCompletedTask ");
    List<InsightsWorkflowExecutionHistory> readyToRunWorkflowHistory = workflowProcessing.getNextTasksForRetry();
    for (InsightsWorkflowExecutionHistory lastCompletedTaskExecution : readyToRunWorkflowHistory) {
        long startTime = System.nanoTime();
        JsonObject mqRetryJsonObject = JsonUtils.parseStringAsJsonObject(lastCompletedTaskExecution.getRequestMessage());
        mqRetryJsonObject.addProperty("exectionHistoryId", lastCompletedTaskExecution.getId());
        String message = new Gson().toJson(mqRetryJsonObject);
        Map<String, Object> requestMessage = WorkflowUtils.convertJsonObjectToMap(message);
        log.debug(" Worlflow Detail  ==== Inside WorkflowRetryExecutor retryWorkflowWithCompletedTask Retry flow workflowHistory {}  ", lastCompletedTaskExecution);
        try {
            workflowProcessing.publishMessageToNextInMQ(requestMessage);
            long processingTime = TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - startTime);
            log.debug("Type=WorkFlow ExecutionId={}  WorkflowId={}  WorkflowType={} TaskDescription={} TaskMQChannel={} status ={} LastRunTime ={} NextRunTime ={} Schedule ={} TaskRetryCount={} RetryType ={} isTaskRetry={} processingTime={} message={}", lastCompletedTaskExecution.getExecutionId(), lastCompletedTaskExecution.getWorkflowConfig().getWorkflowId(), lastCompletedTaskExecution.getWorkflowConfig().getWorkflowType(), "-", "-", lastCompletedTaskExecution.getTaskStatus(), lastCompletedTaskExecution.getWorkflowConfig().getLastRun(), "-", lastCompletedTaskExecution.getWorkflowConfig().getScheduleType(), lastCompletedTaskExecution.getRetryCount(), "-", "WorkflowWithCompletedTask", processingTime, "-");
            log.debug(StringExpressionConstants.STR_EXP_WORKFLOW_4 + StringExpressionConstants.STR_EXP_TASKRETRYCOUNT, lastCompletedTaskExecution.getExecutionId(), lastCompletedTaskExecution.getWorkflowConfig().getWorkflowId(), lastCompletedTaskExecution.getWorkflowConfig().getLastRun(), lastCompletedTaskExecution.getWorkflowConfig().getNextRun(), lastCompletedTaskExecution.getWorkflowConfig().getScheduleType(), mqRetryJsonObject.get(WorkflowUtils.RETRY_JSON_PROPERTY).getAsString(), lastCompletedTaskExecution.getRetryCount(), "-", "-", lastCompletedTaskExecution.getWorkflowConfig().getWorkflowType(), processingTime, lastCompletedTaskExecution.getTaskStatus(), "Inside WorkflowRetryExecutor retryWorkflowWithCompletedTask Retry flow workflowHistory");
        } catch (WorkflowTaskInitializationException e) {
            log.error(" Worlflow Detail  ====  workflow failed to retry and will be picked up in next retry schedule  {} ", lastCompletedTaskExecution);
            log.error(StringExpressionConstants.STR_EXP_WORKFLOW_4 + StringExpressionConstants.STR_EXP_TASKRETRYCOUNT, lastCompletedTaskExecution.getExecutionId(), lastCompletedTaskExecution.getWorkflowConfig().getWorkflowId(), lastCompletedTaskExecution.getWorkflowConfig().getLastRun(), lastCompletedTaskExecution.getWorkflowConfig().getNextRun(), lastCompletedTaskExecution.getWorkflowConfig().getScheduleType(), mqRetryJsonObject.get(WorkflowUtils.RETRY_JSON_PROPERTY).getAsString(), lastCompletedTaskExecution.getRetryCount(), "-", "-", lastCompletedTaskExecution.getWorkflowConfig().getWorkflowType(), 0, lastCompletedTaskExecution.getTaskStatus(), "In WorkflowRetryExecutor,retryWorkflowWithCompletedTask failed due to exception.");
            InsightsStatusProvider.getInstance().createInsightStatusNode("In WorkflowRetryExecutor,retryWorkflowWithCompletedTask failed due to exception. Last completed execution: " + lastCompletedTaskExecution, PlatformServiceConstants.FAILURE);
        }
    }
}
Also used : JsonObject(com.google.gson.JsonObject) Gson(com.google.gson.Gson) JsonObject(com.google.gson.JsonObject) WorkflowTaskInitializationException(com.cognizant.devops.platformworkflow.workflowtask.exception.WorkflowTaskInitializationException) InsightsWorkflowExecutionHistory(com.cognizant.devops.platformdal.workflow.InsightsWorkflowExecutionHistory)

Example 5 with InsightsWorkflowExecutionHistory

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

the class GrafanaDashboardPdfConfigDAL method deleteGrafanaDashboardConfig.

public void deleteGrafanaDashboardConfig(GrafanaDashboardPdfConfig grafanaDashboardPdfConfig) {
    try {
        Map<String, Object> parameters = new HashMap<>();
        parameters.put("workflowId", grafanaDashboardPdfConfig.getWorkflowConfig().getWorkflowId());
        List<InsightsWorkflowExecutionHistory> executionRecord = getResultList("FROM InsightsWorkflowExecutionHistory a WHERE a.workflowConfig.workflowId= :workflowId", InsightsWorkflowExecutionHistory.class, parameters);
        for (InsightsWorkflowExecutionHistory history : executionRecord) {
            delete(history);
        }
        delete(grafanaDashboardPdfConfig);
    } catch (Exception e) {
        log.error(e.getMessage());
        throw e;
    }
}
Also used : HashMap(java.util.HashMap) InsightsWorkflowExecutionHistory(com.cognizant.devops.platformdal.workflow.InsightsWorkflowExecutionHistory)

Aggregations

InsightsWorkflowExecutionHistory (com.cognizant.devops.platformdal.workflow.InsightsWorkflowExecutionHistory)14 Test (org.testng.annotations.Test)5 InsightsWorkflowConfiguration (com.cognizant.devops.platformdal.workflow.InsightsWorkflowConfiguration)4 WorkflowTaskInitializationException (com.cognizant.devops.platformworkflow.workflowtask.exception.WorkflowTaskInitializationException)3 PlatformWorkflowApplicationTest (com.cognizant.devops.platformworkflow.workflowtask.utils.PlatformWorkflowApplicationTest)3 Gson (com.google.gson.Gson)3 JsonObject (com.google.gson.JsonObject)3 WorkflowRetryExecutor (com.cognizant.devops.platformworkflow.workflowtask.core.WorkflowRetryExecutor)2 ArrayList (java.util.ArrayList)2 ReportConfigDAL (com.cognizant.devops.platformdal.assessmentreport.ReportConfigDAL)1 InsightsWorkflowTask (com.cognizant.devops.platformdal.workflow.InsightsWorkflowTask)1 WorkflowFailedTaskException (com.cognizant.devops.platformworkflow.workflowtask.exception.WorkflowFailedTaskException)1 Type (java.lang.reflect.Type)1 HashMap (java.util.HashMap)1 List (java.util.List)1 PersistenceException (javax.persistence.PersistenceException)1