mirror of
https://github.com/kemko/nomad.git
synced 2026-01-05 18:05:42 +03:00
Bring up-to-date with master
This commit is contained in:
@@ -193,6 +193,23 @@ func (c *Command) readConfig() *Config {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Verify the paths are absolute.
|
||||
dirs := map[string]string{
|
||||
"data-dir": config.DataDir,
|
||||
"alloc-dir": config.Client.AllocDir,
|
||||
"state-dir": config.Client.StateDir,
|
||||
}
|
||||
for k, dir := range dirs {
|
||||
if dir == "" {
|
||||
continue
|
||||
}
|
||||
|
||||
if !filepath.IsAbs(dir) {
|
||||
c.Ui.Error(fmt.Sprintf("%s must be given as an absolute path: got %v", k, dir))
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
// Ensure that we have the directories we neet to run.
|
||||
if config.Server.Enabled && config.DataDir == "" {
|
||||
c.Ui.Error("Must specify data directory")
|
||||
|
||||
@@ -5,6 +5,7 @@ import (
|
||||
"encoding/gob"
|
||||
"fmt"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/hashicorp/nomad/api"
|
||||
"github.com/hashicorp/nomad/jobspec"
|
||||
@@ -89,8 +90,11 @@ func (c *RunCommand) Run(args []string) int {
|
||||
return 1
|
||||
}
|
||||
|
||||
// Check if the job is periodic.
|
||||
periodic := job.IsPeriodic()
|
||||
|
||||
// Convert it to something we can use
|
||||
apiJob, err := convertJob(job)
|
||||
apiJob, err := convertStructJob(job)
|
||||
if err != nil {
|
||||
c.Ui.Error(fmt.Sprintf("Error converting job: %s", err))
|
||||
return 1
|
||||
@@ -111,9 +115,14 @@ func (c *RunCommand) Run(args []string) int {
|
||||
}
|
||||
|
||||
// Check if we should enter monitor mode
|
||||
if detach {
|
||||
if detach || periodic {
|
||||
c.Ui.Output("Job registration successful")
|
||||
c.Ui.Output("Evaluation ID: " + evalID)
|
||||
if periodic {
|
||||
c.Ui.Output(fmt.Sprintf("Approximate next launch time: %v", job.Periodic.Next(time.Now())))
|
||||
} else {
|
||||
c.Ui.Output("Evaluation ID: " + evalID)
|
||||
}
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
@@ -123,9 +132,9 @@ func (c *RunCommand) Run(args []string) int {
|
||||
|
||||
}
|
||||
|
||||
// convertJob is used to take a *structs.Job and convert it to an *api.Job.
|
||||
// convertStructJob is used to take a *structs.Job and convert it to an *api.Job.
|
||||
// This function is just a hammer and probably needs to be revisited.
|
||||
func convertJob(in *structs.Job) (*api.Job, error) {
|
||||
func convertStructJob(in *structs.Job) (*api.Job, error) {
|
||||
gob.Register([]map[string]interface{}{})
|
||||
gob.Register([]interface{}{})
|
||||
var apiJob *api.Job
|
||||
|
||||
@@ -1,8 +1,14 @@
|
||||
package command
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/gob"
|
||||
"fmt"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/hashicorp/nomad/api"
|
||||
"github.com/hashicorp/nomad/nomad/structs"
|
||||
)
|
||||
|
||||
type StatusCommand struct {
|
||||
@@ -118,6 +124,14 @@ func (c *StatusCommand) Run(args []string) int {
|
||||
}
|
||||
}
|
||||
|
||||
// Check if it is periodic
|
||||
sJob, err := convertApiJob(job)
|
||||
if err != nil {
|
||||
c.Ui.Error(fmt.Sprintf("Error converting job: %s", err))
|
||||
return 1
|
||||
}
|
||||
periodic := sJob.IsPeriodic()
|
||||
|
||||
// Format the job info
|
||||
basic := []string{
|
||||
fmt.Sprintf("ID|%s", job.ID),
|
||||
@@ -126,10 +140,19 @@ func (c *StatusCommand) Run(args []string) int {
|
||||
fmt.Sprintf("Priority|%d", job.Priority),
|
||||
fmt.Sprintf("Datacenters|%s", strings.Join(job.Datacenters, ",")),
|
||||
fmt.Sprintf("Status|%s", job.Status),
|
||||
fmt.Sprintf("Periodic|%v", periodic),
|
||||
}
|
||||
|
||||
var evals, allocs []string
|
||||
if !short {
|
||||
if periodic {
|
||||
basic = append(basic, fmt.Sprintf("Next Periodic Launch|%v",
|
||||
sJob.Periodic.Next(time.Now())))
|
||||
}
|
||||
|
||||
c.Ui.Output(formatKV(basic))
|
||||
|
||||
if !periodic && !short {
|
||||
var evals, allocs []string
|
||||
|
||||
// Query the evaluations
|
||||
jobEvals, _, err := client.Jobs().Evaluations(job.ID, nil)
|
||||
if err != nil {
|
||||
@@ -167,15 +190,28 @@ func (c *StatusCommand) Run(args []string) int {
|
||||
alloc.DesiredStatus,
|
||||
alloc.ClientStatus)
|
||||
}
|
||||
}
|
||||
|
||||
// Dump the output
|
||||
c.Ui.Output(formatKV(basic))
|
||||
if !short {
|
||||
c.Ui.Output("\n==> Evaluations")
|
||||
c.Ui.Output(formatList(evals))
|
||||
c.Ui.Output("\n==> Allocations")
|
||||
c.Ui.Output(formatList(allocs))
|
||||
}
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
// convertApiJob is used to take a *api.Job and convert it to an *struct.Job.
|
||||
// This function is just a hammer and probably needs to be revisited.
|
||||
func convertApiJob(in *api.Job) (*structs.Job, error) {
|
||||
gob.Register(map[string]interface{}{})
|
||||
gob.Register([]interface{}{})
|
||||
var structJob *structs.Job
|
||||
buf := new(bytes.Buffer)
|
||||
if err := gob.NewEncoder(buf).Encode(in); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := gob.NewDecoder(buf).Decode(&structJob); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return structJob, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user