-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
272 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import 'dart:convert'; | ||
import 'dart:developer'; | ||
|
||
import 'package:http/http.dart' as http; | ||
import 'package:paas_dashboard_flutter/api/http_util.dart'; | ||
import 'package:paas_dashboard_flutter/api/pulsar/pulsar_tenant_api.dart'; | ||
import 'package:paas_dashboard_flutter/module/pulsar/pulsar_cluster.dart'; | ||
|
||
class PulsarClusterAPi { | ||
static Future<List<ClusterResp>> cluster(String host, int port) async { | ||
var url = 'http://$host:${port.toString()}/admin/v2/brokers/version'; | ||
final versionResponse = await http.get(Uri.parse(url)); | ||
if (HttpUtil.abnormal(versionResponse.statusCode)) { | ||
log('ErrorCode is ${versionResponse.statusCode}, body is ${versionResponse.body}'); | ||
throw Exception( | ||
'ErrorCode is ${versionResponse.statusCode}, body is ${versionResponse.body}'); | ||
} | ||
String version = versionResponse.body; | ||
|
||
String tenantInfo = ""; | ||
await PulsarTenantAPi.getTenantInfo(host, port, "public") | ||
.then((value) => tenantInfo = value); | ||
String cluster = | ||
((json.decode(tenantInfo) as Map)["allowedClusters"] as List)[0]; | ||
url = 'http://$host:${port.toString()}/admin/v2/brokers/$cluster'; | ||
final brokersResponse = await http.get(Uri.parse(url)); | ||
if (HttpUtil.abnormal(brokersResponse.statusCode)) { | ||
log('ErrorCode is ${brokersResponse.statusCode}, body is ${brokersResponse.body}'); | ||
throw Exception( | ||
'ErrorCode is ${brokersResponse.statusCode}, body is ${brokersResponse.body}'); | ||
} | ||
List brokers = json.decode(brokersResponse.body) as List; | ||
|
||
url = 'http://$host:${port.toString()}/admin/v2/brokers/leaderBroker'; | ||
final leaderBrokerResponse = await http.get(Uri.parse(url)); | ||
if (HttpUtil.abnormal(leaderBrokerResponse.statusCode)) { | ||
log('ErrorCode is ${leaderBrokerResponse.statusCode}, body is ${leaderBrokerResponse.body}'); | ||
throw Exception( | ||
'ErrorCode is ${leaderBrokerResponse.statusCode}, body is ${leaderBrokerResponse.body}'); | ||
} | ||
String leader = json.decode(leaderBrokerResponse.body)["serviceUrl"]; | ||
|
||
List<ClusterResp> respList = new List.empty(growable: true); | ||
brokers.forEach((element) { | ||
respList.add(new ClusterResp( | ||
element, leader.contains(element).toString(), version)); | ||
}); | ||
return respList; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
class ClusterResp { | ||
final String instance; | ||
final String isLeader; | ||
final String version; | ||
|
||
ClusterResp(this.instance, this.isLeader, this.version); | ||
|
||
ClusterResp deepCopy() { | ||
return new ClusterResp(instance, isLeader, version); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,93 @@ | ||
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_cluster_view_model.dart'; | ||
import 'package:provider/provider.dart'; | ||
|
||
class PulsarBasicWidget extends StatelessWidget { | ||
class PulsarBasicWidget extends StatefulWidget { | ||
PulsarBasicWidget(); | ||
|
||
@override | ||
State<StatefulWidget> createState() { | ||
return new PulsarBasicScreenState(); | ||
} | ||
} | ||
|
||
class PulsarBasicScreenState extends State<PulsarBasicWidget> { | ||
final searchTextController = TextEditingController(); | ||
|
||
@override | ||
void initState() { | ||
super.initState(); | ||
final vm = Provider.of<PulsarClusterViewModel>(context, listen: false); | ||
vm.fetchPulsarCluster(); | ||
searchTextController.addListener(() { | ||
vm.filter(searchTextController.text); | ||
}); | ||
} | ||
|
||
@override | ||
void dispose() { | ||
searchTextController.dispose(); | ||
super.dispose(); | ||
} | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return ListView( | ||
children: <Widget>[], | ||
final vm = Provider.of<PulsarClusterViewModel>(context); | ||
if (vm.loading) { | ||
WidgetsBinding.instance!.addPostFrameCallback((timeStamp) { | ||
SpinnerUtil.create(); | ||
}); | ||
} | ||
ExceptionUtil.processLoadExceptionPageable(vm, context); | ||
ExceptionUtil.processOpExceptionPageable(vm, context); | ||
var topicsFuture = SingleChildScrollView( | ||
child: DataTable( | ||
showCheckboxColumn: false, | ||
columns: [ | ||
DataColumn(label: Text(S.of(context).brokersName)), | ||
DataColumn(label: Text(S.of(context).isLeader)), | ||
DataColumn(label: Text(S.of(context).versionName)), | ||
], | ||
rows: vm.displayList | ||
.map((data) => DataRow(cells: [ | ||
DataCell( | ||
Text(data.instance), | ||
), | ||
DataCell( | ||
Text(data.isLeader), | ||
), | ||
DataCell( | ||
Text(data.version), | ||
), | ||
])) | ||
.toList()), | ||
); | ||
var refreshButton = TextButton( | ||
onPressed: () { | ||
vm.fetchPulsarCluster(); | ||
}, | ||
child: Text(S.of(context).refresh)); | ||
var body = ListView( | ||
children: <Widget>[ | ||
Container( | ||
height: 50, | ||
child: ListView( | ||
scrollDirection: Axis.horizontal, | ||
shrinkWrap: true, | ||
children: [refreshButton], | ||
), | ||
), | ||
Text( | ||
'Pulsar Cluster', | ||
style: TextStyle(fontSize: 22), | ||
), | ||
topicsFuture | ||
], | ||
); | ||
|
||
return body; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import 'package:paas_dashboard_flutter/api/pulsar/pulsar_cluster_api.dart'; | ||
import 'package:paas_dashboard_flutter/module/pulsar/pulsar_cluster.dart'; | ||
import 'package:paas_dashboard_flutter/persistent/po/pulsar_instance_po.dart'; | ||
|
||
import '../base_load_list_page_view_model.dart'; | ||
|
||
class PulsarClusterViewModel extends BaseLoadListPageViewModel<ClusterResp> { | ||
List<ClusterResp> instances = <ClusterResp>[]; | ||
|
||
final PulsarInstancePo pulsarInstancePo; | ||
|
||
PulsarClusterViewModel(this.pulsarInstancePo); | ||
|
||
int get id { | ||
return this.pulsarInstancePo.id; | ||
} | ||
|
||
String get name { | ||
return this.pulsarInstancePo.name; | ||
} | ||
|
||
String get host { | ||
return this.pulsarInstancePo.host; | ||
} | ||
|
||
int get port { | ||
return this.pulsarInstancePo.port; | ||
} | ||
|
||
Future<void> fetchPulsarCluster() async { | ||
try { | ||
this.fullList = await PulsarClusterAPi.cluster(host, port); | ||
this.displayList = this.fullList; | ||
} on Exception catch (e) { | ||
loadException = e; | ||
loading = false; | ||
} | ||
loadSuccess(); | ||
notifyListeners(); | ||
} | ||
|
||
Future<void> filter(String str) async { | ||
notifyListeners(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,4 +28,4 @@ SPEC CHECKSUMS: | |
|
||
PODFILE CHECKSUM: 6eac6b3292e5142cfc23bdeb71848a40ec51c14c | ||
|
||
COCOAPODS: 1.10.1 | ||
COCOAPODS: 1.10.2 |