Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
小 白蛋
Nomad
Commits
920e0d7f
Commit
920e0d7f
authored
7 years ago
by
Alex Dadgar
Browse files
Options
Download
Email Patches
Plain Diff
logs and fs
parent
3ae8ecb3
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
command/fs.go
+22
-0
command/fs.go
command/fs_test.go
+34
-0
command/fs_test.go
command/logs.go
+22
-0
command/logs.go
command/logs_test.go
+34
-0
command/logs_test.go
with
112 additions
and
0 deletions
+112
-0
command/fs.go
+
22
-
0
View file @
920e0d7f
...
...
@@ -12,6 +12,8 @@ import (
humanize
"github.com/dustin/go-humanize"
"github.com/hashicorp/nomad/api"
"github.com/hashicorp/nomad/api/contexts"
"github.com/posener/complete"
)
const
(
...
...
@@ -77,6 +79,26 @@ func (f *FSCommand) Synopsis() string {
return
"Inspect the contents of an allocation directory"
}
func
(
f
*
FSCommand
)
AutocompleteFlags
()
complete
.
Flags
{
return
nil
}
func
(
f
*
FSCommand
)
AutocompleteArgs
()
complete
.
Predictor
{
client
,
_
:=
f
.
Meta
.
Client
()
return
complete
.
PredictFunc
(
func
(
a
complete
.
Args
)
[]
string
{
if
len
(
a
.
Completed
)
>
1
{
return
nil
}
resp
,
err
:=
client
.
Search
()
.
PrefixSearch
(
a
.
Last
,
contexts
.
Allocs
)
if
err
!=
nil
{
return
[]
string
{}
}
return
resp
.
Matches
[
contexts
.
Allocs
]
})
}
func
(
f
*
FSCommand
)
Run
(
args
[]
string
)
int
{
var
verbose
,
machine
,
job
,
stat
,
tail
,
follow
bool
var
numLines
,
numBytes
int64
...
...
This diff is collapsed.
Click to expand it.
command/fs_test.go
+
34
-
0
View file @
920e0d7f
...
...
@@ -4,7 +4,11 @@ import (
"strings"
"testing"
"github.com/hashicorp/nomad/nomad/mock"
"github.com/hashicorp/nomad/nomad/structs"
"github.com/mitchellh/cli"
"github.com/posener/complete"
"github.com/stretchr/testify/assert"
)
func
TestFSCommand_Implements
(
t
*
testing
.
T
)
{
...
...
@@ -81,5 +85,35 @@ func TestFSCommand_Fails(t *testing.T) {
if
out
:=
ui
.
ErrorWriter
.
String
();
!
strings
.
Contains
(
out
,
"No allocation(s) with prefix or id"
)
{
t
.
Fatalf
(
"expected not found error, got: %s"
,
out
)
}
}
func
TestFSCommand_AutocompleteArgs
(
t
*
testing
.
T
)
{
assert
:=
assert
.
New
(
t
)
t
.
Parallel
()
srv
,
_
,
url
:=
testServer
(
t
,
true
,
nil
)
defer
srv
.
Shutdown
()
ui
:=
new
(
cli
.
MockUi
)
cmd
:=
&
FSCommand
{
Meta
:
Meta
{
Ui
:
ui
,
flagAddress
:
url
}}
// Create a fake alloc
state
:=
srv
.
Agent
.
Server
()
.
State
()
a
:=
mock
.
Alloc
()
assert
.
Nil
(
state
.
UpsertAllocs
(
1000
,
[]
*
structs
.
Allocation
{
a
}))
prefix
:=
a
.
ID
[
:
5
]
args
:=
complete
.
Args
{
Last
:
prefix
}
predictor
:=
cmd
.
AutocompleteArgs
()
res
:=
predictor
.
Predict
(
args
)
assert
.
Equal
(
1
,
len
(
res
))
assert
.
Equal
(
a
.
ID
,
res
[
0
])
// Autocomplete should only complete once
args
=
complete
.
Args
{
Last
:
prefix
,
Completed
:
[]
string
{
prefix
,
"1"
,
"2"
}}
predictor
=
cmd
.
AutocompleteArgs
()
res
=
predictor
.
Predict
(
args
)
assert
.
Nil
(
res
)
}
This diff is collapsed.
Click to expand it.
command/logs.go
+
22
-
0
View file @
920e0d7f
...
...
@@ -10,6 +10,8 @@ import (
"time"
"github.com/hashicorp/nomad/api"
"github.com/hashicorp/nomad/api/contexts"
"github.com/posener/complete"
)
type
LogsCommand
struct
{
...
...
@@ -59,6 +61,26 @@ func (l *LogsCommand) Synopsis() string {
return
"Streams the logs of a task."
}
func
(
l
*
LogsCommand
)
AutocompleteFlags
()
complete
.
Flags
{
return
nil
}
func
(
l
*
LogsCommand
)
AutocompleteArgs
()
complete
.
Predictor
{
client
,
_
:=
l
.
Meta
.
Client
()
return
complete
.
PredictFunc
(
func
(
a
complete
.
Args
)
[]
string
{
if
len
(
a
.
Completed
)
>
1
{
return
nil
}
resp
,
err
:=
client
.
Search
()
.
PrefixSearch
(
a
.
Last
,
contexts
.
Allocs
)
if
err
!=
nil
{
return
[]
string
{}
}
return
resp
.
Matches
[
contexts
.
Allocs
]
})
}
func
(
l
*
LogsCommand
)
Run
(
args
[]
string
)
int
{
var
verbose
,
job
,
tail
,
stderr
,
follow
bool
var
numLines
,
numBytes
int64
...
...
This diff is collapsed.
Click to expand it.
command/logs_test.go
+
34
-
0
View file @
920e0d7f
...
...
@@ -4,7 +4,11 @@ import (
"strings"
"testing"
"github.com/hashicorp/nomad/nomad/mock"
"github.com/hashicorp/nomad/nomad/structs"
"github.com/mitchellh/cli"
"github.com/posener/complete"
"github.com/stretchr/testify/assert"
)
func
TestLogsCommand_Implements
(
t
*
testing
.
T
)
{
...
...
@@ -63,5 +67,35 @@ func TestLogsCommand_Fails(t *testing.T) {
if
out
:=
ui
.
ErrorWriter
.
String
();
!
strings
.
Contains
(
out
,
"No allocation(s) with prefix or id"
)
{
t
.
Fatalf
(
"expected not found error, got: %s"
,
out
)
}
}
func
TestLogsCommand_AutocompleteArgs
(
t
*
testing
.
T
)
{
assert
:=
assert
.
New
(
t
)
t
.
Parallel
()
srv
,
_
,
url
:=
testServer
(
t
,
true
,
nil
)
defer
srv
.
Shutdown
()
ui
:=
new
(
cli
.
MockUi
)
cmd
:=
&
LogsCommand
{
Meta
:
Meta
{
Ui
:
ui
,
flagAddress
:
url
}}
// Create a fake alloc
state
:=
srv
.
Agent
.
Server
()
.
State
()
a
:=
mock
.
Alloc
()
assert
.
Nil
(
state
.
UpsertAllocs
(
1000
,
[]
*
structs
.
Allocation
{
a
}))
prefix
:=
a
.
ID
[
:
5
]
args
:=
complete
.
Args
{
Last
:
prefix
}
predictor
:=
cmd
.
AutocompleteArgs
()
res
:=
predictor
.
Predict
(
args
)
assert
.
Equal
(
1
,
len
(
res
))
assert
.
Equal
(
a
.
ID
,
res
[
0
])
// Autocomplete should only complete once
args
=
complete
.
Args
{
Last
:
prefix
,
Completed
:
[]
string
{
prefix
,
"1"
,
"2"
}}
predictor
=
cmd
.
AutocompleteArgs
()
res
=
predictor
.
Predict
(
args
)
assert
.
Nil
(
res
)
}
This diff is collapsed.
Click to expand it.
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment