|
13 | 13 | import static io.camunda.migration.data.impl.persistence.IdKeyMapper.TYPE.HISTORY_PROCESS_INSTANCE; |
14 | 14 | import static io.camunda.migration.data.impl.util.ConverterUtil.getNextKey; |
15 | 15 |
|
| 16 | +import io.camunda.db.rdbms.read.domain.FlowNodeInstanceDbQuery; |
| 17 | +import io.camunda.db.rdbms.write.domain.FlowNodeInstanceDbModel; |
16 | 18 | import io.camunda.db.rdbms.write.domain.JobDbModel; |
17 | 19 | import io.camunda.migration.data.impl.history.C7Entity; |
18 | 20 | import io.camunda.migration.data.impl.history.EntitySkippedException; |
19 | | -import io.camunda.migration.data.impl.logging.HistoryMigratorLogs; |
| 21 | +import io.camunda.migration.data.impl.persistence.IdKeyMapper; |
20 | 22 | import io.camunda.search.entities.ProcessInstanceEntity; |
| 23 | +import io.camunda.search.filter.FlowNodeInstanceFilter; |
| 24 | +import java.util.Date; |
| 25 | +import java.util.List; |
| 26 | +import java.util.function.BiConsumer; |
| 27 | +import java.util.function.Consumer; |
| 28 | +import java.util.function.Function; |
21 | 29 | import org.camunda.bpm.engine.history.HistoricJobLog; |
22 | 30 | import org.springframework.stereotype.Service; |
23 | 31 |
|
|
35 | 43 | * </p> |
36 | 44 | */ |
37 | 45 | @Service |
38 | | -public class JobMigrator extends BaseMigrator<HistoricJobLog, JobDbModel> { |
| 46 | +public class JobMigrator extends HistoryEntityMigrator<HistoricJobLog, JobDbModel> { |
39 | 47 |
|
40 | | - /** |
41 | | - * Migrates all historic job log entries from Camunda 7 to Camunda 8. |
42 | | - * <p> |
43 | | - * Processes log entries in ascending timestamp order. Since tracking is done by C7 job ID, only |
44 | | - * the first log entry encountered per job is migrated; subsequent entries for the same job are |
45 | | - * deduplicated via the tracking table. |
46 | | - * </p> |
47 | | - */ |
48 | 48 | @Override |
49 | | - public void migrateAll() { |
50 | | - fetchMigrateOrRetry( |
51 | | - HISTORY_JOB, |
52 | | - c7Client::getHistoricJobLog, |
53 | | - c7Client::fetchAndHandleHistoricJobLogs |
54 | | - ); |
| 49 | + public BiConsumer<Consumer<HistoricJobLog>, Date> fetchForMigrateHandler() { |
| 50 | + return c7Client::fetchAndHandleHistoricJobLogs; |
| 51 | + } |
| 52 | + |
| 53 | + @Override |
| 54 | + public Function<String, HistoricJobLog> fetchForRetryHandler() { |
| 55 | + return c7Client::getHistoricJobLog; |
| 56 | + } |
| 57 | + |
| 58 | + @Override |
| 59 | + public IdKeyMapper.TYPE getType() { |
| 60 | + return HISTORY_JOB; |
55 | 61 | } |
56 | 62 |
|
57 | 63 | /** |
@@ -114,4 +120,35 @@ public Long migrateTransactionally(final HistoricJobLog c7JobLog) { |
114 | 120 |
|
115 | 121 | return null; |
116 | 122 | } |
| 123 | + |
| 124 | + /** |
| 125 | + * Finds the C8 flow node instance key by C7 activity ID and process instance ID. |
| 126 | + * <p> |
| 127 | + * Since {@link HistoricJobLog} provides only the activity ID (not the activity instance ID), |
| 128 | + * this method searches C8 flow node instances by activity ID within the migrated process |
| 129 | + * instance. |
| 130 | + * </p> |
| 131 | + * |
| 132 | + * @param activityId the C7 activity ID |
| 133 | + * @param processInstanceId the C7 process instance ID |
| 134 | + * @return the C8 flow node instance key, or {@code null} if not found |
| 135 | + */ |
| 136 | + protected Long findFlowNodeInstanceKey(String activityId, String processInstanceId) { |
| 137 | + Long processInstanceKey = dbClient.findC8KeyByC7IdAndType(processInstanceId, HISTORY_PROCESS_INSTANCE); |
| 138 | + if (processInstanceKey == null) { |
| 139 | + return null; |
| 140 | + } |
| 141 | + |
| 142 | + List<FlowNodeInstanceDbModel> flowNodes = c8Client.searchFlowNodeInstances( |
| 143 | + FlowNodeInstanceDbQuery.of(builder -> builder.filter( |
| 144 | + FlowNodeInstanceFilter.of(filter -> filter.flowNodeIds(activityId).processInstanceKeys(processInstanceKey)) |
| 145 | + )) |
| 146 | + ); |
| 147 | + |
| 148 | + if (!flowNodes.isEmpty()) { |
| 149 | + return flowNodes.getFirst().flowNodeInstanceKey(); |
| 150 | + } else { |
| 151 | + return null; |
| 152 | + } |
| 153 | + } |
117 | 154 | } |
0 commit comments