Skip to content

Commit

Permalink
Add SSH Functionality via SSH.NET
Browse files Browse the repository at this point in the history
  • Loading branch information
zieglerSe committed Nov 10, 2023
1 parent 8e38c9e commit 8a537d0
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 9 deletions.
7 changes: 5 additions & 2 deletions src/Slurmi/Job.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1906,6 +1906,8 @@ type Job (jobName: string,processList:(string*string list)list)=
localStr.Append ("#!/bin/bash \n") |> ignore
localStr.Append ("#SBATCH ") |> ignore
localStr.AppendFormat (sprintf "-J %s " this.Name) |> ignore
localStr.Append ("--parsable ") |> ignore

localStr.Append (this.formatOneDash) |> ignore
localStr.Append (this.formatTwoDashes) |> ignore
localStr.Append (this.formatOnlyKey) |> ignore
Expand All @@ -1920,6 +1922,7 @@ type Job (jobName: string,processList:(string*string list)list)=
//strLocal.AppendLine ("#!/bin/bash") |> ignore
strLocal.AppendLine ("sbatch <<EOF") |> ignore
strLocal.Append this.formatSlurmCalls |> ignore

strLocal.AppendLine("EOF") |> ignore
strLocal.ToString()

Expand Down Expand Up @@ -1954,7 +1957,7 @@ type Job (jobName: string,processList:(string*string list)list)=
|> this.matchOutput

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

let res = this.getResultFromCallBash (job.formatProcess)
// submit
Expand All @@ -1966,7 +1969,7 @@ type Job (jobName: string,processList:(string*string list)list)=
member this.sendToTerminalAndReceiveJobIDCMD (job:Job)=
// job
// set parsable
job.OnlyKey |> OnlyKey.SetParsable true |> ignore
//job.OnlyKey |> OnlyKey.SetParsable true |> ignore

let res = this.getResultFromCallCMD (job.formatProcess)
// submit
Expand Down
1 change: 1 addition & 0 deletions src/Slurmi/Slurmi.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
<PackageReference Include="DynamicObj" Version="2.0.0" />
<PackageReference Include="Fli" Version="1.10.0" />
<PackageReference Include="Graphoscope" Version="0.3.0" />
<PackageReference Include="SSH.NET" Version="2023.0.0" />

</ItemGroup>

Expand Down
56 changes: 49 additions & 7 deletions src/Slurmi/Workflow.fs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
open Fli
open Graphoscope
open System.Collections.Generic
open SshNet
open Renci.SshNet
open Renci.SshNet.Common

module Workflow =
type JobWithDep =
Expand All @@ -24,7 +27,7 @@ module Workflow =
|> List.iter (
fun jobWithDep ->
//FGraph.addElement jobWithDep.JobInfo.Name jobWithDep.DependingOn jobWithDep.DependingOn |> ignore
jobWithDep.JobInfo.OnlyKey |> OnlyKey.SetParsable true |> ignore
//jobWithDep.JobInfo.OnlyKey |> OnlyKey.SetParsable true |> ignore
jobWithDep.DependingOn
|> List.iter (fun (job,dep) -> FGraph.addElement job.Name (input|> List.find (fun x -> x.JobInfo.Name = job.Name)) jobWithDep.JobInfo.Name jobWithDep dep g |> ignore))

Expand Down Expand Up @@ -78,9 +81,12 @@ module Workflow =
member this.formatDep (graph:FGraph<string,JobWithDep,KindOfDependency>) (job:string) =
let deps = (this.getDependencies graph job) |> Seq.map (fun x ->(KindOfDependency.toString x.Value)+(this.getJobId graph x.Key)) |> Seq.toArray
let jobInfo = this.getJob graph job
let command = deps |> String.concat (jobInfo.AllOrAny |> TypeOfDep.toString)
//printfn "%A" command
jobInfo.JobInfo.TwoDashes |> LongCommand.SetDependency command |> ignore
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.TwoDashes |> LongCommand.SetDependency command |> ignore

member this.checkForWorkedBash (graph:FGraph<string,JobWithDep,KindOfDependency>)(jobToLook:string) (workedOn:List<string>)=
if (this.arePredecessorsWorkedAlready graph jobToLook workedOn) then
Expand All @@ -99,8 +105,38 @@ module Workflow =
else
//printfn "false"
()
member this.sshToTerminal (client:SshClient) (job:Job)=
client.RunCommand(job.produceCall).Result

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

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

member this.checkAllForWorked (graph:FGraph<string,JobWithDep,KindOfDependency>) (jobs:string ) (workedOn:List<string>) =
this.formatDep graph jobToLook
jtwo.JobInfo |> Job.SetJobID (this.sshToTerminal client (jtwo.JobInfo)) |> ignore

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


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

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

member this.checkAllForWorked (graph:FGraph<string,JobWithDep,KindOfDependency>) (jobs:string ) (workedOn:List<string>) =
this.checkForWorkedBash graph jobs workedOn
if (this.hasSuccessors graph jobs) then
let successors = this.getSuccessors graph jobs
Expand All @@ -116,6 +152,12 @@ module Workflow =
|> Seq.toArray
firstNodes |> Array.map (fun x -> this.checkAllForWorked graph x.JobInfo.Name workedOn) |> ignore

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

type Workflow =
{
Jobs : JobWithDep list
Expand Down Expand Up @@ -156,7 +198,7 @@ module Workflow =
member this.sendToTerminalAndReceiveJobIDBash (job:JobWithDep)=
// job
// set parsable
job.JobInfo.OnlyKey |> OnlyKey.SetParsable true |> ignore
//job.JobInfo.OnlyKey |> OnlyKey.SetParsable true |> ignore

let res = this.getResultFromCallBash (job.JobInfo.formatProcess)
// submit
Expand All @@ -168,7 +210,7 @@ module Workflow =
member this.sendToTerminalAndReceiveJobIDCMD (job:JobWithDep)=
// job
// set parsable
job.JobInfo.OnlyKey |> OnlyKey.SetParsable true |> ignore
//job.JobInfo.OnlyKey |> OnlyKey.SetParsable true |> ignore

let res = this.getResultFromCallCMD (job.JobInfo.formatProcess)
// submit
Expand Down

0 comments on commit 8a537d0

Please sign in to comment.