open-nomad/nomad/mock/mock.go

241 lines
5.1 KiB
Go
Raw Normal View History

package mock
2015-10-31 01:34:23 +00:00
import (
"github.com/hashicorp/nomad/nomad/structs"
"time"
)
func Node() *structs.Node {
node := &structs.Node{
ID: structs.GenerateUUID(),
Datacenter: "dc1",
Name: "foobar",
Attributes: map[string]string{
2015-09-07 02:47:02 +00:00
"kernel.name": "linux",
"arch": "x86",
"version": "0.1.0",
"driver.exec": "1",
},
Resources: &structs.Resources{
2015-09-23 18:14:32 +00:00
CPU: 4000,
MemoryMB: 8192,
DiskMB: 100 * 1024,
IOPS: 150,
Networks: []*structs.NetworkResource{
&structs.NetworkResource{
Device: "eth0",
CIDR: "192.168.0.100/32",
MBits: 1000,
},
},
},
Reserved: &structs.Resources{
2015-09-23 18:14:32 +00:00
CPU: 100,
MemoryMB: 256,
DiskMB: 4 * 1024,
Networks: []*structs.NetworkResource{
&structs.NetworkResource{
Device: "eth0",
IP: "192.168.0.100",
ReservedPorts: []int{22},
MBits: 1,
},
},
},
Links: map[string]string{
"consul": "foobar.dc1",
},
Meta: map[string]string{
"pci-dss": "true",
},
NodeClass: "linux-medium-pci",
Status: structs.NodeStatusReady,
}
return node
}
func Job() *structs.Job {
job := &structs.Job{
2015-09-15 18:12:46 +00:00
Region: "global",
ID: structs.GenerateUUID(),
2015-08-14 05:07:01 +00:00
Name: "my-job",
Type: structs.JobTypeService,
Priority: 50,
AllAtOnce: false,
Datacenters: []string{"dc1"},
Constraints: []*structs.Constraint{
&structs.Constraint{
LTarget: "$attr.kernel.name",
RTarget: "linux",
Operand: "=",
},
},
TaskGroups: []*structs.TaskGroup{
&structs.TaskGroup{
Name: "web",
Count: 10,
2015-10-31 01:34:23 +00:00
RestartPolicy: &structs.RestartPolicy{
Attempts: 3,
Interval: 10 * time.Minute,
Delay: 1 * time.Minute,
},
Tasks: []*structs.Task{
&structs.Task{
Name: "web",
2015-08-29 23:24:01 +00:00
Driver: "exec",
Config: map[string]string{
2015-08-29 23:24:01 +00:00
"command": "/bin/date",
"args": "+%s",
},
Env: map[string]string{
"FOO": "bar",
},
Resources: &structs.Resources{
2015-09-23 18:14:32 +00:00
CPU: 500,
MemoryMB: 256,
2015-09-13 23:40:31 +00:00
Networks: []*structs.NetworkResource{
&structs.NetworkResource{
MBits: 50,
2015-09-22 21:02:51 +00:00
DynamicPorts: []string{"http"},
2015-09-13 23:40:31 +00:00
},
},
},
},
},
Meta: map[string]string{
"elb_check_type": "http",
"elb_check_interval": "30s",
"elb_check_min": "3",
},
},
},
Meta: map[string]string{
"owner": "armon",
},
2015-08-13 23:25:59 +00:00
Status: structs.JobStatusPending,
CreateIndex: 42,
ModifyIndex: 99,
}
return job
}
2015-10-14 23:43:06 +00:00
func SystemJob() *structs.Job {
job := &structs.Job{
Region: "global",
ID: structs.GenerateUUID(),
Name: "my-job",
Type: structs.JobTypeSystem,
Priority: 100,
AllAtOnce: false,
Datacenters: []string{"dc1"},
Constraints: []*structs.Constraint{
&structs.Constraint{
LTarget: "$attr.kernel.name",
RTarget: "linux",
Operand: "=",
},
},
TaskGroups: []*structs.TaskGroup{
&structs.TaskGroup{
Name: "web",
Count: 1,
2015-10-31 01:34:23 +00:00
RestartPolicy: &structs.RestartPolicy{
Attempts: 3,
Interval: 10 * time.Minute,
Delay: 1 * time.Minute,
},
2015-10-14 23:43:06 +00:00
Tasks: []*structs.Task{
&structs.Task{
Name: "web",
Driver: "exec",
Config: map[string]string{
"command": "/bin/date",
"args": "+%s",
},
Resources: &structs.Resources{
CPU: 500,
MemoryMB: 256,
Networks: []*structs.NetworkResource{
&structs.NetworkResource{
MBits: 50,
DynamicPorts: []string{"http"},
},
},
},
},
},
},
},
Meta: map[string]string{
"owner": "armon",
},
Status: structs.JobStatusPending,
CreateIndex: 42,
ModifyIndex: 99,
}
return job
}
func Eval() *structs.Evaluation {
eval := &structs.Evaluation{
ID: structs.GenerateUUID(),
Priority: 50,
Type: structs.JobTypeService,
JobID: structs.GenerateUUID(),
Status: structs.EvalStatusPending,
}
return eval
}
func Alloc() *structs.Allocation {
alloc := &structs.Allocation{
ID: structs.GenerateUUID(),
EvalID: structs.GenerateUUID(),
2015-08-29 23:24:01 +00:00
NodeID: "foo",
TaskGroup: "web",
Resources: &structs.Resources{
2015-09-23 18:14:32 +00:00
CPU: 500,
MemoryMB: 256,
Networks: []*structs.NetworkResource{
&structs.NetworkResource{
2015-09-13 02:13:00 +00:00
Device: "eth0",
IP: "192.168.0.100",
ReservedPorts: []int{12345},
MBits: 100,
2015-09-22 21:02:51 +00:00
DynamicPorts: []string{"http"},
},
},
},
TaskResources: map[string]*structs.Resources{
"web": &structs.Resources{
2015-09-23 18:14:32 +00:00
CPU: 500,
MemoryMB: 256,
Networks: []*structs.NetworkResource{
&structs.NetworkResource{
Device: "eth0",
IP: "192.168.0.100",
ReservedPorts: []int{5000},
MBits: 50,
2015-09-22 21:02:51 +00:00
DynamicPorts: []string{"http"},
},
},
},
},
2015-08-25 23:19:21 +00:00
Job: Job(),
DesiredStatus: structs.AllocDesiredStatusRun,
ClientStatus: structs.AllocClientStatusPending,
}
alloc.JobID = alloc.Job.ID
return alloc
}
func Plan() *structs.Plan {
return &structs.Plan{
Priority: 50,
}
}
func PlanResult() *structs.PlanResult {
return &structs.PlanResult{}
}