Skip to content

Commit

Permalink
Support source sink basic info (#14)
Browse files Browse the repository at this point in the history
  • Loading branch information
shoothzj authored Dec 1, 2021
1 parent a1c13ca commit dfc3552
Show file tree
Hide file tree
Showing 16 changed files with 543 additions and 5 deletions.
14 changes: 14 additions & 0 deletions lib/api/pulsar/pulsar_sink_api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,18 @@ class PulsarSinkApi {
List jsonResponse = json.decode(response.body) as List;
return jsonResponse.map((name) => new SinkResp(name)).toList();
}

static Future<SinkConfigResp> getSink(
String host, int port, String tenant, String namespace, String sinkName) async {
var url =
'http://$host:${port.toString()}/admin/v3/sinks/$tenant/$namespace/$sinkName';
final response = await http.get(Uri.parse(url));
if (HttpUtil.abnormal(response.statusCode)) {
log('ErrorCode is ${response.statusCode}, body is ${response.body}');
throw Exception(
'ErrorCode is ${response.statusCode}, body is ${response.body}');
}
Map jsonResponse = json.decode(response.body) as Map;
return SinkConfigResp.fromJson(jsonResponse);
}
}
14 changes: 14 additions & 0 deletions lib/api/pulsar/pulsar_source_api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,18 @@ class PulsarSourceApi {
List jsonResponse = json.decode(response.body) as List;
return jsonResponse.map((name) => new SourceResp(name)).toList();
}

static Future<SourceConfigResp> getSource(
String host, int port, String tenant, String namespace, String sourceName) async {
var url =
'http://$host:${port.toString()}/admin/v3/sources/$tenant/$namespace/$sourceName';
final response = await http.get(Uri.parse(url));
if (HttpUtil.abnormal(response.statusCode)) {
log('ErrorCode is ${response.statusCode}, body is ${response.body}');
throw Exception(
'ErrorCode is ${response.statusCode}, body is ${response.body}');
}
Map jsonResponse = json.decode(response.body) as Map;
return SourceConfigResp.fromJson(jsonResponse);
}
}
10 changes: 10 additions & 0 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import 'package:paas_dashboard_flutter/vm/pulsar/pulsar_instance_list_view_model
import 'package:paas_dashboard_flutter/vm/pulsar/pulsar_instance_view_model.dart';
import 'package:paas_dashboard_flutter/vm/pulsar/pulsar_namespace_view_model.dart';
import 'package:paas_dashboard_flutter/vm/pulsar/pulsar_partitioned_topic_view_model.dart';
import 'package:paas_dashboard_flutter/vm/pulsar/pulsar_sink_view_model.dart';
import 'package:paas_dashboard_flutter/vm/pulsar/pulsar_source_view_model.dart';
import 'package:paas_dashboard_flutter/vm/pulsar/pulsar_tenant_view_model.dart';
import 'package:paas_dashboard_flutter/vm/pulsar/pulsar_topic_view_model.dart';
import 'package:provider/provider.dart';
Expand Down Expand Up @@ -85,6 +87,14 @@ class MyApp extends StatelessWidget {
final args = settings.arguments as PulsarTopicViewModel;
return RouteGen.pulsarTopic(args);
}
if (settings.name == PageRouteConst.PulsarSource) {
final args = settings.arguments as PulsarSourceViewModel;
return RouteGen.pulsarSource(args);
}
if (settings.name == PageRouteConst.PulsarSink) {
final args = settings.arguments as PulsarSinkViewModel;
return RouteGen.pulsarSink(args);
}
},
);
}
Expand Down
22 changes: 22 additions & 0 deletions lib/module/pulsar/pulsar_sink.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,23 @@ class SinkConfigReq {
}
}

class SinkConfigResp {
final String name;
final String tenant;
final String namespace;
final List<dynamic> inputs;
final Map configs;
final String archive;

SinkConfigResp(this.name, this.tenant, this.namespace, this.inputs,
this.configs, this.archive);

factory SinkConfigResp.fromJson(Map map) {
return SinkConfigResp(map["name"], map["tenant"], map["namespace"],
map["inputs"], map["configs"], map["archive"]);
}
}

