This is an automated email from the ASF dual-hosted git repository.

pabloem pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/beam.git


The following commit(s) were added to refs/heads/master by this push:
     new b94d6b3  Merge pull request #16183 from [BEAM-13427] [Playground]  
show logs for precompiled objects
b94d6b3 is described below

commit b94d6b3e17e8d3c02e6d3a430785775f62db3a2f
Author: Aydar Farrakhov <[email protected]>
AuthorDate: Thu Jan 6 20:25:29 2022 +0300

    Merge pull request #16183 from [BEAM-13427] [Playground]  show logs for 
precompiled objects
    
    * [BEAM-13411][Playground]
    Add method to get logs of precompiledObjects
    
    * [BEAM-13427] show logs for precompiled objects
    
    * [BEAM-13427] add support for dots in pipeline optons
    
    * [BEAM-13427]: revert go file
    
    * [BEAM-13427]: fix build
    
    * [BEAM-13427] playground refactoring
    
    * [BEAM-13427] playground print logs errors
    
    Co-authored-by: AydarZaynutdinov <[email protected]>
---
 .../modules/editor/parsers/run_options_parser.dart | 24 +++++++++++++-------
 .../lib/modules/examples/models/example_model.dart |  6 +++++
 .../example_client/example_client.dart             |  2 ++
 .../example_client/grpc_example_client.dart        | 26 +++++++++++++++++++++-
 .../examples/repositories/example_repository.dart  |  7 ++++++
 .../pages/playground/states/examples_state.dart    | 24 +++++++++++++-------
 .../pages/playground/states/playground_state.dart  |  3 ++-
 .../editor/parsers/run_options_parser_test.dart    |  4 ++++
 8 files changed, 78 insertions(+), 18 deletions(-)

diff --git 
a/playground/frontend/lib/modules/editor/parsers/run_options_parser.dart 
b/playground/frontend/lib/modules/editor/parsers/run_options_parser.dart
index dc9cbb1..e508a40 100644
--- a/playground/frontend/lib/modules/editor/parsers/run_options_parser.dart
+++ b/playground/frontend/lib/modules/editor/parsers/run_options_parser.dart
@@ -16,7 +16,8 @@
  * limitations under the License.
  */
 
-RegExp regExp = RegExp(r'\-\-([A-z0-9]*)\s*([A-z0-9]*)\s*');
+RegExp pipelineOptionsRegExp =
+    RegExp(r'''--([A-z0-9]*)\s+([A-z0-9\/\"\'\*\-\:\;\.]*)''');
 
 const keyValueGroupCount = 2;
 
@@ -30,16 +31,15 @@ Map<String, String>? parsePipelineOptions(String 
pipelineOptions) {
   if (pipelineOptions.isEmpty) {
     return result;
   }
-  final matches = regExp.allMatches(pipelineOptions);
+  final matches = pipelineOptionsRegExp.allMatches(pipelineOptions);
   if (matches.isEmpty) {
     return null;
   }
-  final hasError = matches
-      .where((match) =>
-          match.groupCount != keyValueGroupCount ||
-          getGroupValue(match, 1).isEmpty ||
-          getGroupValue(match, 2).isEmpty)
-      .isNotEmpty;
+  final hasError = matches.where((match) {
+    return match.groupCount != keyValueGroupCount ||
+        getGroupValue(match, 1).isEmpty ||
+        getGroupValue(match, 2).isEmpty;
+  }).isNotEmpty;
   if (hasError) {
     return null;
   }
@@ -48,6 +48,14 @@ Map<String, String>? parsePipelineOptions(String 
pipelineOptions) {
     final value = getGroupValue(match, 2);
     result[key] = value;
   }
+  var optionsCopy = pipelineOptions;
+  for (var element in result.entries) {
+    optionsCopy = optionsCopy.replaceAll('--${element.key}', '');
+    optionsCopy = optionsCopy.replaceAll(element.value, '');
+  }
+  if (optionsCopy.trim().isNotEmpty) {
+    return null;
+  }
   return result;
 }
 
