From 9489f45947d42b4e5c5fc8fbcbc42f5fa597ba82 Mon Sep 17 00:00:00 2001 From: Clint Shryock Date: Fri, 16 Oct 2015 17:05:25 -0500 Subject: [PATCH] update driver docs --- client/driver/exec.go | 76 ++++++++++++------------ client/driver/exec_test.go | 74 +++++++++++------------ client/driver/java.go | 20 +++---- client/driver/qemu.go | 18 +++--- website/.ruby-version | 1 + website/source/docs/drivers/exec.html.md | 5 ++ website/source/docs/drivers/java.html.md | 2 +- website/source/docs/drivers/qemu.html.md | 2 +- 8 files changed, 100 insertions(+), 98 deletions(-) create mode 100644 website/.ruby-version diff --git a/client/driver/exec.go b/client/driver/exec.go index 9b0beb2bd41..8b8f93f0049 100644 --- a/client/driver/exec.go +++ b/client/driver/exec.go @@ -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" @@ -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. diff --git a/client/driver/exec_test.go b/client/driver/exec_test.go index 0da95483992..0eb27886b31 100644 --- a/client/driver/exec_test.go +++ b/client/driver/exec_test.go @@ -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) { diff --git a/client/driver/java.go b/client/driver/java.go index d22bdc2d9f9..9c422ffb0b2 100644 --- a/client/driver/java.go +++ b/client/driver/java.go @@ -11,7 +11,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/client/executor" @@ -100,19 +100,18 @@ func (d *JavaDriver) Start(ctx *ExecContext, task *structs.Task) (DriverHandle, return nil, fmt.Errorf("Could not find task directory for task: %v", d.DriverContext.taskName) } - destDir := filepath.Join(taskDir, allocdir.TaskLocal) + destDir := filepath.Join(taskDir, allocdir.TaskLocal) - // Create a location to download the binary. - jarName := path.Base(source) - jarPath := filepath.Join(destDir, jarName) - if err := getter.GetFile(jarPath, source); err != nil { - return nil, fmt.Errorf("Error downloading source for Java driver: %s", err) + // Create a location to download the binary. + jarName := path.Base(source) + jarPath := filepath.Join(destDir, jarName) + if err := getter.GetFile(jarPath, source); err != nil { + return nil, fmt.Errorf("Error downloading source for Java driver: %s", err) } // 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 != "" { @@ -120,11 +119,8 @@ func (d *JavaDriver) Start(ctx *ExecContext, task *structs.Task) (DriverHandle, args = append(args, 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)} + args := []string{"-jar", filepath.Join(allocdir.TaskLocal, jarName)} if argRaw, ok := task.Config["args"]; ok { args = append(args, argRaw) } diff --git a/client/driver/qemu.go b/client/driver/qemu.go index 1d623be6477..739017a6d25 100644 --- a/client/driver/qemu.go +++ b/client/driver/qemu.go @@ -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" @@ -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") } @@ -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", @@ -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), } diff --git a/website/.ruby-version b/website/.ruby-version new file mode 100644 index 00000000000..b1b25a5ffae --- /dev/null +++ b/website/.ruby-version @@ -0,0 +1 @@ +2.2.2 diff --git a/website/source/docs/drivers/exec.html.md b/website/source/docs/drivers/exec.html.md index 1f3e50935c0..2311c40183c 100644 --- a/website/source/docs/drivers/exec.html.md +++ b/website/source/docs/drivers/exec.html.md @@ -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. @@ -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: diff --git a/website/source/docs/drivers/java.html.md b/website/source/docs/drivers/java.html.md index 62e1636a3ad..f174bad657e 100644 --- a/website/source/docs/drivers/java.html.md +++ b/website/source/docs/drivers/java.html.md @@ -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. diff --git a/website/source/docs/drivers/qemu.html.md b/website/source/docs/drivers/qemu.html.md index dbc941234d9..54a55263660 100644 --- a/website/source/docs/drivers/qemu.html.md +++ b/website/source/docs/drivers/qemu.html.md @@ -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.