11package main
22
33import (
4+ "errors"
45 "fmt"
56 "log"
67 "os"
@@ -23,6 +24,8 @@ import (
2324
2425const (
2526 LoopWaitSecond = 2
27+ OVHConfig = "ovh"
28+ SwiftConfig = "swift"
2629)
2730
2831var (
5053)
5154
5255var (
53- configPath = "configuration.ini"
56+ configPath = "configuration.ini"
57+ SupportedProtocols = []string {SwiftConfig }
5458)
5559
5660type (
@@ -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