class SinkResp {
final String sinkName;

Expand All @@ -31,6 +48,11 @@ class SinkResp {
SinkResp deepCopy() {
return new SinkResp(this.sinkName);
}

@override
String toString() {
return 'SinkResp{sinkName: $sinkName}';
}
}

class PulsarSink {
Expand Down
17 changes: 17 additions & 0 deletions lib/module/pulsar/pulsar_source.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,23 @@ class SourceConfigReq {
}
}

class SourceConfigResp {
final String name;
final String tenant;
final String namespace;
final String topicName;
final Map configs;
final String archive;

SourceConfigResp(this.name, this.tenant, this.namespace, this.topicName,
this.configs, this.archive);

factory SourceConfigResp.fromJson(Map map) {
return SourceConfigResp(map["name"], map["tenant"], map["namespace"],
map["topicName"], map["configs"], map["archive"]);
}
}

class SourceResp {
final String sourceName;

Expand Down
2 changes: 2 additions & 0 deletions lib/route/page_route_const.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,6 @@ class PageRouteConst {
static const String PulsarNamespace = '/pulsar/instance/tenant/namespace';
static const String PulsarPartitionedTopic = '/pulsar/instance/tenant/namespace/partitioned-topic';
static const String PulsarTopic = '/pulsar/instance/tenant/namespace/topic';
static const String PulsarSource = '/pulsar/instance/tenant/namespace/source';
static const String PulsarSink = '/pulsar/instance/tenant/namespace/sink';
}
20 changes: 20 additions & 0 deletions lib/route/route_gen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,15 @@ import 'package:flutter/material.dart';
import 'package:paas_dashboard_flutter/ui/pulsar/pulsar_instance.dart';
import 'package:paas_dashboard_flutter/ui/pulsar/screen/pulsar_namespace.dart';
import 'package:paas_dashboard_flutter/ui/pulsar/screen/pulsar_partitioned_topic.dart';
import 'package:paas_dashboard_flutter/ui/pulsar/screen/pulsar_sink.dart';
import 'package:paas_dashboard_flutter/ui/pulsar/screen/pulsar_source.dart';
import 'package:paas_dashboard_flutter/ui/pulsar/screen/pulsar_tenant.dart';
import 'package:paas_dashboard_flutter/ui/pulsar/screen/pulsar_topic.dart';
import 'package:paas_dashboard_flutter/vm/pulsar/pulsar_instance_view_model.dart';
import 'package:paas_dashboard_flutter/vm/pulsar/pulsar_namespace_view_model.dart';
import 'package:paas_dashboard_flutter/vm/pulsar/pulsar_partitioned_topic_view_model.dart';
import 'package:paas_dashboard_flutter/vm/pulsar/pulsar_sink_view_model.dart';
import 'package:paas_dashboard_flutter/vm/pulsar/pulsar_source_view_model.dart';
import 'package:paas_dashboard_flutter/vm/pulsar/pulsar_tenant_view_model.dart';
import 'package:paas_dashboard_flutter/vm/pulsar/pulsar_topic_view_model.dart';
import 'package:provider/provider.dart';
Expand Down Expand Up @@ -53,4 +57,20 @@ class RouteGen {
child: PulsarTopic(),
));
}

static Route pulsarSource(PulsarSourceViewModel viewModel) {
return MaterialPageRoute(
builder: (context) => ChangeNotifierProvider(
create: (context) => viewModel,
child: PulsarSourceScreen(),
));
}

static Route pulsarSink(PulsarSinkViewModel viewModel) {
return MaterialPageRoute(
builder: (context) => ChangeNotifierProvider(
create: (context) => viewModel,
child: PulsarSinkScreen(),
));
}
}
50 changes: 50 additions & 0 deletions lib/ui/pulsar/screen/pulsar_sink.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import 'package:flutter/material.dart';
import 'package:paas_dashboard_flutter/generated/l10n.dart';
import 'package:paas_dashboard_flutter/ui/pulsar/widget/pulsar_sink_basic.dart';
import 'package:paas_dashboard_flutter/vm/pulsar/pulsar_sink_basic_view_model.dart';
import 'package:paas_dashboard_flutter/vm/pulsar/pulsar_sink_view_model.dart';
import 'package:provider/provider.dart';

class PulsarSinkScreen extends StatefulWidget {
PulsarSinkScreen();

@override
State<StatefulWidget> createState() {
return new _PulsarSinkScreenState();
}
}

class _PulsarSinkScreenState extends State<PulsarSinkScreen> {
_PulsarSinkScreenState();

@override
Widget build(BuildContext context) {
final vm = Provider.of<PulsarSinkViewModel>(context);
return DefaultTabController(
length: 1,
child: Scaffold(
appBar: AppBar(
title: Text(
'Pulsar Sink Tenant ${vm.tenant} -> Namespace ${vm.namespace} -> Topic ${vm.sinkName}'),
bottom: TabBar(
tabs: [
Tab(text: S.of(context).basic),
],
),
),
body: TabBarView(
children: [
ChangeNotifierProvider(
create: (context) => PulsarSinkBasicViewModel(
vm.pulsarInstancePo,
vm.tenantResp,
vm.namespaceResp,
vm.sinkResp),
child: PulsarSinkBasicWidget(),
).build(context),
],
),
),
);
}
}
51 changes: 51 additions & 0 deletions lib/ui/pulsar/screen/pulsar_source.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import 'package:flutter/material.dart';
import 'package:paas_dashboard_flutter/generated/l10n.dart';
import 'package:paas_dashboard_flutter/ui/pulsar/widget/pulsar_source_basic.dart';
import 'package:paas_dashboard_flutter/ui/pulsar/widget/pulsar_topic_basic.dart';
import 'package:paas_dashboard_flutter/vm/pulsar/pulsar_source_basic_view_model.dart';
import 'package:paas_dashboard_flutter/vm/pulsar/pulsar_source_view_model.dart';
import 'package:provider/provider.dart';

