Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
b73f5f7
[Playground][BEAM-12941][Bugfix] Fix workflows for playground applica…
snkalinin Nov 16, 2021
d449275
Revert "[Playground][BEAM-12941][Bugfix] Fix workflows for playground…
ilya-kozyrev Nov 16, 2021
69d0191
Merge branch 'apache:master' into master
ilya-kozyrev Nov 16, 2021
1bf7f6f
Merge branch 'apache:master' into master
Nov 16, 2021
72bad55
Merge branch 'apache:master' into master
ilya-kozyrev Nov 16, 2021
1d6783e
Merge branch 'apache:master' into master
Nov 16, 2021
3a81f54
Merge branch 'apache:master' into master
ilya-kozyrev Nov 16, 2021
d9cce13
Merge branch 'apache:master' into master
Nov 17, 2021
c24b695
Merge branch 'apache:master' into master
Nov 19, 2021
10e7762
Merge branch 'apache:master' into master
Nov 19, 2021
24ef6bf
Merge branch 'apache:master' into master
pavel-avilov Nov 21, 2021
ab58327
Merge branch 'apache:master' into master
Nov 23, 2021
302cb1f
Merge branch 'apache:master' into master
ElessarST Nov 24, 2021
e28a7c3
[BEAM-13241] Added routing by sdk
miamihotline Nov 24, 2021
445b3d9
[BEAM-13241] Moved urls to config.g.dart, changed tests
miamihotline Nov 24, 2021
4d9caae
[BEAM-13241] Changed grpc_example_client route to backend JAVA route
miamihotline Nov 24, 2021
c61bbda
Merge branch 'apache:master' into master
Nov 25, 2021
97e7b56
[BEAM-13241] Fixed routing, added workaround channel
miamihotline Nov 25, 2021
d744d36
Merge branch 'apache:master' into master
Nov 29, 2021
e11978b
Merge branch 'master' into BEAM-13241-frontend-routing
ElessarST Nov 29, 2021
b025767
[BEAM-13241] fix linter issues
ElessarST Nov 29, 2021
ff80f8e
[BEAM-13241] add licences to mocks
ElessarST Nov 29, 2021
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
12 changes: 12 additions & 0 deletions playground/frontend/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ apply plugin: 'base'
applyDockerNature()

def playgroundBackendUrl = project.playgroundBackendUrl
def playgroundBackendJavaRouteUrl = project.playgroundBackendJavaRouteUrl
def playgroundBackendGoRouteUrl = project.playgroundBackendGoRouteUrl
def playgroundBackendPythonRouteUrl = project.playgroundBackendPythonRouteUrl
def playgroundBackendScioRouteUrl = project.playgroundBackendScioRouteUrl

def playgroundJobServerProject = "${project.path.replace('-container', '')}"

