From 00fc10fffb531e5f74ee3491c95ddde41b4c813d Mon Sep 17 00:00:00 2001 From: udsamani Date: Wed, 11 Sep 2024 09:00:00 +0100 Subject: [PATCH] wasm exeuctor models refactored --- cmd/cli/wasm/wasm_run.go | 2 +- pkg/bidstrategy/semantic/storage_installed_test.go | 2 +- pkg/compute/executor.go | 6 +++--- pkg/executor/wasm/executor.go | 3 +-- pkg/executor/wasm/handler.go | 3 +-- pkg/executor/wasm/{models => }/types.go | 2 +- pkg/models/utils/job.go | 2 +- pkg/test/devstack/default_publisher_test.go | 2 +- pkg/test/devstack/multiple_input_files_test.go | 2 +- pkg/test/devstack/publish_on_error_test.go | 2 +- pkg/test/devstack/url_test.go | 2 +- pkg/test/logstream/stream_wasm_test.go | 2 +- pkg/test/scenario/test_scenarios.go | 2 +- 13 files changed, 15 insertions(+), 17 deletions(-) rename pkg/executor/wasm/{models => }/types.go (99%) diff --git a/cmd/cli/wasm/wasm_run.go b/cmd/cli/wasm/wasm_run.go index 8205c1d09e..c27e76b802 100644 --- a/cmd/cli/wasm/wasm_run.go +++ b/cmd/cli/wasm/wasm_run.go @@ -24,7 +24,7 @@ import ( "github.com/bacalhau-project/bacalhau/cmd/util/parse" "github.com/bacalhau-project/bacalhau/cmd/util/printer" "github.com/bacalhau-project/bacalhau/pkg/executor/wasm" - engine_wasm "github.com/bacalhau-project/bacalhau/pkg/executor/wasm/models" + engine_wasm "github.com/bacalhau-project/bacalhau/pkg/executor/wasm" "github.com/bacalhau-project/bacalhau/pkg/models" "github.com/bacalhau-project/bacalhau/pkg/publicapi/apimodels" clientv2 "github.com/bacalhau-project/bacalhau/pkg/publicapi/client/v2" diff --git a/pkg/bidstrategy/semantic/storage_installed_test.go b/pkg/bidstrategy/semantic/storage_installed_test.go index cb3d339587..acda472767 100644 --- a/pkg/bidstrategy/semantic/storage_installed_test.go +++ b/pkg/bidstrategy/semantic/storage_installed_test.go @@ -9,7 +9,7 @@ import ( "github.com/stretchr/testify/require" - wasmmodels "github.com/bacalhau-project/bacalhau/pkg/executor/wasm/models" + wasmmodels "github.com/bacalhau-project/bacalhau/pkg/executor/wasm" "github.com/bacalhau-project/bacalhau/pkg/lib/provider" "github.com/bacalhau-project/bacalhau/pkg/models" "github.com/bacalhau-project/bacalhau/pkg/test/mock" diff --git a/pkg/compute/executor.go b/pkg/compute/executor.go index f6d598822f..26a5d50e3a 100644 --- a/pkg/compute/executor.go +++ b/pkg/compute/executor.go @@ -14,7 +14,7 @@ import ( "github.com/bacalhau-project/bacalhau/pkg/compute/store" "github.com/bacalhau-project/bacalhau/pkg/executor" - wasmmodels "github.com/bacalhau-project/bacalhau/pkg/executor/wasm/models" + "github.com/bacalhau-project/bacalhau/pkg/executor/wasm" "github.com/bacalhau-project/bacalhau/pkg/publisher" "github.com/bacalhau-project/bacalhau/pkg/storage" "github.com/bacalhau-project/bacalhau/pkg/system" @@ -80,7 +80,7 @@ func prepareInputVolumes( func prepareWasmVolumes( ctx context.Context, strgprovider storage.StorageProvider, - storageDirectory string, wasmEngine wasmmodels.EngineSpec) ( + storageDirectory string, wasmEngine wasm.EngineSpec) ( map[string][]storage.PreparedStorage, func(context.Context) error, error, ) { importModuleVolumes, err := storage.ParallelPrepareStorage(ctx, strgprovider, storageDirectory, wasmEngine.ImportModules...) @@ -156,7 +156,7 @@ func PrepareRunArguments( */ var engineArgs *models.SpecConfig if execution.Job.Task().Engine.IsType(models.EngineWasm) { - wasmEngine, err := wasmmodels.DecodeSpec(execution.Job.Task().Engine) + wasmEngine, err := wasm.DecodeSpec(execution.Job.Task().Engine) if err != nil { return nil, nil, err } diff --git a/pkg/executor/wasm/executor.go b/pkg/executor/wasm/executor.go index 014730c005..f8b1dff520 100644 --- a/pkg/executor/wasm/executor.go +++ b/pkg/executor/wasm/executor.go @@ -19,7 +19,6 @@ import ( "github.com/bacalhau-project/bacalhau/pkg/bidstrategy" "github.com/bacalhau-project/bacalhau/pkg/executor" - wasmmodels "github.com/bacalhau-project/bacalhau/pkg/executor/wasm/models" wasmlogs "github.com/bacalhau-project/bacalhau/pkg/logger/wasm" "github.com/bacalhau-project/bacalhau/pkg/storage" "github.com/bacalhau-project/bacalhau/pkg/storage/util" @@ -91,7 +90,7 @@ func (e *Executor) Start(ctx context.Context, request *executor.RunCommandReques engineConfig = engineConfig.WithMemoryLimitPages(uint32(requestedPages)) } - engineParams, err := wasmmodels.DecodeArguments(request.EngineParams) + engineParams, err := DecodeArguments(request.EngineParams) if err != nil { return fmt.Errorf("decoding wasm arguments: %w", err) } diff --git a/pkg/executor/wasm/handler.go b/pkg/executor/wasm/handler.go index 2acb054f09..9f555e8428 100644 --- a/pkg/executor/wasm/handler.go +++ b/pkg/executor/wasm/handler.go @@ -17,7 +17,6 @@ import ( "golang.org/x/exp/maps" "github.com/bacalhau-project/bacalhau/pkg/executor" - wasmmodels "github.com/bacalhau-project/bacalhau/pkg/executor/wasm/models" wasmlogs "github.com/bacalhau-project/bacalhau/pkg/logger/wasm" "github.com/bacalhau-project/bacalhau/pkg/models" "github.com/bacalhau-project/bacalhau/pkg/storage" @@ -29,7 +28,7 @@ type executionHandler struct { // runtime configured with resource-limits runtime wazero.Runtime // arguments used to instantiate and run the wasm module - arguments *wasmmodels.EngineArguments + arguments *EngineArguments // virtual filesystem exposed to wasm module fs fs.FS // wasm modules imported by main wasm module diff --git a/pkg/executor/wasm/models/types.go b/pkg/executor/wasm/types.go similarity index 99% rename from pkg/executor/wasm/models/types.go rename to pkg/executor/wasm/types.go index fae1fff15b..e35496d18d 100644 --- a/pkg/executor/wasm/models/types.go +++ b/pkg/executor/wasm/types.go @@ -1,4 +1,4 @@ -package models +package wasm import ( "encoding/json" diff --git a/pkg/models/utils/job.go b/pkg/models/utils/job.go index 56bd4df775..fdbe16d9c4 100644 --- a/pkg/models/utils/job.go +++ b/pkg/models/utils/job.go @@ -1,7 +1,7 @@ package utils import ( - wasm "github.com/bacalhau-project/bacalhau/pkg/executor/wasm/models" + "github.com/bacalhau-project/bacalhau/pkg/executor/wasm" "github.com/bacalhau-project/bacalhau/pkg/models" "github.com/rs/zerolog/log" "github.com/samber/lo" diff --git a/pkg/test/devstack/default_publisher_test.go b/pkg/test/devstack/default_publisher_test.go index 2e801f365a..1221ffc141 100644 --- a/pkg/test/devstack/default_publisher_test.go +++ b/pkg/test/devstack/default_publisher_test.go @@ -7,7 +7,7 @@ import ( "os" "testing" - wasmmodels "github.com/bacalhau-project/bacalhau/pkg/executor/wasm/models" + wasmmodels "github.com/bacalhau-project/bacalhau/pkg/executor/wasm" _ "github.com/bacalhau-project/bacalhau/pkg/logger" "github.com/bacalhau-project/bacalhau/pkg/models" "github.com/bacalhau-project/bacalhau/pkg/publisher/local" diff --git a/pkg/test/devstack/multiple_input_files_test.go b/pkg/test/devstack/multiple_input_files_test.go index 28a30b0d04..b49d22cbc8 100644 --- a/pkg/test/devstack/multiple_input_files_test.go +++ b/pkg/test/devstack/multiple_input_files_test.go @@ -10,7 +10,7 @@ import ( "github.com/bacalhau-project/bacalhau/pkg/devstack" "github.com/bacalhau-project/bacalhau/pkg/downloader" - wasmmodels "github.com/bacalhau-project/bacalhau/pkg/executor/wasm/models" + wasmmodels "github.com/bacalhau-project/bacalhau/pkg/executor/wasm" "github.com/bacalhau-project/bacalhau/pkg/models" publisher_local "github.com/bacalhau-project/bacalhau/pkg/publisher/local" diff --git a/pkg/test/devstack/publish_on_error_test.go b/pkg/test/devstack/publish_on_error_test.go index ff87a683ac..e4f06fdda8 100644 --- a/pkg/test/devstack/publish_on_error_test.go +++ b/pkg/test/devstack/publish_on_error_test.go @@ -7,7 +7,7 @@ import ( "github.com/bacalhau-project/bacalhau/pkg/devstack" "github.com/bacalhau-project/bacalhau/pkg/downloader" - wasmmodels "github.com/bacalhau-project/bacalhau/pkg/executor/wasm/models" + wasmmodels "github.com/bacalhau-project/bacalhau/pkg/executor/wasm" _ "github.com/bacalhau-project/bacalhau/pkg/logger" "github.com/bacalhau-project/bacalhau/pkg/models" publisher_local "github.com/bacalhau-project/bacalhau/pkg/publisher/local" diff --git a/pkg/test/devstack/url_test.go b/pkg/test/devstack/url_test.go index 75b5963fcf..20246d74a8 100644 --- a/pkg/test/devstack/url_test.go +++ b/pkg/test/devstack/url_test.go @@ -15,7 +15,7 @@ import ( "github.com/bacalhau-project/bacalhau/pkg/config/types" "github.com/bacalhau-project/bacalhau/pkg/devstack" "github.com/bacalhau-project/bacalhau/pkg/downloader" - wasmmodels "github.com/bacalhau-project/bacalhau/pkg/executor/wasm/models" + wasmmodels "github.com/bacalhau-project/bacalhau/pkg/executor/wasm" "github.com/bacalhau-project/bacalhau/pkg/models" "github.com/bacalhau-project/bacalhau/pkg/node" publisher_local "github.com/bacalhau-project/bacalhau/pkg/publisher/local" diff --git a/pkg/test/logstream/stream_wasm_test.go b/pkg/test/logstream/stream_wasm_test.go index 882263a0cf..004f774315 100644 --- a/pkg/test/logstream/stream_wasm_test.go +++ b/pkg/test/logstream/stream_wasm_test.go @@ -17,7 +17,7 @@ import ( "github.com/bacalhau-project/bacalhau/pkg/test/mock" "github.com/bacalhau-project/bacalhau/testdata/wasm/cat" - wasmmodels "github.com/bacalhau-project/bacalhau/pkg/executor/wasm/models" + wasmmodels "github.com/bacalhau-project/bacalhau/pkg/executor/wasm" ) func (s *LogStreamTestSuite) TestWasmOutputStream() { diff --git a/pkg/test/scenario/test_scenarios.go b/pkg/test/scenario/test_scenarios.go index f78b33fb1d..1954930c52 100644 --- a/pkg/test/scenario/test_scenarios.go +++ b/pkg/test/scenario/test_scenarios.go @@ -8,7 +8,7 @@ import ( "github.com/bacalhau-project/bacalhau/pkg/devstack" "github.com/bacalhau-project/bacalhau/pkg/downloader" dockmodels "github.com/bacalhau-project/bacalhau/pkg/executor/docker/models" - wasmmodels "github.com/bacalhau-project/bacalhau/pkg/executor/wasm/models" + wasmmodels "github.com/bacalhau-project/bacalhau/pkg/executor/wasm" "github.com/bacalhau-project/bacalhau/pkg/models" publisher_local "github.com/bacalhau-project/bacalhau/pkg/publisher/local" "github.com/bacalhau-project/bacalhau/testdata/wasm/cat"