jobspec: parse job-level meta fields

This commit is contained in:
Mitchell Hashimoto 2015-09-14 17:46:52 -07:00
parent 9bd1c2f177
commit 8a006f2711
3 changed files with 23 additions and 0 deletions

View File

@ -74,6 +74,7 @@ func parseJob(result *structs.Job, obj *hclobj.Object) error {
if err := hcl.DecodeObject(&m, obj); err != nil {
return err
}
delete(m, "meta")
// Set the name to the object key
result.Name = obj.Key
@ -83,6 +84,20 @@ func parseJob(result *structs.Job, obj *hclobj.Object) error {
return err
}
// Parse out meta fields. These are in HCL as a list so we need
// to iterate over them and merge them.
if metaO := obj.Get("meta", false); metaO != nil {
for _, o := range metaO.Elem(false) {
var m map[string]interface{}
if err := hcl.DecodeObject(&m, o); err != nil {
return err
}
if err := mapstructure.WeakDecode(m, &result.Meta); err != nil {
return err
}
}
}
// If we have tasks outside, do those
if o := obj.Get("task", false); o != nil {
var tasks []*structs.Task

View File

@ -23,6 +23,10 @@ func TestParse(t *testing.T) {
AllAtOnce: true,
Datacenters: []string{"us2", "eu1"},
Meta: map[string]string{
"foo": "bar",
},
TaskGroups: []*structs.TaskGroup{
&structs.TaskGroup{
Name: "outside",

View File

@ -5,6 +5,10 @@ job "binstore-storagelocker" {
all_at_once = true
datacenters = ["us2", "eu1"]
meta {
foo = "bar"
}
task "outside" {
driver = "java"
config {