Skip to content

Commit

Permalink
Add code of the default example to response
Browse files Browse the repository at this point in the history
  • Loading branch information
pavel-avilov committed Feb 9, 2022
1 parent e413153 commit da6baa0
Show file tree
Hide file tree
Showing 14 changed files with 655 additions and 484 deletions.
20 changes: 13 additions & 7 deletions playground/api/v1/api.proto
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,12 @@ message PrecompiledObject{
bool default_example = 9;
}

// DefaultExample represents the default PrecompiledObject and his code
message DefaultExample{
PrecompiledObject precompiled_object = 1;
string code = 2;
}

// Categories represent the array of messages with sdk and categories at this sdk
message Categories{
message Category{
Expand Down Expand Up @@ -204,8 +210,8 @@ message GetPrecompiledObjectGraphRequest{
string cloud_path = 1;
}

// GetDefaultPrecompiledObjectRequest contains information of the needed PrecompiledObject sdk.
message GetDefaultPrecompiledObjectRequest {
// GetDefaultExampleRequest contains information of the needed PrecompiledObject sdk.
message GetDefaultExampleRequest {
Sdk sdk = 1;
}

Expand Down Expand Up @@ -234,9 +240,9 @@ message GetPrecompiledObjectGraphResponse {
string graph = 1;
}

// GetDefaultPrecompiledObjectResponse represents the default PrecompiledObject and his category for the sdk.
message GetDefaultPrecompiledObjectResponse {
PrecompiledObject precompiled_object = 1;
// GetDefaultExampleResponse represents the default PrecompiledObject and his code for the sdk.
message GetDefaultExampleResponse {
DefaultExample default_example = 1;
}

service PlaygroundService {
Expand Down Expand Up @@ -286,6 +292,6 @@ service PlaygroundService {
// Get the graph of an PrecompiledObject.
rpc GetPrecompiledObjectGraph(GetPrecompiledObjectGraphRequest) returns (GetPrecompiledObjectGraphResponse);

// Get the default precompile object for the sdk.
rpc GetDefaultPrecompiledObject(GetDefaultPrecompiledObjectRequest) returns (GetDefaultPrecompiledObjectResponse);
// Get the default example for the sdk.
rpc GetDefaultExample(GetDefaultExampleRequest) returns (GetDefaultExampleResponse);
}
22 changes: 7 additions & 15 deletions playground/backend/cmd/server/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -318,26 +318,18 @@ func (controller *playgroundController) GetPrecompiledObjectGraph(ctx context.Co
return &response, nil
}

// GetDefaultPrecompiledObject returns the default precompile object for sdk.
func (controller *playgroundController) GetDefaultPrecompiledObject(ctx context.Context, info *pb.GetDefaultPrecompiledObjectRequest) (*pb.GetDefaultPrecompiledObjectResponse, error) {
// GetDefaultExample returns the default precompile object for sdk.
func (controller *playgroundController) GetDefaultExample(ctx context.Context, info *pb.GetDefaultExampleRequest) (*pb.GetDefaultExampleResponse, error) {
switch info.Sdk {
case pb.Sdk_SDK_UNSPECIFIED:
logger.Errorf("GetDefaultPrecompiledObject(): unimplemented sdk: %s\n", info.Sdk)
logger.Errorf("GetDefaultExample(): 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)
defaultExample, err := utils.GetDefaultExample(ctx, info.Sdk, controller.cacheService)
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")
logger.Errorf("GetDefaultExample(): error during getting default example: %s", err.Error())
return nil, errors.InternalError("Error during getting Default Examples", "Error with cloud connection")
}
response := pb.GetDefaultPrecompiledObjectResponse{PrecompiledObject: &pb.PrecompiledObject{
CloudPath: precompiledObject.CloudPath,
Name: precompiledObject.Name,
Description: precompiledObject.Description,
Type: precompiledObject.Type,
PipelineOptions: precompiledObject.PipelineOptions,
Link: precompiledObject.Link,
DefaultExample: precompiledObject.DefaultExample,
}}
response := pb.GetDefaultExampleResponse{DefaultExample: defaultExample}
return &response, nil
}
8 changes: 4 additions & 4 deletions playground/backend/cmd/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ func setupCache(ctx context.Context, appEnv environment.ApplicationEnvs) (cache.
}
}

// setupExamplesCatalog saves precompiled objects catalog from storage to cache
// setupExamplesCatalog saves precompiled objects catalog and default example from storage to cache
func setupExamplesCatalog(ctx context.Context, cacheService cache.Cache) error {
catalog, err := utils.GetCatalogFromStorage(ctx)
if err != nil {
Expand All @@ -130,12 +130,12 @@ func setupExamplesCatalog(ctx context.Context, cacheService cache.Cache) error {
}

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

0 comments on commit da6baa0

Please sign in to comment.