From 9bfbd32d5bf13bdfaa697e90404ae9c549b5b074 Mon Sep 17 00:00:00 2001 From: mreyescdl Date: Thu, 12 Dec 2024 13:33:06 -0800 Subject: [PATCH] Support Update Reporting for batches --- src/main/java/org/cdlib/mrt/zk/Batch.java | 27 ++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/cdlib/mrt/zk/Batch.java b/src/main/java/org/cdlib/mrt/zk/Batch.java index 614bfb1..dfcf28f 100644 --- a/src/main/java/org/cdlib/mrt/zk/Batch.java +++ b/src/main/java/org/cdlib/mrt/zk/Batch.java @@ -132,6 +132,7 @@ public static Batch acquirePendingBatch(ZooKeeper client) throws MerrittZKNodeIn } return null; } + public static Batch acquireBatchForReporting(ZooKeeper client) throws MerrittZKNodeInvalid, KeeperException, InterruptedException, MerrittStateError { List batches = client.getChildren(QueueItem.ZkPaths.Batch.path, false); batches.sort(String::compareTo); @@ -142,7 +143,7 @@ public static Batch acquireBatchForReporting(ZooKeeper client) throws MerrittZKN Batch b = new Batch(cp); b.load(client); - if (b.status() == BatchState.Completed || b.status() == BatchState.Failed) { + if (b.status() == BatchState.Completed || b.status() == BatchState.Failed || b.status() == BatchState.UpdateReporting) { continue; } @@ -156,6 +157,30 @@ public static Batch acquireBatchForReporting(ZooKeeper client) throws MerrittZKN return null; } + public static Batch acquireUpdateBatchForReporting(ZooKeeper client) throws MerrittZKNodeInvalid, KeeperException, InterruptedException, MerrittStateError { + List batches = client.getChildren(QueueItem.ZkPaths.Batch.path, false); + batches.sort(String::compareTo); + for(String cp: batches) { + String p = String.format("%s/%s/states/%s", QueueItem.ZkPaths.Batch.path, cp, BatchJobStates.Processing.path); + if (QueueItemHelper.exists(client, p)) { + if (client.getChildren(p, false).isEmpty()) { + Batch b = new Batch(cp); + b.load(client); + + if (b.status() == BatchState.UpdateReporting) { + if (b.lock(client)) { + // b.setStatus(client, BatchState.Reporting); + return b; + } + else + continue; + } + } + } + } + return null; + } + public static List deleteCompletedBatches(ZooKeeper client) throws MerrittZKNodeInvalid, KeeperException, InterruptedException, MerrittStateError { List deleted = new ArrayList<>(); if (!QueueItemHelper.exists(client, QueueItem.ZkPaths.Batch.path)) {