2019-01-18 18:00:28 +00:00
|
|
|
package agent
|
2017-02-20 23:53:56 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"time"
|
|
|
|
|
2019-01-18 18:00:28 +00:00
|
|
|
"github.com/hashicorp/nomad/api"
|
2017-02-20 23:53:56 +00:00
|
|
|
"github.com/hashicorp/nomad/helper"
|
2017-09-29 16:58:48 +00:00
|
|
|
"github.com/hashicorp/nomad/helper/uuid"
|
2017-02-20 23:53:56 +00:00
|
|
|
)
|
|
|
|
|
2019-01-18 18:00:28 +00:00
|
|
|
func MockJob() *api.Job {
|
|
|
|
job := &api.Job{
|
2017-02-20 23:53:56 +00:00
|
|
|
Region: helper.StringToPtr("global"),
|
2017-09-29 16:58:48 +00:00
|
|
|
ID: helper.StringToPtr(uuid.Generate()),
|
2017-02-20 23:53:56 +00:00
|
|
|
Name: helper.StringToPtr("my-job"),
|
|
|
|
Type: helper.StringToPtr("service"),
|
|
|
|
Priority: helper.IntToPtr(50),
|
|
|
|
AllAtOnce: helper.BoolToPtr(false),
|
|
|
|
Datacenters: []string{"dc1"},
|
2019-01-18 18:00:28 +00:00
|
|
|
Constraints: []*api.Constraint{
|
2017-09-26 22:26:33 +00:00
|
|
|
{
|
2017-02-20 23:53:56 +00:00
|
|
|
LTarget: "${attr.kernel.name}",
|
|
|
|
RTarget: "linux",
|
|
|
|
Operand: "=",
|
|
|
|
},
|
|
|
|
},
|
2019-01-18 18:00:28 +00:00
|
|
|
TaskGroups: []*api.TaskGroup{
|
2017-09-26 22:26:33 +00:00
|
|
|
{
|
2017-02-20 23:53:56 +00:00
|
|
|
Name: helper.StringToPtr("web"),
|
|
|
|
Count: helper.IntToPtr(10),
|
2019-01-18 18:00:28 +00:00
|
|
|
EphemeralDisk: &api.EphemeralDisk{
|
2017-02-20 23:53:56 +00:00
|
|
|
SizeMB: helper.IntToPtr(150),
|
|
|
|
},
|
2019-01-18 18:00:28 +00:00
|
|
|
RestartPolicy: &api.RestartPolicy{
|
2017-02-20 23:53:56 +00:00
|
|
|
Attempts: helper.IntToPtr(3),
|
|
|
|
Interval: helper.TimeToPtr(10 * time.Minute),
|
|
|
|
Delay: helper.TimeToPtr(1 * time.Minute),
|
|
|
|
Mode: helper.StringToPtr("delay"),
|
|
|
|
},
|
2019-01-18 18:00:28 +00:00
|
|
|
Tasks: []*api.Task{
|
2017-09-26 22:26:33 +00:00
|
|
|
{
|
2017-02-20 23:53:56 +00:00
|
|
|
Name: "web",
|
|
|
|
Driver: "exec",
|
|
|
|
Config: map[string]interface{}{
|
|
|
|
"command": "/bin/date",
|
|
|
|
},
|
|
|
|
Env: map[string]string{
|
|
|
|
"FOO": "bar",
|
|
|
|
},
|
2019-01-18 18:00:28 +00:00
|
|
|
Services: []*api.Service{
|
2017-02-20 23:53:56 +00:00
|
|
|
{
|
|
|
|
Name: "${TASK}-frontend",
|
|
|
|
PortLabel: "http",
|
|
|
|
Tags: []string{"pci:${meta.pci-dss}", "datacenter:${node.datacenter}"},
|
2019-01-18 18:00:28 +00:00
|
|
|
Checks: []api.ServiceCheck{
|
2017-02-20 23:53:56 +00:00
|
|
|
{
|
|
|
|
Name: "check-table",
|
|
|
|
Type: "script",
|
|
|
|
Command: "/usr/local/check-table-${meta.database}",
|
|
|
|
Args: []string{"${meta.version}"},
|
|
|
|
Interval: 30 * time.Second,
|
|
|
|
Timeout: 5 * time.Second,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "${TASK}-admin",
|
|
|
|
PortLabel: "admin",
|
|
|
|
},
|
|
|
|
},
|
2019-01-18 18:00:28 +00:00
|
|
|
LogConfig: api.DefaultLogConfig(),
|
|
|
|
Resources: &api.Resources{
|
2017-02-20 23:53:56 +00:00
|
|
|
CPU: helper.IntToPtr(500),
|
|
|
|
MemoryMB: helper.IntToPtr(256),
|
2019-01-18 18:00:28 +00:00
|
|
|
Networks: []*api.NetworkResource{
|
2017-09-26 22:26:33 +00:00
|
|
|
{
|
2017-02-20 23:53:56 +00:00
|
|
|
MBits: helper.IntToPtr(50),
|
2019-01-18 18:00:28 +00:00
|
|
|
DynamicPorts: []api.Port{{Label: "http"}, {Label: "admin"}},
|
2017-02-20 23:53:56 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Meta: map[string]string{
|
|
|
|
"foo": "bar",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Meta: map[string]string{
|
|
|
|
"elb_check_type": "http",
|
|
|
|
"elb_check_interval": "30s",
|
|
|
|
"elb_check_min": "3",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Meta: map[string]string{
|
|
|
|
"owner": "armon",
|
|
|
|
},
|
|
|
|
}
|
|
|
|
job.Canonicalize()
|
|
|
|
return job
|
|
|
|
}
|
|
|
|
|
2019-05-02 20:00:21 +00:00
|
|
|
func MockRegionalJob() *api.Job {
|
|
|
|
j := MockJob()
|
|
|
|
j.Region = helper.StringToPtr("north-america")
|
|
|
|
return j
|
|
|
|
}
|