Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
509b7ff
Implement method to get a default example for each SDKs
pavel-avilov Jan 12, 2022
e9cbe79
Add error handling
pavel-avilov Jan 12, 2022
68edd97
Added saving of precompiled objects catalog to cache at the server st…
Jan 12, 2022
ab16bea
Added caching of the catalog only in case of unspecified SDK
Jan 12, 2022
d181cce
Update regarding comments
Jan 13, 2022
5743386
Update regarding comments
Jan 13, 2022
38673a4
Simplified logging regarding comment
Jan 14, 2022
4071bdb
Get defaultExamplePath from the corresponding config
pavel-avilov Jan 14, 2022
3047469
Refactoring code
pavel-avilov Jan 14, 2022
d6e5d0b
Add the `link` field to response
pavel-avilov Jan 18, 2022
f80ebdd
Merge branch 'master' into BEAM-13633_default_ex_for_sdks
pavel-avilov Jan 19, 2022
e035006
Remove gjson;
pavel-avilov Jan 19, 2022
c3c5c79
Refactoring code
pavel-avilov Jan 19, 2022
931b79e
Merge remote-tracking branch 'origin/BEAM-13632-cache-examples-data' …
pavel-avilov Jan 20, 2022
29e6f61
Getting default precompiled object from cache
pavel-avilov Jan 21, 2022
5688841
Refactoring code
pavel-avilov Jan 21, 2022
43fc19b
Added saving of precompiled objects catalog to cache at the server st…
Jan 12, 2022
27b0157
Added caching of the catalog only in case of unspecified SDK
Jan 12, 2022
b9b77b9
Update regarding comments
Jan 13, 2022
2187918
Update regarding comments
Jan 13, 2022
3655716
Simplified logging regarding comment
Jan 14, 2022
7fe3d8b
Updates regarding comments
Jan 24, 2022
6830670
Update for environment_service_test.go
Jan 24, 2022
af655a5
Merge remote-tracking branch 'origin/BEAM-13632-cache-examples-data' …
pavel-avilov Jan 24, 2022
b95103c
Get default example from catalog
pavel-avilov Jan 24, 2022
f4ae9a7
GetCatalogFromCacheOrStorage method
pavel-avilov Jan 25, 2022
276ddd1
Merge branch 'master' into BEAM-13633_default_ex_for_sdks
pavel-avilov Jan 25, 2022
94a1613
Merge branch 'master' into BEAM-13633_default_ex_for_sdks
pavel-avilov Jan 26, 2022
1550e3a
Update licenses
pavel-avilov Jan 26, 2022
8e6e1e5
Merge branch 'master' into BEAM-13633_default_ex_for_sdks
pavel-avilov Feb 1, 2022
af3623c
Update licenses;
pavel-avilov Feb 1, 2022
a7d6ded
Merge branch 'master' into BEAM-13633_default_ex_for_sdks
Feb 7, 2022
3c8bd03
[BEAM-13633][Playground]
Feb 7, 2022
f273192
[BEAM-13633][Playground]
Feb 7, 2022
ebf5888
[BEAM-13633][Playground]
Feb 8, 2022
29c28b5
Merge branch 'master' into BEAM-13633_default_ex_for_sdks
Feb 8, 2022
e413153
[BEAM-13633][Playground]
Feb 8, 2022
da6baa0
Add code of the default example to response
pavel-avilov Feb 9, 2022
1ea1026
Revert "Add code of the default example to response"
pavel-avilov Feb 9, 2022
d8b7bdb
Refactoring code
pavel-avilov Feb 9, 2022
c189363
Refactoring code;
Feb 10, 2022
6e63cfb
Edit commentaries
pavel-avilov Feb 10, 2022
0bcb1c4
Refactoring code
pavel-avilov Feb 10, 2022
66a3ca5
Merge remote-tracking branch 'origin/master' into BEAM-13633_default_…
pavel-avilov Mar 1, 2022
52622a3
Merge branch 'master' into BEAM-13633_default_ex_for_sdks
pavel-avilov Mar 1, 2022
4f54530
Add bucket name to methods
pavel-avilov Mar 1, 2022
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
1 change: 1 addition & 0 deletions playground/api/v1/api.proto
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ message PrecompiledObject{
string link = 6;
bool multifile = 7;
int32 context_line = 8;
bool default_example = 9;
}