class PulsarSourceScreen extends StatefulWidget {
PulsarSourceScreen();

@override
State<StatefulWidget> createState() {
return new _PulsarSourceScreenState();
}
}

class _PulsarSourceScreenState extends State<PulsarSourceScreen> {
_PulsarSourceScreenState();

@override
Widget build(BuildContext context) {
final vm = Provider.of<PulsarSourceViewModel>(context);
return DefaultTabController(
length: 1,
child: Scaffold(
appBar: AppBar(
title: Text(
'Pulsar Source Tenant ${vm.tenant} -> Namespace ${vm.namespace} -> Topic ${vm.sourceName}'),
bottom: TabBar(
tabs: [
Tab(text: S.of(context).basic),
],
),
),
body: TabBarView(
children: [
ChangeNotifierProvider(
create: (context) => PulsarSourceBasicViewModel(
vm.pulsarInstancePo,
vm.tenantResp,
vm.namespaceResp,
vm.sourceResp),
child: PulsarSourceBasicWidget(),
).build(context),
],
),
),
);
}
}
94 changes: 94 additions & 0 deletions lib/ui/pulsar/widget/pulsar_sink_basic.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
import 'package:flutter/material.dart';
import 'package:paas_dashboard_flutter/generated/l10n.dart';
import 'package:paas_dashboard_flutter/ui/util/exception_util.dart';
import 'package:paas_dashboard_flutter/ui/util/spinner_util.dart';
import 'package:paas_dashboard_flutter/vm/pulsar/pulsar_sink_basic_view_model.dart';
import 'package:paas_dashboard_flutter/vm/pulsar/pulsar_topic_basic_view_model.dart';
import 'package:provider/provider.dart';

class PulsarSinkBasicWidget extends StatefulWidget {
PulsarSinkBasicWidget();

@override
State<StatefulWidget> createState() {
return new PulsarSinkBasicWidgetState();
}
}

class PulsarSinkBasicWidgetState
extends State<PulsarSinkBasicWidget> {
@override
void initState() {
super.initState();
final vm = Provider.of<PulsarSinkBasicViewModel>(context,
listen: false);
vm.fetch();
}

@override
Widget build(BuildContext context) {
final vm = Provider.of<PulsarSinkBasicViewModel>(context);
if (vm.loading) {
WidgetsBinding.instance!.addPostFrameCallback((timeStamp) {
SpinnerUtil.create();
});
}
ExceptionUtil.processLoadException(vm, context);
ExceptionUtil.processOpException(vm, context);
var refreshButton =
TextButton(onPressed: () {}, child: Text(S.of(context).refresh));
var body = ListView(
children: <Widget>[
Container(
height: 50,
child: ListView(
scrollDirection: Axis.horizontal,
shrinkWrap: true,
children: [refreshButton],
),
),
Container(
height: 50,
child: ListView(
scrollDirection: Axis.horizontal,
shrinkWrap: true,
children: [
Text(
'inputs is ${vm.inputs}',
style: new TextStyle(fontSize: 20),
),
],
),
),
Container(
height: 50,
child: ListView(
scrollDirection: Axis.horizontal,
shrinkWrap: true,
children: [
Text(
'configs is ${vm.configs}',
style: new TextStyle(fontSize: 20),
),
],
),
),
Container(
height: 50,
child: ListView(
scrollDirection: Axis.horizontal,
shrinkWrap: true,
children: [
Text(
'archive is ${vm.archive}',
style: new TextStyle(fontSize: 20),
),
],
),
),
],
);
return body;
}

}
6 changes: 3 additions & 3 deletions lib/ui/pulsar/widget/pulsar_sink_list.dart
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,15 @@ class PulsarSinkListWidgetState extends State<PulsarSinkListWidget> {
vm.setDataConverter((item) => DataRow(
onSelectChanged: (bool? selected) {
Navigator.pushNamed(
context, PageRouteConst.PulsarPartitionedTopic,
context, PageRouteConst.PulsarSink,
arguments: item.deepCopy());
},
cells: [
DataCell(
Text(item.name),
Text(item.sinkName),
),
DataCellUtil.newDellDataCell(() {
vm.deleteSink(item.name);
vm.deleteSink(item.sinkName);
}),
]));
var topicsTable = SingleChildScrollView(
Expand Down
Loading

0 comments on commit dfc3552

Please sign in to comment.