Skip to content

Commit

Permalink
update driver docs
Browse files Browse the repository at this point in the history
  • Loading branch information
catsby committed Oct 16, 2015
1 parent e14032f commit b097d19
Show file tree
Hide file tree
Showing 8 changed files with 92 additions and 90 deletions.
76 changes: 38 additions & 38 deletions client/driver/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@ package driver

import (
"fmt"
"log"
"os/exec"
"path"
"path/filepath"
"log"
"os/exec"
"path"
"path/filepath"
"runtime"
"syscall"
"time"

"github.com/hashicorp/go-getter"
"github.com/hashicorp/nomad/client/allocdir"
"github.com/hashicorp/go-getter"
"github.com/hashicorp/nomad/client/allocdir"
"github.com/hashicorp/nomad/client/config"
"github.com/hashicorp/nomad/client/executor"
"github.com/hashicorp/nomad/nomad/structs"
Expand Down Expand Up @@ -47,40 +47,40 @@ func (d *ExecDriver) Fingerprint(cfg *config.Config, node *structs.Node) (bool,
}

func (d *ExecDriver) Start(ctx *ExecContext, task *structs.Task) (DriverHandle, error) {
// Get the command to be ran, or if omitted, download an artifact for
// execution. Currently a supplied command takes precedence, and an artifact
// is only downloaded if no command is supplied
// Get the command to be ran, or if omitted, download an artifact for
// execution. Currently a supplied command takes precedence, and an artifact
// is only downloaded if no command is supplied
command, ok := task.Config["command"]
if !ok || command == "" {
source, sok := task.Config["artifact_source"]
if !sok || source == "" {
return nil, fmt.Errorf("missing command or source for exec driver")
}

// Proceed to download an artifact to be executed.
// We use go-getter to support a variety of protocols, but need to change
// file permissions of the resulted download to be executable
taskDir, ok := ctx.AllocDir.TaskDirs[d.DriverContext.taskName]
if !ok {
return nil, fmt.Errorf("[Err] driver.Exec: Could not find task directory for task: %v", d.DriverContext.taskName)
}

destDir := filepath.Join(taskDir, allocdir.TaskLocal)

// Create a location to download the artifact.
artifactName := path.Base(source)
command = filepath.Join(destDir, artifactName)
if err := getter.GetFile(command, source); err != nil {
return nil, fmt.Errorf("[Err] driver.Exec: Error downloading source for Exec driver: %s", err)
}

cmd := exec.Command("chmod", "+x", command)
if err := cmd.Run(); err != nil {
log.Printf("[Err] driver.Exec: Error making artifact executable: %s", err)
}

// re-assign the command to be the local execution path
command = filepath.Join(allocdir.TaskLocal, artifactName)
source, sok := task.Config["artifact_source"]
if !sok || source == "" {
return nil, fmt.Errorf("missing command or source for exec driver")
}

// Proceed to download an artifact to be executed.
// We use go-getter to support a variety of protocols, but need to change
// file permissions of the resulted download to be executable
taskDir, ok := ctx.AllocDir.TaskDirs[d.DriverContext.taskName]
if !ok {
return nil, fmt.Errorf("[Err] driver.Exec: Could not find task directory for task: %v", d.DriverContext.taskName)
}

destDir := filepath.Join(taskDir, allocdir.TaskLocal)

// Create a location to download the artifact.
artifactName := path.Base(source)
command = filepath.Join(destDir, artifactName)
if err := getter.GetFile(command, source); err != nil {
return nil, fmt.Errorf("[Err] driver.Exec: Error downloading source for Exec driver: %s", err)
}

cmd := exec.Command("chmod", "+x", command)
if err := cmd.Run(); err != nil {
log.Printf("[Err] driver.Exec: Error making artifact executable: %s", err)
}

// re-assign the command to be the local execution path
command = filepath.Join(allocdir.TaskLocal, artifactName)
}

// Get the environment variables.
Expand Down
74 changes: 37 additions & 37 deletions client/driver/exec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,43 +121,43 @@ func TestExecDriver_Start_Wait(t *testing.T) {
}

func TestExecDriver_Start_Artifact_Wait(t *testing.T) {
ctestutils.ExecCompatible(t)
task := &structs.Task{
Name: "sleep",
Config: map[string]string{
"artifact_source": "https://dl.dropboxusercontent.com/u/47675/jar_thing/hi_linux_amd64",
},
Resources: basicResources,
}

driverCtx := testDriverContext(task.Name)
ctx := testDriverExecContext(task, driverCtx)
defer ctx.AllocDir.Destroy()
d := NewExecDriver(driverCtx)

handle, err := d.Start(ctx, task)
if err != nil {
t.Fatalf("err: %v", err)
}
if handle == nil {
t.Fatalf("missing handle")
}

// Update should be a no-op
err = handle.Update(task)
if err != nil {
t.Fatalf("err: %v", err)
}

// Task should terminate quickly
select {
case err := <-handle.WaitCh():
if err != nil {
t.Fatalf("err: %v", err)
}
case <-time.After(2 * time.Second):
t.Fatalf("timeout")
}
ctestutils.ExecCompatible(t)
task := &structs.Task{
Name: "sleep",
Config: map[string]string{
"artifact_source": "https://dl.dropboxusercontent.com/u/47675/jar_thing/hi_linux_amd64",
},
Resources: basicResources,
}

driverCtx := testDriverContext(task.Name)
ctx := testDriverExecContext(task, driverCtx)
defer ctx.AllocDir.Destroy()
d := NewExecDriver(driverCtx)

handle, err := d.Start(ctx, task)
if err != nil {
t.Fatalf("err: %v", err)
}
if handle == nil {
t.Fatalf("missing handle")
}

// Update should be a no-op
err = handle.Update(task)
if err != nil {
t.Fatalf("err: %v", err)
}

// Task should terminate quickly
select {
case err := <-handle.WaitCh():
if err != nil {
t.Fatalf("err: %v", err)
}
case <-time.After(2 * time.Second):
t.Fatalf("timeout")
}
}

func TestExecDriver_Start_Wait_AllocDir(t *testing.T) {
Expand Down
4 changes: 0 additions & 4 deletions client/driver/java.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,16 +112,12 @@ func (d *JavaDriver) Start(ctx *ExecContext, task *structs.Task) (DriverHandle,
// Get the environment variables.
envVars := TaskEnvironmentVariables(ctx, task)

args := []string{}
// Look for jvm options
jvm_options, ok := task.Config["jvm_options"]
if ok && jvm_options != "" {
d.logger.Printf("[DEBUG] driver.java: found JVM options: %s", jvm_options)
}

// Build the argument list
args = append(args, "-jar", filepath.Join(allocdir.TaskLocal, fName))

// Build the argument list.
args := []string{"-jar", filepath.Join(allocdir.TaskLocal, jarName)}
if argRaw, ok := task.Config["args"]; ok {
Expand Down
18 changes: 9 additions & 9 deletions client/driver/qemu.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (
"syscall"
"time"

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

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

// compute and check checksum
if check, ok := task.Config["checksum"]; ok {
d.logger.Printf("[DEBUG] Running checksum on (%s)", vmID)
hasher := sha256.New()
file, err := os.Open(vmPath)
file, err := os.Open(vmPath)
if err != nil {
return nil, fmt.Errorf("Failed to open file for checksum")
}
Expand Down Expand Up @@ -143,7 +143,7 @@ func (d *QemuDriver) Start(ctx *ExecContext, task *structs.Task) (DriverHandle,
"-machine", "type=pc,accel=" + accelerator,
"-name", vmID,
"-m", mem,
"-drive", "file=" + vmPath,
"-drive", "file=" + vmPath,
"-nodefconfig",
"-nodefaults",
"-nographic",
Expand Down Expand Up @@ -220,7 +220,7 @@ func (d *QemuDriver) Start(ctx *ExecContext, task *structs.Task) (DriverHandle,
// Create and Return Handle
h := &qemuHandle{
proc: cmd.Process,
vmID: vmPath,
vmID: vmPath,
doneCh: make(chan struct{}),
waitCh: make(chan error, 1),
}
Expand Down
1 change: 1 addition & 0 deletions website/.ruby-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
2.2.2
5 changes: 5 additions & 0 deletions website/source/docs/drivers/exec.html.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ scripts or other wrappers which provide higher level features.
The `exec` driver supports the following configuration in the job spec:

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

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

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

You must specify either a `command` or a `artifact_source` to be executed. Any
`command` is assumed to be present on the running client.

## Client Attributes

The `exec` driver will set the following client attributes:
Expand Down
2 changes: 1 addition & 1 deletion website/source/docs/drivers/java.html.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ HTTP from the Nomad client.
The `java` driver supports the following configuration in the job spec:

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

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

Expand Down
2 changes: 1 addition & 1 deletion website/source/docs/drivers/qemu.html.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ The `Qemu` driver can execute any regular `qemu` image (e.g. `qcow`, `img`,
The `Qemu` driver supports the following configuration in the job spec:

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

0 comments on commit b097d19

Please sign in to comment.