Skip to content

Commit

Permalink
Add ability to restrict maximum number of CPUs with Group Authz.
Browse files Browse the repository at this point in the history
  • Loading branch information
oldpatricka committed May 27, 2010
1 parent 12e8065 commit 61c2238
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 0 deletions.
Expand Up @@ -14,6 +14,9 @@ vws.group.authz.maxReservedMinutes=300
# the all-time maximum usage cap.
vws.group.authz.maxElapsedReservedMinutes=300

# Maximum number of CPUs per VM instance
vws.group.authz.maxCPUs=2

# Maximum number of running workspaces at one point in time
vws.group.authz.maxWorkspaceNumber=5

Expand Down
Expand Up @@ -150,6 +150,39 @@ public static Integer decide(String dn,
buf.append(requestDur)
.append("\n");

// zero or below means no check should be made
if (rights.getMaxCPUs() > 0) {
final long maxCPUs = rights.getMaxCPUs();
for (int i = 0; i < bindings.length; i++) {

final VirtualMachineDeployment dep = bindings[i].getDeployment();
if (dep == null) {
final String msg = "ERROR: No deployment information in " +
"binding, can't make decision.";
buf.append(msg);
logger.error(buf.toString());
throw new AuthorizationException(msg);
}
final long currentCPUs = dep.getIndividualCPUCount();
if (currentCPUs > maxCPUs) {

buf.append("\nDenied: Requested CPU count (")
.append(currentCPUs)
.append(") + is greater or equal to maximum CPU count (")
.append(maxCPUs)
.append(").\n");

logger.warn(buf.toString());

throw new ResourceRequestDeniedException(
"You requested too many CPUs (" +
currentCPUs + "), the " +
"maximum is " +
maxCPUs + " CPUs.");
}
}
}

// zero or below means no check should be made
if (rights.getMaxReservedMinutes() > 0) {
final long max = rights.getMaxReservedMinutes();
Expand Down
Expand Up @@ -41,6 +41,11 @@ public class GroupRights {
public static final String PROPKEY_MAX_WORKSPACE_NUMBER =
"vws.group.authz.maxWorkspaceNumber";

// this controls 'maximum number of CPUs per request', 0 is unlimited
private long maxCPUs;
public static final String PROPKEY_MAX_CPUS =
"vws.group.authz.maxCPUs";

// this controls 'number of VMs in group', 0 is unlimited
// this is different than 'number of VMs running at once'
private long maxWorkspacesInGroup;
Expand Down Expand Up @@ -95,6 +100,11 @@ public GroupRights(Properties props, String source) throws Exception {
getZeroOrPositiveLong(props,
PROPKEY_MAX_WORKSPACES_IN_GROUP,
source);
// can be null
this.maxCPUs =
getZeroOrPositiveLongAllowNull(props,
PROPKEY_MAX_CPUS,
source);

// can be null
this.groupName = props.getProperty(PROPKEY_GROUP_NAME);
Expand Down Expand Up @@ -156,6 +166,22 @@ private static long getZeroOrPositiveLong(Properties props,
return val.longValue();
}

// Some values can be null, and should return a zero for that case
private static long getZeroOrPositiveLongAllowNull(Properties props,
String key,
String source) throws Exception {

final String prop = props.getProperty(key);
final Long val;
if (null == prop) {
val = Long.valueOf(0);
}
else {
val = getZeroOrPositiveLong(props, key, source);
}
return val.longValue();
}

public long getMaxReservedMinutes() {
return this.maxReservedMinutes;
}
Expand All @@ -164,6 +190,10 @@ public long getMaxElapsedReservedMinutes() {
return this.maxElapsedReservedMinutes;
}

public long getMaxCPUs() {
return this.maxCPUs;
}

public long getMaxWorkspaceNumber() {
return this.maxWorkspaceNumber;
}
Expand Down Expand Up @@ -205,6 +235,7 @@ public String toString() {
", imageNodeHostname='" + this.imageNodeHostname + '\'' +
", imageBaseDirectory='" + this.imageBaseDirectory + '\'' +
", dirHashMode=" + this.dirHashMode +
", maxCPUs=" + this.maxCPUs +
'}';
}
}

0 comments on commit 61c2238

Please sign in to comment.