pavel-avilov commented on a change in pull request #16484:
URL: https://github.com/apache/beam/pull/16484#discussion_r791811526



##########
File path: playground/backend/cmd/server/controller.go
##########
@@ -294,3 +299,29 @@ func (controller *playgroundController) 
GetPrecompiledObjectLogs(ctx context.Con
        response := pb.GetPrecompiledObjectLogsResponse{Output: 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, pb.Sdk_SDK_SCIO:

Review comment:
       Done.

##########
File path: playground/backend/internal/utils/precompiled_objects_utils.go
##########
@@ -34,7 +43,61 @@ func PutPrecompiledObjectsToCategory(categoryName string, 
precompiledObjects *cl
                        Type:            object.Type,
                        PipelineOptions: object.PipelineOptions,
                        Link:            object.Link,
+                       DefaultExample:  object.DefaultExample,
                })
        }
        sdkCategory.Categories = append(sdkCategory.Categories, &category)
 }
+
+// GetPrecompiledObjectsCatalogFromCache returns the precompiled objects 
catalog from the cache
+func GetPrecompiledObjectsCatalogFromCache(ctx context.Context, cacheService 
cache.Cache) ([]*pb.Categories, error) {

Review comment:
       Done

##########
File path: playground/backend/internal/utils/precompiled_objects_utils.go
##########
@@ -34,7 +43,61 @@ func PutPrecompiledObjectsToCategory(categoryName string, 
precompiledObjects *cl
                        Type:            object.Type,
                        PipelineOptions: object.PipelineOptions,
                        Link:            object.Link,
+                       DefaultExample:  object.DefaultExample,
                })
        }
        sdkCategory.Categories = append(sdkCategory.Categories, &category)
 }
+
+// GetPrecompiledObjectsCatalogFromCache returns the precompiled objects 
catalog from the cache
+func GetPrecompiledObjectsCatalogFromCache(ctx context.Context, cacheService 
cache.Cache) ([]*pb.Categories, error) {
+       value, err := cacheService.GetValue(ctx, ExamplesDataPipelineId, 
cache.ExamplesCatalog)
+       if err != nil {
+               logger.Errorf("%s: cache.GetValue: %s\n", 
ExamplesDataPipelineId, err.Error())
+               return nil, err
+       }
+       catalog, converted := value.([]*pb.Categories)

Review comment:
       Done

##########
File path: playground/backend/internal/utils/precompiled_objects_utils.go
##########
@@ -34,7 +43,61 @@ func PutPrecompiledObjectsToCategory(categoryName string, 
precompiledObjects *cl
                        Type:            object.Type,
                        PipelineOptions: object.PipelineOptions,
                        Link:            object.Link,
+                       DefaultExample:  object.DefaultExample,
                })
        }
        sdkCategory.Categories = append(sdkCategory.Categories, &category)
 }
+
+// GetPrecompiledObjectsCatalogFromCache returns the precompiled objects 
catalog from the cache
+func GetPrecompiledObjectsCatalogFromCache(ctx context.Context, cacheService 
cache.Cache) ([]*pb.Categories, error) {
+       value, err := cacheService.GetValue(ctx, ExamplesDataPipelineId, 
cache.ExamplesCatalog)
+       if err != nil {
+               logger.Errorf("%s: cache.GetValue: %s\n", 
ExamplesDataPipelineId, err.Error())
+               return nil, err
+       }
+       catalog, converted := value.([]*pb.Categories)

Review comment:
       Yes of course

##########
File path: playground/backend/internal/utils/precompiled_objects_utils.go
##########
@@ -34,7 +43,61 @@ func PutPrecompiledObjectsToCategory(categoryName string, 
precompiledObjects *cl
                        Type:            object.Type,
                        PipelineOptions: object.PipelineOptions,
                        Link:            object.Link,
+                       DefaultExample:  object.DefaultExample,
                })
        }
        sdkCategory.Categories = append(sdkCategory.Categories, &category)
 }
+
+// GetPrecompiledObjectsCatalogFromCache returns the precompiled objects 
catalog from the cache
+func GetPrecompiledObjectsCatalogFromCache(ctx context.Context, cacheService 
cache.Cache) ([]*pb.Categories, error) {
+       value, err := cacheService.GetValue(ctx, ExamplesDataPipelineId, 
cache.ExamplesCatalog)
+       if err != nil {
+               logger.Errorf("%s: cache.GetValue: %s\n", 
ExamplesDataPipelineId, err.Error())
+               return nil, err
+       }
+       catalog, converted := value.([]*pb.Categories)
+       if !converted {
+               logger.Errorf("%s: couldn't convert value to catalog: %s", 
cache.ExamplesCatalog, value)
+               return nil, errors.InternalError("Error during getting the 
catalog from cache", "Error during getting catalog")
+       }
+       return catalog, nil
+}
+
+// GetPrecompiledObjectsCatalogFromStorage returns the precompiled objects 
catalog from the cloud storage
+func GetPrecompiledObjectsCatalogFromStorage(ctx context.Context, sdk pb.Sdk, 
category string) ([]*pb.Categories, error) {

Review comment:
       This goes from [[BEAM-13632]](https://github.com/apache/beam/pull/16493)

##########
File path: playground/backend/cmd/server/controller.go
##########
@@ -294,3 +293,35 @@ func (controller *playgroundController) 
GetPrecompiledObjectLogs(ctx context.Con
        response := pb.GetPrecompiledObjectLogsResponse{Output: 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, pb.Sdk_SDK_SCIO:
+               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())
+       }
+       catalog, err := controller.cacheService.GetCatalog(ctx)
+       if err != nil {
+               logger.Errorf("GetDefaultPrecompiledObject(): cache error: %s", 
err.Error())
+               catalog, err = utils.GetCatalogFromStorage(ctx)
+               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("GetDefaultPrecompiledObject(): cache 
error: %s", err.Error())
+               }
+       }

Review comment:
       Done.

##########
File path: playground/backend/cmd/server/server.go
##########
@@ -109,6 +118,18 @@ func setupCache(ctx context.Context, appEnv 
environment.ApplicationEnvs) (cache.
        }
 }
 
+// setupExamplesCatalog saves precompiled objects catalog from storage to cache
+func setupExamplesCatalog(ctx context.Context, cacheService cache.Cache) error 
{

Review comment:
       This goes from [[BEAM-13632]](https://github.com/apache/beam/pull/16493)

##########
File path: playground/backend/internal/utils/precompiled_objects_utils.go
##########
@@ -34,7 +36,75 @@ func PutPrecompiledObjectsToCategory(categoryName string, 
precompiledObjects *cl
                        Type:            object.Type,
                        PipelineOptions: object.PipelineOptions,
                        Link:            object.Link,
+                       DefaultExample:  object.DefaultExample,
                })
        }
        sdkCategory.Categories = append(sdkCategory.Categories, &category)
 }
+
+// GetCatalogFromStorage returns the precompiled objects catalog from the 
cloud storage
+func GetCatalogFromStorage(ctx context.Context) ([]*pb.Categories, error) {

Review comment:
       This goes from [[BEAM-13632]](https://github.com/apache/beam/pull/16493)




-- 
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]


Reply via email to