Skip to content

Commit 9489f45

Browse files
committed
update driver docs
1 parent 465dbd6 commit 9489f45

File tree

8 files changed

+100
-98
lines changed

8 files changed

+100
-98
lines changed

client/driver/exec.go

Lines changed: 38 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,16 @@ package driver
22

33
import (
44
"fmt"
5-
"log"
6-
"os/exec"
7-
"path"
8-
"path/filepath"
5+
"log"
6+
"os/exec"
7+
"path"
8+
"path/filepath"
99
"runtime"
1010
"syscall"
1111
"time"
1212

13-
"github.com/hashicorp/go-getter"
14-
"github.com/hashicorp/nomad/client/allocdir"
13+
"github.com/hashicorp/go-getter"
14+
"github.com/hashicorp/nomad/client/allocdir"
1515
"github.com/hashicorp/nomad/client/config"
1616
"github.com/hashicorp/nomad/client/executor"
1717
"github.com/hashicorp/nomad/nomad/structs"
@@ -47,40 +47,40 @@ func (d *ExecDriver) Fingerprint(cfg *config.Config, node *structs.Node) (bool,
4747
}
4848

4949
func (d *ExecDriver) Start(ctx *ExecContext, task *structs.Task) (DriverHandle, error) {
50-
// Get the command to be ran, or if omitted, download an artifact for
51-
// execution. Currently a supplied command takes precedence, and an artifact
52-
// is only downloaded if no command is supplied
50+
// Get the command to be ran, or if omitted, download an artifact for
51+
// execution. Currently a supplied command takes precedence, and an artifact
52+
// is only downloaded if no command is supplied
5353
command, ok := task.Config["command"]
5454
if !ok || command == "" {
55-
source, sok := task.Config["artifact_source"]
56-
if !sok || source == "" {
57-
return nil, fmt.Errorf("missing command or source for exec driver")
58-
}
59-
60-
// Proceed to download an artifact to be executed.
61-
// We use go-getter to support a variety of protocols, but need to change
62-
// file permissions of the resulted download to be executable
63-
taskDir, ok := ctx.AllocDir.TaskDirs[d.DriverContext.taskName]
64-
if !ok {
65-
return nil, fmt.Errorf("[Err] driver.Exec: Could not find task directory for task: %v", d.DriverContext.taskName)
66-
}
67-
68-
destDir := filepath.Join(taskDir, allocdir.TaskLocal)
69-
70-
// Create a location to download the artifact.
71-
artifactName := path.Base(source)
72-
command = filepath.Join(destDir, artifactName)
73-
if err := getter.GetFile(command, source); err != nil {
74-
return nil, fmt.Errorf("[Err] driver.Exec: Error downloading source for Exec driver: %s", err)
75-
}
76-
77-
cmd := exec.Command("chmod", "+x", command)
78-
if err := cmd.Run(); err != nil {
79-
log.Printf("[Err] driver.Exec: Error making artifact executable: %s", err)
80-
}
81-
82-
// re-assign the command to be the local execution path
83-
command = filepath.Join(allocdir.TaskLocal, artifactName)
55+
source, sok := task.Config["artifact_source"]
56+
if !sok || source == "" {
57+
return nil, fmt.Errorf("missing command or source for exec driver")
58+
}
59+
60+
// Proceed to download an artifact to be executed.
61+
// We use go-getter to support a variety of protocols, but need to change
62+
// file permissions of the resulted download to be executable
63+
taskDir, ok := ctx.AllocDir.TaskDirs[d.DriverContext.taskName]
64+
if !ok {
65+
return nil, fmt.Errorf("[Err] driver.Exec: Could not find task directory for task: %v", d.DriverContext.taskName)
66+
}
67+
68+
destDir := filepath.Join(taskDir, allocdir.TaskLocal)
69+
70+
// Create a location to download the artifact.
71+
artifactName := path.Base(source)
72+
command = filepath.Join(destDir, artifactName)
73+
if err := getter.GetFile(command, source); err != nil {
74+
return nil, fmt.Errorf("[Err] driver.Exec: Error downloading source for Exec driver: %s", err)
75+
}
76+
77+
cmd := exec.Command("chmod", "+x", command)
78+
if err := cmd.Run(); err != nil {
79+
log.Printf("[Err] driver.Exec: Error making artifact executable: %s", err)
80+
}
81+
82+
// re-assign the command to be the local execution path
83+
command = filepath.Join(allocdir.TaskLocal, artifactName)
8484
}
8585

8686
// Get the environment variables.

client/driver/exec_test.go

Lines changed: 37 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -121,43 +121,43 @@ func TestExecDriver_Start_Wait(t *testing.T) {
121121
}
122122

123123
func TestExecDriver_Start_Artifact_Wait(t *testing.T) {
124-
ctestutils.ExecCompatible(t)
125-
task := &structs.Task{
126-
Name: "sleep",
127-
Config: map[string]string{
128-
"artifact_source": "https://dl.dropboxusercontent.com/u/47675/jar_thing/hi_linux_amd64",
129-
},
130-
Resources: basicResources,
131-
}
132-
133-
driverCtx := testDriverContext(task.Name)
134-
ctx := testDriverExecContext(task, driverCtx)
135-
defer ctx.AllocDir.Destroy()
136-
d := NewExecDriver(driverCtx)
137-
138-
handle, err := d.Start(ctx, task)
139-
if err != nil {
140-
t.Fatalf("err: %v", err)
141-
}
142-
if handle == nil {
143-
t.Fatalf("missing handle")
144-
}
145-
146-
// Update should be a no-op
147-
err = handle.Update(task)
148-
if err != nil {
149-
t.Fatalf("err: %v", err)
150-
}
151-
152-
// Task should terminate quickly
153-
select {
154-
case err := <-handle.WaitCh():
155-
if err != nil {
156-
t.Fatalf("err: %v", err)
157-
}
158-
case <-time.After(2 * time.Second):
159-
t.Fatalf("timeout")
160-
}
124+
ctestutils.ExecCompatible(t)
125+
task := &structs.Task{
126+
Name: "sleep",
127+
Config: map[string]string{
128+
"artifact_source": "https://dl.dropboxusercontent.com/u/47675/jar_thing/hi_linux_amd64",
129+
},
130+
Resources: basicResources,
131+
}
132+
133+
driverCtx := testDriverContext(task.Name)
134+
ctx := testDriverExecContext(task, driverCtx)
135+
defer ctx.AllocDir.Destroy()
136+
d := NewExecDriver(driverCtx)
137+
138+
handle, err := d.Start(ctx, task)
139+
if err != nil {
140+
t.Fatalf("err: %v", err)
141+
}
142+
if handle == nil {
143+
t.Fatalf("missing handle")
144+
}
145+
146+
// Update should be a no-op
147+
err = handle.Update(task)
148+
if err != nil {
149+
t.Fatalf("err: %v", err)
150+
}
151+
152+
// Task should terminate quickly
153+
select {
154+
case err := <-handle.WaitCh():
155+
if err != nil {
156+
t.Fatalf("err: %v", err)
157+
}
158+
case <-time.After(2 * time.Second):
159+
t.Fatalf("timeout")
160+
}
161161
}
162162

163163
func TestExecDriver_Start_Wait_AllocDir(t *testing.T) {

client/driver/java.go

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import (
1111
"syscall"
1212
"time"
1313

14-
"github.com/hashicorp/go-getter"
14+
"github.com/hashicorp/go-getter"
1515
"github.com/hashicorp/nomad/client/allocdir"
1616
"github.com/hashicorp/nomad/client/config"
1717
"github.com/hashicorp/nomad/client/executor"
@@ -100,31 +100,27 @@ func (d *JavaDriver) Start(ctx *ExecContext, task *structs.Task) (DriverHandle,
100100
return nil, fmt.Errorf("Could not find task directory for task: %v", d.DriverContext.taskName)
101101
}
102102

103-
destDir := filepath.Join(taskDir, allocdir.TaskLocal)
103+
destDir := filepath.Join(taskDir, allocdir.TaskLocal)
104104

105-
// Create a location to download the binary.
106-
jarName := path.Base(source)
107-
jarPath := filepath.Join(destDir, jarName)
108-
if err := getter.GetFile(jarPath, source); err != nil {
109-
return nil, fmt.Errorf("Error downloading source for Java driver: %s", err)
105+
// Create a location to download the binary.
106+
jarName := path.Base(source)
107+
jarPath := filepath.Join(destDir, jarName)
108+
if err := getter.GetFile(jarPath, source); err != nil {
109+
return nil, fmt.Errorf("Error downloading source for Java driver: %s", err)
110110
}
111111

112112
// Get the environment variables.
113113
envVars := TaskEnvironmentVariables(ctx, task)
114114

115-
args := []string{}
116115
// Look for jvm options
117116
jvm_options, ok := task.Config["jvm_options"]
118117
if ok && jvm_options != "" {
119118
d.logger.Printf("[DEBUG] driver.java: found JVM options: %s", jvm_options)
120119
args = append(args, jvm_options)
121120
}
122121

123-
// Build the argument list
124-
args = append(args, "-jar", filepath.Join(allocdir.TaskLocal, fName))
125-
126122
// Build the argument list.
127-
args := []string{"-jar", filepath.Join(allocdir.TaskLocal, jarName)}
123+
args := []string{"-jar", filepath.Join(allocdir.TaskLocal, jarName)}
128124
if argRaw, ok := task.Config["args"]; ok {
129125
args = append(args, argRaw)
130126
}

client/driver/qemu.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import (
1818
"syscall"
1919
"time"
2020

21-
"github.com/hashicorp/go-getter"
21+
"github.com/hashicorp/go-getter"
2222
"github.com/hashicorp/nomad/client/allocdir"
2323
"github.com/hashicorp/nomad/client/config"
2424
"github.com/hashicorp/nomad/nomad/structs"
@@ -100,19 +100,19 @@ func (d *QemuDriver) Start(ctx *ExecContext, task *structs.Task) (DriverHandle,
100100
return nil, fmt.Errorf("Could not find task directory for task: %v", d.DriverContext.taskName)
101101
}
102102

103-
// Create a location to download the binary.
104-
destDir := filepath.Join(taskDir, allocdir.TaskLocal)
103+
// Create a location to download the binary.
104+
destDir := filepath.Join(taskDir, allocdir.TaskLocal)
105105
vmID := fmt.Sprintf("qemu-vm-%s-%s", structs.GenerateUUID(), filepath.Base(source))
106-
vmPath := filepath.Join(destDir, vmID)
107-
if err := getter.GetFile(vmPath, source); err != nil {
108-
return nil, fmt.Errorf("Error downloading source for Java driver: %s", err)
106+
vmPath := filepath.Join(destDir, vmID)
107+
if err := getter.GetFile(vmPath, source); err != nil {
108+
return nil, fmt.Errorf("Error downloading source for Java driver: %s", err)
109109
}
110110

111111
// compute and check checksum
112112
if check, ok := task.Config["checksum"]; ok {
113113
d.logger.Printf("[DEBUG] Running checksum on (%s)", vmID)
114114
hasher := sha256.New()
115-
file, err := os.Open(vmPath)
115+
file, err := os.Open(vmPath)
116116
if err != nil {
117117
return nil, fmt.Errorf("Failed to open file for checksum")
118118
}
@@ -143,7 +143,7 @@ func (d *QemuDriver) Start(ctx *ExecContext, task *structs.Task) (DriverHandle,
143143
"-machine", "type=pc,accel=" + accelerator,
144144
"-name", vmID,
145145
"-m", mem,
146-
"-drive", "file=" + vmPath,
146+
"-drive", "file=" + vmPath,
147147
"-nodefconfig",
148148
"-nodefaults",
149149
"-nographic",
@@ -220,7 +220,7 @@ func (d *QemuDriver) Start(ctx *ExecContext, task *structs.Task) (DriverHandle,
220220
// Create and Return Handle
221221
h := &qemuHandle{
222222
proc: cmd.Process,
223-
vmID: vmPath,
223+
vmID: vmPath,
224224
doneCh: make(chan struct{}),
225225
waitCh: make(chan error, 1),
226226
}

website/.ruby-version

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
2.2.2

website/source/docs/drivers/exec.html.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ scripts or other wrappers which provide higher level features.
2121
The `exec` driver supports the following configuration in the job spec:
2222

2323
* `command` - The command to execute. Must be provided.
24+
* `artifact_source` – Source location of an executable artifact. Must be accessible
25+
from the Nomad client
2426

2527
* `args` - The argument list to the command, space seperated. Optional.
2628

@@ -30,6 +32,9 @@ The `exec` driver can run on all supported operating systems but to provide
3032
proper isolation the client must be run as root on non-Windows operating systems.
3133
Further, to support cgroups, `/sys/fs/cgroups/` must be mounted.
3234

35+
You must specify either a `command` or a `artifact_source` to be executed. Any
36+
`command` is assumed to be present on the running client.
37+
3338
## Client Attributes
3439

3540
The `exec` driver will set the following client attributes:

website/source/docs/drivers/java.html.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ HTTP from the Nomad client.
1919
The `java` driver supports the following configuration in the job spec:
2020

2121
* `jar_source` - **(Required)** The hosted location of the source Jar file. Must be accessible
22-
from the Nomad client, via HTTP
22+
from the Nomad client
2323

2424
* `args` - **(Optional)** The argument list for the `java` command, space separated.
2525

website/source/docs/drivers/qemu.html.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ The `Qemu` driver can execute any regular `qemu` image (e.g. `qcow`, `img`,
2424
The `Qemu` driver supports the following configuration in the job spec:
2525

2626
* `image_source` - **(Required)** The hosted location of the source Qemu image. Must be accessible
27-
from the Nomad client, via HTTP.
27+
from the Nomad client
2828
* `checksum` - **(Required)** The MD5 checksum of the `qemu` image. If the
2929
checksums do not match, the `Qemu` diver will fail to start the image
3030
* `accelerator` - (Optional) The type of accelerator to use in the invocation.

0 commit comments

Comments
 (0)