Skip to content

Commit 0462d45

Browse files
authored
Merge pull request #15 from ovh/dev/cgallot/PDATA-3104-understandable-error-messages
Dev/cgallot/pdata 3104 understandable error messages
2 parents 0b1cb1e + 4ce84a1 commit 0462d45

File tree

4 files changed

+89
-20
lines changed

4 files changed

+89
-20
lines changed

data_processing.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,3 +141,21 @@ func (c *Client) Kill(projectID string, jobID string) error {
141141
path := fmt.Sprintf(DataProcessingStatus, url.QueryEscape(projectID), url.QueryEscape(jobID))
142142
return c.OVH.Delete(path, nil)
143143
}
144+
145+
// GetErrorDetails return the error details as a formatted string
146+
func GetErrorDetails(err *ovh.APIError) string {
147+
if len(err.Details) == 0 {
148+
return ""
149+
}
150+
details := "{"
151+
first := true
152+
for key, value := range err.Details {
153+
if first {
154+
first = false
155+
} else {
156+
details += ", "
157+
}
158+
details = fmt.Sprintf("%s \"%s\": \"%s\"", details, key, value)
159+
}
160+
return details + " }"
161+
}

go.mod

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@ require (
88
github.com/dustin/go-humanize v1.0.0
99
github.com/gabriel-vasile/mimetype v1.1.0
1010
github.com/ncw/swift v1.0.52
11-
github.com/ovh/go-ovh v0.0.0-20181109152953-ba5adb4cf014
11+
github.com/ovh/go-ovh v1.1.1-0.20211209132054-5bcee91ddcd5
1212
github.com/peterhellberg/duration v0.0.0-20191119133758-ec6baeebcd10
13-
github.com/smartystreets/goconvey v1.6.4 // indirect
14-
gopkg.in/ini.v1 v1.55.0
13+
gopkg.in/ini.v1 v1.57.0
1514
)

go.sum

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ github.com/jtolds/gls v4.20.0+incompatible h1:xdiiI2gbIgH/gLH7ADydsJ1uDOEzR8yvV7
1616
github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU=
1717
github.com/ncw/swift v1.0.52 h1:ACF3JufDGgeKp/9mrDgQlEgS8kRYC4XKcuzj/8EJjQU=
1818
github.com/ncw/swift v1.0.52/go.mod h1:23YIA4yWVnGwv2dQlN4bB7egfYX6YLn0Yo/S6zZO/ZM=
19-
github.com/ovh/go-ovh v0.0.0-20181109152953-ba5adb4cf014 h1:37VE5TYj2m/FLA9SNr4z0+A0JefvTmR60Zwf8XSEV7c=
20-
github.com/ovh/go-ovh v0.0.0-20181109152953-ba5adb4cf014/go.mod h1:joRatxRJaZBsY3JAOEMcoOp05CnZzsx4scTxi95DHyQ=
19+
github.com/ovh/go-ovh v1.1.1-0.20211209132054-5bcee91ddcd5 h1:FKZON4nzuqn7tAyvIxMJKRke1ZXNOU8CRiMc6OX2caQ=
20+
github.com/ovh/go-ovh v1.1.1-0.20211209132054-5bcee91ddcd5/go.mod h1:AxitLZ5HBRPyUd+Zl60Ajaag+rNTdVXWIkzfrVuTXWA=
2121
github.com/peterhellberg/duration v0.0.0-20191119133758-ec6baeebcd10 h1:Jf08dx6hxr6aNpHzUmYitsKGm6BmCFbwDGPb27/Boyc=
2222
github.com/peterhellberg/duration v0.0.0-20191119133758-ec6baeebcd10/go.mod h1:x5xjkH61fUOJVgCCDgqNzlJvdLXiYpmMzSuum2FBOaw=
2323
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
@@ -34,5 +34,5 @@ golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5h
3434
golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg=
3535
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
3636
golang.org/x/tools v0.0.0-20190328211700-ab21143f2384/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
37-
gopkg.in/ini.v1 v1.55.0 h1:E8yzL5unfpW3M6fz/eB7Cb5MQAYSZ7GKo4Qth+N2sgQ=
38-
gopkg.in/ini.v1 v1.55.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k=
37+
gopkg.in/ini.v1 v1.57.0 h1:9unxIsFcTt4I55uWluz+UmL95q4kdJ0buvQ1ZIqVQww=
38+
gopkg.in/ini.v1 v1.57.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k=

submit.go

Lines changed: 65 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package main
22

