Search in sources :

Example 1 with BatchSystemType

use of cbit.vcell.server.HtcJobID.BatchSystemType in project vcell by virtualcell.

the class SlurmProxy method creatCommandService.

public static HtcProxy creatCommandService(java.lang.String[] sshHostUserKeyfile) throws IOException {
    CommandService commandService = null;
    if (sshHostUserKeyfile != null && sshHostUserKeyfile.length == 3) {
        ArrayList<String> htcDispatchHostNames = new ArrayList<String>();
        StringTokenizer st = new StringTokenizer(sshHostUserKeyfile[0], ", ");
        while (st.hasMoreElements()) {
            htcDispatchHostNames.add(st.nextToken());
        }
        // String sshHost = sshHostUserKeyfile[0];
        String sshUser = sshHostUserKeyfile[1];
        File sshKeyFile = new File(sshHostUserKeyfile[2]);
        try {
            commandService = new CommandServiceSshNative(htcDispatchHostNames.toArray(new String[0]), sshUser, sshKeyFile);
            commandService.command(new String[] { "/usr/bin/env bash -c ls | head -5" });
        // lg.trace("SSH Connection test passed with installed keyfile, running ls as user "+sshUser+" on "+sshHost);
        } catch (Exception e) {
            e.printStackTrace();
            try {
                commandService = new CommandServiceSshNative(htcDispatchHostNames.toArray(new String[0]), sshUser, sshKeyFile, new File("/root"));
                CommandOutput commandOutput = commandService.command(new String[] { "/usr/bin/env bash -c ls | head -5" });
            // lg.trace("SSH Connection test passed after installing keyfile, running ls as user "+sshUser+" on "+sshHost);
            } catch (Exception e2) {
                e.printStackTrace();
                throw new RuntimeException("failed to establish an ssh command connection to " + sshHostUserKeyfile[0] + " as user '" + sshUser + "' using key '" + sshKeyFile + "'", e);
            }
        }
        // can't make user directories, they are remote.
        AbstractSolver.bMakeUserDirs = false;
    } else {
        commandService = new CommandServiceLocal();
    }
    BatchSystemType batchSystemType = BatchSystemType.SLURM;
    HtcProxy htcProxy = null;
    switch(batchSystemType) {
        case SLURM:
            {
                htcProxy = new SlurmProxy(commandService, PropertyLoader.getRequiredProperty(PropertyLoader.htcUser));
                break;
            }
        default:
            {
                throw new RuntimeException("unrecognized batch scheduling option :" + batchSystemType);
            }
    }
    return htcProxy;
}
Also used : HtcProxy(cbit.vcell.message.server.htc.HtcProxy) CommandService(cbit.vcell.message.server.cmd.CommandService) CommandOutput(cbit.vcell.message.server.cmd.CommandService.CommandOutput) ArrayList(java.util.ArrayList) ExecutableException(org.vcell.util.exe.ExecutableException) HtcException(cbit.vcell.message.server.htc.HtcException) IOException(java.io.IOException) HtcJobNotFoundException(cbit.vcell.message.server.htc.HtcJobNotFoundException) StringTokenizer(java.util.StringTokenizer) CommandServiceLocal(cbit.vcell.message.server.cmd.CommandServiceLocal) BatchSystemType(cbit.vcell.server.HtcJobID.BatchSystemType) File(java.io.File) CommandServiceSshNative(cbit.vcell.message.server.cmd.CommandServiceSshNative)

Aggregations

CommandService (cbit.vcell.message.server.cmd.CommandService)1 CommandOutput (cbit.vcell.message.server.cmd.CommandService.CommandOutput)1 CommandServiceLocal (cbit.vcell.message.server.cmd.CommandServiceLocal)1 CommandServiceSshNative (cbit.vcell.message.server.cmd.CommandServiceSshNative)1 HtcException (cbit.vcell.message.server.htc.HtcException)1 HtcJobNotFoundException (cbit.vcell.message.server.htc.HtcJobNotFoundException)1 HtcProxy (cbit.vcell.message.server.htc.HtcProxy)1 BatchSystemType (cbit.vcell.server.HtcJobID.BatchSystemType)1 File (java.io.File)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 StringTokenizer (java.util.StringTokenizer)1 ExecutableException (org.vcell.util.exe.ExecutableException)1