diff --git a/playground/frontend/lib/modules/examples/models/example_model.dart 
b/playground/frontend/lib/modules/examples/models/example_model.dart
index d24c334..264b828 100644
--- a/playground/frontend/lib/modules/examples/models/example_model.dart
+++ b/playground/frontend/lib/modules/examples/models/example_model.dart
@@ -45,6 +45,7 @@ class ExampleModel with Comparable<ExampleModel> {
   final String description;
   String? source;
   String? outputs;
+  String? logs;
   String? pipelineOptions;
 
   ExampleModel({
@@ -54,6 +55,7 @@ class ExampleModel with Comparable<ExampleModel> {
     required this.type,
     this.source,
     this.outputs,
+    this.logs,
     this.pipelineOptions,
   });
 
@@ -65,6 +67,10 @@ class ExampleModel with Comparable<ExampleModel> {
     this.outputs = outputs;
   }
 
+  setLogs(String logs) {
+    this.logs = logs;
+  }
+
   bool isInfoFetched() {
     // checking only source, because outputs/logs can be empty
     return source?.isNotEmpty ?? false;
diff --git 
a/playground/frontend/lib/modules/examples/repositories/example_client/example_client.dart
 
b/playground/frontend/lib/modules/examples/repositories/example_client/example_client.dart
index 077024f..c034efb 100644
--- 
a/playground/frontend/lib/modules/examples/repositories/example_client/example_client.dart
+++ 
b/playground/frontend/lib/modules/examples/repositories/example_client/example_client.dart
@@ -30,4 +30,6 @@ abstract class ExampleClient {
   Future<GetExampleResponse> getExample(GetExampleRequestWrapper request);
 
   Future<OutputResponse> getExampleOutput(GetExampleRequestWrapper request);
+
+  Future<OutputResponse> getExampleLogs(GetExampleRequestWrapper request);
 }
diff --git 
a/playground/frontend/lib/modules/examples/repositories/example_client/grpc_example_client.dart
 
b/playground/frontend/lib/modules/examples/repositories/example_client/grpc_example_client.dart
index 5f01aa1..149a467 100644
--- 
a/playground/frontend/lib/modules/examples/repositories/example_client/grpc_example_client.dart
+++ 
b/playground/frontend/lib/modules/examples/repositories/example_client/grpc_example_client.dart
@@ -72,7 +72,25 @@ class GrpcExampleClient implements ExampleClient {
           .getPrecompiledObjectOutput(
               _getExampleOutputRequestToGrpcRequest(request))
           .then((response) =>
-              OutputResponse(replaceIncorrectSymbols(response.output))),
+              OutputResponse(replaceIncorrectSymbols(response.output)))
+          .catchError((err) {
+        print(err);
+        OutputResponse('');
+      }),
+    );
+  }
+
+  @override
+  Future<OutputResponse> getExampleLogs(GetExampleRequestWrapper request) {
+    return _runSafely(
+      () => _defaultClient
+          
.getPrecompiledObjectLogs(_getExampleLogRequestToGrpcRequest(request))
+          .then((response) =>
+              OutputResponse(replaceIncorrectSymbols(response.output)))
+          .catchError((err) {
+        print(err);
+        OutputResponse('');
+      }),
     );
   }
 
@@ -106,6 +124,12 @@ class GrpcExampleClient implements ExampleClient {
     return grpc.GetPrecompiledObjectOutputRequest()..cloudPath = request.path;
   }
 
+  grpc.GetPrecompiledObjectLogsRequest _getExampleLogRequestToGrpcRequest(
+    GetExampleRequestWrapper request,
+  ) {
+    return grpc.GetPrecompiledObjectLogsRequest()..cloudPath = request.path;
+  }
+
   grpc.Sdk _getGrpcSdk(SDK sdk) {
     switch (sdk) {
       case SDK.java:
diff --git 
a/playground/frontend/lib/modules/examples/repositories/example_repository.dart 
b/playground/frontend/lib/modules/examples/repositories/example_repository.dart
index fb003e5..04ad462 100644
--- 
a/playground/frontend/lib/modules/examples/repositories/example_repository.dart
+++ 
b/playground/frontend/lib/modules/examples/repositories/example_repository.dart
@@ -47,4 +47,11 @@ class ExampleRepository {
     final result = await _client.getExampleOutput(request);
     return result.output;
   }
+
+  Future<String> getExampleLogs(
+    GetExampleRequestWrapper request,
+  ) async {
+    final result = await _client.getExampleLogs(request);
+    return result.output;
+  }
 }
diff --git 
a/playground/frontend/lib/pages/playground/states/examples_state.dart 
b/playground/frontend/lib/pages/playground/states/examples_state.dart
index acc9cfe..8ef687d 100644
--- a/playground/frontend/lib/pages/playground/states/examples_state.dart
+++ b/playground/frontend/lib/pages/playground/states/examples_state.dart
@@ -41,27 +41,35 @@ class ExampleState with ChangeNotifier {
   }
 
   Future<String> getExampleOutput(String id, SDK sdk) async {
-    String output = await _exampleRepository.getExampleOutput(
+    return await _exampleRepository.getExampleOutput(
       GetExampleRequestWrapper(id, sdk),
     );
-    return output;
   }
 
   Future<String> getExampleSource(String id, SDK sdk) async {
-    String source = await _exampleRepository.getExampleSource(
+    return await _exampleRepository.getExampleSource(
+      GetExampleRequestWrapper(id, sdk),
+    );
+  }
+
+  Future<String> getExampleLogs(String id, SDK sdk) async {
+    return await _exampleRepository.getExampleLogs(
       GetExampleRequestWrapper(id, sdk),
     );
-    return source;
   }
 
   Future<ExampleModel> loadExampleInfo(ExampleModel example, SDK sdk) async {
     if (example.isInfoFetched()) {
       return example;
     }
-    String source = await getExampleSource(example.path, sdk);
-    example.setSource(source);
-    final outputs = await getExampleOutput(example.path, sdk);
-    example.setOutputs(outputs);
+    final exampleData = await Future.wait([
+      getExampleSource(example.path, sdk),
+      getExampleOutput(example.path, sdk),
+      getExampleLogs(example.path, sdk)
+    ]);
+    example.setSource(exampleData[0]);
+    example.setOutputs(exampleData[1]);
+    example.setLogs(exampleData[2]);
     return example;
   }
 
diff --git 
a/playground/frontend/lib/pages/playground/states/playground_state.dart 
b/playground/frontend/lib/pages/playground/states/playground_state.dart
index 6308958..6a81403 100644
--- a/playground/frontend/lib/pages/playground/states/playground_state.dart
+++ b/playground/frontend/lib/pages/playground/states/playground_state.dart
@@ -30,7 +30,7 @@ const kTitleLength = 15;
 const kPrecompiledDelay = Duration(seconds: 1);
 const kTitle = 'Catalog';
 const kPipelineOptionsParseError =
-    'Failed to parse pipeline options, please check the format (--key1 value1 
--key2 value2)';
+    'Failed to parse pipeline options, please check the format (example: 
--key1 value1 --key2 value2), only alphanumeric and ",*,/,-,:,;,\',. symbols 
are allowed';
 
 class PlaygroundState with ChangeNotifier {
   late SDK _sdk;
@@ -155,6 +155,7 @@ class PlaygroundState with ChangeNotifier {
     _result = RunCodeResult(
       status: RunCodeStatus.finished,
       output: _selectedExample!.outputs,
+      log: _selectedExample!.logs,
     );
     notifyListeners();
   }
diff --git 
a/playground/frontend/test/modules/editor/parsers/run_options_parser_test.dart 
b/playground/frontend/test/modules/editor/parsers/run_options_parser_test.dart
index 3ef276a..26657af 100644
--- 
a/playground/frontend/test/modules/editor/parsers/run_options_parser_test.dart
+++ 
b/playground/frontend/test/modules/editor/parsers/run_options_parser_test.dart
@@ -39,6 +39,10 @@ void main() {
         parsePipelineOptions('--key1    value1     --key2     value2'),
         {'key1': 'value1', 'key2': 'value2'},
       );
+      expect(
+        parsePipelineOptions('--output1 ./dir --output2 "value"'),
+        {'output1': './dir', 'output2': '"value"'},
+      );
     });
   });
   group('PipelineOptions to string', () {

Reply via email to