-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathqsub.go
More file actions
107 lines (96 loc) · 1.96 KB
/
Copy pathqsub.go
File metadata and controls
107 lines (96 loc) · 1.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
package main
import (
"fmt"
"regexp"
"strings"
)
type QsubFacade struct {
Shell ShellExecutor
PLGridFacade
}
//gets resource states
//returns array of resource states
func (qf QsubFacade) StatusCheck() ([]string, error) {
command := `qstat -u $USER`
stringOutput, err := qf.Shell.execute("[qsub]", command)
if err != nil {
return nil, fmt.Errorf(stringOutput)
}
return strings.Split(stringOutput, "\n"), nil
}
//receives command to execute
//executes command, extracts resource ID
//returns new job ID
func (qf QsubFacade) PrepareResource(ids, command string) (string, error) {
stringOutput, err := qf.Shell.execute(ids, command)
if err != nil {
return "", fmt.Errorf(stringOutput)
}
matches := regexp.MustCompile(`([\d]+.batch.grid.cyf-kr.edu.pl)`).FindStringSubmatch(stringOutput)
if len(matches) == 0 {
return "", fmt.Errorf(stringOutput)
}
return matches[1], nil
}
//receives job ID
//checks resource state based on job state
//returns resource state
func (qf QsubFacade) ResourceStatus(statusArray []string, smRecord *SMRecord) (string, error) {
if smRecord.JobID == "" {
return "available", nil
}
for _, status := range statusArray {
if strings.Contains(status, strings.Split(smRecord.JobID, ".")[0]) {
matches := regexp.MustCompile(`(?:\S+\s+){9}([A-Z]).+`).FindStringSubmatch(status)
if len(matches) == 0 {
return "", fmt.Errorf(status)
}
var res string
switch matches[1] {
case "Q":
{
res = "initializing"
}
case "W":
{
res = "initializing"
}
case "H":
{
res = "running_sm"
}
case "R":
{
res = "running_sm"
}
case "T":
{
res = "running_sm"
}
case "C":
{
res = "released"
}
case "E":
{
res = "released"
}
case "U":
{
res = "released"
}
case "S":
{
res = "error"
}
default:
{
return "", fmt.Errorf(status)
}
}
return res, nil
}
}
// no such jobID
return "released", nil
}