Skip to content

Commit

Permalink
Merge pull request #1165 from virtualcell/filter-slurm-user
Browse files Browse the repository at this point in the history
restrict Slurm job actions to user vcell, not just partition
  • Loading branch information
jcschaff authored Feb 29, 2024
2 parents 1dcd04d + f25e3b6 commit 106f1fa
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 38 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ jobs:

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v2
uses: github/codeql-action/init@v3
with:
languages: ${{ matrix.language }}
# If you wish to specify custom queries, you can do so here or in a config file.
Expand All @@ -60,7 +60,7 @@ jobs:
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
# If this step fails, then you should remove it and run the build manually (see below)
- name: Autobuild
uses: github/codeql-action/autobuild@v2
uses: github/codeql-action/autobuild@v3

# ℹ️ Command-line programs to run using the OS shell.
# 📚 https://git.io/JvXDl
Expand All @@ -74,4 +74,4 @@ jobs:
# make release

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v2
uses: github/codeql-action/analyze@v3
20 changes: 8 additions & 12 deletions pythonCopasiOpt/vcell-opt/poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package cbit.vcell.util;
package org.vcell.admin.cli.tools;

import java.io.BufferedReader;
import java.io.File;
Expand All @@ -14,6 +14,7 @@
import java.util.StringTokenizer;
import java.util.TreeMap;

import cbit.vcell.message.server.htc.HtcProxy;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.vcell.util.BeanUtils;
Expand All @@ -27,8 +28,8 @@
import net.schmizz.sshj.userauth.keyprovider.FileKeyProvider;
import net.schmizz.sshj.userauth.keyprovider.OpenSSHKeyFile;

