/** * Return workflow instances matching the given query. * @param query The query parameters. * @return Matching workflow instances, or empty collection if none found. */ public Collection<WorkflowInstance> listWorkflowInstances(QueryWorkflowInstances query) { return workflowInstanceDao.queryWorkflowInstances(query); } }
public boolean checkDatabaseConnection() { healthCheckDao.checkDatabaseConnection(); return true; } }
/** * Return all workflow executors of this executor group. * @return The workflow executors. */ public List<WorkflowExecutor> getWorkflowExecutors() { return executorDao.getExecutors(); } }
public MetricsWorkflowExecutorListener(MetricRegistry metricRegistry, ExecutorDao executors) { this.metricRegistry = metricRegistry; this.nflowExecutorGroup = executors.getExecutorGroup(); this.nflowExecutorId = executors.getExecutorId(); }
public int updateWorkflowInstance(WorkflowInstance instance) { // using sqlVariants.nextActivationUpdate() requires that nextActivation is used 3 times Timestamp nextActivation = toTimestamp(instance.nextActivation); return jdbc.update(updateWorkflowInstanceSql(), instance.status.name(), instance.state, abbreviate(instance.stateText, instanceStateTextLength), nextActivation, nextActivation, nextActivation, instance.status == executing ? executorInfo.getExecutorId() : null, instance.retries, instance.id); }
public WorkflowInstance getWorkflowInstance(int id) { String sql = "select w.*, " + "(select min(execution_start) from nflow_workflow_action a where a.workflow_id = w.id) as started " + "from nflow_workflow w where w.id = ?"; WorkflowInstance instance = jdbc.queryForObject(sql, new WorkflowInstanceRowMapper(), id); fillState(instance); fillChildWorkflows(instance); return instance; }
private QueueStatistics executionStatistics() { String sql = "select count(1) items, current_timestamp oldest, current_timestamp newest, current_timestamp dbtime " + "from nflow_workflow " + "where executor_id is not null and " + executorInfo.getExecutorGroupCondition(); return jdbc.query(sql, new StatisticsExtractor(true)); }
public List<Integer> listArchivableWorkflows(DateTime before, int maxRows) { return jdbc.query( "select w.id id from nflow_workflow w, " + "(" + " select parent.id from nflow_workflow parent " + " where parent.next_activation is null and parent.modified <= ? " + " and parent.root_workflow_id is null " + " and not exists(" + " select 1 from nflow_workflow child where child.root_workflow_id = parent.id " + " and (child.modified > ? or child.next_activation is not null)" + " )" + " order by modified asc " + " limit " + maxRows + ") as archivable_parent " + "where archivable_parent.id = w.id or archivable_parent.id = w.root_workflow_id", new ArchivableWorkflowsRowMapper(), toTimestamp(before), toTimestamp(before)); }
public List<Integer> pollNextWorkflowInstanceIds(final int batchSize) { if (sqlVariants.hasUpdateReturning()) { return pollNextWorkflowInstanceIdsWithUpdateReturning(batchSize); } return pollNextWorkflowInstanceIdsWithTransaction(batchSize); }
/** * Return the workflow instance matching the given id. * @param id Workflow instance id. * @return The workflow instance, or null if not found. */ public WorkflowInstance getWorkflowInstance(int id) { return workflowInstanceDao.getWorkflowInstance(id); }
public synchronized int getExecutorId() { if (executorId == -1) { executorId = allocateExecutorId(); } return executorId; }
/** * Return queue statistics for the executor group. * @return Queue statistics. */ public Statistics getStatistics() { return statisticsDao.getQueueStatistics(); }
/** * Return statistics for a given workflow definition type. * @param type The workflow definition type. * @param createdAfter If given, count only workflow instances created after this time. * @param createdBefore If given, count only workflow instances created before this time. * @param modifiedAfter If given, count only workflow instances modified after this time. * @param modifiedBefore If given, count only workflow instances modified after this time. * @return The statistics per workflow state and status. */ public Map<String, Map<String, WorkflowDefinitionStatistics>> getWorkflowDefinitionStatistics(String type, DateTime createdAfter, DateTime createdBefore, DateTime modifiedAfter, DateTime modifiedBefore) { return statisticsDao.getWorkflowDefinitionStatistics(type, createdAfter, createdBefore, modifiedAfter, modifiedBefore); } }
@SuppressFBWarnings(value = "UWF_FIELD_NOT_INITIALIZED_IN_CONSTRUCTOR", justification = "tableMetadataChecker is injected") public void ensureValidArchiveTablesExist() { tableMetadataChecker.ensureCopyingPossible("nflow_workflow", "nflow_archive_workflow"); tableMetadataChecker.ensureCopyingPossible("nflow_workflow_action", "nflow_archive_workflow_action"); tableMetadataChecker.ensureCopyingPossible("nflow_workflow_state", "nflow_archive_workflow_state"); }
private void archiveStateTable(String workflowIdParams) { String columns = columnsFromMetadata("nflow_workflow_state"); jdbc.update("insert into nflow_archive_workflow_state (" + columns + ") " + "select " + columns + " from nflow_workflow_state where workflow_id in " + workflowIdParams); }
/** * Wake up the workflow instance matching the given id if it is in one of the expected states. * @param id Workflow instance id. * @param expectedStates The expected states. * @return True if the instance was woken up, false otherwise. */ @Transactional public boolean wakeupWorkflowInstance(long id, String... expectedStates) { return workflowInstanceDao.wakeupWorkflowInstanceIfNotExecuting(id, expectedStates); }
@Override public InstanceInfo mapRow(ResultSet rs, int rowNum) throws SQLException { InstanceInfo instance = new InstanceInfo(); instance.id = rs.getInt("id"); instance.state = rs.getString("state"); return instance; } });
String whereConditionForInstanceUpdate() { return "where executor_id is null and status in (" + sqlVariants.workflowStatus(created) + ", " + sqlVariants.workflowStatus(inProgress) + ") and next_activation <= current_timestamp and " + executorInfo.getExecutorGroupCondition() + " order by next_activation asc"; }
private QueueStatistics queuedStatistics() { String sql = "select count(1) items, min(next_activation) oldest, max(next_activation) newest, current_timestamp dbtime " + "from nflow_workflow " + "where next_activation < current_timestamp and executor_id is null and " + executorInfo.getExecutorGroupCondition(); return jdbc.query(sql, new StatisticsExtractor(false)); }
@Override public List<WorkflowInstance> queryChildWorkflows(QueryWorkflowInstances query) { QueryWorkflowInstances restrictedQuery = new QueryWorkflowInstances.Builder(query).setParentWorkflowId(instance.id).build(); return workflowDao.queryWorkflowInstances(restrictedQuery); }