Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion playground/backend/cmd/server/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func (controller *playgroundController) RunCode(ctx context.Context, info *pb.Ru
return nil, errors.InternalError("Run code", "Error during setup file system: "+err.Error())
}

compileBuilder, err := compile_builder.Setup(lc.GetAbsoluteExecutableFilePath(), lc.GetAbsoluteExecutableFilesFolderPath(), info.Sdk, controller.env.BeamSdkEnvs.ExecutorConfig)
compileBuilder, err := compile_builder.Setup(lc.GetAbsoluteSourceFilePath(), lc.GetAbsoluteBaseFolderPath(), info.Sdk, controller.env.BeamSdkEnvs.ExecutorConfig)
if err != nil {
logger.Errorf("RunCode(): error during setup run builder: %s\n", err.Error())
return nil, errors.InvalidArgumentError("Run code", "Error during setup compile builder: "+err.Error())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,8 +222,8 @@ func Test_Process(t *testing.T) {
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
lc, _ := fs_tool.NewLifeCycle(pb.Sdk_SDK_JAVA, tt.args.pipelineId, os.Getenv("APP_WORK_DIR"))
filePath := lc.GetAbsoluteExecutableFilePath()
workingDir := lc.GetAbsoluteExecutableFilesFolderPath()
filePath := lc.GetAbsoluteSourceFilePath()
workingDir := lc.GetAbsoluteBaseFolderPath()

exec := executors.NewExecutorBuilder().
WithValidator().
Expand All @@ -239,7 +239,7 @@ func Test_Process(t *testing.T) {
t.Fatalf("error during prepare folders: %s", err.Error())
}
if tt.createExecFile {
_, _ = lc.CreateExecutableFile(tt.code)
_, _ = lc.CreateSourceCodeFile(tt.code)
}

if tt.cancelFunc {
Expand All @@ -258,7 +258,7 @@ func Test_Process(t *testing.T) {

compileOutput, _ := cacheService.GetValue(tt.args.ctx, tt.args.pipelineId, cache.CompileOutput)
if tt.expectedCompileOutput != nil && strings.Contains(tt.expectedCompileOutput.(string), "%s") {
tt.expectedCompileOutput = fmt.Sprintf(tt.expectedCompileOutput.(string), lc.GetAbsoluteExecutableFilePath())
tt.expectedCompileOutput = fmt.Sprintf(tt.expectedCompileOutput.(string), lc.GetAbsoluteSourceFilePath())
}
if !reflect.DeepEqual(compileOutput, tt.expectedCompileOutput) {
t.Errorf("processCode() set compileOutput: %s, but expectes: %s", compileOutput, tt.expectedCompileOutput)
Expand Down
4 changes: 2 additions & 2 deletions playground/backend/internal/executors/executor_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,8 @@ func (b *RunBuilder) WithArgs(runArgs []string) *RunBuilder {
return b
}

//WithClassName adds file name to executor
func (b *RunBuilder) WithClassName(name string) *RunBuilder {
//WithExecutableName adds file name to executor
func (b *RunBuilder) WithExecutableName(name string) *RunBuilder {
b.actions = append(b.actions, func(e *Executor) {
e.runArgs.fileName = name
})
Expand Down
2 changes: 1 addition & 1 deletion playground/backend/internal/executors/executor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func BaseExecutorBuilder(envs environment.BeamEnvs, workingDir string, filePath
WithRunner().
WithCommand(envs.ExecutorConfig.RunCmd).
WithArgs(envs.ExecutorConfig.RunArgs).
WithClassName("HelloWorld").
WithExecutableName("HelloWorld").
WithWorkingDir(workingDir).
WithValidator().
WithSdkValidators(validatorsFuncs).
Expand Down
40 changes: 20 additions & 20 deletions playground/backend/internal/fs_tool/fs.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,16 @@ const (
// Folder contains names of folders with executable and compiled files.
// For each SDK these values should be set depending on folders that need for the SDK.
type Folder struct {
BaseFolder string
ExecutableFolder string
CompiledFolder string
BaseFolder string
SourceFileFolder string
ExecutableFileFolder string
}

// Extension contains executable and compiled files' extensions.
// For each SDK these values should be set depending on SDK's extensions.
type Extension struct {
ExecutableExtension string
CompiledExtension string
SourceFileExtension string
ExecutableFileExtension string
}

// LifeCycle is used for preparing folders and files to process code for one request.
Expand Down Expand Up @@ -88,39 +88,39 @@ func (l *LifeCycle) DeleteFolders() error {
return nil
}

// CreateExecutableFile creates an executable file (i.e. file.{executableExtension}).
func (l *LifeCycle) CreateExecutableFile(code string) (string, error) {
if _, err := os.Stat(l.Folder.ExecutableFolder); os.IsNotExist(err) {
// CreateSourceCodeFile creates an executable file (i.e. file.{sourceFileExtension}).
func (l *LifeCycle) CreateSourceCodeFile(code string) (string, error) {
if _, err := os.Stat(l.Folder.SourceFileFolder); os.IsNotExist(err) {
return "", err
}

fileName := l.pipelineId.String() + l.Extension.ExecutableExtension
filePath := filepath.Join(l.Folder.ExecutableFolder, fileName)
fileName := l.pipelineId.String() + l.Extension.SourceFileExtension
filePath := filepath.Join(l.Folder.SourceFileFolder, fileName)
err := os.WriteFile(filePath, []byte(code), fileMode)
if err != nil {
return "", err
}
return fileName, nil
}

// GetAbsoluteExecutableFilePath returns absolute filepath to executable file (/path/to/workingDir/executable_files/{pipelineId}/src/{pipelineId}.{executableExtension}).
func (l *LifeCycle) GetAbsoluteExecutableFilePath() string {
fileName := l.pipelineId.String() + l.Extension.ExecutableExtension
filePath := filepath.Join(l.Folder.ExecutableFolder, fileName)
// GetAbsoluteSourceFilePath returns absolute filepath to executable file (/path/to/workingDir/executable_files/{pipelineId}/src/{pipelineId}.{sourceFileExtension}).
func (l *LifeCycle) GetAbsoluteSourceFilePath() string {
fileName := l.pipelineId.String() + l.Extension.SourceFileExtension
filePath := filepath.Join(l.Folder.SourceFileFolder, fileName)
absoluteFilePath, _ := filepath.Abs(filePath)
return absoluteFilePath
}

// GetAbsoluteBinaryFilePath returns absolute filepath to compiled file (/path/to/workingDir/executable_files/{pipelineId}/bin/{pipelineId}.{compiledExtension}).
func (l *LifeCycle) GetAbsoluteBinaryFilePath() string {
fileName := l.pipelineId.String() + l.Extension.CompiledExtension
filePath := filepath.Join(l.Folder.CompiledFolder, fileName)
// GetAbsoluteExecutableFilePath returns absolute filepath to compiled file (/path/to/workingDir/executable_files/{pipelineId}/bin/{pipelineId}.{executableExtension}).
func (l *LifeCycle) GetAbsoluteExecutableFilePath() string {
fileName := l.pipelineId.String() + l.Extension.ExecutableFileExtension
filePath := filepath.Join(l.Folder.ExecutableFileFolder, fileName)
absoluteFilePath, _ := filepath.Abs(filePath)
return absoluteFilePath
}

// GetAbsoluteExecutableFilesFolderPath returns absolute path to executable folder (/path/to/workingDir/executable_files/{pipelineId}).
func (l *LifeCycle) GetAbsoluteExecutableFilesFolderPath() string {
// GetAbsoluteBaseFolderPath returns absolute path to executable folder (/path/to/workingDir/executable_files/{pipelineId}).
func (l *LifeCycle) GetAbsoluteBaseFolderPath() string {
absoluteFilePath, _ := filepath.Abs(l.Folder.BaseFolder)
return absoluteFilePath
}
48 changes: 24 additions & 24 deletions playground/backend/internal/fs_tool/fs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ func TestLifeCycle_CreateExecutableFile(t *testing.T) {
name: "executable folder doesn't exist",
fields: fields{
folder: Folder{
ExecutableFolder: srcFileFolder,
CompiledFolder: binFileFolder,
SourceFileFolder: srcFileFolder,
ExecutableFileFolder: binFileFolder,
},
pipelineId: pipelineId,
},
Expand All @@ -66,12 +66,12 @@ func TestLifeCycle_CreateExecutableFile(t *testing.T) {
name: "executable folder exists",
createFolders: []string{srcFileFolder},
fields: fields{
folder: Folder{ExecutableFolder: srcFileFolder},
extension: Extension{ExecutableExtension: javaExecutableFileExtension},
folder: Folder{SourceFileFolder: srcFileFolder},
extension: Extension{SourceFileExtension: javaSourceFileExtension},
pipelineId: pipelineId,
},
args: args{code: "TEST_CODE"},
want: pipelineId.String() + javaExecutableFileExtension,
want: pipelineId.String() + javaSourceFileExtension,
wantErr: false,
},
}
Expand All @@ -86,13 +86,13 @@ func TestLifeCycle_CreateExecutableFile(t *testing.T) {
Extension: tt.fields.extension,
pipelineId: tt.fields.pipelineId,
}
got, err := l.CreateExecutableFile(tt.args.code)
got, err := l.CreateSourceCodeFile(tt.args.code)
if (err != nil) != tt.wantErr {
t.Errorf("CreateExecutableFile() error = %v, wantErr %v", err, tt.wantErr)
t.Errorf("CreateSourceCodeFile() error = %v, wantErr %v", err, tt.wantErr)
return
}
if got != tt.want {
t.Errorf("CreateExecutableFile() got = %v, want %v", got, tt.want)
t.Errorf("CreateSourceCodeFile() got = %v, want %v", got, tt.want)
}
})
os.RemoveAll(baseFileFolder)
Expand Down Expand Up @@ -208,13 +208,13 @@ func TestNewLifeCycle(t *testing.T) {
want: &LifeCycle{
folderGlobs: []string{baseFileFolder, srcFileFolder, binFileFolder},
Folder: Folder{
BaseFolder: baseFileFolder,
ExecutableFolder: srcFileFolder,
CompiledFolder: binFileFolder,
BaseFolder: baseFileFolder,
SourceFileFolder: srcFileFolder,
ExecutableFileFolder: binFileFolder,
},
Extension: Extension{
ExecutableExtension: javaExecutableFileExtension,
CompiledExtension: javaCompiledFileExtension,
SourceFileExtension: javaSourceFileExtension,
ExecutableFileExtension: javaCompiledFileExtension,
},
ExecutableName: executableName,
pipelineId: pipelineId,
Expand Down Expand Up @@ -260,7 +260,7 @@ func TestLifeCycle_GetAbsoluteExecutableFilePath(t *testing.T) {
baseFileFolder := fmt.Sprintf("%s_%s", baseFileFolder, pipelineId)
srcFileFolder := baseFileFolder + "/src"

filePath := fmt.Sprintf("%s/%s", srcFileFolder, pipelineId.String()+javaExecutableFileExtension)
filePath := fmt.Sprintf("%s/%s", srcFileFolder, pipelineId.String()+javaSourceFileExtension)
absolutePath, _ := filepath.Abs(filePath)
type fields struct {
folderGlobs []string
Expand All @@ -275,13 +275,13 @@ func TestLifeCycle_GetAbsoluteExecutableFilePath(t *testing.T) {
wantErr bool
}{
{
name: "GetAbsoluteExecutableFilePath",
name: "GetAbsoluteSourceFilePath",
fields: fields{
Folder: Folder{
BaseFolder: baseFileFolder,
ExecutableFolder: srcFileFolder,
SourceFileFolder: srcFileFolder,
},
Extension: Extension{ExecutableExtension: javaExecutableFileExtension},
Extension: Extension{SourceFileExtension: javaSourceFileExtension},
pipelineId: pipelineId,
},
want: absolutePath,
Expand All @@ -295,9 +295,9 @@ func TestLifeCycle_GetAbsoluteExecutableFilePath(t *testing.T) {
Extension: tt.fields.Extension,
pipelineId: tt.fields.pipelineId,
}
got := l.GetAbsoluteExecutableFilePath()
got := l.GetAbsoluteSourceFilePath()
if got != tt.want {
t.Errorf("GetAbsoluteExecutableFilePath() got = %v, want %v", got, tt.want)
t.Errorf("GetAbsoluteSourceFilePath() got = %v, want %v", got, tt.want)
}
})
}
Expand All @@ -324,7 +324,7 @@ func TestLifeCycle_GetAbsoluteExecutableFilesFolderPath(t *testing.T) {
name: "GetAbsoluteExecutableFolderPath",
fields: fields{
Folder: Folder{BaseFolder: baseFileFolder},
Extension: Extension{ExecutableExtension: javaExecutableFileExtension},
Extension: Extension{SourceFileExtension: javaSourceFileExtension},
pipelineId: pipelineId,
},
want: absolutePath,
Expand All @@ -338,9 +338,9 @@ func TestLifeCycle_GetAbsoluteExecutableFilesFolderPath(t *testing.T) {
Extension: tt.fields.Extension,
pipelineId: tt.fields.pipelineId,
}
got := l.GetAbsoluteExecutableFilesFolderPath()
got := l.GetAbsoluteBaseFolderPath()
if got != tt.want {
t.Errorf("GetAbsoluteExecutableFilesFolderPath() got = %v, want %v", got, tt.want)
t.Errorf("GetAbsoluteBaseFolderPath() got = %v, want %v", got, tt.want)
}
})
}
Expand Down Expand Up @@ -369,8 +369,8 @@ func TestLifeCycle_ExecutableName(t *testing.T) {
name: "ExecutableName",
fields: fields{
Folder: Folder{
BaseFolder: baseFileFolder,
CompiledFolder: binFileFolder,
BaseFolder: baseFileFolder,
ExecutableFileFolder: binFileFolder,
},
ExecutableName: func(u uuid.UUID, s string) (string, error) {
return "MOCK_EXECUTABLE_NAME", nil
Expand Down
6 changes: 3 additions & 3 deletions playground/backend/internal/fs_tool/go_fs.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ import (
)

const (
goExecutableFileExtension = ".go"
goCompiledFileExtension = ""
goSourceFileExtension = ".go"
goExecutableFileExtension = ""
)

// newGoLifeCycle creates LifeCycle with go SDK environment.
func newGoLifeCycle(pipelineId uuid.UUID, workingDir string) *LifeCycle {
return newCompilingLifeCycle(pipelineId, workingDir, goExecutableFileExtension, goCompiledFileExtension)
return newCompilingLifeCycle(pipelineId, workingDir, goSourceFileExtension, goExecutableFileExtension)
}
10 changes: 5 additions & 5 deletions playground/backend/internal/fs_tool/go_fs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,13 @@ func Test_newGoLifeCycle(t *testing.T) {
want: &LifeCycle{
folderGlobs: []string{baseFileFolder, srcFileFolder, binFileFolder},
Folder: Folder{
BaseFolder: baseFileFolder,
ExecutableFolder: srcFileFolder,
CompiledFolder: binFileFolder,
BaseFolder: baseFileFolder,
SourceFileFolder: srcFileFolder,
ExecutableFileFolder: binFileFolder,
},
Extension: Extension{
ExecutableExtension: goExecutableFileExtension,
CompiledExtension: goCompiledFileExtension,
SourceFileExtension: goSourceFileExtension,
ExecutableFileExtension: goExecutableFileExtension,
},
pipelineId: pipelineId,
},
Expand Down
6 changes: 3 additions & 3 deletions playground/backend/internal/fs_tool/java_fs.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ import (
)

const (
javaExecutableFileExtension = ".java"
javaCompiledFileExtension = ".class"
javaSourceFileExtension = ".java"
javaCompiledFileExtension = ".class"
)

// newJavaLifeCycle creates LifeCycle with java SDK environment.
func newJavaLifeCycle(pipelineId uuid.UUID, workingDir string) *LifeCycle {
javaLifeCycle := newCompilingLifeCycle(pipelineId, workingDir, javaExecutableFileExtension, javaCompiledFileExtension)
javaLifeCycle := newCompilingLifeCycle(pipelineId, workingDir, javaSourceFileExtension, javaCompiledFileExtension)
javaLifeCycle.ExecutableName = executableName
return javaLifeCycle
}
Expand Down
18 changes: 9 additions & 9 deletions playground/backend/internal/fs_tool/java_fs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,13 @@ func Test_newJavaLifeCycle(t *testing.T) {
want: &LifeCycle{
folderGlobs: []string{baseFileFolder, srcFileFolder, binFileFolder},
Folder: Folder{
BaseFolder: baseFileFolder,
ExecutableFolder: srcFileFolder,
CompiledFolder: binFileFolder,
BaseFolder: baseFileFolder,
SourceFileFolder: srcFileFolder,
ExecutableFileFolder: binFileFolder,
},
Extension: Extension{
ExecutableExtension: javaExecutableFileExtension,
CompiledExtension: javaCompiledFileExtension,
SourceFileExtension: javaSourceFileExtension,
ExecutableFileExtension: javaCompiledFileExtension,
},
ExecutableName: executableName,
pipelineId: pipelineId,
Expand Down Expand Up @@ -103,7 +103,7 @@ func Test_executableName(t *testing.T) {
wantErr bool
}{
{
// Test case with calling executableName method with correct pipelineId and workingDir.
// Test case with calling sourceFileName method with correct pipelineId and workingDir.
// As a result, want to receive a name that should be executed
name: "get executable name",
prepare: func() {
Expand All @@ -122,7 +122,7 @@ func Test_executableName(t *testing.T) {
wantErr: false,
},
{
// Test case with calling executableName method with correct pipelineId and workingDir.
// Test case with calling sourceFileName method with correct pipelineId and workingDir.
// As a result, want to receive an error.
name: "directory doesn't exist",
prepare: func() {},
Expand All @@ -139,11 +139,11 @@ func Test_executableName(t *testing.T) {
tt.prepare()
got, err := executableName(tt.args.pipelineId, tt.args.workingDir)
if (err != nil) != tt.wantErr {
t.Errorf("executableName() error = %v, wantErr %v", err, tt.wantErr)
t.Errorf("sourceFileName() error = %v, wantErr %v", err, tt.wantErr)
return
}
if got != tt.want {
t.Errorf("executableName() got = %v, want %v", got, tt.want)
t.Errorf("sourceFileName() got = %v, want %v", got, tt.want)
}
})
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,21 +26,21 @@ const (
compiledFolderName = "bin"
)

// newCompilingLifeCycle creates LifeCycle with compiled SDK environment.
func newCompilingLifeCycle(pipelineId uuid.UUID, workingDir string, executableFileExtension string, compiledFileExtension string) *LifeCycle {
// newCompilingLifeCycle creates LifeCycle for compiled SDK environment.
func newCompilingLifeCycle(pipelineId uuid.UUID, workingDir string, sourceFileExtension string, compiledFileExtension string) *LifeCycle {
baseFileFolder := filepath.Join(workingDir, baseFileFolder, pipelineId.String())
srcFileFolder := filepath.Join(baseFileFolder, sourceFolderName)
binFileFolder := filepath.Join(baseFileFolder, compiledFolderName)
return &LifeCycle{
folderGlobs: []string{baseFileFolder, srcFileFolder, binFileFolder},
Folder: Folder{
BaseFolder: baseFileFolder,
ExecutableFolder: srcFileFolder,
CompiledFolder: binFileFolder,
BaseFolder: baseFileFolder,
SourceFileFolder: srcFileFolder,
ExecutableFileFolder: binFileFolder,
},
Extension: Extension{
ExecutableExtension: executableFileExtension,
CompiledExtension: compiledFileExtension,
SourceFileExtension: sourceFileExtension,
ExecutableFileExtension: compiledFileExtension,
},
pipelineId: pipelineId,
}
Expand Down
Loading