Refactored quota handling: use of constants.
This commit is contained in:
parent
ffae738ec6
commit
86f2bb47a0
9
hsarback/src/de/hsadmin/hostsharing/QuotaLimit.java
Normal file
9
hsarback/src/de/hsadmin/hostsharing/QuotaLimit.java
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
package de.hsadmin.hostsharing;
|
||||||
|
|
||||||
|
public class QuotaLimit {
|
||||||
|
|
||||||
|
public static final double USER_HARD_FACTOR = 1.50;
|
||||||
|
public static final double GROUP_HARD_FACTOR = 1.50;
|
||||||
|
public static final double INODE_LIMIT_FACTOR = 0.25;
|
||||||
|
|
||||||
|
}
|
@ -16,6 +16,7 @@ import de.hsadmin.core.qserv.VelocityProcessor;
|
|||||||
import de.hsadmin.core.qserv.WaitingTasksProcessor;
|
import de.hsadmin.core.qserv.WaitingTasksProcessor;
|
||||||
import de.hsadmin.core.util.PasswordTool;
|
import de.hsadmin.core.util.PasswordTool;
|
||||||
import de.hsadmin.hostsharing.BasePacType;
|
import de.hsadmin.hostsharing.BasePacType;
|
||||||
|
import de.hsadmin.hostsharing.QuotaLimit;
|
||||||
import de.hsadmin.mods.user.UnixUser;
|
import de.hsadmin.mods.user.UnixUser;
|
||||||
|
|
||||||
|
|
||||||
@ -143,13 +144,13 @@ public class PacProcessorFactory implements EntityProcessorFactory {
|
|||||||
BaseComponent baseComponent = pacComponent.getBaseComponent();
|
BaseComponent baseComponent = pacComponent.getBaseComponent();
|
||||||
String feature = baseComponent.getFeature();
|
String feature = baseComponent.getFeature();
|
||||||
if ("QUOTA".equals(feature)) {
|
if ("QUOTA".equals(feature)) {
|
||||||
quota = pacComponent.getQuantity();
|
quota = pacComponent.getQuantity() * 1024;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
int blocksSoft = quota * 1024;
|
int blocksSoft = quota;
|
||||||
int blocksHard = quota * 1024 * 2;
|
int blocksHard = ((Double) (quota * QuotaLimit.GROUP_HARD_FACTOR)).intValue();
|
||||||
int inodesSoft = blocksSoft / 4;
|
int inodesSoft = ((Double) (quota * QuotaLimit.INODE_LIMIT_FACTOR)).intValue();
|
||||||
int inodesHard = blocksHard / 4;
|
int inodesHard = ((Double) (quota * QuotaLimit.INODE_LIMIT_FACTOR)).intValue();
|
||||||
return new ShellProcessor("setquota -g " + pac.getName() + " "
|
return new ShellProcessor("setquota -g " + pac.getName() + " "
|
||||||
+ blocksSoft + " " + blocksHard + " "
|
+ blocksSoft + " " + blocksHard + " "
|
||||||
+ inodesSoft + " " + inodesHard + " "
|
+ inodesSoft + " " + inodesHard + " "
|
||||||
|
@ -7,6 +7,7 @@ import de.hsadmin.core.qserv.CompoundProcessor;
|
|||||||
import de.hsadmin.core.qserv.EntityProcessorFactory;
|
import de.hsadmin.core.qserv.EntityProcessorFactory;
|
||||||
import de.hsadmin.core.qserv.Processor;
|
import de.hsadmin.core.qserv.Processor;
|
||||||
import de.hsadmin.core.qserv.ShellProcessor;
|
import de.hsadmin.core.qserv.ShellProcessor;
|
||||||
|
import de.hsadmin.hostsharing.QuotaLimit;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Factory class which creates Processor instances for dealing with UNIX user
|
* Factory class which creates Processor instances for dealing with UNIX user
|
||||||
@ -15,7 +16,7 @@ import de.hsadmin.core.qserv.ShellProcessor;
|
|||||||
* @author mi
|
* @author mi
|
||||||
*/
|
*/
|
||||||
public class UnixUserProcessorFactory implements EntityProcessorFactory {
|
public class UnixUserProcessorFactory implements EntityProcessorFactory {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return a Processor which creates a new UNIX user account
|
* @return a Processor which creates a new UNIX user account
|
||||||
*/
|
*/
|
||||||
@ -73,25 +74,29 @@ public class UnixUserProcessorFactory implements EntityProcessorFactory {
|
|||||||
|
|
||||||
private void appendSetQuotaProcessor(CompoundProcessor aCP, UnixUser user) {
|
private void appendSetQuotaProcessor(CompoundProcessor aCP, UnixUser user) {
|
||||||
Integer quotaSoft = user.getQuotaSoftlimit();
|
Integer quotaSoft = user.getQuotaSoftlimit();
|
||||||
if (quotaSoft == null || quotaSoft.intValue() == 0) {
|
if (quotaSoft == null) {
|
||||||
|
quotaSoft = new Integer(0);
|
||||||
|
} else {
|
||||||
|
quotaSoft = quotaSoft * 1024;
|
||||||
|
}
|
||||||
|
if (quotaSoft.intValue() == 0) {
|
||||||
aCP.appendProcessor(new ShellProcessor("setquota -u "
|
aCP.appendProcessor(new ShellProcessor("setquota -u "
|
||||||
+ user.getName() + " 0 0 0 0 "
|
+ user.getName() + " 0 0 0 0 "
|
||||||
+ "`df /home/pacs/ | tail -n1 | cut -d' ' -f1`"));
|
+ "`df /home/pacs/ | tail -n1 | cut -d' ' -f1`"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Integer userSoftQuota = quotaSoft * 1024;
|
|
||||||
Integer quotaHard = user.getQuotaHardlimit();
|
Integer quotaHard = user.getQuotaHardlimit();
|
||||||
if (quotaHard == null) {
|
if (quotaHard == null) {
|
||||||
quotaHard = new Integer(0);
|
quotaHard = new Integer(0);
|
||||||
}
|
} else {
|
||||||
Integer userHardQuota = quotaHard * 1024;
|
quotaHard = quotaHard * 1024;
|
||||||
if (userHardQuota.intValue() < userSoftQuota.intValue()) {
|
}
|
||||||
// set default value
|
if (quotaHard.intValue() < quotaSoft.intValue()) {
|
||||||
userHardQuota = ((Double) (userSoftQuota * 1.5 + 32)).intValue();
|
quotaHard = ((Double) (quotaSoft * QuotaLimit.USER_HARD_FACTOR)).intValue();
|
||||||
}
|
}
|
||||||
aCP.appendProcessor(new ShellProcessor("setquota -u "
|
aCP.appendProcessor(new ShellProcessor("setquota -u "
|
||||||
+ user.getName() + " " + userSoftQuota + " "
|
+ user.getName() + " " + quotaSoft + " "
|
||||||
+ userHardQuota + " 0 0 "
|
+ quotaHard + " 0 0 "
|
||||||
+ "`df /home/pacs/ | tail -n1 | cut -d' ' -f1`"));
|
+ "`df /home/pacs/ | tail -n1 | cut -d' ' -f1`"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user