33
import (
4+
"errors"
45
"fmt"
56
"log"
67
"os"
@@ -23,6 +24,8 @@ import (
2324

2425
const (
2526
LoopWaitSecond = 2
27+
OVHConfig = "ovh"
28+
SwiftConfig = "swift"
2629
)
2730

2831
var (
@@ -50,7 +53,8 @@ var (
5053
)
5154

5255
var (
53-
configPath = "configuration.ini"
56+
configPath = "configuration.ini"
57+
SupportedProtocols = []string{SwiftConfig}
5458
)
5559

5660
type (
@@ -73,6 +77,11 @@ func main() {
7377
log.Fatalf("Unable to load conf: %s", err)
7478
}
7579

80+
protocols, err := validConfig(conf)
81+
if err != nil {
82+
log.Fatalf("Invalid conf: %s", err)
83+
}
84+
7685
ovhConf := new(OVHConf)
7786
if err := conf["ovh"].MapTo(ovhConf); err != nil {
7887
log.Fatalf("Unable to parse \"ovh\" conf: %s", err)
@@ -93,20 +102,24 @@ func main() {
93102
splitFile := strings.Split(args.File, "/")
94103
protocol := strings.TrimSuffix(splitFile[0], ":")
95104
containerName := splitFile[1]
96-
storage, err := upload.New(conf[protocol], protocol)
97-
if err != nil {
98-
log.Fatalf("Error while Initialise Upload Storage: %s", err)
99-
}
100-
101-
if storage == nil {
102-
log.Fatalf("No configuration found for protocol %s", protocol)
103-
}
104-
filesList := strings.Split(args.Upload, ",")
105-
for _, file := range filesList {
106-
err = storage.Upload(file, containerName)
105+
if inTheList(protocol, protocols) {
106+
storage, err := upload.New(conf[protocol], protocol)
107107
if err != nil {
108-
log.Fatalf("Error while uploading file(s): %s", err)
108+
log.Fatalf("Error while initializing upload storage configurations: %s", err)
109109
}
110+
111+
if storage == nil {
112+
log.Fatalf("No configuration found for protocol %s", protocol)
113+
}
114+
filesList := strings.Split(args.Upload, ",")
115+
for _, file := range filesList {
116+
err = storage.Upload(file, containerName)
117+
if err != nil {
118+
log.Fatalf("Error while uploading file(s): %s", err)
119+
}
120+
}
121+
} else {
122+
log.Fatalf("Error while initializing upload storage configurations: protocol %s isn't configured in %s or isn't supported", protocol, configPath)
110123
}
111124
}
112125

@@ -117,6 +130,16 @@ func main() {
117130

118131
job, err := client.Submit(args.ProjectID, jobSubmitValue)
119132
if err != nil {
133+
if ovherr, ok := err.(*ovh.APIError); ok {
134+
if err.Error() == "Error 422: \"Unprocessable Entity\"" {
135+
log.Fatalf("Unable to submit job: %s :: %s :: %v. "+
136+
"Please check that your requested job complies with the OVHcloud Data Processing capabilities "+
137+
"(https://docs.ovh.com/gb/en/data-processing/capabilities/#the-apache-spark-job-in-data-processing-is-limited-to)", err, ovherr.Class, GetErrorDetails(ovherr))
138+
} else {
139+
log.Fatalf("Unable to submit job: %s :: %s :: %v.", err, ovherr.Class, GetErrorDetails(ovherr))
140+
}
141+
}
142+
120143
log.Fatalf("Unable to submit job: %s", err)
121144
}
122145

@@ -165,6 +188,7 @@ func ParsArgs() *JobSubmit {
165188
if args.JobName == "" {
166189
jobSubmit.Name = randomdata.SillyName()
167190
}
191+
168192
if strings.EqualFold(filepath.Ext(args.File), ".jar") {
169193
if args.Class == "" {
170194
p.Fail("You must provide --class when using jar file")
@@ -380,3 +404,31 @@ func PrintLog(jobLog []*Log) (lastPrintLog uint64) {
380404
}
381405
return lastPrintLog
382406
}
407+
408+
// test if a value is in the given list
409+
func inTheList(value string, values []string) bool {
410+
for _, element := range values {
411+
if value == element {
412+
return true
413+
}
414+
}
415+
return false
416+
}
417+
418+
// test if the given configurations are valid and list the protocols configured
419+
func validConfig(configSections map[string]*ini.Section) ([]string, error) {
420+
var confList []string
421+
var protocolsList []string
422+
for name, _ := range configSections {
423+
confList = append(confList, name)
424+
if inTheList(name, SupportedProtocols) {
425+
protocolsList = append(protocolsList, name)
426+
}
427+
}
428+
429+
if !inTheList(OVHConfig, confList) {
430+
return protocolsList, errors.New("missing [ovh] configurations in " + configPath)
431+
}
432+
433+
return protocolsList, nil
434+
}

0 commit comments

Comments
 (0)