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