mirror of
https://github.com/kemko/nomad.git
synced 2026-01-04 09:25:46 +03:00
Merge branch 'master' into f-update-block
This commit is contained in:
@@ -10,6 +10,7 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/boltdb/bolt"
|
||||
consulapi "github.com/hashicorp/consul/api"
|
||||
"github.com/hashicorp/consul/testutil"
|
||||
"github.com/hashicorp/nomad/client"
|
||||
@@ -44,13 +45,16 @@ func TestConsul_Integration(t *testing.T) {
|
||||
}
|
||||
}
|
||||
// Create an embedded Consul server
|
||||
testconsul := testutil.NewTestServerConfig(t, func(c *testutil.TestServerConfig) {
|
||||
testconsul, err := testutil.NewTestServerConfig(func(c *testutil.TestServerConfig) {
|
||||
// If -v wasn't specified squelch consul logging
|
||||
if !testing.Verbose() {
|
||||
c.Stdout = ioutil.Discard
|
||||
c.Stderr = ioutil.Discard
|
||||
}
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("error starting test consul server: %v", err)
|
||||
}
|
||||
defer testconsul.Stop()
|
||||
|
||||
conf := config.DefaultConfig()
|
||||
@@ -72,6 +76,15 @@ func TestConsul_Integration(t *testing.T) {
|
||||
}
|
||||
defer os.RemoveAll(conf.AllocDir)
|
||||
|
||||
tmp, err := ioutil.TempFile("", "state-db")
|
||||
if err != nil {
|
||||
t.Fatalf("error creating state db file: %v", err)
|
||||
}
|
||||
db, err := bolt.Open(tmp.Name(), 0600, nil)
|
||||
if err != nil {
|
||||
t.Fatalf("error creating state db: %v", err)
|
||||
}
|
||||
|
||||
alloc := mock.Alloc()
|
||||
task := alloc.Job.TaskGroups[0].Tasks[0]
|
||||
task.Driver = "mock_driver"
|
||||
@@ -132,7 +145,7 @@ func TestConsul_Integration(t *testing.T) {
|
||||
serviceClient.Run()
|
||||
close(consulRan)
|
||||
}()
|
||||
tr := client.NewTaskRunner(logger, conf, logUpdate, taskDir, alloc, task, vclient, serviceClient)
|
||||
tr := client.NewTaskRunner(logger, conf, db, logUpdate, taskDir, alloc, task, vclient, serviceClient)
|
||||
tr.MarkReceived()
|
||||
go tr.Run()
|
||||
defer func() {
|
||||
|
||||
@@ -21,6 +21,7 @@ import (
|
||||
|
||||
"github.com/docker/docker/pkg/ioutils"
|
||||
"github.com/hashicorp/nomad/client/allocdir"
|
||||
"github.com/hashicorp/nomad/nomad/structs"
|
||||
"github.com/hpcloud/tail/watch"
|
||||
"github.com/ugorji/go/codec"
|
||||
)
|
||||
@@ -290,7 +291,7 @@ func NewStreamFramer(out io.WriteCloser, plainTxt bool,
|
||||
heartbeatRate, batchWindow time.Duration, frameSize int) *StreamFramer {
|
||||
|
||||
// Create a JSON encoder
|
||||
enc := codec.NewEncoder(out, jsonHandle)
|
||||
enc := codec.NewEncoder(out, structs.JsonHandle)
|
||||
|
||||
// Create the heartbeat and flush ticker
|
||||
heartbeat := time.NewTicker(heartbeatRate)
|
||||
@@ -636,7 +637,7 @@ OUTER:
|
||||
}
|
||||
|
||||
// Send the frame
|
||||
if n != 0 {
|
||||
if n != 0 || lastEvent != "" {
|
||||
if err := framer.Send(path, lastEvent, data[:n], offset); err != nil {
|
||||
return parseFramerErr(err)
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/hashicorp/nomad/client/allocdir"
|
||||
"github.com/hashicorp/nomad/nomad/structs"
|
||||
"github.com/hashicorp/nomad/testutil"
|
||||
"github.com/ugorji/go/codec"
|
||||
)
|
||||
@@ -123,7 +124,7 @@ func TestStreamFramer_Flush(t *testing.T) {
|
||||
sf.Run()
|
||||
|
||||
// Create a decoder
|
||||
dec := codec.NewDecoder(r, jsonHandle)
|
||||
dec := codec.NewDecoder(r, structs.JsonHandle)
|
||||
|
||||
f := "foo"
|
||||
fe := "bar"
|
||||
@@ -191,7 +192,7 @@ func TestStreamFramer_Batch(t *testing.T) {
|
||||
sf.Run()
|
||||
|
||||
// Create a decoder
|
||||
dec := codec.NewDecoder(r, jsonHandle)
|
||||
dec := codec.NewDecoder(r, structs.JsonHandle)
|
||||
|
||||
f := "foo"
|
||||
fe := "bar"
|
||||
@@ -268,7 +269,7 @@ func TestStreamFramer_Heartbeat(t *testing.T) {
|
||||
sf.Run()
|
||||
|
||||
// Create a decoder
|
||||
dec := codec.NewDecoder(r, jsonHandle)
|
||||
dec := codec.NewDecoder(r, structs.JsonHandle)
|
||||
|
||||
// Start the reader
|
||||
resultCh := make(chan struct{})
|
||||
@@ -320,7 +321,7 @@ func TestStreamFramer_Order(t *testing.T) {
|
||||
sf.Run()
|
||||
|
||||
// Create a decoder
|
||||
dec := codec.NewDecoder(r, jsonHandle)
|
||||
dec := codec.NewDecoder(r, structs.JsonHandle)
|
||||
|
||||
files := []string{"1", "2", "3", "4", "5"}
|
||||
input := bytes.NewBuffer(make([]byte, 0, 100000))
|
||||
@@ -592,7 +593,7 @@ func TestHTTP_Stream_Modify(t *testing.T) {
|
||||
r, w := io.Pipe()
|
||||
defer r.Close()
|
||||
defer w.Close()
|
||||
dec := codec.NewDecoder(r, jsonHandle)
|
||||
dec := codec.NewDecoder(r, structs.JsonHandle)
|
||||
|
||||
data := []byte("helloworld")
|
||||
|
||||
@@ -668,7 +669,7 @@ func TestHTTP_Stream_Truncate(t *testing.T) {
|
||||
r, w := io.Pipe()
|
||||
defer r.Close()
|
||||
defer w.Close()
|
||||
dec := codec.NewDecoder(r, jsonHandle)
|
||||
dec := codec.NewDecoder(r, structs.JsonHandle)
|
||||
|
||||
data := []byte("helloworld")
|
||||
|
||||
@@ -778,7 +779,7 @@ func TestHTTP_Stream_Delete(t *testing.T) {
|
||||
wrappedW := &WriteCloseChecker{WriteCloser: w}
|
||||
defer r.Close()
|
||||
defer w.Close()
|
||||
dec := codec.NewDecoder(r, jsonHandle)
|
||||
dec := codec.NewDecoder(r, structs.JsonHandle)
|
||||
|
||||
data := []byte("helloworld")
|
||||
|
||||
@@ -869,7 +870,7 @@ func TestHTTP_Logs_NoFollow(t *testing.T) {
|
||||
wrappedW := &WriteCloseChecker{WriteCloser: w}
|
||||
defer r.Close()
|
||||
defer w.Close()
|
||||
dec := codec.NewDecoder(r, jsonHandle)
|
||||
dec := codec.NewDecoder(r, structs.JsonHandle)
|
||||
|
||||
var received []byte
|
||||
|
||||
@@ -955,7 +956,7 @@ func TestHTTP_Logs_Follow(t *testing.T) {
|
||||
wrappedW := &WriteCloseChecker{WriteCloser: w}
|
||||
defer r.Close()
|
||||
defer w.Close()
|
||||
dec := codec.NewDecoder(r, jsonHandle)
|
||||
dec := codec.NewDecoder(r, structs.JsonHandle)
|
||||
|
||||
var received []byte
|
||||
|
||||
@@ -1071,7 +1072,7 @@ func BenchmarkHTTP_Logs_Follow(t *testing.B) {
|
||||
wrappedW := &WriteCloseChecker{WriteCloser: w}
|
||||
defer r.Close()
|
||||
defer w.Close()
|
||||
dec := codec.NewDecoder(r, jsonHandle)
|
||||
dec := codec.NewDecoder(r, structs.JsonHandle)
|
||||
|
||||
var received []byte
|
||||
|
||||
|
||||
@@ -29,18 +29,6 @@ const (
|
||||
scadaHTTPAddr = "SCADA"
|
||||
)
|
||||
|
||||
var (
|
||||
// jsonHandle and jsonHandlePretty are the codec handles to JSON encode
|
||||
// structs. The pretty handle will add indents for easier human consumption.
|
||||
jsonHandle = &codec.JsonHandle{
|
||||
HTMLCharsAsIs: true,
|
||||
}
|
||||
jsonHandlePretty = &codec.JsonHandle{
|
||||
HTMLCharsAsIs: true,
|
||||
Indent: 4,
|
||||
}
|
||||
)
|
||||
|
||||
// HTTPServer is used to wrap an Agent and expose it over an HTTP interface
|
||||
type HTTPServer struct {
|
||||
agent *Agent
|
||||
@@ -186,6 +174,7 @@ func (s *HTTPServer) registerHandlers(enableDebug bool) {
|
||||
s.mux.HandleFunc("/debug/pprof/cmdline", pprof.Cmdline)
|
||||
s.mux.HandleFunc("/debug/pprof/profile", pprof.Profile)
|
||||
s.mux.HandleFunc("/debug/pprof/symbol", pprof.Symbol)
|
||||
s.mux.HandleFunc("/debug/pprof/trace", pprof.Trace)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -248,13 +237,13 @@ func (s *HTTPServer) wrap(handler func(resp http.ResponseWriter, req *http.Reque
|
||||
if obj != nil {
|
||||
var buf bytes.Buffer
|
||||
if prettyPrint {
|
||||
enc := codec.NewEncoder(&buf, jsonHandlePretty)
|
||||
enc := codec.NewEncoder(&buf, structs.JsonHandlePretty)
|
||||
err = enc.Encode(obj)
|
||||
if err == nil {
|
||||
buf.Write([]byte("\n"))
|
||||
}
|
||||
} else {
|
||||
enc := codec.NewEncoder(&buf, jsonHandle)
|
||||
enc := codec.NewEncoder(&buf, structs.JsonHandle)
|
||||
err = enc.Encode(obj)
|
||||
}
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user