mirror of
https://github.com/kemko/nomad.git
synced 2026-01-06 10:25:42 +03:00
Rename structs
This commit is contained in:
@@ -59,15 +59,15 @@ func (s *HTTPServer) AllocSpecificRequest(resp http.ResponseWriter, req *http.Re
|
||||
return nil, CodedError(404, "alloc not found")
|
||||
}
|
||||
|
||||
// Decode the input data if there is any
|
||||
// Decode the payload if there is any
|
||||
alloc := out.Alloc
|
||||
if alloc.Job != nil && len(alloc.Job.InputData) != 0 {
|
||||
decoded, err := snappy.Decode(nil, alloc.Job.InputData)
|
||||
if alloc.Job != nil && len(alloc.Job.Payload) != 0 {
|
||||
decoded, err := snappy.Decode(nil, alloc.Job.Payload)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
alloc = alloc.Copy()
|
||||
alloc.Job.InputData = decoded
|
||||
alloc.Job.Payload = decoded
|
||||
}
|
||||
|
||||
return alloc, nil
|
||||
|
||||
@@ -163,7 +163,7 @@ func TestHTTP_AllocQuery(t *testing.T) {
|
||||
})
|
||||
}
|
||||
|
||||
func TestHTTP_AllocQuery_InputData(t *testing.T) {
|
||||
func TestHTTP_AllocQuery_Payload(t *testing.T) {
|
||||
httpTest(t, nil, func(s *TestServer) {
|
||||
// Directly manipulate the state
|
||||
state := s.Agent.server.State()
|
||||
@@ -172,10 +172,10 @@ func TestHTTP_AllocQuery_InputData(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
// Insert InputData compressed
|
||||
// Insert Payload compressed
|
||||
expected := []byte("hello world")
|
||||
compressed := snappy.Encode(nil, expected)
|
||||
alloc.Job.InputData = compressed
|
||||
alloc.Job.Payload = compressed
|
||||
|
||||
err := state.UpsertAllocs(1000, []*structs.Allocation{alloc})
|
||||
if err != nil {
|
||||
@@ -212,9 +212,9 @@ func TestHTTP_AllocQuery_InputData(t *testing.T) {
|
||||
t.Fatalf("bad: %#v", a)
|
||||
}
|
||||
|
||||
// Check the input data is decompressed
|
||||
if !reflect.DeepEqual(a.Job.InputData, expected) {
|
||||
t.Fatalf("InputData not decompressed properly; got %#v; want %#v", a.Job.InputData, expected)
|
||||
// Check the payload is decompressed
|
||||
if !reflect.DeepEqual(a.Job.Payload, expected) {
|
||||
t.Fatalf("Payload not decompressed properly; got %#v; want %#v", a.Job.Payload, expected)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
@@ -210,15 +210,15 @@ func (s *HTTPServer) jobQuery(resp http.ResponseWriter, req *http.Request,
|
||||
return nil, CodedError(404, "job not found")
|
||||
}
|
||||
|
||||
// Decode the input data if there is any
|
||||
// Decode the payload if there is any
|
||||
job := out.Job
|
||||
if len(job.InputData) != 0 {
|
||||
decoded, err := snappy.Decode(nil, out.Job.InputData)
|
||||
if len(job.Payload) != 0 {
|
||||
decoded, err := snappy.Decode(nil, out.Job.Payload)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
job = job.Copy()
|
||||
job.InputData = decoded
|
||||
job.Payload = decoded
|
||||
}
|
||||
|
||||
return job, nil
|
||||
|
||||
@@ -207,15 +207,15 @@ func TestHTTP_JobQuery(t *testing.T) {
|
||||
})
|
||||
}
|
||||
|
||||
func TestHTTP_JobQuery_InputData(t *testing.T) {
|
||||
func TestHTTP_JobQuery_Payload(t *testing.T) {
|
||||
httpTest(t, nil, func(s *TestServer) {
|
||||
// Create the job
|
||||
job := mock.Job()
|
||||
|
||||
// Insert InputData compressed
|
||||
// Insert Payload compressed
|
||||
expected := []byte("hello world")
|
||||
compressed := snappy.Encode(nil, expected)
|
||||
job.InputData = compressed
|
||||
job.Payload = compressed
|
||||
|
||||
args := structs.JobRegisterRequest{
|
||||
Job: job,
|
||||
@@ -256,9 +256,9 @@ func TestHTTP_JobQuery_InputData(t *testing.T) {
|
||||
t.Fatalf("bad: %#v", j)
|
||||
}
|
||||
|
||||
// Check the input data is decompressed
|
||||
if !reflect.DeepEqual(j.InputData, expected) {
|
||||
t.Fatalf("InputData not decompressed properly; got %#v; want %#v", j.InputData, expected)
|
||||
// Check the payload is decompressed
|
||||
if !reflect.DeepEqual(j.Payload, expected) {
|
||||
t.Fatalf("Payload not decompressed properly; got %#v; want %#v", j.Payload, expected)
|
||||
}
|
||||
})
|
||||
}
|
||||
@@ -582,9 +582,9 @@ func TestHTTP_JobPlan(t *testing.T) {
|
||||
|
||||
func TestHTTP_JobDispatch(t *testing.T) {
|
||||
httpTest(t, nil, func(s *TestServer) {
|
||||
// Create the dispatch template job
|
||||
// Create the constructor job
|
||||
job := mock.Job()
|
||||
job.Dispatch = &structs.DispatchConfig{}
|
||||
job.Constructor = &structs.ConstructorConfig{}
|
||||
|
||||
args := structs.JobRegisterRequest{
|
||||
Job: job,
|
||||
|
||||
@@ -75,16 +75,16 @@ func (c *JobDispatchCommand) Run(args []string) int {
|
||||
}
|
||||
|
||||
templateJob := args[0]
|
||||
var inputData []byte
|
||||
var payload []byte
|
||||
var readErr error
|
||||
|
||||
// Read the input
|
||||
if len(args) == 2 {
|
||||
switch args[1] {
|
||||
case "-":
|
||||
inputData, readErr = ioutil.ReadAll(os.Stdin)
|
||||
payload, readErr = ioutil.ReadAll(os.Stdin)
|
||||
default:
|
||||
inputData, readErr = ioutil.ReadFile(args[1])
|
||||
payload, readErr = ioutil.ReadFile(args[1])
|
||||
}
|
||||
if readErr != nil {
|
||||
c.Ui.Error(fmt.Sprintf("Error reading input data: %v", readErr))
|
||||
@@ -112,7 +112,7 @@ func (c *JobDispatchCommand) Run(args []string) int {
|
||||
}
|
||||
|
||||
// Dispatch the job
|
||||
resp, _, err := client.Jobs().Dispatch(templateJob, metaMap, inputData, nil)
|
||||
resp, _, err := client.Jobs().Dispatch(templateJob, metaMap, payload, nil)
|
||||
if err != nil {
|
||||
c.Ui.Error(fmt.Sprintf("Failed to dispatch job: %s", err))
|
||||
return 1
|
||||
|
||||
@@ -147,9 +147,9 @@ func (c *RunCommand) Run(args []string) int {
|
||||
return 1
|
||||
}
|
||||
|
||||
// Check if the job is periodic or is a dispatch template
|
||||
// Check if the job is periodic or is a constructor job
|
||||
periodic := job.IsPeriodic()
|
||||
template := job.IsDispatchTemplate()
|
||||
constructor := job.IsConstructor()
|
||||
|
||||
// Parse the Vault token
|
||||
if vaultToken == "" {
|
||||
@@ -240,14 +240,14 @@ func (c *RunCommand) Run(args []string) int {
|
||||
}
|
||||
|
||||
// Check if we should enter monitor mode
|
||||
if detach || periodic || template {
|
||||
if detach || periodic || constructor {
|
||||
c.Ui.Output("Job registration successful")
|
||||
if periodic {
|
||||
now := time.Now().UTC()
|
||||
next := job.Periodic.Next(now)
|
||||
c.Ui.Output(fmt.Sprintf("Approximate next launch time: %s (%s from now)",
|
||||
formatTime(next), formatTimeDifference(now, next, time.Second)))
|
||||
} else if !template {
|
||||
} else if !constructor {
|
||||
c.Ui.Output("Evaluation ID: " + evalID)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user