github.com/dkerwin/nomad@v0.3.3-0.20160525181927-74554135514b/nomad/mock/mock.go (about) 1 package mock 2 3 import ( 4 "time" 5 6 "github.com/hashicorp/nomad/nomad/structs" 7 ) 8 9 func Node() *structs.Node { 10 node := &structs.Node{ 11 ID: structs.GenerateUUID(), 12 Datacenter: "dc1", 13 Name: "foobar", 14 Attributes: map[string]string{ 15 "kernel.name": "linux", 16 "arch": "x86", 17 "version": "0.1.0", 18 "driver.exec": "1", 19 }, 20 Resources: &structs.Resources{ 21 CPU: 4000, 22 MemoryMB: 8192, 23 DiskMB: 100 * 1024, 24 IOPS: 150, 25 Networks: []*structs.NetworkResource{ 26 &structs.NetworkResource{ 27 Device: "eth0", 28 CIDR: "192.168.0.100/32", 29 MBits: 1000, 30 }, 31 }, 32 }, 33 Reserved: &structs.Resources{ 34 CPU: 100, 35 MemoryMB: 256, 36 DiskMB: 4 * 1024, 37 Networks: []*structs.NetworkResource{ 38 &structs.NetworkResource{ 39 Device: "eth0", 40 IP: "192.168.0.100", 41 ReservedPorts: []structs.Port{{Label: "main", Value: 22}}, 42 MBits: 1, 43 }, 44 }, 45 }, 46 Links: map[string]string{ 47 "consul": "foobar.dc1", 48 }, 49 Meta: map[string]string{ 50 "pci-dss": "true", 51 "database": "mysql", 52 "version": "5.6", 53 }, 54 NodeClass: "linux-medium-pci", 55 Status: structs.NodeStatusReady, 56 } 57 node.ComputeClass() 58 return node 59 } 60 61 func Job() *structs.Job { 62 job := &structs.Job{ 63 Region: "global", 64 ID: structs.GenerateUUID(), 65 Name: "my-job", 66 Type: structs.JobTypeService, 67 Priority: 50, 68 AllAtOnce: false, 69 Datacenters: []string{"dc1"}, 70 Constraints: []*structs.Constraint{ 71 &structs.Constraint{ 72 LTarget: "${attr.kernel.name}", 73 RTarget: "linux", 74 Operand: "=", 75 }, 76 }, 77 TaskGroups: []*structs.TaskGroup{ 78 &structs.TaskGroup{ 79 Name: "web", 80 Count: 10, 81 RestartPolicy: &structs.RestartPolicy{ 82 Attempts: 3, 83 Interval: 10 * time.Minute, 84 Delay: 1 * time.Minute, 85 Mode: structs.RestartPolicyModeDelay, 86 }, 87 Tasks: []*structs.Task{ 88 &structs.Task{ 89 Name: "web", 90 Driver: "exec", 91 Config: map[string]interface{}{ 92 "command": "/bin/date", 93 }, 94 Env: map[string]string{ 95 "FOO": "bar", 96 }, 97 Services: []*structs.Service{ 98 { 99 Name: "${TASK}-frontend", 100 PortLabel: "http", 101 Tags: []string{"pci:${meta.pci-dss}", "datacenter:${node.datacenter}"}, 102 Checks: []*structs.ServiceCheck{ 103 { 104 Name: "check-table", 105 Type: structs.ServiceCheckScript, 106 Command: "/usr/local/check-table-${meta.database}", 107 Args: []string{"${meta.version}"}, 108 Interval: 30 * time.Second, 109 Timeout: 5 * time.Second, 110 }, 111 }, 112 }, 113 { 114 Name: "${TASK}-admin", 115 PortLabel: "admin", 116 }, 117 }, 118 LogConfig: structs.DefaultLogConfig(), 119 Resources: &structs.Resources{ 120 CPU: 500, 121 MemoryMB: 256, 122 DiskMB: 150, 123 Networks: []*structs.NetworkResource{ 124 &structs.NetworkResource{ 125 MBits: 50, 126 DynamicPorts: []structs.Port{{Label: "http"}, {Label: "admin"}}, 127 }, 128 }, 129 }, 130 Meta: map[string]string{ 131 "foo": "bar", 132 }, 133 }, 134 }, 135 Meta: map[string]string{ 136 "elb_check_type": "http", 137 "elb_check_interval": "30s", 138 "elb_check_min": "3", 139 }, 140 }, 141 }, 142 Meta: map[string]string{ 143 "owner": "armon", 144 }, 145 Status: structs.JobStatusPending, 146 CreateIndex: 42, 147 ModifyIndex: 99, 148 JobModifyIndex: 99, 149 } 150 job.InitFields() 151 return job 152 } 153 154 func SystemJob() *structs.Job { 155 job := &structs.Job{ 156 Region: "global", 157 ID: structs.GenerateUUID(), 158 Name: "my-job", 159 Type: structs.JobTypeSystem, 160 Priority: 100, 161 AllAtOnce: false, 162 Datacenters: []string{"dc1"}, 163 Constraints: []*structs.Constraint{ 164 &structs.Constraint{ 165 LTarget: "${attr.kernel.name}", 166 RTarget: "linux", 167 Operand: "=", 168 }, 169 }, 170 TaskGroups: []*structs.TaskGroup{ 171 &structs.TaskGroup{ 172 Name: "web", 173 Count: 1, 174 RestartPolicy: &structs.RestartPolicy{ 175 Attempts: 3, 176 Interval: 10 * time.Minute, 177 Delay: 1 * time.Minute, 178 Mode: structs.RestartPolicyModeDelay, 179 }, 180 Tasks: []*structs.Task{ 181 &structs.Task{ 182 Name: "web", 183 Driver: "exec", 184 Config: map[string]interface{}{ 185 "command": "/bin/date", 186 }, 187 Resources: &structs.Resources{ 188 CPU: 500, 189 MemoryMB: 256, 190 Networks: []*structs.NetworkResource{ 191 &structs.NetworkResource{ 192 MBits: 50, 193 DynamicPorts: []structs.Port{{Label: "http"}}, 194 }, 195 }, 196 }, 197 LogConfig: structs.DefaultLogConfig(), 198 }, 199 }, 200 }, 201 }, 202 Meta: map[string]string{ 203 "owner": "armon", 204 }, 205 Status: structs.JobStatusPending, 206 CreateIndex: 42, 207 ModifyIndex: 99, 208 } 209 return job 210 } 211 212 func PeriodicJob() *structs.Job { 213 job := Job() 214 job.Type = structs.JobTypeBatch 215 job.Periodic = &structs.PeriodicConfig{ 216 Enabled: true, 217 SpecType: structs.PeriodicSpecCron, 218 Spec: "*/30 * * * *", 219 } 220 return job 221 } 222 223 func Eval() *structs.Evaluation { 224 eval := &structs.Evaluation{ 225 ID: structs.GenerateUUID(), 226 Priority: 50, 227 Type: structs.JobTypeService, 228 JobID: structs.GenerateUUID(), 229 Status: structs.EvalStatusPending, 230 } 231 return eval 232 } 233 234 func Alloc() *structs.Allocation { 235 alloc := &structs.Allocation{ 236 ID: structs.GenerateUUID(), 237 EvalID: structs.GenerateUUID(), 238 NodeID: "12345678-abcd-efab-cdef-123456789abc", 239 TaskGroup: "web", 240 Resources: &structs.Resources{ 241 CPU: 500, 242 MemoryMB: 256, 243 DiskMB: 10, 244 Networks: []*structs.NetworkResource{ 245 &structs.NetworkResource{ 246 Device: "eth0", 247 IP: "192.168.0.100", 248 ReservedPorts: []structs.Port{{Label: "main", Value: 5000}}, 249 MBits: 50, 250 DynamicPorts: []structs.Port{{Label: "http"}}, 251 }, 252 }, 253 }, 254 TaskResources: map[string]*structs.Resources{ 255 "web": &structs.Resources{ 256 CPU: 500, 257 MemoryMB: 256, 258 DiskMB: 10, 259 Networks: []*structs.NetworkResource{ 260 &structs.NetworkResource{ 261 Device: "eth0", 262 IP: "192.168.0.100", 263 ReservedPorts: []structs.Port{{Label: "main", Value: 5000}}, 264 MBits: 50, 265 DynamicPorts: []structs.Port{{Label: "http"}}, 266 }, 267 }, 268 }, 269 }, 270 Job: Job(), 271 DesiredStatus: structs.AllocDesiredStatusRun, 272 ClientStatus: structs.AllocClientStatusPending, 273 } 274 alloc.JobID = alloc.Job.ID 275 return alloc 276 } 277 278 func Plan() *structs.Plan { 279 return &structs.Plan{ 280 Priority: 50, 281 } 282 } 283 284 func PlanResult() *structs.PlanResult { 285 return &structs.PlanResult{} 286 }