Skip to content

Commit

Permalink
add topic detail info (#21)
Browse files Browse the repository at this point in the history
  • Loading branch information
fu-turer committed Dec 11, 2021
1 parent b184920 commit daf03c6
Show file tree
Hide file tree
Showing 22 changed files with 850 additions and 20 deletions.
107 changes: 107 additions & 0 deletions lib/api/pulsar/pulsar_partitioned_topic_api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ 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_consume.dart';
import 'package:paas_dashboard_flutter/module/pulsar/pulsar_partitioned_topic_base.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';
Expand Down Expand Up @@ -130,6 +132,72 @@ class PulsarPartitionedTopicApi {
return "";
}

static Future<List<ConsumerResp>> getConsumers(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<ConsumerResp> respList = new List.empty(growable: true);
Map statsMap = json.decode(data) as Map;
if (statsMap.containsKey("subscriptions")) {
Map subscriptionsMap = statsMap["subscriptions"] as Map;
subscriptionsMap.forEach((key, value) {
Map subMap = value as Map;
if (subMap.containsKey("consumers")) {
List consumers = subMap["consumers"] as List;
consumers.forEach((element) {
Map consumer = element as Map;
double rateOut = 0;
double throughputOut = 0;
String clientVersion = "";
String address = "";
String consumerName = "";
double availablePermits = 0;
double unackedMessages = 0;
double lastConsumedTimestamp = 0;
if (consumer.containsKey("consumerName")) {
consumerName = consumer["consumerName"];
}
if (consumer.containsKey("address")) {
address = consumer["address"];
}
if (consumer.containsKey("clientVersion")) {
clientVersion = consumer["clientVersion"];
}
if (consumer.containsKey("throughputOut")) {
throughputOut = consumer["throughputOut"];
}
if (consumer.containsKey("rateOut")) {
rateOut = consumer["rateOut"];
}
if (consumer.containsKey("availablePermits")) {
availablePermits = consumer["availablePermits"];
}
if (consumer.containsKey("unackedMessages")) {
unackedMessages = consumer["unackedMessages"];
}
if (consumer.containsKey("lastConsumedTimestamp")) {
lastConsumedTimestamp = consumer["lastConsumedTimestamp"];
}
ConsumerResp consumerResp = new ConsumerResp(
consumerName,
key,
rateOut,
throughputOut,
availablePermits,
unackedMessages,
lastConsumedTimestamp,
clientVersion,
address);
respList.add(consumerResp);
});
}
});
}
return respList;
}

static Future<List<ProducerResp>> getProducers(String host, int port,
String tenant, String namespace, String topic) async {
String data = "";
Expand Down Expand Up @@ -174,4 +242,43 @@ class PulsarPartitionedTopicApi {
}
return respList;
}

static Future<PulsarPartitionedTopicBaseResp> getBase(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});

Map statsMap = json.decode(data) as Map;
String topicName = topic;
int partitionNum = 0;
double msgRateIn = 0;
double msgRateOut = 0;
double msgInCounter = 0;
double msgOutCounter = 0;
double storageSize = 0;

if (statsMap.containsKey("metadata")) {
Map metadata = statsMap["metadata"] as Map;
partitionNum = metadata["partitions"];
}
if (statsMap.containsKey("msgRateIn")) {
msgRateIn = statsMap["msgRateIn"];
}
if (statsMap.containsKey("msgRateOut")) {
msgRateOut = statsMap["msgRateOut"];
}
if (statsMap.containsKey("msgInCounter")) {
msgInCounter = statsMap["msgInCounter"];
}
if (statsMap.containsKey("msgOutCounter")) {
msgOutCounter = statsMap["msgOutCounter"];
}
if (statsMap.containsKey("storageSize")) {
storageSize = statsMap["storageSize"];
}
return new PulsarPartitionedTopicBaseResp(topicName, partitionNum,
msgRateIn, msgRateOut, msgInCounter, msgOutCounter, storageSize);
}
}
105 changes: 105 additions & 0 deletions lib/api/pulsar/pulsar_topic_api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ 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_consume.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/module/pulsar/pulsar_topic_base.dart';
import 'package:paas_dashboard_flutter/ui/util/string_util.dart';

