Execute commands in runner via WebSocket
This enables executing commands in runners and forwarding input and output between the runner and the websocket to the client. Co-authored-by: Maximilian Paß <maximilian.pass@student.hpi.uni-potsdam.de>
This commit is contained in:
@@ -3,6 +3,7 @@ package nomad
|
||||
import (
|
||||
"context"
|
||||
nomadApi "github.com/hashicorp/nomad/api"
|
||||
"io"
|
||||
"net/url"
|
||||
)
|
||||
|
||||
@@ -23,6 +24,10 @@ type apiQuerier interface {
|
||||
// DeleteRunner deletes the runner with the given Id.
|
||||
DeleteRunner(runnerId string) (err error)
|
||||
|
||||
// ExecuteCommand runs a command in the passed allocation.
|
||||
ExecuteCommand(allocationID string, ctx context.Context, command []string,
|
||||
stdin io.Reader, stdout, stderr io.Writer) (int, error)
|
||||
|
||||
// loadRunners loads all allocations of the specified job.
|
||||
loadRunners(jobId string) (allocationListStub []*nomadApi.AllocationListStub, err error)
|
||||
|
||||
@@ -60,6 +65,16 @@ func (nc *nomadApiClient) DeleteRunner(runnerId string) (err error) {
|
||||
return err
|
||||
}
|
||||
|
||||
func (nc *nomadApiClient) ExecuteCommand(allocationID string,
|
||||
ctx context.Context, command []string,
|
||||
stdin io.Reader, stdout, stderr io.Writer) (int, error) {
|
||||
allocation, _, err := nc.client.Allocations().Info(allocationID, nil)
|
||||
if err != nil {
|
||||
return 1, err
|
||||
}
|
||||
return nc.client.Allocations().Exec(ctx, allocation, TaskName, true, command, stdin, stdout, stderr, nil, nil)
|
||||
}
|
||||
|
||||
func (nc *nomadApiClient) loadRunners(jobId string) (allocationListStub []*nomadApi.AllocationListStub, err error) {
|
||||
allocationListStub, _, err = nc.client.Jobs().Allocations(jobId, true, nil)
|
||||
return
|
||||
|
Reference in New Issue
Block a user