Skip to content

Commit

Permalink
Merge pull request #5 from CSBiology/runner
Browse files Browse the repository at this point in the history
Update Runner and SSH logic 
Solves #3 and #4
  • Loading branch information
zieglerSe authored Nov 17, 2023
2 parents 20e3858 + 0bed872 commit 42bf074
Show file tree
Hide file tree
Showing 11 changed files with 212 additions and 138 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -396,3 +396,5 @@ FodyWeavers.xsd

# JetBrains Rider
*.sln.iml
/sshConnection.md
/sshConnection.md
6 changes: 6 additions & 0 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
### 0.0.3 (Released 2023-11-13)
* Improve readability
* Add SSH functionality
* Updated documentation


### 0.0.2 (Released 2023-10-25)
* Update Backend
- Enable automated submission to Slurm
Expand Down
5 changes: 3 additions & 2 deletions Slurmi.sln
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,10 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "docs", "docs", "{3F1EFAF6-6
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "articles", "articles", "{876BAFF8-7221-4E72-A08A-7C242856DAAA}"
ProjectSection(SolutionItems) = preProject
docs\docfx_project\articles\jobCreation.md = docs\docfx_project\articles\jobCreation.md
sshConnection.md = sshConnection.md
docs\docfx_project\articles\toc.yml = docs\docfx_project\articles\toc.yml
docs\docfx_project\articles\tut.md = docs\docfx_project\articles\tut.md
docs\docfx_project\articles\tutwf.md = docs\docfx_project\articles\tutwf.md
docs\docfx_project\articles\workflowCreation.md = docs\docfx_project\articles\workflowCreation.md
EndProjectSection
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "ci", "ci", "{E74630EE-40C9-472E-A517-2BA8EB619D39}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,11 +131,11 @@ myJob.produceCall
// "
```

This job can be submitted using the `Connection.callToTerminalBash` function.
This job can be submitted using the `Runner.callToTerminalBash` function.
The job ID is returned as a string.

```fsharp
Connection.callToTerminalBash myJob.produceCall
Runner.callToTerminalBash myJob.produceCall
```


6 changes: 4 additions & 2 deletions docs/docfx_project/articles/toc.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
- name: Writing a jobscript
href: tut.md
href: jobCreation.md
- name: Writing a workflow
href: tutwf.md
href: workflowCreation.md
- name: SSH Connection
href: sshConnection.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ This workflow can now be submitted to the cluster. With this, all dependencies w
```fsharp
let workedOn = new List<string>()
WFGraph.submitAll resultGraph.Graph.Graph workedOn
Runner.submitAll resultGraph.Graph.Graph workedOn
```

## Visualisation
Expand Down
60 changes: 0 additions & 60 deletions src/Slurmi/Connection.fs

This file was deleted.

136 changes: 136 additions & 0 deletions src/Slurmi/Runner.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
namespace Slurmi

module Runner =
open Fli
open Graphoscope
open System.Collections.Generic
open SshNet
open Renci.SshNet
open Renci.SshNet.Common
open Workflow
//open Connection


let matchOutput (output) =
match output with
| Some value -> value
| None -> failwith "No output"

let callToTerminalCMD (command:string) =
let processResponse =
cli {
Shell CMD
Command command
}
|> Command.execute
// processResponse.Text
processResponse
let callToTerminalBash (command:string) =
let processResponse =
cli {
Shell BASH
Command command
}
|> Command.execute
// processResponse.Text
processResponse

let getResultFromCallCMD (command:string) =
(callToTerminalCMD (command)).Text
|> matchOutput

let getResultFromCallBash (command:string) =
(callToTerminalBash (command)).Text
|> matchOutput

let sendToTerminalAndReceiveJobIDBash (job:Job)=
//job.OnlyKey |> OnlyKey.SetParsable true |> ignore

let res = getResultFromCallBash (job.formatProcess)
// submit
// get return
// set as Job ID
job |> Job.SetJobID res |> ignore


let sendToTerminalAndReceiveJobIDCMD (job:Job)=
// job
// set parsable
//job.OnlyKey |> OnlyKey.SetParsable true |> ignore

let res = getResultFromCallCMD (job.formatProcess)
// submit
// get return
// set as Job ID
job |> Job.SetJobID res |> ignore

let checkForWorkedBash (graph:FGraph<string,JobWithDep,KindOfDependency>)(jobToLook:string) (workedOn:List<string>)=
if (WFGraph.arePredecessorsWorkedAlready graph jobToLook workedOn) then

if workedOn.Contains jobToLook then
//then printfn "already worked on %A "jobToLook
()
else
//printfn "added %A" jobToLook
let jtwo = WFGraph.getJob graph jobToLook

WFGraph.formatDep graph jobToLook
jtwo.JobInfo |> Job.SetJobID (getResultFromCallBash (jtwo.JobInfo.produceCall)) |> ignore

workedOn.Add jobToLook
else
//printfn "false"
()

let sshToTerminal (client:SshClient) (job:Job)=
client.RunCommand(job.produceCall).Result

let checkForWorkedBashSSH (graph:FGraph<string,JobWithDep,KindOfDependency>)(jobToLook:string) (workedOn:List<string>) (client: SshClient)=
if (WFGraph.arePredecessorsWorkedAlready graph jobToLook workedOn) then

if workedOn.Contains jobToLook then
//then printfn "already worked on %A "jobToLook
()
else
//printfn "added %A" jobToLook
let jtwo = WFGraph.getJob graph jobToLook

WFGraph.formatDep graph jobToLook
jtwo.JobInfo |> Job.SetJobID (sshToTerminal client (jtwo.JobInfo)) |> ignore

workedOn.Add jobToLook
else
//printfn "false"
()


let rec checkAllForWorkedSSH (graph:FGraph<string,JobWithDep,KindOfDependency>) (jobs:string ) (workedOn:List<string>) (client: SshClient)=
checkForWorkedBashSSH graph jobs workedOn client
if (WFGraph.hasSuccessors graph jobs) then
let successors = WFGraph.getSuccessors graph jobs

successors |> Seq.iter (fun x -> checkAllForWorkedSSH graph (fst x) workedOn client)
else
()

let rec checkAllForWorked (graph:FGraph<string,JobWithDep,KindOfDependency>) (jobs:string ) (workedOn:List<string>) =
checkForWorkedBash graph jobs workedOn
if (WFGraph.hasSuccessors graph jobs) then
let successors = WFGraph.getSuccessors graph jobs

successors |> Seq.iter (fun x -> checkAllForWorked graph (fst x) workedOn)
else
()


let submitAll (graph:FGraph<string,JobWithDep,KindOfDependency>) (workedOn:List<string>)=
let firstNodes =
WFGraph.getNodesWithoutDependencies graph
|> Seq.toArray
firstNodes |> Array.map (fun x -> checkAllForWorked graph x.JobInfo.Name workedOn) |> ignore

let submitAllSSH (graph:FGraph<string,JobWithDep,KindOfDependency>) (workedOn:List<string>) (client:SshClient)=
let firstNodes =
WFGraph.getNodesWithoutDependencies graph
|> Seq.toArray
firstNodes |> Array.map (fun x -> checkAllForWorkedSSH graph x.JobInfo.Name workedOn client) |> ignore
2 changes: 1 addition & 1 deletion src/Slurmi/Slurmi.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@
<Compile Include="Process.fs" />
<Compile Include="Dependency.fs" />
<Compile Include="Job.fs" />
<Compile Include="Connection.fs" />
<Compile Include="Workflow.fs" />
<Compile Include="Runner.fs" />
</ItemGroup>

<ItemGroup>
Expand Down
72 changes: 2 additions & 70 deletions src/Slurmi/Workflow.fs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ open System.Collections.Generic
open SshNet
open Renci.SshNet
open Renci.SshNet.Common
open Connection
//open Connection

module Workflow =
type JobWithDep =
Expand Down Expand Up @@ -85,79 +85,11 @@ module Workflow =
let command = deps |> String.concat (jobInfo.AllOrAny |> TypeOfDep.toString) |> String.filter (fun x -> x <> ' ' ) |> String.filter (fun x -> x <> '\n')
printfn "%A" command
if command = "" then
printfn "no"
else
jobInfo.JobInfo.CommandWithArgument |> Command.SetDependency command |> ignore

static member checkForWorkedBash (graph:FGraph<string,JobWithDep,KindOfDependency>)(jobToLook:string) (workedOn:List<string>)=
if (WFGraph.arePredecessorsWorkedAlready graph jobToLook workedOn) then

if workedOn.Contains jobToLook then
//then printfn "already worked on %A "jobToLook
()
else
//printfn "added %A" jobToLook
let jtwo = WFGraph.getJob graph jobToLook

WFGraph.formatDep graph jobToLook
jtwo.JobInfo |> Job.SetJobID (getResultFromCallBash (jtwo.JobInfo.produceCall)) |> ignore

workedOn.Add jobToLook
else
//printfn "false"
()
static member sshToTerminal (client:SshClient) (job:Job)=
client.RunCommand(job.produceCall).Result

static member checkForWorkedBashSSH (graph:FGraph<string,JobWithDep,KindOfDependency>)(jobToLook:string) (workedOn:List<string>) (client: SshClient)=
if (WFGraph.arePredecessorsWorkedAlready graph jobToLook workedOn) then

if workedOn.Contains jobToLook then
//then printfn "already worked on %A "jobToLook
()
else
printfn "added %A" jobToLook
let jtwo = WFGraph.getJob graph jobToLook

WFGraph.formatDep graph jobToLook
jtwo.JobInfo |> Job.SetJobID (WFGraph.sshToTerminal client (jtwo.JobInfo)) |> ignore

workedOn.Add jobToLook
else
//printfn "false"
()


static member checkAllForWorkedSSH (graph:FGraph<string,JobWithDep,KindOfDependency>) (jobs:string ) (workedOn:List<string>) (client: SshClient)=
WFGraph.checkForWorkedBashSSH graph jobs workedOn client
if (WFGraph.hasSuccessors graph jobs) then
let successors = WFGraph.getSuccessors graph jobs

successors |> Seq.iter (fun x -> WFGraph.checkAllForWorkedSSH graph (fst x) workedOn client)
else
()

static member checkAllForWorked (graph:FGraph<string,JobWithDep,KindOfDependency>) (jobs:string ) (workedOn:List<string>) =
WFGraph.checkForWorkedBash graph jobs workedOn
if (WFGraph.hasSuccessors graph jobs) then
let successors = WFGraph.getSuccessors graph jobs

successors |> Seq.iter (fun x -> WFGraph.checkAllForWorked graph (fst x) workedOn)
else
()
jobInfo.JobInfo.CommandWithArgument |> Command.SetDependency command |> ignore


static member submitAll (graph:FGraph<string,JobWithDep,KindOfDependency>) (workedOn:List<string>)=
let firstNodes =
WFGraph.getNodesWithoutDependencies graph
|> Seq.toArray
firstNodes |> Array.map (fun x -> WFGraph.checkAllForWorked graph x.JobInfo.Name workedOn) |> ignore

static member submitAllSSH (graph:FGraph<string,JobWithDep,KindOfDependency>) (workedOn:List<string>) (client:SshClient)=
let firstNodes =
WFGraph.getNodesWithoutDependencies graph
|> Seq.toArray
firstNodes |> Array.map (fun x -> WFGraph.checkAllForWorkedSSH graph x.JobInfo.Name workedOn client) |> ignore

type Workflow =
{
Expand Down
Loading

0 comments on commit 42bf074

Please sign in to comment.