AydarZaynutdinov commented on a change in pull request #15803:
URL: https://github.com/apache/beam/pull/15803#discussion_r737378553
##########
File path: playground/backend/cmd/server/controller.go
##########
@@ -54,3 +121,125 @@ func (controller *playgroundController)
GetCompileOutput(ctx context.Context, in
compileOutput := pb.GetCompileOutputResponse{Output: "test compile
output"}
return &compileOutput, nil
}
+
+// setupValidators returns validators based on sdk
+func setupValidators(sdk pb.Sdk, filepath string) *[]validators.Validator {
+ var val *[]validators.Validator
+ switch sdk {
+ case pb.Sdk_SDK_JAVA:
+ val = validators.GetJavaValidators(filepath)
+ }
+ return val
+}
+
+// processCode validates, compiles and runs code by pipelineId.
+// During each operation updates status of execution and saves it into cache.
+// In case of some step is failed saves output logs to cache.
+// After success code running saves output to cache.
+// At the end of this method deletes all created folders
+func processCode(ctx context.Context, cacheService cache.Cache, lc
*fs_tool.LifeCycle, execBuilder *executors.CompileBuilder, pipelineId
uuid.UUID, env *environment.Environment) {
+ defer cleanUp(pipelineId, lc)
+
+ exec := execBuilder.Build()
+
+ // validate
+ log.Printf("%s: Validate() ...\n", pipelineId)
+
+ validateFunc := exec.Validate()
+ if err := validateFunc(); err != nil {
+ // error during validation
+ // TODO move to processError when status for validation error
will be added
+ log.Printf("%s: Validate: %s\n", pipelineId, err.Error())
+ setToCache(ctx, cacheService, pipelineId, cache.Status,
pb.Status_STATUS_ERROR)
+ return
+ }
+ log.Printf("%s: Validate() finish\n", pipelineId)
+
+ // compile
+ log.Printf("%s: Compile() ...\n", pipelineId)
+ compileCmd := exec.Compile()
+ if data, err := compileCmd.CombinedOutput(); err != nil {
+ processError(ctx, err, data, pipelineId, cacheService,
pb.Status_STATUS_COMPILE_ERROR)
+ return
+ }
+ log.Printf("%s: Compile() finish\n", pipelineId)
+
+ // set empty value to pipelineId: cache.SubKey_CompileOutput
+ setToCache(ctx, cacheService, pipelineId, cache.CompileOutput, "")
+
+ className, err := lc.ExecutableName(pipelineId,
env.ApplicationEnvs.WorkingDir())
+ if err != nil {
+ log.Printf("%s: get executable file name: %s\n", pipelineId,
err.Error())
+ setToCache(ctx, cacheService, pipelineId, cache.Status,
pb.Status_STATUS_ERROR)
+ return
+ }
+
+ exec = execBuilder.
+ WithRunner().
+ WithCommand(env.BeamSdkEnvs.ExecutorConfig.RunCmd).
+ WithArgs(env.BeamSdkEnvs.ExecutorConfig.RunArgs).
+ WithClassName(className).
+ WithWorkingDir(lc.GetAbsoluteExecutableFilesFolderPath()).
+ Build()
+
+ log.Printf("%s: Run() ...\n", pipelineId)
+ runCmd := exec.Run()
+ data, err := runCmd.CombinedOutput()
+ if err != nil {
+ // error during run code
+ processError(ctx, err, data, pipelineId, cacheService,
pb.Status_STATUS_ERROR)
+ return
+ }
+ log.Printf("%s: Run() finish\n", pipelineId)
+ processSuccess(ctx, data, pipelineId, cacheService)
+}
+
+// cleanUp removes all prepared folders for received LifeCycle
+func cleanUp(pipelineId uuid.UUID, lc *fs_tool.LifeCycle) {
+ log.Printf("%s: DeleteFolders() ...\n", pipelineId)
+ err := lc.DeleteFolders()
+ if err != nil {
+ log.Printf("%s: DeleteFolders(): %s\n", pipelineId, err.Error())
+ }
+ log.Printf("%s: DeleteFolders() complete\n", pipelineId)
+ log.Printf("%s: complete\n", pipelineId)
+}
+
+// processError processes error received during processing code via setting a
corresponding status and output to cache
+func processError(ctx context.Context, err error, data []byte, pipelineId
uuid.UUID, cacheService cache.Cache, status pb.Status) {
+ switch status {
+ case pb.Status_STATUS_ERROR:
+ log.Printf("%s: Run: err: %s, output: %s\n", pipelineId,
err.Error(), data)
+
+ // set to cache pipelineId: cache.SubKey_RunOutput: err.Error()
+ setToCache(ctx, cacheService, pipelineId, cache.RunOutput,
"error: "+err.Error()+", output: "+string(data))
+
+ // set to cache pipelineId: cache.SubKey_Status:
pb.Status_STATUS_ERROR
+ setToCache(ctx, cacheService, pipelineId, cache.Status,
pb.Status_STATUS_ERROR)
+ case pb.Status_STATUS_COMPILE_ERROR:
+ log.Printf("%s: Compile: err: %s, output: %s\n", pipelineId,
err.Error(), data)
+
+ // set to cache pipelineId: cache.SubKey_CompileOutput:
err.Error()
+ setToCache(ctx, cacheService, pipelineId, cache.CompileOutput,
"error: "+err.Error()+", output: "+string(data))
+
+ // set to cache pipelineId: cache.SubKey_Status:
pb.Status_STATUS_ERROR
+ setToCache(ctx, cacheService, pipelineId, cache.Status,
pb.Status_STATUS_COMPILE_ERROR)
+ }
+}
+
+// processSuccess processes case after successful code processing via setting
a corresponding status and output to cache
+func processSuccess(ctx context.Context, output []byte, pipelineId uuid.UUID,
cacheService cache.Cache) {
+ // set to cache pipelineId: cache.SubKey_RunOutput: output
+ setToCache(ctx, cacheService, pipelineId, cache.RunOutput,
string(output))
Review comment:
Changed.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]