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());
}
}
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());
}
}
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);
}
}
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");
}
}
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());
}
}
Aggregations