class PulsarTopicApi {
Expand Down Expand Up @@ -109,6 +111,71 @@ class PulsarTopicApi {
return "";
}

static Future<List<ConsumerResp>> getConsumers(String host, int port,
String tenant, String namespace, String topic) async {
String data = "";
await PulsarStatApi.topicStats(host, port, tenant, namespace, topic)
.then((value) => {data = value});
List<ConsumerResp> respList = new List.empty(growable: true);
Map statsMap = json.decode(data) as Map;
if (statsMap.containsKey("subscriptions")) {
Map subscriptionsMap = statsMap["subscriptions"] as Map;
subscriptionsMap.forEach((key, value) {
Map subMap = value as Map;
if (subMap.containsKey("consumers")) {
List consumers = subMap["consumers"] as List;
consumers.forEach((element) {
Map consumer = element as Map;
double rateOut = 0;
double throughputOut = 0;
String clientVersion = "";
String address = "";
String consumerName = "";
double availablePermits = 0;
double unackedMessages = 0;
double lastConsumedTimestamp = 0;
if (consumer.containsKey("consumerName")) {
consumerName = consumer["consumerName"];
}
if (consumer.containsKey("address")) {
address = consumer["address"];
}
if (consumer.containsKey("clientVersion")) {
clientVersion = consumer["clientVersion"];
}
if (consumer.containsKey("throughputOut")) {
throughputOut = consumer["throughputOut"];
}
if (consumer.containsKey("rateOut")) {
rateOut = consumer["rateOut"];
}
if (consumer.containsKey("availablePermits")) {
availablePermits = consumer["availablePermits"];
}
if (consumer.containsKey("unackedMessages")) {
unackedMessages = consumer["unackedMessages"];
}
if (consumer.containsKey("lastConsumedTimestamp")) {
lastConsumedTimestamp = consumer["lastConsumedTimestamp"];
}
ConsumerResp consumerResp = new ConsumerResp(
consumerName,
key,
rateOut,
throughputOut,
availablePermits,
unackedMessages,
lastConsumedTimestamp,
clientVersion,
address);
respList.add(consumerResp);
});
}
});
}
return respList;
}

static Future<List<ProducerResp>> getProducers(String host, int port,
String tenant, String namespace, String topic) async {
String data = "";
Expand All @@ -132,4 +199,42 @@ class PulsarTopicApi {
}
return respList;
}

static Future<PulsarTopicBaseResp> getBase(String host, int port,
String tenant, String namespace, String topic) async {
String data = "";
await PulsarStatApi.topicStats(host, port, tenant, namespace, topic)
.then((value) => {data = value});

Map statsMap = json.decode(data) as Map;
String topicName = topic;
int partitionNum = 0;
double msgRateIn = 0;
double msgRateOut = 0;
double msgInCounter = 0;
double msgOutCounter = 0;
double storageSize = 0;

if (statsMap.containsKey("metadata")) {
Map metadata = statsMap["metadata"] as Map;
partitionNum = metadata["partitions"];
}
if (statsMap.containsKey("msgRateIn")) {
msgRateIn = statsMap["msgRateIn"];
}
if (statsMap.containsKey("msgRateOut")) {
msgRateOut = statsMap["msgRateOut"];
}
if (statsMap.containsKey("msgInCounter")) {
msgInCounter = statsMap["msgInCounter"];
}
if (statsMap.containsKey("msgOutCounter")) {
msgOutCounter = statsMap["msgOutCounter"];
}
if (statsMap.containsKey("storageSize")) {
storageSize = statsMap["storageSize"];
}
return new PulsarTopicBaseResp(topicName, partitionNum, msgRateIn,
msgRateOut, msgInCounter, msgOutCounter, storageSize);
}
}
4 changes: 2 additions & 2 deletions lib/generated/intl/messages_en.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
// ignore_for_file:prefer_single_quotes,comment_references, directives_ordering
// ignore_for_file:annotate_overrides,prefer_generic_function_type_aliases
// ignore_for_file:unused_import, file_names, avoid_escaping_inner_quotes
// ignore_for_file:unnecessary_string_interpolations, unnecessary_string_escapes

