forked from cyverse-de/model
-
Notifications
You must be signed in to change notification settings - Fork 0
/
io.go
116 lines (100 loc) · 3.42 KB
/
io.go
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
108
109
110
111
112
113
114
115
116
package model
import (
"fmt"
"path"
"strings"
)
// StepInput describes a single input for a job step.
type StepInput struct {
ID string `json:"id"`
Ticket string `json:"ticket"`
Multiplicity string `json:"multiplicity"`
Name string `json:"name"`
Property string `json:"property"`
Retain bool `json:"retain"`
Type string `json:"type"`
Value string `json:"value"`
}
// IRODSPath returns a string containing the iRODS path to an input file.
func (i *StepInput) IRODSPath() string {
if i.Multiplicity == "collection" {
if !strings.HasSuffix(i.Value, "/") {
return fmt.Sprintf("%s/", i.Value)
}
}
return i.Value
}
// Identifier returns a string containing the input job's identifier in the
// format "input-<suffix>"
func (i *StepInput) Identifier(suffix string) string {
return fmt.Sprintf("input-%s", suffix)
}
// Stdout returns a string containing the path to the input job's stdout file.
// It should be a relative path in the format "logs/logs-stdout-<i.Identifier(suffix)>"
func (i *StepInput) Stdout(suffix string) string {
return path.Join("logs", fmt.Sprintf("logs-stdout-%s", i.Identifier(suffix)))
}
// Stderr returns a string containing the path to the input job's stderr file.
// It should be a relative path in the format "logs/logs-stderr-<i.Identifier(suffix)>"
func (i *StepInput) Stderr(suffix string) string {
return path.Join("logs", fmt.Sprintf("logs-stderr-%s", i.Identifier(suffix)))
}
// LogPath returns the path to the Condor log file for the input job. The returned
// path will be in the format "<parent>/logs/logs-condor-<i.Identifier(suffix)>"
func (i *StepInput) LogPath(parent, suffix string) string {
return path.Join(parent, "logs", fmt.Sprintf("logs-condor-%s", i.Identifier(suffix)))
}
// Source returns the path to the local filename of the input file.
func (i *StepInput) Source() string {
value := path.Base(i.Value)
if i.Multiplicity == "collection" {
if !strings.HasSuffix(value, "/") {
return fmt.Sprintf("%s/", value)
}
}
return value
}
// InputSourceListArguments returns the porklock settings needed for a get command with an input path list.
func (j *Job) InputSourceListArguments(sourceListPath string) []string {
args := []string{
"get",
"--user", j.Submitter,
"--source-list", sourceListPath,
"--config", "/configs/irods-config",
}
args = append(args, MetadataArgs(j.FileMetadata).FileMetadataArguments()...)
return args
}
// Arguments returns the porklock settings needed for the input operation.
func (i *StepInput) Arguments(username string, metadata []FileMetadata) []string {
args := []string{
"get",
"--user", username,
"--source", i.IRODSPath(),
"--config", "/configs/irods-config",
}
args = append(args, MetadataArgs(metadata).FileMetadataArguments()...)
return args
}
// StepOutput describes a single output for a job step.
type StepOutput struct {
Multiplicity string `json:"multiplicity"`
Name string `json:"name"`
Property string `json:"property"`
QualID string `json:"qual-id"`
Retain bool `json:"retain"`
Type string `json:"type"`
}
// Source returns the path to the local filename for the output file.
func (o *StepOutput) Source() string {
value := o.Name
if o.Multiplicity == "collection" {
if !path.IsAbs(value) {
value = fmt.Sprintf("/de-app-work/%s", value)
}
if !strings.HasSuffix(value, "/") {
value = fmt.Sprintf("%s/", value)
}
}
return value
}