github.com/kardianos/nomad@v0.1.3-0.20151022182107-b13df73ee850/nomad/mock/mock.go (about) 1 package mock 2 3 import "github.com/hashicorp/nomad/nomad/structs" 4 5 func Node() *structs.Node { 6 node := &structs.Node{ 7 ID: structs.GenerateUUID(), 8 Datacenter: "dc1", 9 Name: "foobar", 10 Attributes: map[string]string{ 11 "kernel.name": "linux", 12 "arch": "x86", 13 "version": "0.1.0", 14 "driver.exec": "1", 15 }, 16 Resources: &structs.Resources{ 17 CPU: 4000, 18 MemoryMB: 8192, 19 DiskMB: 100 * 1024, 20 IOPS: 150, 21 Networks: []*structs.NetworkResource{ 22 &structs.NetworkResource{ 23 Device: "eth0", 24 CIDR: "192.168.0.100/32", 25 MBits: 1000, 26 }, 27 }, 28 }, 29 Reserved: &structs.Resources{ 30 CPU: 100, 31 MemoryMB: 256, 32 DiskMB: 4 * 1024, 33 Networks: []*structs.NetworkResource{ 34 &structs.NetworkResource{ 35 Device: "eth0", 36 IP: "192.168.0.100", 37 ReservedPorts: []int{22}, 38 MBits: 1, 39 }, 40 }, 41 }, 42 Links: map[string]string{ 43 "consul": "foobar.dc1", 44 }, 45 Meta: map[string]string{ 46 "pci-dss": "true", 47 }, 48 NodeClass: "linux-medium-pci", 49 Status: structs.NodeStatusReady, 50 } 51 return node 52 } 53 54 func Job() *structs.Job { 55 job := &structs.Job{ 56 Region: "global", 57 ID: structs.GenerateUUID(), 58 Name: "my-job", 59 Type: structs.JobTypeService, 60 Priority: 50, 61 AllAtOnce: false, 62 Datacenters: []string{"dc1"}, 63 Constraints: []*structs.Constraint{ 64 &structs.Constraint{ 65 Hard: true, 66 LTarget: "$attr.kernel.name", 67 RTarget: "linux", 68 Operand: "=", 69 }, 70 }, 71 TaskGroups: []*structs.TaskGroup{ 72 &structs.TaskGroup{ 73 Name: "web", 74 Count: 10, 75 Tasks: []*structs.Task{ 76 &structs.Task{ 77 Name: "web", 78 Driver: "exec", 79 Config: map[string]string{ 80 "command": "/bin/date", 81 "args": "+%s", 82 }, 83 Resources: &structs.Resources{ 84 CPU: 500, 85 MemoryMB: 256, 86 Networks: []*structs.NetworkResource{ 87 &structs.NetworkResource{ 88 MBits: 50, 89 DynamicPorts: []string{"http"}, 90 }, 91 }, 92 }, 93 }, 94 }, 95 Meta: map[string]string{ 96 "elb_check_type": "http", 97 "elb_check_interval": "30s", 98 "elb_check_min": "3", 99 }, 100 }, 101 }, 102 Meta: map[string]string{ 103 "owner": "armon", 104 }, 105 Status: structs.JobStatusPending, 106 CreateIndex: 42, 107 ModifyIndex: 99, 108 } 109 return job 110 } 111 112 func SystemJob() *structs.Job { 113 job := &structs.Job{ 114 Region: "global", 115 ID: structs.GenerateUUID(), 116 Name: "my-job", 117 Type: structs.JobTypeSystem, 118 Priority: 100, 119 AllAtOnce: false, 120 Datacenters: []string{"dc1"}, 121 Constraints: []*structs.Constraint{ 122 &structs.Constraint{ 123 Hard: true, 124 LTarget: "$attr.kernel.name", 125 RTarget: "linux", 126 Operand: "=", 127 }, 128 }, 129 TaskGroups: []*structs.TaskGroup{ 130 &structs.TaskGroup{ 131 Name: "web", 132 Count: 1, 133 Tasks: []*structs.Task{ 134 &structs.Task{ 135 Name: "web", 136 Driver: "exec", 137 Config: map[string]string{ 138 "command": "/bin/date", 139 "args": "+%s", 140 }, 141 Resources: &structs.Resources{ 142 CPU: 500, 143 MemoryMB: 256, 144 Networks: []*structs.NetworkResource{ 145 &structs.NetworkResource{ 146 MBits: 50, 147 DynamicPorts: []string{"http"}, 148 }, 149 }, 150 }, 151 }, 152 }, 153 }, 154 }, 155 Meta: map[string]string{ 156 "owner": "armon", 157 }, 158 Status: structs.JobStatusPending, 159 CreateIndex: 42, 160 ModifyIndex: 99, 161 } 162 return job 163 } 164 165 func Eval() *structs.Evaluation { 166 eval := &structs.Evaluation{ 167 ID: structs.GenerateUUID(), 168 Priority: 50, 169 Type: structs.JobTypeService, 170 JobID: structs.GenerateUUID(), 171 Status: structs.EvalStatusPending, 172 } 173 return eval 174 } 175 176 func Alloc() *structs.Allocation { 177 alloc := &structs.Allocation{ 178 ID: structs.GenerateUUID(), 179 EvalID: structs.GenerateUUID(), 180 NodeID: "foo", 181 TaskGroup: "web", 182 Resources: &structs.Resources{ 183 CPU: 500, 184 MemoryMB: 256, 185 Networks: []*structs.NetworkResource{ 186 &structs.NetworkResource{ 187 Device: "eth0", 188 IP: "192.168.0.100", 189 ReservedPorts: []int{12345}, 190 MBits: 100, 191 DynamicPorts: []string{"http"}, 192 }, 193 }, 194 }, 195 TaskResources: map[string]*structs.Resources{ 196 "web": &structs.Resources{ 197 CPU: 500, 198 MemoryMB: 256, 199 Networks: []*structs.NetworkResource{ 200 &structs.NetworkResource{ 201 Device: "eth0", 202 IP: "192.168.0.100", 203 ReservedPorts: []int{5000}, 204 MBits: 50, 205 DynamicPorts: []string{"http"}, 206 }, 207 }, 208 }, 209 }, 210 Job: Job(), 211 DesiredStatus: structs.AllocDesiredStatusRun, 212 ClientStatus: structs.AllocClientStatusPending, 213 } 214 alloc.JobID = alloc.Job.ID 215 return alloc 216 } 217 218 func Plan() *structs.Plan { 219 return &structs.Plan{ 220 Priority: 50, 221 } 222 } 223 224 func PlanResult() *structs.PlanResult { 225 return &structs.PlanResult{} 226 }