Skip to content

Commit

Permalink
Support to show producer list and partition list (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
shoothzj authored Nov 16, 2021
1 parent 8e82e90 commit 7bbc69f
Show file tree
Hide file tree
Showing 21 changed files with 385 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,13 @@ 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_stat_api.dart';
import 'package:paas_dashboard_flutter/module/pulsar/pulsar_partitioned_topic_detail.dart';
import 'package:paas_dashboard_flutter/module/pulsar/pulsar_produce.dart';
import 'package:paas_dashboard_flutter/module/pulsar/pulsar_subscription.dart';
import 'package:paas_dashboard_flutter/module/pulsar/pulsar_topic.dart';
import 'package:paas_dashboard_flutter/ui/util/string_util.dart';

class PulsarTopicAPi {
class PulsarPartitionedTopicAPi {
static Future<String> createPartitionTopic(String host, int port,
String tenant, String namespace, String topic, int partitionNum) async {
var url =
Expand Down Expand Up @@ -63,11 +66,12 @@ class PulsarTopicAPi {
List<SubscriptionResp> respList = new List.empty(growable: true);
Map statsMap = json.decode(data) as Map;
if (statsMap.containsKey("subscriptions")) {
Map subscriptionsMap = statsMap["subscriptions"] as Map<String,dynamic>;
Map subscriptionsMap = statsMap["subscriptions"] as Map<String, dynamic>;
subscriptionsMap.forEach((key, value) {
double rateOut = value["msgRateOut"];
int backlog = value["msgBacklog"];
SubscriptionResp subscriptionDetail = new SubscriptionResp(key, backlog, rateOut);
SubscriptionResp subscriptionDetail =
new SubscriptionResp(key, backlog, rateOut);
respList.add(subscriptionDetail);
});
}
Expand Down Expand Up @@ -108,4 +112,49 @@ class PulsarTopicAPi {
}
return "";
}

static Future<List<ProducerResp>> getProducers(String host, int port,
String tenant, String namespace, String topic) async {
String data = "";
await PulsarStatAPi.partitionedTopicStats(
host, port, tenant, namespace, topic)
.then((value) => {data = value});
List<ProducerResp> respList = new List.empty(growable: true);
Map statsMap = json.decode(data) as Map;
if (statsMap.containsKey("publishers")) {
List publisherList = statsMap["publishers"] as List<dynamic>;
publisherList.forEach((element) {
String producerName = StringUtil.nullStr(element["producerName"]);
double rateIn = element["msgRateIn"];
double throughputIn = element["msgThroughputIn"];
String clientVersion = StringUtil.nullStr(element["clientVersion"]);
double averageMsgSize = element["averageMsgSize"];
String address = StringUtil.nullStr(element["address"]);
ProducerResp producerResp = new ProducerResp(producerName, rateIn,
throughputIn, clientVersion, averageMsgSize, address);
respList.add(producerResp);
});
}
return respList;
}

static Future<List<PulsarPartitionedTopicDetailResp>> getDetails(String host,
int port, String tenant, String namespace, String topic) async {
String data = "";
await PulsarStatAPi.partitionedTopicStats(
host, port, tenant, namespace, topic)
.then((value) => {data = value});
List<PulsarPartitionedTopicDetailResp> respList =
new List.empty(growable: true);
Map statsMap = json.decode(data) as Map;
if (statsMap.containsKey("partitions")) {
Map partitionsMap = statsMap["partitions"] as Map<String, dynamic>;
partitionsMap.forEach((key, value) {
int backlog = value["backlogSize"];
var resp = new PulsarPartitionedTopicDetailResp(key, backlog);
respList.add(resp);
});
}
return respList;
}
}
7 changes: 6 additions & 1 deletion lib/generated/intl/messages_en.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,20 +32,24 @@ class MessageLookup extends MessageLookupByLibrary {
MessageLookupByLibrary.simpleMessage("ConfirmClear?"),
"confirmDeleteQuestion":
MessageLookupByLibrary.simpleMessage("ConfirmDelete?"),
"consume": MessageLookupByLibrary.simpleMessage("consume"),
"consumerList": MessageLookupByLibrary.simpleMessage("Consumer List"),
"delete": MessageLookupByLibrary.simpleMessage("Delete"),
"deleteNamespace":
MessageLookupByLibrary.simpleMessage("Delete Namespace"),
"deleteTenant": MessageLookupByLibrary.simpleMessage("Delete Tenant"),
"deleteTopic": MessageLookupByLibrary.simpleMessage("Delete Topic"),
"detail": MessageLookupByLibrary.simpleMessage("detail"),
"email": MessageLookupByLibrary.simpleMessage("email"),
"isLeader": MessageLookupByLibrary.simpleMessage("Is Leader"),
"languageSettings":
MessageLookupByLibrary.simpleMessage("Language Settings"),
"name": MessageLookupByLibrary.simpleMessage("name"),
"namespaceName": MessageLookupByLibrary.simpleMessage("Namespace Name"),
"namespaces": MessageLookupByLibrary.simpleMessage("Namespaces"),
"partitionList": MessageLookupByLibrary.simpleMessage("Partition List"),
"partitionNum":
MessageLookupByLibrary.simpleMessage("partition number"),
MessageLookupByLibrary.simpleMessage("Partition number"),
"produce": MessageLookupByLibrary.simpleMessage("Produce"),
"producerList": MessageLookupByLibrary.simpleMessage("Producer List"),
"refresh": MessageLookupByLibrary.simpleMessage("Refresh"),
Expand All @@ -56,6 +60,7 @@ class MessageLookup extends MessageLookupByLibrary {
"searchByTopic":
MessageLookupByLibrary.simpleMessage("Search by Topic Name"),
"settings": MessageLookupByLibrary.simpleMessage("Settings"),
"subscription": MessageLookupByLibrary.simpleMessage("subscription"),
"subscriptionList":
MessageLookupByLibrary.simpleMessage("Subscription list"),
"subscriptionName":
Expand Down
5 changes: 5 additions & 0 deletions lib/generated/intl/messages_zh.dart
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,20 @@ class MessageLookup extends MessageLookupByLibrary {
"confirm": MessageLookupByLibrary.simpleMessage("确认"),
"confirmClearBacklog": MessageLookupByLibrary.simpleMessage("确认清理积压吗?"),
"confirmDeleteQuestion": MessageLookupByLibrary.simpleMessage("确认删除吗?"),
"consume": MessageLookupByLibrary.simpleMessage("消费"),
"consumerList": MessageLookupByLibrary.simpleMessage("消费者列表"),
"delete": MessageLookupByLibrary.simpleMessage("删除"),
"deleteNamespace": MessageLookupByLibrary.simpleMessage("删除命名空间"),
"deleteTenant": MessageLookupByLibrary.simpleMessage("删除租户"),
"deleteTopic": MessageLookupByLibrary.simpleMessage("删除 Topic"),
"detail": MessageLookupByLibrary.simpleMessage("详细信息"),
"email": MessageLookupByLibrary.simpleMessage("邮箱"),
"isLeader": MessageLookupByLibrary.simpleMessage("是否是主节点"),
"languageSettings": MessageLookupByLibrary.simpleMessage("语言设置"),
"name": MessageLookupByLibrary.simpleMessage("名称"),
"namespaceName": MessageLookupByLibrary.simpleMessage("命名空间名称"),
"namespaces": MessageLookupByLibrary.simpleMessage("命名空间列表"),
"partitionList": MessageLookupByLibrary.simpleMessage("partition 列表"),
"partitionNum": MessageLookupByLibrary.simpleMessage("partition 个数"),
"produce": MessageLookupByLibrary.simpleMessage("生产"),
"producerList": MessageLookupByLibrary.simpleMessage("生产者列表"),
Expand All @@ -48,6 +52,7 @@ class MessageLookup extends MessageLookupByLibrary {
"searchByTenant": MessageLookupByLibrary.simpleMessage("按租户名称搜索"),
"searchByTopic": MessageLookupByLibrary.simpleMessage("按 Topic 名称搜索"),
"settings": MessageLookupByLibrary.simpleMessage("设置"),
"subscription": MessageLookupByLibrary.simpleMessage("订阅"),
"subscriptionList": MessageLookupByLibrary.simpleMessage("订阅列表"),
"subscriptionName": MessageLookupByLibrary.simpleMessage("订阅名称"),
"tenantName": MessageLookupByLibrary.simpleMessage("租户名称"),
Expand Down
54 changes: 52 additions & 2 deletions lib/generated/l10n.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion lib/l10n/intl_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"cancel": "Cancel",
"confirm": "Confirm",
"basic": "Basic",
"detail": "detail",
"confirmDeleteQuestion": "ConfirmDelete?",
"brokersName": "Broker Instance",
"isLeader": "Is Leader",
Expand All @@ -23,9 +24,13 @@
"deleteTopic": "Delete Topic",
"produce": "Produce",
"producerList": "Producer List",
"partitionNum": "partition number",
"partitionNum": "Partition number",
"partitionList": "Partition List",
"consume": "consume",
"consumerList": "Consumer List",
"clearBacklog": "Clear Backlog",
"confirmClearBacklog": "ConfirmClear?",
"subscription": "subscription",
"subscriptionList": "Subscription list",
"subscriptionName": "Subscription Name",
"aboutAuthor": "About author",
Expand Down
5 changes: 5 additions & 0 deletions lib/l10n/intl_zh.arb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"cancel": "取消",
"confirm": "确认",
"basic": "基础信息",
"detail": "详细信息",
"confirmDeleteQuestion": "确认删除吗?",
"brokersName": "Pulsar 实例",
"isLeader": "是否是主节点",
Expand All @@ -24,8 +25,12 @@
"produce": "生产",
"producerList": "生产者列表",
"partitionNum": "partition 个数",
"partitionList": "partition 列表",
"consume": "消费",
"consumerList": "消费者列表",
"clearBacklog": "清理积压",
"confirmClearBacklog": "确认清理积压吗?",
"subscription": "订阅",
"subscriptionList": "订阅列表",
"subscriptionName": "订阅名称",
"aboutAuthor": "关于作者",
Expand Down
10 changes: 10 additions & 0 deletions lib/module/pulsar/pulsar_partitioned_topic_detail.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
class PulsarPartitionedTopicDetailResp {
final String topicName;
final int backlogSize;

PulsarPartitionedTopicDetailResp(this.topicName, this.backlogSize);

PulsarPartitionedTopicDetailResp deepCopy() {
return new PulsarPartitionedTopicDetailResp(topicName, backlogSize);
}
}
11 changes: 9 additions & 2 deletions lib/module/pulsar/pulsar_produce.dart
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
class ProducerResp {
final String producerName;
final double rateIn;
final double throughputIn;
final String clientVersion;
final double averageMsgSize;
final String address;

ProducerResp(this.producerName);
ProducerResp(this.producerName, this.rateIn, this.throughputIn,
this.clientVersion, this.averageMsgSize, this.address);

ProducerResp deepCopy() {
return new ProducerResp(producerName);
return new ProducerResp(producerName, rateIn, throughputIn, clientVersion,
averageMsgSize, address);
}
}
6 changes: 3 additions & 3 deletions lib/ui/pulsar/pulsar_instance.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import 'package:flutter/material.dart';
import 'package:paas_dashboard_flutter/ui/pulsar/tab/pulsar_basic.dart';
import 'package:paas_dashboard_flutter/ui/pulsar/tab/pulsar_details.dart';
import 'package:paas_dashboard_flutter/ui/pulsar/tab/pulsar_message_query.dart';
import 'package:paas_dashboard_flutter/ui/pulsar/widget/pulsar_basic.dart';
import 'package:paas_dashboard_flutter/ui/pulsar/widget/pulsar_details.dart';
import 'package:paas_dashboard_flutter/ui/pulsar/widget/pulsar_message_query.dart';
import 'package:paas_dashboard_flutter/vm/pulsar/pulsar_cluster_view_model.dart';
import 'package:paas_dashboard_flutter/vm/pulsar/pulsar_instance_view_model.dart';
import 'package:provider/provider.dart';
Expand Down
22 changes: 17 additions & 5 deletions lib/ui/pulsar/screen/pulsar_partitioned_topic.dart
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import 'package:flutter/material.dart';
import 'package:paas_dashboard_flutter/generated/l10n.dart';
import 'package:paas_dashboard_flutter/ui/pulsar/widget/pulsar_partitioned_topic_basic.dart';
import 'package:paas_dashboard_flutter/ui/pulsar/widget/pulsar_partitioned_topic_detail.dart';
import 'package:paas_dashboard_flutter/ui/pulsar/widget/pulsar_partitioned_topic_produce.dart';
import 'package:paas_dashboard_flutter/ui/pulsar/widget/pulsar_partitioned_topic_subscription.dart';
import 'package:paas_dashboard_flutter/vm/pulsar/pulsar_partitioned_topic_basic_view_model.dart';
import 'package:paas_dashboard_flutter/vm/pulsar/pulsar_partitioned_topic_detail_view_model.dart';
import 'package:paas_dashboard_flutter/vm/pulsar/pulsar_partitioned_topic_produce_view_model.dart';
import 'package:paas_dashboard_flutter/vm/pulsar/pulsar_partitioned_topic_subscription_view_model.dart';
import 'package:paas_dashboard_flutter/vm/pulsar/pulsar_partitioned_topic_view_model.dart';
Expand All @@ -24,15 +27,16 @@ class _PulsarPartitionedTopicState extends State<PulsarPartitionedTopic> {
Widget build(BuildContext context) {
final vm = Provider.of<PulsarPartitionedTopicViewModel>(context);
return DefaultTabController(
length: 3,
length: 4,
child: Scaffold(
appBar: AppBar(
title: Text('Pulsar ${vm.topic} Dashboard'),
title: Text('Pulsar Partitioned Topic ${vm.topic}'),
bottom: TabBar(
tabs: [
Tab(text: "Basic"),
Tab(text: "Subscription"),
Tab(text: "Produce"),
Tab(text: S.of(context).basic),
Tab(text: S.of(context).detail),
Tab(text: S.of(context).subscription),
Tab(text: S.of(context).produce),
],
),
),
Expand All @@ -46,6 +50,14 @@ class _PulsarPartitionedTopicState extends State<PulsarPartitionedTopic> {
vm.topicResp),
child: PulsarPartitionedTopicBasicWidget(),
).build(context),
ChangeNotifierProvider(
create: (context) => new PulsarPartitionedTopicDetailViewModel(
vm.pulsarInstancePo,
vm.tenantResp,
vm.namespaceResp,
vm.topicResp),
child: PulsarPartitionedTopicDetailWidget(),
).build(context),
ChangeNotifierProvider(
create: (context) =>
new PulsarPartitionedTopicSubscriptionViewModel(
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit 7bbc69f

Please sign in to comment.