public class VCellSimStatus {
private final static Logger lg = LogManager.getLogger(VCellSimStatus.class);
public class VCellSimStatus_NOT_USED {
private final static Logger lg = LogManager.getLogger(VCellSimStatus_NOT_USED.class);

public static class CommandExecError extends Exception {
public CommandExecError(String message){
Expand Down Expand Up @@ -115,7 +116,7 @@ public VCellSlurmAssoc(VCellSlurmAssoc other){

public static void main(String[] args){
if(args.length != 6){
System.out.println("Usage: " + VCellSimStatus.class.getSimpleName() + " dbHost dbName dbUser dbPassword sshRSAKeyFile slurmHost");
System.out.println("Usage: " + VCellSimStatus_NOT_USED.class.getSimpleName() + " dbHost dbName dbUser dbPassword sshRSAKeyFile slurmHost");
System.exit(1);
}
String dbHost = args[0];
Expand All @@ -138,7 +139,7 @@ public static void main(String[] args){
//TO_CHAR(SYSDATE, 'YYYY-MM-DD HH24:MI:SS')
stmt = con.createStatement();
String sql =
"select 'V_' || vc_simulationjob.serverid || '_' || simref || '_' || vc_simulationjob.jobindex || '_' || vc_simulationjob.taskid slurnjobname,vc_userinfo.userid," +
"select '"+HtcProxy.JOB_NAME_PREFIX_SIMULATION+"' || vc_simulationjob.serverid || '_' || simref || '_' || vc_simulationjob.jobindex || '_' || vc_simulationjob.taskid slurnjobname,vc_userinfo.userid," +
"vc_simulationjob.*" +
" from vc_simulationjob,vc_simulation,vc_userinfo" +
" where schedulerstatus not in (4,5,6) and vc_simulation.id=vc_simulationjob.simref" +
Expand Down Expand Up @@ -230,7 +231,7 @@ public static void main(String[] args){
// continue;
// }
// String s = st.nextToken();
if(nextStr.contains("V_")){
if(nextStr.contains(HtcProxy.JOB_NAME_PREFIX_SIMULATION)){
StringTokenizer st = new StringTokenizer(nextStr, " ", false);
//GEt slurmjobid (and array job index if present)
String slurmJobIDAndArrayIndex = st.nextToken();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,9 @@ public void run() {
for (HtcJobInfo htcJobInfo : runningJobs.keySet()){
try {
String simJobName = htcJobInfo.getJobName();
if (!simJobName.startsWith(HtcProxy.JOB_NAME_PREFIX_SIMULATION)){
continue;
}
HtcProxy.SimTaskInfo simTaskInfo = HtcProxy.getSimTaskInfoFromSimJobName(simJobName);
SimulationJobStatus simJobStatus = simulationDatabase.getLatestSimulationJobStatus(simTaskInfo.simId, simTaskInfo.jobIndex);
String failureMessage = null;
Expand All @@ -404,7 +407,7 @@ public void run() {
}
}
}
if (killJob && HtcProxy.isMyJob(htcJobInfo)){
if (killJob && HtcProxy.isMySimulationJob(htcJobInfo)){
if (lg.isWarnEnabled()) {
lg.warn("killing " + htcJobInfo + ", " + failureMessage);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@

public abstract class HtcProxy {
public static final Logger LG = LogManager.getLogger(HtcProxy.class);
public static final String JOB_NAME_PREFIX_SIMULATION = "V_";
public static final String JOB_NAME_PREFIX_COPASI_PAREST = "CopasiParest_";

public interface HtcProxyFactory {
HtcProxy getHtcProxy();
Expand Down Expand Up @@ -124,17 +126,28 @@ public boolean equals(Object obj) {
* set {@link HtcProxy#HTC_SIMULATION_JOB_NAME_PREFIX}
* @return V_<i>server<i>
*/
private static String jobNamePrefix( ){
String stub = "V_";
private static String simulationJobNamePrefix( ){
String stub = JOB_NAME_PREFIX_SIMULATION;
String server = PropertyLoader.getRequiredProperty(PropertyLoader.vcellServerIDProperty);
return stub + server + "_";
}

public static boolean isMyJob(HtcJobInfo htcJobInfo){
return htcJobInfo.getJobName().startsWith(jobNamePrefix());

/**
* set {@link HtcProxy#HTC_SIMULATION_JOB_NAME_PREFIX}
* @return CopasiParest
*/
private static String parameterEstimationJobNamePrefix( ){
return JOB_NAME_PREFIX_COPASI_PAREST;
}

public final static String HTC_SIMULATION_JOB_NAME_PREFIX = jobNamePrefix();

public static boolean isMySimulationJob(HtcJobInfo htcJobInfo){
return htcJobInfo.getJobName().startsWith(simulationJobNamePrefix());
}
public static boolean isMyParameterEstimationJob(HtcJobInfo htcJobInfo){
return htcJobInfo.getJobName().startsWith(parameterEstimationJobNamePrefix());
}

public final static String HTC_SIMULATION_JOB_NAME_PREFIX = simulationJobNamePrefix();
protected final CommandService commandService;
protected final String htcUser;

Expand Down Expand Up @@ -196,7 +209,8 @@ public static SimTaskInfo getSimTaskInfoFromSimJobName(String simJobName) throws
if (tokens.hasMoreTokens()){
taskIdString = tokens.nextToken();
}
if (PREFIX.equals("V") && SITE!=null && simIdString!=null && jobIndexString!=null && taskIdString!=null){
String expectedSimPrefix = HtcProxy.JOB_NAME_PREFIX_SIMULATION.replace("_","");
if (PREFIX.equals(expectedSimPrefix) && SITE!=null && simIdString!=null && jobIndexString!=null && taskIdString!=null){
KeyValue simId = new KeyValue(simIdString);
int jobIndex = Integer.valueOf(jobIndexString);
int taskId = Integer.valueOf(taskIdString);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public static SlurmProxy createLocalProxy(List<String> htcDispatchHostNames, Str
@Override
public void killJobSafe(HtcJobInfo htcJobInfo) throws ExecutableException, HtcException {
final String JOB_CMD_DELETE = PropertyLoader.getProperty(PropertyLoader.slurm_cmd_scancel,"scancel");
String[] cmd = new String[]{JOB_CMD_DELETE, "--jobname", htcJobInfo.getJobName(), Long.toString(htcJobInfo.getHtcJobID().getJobNumber())};
String[] cmd = new String[]{JOB_CMD_DELETE,"-u",getHtcUser(), "--jobname", htcJobInfo.getJobName(), Long.toString(htcJobInfo.getHtcJobID().getJobNumber())};
try {
//CommandOutput commandOutput = commandService.command(cmd, new int[] { 0, QDEL_JOB_NOT_FOUND_RETURN_CODE });
if (LG.isDebugEnabled()) {
Expand All @@ -108,7 +108,7 @@ public void killJobSafe(HtcJobInfo htcJobInfo) throws ExecutableException, HtcEx
@Override
public void killJobUnsafe(HtcJobID htcJobId) throws ExecutableException, HtcException {
final String JOB_CMD_DELETE = PropertyLoader.getProperty(PropertyLoader.slurm_cmd_scancel,"scancel");
String[] cmd = new String[]{JOB_CMD_DELETE, Long.toString(htcJobId.getJobNumber())};
String[] cmd = new String[]{JOB_CMD_DELETE, "-u", getHtcUser(), Long.toString(htcJobId.getJobNumber())};
try {
//CommandOutput commandOutput = commandService.command(cmd, new int[] { 0, QDEL_JOB_NOT_FOUND_RETURN_CODE });
if (LG.isDebugEnabled()) {
Expand Down Expand Up @@ -282,7 +282,7 @@ public Map<HtcJobInfo, HtcJobStatus> getRunningJobs() throws ExecutableException
final String JOB_CMD_SQUEUE = PropertyLoader.getProperty(PropertyLoader.slurm_cmd_squeue,"squeue");
// squeue -p vcell2 -O jobid:25,name:25,state:13
String partition = PropertyLoader.getRequiredProperty(PropertyLoader.slurm_partition);
String[] cmds = {JOB_CMD_SQUEUE,"-p",partition,"-O","jobid:25,name:25,state:13,batchhost"};
String[] cmds = {JOB_CMD_SQUEUE,"-p",partition,"-u",getHtcUser(),"-O","jobid:25,name:25,state:13,batchhost"};
CommandOutput commandOutput = commandService.command(cmds);

String output = commandOutput.getStandardOutput();
Expand Down Expand Up @@ -330,7 +330,7 @@ public Map<HtcJobInfo,HtcJobStatus> getJobStatus(List<HtcJobInfo> requestedHtcJo
jobNumbers.add(Long.toString(jobInfo.getHtcJobID().getJobNumber()));
}
String jobList = String.join(",", jobNumbers);
String[] cmds = {JOB_CMD_SACCT,"-P","-j",jobList,"-o","jobid%25,jobname%25,state%13"};
String[] cmds = {JOB_CMD_SACCT,"-P","-u",getHtcUser(),"-j",jobList,"-o","jobid%25,jobname%25,state%13"};
CommandOutput commandOutput = commandService.command(cmds);

String output = commandOutput.getStandardOutput();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import org.vcell.util.document.KeyValue;

import static cbit.vcell.message.server.htc.HtcProxy.getSimTaskInfoFromSimJobName;
import static cbit.vcell.message.server.htc.HtcProxy.isMyJob;
import static cbit.vcell.message.server.htc.HtcProxy.isMySimulationJob;
import static cbit.vcell.server.HtcJobID.BatchSystemType.SLURM;
import static org.junit.jupiter.api.Assertions.*;

Expand Down Expand Up @@ -51,11 +51,11 @@ public void test_getSimTaskInfoFromSimJobName() throws NumberFormatException, Ht
@Test
public void test_isMyJob(){
PropertyLoader.setProperty(PropertyLoader.vcellServerIDProperty, "ALPHA");
assertTrue(HtcProxy.isMyJob(new HtcJobInfo(new HtcJobID("1200725", BatchSystemType.SLURM), "V_ALPHA_115785823_0_0")));
assertFalse(isMyJob(new HtcJobInfo(new HtcJobID("1200725", SLURM), "V_BETA_115785823_0_0")));
assertTrue(HtcProxy.isMySimulationJob(new HtcJobInfo(new HtcJobID("1200725", BatchSystemType.SLURM), "V_ALPHA_115785823_0_0")));
assertFalse(isMySimulationJob(new HtcJobInfo(new HtcJobID("1200725", SLURM), "V_BETA_115785823_0_0")));

PropertyLoader.setProperty(PropertyLoader.vcellServerIDProperty, "BETA");
assertTrue(HtcProxy.isMyJob(new HtcJobInfo(new HtcJobID("1200725", BatchSystemType.SLURM), "V_BETA_115785823_0_0")));
assertTrue(HtcProxy.isMySimulationJob(new HtcJobInfo(new HtcJobID("1200725", BatchSystemType.SLURM), "V_BETA_115785823_0_0")));
}

}

0 comments on commit 106f1fa

Please sign in to comment.