// Categories represent the array of messages with sdk and categories at this sdk
Expand Down
30 changes: 20 additions & 10 deletions playground/backend/cmd/server/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -260,16 +260,10 @@ func (controller *playgroundController) Cancel(ctx context.Context, info *pb.Can
// - If there is no catalog in the cache, gets the catalog from the Storage and saves it to the cache
// - If SDK or category is specified in the request, gets the catalog from the cache and filters it by SDK and category
func (controller *playgroundController) GetPrecompiledObjects(ctx context.Context, info *pb.GetPrecompiledObjectsRequest) (*pb.GetPrecompiledObjectsResponse, error) {
catalog, err := controller.cacheService.GetCatalog(ctx)
catalog, err := utils.GetCatalogFromCacheOrStorage(ctx, controller.cacheService, controller.env.ApplicationEnvs.BucketName())
if err != nil {
logger.Errorf("GetPrecompiledObjects(): cache error: %s", err.Error())
catalog, err = utils.GetCatalogFromStorage(ctx, controller.env.ApplicationEnvs.BucketName())
if err != nil {
return nil, errors.InternalError("Error during getting Precompiled Objects", "Error with cloud connection")
}
if err = controller.cacheService.SetCatalog(ctx, catalog); err != nil {
logger.Errorf("GetPrecompiledObjects(): cache error: %s", err.Error())
}
logger.Errorf("GetPrecompiledObjects(): error during getting catalog: %s", err.Error())
return nil, errors.InternalError("Error during getting Precompiled Objects", "Error with cloud connection")
}
return &pb.GetPrecompiledObjectsResponse{
SdkCategories: utils.FilterCatalog(catalog, info.Sdk, info.Category),
Expand All @@ -279,7 +273,7 @@ func (controller *playgroundController) GetPrecompiledObjects(ctx context.Contex
// GetPrecompiledObjectCode returns the code of the specific example
func (controller *playgroundController) GetPrecompiledObjectCode(ctx context.Context, info *pb.GetPrecompiledObjectCodeRequest) (*pb.GetPrecompiledObjectCodeResponse, error) {
cd := cloud_bucket.New()
codeString, err := cd.GetPrecompiledObject(ctx, info.GetCloudPath(), controller.env.ApplicationEnvs.BucketName())
codeString, err := cd.GetPrecompiledObjectCode(ctx, info.GetCloudPath(), controller.env.ApplicationEnvs.BucketName())
if err != nil {
logger.Errorf("GetPrecompiledObjectCode(): cloud storage error: %s", err.Error())
return nil, errors.InternalError("Error during getting Precompiled Object's code", "Error with cloud connection")
Expand Down Expand Up @@ -323,3 +317,19 @@ func (controller *playgroundController) GetPrecompiledObjectGraph(ctx context.Co
response := pb.GetPrecompiledObjectGraphResponse{Graph: logs}
return &response, nil
}

// GetDefaultPrecompiledObject returns the default precompile object for sdk.
func (controller *playgroundController) GetDefaultPrecompiledObject(ctx context.Context, info *pb.GetDefaultPrecompiledObjectRequest) (*pb.GetDefaultPrecompiledObjectResponse, error) {
switch info.Sdk {
case pb.Sdk_SDK_UNSPECIFIED:
logger.Errorf("GetDefaultPrecompiledObject(): unimplemented sdk: %s\n", info.Sdk)
return nil, errors.InvalidArgumentError("Error during preparing", "Sdk is not implemented yet: %s", info.Sdk.String())
}
precompiledObject, err := utils.GetDefaultPrecompiledObject(ctx, info.Sdk, controller.cacheService, controller.env.ApplicationEnvs.BucketName())
if err != nil {
logger.Errorf("GetDefaultPrecompiledObject(): error during getting catalog: %s", err.Error())
return nil, errors.InternalError("Error during getting Precompiled Objects", "Error with cloud connection")
}
response := pb.GetDefaultPrecompiledObjectResponse{PrecompiledObject: precompiledObject}
return &response, nil
}
13 changes: 13 additions & 0 deletions playground/backend/cmd/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"beam.apache.org/playground/backend/internal/cache"
"beam.apache.org/playground/backend/internal/cache/local"
"beam.apache.org/playground/backend/internal/cache/redis"
"beam.apache.org/playground/backend/internal/cloud_bucket"
"beam.apache.org/playground/backend/internal/environment"
"beam.apache.org/playground/backend/internal/logger"
"beam.apache.org/playground/backend/internal/utils"
Expand Down Expand Up @@ -127,6 +128,18 @@ func setupExamplesCatalog(ctx context.Context, cacheService cache.Cache, bucketN
if err = cacheService.SetCatalog(ctx, catalog); err != nil {
logger.Errorf("GetPrecompiledObjects(): cache error: %s", err.Error())
}

bucket := cloud_bucket.New()
defaultPrecompiledObjects, err := bucket.GetDefaultPrecompiledObjects(ctx, bucketName)
if err != nil {
return err
}
for sdk, precompiledObject := range defaultPrecompiledObjects {
if err := cacheService.SetDefaultPrecompiledObject(ctx, sdk, precompiledObject); err != nil {
logger.Errorf("GetPrecompiledObjects(): cache error: %s", err.Error())
return err
}
}
return nil
}

Expand Down
Loading