Commit ad316c0f authored by Costin Grigoras's avatar Costin Grigoras
Browse files

Correctly list job quota details for an arbitrary account

parent 82dd36a3
......@@ -254,11 +254,12 @@ public class TaskQueueApiUtils {
}
/**
* @param user Account to get the quota information for
* @return jobs quota for the current user
*/
public Quota getJobsQuota() {
public static Quota getJobsQuota(final AliEnPrincipal user) {
try {
final GetQuota gq = new GetQuota(commander.getUser());
final GetQuota gq = new GetQuota(user);
final GetQuota gqres = Dispatcher.execute(gq);
return gqres.getQuota();
}
......
/**
*
*
*/
package alien.quotas;
......@@ -18,7 +18,7 @@ import lia.util.StringFactory;
*/
public class Quota implements Serializable, Comparable<Quota> {
/**
*
*
*/
private static final long serialVersionUID = -267664655406935779L;
......@@ -150,10 +150,10 @@ public class Quota implements Serializable, Comparable<Quota> {
@Override
public String toString() {
return "Quota: userid: " + userId + "\n" + "priority\t: " + priority + "\n" + "maxparallelJobs\t: " + maxparallelJobs + "\n" + "userload\t: " + userload + "\n" + "nominalparallelJobs\t: "
+ nominalparallelJobs + "\n" + "computedpriority\t: " + computedpriority + "\n" + "waiting\t: " + waiting + "\n" + "running\t: " + running + "\n" + "maxUnfinishedJobs\t: "
+ maxUnfinishedJobs + "\n" + "maxTotalCpuCost\t: " + maxTotalCpuCost + "\n" + "totalRunningTimeLast24h\t: " + totalRunningTimeLast24h + "\n" + "unfinishedJobsLast24h\t: "
+ unfinishedJobsLast24h + "\n" + "totalCpuCostLast24h\t: " + totalCpuCostLast24h + "\n" + "maxTotalRunningTime\t: " + maxTotalRunningTime;
return "Quota of " + user + " (userid: " + userId + ")\n" + "priority\t: " + priority + "\n" + "maxparallelJobs\t: " + maxparallelJobs + "\n" + "userload\t: " + userload + "\n"
+ "nominalparallelJobs\t: " + nominalparallelJobs + "\n" + "computedpriority\t: " + computedpriority + "\n" + "waiting\t: " + waiting + "\n" + "running\t: " + running + "\n"
+ "maxUnfinishedJobs\t: " + maxUnfinishedJobs + "\n" + "maxTotalCpuCost\t: " + maxTotalCpuCost + "\n" + "totalRunningTimeLast24h\t: " + totalRunningTimeLast24h + "\n"
+ "unfinishedJobsLast24h\t: " + unfinishedJobsLast24h + "\n" + "totalCpuCostLast24h\t: " + totalCpuCostLast24h + "\n" + "maxTotalRunningTime\t: " + maxTotalRunningTime;
}
@Override
......
......@@ -29,10 +29,10 @@ public class JAliEnCommandjquota extends JAliEnBaseCommand {
return;
}
final String username = commander.user.getName();
final String username = user_to_set.getName();
if (command.equals("list")) {
final Quota q = commander.q_api.getJobsQuota();
final Quota q = TaskQueueApiUtils.getJobsQuota(user_to_set);
if (q == null) {
commander.setReturnCode(ErrNo.ENODATA, "No jobs quota found for user " + username);
return;
......@@ -75,14 +75,11 @@ public class JAliEnCommandjquota extends JAliEnBaseCommand {
@Override
public void printHelp() {
commander.printOutln();
commander.printOutln("jquota: Displays information about Job Quotas.");
commander.printOutln("Usage:");
commander.printOutln(" jquota list <user> - list the user quota for job");
commander.printOutln(" use just 'jquota list' for all users");
commander.printOutln();
commander.printOutln(" jquota set <user> <field> <value> - set the user quota for job");
commander.printOutln(" (maxUnfinishedJobs, maxTotalCpuCost, maxTotalRunningTime)");
commander.printOutln(" use <user>=% for all users");
commander.printOutln(helpUsage("jquota", "Displays information about Job Quotas."));
commander.printOutln(helpStartOptions());
commander.printOutln(helpOption("list [username]", "get job quota information for the current account, or the indicated one"));
commander.printOutln(helpOption("set <user> <field> <value>", "to set quota fileds (one of maxUnfinishedJobs, maxTotalCpuCost, maxTotalRunningTime)"));
}
@Override
......@@ -100,8 +97,11 @@ public class JAliEnCommandjquota extends JAliEnBaseCommand {
this.isAdmin = commander.getUser().canBecome("admin");
if (alArguments.size() == 0)
return;
this.command = alArguments.get(0);
System.out.println(alArguments);
this.user_to_set = commander.getUser();
if (this.command.equals("set") && alArguments.size() == 4) {
this.user_to_set = UserFactory.getByUsername(alArguments.get(1));
......@@ -118,6 +118,15 @@ public class JAliEnCommandjquota extends JAliEnBaseCommand {
// FIXME invalid numeric values are ignored
}
}
if (this.command.equals("list") && alArguments.size() > 1) {
this.user_to_set = UserFactory.getByUsername(alArguments.get(1));
if (this.user_to_set == null) {
commander.printErrln("No such account name: " + alArguments.get(1));
setArgumentsOk(false);
}
}
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment