Skip to content

Commit

Permalink
Remove Unstable IsLeader Feature
Browse files Browse the repository at this point in the history
  • Loading branch information
shoothzj committed Aug 2, 2021
1 parent 25fd003 commit db444bf
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 29 deletions.
35 changes: 19 additions & 16 deletions lib/api/pulsar/pulsar_cluster_api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,39 +8,42 @@ 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 version = await getVersion(host, port);
String tenantInfo =
await PulsarTenantAPi.getTenantInfo(host, port, "public");
String cluster =
((json.decode(tenantInfo) as Map)["allowedClusters"] as List)[0];
url = 'http://$host:${port.toString()}/admin/v2/brokers/$cluster';
String 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;
return brokers.map((e) => ClusterResp(e, version)).toList();
}

url = 'http://$host:${port.toString()}/admin/v2/brokers/leaderBroker';
static Future<String> getVersion(String host, int port) async {
String 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}');
}
return versionResponse.body;
}

static Future<String> getLeader(String host, int port) async {
String 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"];

return brokers
.map((e) => ClusterResp(e, leader.contains(e).toString(), version))
.toList();
return json.decode(leaderBrokerResponse.body)["serviceUrl"];
}
}
5 changes: 2 additions & 3 deletions lib/module/pulsar/pulsar_cluster.dart
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
class ClusterResp {
final String instance;
final String isLeader;
final String version;

ClusterResp(this.instance, this.isLeader, this.version);
ClusterResp(this.instance, this.version);

ClusterResp deepCopy() {
return new ClusterResp(instance, isLeader, version);
return new ClusterResp(instance, version);
}
}
10 changes: 0 additions & 10 deletions lib/ui/pulsar/tab/pulsar_basic.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,15 @@ class PulsarBasicWidget extends StatefulWidget {
}

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();
}

Expand All @@ -48,17 +42,13 @@ class PulsarBasicScreenState extends State<PulsarBasicWidget> {
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),
),
Expand Down

0 comments on commit db444bf

Please sign in to comment.