mirror of
https://github.com/kemko/nomad.git
synced 2026-01-02 00:15:43 +03:00
* Scaffolding actions (#18639) * Task-level actions for job submissions and retrieval * FIXME: Temporary workaround to get ember dev server to pass exec through to 4646 * Update api/tasks.go Co-authored-by: Tim Gross <tgross@hashicorp.com> * Update command/agent/job_endpoint.go Co-authored-by: Tim Gross <tgross@hashicorp.com> * Diff and copy implementations * Action structs get their own file, diff updates to behave like our other diffs * Test to observe actions changes in a version update * Tests migrated into structs/diff_test and modified with PR comments in mind * APIActionToSTructsAction now returns a new value * de-comment some plain parts, remove unused action lookup * unused param in action converter --------- Co-authored-by: Tim Gross <tgross@hashicorp.com> * New endpoint: job/:id/actions (#18690) * unused param in action converter * backing out of parse_job level and moved toward new endpoint level * Adds taskName and taskGroupName to actions at job level * Unmodified job mock actions tests * actionless job test * actionless job test * Multi group multi task actions test * HTTP method check for GET, cleaner errors in job_endpoint_test * decomment * Actions aggregated at job model level (#18733) * Removal of temporary fix to proxy to 4646 * Run Action websocket endpoint (#18760) * Working demo for review purposes * removal of cors passthru for websockets * Remove job_endpoint-specific ws handlers and aimed at existing alloc exec handlers instead * PR comments adressed, no need for taskGroup pass, better group and task lookups from alloc * early return in action validate and removed jobid from req args per PR comments * todo removal, we're checking later in the rpc * boolean style change on tty * Action CLI command (#18778) * Action command init and stuck-notes * Conditional reqpath to aim at Job action endpoint * De-logged * General CLI command cleanup, observe namespace, pass action as string, get random alloc w group adherence * tab and varname cleanup * Remove action param from Allocations().Exec calls * changelog * dont nil-check acl --------- Co-authored-by: Tim Gross <tgross@hashicorp.com>
142 lines
3.4 KiB
Go
142 lines
3.4 KiB
Go
// Copyright (c) HashiCorp, Inc.
|
|
// SPDX-License-Identifier: BUSL-1.1
|
|
|
|
package agent
|
|
|
|
import (
|
|
"time"
|
|
|
|
"github.com/hashicorp/nomad/api"
|
|
"github.com/hashicorp/nomad/helper/pointer"
|
|
"github.com/hashicorp/nomad/helper/uuid"
|
|
)
|
|
|
|
func MockJob() *api.Job {
|
|
job := &api.Job{
|
|
Region: pointer.Of("global"),
|
|
ID: pointer.Of(uuid.Generate()),
|
|
Name: pointer.Of("my-job"),
|
|
Type: pointer.Of("service"),
|
|
Priority: pointer.Of(50),
|
|
AllAtOnce: pointer.Of(false),
|
|
Datacenters: []string{"dc1"},
|
|
Constraints: []*api.Constraint{
|
|
{
|
|
LTarget: "${attr.kernel.name}",
|
|
RTarget: "linux",
|
|
Operand: "=",
|
|
},
|
|
},
|
|
TaskGroups: []*api.TaskGroup{
|
|
{
|
|
Name: pointer.Of("web"),
|
|
Count: pointer.Of(10),
|
|
EphemeralDisk: &api.EphemeralDisk{
|
|
SizeMB: pointer.Of(150),
|
|
},
|
|
RestartPolicy: &api.RestartPolicy{
|
|
Attempts: pointer.Of(3),
|
|
Interval: pointer.Of(10 * time.Minute),
|
|
Delay: pointer.Of(1 * time.Minute),
|
|
Mode: pointer.Of("delay"),
|
|
RenderTemplates: pointer.Of(false),
|
|
},
|
|
Networks: []*api.NetworkResource{
|
|
{
|
|
Mode: "host",
|
|
DynamicPorts: []api.Port{{Label: "http"}, {Label: "admin"}},
|
|
},
|
|
},
|
|
Tasks: []*api.Task{
|
|
{
|
|
Name: "web",
|
|
Driver: "exec",
|
|
Config: map[string]interface{}{
|
|
"command": "/bin/date",
|
|
},
|
|
Env: map[string]string{
|
|
"FOO": "bar",
|
|
},
|
|
Services: []*api.Service{
|
|
{
|
|
Name: "${TASK}-frontend",
|
|
PortLabel: "http",
|
|
Tags: []string{"pci:${meta.pci-dss}", "datacenter:${node.datacenter}"},
|
|
Checks: []api.ServiceCheck{
|
|
{
|
|
Name: "check-table",
|
|
Type: "script",
|
|
Command: "/usr/local/check-table-${meta.database}",
|
|
Args: []string{"${meta.version}"},
|
|
Interval: 30 * time.Second,
|
|
Timeout: 5 * time.Second,
|
|
},
|
|
},
|
|
},
|
|
{
|
|
Name: "${TASK}-admin",
|
|
PortLabel: "admin",
|
|
},
|
|
},
|
|
// actions
|
|
Actions: []*api.Action{
|
|
{
|
|
Name: "date test",
|
|
Command: "/bin/date",
|
|
Args: []string{"-u"},
|
|
},
|
|
{
|
|
Name: "echo test",
|
|
Command: "/bin/echo",
|
|
Args: []string{"hello world"},
|
|
},
|
|
},
|
|
LogConfig: api.DefaultLogConfig(),
|
|
Resources: &api.Resources{
|
|
CPU: pointer.Of(500),
|
|
MemoryMB: pointer.Of(256),
|
|
},
|
|
Meta: map[string]string{
|
|
"foo": "bar",
|
|
},
|
|
},
|
|
},
|
|
Meta: map[string]string{
|
|
"elb_check_type": "http",
|
|
"elb_check_interval": "30s",
|
|
"elb_check_min": "3",
|
|
},
|
|
},
|
|
},
|
|
Meta: map[string]string{
|
|
"owner": "armon",
|
|
},
|
|
}
|
|
job.Canonicalize()
|
|
return job
|
|
}
|
|
|
|
func MockRegionalJob() *api.Job {
|
|
j := MockJob()
|
|
j.Region = pointer.Of("north-america")
|
|
return j
|
|
}
|
|
|
|
// MockRunnableJob returns a mock job that has a configuration that allows it to be
|
|
// placed on a TestAgent.
|
|
func MockRunnableJob() *api.Job {
|
|
job := MockJob()
|
|
|
|
// Configure job so it can be run on a TestAgent
|
|
job.Constraints = nil
|
|
job.TaskGroups[0].Constraints = nil
|
|
job.TaskGroups[0].Count = pointer.Of(1)
|
|
job.TaskGroups[0].Tasks[0].Driver = "mock_driver"
|
|
job.TaskGroups[0].Tasks[0].Services = nil
|
|
job.TaskGroups[0].Tasks[0].Config = map[string]interface{}{
|
|
"run_for": "10s",
|
|
}
|
|
|
|
return job
|
|
}
|