Skip to content

Commit

Permalink
Merge pull request #15853 from [BEAM-13145][Playground] Validation error
Browse files Browse the repository at this point in the history
[BEAM-13145][Playground] Validation error
  • Loading branch information
pabloem committed Nov 2, 2021
2 parents 5103b8f + 59f5772 commit 59bd9a0
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 71 deletions.
11 changes: 7 additions & 4 deletions playground/api/v1/api.proto
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,14 @@ enum Sdk {

enum Status {
STATUS_UNSPECIFIED = 0;
STATUS_EXECUTING = 1;
STATUS_FINISHED = 2;
STATUS_ERROR = 3;
STATUS_VALIDATING = 1;
STATUS_VALIDATION_ERROR = 2;
STATUS_COMPILING = 3;
STATUS_COMPILE_ERROR = 4;
STATUS_RUN_TIMEOUT = 5;
STATUS_EXECUTING = 5;
STATUS_FINISHED = 6;
STATUS_ERROR = 7;
STATUS_RUN_TIMEOUT = 8;
}

// RunCodeRequest represents a code text and options of SDK which executes the code.
Expand Down
35 changes: 21 additions & 14 deletions playground/backend/cmd/server/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func (controller *playgroundController) RunCode(ctx context.Context, info *pb.Ru

compileBuilder := setupCompileBuilder(lc, info.Sdk, controller.env.BeamSdkEnvs.ExecutorConfig)

setToCache(ctx, controller.cacheService, pipelineId, cache.Status, pb.Status_STATUS_EXECUTING)
setToCache(ctx, controller.cacheService, pipelineId, cache.Status, pb.Status_STATUS_VALIDATING)
if err := controller.cacheService.SetExpTime(ctx, pipelineId, cacheExpirationTime); err != nil {
logger.Errorf("%s: RunCode(): cache.SetExpTime(): %s\n", pipelineId, err.Error())
return nil, errors.InternalError("Run code()", "Error during set expiration to cache: "+err.Error())
Expand Down Expand Up @@ -219,13 +219,11 @@ func processCode(ctx context.Context, cacheService cache.Cache, lc *fs_tool.Life
logger.Infof("%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
logger.Errorf("%s: Validate: %s\n", pipelineId, err.Error())
setToCache(ctx, cacheService, pipelineId, cache.Status, pb.Status_STATUS_ERROR)
processError(ctx, err, nil, pipelineId, cacheService, pb.Status_STATUS_VALIDATION_ERROR)
return
} else {
processSuccess(ctx, nil, pipelineId, cacheService, pb.Status_STATUS_COMPILING)
}
logger.Infof("%s: Validate() finish\n", pipelineId)

// compile
logger.Infof("%s: Compile() ...\n", pipelineId)
Expand All @@ -250,7 +248,6 @@ func processCode(ctx context.Context, cacheService cache.Cache, lc *fs_tool.Life
logger.Infof("%s: Run() ...\n", pipelineId)
runCmd := exec.Run()
if data, err := runCmd.CombinedOutput(); err != nil {
// error during run code
processError(ctx, err, data, pipelineId, cacheService, pb.Status_STATUS_ERROR)
return
} else {
Expand All @@ -271,14 +268,11 @@ func cleanUp(pipelineId uuid.UUID, lc *fs_tool.LifeCycle) {
// 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:
logger.Errorf("%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))
case pb.Status_STATUS_VALIDATION_ERROR:
logger.Errorf("%s: Validate: %s\n", pipelineId, err.Error())

// set to cache pipelineId: cache.SubKey_Status: pb.Status_STATUS_ERROR
setToCache(ctx, cacheService, pipelineId, cache.Status, pb.Status_STATUS_ERROR)
// set to cache pipelineId: cache.SubKey_Status: pb.Status_STATUS_VALIDATION_ERROR
setToCache(ctx, cacheService, pipelineId, cache.Status, pb.Status_STATUS_VALIDATION_ERROR)
case pb.Status_STATUS_COMPILE_ERROR:
logger.Errorf("%s: Compile: err: %s, output: %s\n", pipelineId, err.Error(), data)

Expand All @@ -287,12 +281,25 @@ func processError(ctx context.Context, err error, data []byte, pipelineId uuid.U

// set to cache pipelineId: cache.SubKey_Status: pb.Status_STATUS_ERROR
setToCache(ctx, cacheService, pipelineId, cache.Status, pb.Status_STATUS_COMPILE_ERROR)
case pb.Status_STATUS_ERROR:
logger.Errorf("%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)
}
}

// 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, status pb.Status) {
switch status {
case pb.Status_STATUS_COMPILING:
logger.Infof("%s: Validate() finish\n", pipelineId)

// set to cache pipelineId: cache.SubKey_Status: pb.Status_STATUS_EXECUTING
setToCache(ctx, cacheService, pipelineId, cache.Status, pb.Status_STATUS_COMPILING)
case pb.Status_STATUS_EXECUTING:
logger.Infof("%s: Compile() finish\n", pipelineId)

Expand Down
8 changes: 4 additions & 4 deletions playground/backend/cmd/server/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ func TestPlaygroundController_RunCode(t *testing.T) {
},
{
// Test case with calling RunCode method with correct SDK.
// As a result want to receive response with pipelineId and status into cache should be set as Status_STATUS_EXECUTING.
// As a result want to receive response with pipelineId and status into cache should be set as Status_STATUS_COMPILING.
name: "RunCode with correct sdk",
args: args{
ctx: context.Background(),
Expand All @@ -148,7 +148,7 @@ func TestPlaygroundController_RunCode(t *testing.T) {
Sdk: pb.Sdk_SDK_JAVA,
},
},
wantStatus: pb.Status_STATUS_EXECUTING,
wantStatus: pb.Status_STATUS_COMPILING,
wantErr: false,
},
}
Expand Down Expand Up @@ -425,11 +425,11 @@ func Test_processCode(t *testing.T) {
}{
{
// Test case with calling processCode method without preparing files with code.
// As a result status into cache should be set as Status_STATUS_ERROR.
// As a result status into cache should be set as Status_STATUS_VALIDATION_ERROR.
name: "validation failed",
createExecFile: false,
code: "",
expectedStatus: pb.Status_STATUS_ERROR,
expectedStatus: pb.Status_STATUS_VALIDATION_ERROR,
expectedCompileOutput: nil,
expectedRunOutput: nil,
args: args{
Expand Down
111 changes: 62 additions & 49 deletions playground/backend/internal/api/v1/api.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 59bd9a0

Please sign in to comment.