Expand Down Expand Up @@ -159,6 +163,14 @@ task("createConfig") {

const String kApiClientURL =
'${playgroundBackendUrl}';
const String kApiJavaClientURL =
'${playgroundBackendJavaRouteUrl}';
const String kApiGoClientURL =
'${playgroundBackendGoRouteUrl}';
const String kApiPythonClientURL =
'${playgroundBackendPythonRouteUrl}';
const String kApiScioClientURL =
'${playgroundBackendScioRouteUrl}';
""")
}
}
6 changes: 5 additions & 1 deletion playground/frontend/gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.
################################################################################
playgroundBackendUrl=https://backend-dot-datatokenization.uc.r.appspot.com
playgroundBackendUrl=https://backend-dot-datatokenization.uc.r.appspot.com
playgroundBackendJavaRouteUrl=https://backend-dot-datatokenization.uc.r.appspot.com/java/
playgroundBackendGoRouteUrl=https://backend-dot-datatokenization.uc.r.appspot.com/go/
playgroundBackendPythonRouteUrl=https://backend-dot-datatokenization.uc.r.appspot.com/python/
playgroundBackendScioRouteUrl=https://backend-dot-datatokenization.uc.r.appspot.com/scio/
47 changes: 47 additions & 0 deletions playground/frontend/lib/api/iis_workaround_channel.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import 'package:grpc/grpc_connection_interface.dart';
// ignore: implementation_imports
import 'package:grpc/src/client/transport/xhr_transport.dart';

class IisWorkaroundChannel extends ClientChannelBase {
final Uri uri;

IisWorkaroundChannel.xhr(this.uri) : super();

@override
ClientConnection createConnection() {
return IisClientConnection(uri);
}
}

class IisClientConnection extends XhrClientConnection {
IisClientConnection(Uri uri) : super(uri);

@override
GrpcTransportStream makeRequest(String path, Duration? timeout,
Map<String, String> metadata, ErrorHandler onError,
{CallOptions? callOptions}) {
print(path);
var pathWithoutFirstSlash = path.substring(1);
print(pathWithoutFirstSlash);
return super.makeRequest(pathWithoutFirstSlash, timeout, metadata, onError,
callOptions: callOptions);
}
}
8 changes: 8 additions & 0 deletions playground/frontend/lib/config.g.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,11 @@

const String kApiClientURL =
'https://backend-dot-datatokenization.uc.r.appspot.com';
const String kApiJavaClientURL =
'https://backend-dot-datatokenization.uc.r.appspot.com/java/';
const String kApiGoClientURL =
'https://backend-dot-datatokenization.uc.r.appspot.com/go/';
const String kApiPythonClientURL =
'https://backend-dot-datatokenization.uc.r.appspot.com/python/';
const String kApiScioClientURL =
'https://backend-dot-datatokenization.uc.r.appspot.com/scio/';
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,23 @@ import 'package:playground/modules/editor/repository/code_repository/run_code_re
abstract class CodeClient {
Future<RunCodeResponse> runCode(RunCodeRequestWrapper request);

Future<CheckStatusResponse> checkStatus(String pipelineUuid);
Future<CheckStatusResponse> checkStatus(
String pipelineUuid,
RunCodeRequestWrapper request,
);

Future<OutputResponse> getCompileOutput(String pipelineUuid);
Future<OutputResponse> getCompileOutput(
String pipelineUuid,
RunCodeRequestWrapper request,
);

Future<OutputResponse> getRunOutput(String pipelineUuid);
Future<OutputResponse> getRunOutput(
String pipelineUuid,
RunCodeRequestWrapper request,
);

Future<OutputResponse> getRunErrorOutput(String pipelineUuid);
Future<OutputResponse> getRunErrorOutput(
String pipelineUuid,
RunCodeRequestWrapper request,
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
*/

import 'package:grpc/grpc_web.dart';
import 'package:playground/api/iis_workaround_channel.dart';
import 'package:playground/api/v1/api.pbgrpc.dart' as grpc;
import 'package:playground/config.g.dart';
import 'package:playground/modules/editor/repository/code_repository/code_client/check_status_response.dart';
Expand All @@ -31,51 +32,64 @@ import 'package:playground/modules/sdk/models/sdk.dart';
const kGeneralError = 'Failed to execute code';

class GrpcCodeClient implements CodeClient {
late final GrpcWebClientChannel _channel;
late final grpc.PlaygroundServiceClient _client;

GrpcCodeClient() {
_channel = GrpcWebClientChannel.xhr(
Uri.parse(kApiClientURL),
grpc.PlaygroundServiceClient createClient(SDK? sdk) {
String apiClientURL = kApiClientURL;
if (sdk != null) {
apiClientURL = sdk.getRoute;
}
IisWorkaroundChannel channel = IisWorkaroundChannel.xhr(
Uri.parse(apiClientURL),
);
_client = grpc.PlaygroundServiceClient(_channel);
return grpc.PlaygroundServiceClient(channel);
}

@override
Future<RunCodeResponse> runCode(RunCodeRequestWrapper request) {
return _runSafely(() => _client
return _runSafely(() => createClient(request.sdk)
.runCode(_toGrpcRequest(request))
.then((response) => RunCodeResponse(response.pipelineUuid)));
}

@override
Future<CheckStatusResponse> checkStatus(String pipelineUuid) {
return _runSafely(() => _client
Future<CheckStatusResponse> checkStatus(
String pipelineUuid,
RunCodeRequestWrapper request,
) {
return _runSafely(() => createClient(request.sdk)
.checkStatus(grpc.CheckStatusRequest(pipelineUuid: pipelineUuid))
.then(
(response) => CheckStatusResponse(_toClientStatus(response.status)),
));
}

@override
Future<OutputResponse> getCompileOutput(String pipelineUuid) {
return _runSafely(() => _client
Future<OutputResponse> getCompileOutput(
String pipelineUuid,
RunCodeRequestWrapper request,
) {
return _runSafely(() => createClient(request.sdk)
.getCompileOutput(
grpc.GetCompileOutputRequest(pipelineUuid: pipelineUuid),
)
.then((response) => OutputResponse(response.output)));
}

@override
Future<OutputResponse> getRunOutput(String pipelineUuid) {
return _runSafely(() => _client
Future<OutputResponse> getRunOutput(
String pipelineUuid,
RunCodeRequestWrapper request,
) {
return _runSafely(() => createClient(request.sdk)
.getRunOutput(grpc.GetRunOutputRequest(pipelineUuid: pipelineUuid))
.then((response) => OutputResponse(response.output)));
}

@override
Future<OutputResponse> getRunErrorOutput(String pipelineUuid) {
return _runSafely(() => _client
Future<OutputResponse> getRunErrorOutput(
String pipelineUuid,
RunCodeRequestWrapper request,
) {
return _runSafely(() => createClient(request.sdk)
.getRunError(grpc.GetRunErrorRequest(pipelineUuid: pipelineUuid))
.then((response) => OutputResponse(response.output)));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class CodeRepository {
yield RunCodeResult(status: RunCodeStatus.preparation);
var runCodeResponse = await _client.runCode(request);
final pipelineUuid = runCodeResponse.pipelineUuid;
yield* _checkPipelineExecution(pipelineUuid);
yield* _checkPipelineExecution(pipelineUuid, request);
} on RunCodeError catch (error) {
yield RunCodeResult(
status: RunCodeStatus.unknownError,
Expand All @@ -48,47 +48,53 @@ class CodeRepository {
}

Stream<RunCodeResult> _checkPipelineExecution(
String pipelineUuid, {
String pipelineUuid,
RunCodeRequestWrapper request, {
RunCodeResult? prevResult,
}) async* {
final statusResponse = await _client.checkStatus(pipelineUuid);
final statusResponse = await _client.checkStatus(pipelineUuid, request);
final result = await _getPipelineResult(
pipelineUuid,
statusResponse.status,
prevResult,
request,
);
yield result;
if (!result.isFinished) {
await Future.delayed(kPipelineCheckDelay);
yield* _checkPipelineExecution(pipelineUuid, prevResult: result);
yield* _checkPipelineExecution(pipelineUuid, request, prevResult: result);
}
}

Future<RunCodeResult> _getPipelineResult(
String pipelineUuid,
RunCodeStatus status,
RunCodeResult? prevResult,
RunCodeRequestWrapper request,
) async {
final prevOutput = prevResult?.output ?? '';
switch (status) {
case RunCodeStatus.compileError:
final compileOutput = await _client.getCompileOutput(pipelineUuid);
final compileOutput = await _client.getCompileOutput(
pipelineUuid,
request,
);
return RunCodeResult(status: status, output: compileOutput.output);
case RunCodeStatus.timeout:
return RunCodeResult(status: status, errorMessage: kTimeoutErrorText);
case RunCodeStatus.runError:
final output = await _client.getRunErrorOutput(pipelineUuid);
final output = await _client.getRunErrorOutput(pipelineUuid, request);
return RunCodeResult(status: status, output: output.output);
case RunCodeStatus.unknownError:
return RunCodeResult(status: status, errorMessage: kUnknownErrorText);
case RunCodeStatus.executing:
final output = await _client.getRunOutput(pipelineUuid);
final output = await _client.getRunOutput(pipelineUuid, request);
return RunCodeResult(
status: status,
output: prevOutput + output.output,
);
case RunCodeStatus.finished:
final output = await _client.getRunOutput(pipelineUuid);
final output = await _client.getRunOutput(pipelineUuid, request);
return RunCodeResult(
status: status, output: prevOutput + output.output);
default:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,10 @@ class ExpansionPanelItem extends StatelessWidget {
child: GestureDetector(
onTap: () async {
if (playgroundState.selectedExample != example) {
final exampleWithInfo =
await exampleState.loadExampleInfo(example);
final exampleWithInfo = await exampleState.loadExampleInfo(
example,
playgroundState.sdk,
);
playgroundState.setExample(exampleWithInfo);
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
*/

import 'package:grpc/grpc_web.dart';
import 'package:playground/api/iis_workaround_channel.dart';
import 'package:playground/api/v1/api.pbgrpc.dart' as grpc;
import 'package:playground/config.g.dart';
import 'package:playground/modules/editor/repository/code_repository/code_client/output_response.dart';
import 'package:playground/modules/examples/models/category_model.dart';
import 'package:playground/modules/examples/models/example_model.dart';
Expand All @@ -30,22 +30,23 @@ import 'package:playground/modules/examples/repositories/models/get_list_of_exam
import 'package:playground/modules/sdk/models/sdk.dart';

class GrpcExampleClient implements ExampleClient {
late final GrpcWebClientChannel _channel;
late final grpc.PlaygroundServiceClient _client;

GrpcExampleClient() {
_channel = GrpcWebClientChannel.xhr(
Uri.parse(kApiClientURL),
grpc.PlaygroundServiceClient createClient(SDK? sdk) {
String apiClientURL = SDK.java.getRoute;
// if (sdk != null) {
// apiClientURL = sdk.getRoute;
// }
IisWorkaroundChannel channel = IisWorkaroundChannel.xhr(
Uri.parse(apiClientURL),
);
_client = grpc.PlaygroundServiceClient(_channel);
return grpc.PlaygroundServiceClient(channel);
}

@override
Future<GetListOfExampleResponse> getListOfExamples(
GetListOfExamplesRequestWrapper request,
) {
return _runSafely(
() => _client
() => createClient(request.sdk)
.getPrecompiledObjects(
_getListOfExamplesRequestToGrpcRequest(request))
.then((response) => GetListOfExampleResponse(
Expand All @@ -56,7 +57,7 @@ class GrpcExampleClient implements ExampleClient {
@override
Future<GetExampleResponse> getExample(GetExampleRequestWrapper request) {
return _runSafely(
() => _client
() => createClient(request.sdk)
.getPrecompiledObjectCode(_getExampleRequestToGrpcRequest(request))
.then((response) => GetExampleResponse(response.code)),
);
Expand All @@ -65,7 +66,7 @@ class GrpcExampleClient implements ExampleClient {
@override
Future<OutputResponse> getExampleOutput(GetExampleRequestWrapper request) {
return _runSafely(
() => _client
() => createClient(request.sdk)
.getPrecompiledObjectOutput(_getExampleRequestToGrpcRequest(request))
.then((response) => OutputResponse(response.output)),
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,11 @@
* limitations under the License.
*/

import 'package:playground/modules/sdk/models/sdk.dart';

class GetExampleRequestWrapper {
final String path;
final SDK sdk;

GetExampleRequestWrapper(this.path);
GetExampleRequestWrapper(this.path, this.sdk);
}
19 changes: 19 additions & 0 deletions playground/frontend/lib/modules/sdk/models/sdk.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
* limitations under the License.
*/

import 'package:playground/config.g.dart';

enum SDK {
java,
go,
Expand All @@ -37,3 +39,20 @@ extension SDKToString on SDK {
}
}
}

extension SdkToRoute on SDK {
String get getRoute {
switch (this) {
case SDK.java:
return kApiJavaClientURL;
case SDK.go:
return kApiGoClientURL;
case SDK.python:
return kApiPythonClientURL;
case SDK.scio:
return kApiScioClientURL;
default:
return '';
}
}
}
Loading