Skip to content

Commit

Permalink
Convert units rather than fail
Browse files Browse the repository at this point in the history
  • Loading branch information
rowleya committed Oct 4, 2023
1 parent 61606d7 commit 0d4801b
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -336,18 +336,17 @@ private static class QuotaInfo {
}

private QuotaInfo parseQuotaData(List<Project> projects) {
String units = null;
log.debug("Parsing {} projects", projects.size());
long total = 0;
for (var project : projects) {
log.debug("Project {} has {} quotas", project.getCollab(),
project.getQuotas().size());
for (var quota : project.getQuotas()) {
if (!quota.getPlatform().equals(quotaProps.getNMPIPlaform())) {
continue;
}
if (units == null) {
units = quota.getUnits();
} else if (units != quota.getUnits()) {
throw new RuntimeException("Quotas have multiple units!");
}
log.debug("Quota for {} = {}{} ({} used)", quota.getPlatform(),
quota.getLimit(), quota.getUnits(), quota.getUsage());

switch (quota.getUnits()) {
case BOARD_SECONDS:
Expand All @@ -363,7 +362,7 @@ private QuotaInfo parseQuotaData(List<Project> projects) {
}
}
}
return new QuotaInfo(total, units);
return new QuotaInfo(total, BOARD_SECONDS);
}

final Optional<String> mayCreateNMPISession(String collab) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
* A NMPI project.
*/
public class Project {
/** The collab of the project. */
private String collab;

/** The quotas of the project. */
private List<Quota> quotas;

Expand All @@ -42,6 +45,21 @@ public void setQuotas(List<Quota> quotas) {
this.quotas = quotas;
}

/**
* @return The collab of the project.
*/
public String getCollab() {
return collab;
}

/**
* @param collab
* the collab of the project to set.
*/
public void setCollab(String collab) {
this.collab = collab;
}

/**
* Used for JSON serialisation; ignores other properties we don't care
* about.
Expand Down

0 comments on commit 0d4801b

Please sign in to comment.