forked from stripe-archive/timberlake
-
Notifications
You must be signed in to change notification settings - Fork 0
/
conf.go
62 lines (53 loc) · 1.41 KB
/
conf.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
package main
import (
"encoding/xml"
"io"
)
type conf struct {
Flags map[string]string `json:"flags"`
Input string `json:"input"`
Output string `json:"output"`
ScaldingSteps string `json:"scaldingSteps"`
name string
}
type confProperty struct {
Name string `xml:"name"`
Value string `xml:"value"`
}
type parsedJobConf struct {
XMLName xml.Name `xml:"configuration"`
Properties []confProperty `xml:"property"`
}
// update applies known configuration properties to the job object.
func (conf *conf) update(c map[string]string) {
if conf.Flags == nil {
conf.Flags = make(map[string]string)
}
for key, value := range c {
conf.Flags[key] = value
switch key {
case "mapreduce.input.fileinputformat.inputdir":
conf.Input = value
case "mapreduce.output.fileoutputformat.outputdir":
conf.Output = value
case "scalding.step.descriptions":
conf.ScaldingSteps = value
case "cascading.app.name":
conf.name = value
}
}
}
// loadConf loads a job's hadoop conf from an xml file represented by r.
func loadConf(r io.Reader) (map[string]string, error) {
decoder := xml.NewDecoder(r)
parsed := parsedJobConf{}
err := decoder.Decode(&parsed)
if err != nil {
return nil, err
}
conf := make(map[string]string, len(parsed.Properties))
for _, prop := range parsed.Properties {
conf[prop.Name] = prop.Value
}
return conf, nil
}