github.com/huiliang/nomad@v0.2.1-0.20151124023127-7a8b664699ff/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 }, 52 NodeClass: "linux-medium-pci", 53 Status: structs.NodeStatusReady, 54 } 55 return node 56 } 57 58 func Job() *structs.Job { 59 job := &structs.Job{ 60 Region: "global", 61 ID: structs.GenerateUUID(), 62 Name: "my-job", 63 Type: structs.JobTypeService, 64 Priority: 50, 65 AllAtOnce: false, 66 Datacenters: []string{"dc1"}, 67 Constraints: []*structs.Constraint{ 68 &structs.Constraint{ 69 LTarget: "$attr.kernel.name", 70 RTarget: "linux", 71 Operand: "=", 72 }, 73 }, 74 TaskGroups: []*structs.TaskGroup{ 75 &structs.TaskGroup{ 76 Name: "web", 77 Count: 10, 78 RestartPolicy: &structs.RestartPolicy{ 79 Attempts: 3, 80 Interval: 10 * time.Minute, 81 Delay: 1 * time.Minute, 82 }, 83 Tasks: []*structs.Task{ 84 &structs.Task{ 85 Name: "web", 86 Driver: "exec", 87 Config: map[string]interface{}{ 88 "command": "/bin/date", 89 }, 90 Env: map[string]string{ 91 "FOO": "bar", 92 }, 93 Resources: &structs.Resources{ 94 CPU: 500, 95 MemoryMB: 256, 96 Networks: []*structs.NetworkResource{ 97 &structs.NetworkResource{ 98 MBits: 50, 99 DynamicPorts: []structs.Port{{Label: "http"}}, 100 }, 101 }, 102 }, 103 }, 104 }, 105 Meta: map[string]string{ 106 "elb_check_type": "http", 107 "elb_check_interval": "30s", 108 "elb_check_min": "3", 109 }, 110 }, 111 }, 112 Meta: map[string]string{ 113 "owner": "armon", 114 }, 115 Status: structs.JobStatusPending, 116 CreateIndex: 42, 117 ModifyIndex: 99, 118 } 119 return job 120 } 121 122 func SystemJob() *structs.Job { 123 job := &structs.Job{ 124 Region: "global", 125 ID: structs.GenerateUUID(), 126 Name: "my-job", 127 Type: structs.JobTypeSystem, 128 Priority: 100, 129 AllAtOnce: false, 130 Datacenters: []string{"dc1"}, 131 Constraints: []*structs.Constraint{ 132 &structs.Constraint{ 133 LTarget: "$attr.kernel.name", 134 RTarget: "linux", 135 Operand: "=", 136 }, 137 }, 138 TaskGroups: []*structs.TaskGroup{ 139 &structs.TaskGroup{ 140 Name: "web", 141 Count: 1, 142 RestartPolicy: &structs.RestartPolicy{ 143 Attempts: 3, 144 Interval: 10 * time.Minute, 145 Delay: 1 * time.Minute, 146 }, 147 Tasks: []*structs.Task{ 148 &structs.Task{ 149 Name: "web", 150 Driver: "exec", 151 Config: map[string]interface{}{ 152 "command": "/bin/date", 153 }, 154 Resources: &structs.Resources{ 155 CPU: 500, 156 MemoryMB: 256, 157 Networks: []*structs.NetworkResource{ 158 &structs.NetworkResource{ 159 MBits: 50, 160 DynamicPorts: []structs.Port{{Label: "http"}}, 161 }, 162 }, 163 }, 164 }, 165 }, 166 }, 167 }, 168 Meta: map[string]string{ 169 "owner": "armon", 170 }, 171 Status: structs.JobStatusPending, 172 CreateIndex: 42, 173 ModifyIndex: 99, 174 } 175 return job 176 } 177 178 func Eval() *structs.Evaluation { 179 eval := &structs.Evaluation{ 180 ID: structs.GenerateUUID(), 181 Priority: 50, 182 Type: structs.JobTypeService, 183 JobID: structs.GenerateUUID(), 184 Status: structs.EvalStatusPending, 185 } 186 return eval 187 } 188 189 func Alloc() *structs.Allocation { 190 alloc := &structs.Allocation{ 191 ID: structs.GenerateUUID(), 192 EvalID: structs.GenerateUUID(), 193 NodeID: "foo", 194 TaskGroup: "web", 195 Resources: &structs.Resources{ 196 CPU: 500, 197 MemoryMB: 256, 198 Networks: []*structs.NetworkResource{ 199 &structs.NetworkResource{ 200 Device: "eth0", 201 IP: "192.168.0.100", 202 ReservedPorts: []structs.Port{{Label: "main", Value: 12345}}, 203 MBits: 100, 204 DynamicPorts: []structs.Port{{Label: "http"}}, 205 }, 206 }, 207 }, 208 TaskResources: map[string]*structs.Resources{ 209 "web": &structs.Resources{ 210 CPU: 500, 211 MemoryMB: 256, 212 Networks: []*structs.NetworkResource{ 213 &structs.NetworkResource{ 214 Device: "eth0", 215 IP: "192.168.0.100", 216 ReservedPorts: []structs.Port{{Label: "main", Value: 5000}}, 217 MBits: 50, 218 DynamicPorts: []structs.Port{{Label: "http"}}, 219 }, 220 }, 221 }, 222 }, 223 TaskStates: map[string]*structs.TaskState{ 224 "web": &structs.TaskState{ 225 State: structs.TaskStatePending, 226 }, 227 }, 228 Job: Job(), 229 DesiredStatus: structs.AllocDesiredStatusRun, 230 ClientStatus: structs.AllocClientStatusPending, 231 } 232 alloc.JobID = alloc.Job.ID 233 return alloc 234 } 235 236 func Plan() *structs.Plan { 237 return &structs.Plan{ 238 Priority: 50, 239 } 240 } 241 242 func PlanResult() *structs.PlanResult { 243 return &structs.PlanResult{} 244 }