Skip to content

Commit

Permalink
Merge pull request #6 from compspec/add/scripts
Browse files Browse the repository at this point in the history
update jobspec for experimental types
  • Loading branch information
vsoch authored Mar 19, 2024
2 parents 0c701c6 + 4a960e2 commit 8020a01
Show file tree
Hide file tree
Showing 9 changed files with 262 additions and 151 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ exp2: build
$(COMMONENVVAR) $(BUILDENVVAR) go build -ldflags '-w' -o ./examples/experimental/bin/example2 examples/experimental/example2/example.go

.PHONY: test
test:
test: all
./examples/v1/bin/example1
./examples/v1/bin/example2
./examples/v1/bin/example3
Expand Down
2 changes: 1 addition & 1 deletion examples/experimental/example1/example.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ func main() {
fmt.Println("This example reads, parses, and validates a Jobspec")

// Assumes running from the root
fileName := flag.String("json", "examples/v1/example1/jobspec.yaml", "yaml file")
fileName := flag.String("json", "examples/experimental/example1/jobspec.yaml", "yaml file")
flag.Parse()

yamlFile := *fileName
Expand Down
5 changes: 3 additions & 2 deletions examples/experimental/example1/jobspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ resources:
with:
- type: core
count: 2
tasks:
- command:
task:
slot: "default"
command:
- ior
count:
per_slot: 1
Expand Down
2 changes: 1 addition & 1 deletion examples/experimental/example2/example.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ func main() {
fmt.Println("This example reads, parses, and validates a Jobspec")

// Assumes running from the root
fileName := flag.String("json", "examples/v1/example2/jobspec.yaml", "yaml file")
fileName := flag.String("json", "examples/experimental/example2/jobspec.yaml", "yaml file")
flag.Parse()

yamlFile := *fileName
Expand Down
35 changes: 19 additions & 16 deletions examples/experimental/example2/jobspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,29 @@ resources:
with:
- type: core
count: 2
tasks:
- count:
task:
slot: "default"
count:
per_slot: 1
script: |
#!/bin/bash
start_fractal() {
sleep 5
curl -X POST http://localhost:9092/start
}
echo "This is task \${FLUX_TASK_RANK}"
if [[ "\${FLUX_TASK_RANK}" == "0" ]]; then
start_fractal &
fractal leader --host 0.0.0.0:50051 --force-exit
else
fractal worker --host flux-sample-0.flux-service.default.svc.cluster.local:50051
fi
scripts:
- name: "job.sh"
content: |
#!/bin/bash
start_fractal() {
sleep 5
curl -X POST http://localhost:9092/start
}
echo "This is task \${FLUX_TASK_RANK}"
if [[ "\${FLUX_TASK_RANK}" == "0" ]]; then
start_fractal &
fractal leader --host 0.0.0.0:50051 --force-exit
else
fractal worker --host flux-sample-0.flux-service.default.svc.cluster.local:50051
fi
resources:
io:
storage:
- priority: 1
storage: mtl2unit
- priority: 2
storage: shm
storage: shm
13 changes: 6 additions & 7 deletions pkg/jobspec/experimental/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,11 @@ func NewSimpleJobspec(name, command string, nodes, tasks int32) (*Jobspec, error
// Tasks reference the slot and command
// Note: if we need better split can use "github.com/google/shlex"
cmd := strings.Split(command, " ")
taskResource := []Tasks{
{
Command: cmd,
Slot: name,
Count: Count{PerSlot: int32(1)},
}}
taskResource := Task{
Command: cmd,
Slot: name,
Count: Count{PerSlot: int32(1)},
}

// Attributes are for the system, we aren't going to add them yet
// attributes:
Expand All @@ -68,6 +67,6 @@ func NewSimpleJobspec(name, command string, nodes, tasks int32) (*Jobspec, error
return &Jobspec{
Version: jobspecVersion,
Resources: []Resource{nodeResource},
Tasks: taskResource,
Task: taskResource,
}, nil
}
10 changes: 3 additions & 7 deletions pkg/jobspec/experimental/jobspec.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,9 @@ func (js *Jobspec) GetJobName() string {
// If we have tasks, we can get from the command
// This entire set of checks is meant to be conservative
// and avoid any errors with nil / empty arrays, etc.
if js.Tasks != nil {
if len(js.Tasks) > 0 {
command := js.Tasks[0].Command
if len(command) > 0 {
name = command[0]
}
}
command := js.Task.Command
if len(command) > 0 {
name = command[0]
}
return name
}
Loading

0 comments on commit 8020a01

Please sign in to comment.