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"
|
2022-08-17 16:26:34 +00:00
|
|
|
"github.com/hashicorp/nomad/helper/pointer"
|
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{
|
2022-08-17 16:26:34 +00:00
|
|
|
Region: pointer.Of("global"),
|
|
|
|
ID: pointer.Of(uuid.Generate()),
|
|
|
|
Name: pointer.Of("my-job"),
|
|
|
|
Type: pointer.Of("service"),
|
|
|
|
Priority: pointer.Of(50),
|
|
|
|
AllAtOnce: pointer.Of(false),
|
2017-02-20 23:53:56 +00:00
|
|
|
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
|
|
|
{
|
2022-08-17 16:26:34 +00:00
|
|
|
Name: pointer.Of("web"),
|
|
|
|
Count: pointer.Of(10),
|
2019-01-18 18:00:28 +00:00
|
|
|
EphemeralDisk: &api.EphemeralDisk{
|
2022-08-17 16:26:34 +00:00
|
|
|
SizeMB: pointer.Of(150),
|
2017-02-20 23:53:56 +00:00
|
|
|
},
|
2019-01-18 18:00:28 +00:00
|
|
|
RestartPolicy: &api.RestartPolicy{
|
2022-08-17 16:26:34 +00:00
|
|
|
Attempts: pointer.Of(3),
|
|
|
|
Interval: pointer.Of(10 * time.Minute),
|
|
|
|
Delay: pointer.Of(1 * time.Minute),
|
|
|
|
Mode: pointer.Of("delay"),
|
2017-02-20 23:53:56 +00:00
|
|
|
},
|
2020-08-28 17:15:26 +00:00
|
|
|
Networks: []*api.NetworkResource{
|
|
|
|
{
|
|
|
|
Mode: "host",
|
|
|
|
DynamicPorts: []api.Port{{Label: "http"}, {Label: "admin"}},
|
|
|
|
},
|
|
|
|
},
|
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{
|
2022-08-17 16:26:34 +00:00
|
|
|
CPU: pointer.Of(500),
|
|
|
|
MemoryMB: pointer.Of(256),
|
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()
|
2022-08-17 16:26:34 +00:00
|
|
|
j.Region = pointer.Of("north-america")
|
2019-05-02 20:00:21 +00:00
|
|
|
return j
|
|
|
|
}
|
2022-11-08 10:26:28 +00:00
|
|
|
|
|
|
|
// MockRunnableJob returns a mock job that has a configuration that allows it to be
|
|
|
|
// placed on a TestAgent.
|
|
|
|
func MockRunnableJob() *api.Job {
|
|
|
|
job := MockJob()
|
|
|
|
|
|
|
|
// Configure job so it can be run on a TestAgent
|
|
|
|
job.Constraints = nil
|
|
|
|
job.TaskGroups[0].Constraints = nil
|
|
|
|
job.TaskGroups[0].Count = pointer.Of(1)
|
|
|
|
job.TaskGroups[0].Tasks[0].Driver = "mock_driver"
|
|
|
|
job.TaskGroups[0].Tasks[0].Services = nil
|
|
|
|
job.TaskGroups[0].Tasks[0].Config = map[string]interface{}{
|
|
|
|
"run_for": "10s",
|
|
|
|
}
|
|
|
|
|
|
|
|
return job
|
|
|
|
}
|