Skip to content

Commit

Permalink
Remove quotas in simulation runs for VCell admin users
Browse files Browse the repository at this point in the history
  • Loading branch information
vcfrmgit committed Jun 1, 2021
1 parent 3a9904f commit 439da88
Show file tree
Hide file tree
Showing 8 changed files with 71 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import java.util.Enumeration;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;

import javax.swing.JScrollPane;

Expand All @@ -25,10 +26,12 @@
import org.vcell.util.PropertyChangeListenerProxyVCell;
import org.vcell.util.document.PropertyConstants;
import org.vcell.util.document.User;
import org.vcell.util.document.User.SPECIALS;
import org.vcell.util.gui.DialogUtils;

import cbit.vcell.client.ClientSimManager;
import cbit.vcell.client.ClientSimManager.ViewerType;
import cbit.vcell.client.test.VCellClientTest;
import cbit.vcell.client.DocumentWindowManager;
import cbit.vcell.client.PopupGenerator;
import cbit.vcell.client.UserMessage;
Expand Down Expand Up @@ -767,10 +770,22 @@ public synchronized void removePropertyChangeListener(PropertyChangeListener lis
*/
void runSimulations(Simulation[] sims, Component parent) {
boolean bOkToRun = true;
boolean bCheckLimits = true;
try {
User loginUser = VCellClientTest.getVCellClient().getClientServerManager().getUser();
TreeMap<SPECIALS, TreeMap<User, String>> specialUsers = VCellClientTest.getVCellClient().getClientServerManager().getUserMetaDbServer().getSpecialUsers();
TreeMap<User, String> powerUsers = specialUsers.get(User.SPECIALS.special0);
if(powerUsers != null && powerUsers.containsKey(loginUser)) {
bCheckLimits = false;
}
} catch (Exception e) {
e.printStackTrace(); // we don't want to make a fuss if it happens
}
for(Simulation sim : sims)
{

//check if every sim in the sim list is ok to run
if(!checkSimulationParameters(sim, parent,true)){
if(!checkSimulationParameters(sim, parent,bCheckLimits)){
bOkToRun = false;
break;
}
Expand Down
2 changes: 1 addition & 1 deletion vcell-core/src/main/java/org/vcell/util/document/User.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
*/
@SuppressWarnings("serial")
public class User implements java.io.Serializable, Matchable, Immutable {
public static enum SPECIALS { special0,special1,special2,special3,publication};//Must match a name 'special' column of 'specialusers' table
public static enum SPECIALS { special0/*AdminUsers*/,special1/*PowerUsers*/,special2,special3,publication};//Must match a name 'special' column of 'specialusers' table
private String userName = null;
private KeyValue key = null;
private static final String VCellTestAccountName = "vcelltestaccount";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
package cbit.vcell.message.server.dispatcher;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
Expand Down Expand Up @@ -219,7 +220,7 @@ public static final int getMaxPdeJobsPerUser() {
* Insert the method's description here.
* Creation date: (5/11/2006 9:32:58 AM)
*/
public static SchedulerDecisions schedule(List<ActiveJob> activeJobsAllSites, PartitionStatistics partitionStatistics, int userQuotaOde, int userQuotaPde, VCellServerID systemID) {
public static SchedulerDecisions schedule(List<ActiveJob> activeJobsAllSites, PartitionStatistics partitionStatistics, int userQuotaOde, int userQuotaPde, VCellServerID systemID,User[] quotaExemptUsers) {
Hashtable<User, UserQuotaInfo> userQuotaInfoMap = new Hashtable<User, UserQuotaInfo>();
//
// gather statistics about all currently active jobs across all sites (per user and aggregate).
Expand Down Expand Up @@ -334,14 +335,15 @@ public int compare(ActiveJob o1, ActiveJob o2) {
ActiveJob waitingJob = prioritizedJobIter.next();
if (waitingJob.simulationOwner.equals(user)){
if (waitingJob.isPDE){
if (numDesiredRunningPDEsAllSites < userQuotaPde){
//(quotaExemptUsers==null?(userQuotaPde:Arrays.asList(quotaExemptUsers).contains(user)?Integer.MAX_VALUE:userQuotaPde)
if (numDesiredRunningPDEsAllSites < (quotaExemptUsers==null?userQuotaPde:(Arrays.asList(quotaExemptUsers).contains(user)?Integer.MAX_VALUE:userQuotaPde))){
numDesiredRunningPDEsAllSites++;
}else{
schedulerDecisions.setHeldUserQuotaPDE(waitingJob);
prioritizedJobIter.remove();
}
}else{
if (numDesiredRunningODEsAllSites < userQuotaOde){
if (numDesiredRunningODEsAllSites < (quotaExemptUsers==null?userQuotaOde:(Arrays.asList(quotaExemptUsers).contains(user)?Integer.MAX_VALUE:userQuotaOde))){
numDesiredRunningODEsAllSites++;
}else{
schedulerDecisions.setHeldUserQuotaODE(waitingJob);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import java.util.Collection;
import java.util.Map;
import java.util.Set;
import java.util.TreeMap;

import org.vcell.util.DataAccessException;
import org.vcell.util.ObjectNotFoundException;
Expand Down Expand Up @@ -53,6 +54,8 @@ public interface SimulationDatabase {

public User getUser(String username) throws DataAccessException, SQLException;

public TreeMap<User.SPECIALS,TreeMap<User,String>> getSpecialUsers() throws DataAccessException, SQLException;

public SimulationInfo getSimulationInfo(User user, KeyValue simKey) throws ObjectNotFoundException, DataAccessException;

public SimulationStatus[] getSimulationStatus(KeyValue[] simKeys) throws ObjectNotFoundException, DataAccessException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.TreeMap;
import java.util.Vector;
import java.util.concurrent.TimeUnit;

Expand Down Expand Up @@ -342,6 +343,10 @@ public User getUser(String username) throws DataAccessException, SQLException {
return user;
}

public TreeMap<User.SPECIALS,TreeMap<User,String>> getSpecialUsers() throws DataAccessException, SQLException{
return databaseServerImpl.getSpecialUsers(null);
}

@Override
public SimulationInfo getSimulationInfo(User user, KeyValue simKey) throws ObjectNotFoundException, DataAccessException {
SimulationInfo simInfo = databaseServerImpl.getSimulationInfo(user, simKey);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@
import java.util.Arrays;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedHashSet;
import java.util.Map;
import java.util.Set;
import java.util.TreeMap;
import java.util.concurrent.RejectedExecutionHandler;
import java.util.concurrent.ScheduledThreadPoolExecutor;
import java.util.concurrent.ThreadFactory;
Expand All @@ -35,6 +37,7 @@
import org.vcell.util.PermissionException;
import org.vcell.util.document.KeyValue;
import org.vcell.util.document.User;
import org.vcell.util.document.User.SPECIALS;
import org.vcell.util.document.VCellServerID;
import org.vcell.util.exe.ExecutableException;

Expand Down Expand Up @@ -250,7 +253,29 @@ public SimpleJobStatus[] getSimpleJobStatus(User user, SimpleJobStatusQuerySpec
}
};


private User[] quotaExemptUsers;//TreeMap<User.SPECIALS,TreeMap<User,String>> specialUsers;
private long lastSpecialUserCheck;
private void reloadSpecialUsers() {
try {
ArrayList<User> adminUserList = new ArrayList<User>();
TreeMap<User.SPECIALS,TreeMap<User,String>> specialUsers = simulationDatabase.getSpecialUsers();
final Iterator<SPECIALS> iterator = specialUsers.keySet().iterator();
while(iterator.hasNext()) {
final SPECIALS next = iterator.next();
if(next == User.SPECIALS.special0) {//Admin Users
final Iterator<User> iter = specialUsers.get(next).keySet().iterator();
while(iter.hasNext()) {
adminUserList.add(iter.next());
}
break;
}
}
quotaExemptUsers = adminUserList.toArray(new User[0]);
} catch (Exception e1) {
e1.printStackTrace();
}
lastSpecialUserCheck = System.currentTimeMillis();
}
public class DispatchThread extends Thread {

Object notifyObject = new Object();
Expand All @@ -262,9 +287,11 @@ public DispatchThread() {
}

public void run() {

reloadSpecialUsers();
while (true) {

if((System.currentTimeMillis()-lastSpecialUserCheck) > (5*60*1000)) {
reloadSpecialUsers();
}
boolean bDispatchedAnyJobs = false;

try {
Expand Down Expand Up @@ -307,7 +334,7 @@ public void run() {
BatchScheduler.ActiveJob activeJob = new BatchScheduler.ActiveJob(simJobStatus, isPDE);
activeJobs.add(activeJob);
}
SchedulerDecisions schedulerDecisions = BatchScheduler.schedule(activeJobs, partitionStatistics, maxOdePerUser, maxPdePerUser, serverID);
SchedulerDecisions schedulerDecisions = BatchScheduler.schedule(activeJobs, partitionStatistics, maxOdePerUser, maxPdePerUser, serverID,quotaExemptUsers);
if (lg.isTraceEnabled()) {
lg.trace("Dispatcher limits: partitionStatistics="+partitionStatistics+", maxOdePerUser="+maxOdePerUser+", maxPdePerUser="+maxPdePerUser);
lg.trace(schedulerDecisions.getRunnableThisSite().size() + " runnable jobs to process");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
package cbit.vcell.message.server.dispatcher;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;

Expand Down Expand Up @@ -93,6 +94,13 @@ public void onDispatch(Simulation simulation, SimulationJobStatus simJobStatus,
public void onStartRequest(VCSimulationIdentifier vcSimID, User user, int simulationScanCount, SimulationDatabase simulationDatabase, VCMessageSession session, VCMessageSession dispatcherQueueSession) throws VCMessagingException, DataAccessException, SQLException {
KeyValue simKey = vcSimID.getSimulationKey();

boolean isAdmin = false;
User myUser = simulationDatabase.getUser(user.getName());
if(myUser instanceof User.SpecialUser) {
//'special0' assigned to users who are VCell project admins
isAdmin = Arrays.asList(((User.SpecialUser)myUser).getMySpecials()).contains(User.SPECIALS.special1);
}

SimulationInfo simulationInfo = null;
try {
simulationInfo = simulationDatabase.getSimulationInfo(user, simKey);
Expand All @@ -111,7 +119,7 @@ public void onStartRequest(VCSimulationIdentifier vcSimID, User user, int simula
return;
}

if (simulationScanCount > Integer.parseInt(cbit.vcell.resource.PropertyLoader.getRequiredProperty(cbit.vcell.resource.PropertyLoader.maxJobsPerScan))) {
if (!isAdmin && simulationScanCount > Integer.parseInt(cbit.vcell.resource.PropertyLoader.getRequiredProperty(cbit.vcell.resource.PropertyLoader.maxJobsPerScan))) {
if (lg.isWarnEnabled()) lg.warn("Too many simulations (" + simulationScanCount + ") for parameter scan." + vcSimID);
StatusMessage message = new StatusMessage(new SimulationJobStatus(VCellServerID.getSystemServerID(), vcSimID, -1, null,
SchedulerStatus.FAILED, 0, SimulationMessage.workerFailure("Too many simulations (" + simulationScanCount + ") for parameter scan."), null, null), user.getName(), null, null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public void test() {
VCellServerID systemID = relSite;


SchedulerDecisions schedulerDecisions = BatchScheduler.schedule(activeJobs, partitionStatistics, userQuotaOde, userQuotaPde, systemID);
SchedulerDecisions schedulerDecisions = BatchScheduler.schedule(activeJobs, partitionStatistics, userQuotaOde, userQuotaPde, systemID,null);
schedulerDecisions.show();

//
Expand Down

0 comments on commit 439da88

Please sign in to comment.