Implement review comments

This commit is contained in:
Maximilian Paß
2022-02-22 16:47:13 +01:00
parent df68461264
commit 2cf890ab91
15 changed files with 109 additions and 110 deletions

View File

@@ -45,7 +45,7 @@ func TestAWSRunnerManager_Claim(t *testing.T) {
assert.NotNil(t, r)
})
t.Run("forwards request for non AWS environments", func(t *testing.T) {
t.Run("forwards request for non-AWS environments", func(t *testing.T) {
nextHandler := &ManagerMock{}
nextHandler.On("Claim", mock.AnythingOfType("dto.EnvironmentID"), mock.AnythingOfType("int")).
Return(nil, nil)
@@ -74,7 +74,7 @@ func TestAWSRunnerManager_Return(t *testing.T) {
assert.NotContains(t, m.usedRunners.List(), r)
})
t.Run("calls nextHandler for non AWS runner", func(t *testing.T) {
t.Run("calls nextHandler for non-AWS runner", func(t *testing.T) {
nextHandler := &ManagerMock{}
nextHandler.On("Return", mock.AnythingOfType("*runner.NomadJob")).Return(nil)
m.SetNextHandler(nextHandler)

View File

@@ -13,7 +13,7 @@ import (
"io"
)
var ErrWrongMessageType = errors.New("received message that is not a text messages")
var ErrWrongMessageType = errors.New("received message that is not a text message")
type awsFunctionRequest struct {
Action string `json:"action"`
@@ -22,6 +22,9 @@ type awsFunctionRequest struct {
}
// AWSFunctionWorkload is an abstraction to build a request to an AWS Lambda Function.
// It is not persisted on a Poseidon restart.
// The InactivityTimer is used actively. It stops listening to the Lambda function.
// AWS terminates the Lambda Function after the [Globals.Function.Timeout](deploy/aws/template.yaml).
type AWSFunctionWorkload struct {
InactivityTimer
id string
@@ -88,6 +91,9 @@ func (w *AWSFunctionWorkload) ExecuteInteractively(id string, _ io.ReadWriter, s
}
// UpdateFileSystem copies Files into the executor.
// Current limitation: No files can be deleted apart from the previously added files.
// Future Work: Deduplication of the file systems, as the largest workload is likely to be used by additional
// CSV files or similar, which are the same for many executions.
func (w *AWSFunctionWorkload) UpdateFileSystem(request *dto.UpdateFileSystemRequest) error {
for _, path := range request.Delete {
delete(w.fs, path)
@@ -136,7 +142,9 @@ func (w *AWSFunctionWorkload) executeCommand(ctx context.Context, command []stri
return
}
// receiveOutput listens for the execution timeout (or the exit code).
exitCode, err := w.receiveOutput(wsConn, stdout, stderr, ctx)
// TimeoutPassed checks the runner timeout
if w.TimeoutPassed() {
err = ErrorRunnerInactivityTimeout
}

View File

@@ -67,7 +67,7 @@ func TestAWSFunctionWorkload_ExecuteInteractively(t *testing.T) {
s := httptest.NewServer(http.HandlerFunc(awsMock.handler))
t.Run("establishes WebSocket connection to AWS endpoint", func(t *testing.T) {
// Convert http://127.0.0.1 to ws://127.0.0.
// Convert http://127.0.0.1 to ws://127.0.0.1
config.Config.AWS.Endpoint = "ws" + strings.TrimPrefix(s.URL, "http")
awsMock.ctx, cancel = context.WithCancel(context.Background())
cancel()
@@ -107,7 +107,7 @@ func TestAWSFunctionWorkload_UpdateFileSystem(t *testing.T) {
awsMock := &awsEndpointMock{}
s := httptest.NewServer(http.HandlerFunc(awsMock.handler))
// Convert http://127.0.0.1 to ws://127.0.0.
// Convert http://127.0.0.1 to ws://127.0.0.1
config.Config.AWS.Endpoint = "ws" + strings.TrimPrefix(s.URL, "http")
awsMock.ctx, cancel = context.WithTimeout(context.Background(), tests.ShortTimeout)
defer cancel()

View File

@@ -75,7 +75,7 @@ type EnvironmentAccessor interface {
EnvironmentStatistics() map[dto.EnvironmentID]*dto.StatisticalExecutionEnvironmentData
}
// AccessorHandler is one handler in te chain of responsibility of runner accessors.
// AccessorHandler is one handler in the chain of responsibility of runner accessors.
// Each runner accessor can handle different requests.
type AccessorHandler interface {
Accessor

View File

@@ -46,6 +46,8 @@ type NomadJob struct {
}
// NewNomadJob creates a new NomadJob with the provided id.
// The InactivityTimer is used actively. It executes onDestroy when it has expired.
// The InactivityTimer is persisted in Nomad by the runner manager's Claim Function.
func NewNomadJob(id string, portMappings []nomadApi.PortMapping,
apiClient nomad.ExecutorAPI, onDestroy DestroyRunnerHandler,
) *NomadJob {