Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
小 白蛋
Nomad
Commits
a6d008a7
Commit
a6d008a7
authored
9 years ago
by
Diptanu Choudhury
Browse files
Options
Download
Email Patches
Plain Diff
Added the fake driver
parent
a52dee75
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
client/driver/driver.go
+1
-0
client/driver/driver.go
client/driver/fake.go
+117
-0
client/driver/fake.go
with
118 additions
and
0 deletions
+118
-0
client/driver/driver.go
+
1
-
0
View file @
a6d008a7
...
...
@@ -25,6 +25,7 @@ var BuiltinDrivers = map[string]Factory{
"java"
:
NewJavaDriver
,
"qemu"
:
NewQemuDriver
,
"rkt"
:
NewRktDriver
,
"fake"
:
NewFakeDriver
,
}
// NewDriver is used to instantiate and return a new driver
...
...
This diff is collapsed.
Click to expand it.
client/driver/fake.go
0 → 100644
+
117
-
0
View file @
a6d008a7
package
driver
import
(
"encoding/json"
"fmt"
"log"
"github.com/hashicorp/nomad/client/config"
dstructs
"github.com/hashicorp/nomad/client/driver/structs"
"github.com/hashicorp/nomad/client/fingerprint"
cstructs
"github.com/hashicorp/nomad/client/structs"
"github.com/hashicorp/nomad/helper/fields"
"github.com/hashicorp/nomad/nomad/structs"
"github.com/mitchellh/mapstructure"
)
type
FakeDriver
struct
{
DriverContext
fingerprint
.
StaticFingerprinter
}
type
FakeDriverConfig
struct
{
Success
float64
`mapstructure:"success"`
Failure
float64
`mapstructure:"failure"`
Crash
float64
`mapstructure:"failure"`
}
type
fakeDriverHandle
struct
{
logger
*
log
.
Logger
waitCh
chan
*
dstructs
.
WaitResult
doneCh
chan
struct
{}
}
func
NewFakeDriver
(
ctx
*
DriverContext
)
Driver
{
return
&
FakeDriver
{
DriverContext
:
*
ctx
}
}
func
(
d
*
FakeDriver
)
Fingerprint
(
cfg
*
config
.
Config
,
node
*
structs
.
Node
)
(
bool
,
error
)
{
return
false
,
nil
}
func
(
d
*
FakeDriver
)
Validate
(
config
map
[
string
]
interface
{})
error
{
fd
:=
&
fields
.
FieldData
{
Raw
:
config
,
Schema
:
map
[
string
]
*
fields
.
FieldSchema
{
"success"
:
&
fields
.
FieldSchema
{
Type
:
fields
.
TypeFloat
,
Required
:
true
,
},
"failure"
:
&
fields
.
FieldSchema
{
Type
:
fields
.
TypeFloat
,
},
"crash"
:
&
fields
.
FieldSchema
{
Type
:
fields
.
TypeFloat
,
},
},
}
if
err
:=
fd
.
Validate
();
err
!=
nil
{
return
err
}
return
nil
}
func
(
d
*
FakeDriver
)
Start
(
ctx
*
ExecContext
,
task
*
structs
.
Task
)
(
DriverHandle
,
error
)
{
var
driverConfig
FakeDriverConfig
if
err
:=
mapstructure
.
WeakDecode
(
task
.
Config
,
&
driverConfig
);
err
!=
nil
{
return
nil
,
err
}
total
:=
driverConfig
.
Success
+
driverConfig
.
Crash
+
driverConfig
.
Failure
if
total
!=
100
{
return
nil
,
fmt
.
Errorf
(
"sum of success, crash and failure has to be 1, got: %v"
,
total
)
}
h
:=
&
fakeDriverHandle
{
logger
:
d
.
logger
,
doneCh
:
make
(
chan
struct
{}),
waitCh
:
make
(
chan
*
dstructs
.
WaitResult
,
1
),
}
return
h
,
nil
}
func
(
d
*
FakeDriver
)
Open
(
ctx
*
ExecContext
,
handleID
string
)
(
DriverHandle
,
error
)
{
id
:=
&
fakeDriverHandle
{}
if
err
:=
json
.
Unmarshal
([]
byte
(
handleID
),
id
);
err
!=
nil
{
return
nil
,
fmt
.
Errorf
(
"Failed to parse handle %q: %v"
,
handleID
,
err
)
}
return
nil
,
nil
}
func
(
h
*
fakeDriverHandle
)
ID
()
string
{
id
:=
fakeDriverHandle
{}
data
,
err
:=
json
.
Marshal
(
id
)
if
err
!=
nil
{
h
.
logger
.
Printf
(
"[ERR] driver.fake: failed to marshal ID to JSON: %s"
,
err
)
}
return
string
(
data
)
}
func
(
h
*
fakeDriverHandle
)
Kill
()
error
{
return
nil
}
func
(
h
*
fakeDriverHandle
)
Stats
()
(
*
cstructs
.
TaskResourceUsage
,
error
)
{
return
nil
,
nil
}
func
(
h
*
fakeDriverHandle
)
Update
(
task
*
structs
.
Task
)
error
{
return
nil
}
func
(
h
*
fakeDriverHandle
)
WaitCh
()
chan
*
dstructs
.
WaitResult
{
return
h
.
waitCh
}
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
Menu
Projects
Groups
Snippets
Help