Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

- Support LocalID locks #6

Merged
merged 1 commit into from
Oct 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions src/main/java/org/cdlib/mrt/zk/JobState.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@ public enum JobState implements IngestState {
*/
Pending {
public List<IngestState> nextStates() {
return Arrays.asList(JobState.Held, JobState.Estimating);
return Arrays.asList(JobState.Held, JobState.Estimating, JobState.Failed);
}
public JobState fail() {
return JobState.Failed;
}
},
/**
Expand Down Expand Up @@ -123,7 +126,7 @@ public JobState fail() {
Failed {
public List<IngestState> nextStates() {
return Arrays.asList(
JobState.Estimating, JobState.Provisioning, JobState.Deleted, JobState.Downloading, JobState.Processing, JobState.Recording, JobState.Notify
JobState.Pending, JobState.Estimating, JobState.Provisioning, JobState.Deleted, JobState.Downloading, JobState.Processing, JobState.Recording, JobState.Notify
);
}
},
Expand Down
11 changes: 11 additions & 0 deletions src/main/java/org/cdlib/mrt/zk/MerrittLocks.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public class MerrittLocks {
public static void initLocks(ZooKeeper client) throws KeeperException, InterruptedException {
QueueItemHelper.createIfNeeded(client, QueueItem.ZkPaths.Locks.path);
QueueItemHelper.createIfNeeded(client, QueueItem.ZkPaths.LocksQueue.path);
QueueItemHelper.createIfNeeded(client, QueueItem.ZkPaths.LocksLocalID.path);
QueueItemHelper.createIfNeeded(client, QueueItem.ZkPaths.LocksStorage.path);
QueueItemHelper.createIfNeeded(client, QueueItem.ZkPaths.LocksInventory.path);
QueueItemHelper.createIfNeeded(client, QueueItem.ZkPaths.LocksCollections.path);
Expand Down Expand Up @@ -79,6 +80,16 @@ public static boolean checkLockCollection(ZooKeeper client, String mnemonic) thr
return QueueItemHelper.exists(client, Paths.get(QueueItem.ZkPaths.LocksCollections.path, mnemonic).toString());
}

public static boolean lockObjectLocalID(ZooKeeper client, String lid) {
return createEphemeralLock(client, Paths.get(QueueItem.ZkPaths.LocksLocalID.path, lid.replaceAll(":?/", "_")).toString());
}
public static void unlockObjectLocalID(ZooKeeper client, String lid) throws InterruptedException, KeeperException {
QueueItemHelper.delete(client, Paths.get(QueueItem.ZkPaths.LocksLocalID.path, lid.replaceAll(":?/", "_")).toString());
}
public static boolean checkLockObjectLocalID(ZooKeeper client, String lid) throws KeeperException, InterruptedException {
return QueueItemHelper.exists(client, Paths.get(QueueItem.ZkPaths.LocksLocalID.path, lid.replaceAll(":?/", "_")).toString());
}

public static boolean lockObjectStorage(ZooKeeper client, String ark) {
return createEphemeralLock(client, Paths.get(QueueItem.ZkPaths.LocksStorage.path, ark.replaceAll(":?/", "_")).toString());
}
Expand Down
1 change: 1 addition & 0 deletions src/main/java/org/cdlib/mrt/zk/QueueItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public static enum ZkPaths {
LocksQueueIngest("/locks/queue/ingest"),
LocksQueueAccessSmall("/locks/queue/accessSmall"),
LocksQueueAccessLarge("/locks/queue/accessLarge"),
LocksLocalID("/locks/localid"),
LocksStorage("/locks/storage"),
LocksInventory("/locks/inventory"),
LocksCollections("/locks/collections");
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/org/cdlib/mrt/zk/StateTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -285,4 +285,4 @@ public void JobRecoveryPath() {
assertTrue(state.isDeletable());
}

}
}
3 changes: 2 additions & 1 deletion src/test/java/org/cdlib/mrt/zk/ZKTestIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,7 @@ public boolean skipListing(String path, Object dp) throws KeeperException, Inter
}
if (path.equals(QueueItem.ZkPaths.LocksInventory.path) ||
path.equals(QueueItem.ZkPaths.LocksCollections.path) ||
path.equals(QueueItem.ZkPaths.LocksLocalID.path) ||
path.equals(QueueItem.ZkPaths.LocksStorage.path) ||
path.equals(QueueItem.ZkPaths.LocksQueue.path)) {
return true;
Expand Down Expand Up @@ -1431,4 +1432,4 @@ public void findByUuid() throws KeeperException, InterruptedException, MerrittZK
assertNull(bbb);
}

}
}
2 changes: 2 additions & 0 deletions states.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ job_states:
Pending:
Held:
Estimating:
Failed: {fail: true}
Held:
Pending:
Deleted:
Expand All @@ -26,6 +27,7 @@ job_states:
Completed:
Deleted:
Failed:
Pending:
Estimating:
Provisioning:
Downloading:
Expand Down
Loading