Skip to content

Commit

Permalink
Create an order to check consumable resources
Browse files Browse the repository at this point in the history
Since consumable resources might track information, it makes sense to check
some before others. This provides a way to do that.
  • Loading branch information
apmasell authored and avarsava committed Feb 9, 2024
1 parent b48cbd4 commit 8943274
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 6 deletions.
1 change: 1 addition & 0 deletions changes/add_cr_order.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* Allows setting checking order on conumable resources
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,19 @@ default Optional<HttpHandler> httpHandler() {
*/
Optional<Pair<String, BasicType>> inputFromSubmitter();

/**
* The order in which this resource should be checked.
*
* <p>Some consumable resources might want to be checked first, especially ones that intend to
* track information. This causes Vidarr to check consumable resources in an order that makes
* sense for those resources.
*
* @return the priority; larger is earlier
*/
default int priority() {
return 0;
}

/**
* Indicate that Vidarr has restarted and it is reasserting an old claim.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@
import java.sql.SQLException;
import java.time.Duration;
import java.time.Instant;
import java.util.Comparator;
import java.util.Map;
import java.util.Optional;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.stream.Collectors;
import org.jooq.SQLDialect;
import org.jooq.impl.DSL;

Expand Down Expand Up @@ -70,7 +70,11 @@ public void run() {
return;
}
var i = 0;
final var resourceBrokers = target.consumableResources().collect(Collectors.toList());
final var resourceBrokers =
target
.consumableResources()
.sorted(Comparator.comparing(cr -> cr.second().priority()))
.toList();
for (i = 0; i < resourceBrokers.size(); i++) {
final var name = resourceBrokers.get(i).first();
final var broker = resourceBrokers.get(i).second();
Expand Down Expand Up @@ -101,11 +105,16 @@ public Optional<String> unavailable() {
if (error.isPresent()) {
updateBlockedResource(error.get());
// Each resource performs a check and only releases resources if they've been acquired
for (int ix=0; ix < resourceBrokers.size(); ix++){
final var tempbroker = resourceBrokers.get(ix).second();
tempbroker.release(workflow, workflowVersion, vidarrId, tempbroker.inputFromSubmitter().map(def -> consumableResources.get(def.first())));
for (final var b : resourceBrokers.subList(0, i)) {
b.second()
.release(
workflow,
workflowVersion,
vidarrId,
b.second().inputFromSubmitter().map(def -> consumableResources.get(def.first())));
}
//Must balance hammering vidarr with requests and adding significant delay to workflow runtime
// Must balance hammering vidarr with requests and adding significant delay to workflow
// runtime
executor.schedule(this, 5, TimeUnit.MINUTES);
return;
}
Expand Down

0 comments on commit 8943274

Please sign in to comment.