/// <summary> /// Submit job to scheduler /// </summary> /// <param name="connectorClient">Connector</param> /// <param name="jobSpecification">Job specification</param> /// <param name="credentials">Credentials</param> /// <returns></returns> public virtual IEnumerable <SubmittedTaskInfo> SubmitJob(object connectorClient, JobSpecification jobSpecification, ClusterAuthenticationCredentials credentials) { var shellCommandSb = new StringBuilder(); SshCommandWrapper command = null; string shellCommand = (string)_convertor.ConvertJobSpecificationToJob(jobSpecification, null); _log.Info($"Submitting job \"{jobSpecification.Id}\", command \"{shellCommand}\""); string sshCommandBase64 = Convert.ToBase64String(Encoding.UTF8.GetBytes(shellCommand)); command = SshCommandUtils.RunSshCommand(new SshClientAdapter((SshClient)connectorClient), $"{_commandScripts.ExecutieCmdPath} {sshCommandBase64}"); shellCommandSb.Clear(); //compose command with parameters of job and task IDs shellCommandSb.Append($"{_linuxLocalCommandScripts.RunLocalCmdPath} {jobSpecification.FileTransferMethod.Cluster.LocalBasepath}/{jobSpecification.Id}/"); jobSpecification.Tasks.ForEach(task => shellCommandSb.Append($" {task.Id}")); //log local HPC Run script to log file shellCommandSb.Append($" >> {jobSpecification.FileTransferMethod.Cluster.LocalBasepath}/{jobSpecification.Id}/job_log.txt &"); shellCommand = shellCommandSb.ToString(); sshCommandBase64 = Convert.ToBase64String(Encoding.UTF8.GetBytes(shellCommand)); command = SshCommandUtils.RunSshCommand(new SshClientAdapter((SshClient)connectorClient), $"{_commandScripts.ExecutieCmdPath} {sshCommandBase64}"); return(GetActualTasksInfo(connectorClient, jobSpecification.Cluster, new string[] { $"{jobSpecification.Id}" })); }
/// <summary> /// Submit job to scheduler /// </summary> /// <param name="connectorClient">Connector</param> /// <param name="jobSpecification">Job specification</param> /// <param name="credentials">Credentials</param> /// <returns></returns> /// <exception cref="Exception"></exception> public virtual IEnumerable <SubmittedTaskInfo> SubmitJob(object connectorClient, JobSpecification jobSpecification, ClusterAuthenticationCredentials credentials) { var jobIdsWithJobArrayIndexes = new List <string>(); SshCommandWrapper command = null; string sshCommand = (string)_convertor.ConvertJobSpecificationToJob(jobSpecification, "qsub -koed"); _log.Info($"Submitting job \"{jobSpecification.Id}\", command \"{sshCommand}\""); string sshCommandBase64 = $"{_commands.InterpreterCommand} '{_commands.ExecutieCmdScriptPath} {Convert.ToBase64String(Encoding.UTF8.GetBytes(sshCommand))}'"; try { command = SshCommandUtils.RunSshCommand(new SshClientAdapter((SshClient)connectorClient), sshCommandBase64); var jobIds = _convertor.GetJobIds(command.Result).ToList(); for (int i = 0; i < jobSpecification.Tasks.Count; i++) { jobIdsWithJobArrayIndexes.AddRange(string.IsNullOrEmpty(jobSpecification.Tasks[i].JobArrays) ? new List <string> { jobIds[i] } : CombineScheduledJobIdWithJobArrayIndexes(jobIds[i], jobSpecification.Tasks[i].JobArrays)); } return(GetActualTasksInfo(connectorClient, jobSpecification.Cluster, jobIdsWithJobArrayIndexes)); } catch (FormatException e) { throw new Exception(@$ "Exception thrown when submitting a job: " "{jobSpecification.Name}" " to the cluster: " "{jobSpecification.Cluster.Name}" ". Submission script result: " "{command.Result}" ".\nSubmission script error message: " "{command.Error}" ".\n Command line for job submission: " "{sshCommandBase64}" ".\n", e); } }