import 'package:intl/intl.dart';
import 'package:intl/message_lookup_by_library.dart';
Expand All @@ -35,7 +34,7 @@ class MessageLookup extends MessageLookupByLibrary {
"confirmDeleteQuestion":
MessageLookupByLibrary.simpleMessage("ConfirmDelete?"),
"consume": MessageLookupByLibrary.simpleMessage("consume"),
"consumer": MessageLookupByLibrary.simpleMessage("consumer"),
"consumer": MessageLookupByLibrary.simpleMessage("Consumer"),
"consumerList": MessageLookupByLibrary.simpleMessage("Consumer List"),
"delete": MessageLookupByLibrary.simpleMessage("Delete"),
"deleteNamespace":
Expand Down Expand Up @@ -74,6 +73,7 @@ class MessageLookup extends MessageLookupByLibrary {
"tenant": MessageLookupByLibrary.simpleMessage("tenant"),
"tenantName": MessageLookupByLibrary.simpleMessage("Tenant Name"),
"tenants": MessageLookupByLibrary.simpleMessage("Tenants"),
"topicDetail": MessageLookupByLibrary.simpleMessage("topic detail"),
"topicName": MessageLookupByLibrary.simpleMessage("Topic Name"),
"topics": MessageLookupByLibrary.simpleMessage("Topics"),
"unit": MessageLookupByLibrary.simpleMessage("unit"),
Expand Down
2 changes: 1 addition & 1 deletion lib/generated/intl/messages_zh.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
// ignore_for_file:prefer_single_quotes,comment_references, directives_ordering
// ignore_for_file:annotate_overrides,prefer_generic_function_type_aliases
// ignore_for_file:unused_import, file_names, avoid_escaping_inner_quotes
// ignore_for_file:unnecessary_string_interpolations, unnecessary_string_escapes

import 'package:intl/intl.dart';
import 'package:intl/message_lookup_by_library.dart';
Expand Down Expand Up @@ -64,6 +63,7 @@ class MessageLookup extends MessageLookupByLibrary {
"tenant": MessageLookupByLibrary.simpleMessage("租户"),
"tenantName": MessageLookupByLibrary.simpleMessage("租户名称"),
"tenants": MessageLookupByLibrary.simpleMessage("租户列表"),
"topicDetail": MessageLookupByLibrary.simpleMessage("主题详情"),
"topicName": MessageLookupByLibrary.simpleMessage("Topic 名称"),
"topics": MessageLookupByLibrary.simpleMessage("Topic 列表"),
"unit": MessageLookupByLibrary.simpleMessage("单位"),
Expand Down
14 changes: 12 additions & 2 deletions lib/generated/l10n.dart

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

3 changes: 2 additions & 1 deletion lib/l10n/intl_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"confirmClearBacklog": "ConfirmClear?",
"confirmDeleteQuestion": "ConfirmDelete?",
"consume": "consume",
"consumer": "consumer",
"consumer": "Consumer",
"consumerList": "Consumer List",
"delete": "Delete",
"deleteNamespace": "Delete Namespace",
Expand Down Expand Up @@ -42,6 +42,7 @@
"tenant": "tenant",
"tenantName": "Tenant Name",
"tenants": "Tenants",
"topicDetail": "topic detail",
"topicName": "Topic Name",
"topics": "Topics",
"unit": "unit",
Expand Down
1 change: 1 addition & 0 deletions lib/l10n/intl_zh.arb
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
"tenant": "租户",
"tenantName": "租户名称",
"tenants": "租户列表",
"topicDetail": "主题详情",
"topicName": "Topic 名称",
"topics": "Topic 列表",
"unit": "单位",
Expand Down
35 changes: 35 additions & 0 deletions lib/module/pulsar/pulsar_consume.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
class ConsumerResp {
final String consumerName;
final String subscriptionName;
final double rateOut;
final double throughputOut;
final double availablePermits;
final double unackedMessages;
final double lastConsumedTimestamp;
final String clientVersion;
final String address;

ConsumerResp(
this.consumerName,
this.subscriptionName,
this.rateOut,
this.throughputOut,
this.availablePermits,
this.unackedMessages,
this.lastConsumedTimestamp,
this.clientVersion,
this.address);

ConsumerResp deepCopy() {
return new ConsumerResp(
consumerName,
subscriptionName,
rateOut,
throughputOut,
availablePermits,
unackedMessages,
lastConsumedTimestamp,
clientVersion,
address);
}
}
Loading

0 comments on commit daf03c6

Please sign in to comment.