Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

optimize backlog quota modify #19

Merged
merged 1 commit into from
Dec 11, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion lib/api/pulsar/pulsar_namespace_api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,11 @@ class PulsarNamespaceApi {
'ErrorCode is ${response.statusCode}, body is ${response.body}');
}
Map jsonResponse = json.decode(response.body) as Map;
return BacklogQuotaResp.fromJson(jsonResponse["destination_storage"]);
var destinationStorageResp = jsonResponse["destination_storage"];
if (destinationStorageResp == null) {
return new BacklogQuotaResp(null, null, null);
}
return BacklogQuotaResp.fromJson(destinationStorageResp);
}

static Future<void> updateBacklogQuota(String host, int port, String tenant,
Expand Down
4 changes: 4 additions & 0 deletions lib/generated/intl/messages_en.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
// 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 @@ -25,6 +26,7 @@ class MessageLookup extends MessageLookupByLibrary {
"appName": MessageLookupByLibrary.simpleMessage("Paas Dashboard"),
"basic": MessageLookupByLibrary.simpleMessage("Basic"),
"brokersName": MessageLookupByLibrary.simpleMessage("Broker Instance"),
"byte": MessageLookupByLibrary.simpleMessage("byte"),
"cancel": MessageLookupByLibrary.simpleMessage("Cancel"),
"clearBacklog": MessageLookupByLibrary.simpleMessage("Clear Backlog"),
"confirm": MessageLookupByLibrary.simpleMessage("Confirm"),
Expand Down Expand Up @@ -61,6 +63,7 @@ class MessageLookup extends MessageLookupByLibrary {
MessageLookupByLibrary.simpleMessage("Search by Tenant Name"),
"searchByTopic":
MessageLookupByLibrary.simpleMessage("Search by Topic Name"),
"second": MessageLookupByLibrary.simpleMessage("second"),
"settings": MessageLookupByLibrary.simpleMessage("Settings"),
"submit": MessageLookupByLibrary.simpleMessage("Submit"),
"subscription": MessageLookupByLibrary.simpleMessage("subscription"),
Expand All @@ -73,6 +76,7 @@ class MessageLookup extends MessageLookupByLibrary {
"tenants": MessageLookupByLibrary.simpleMessage("Tenants"),
"topicName": MessageLookupByLibrary.simpleMessage("Topic Name"),
"topics": MessageLookupByLibrary.simpleMessage("Topics"),
"unit": MessageLookupByLibrary.simpleMessage("unit"),
"versionName": MessageLookupByLibrary.simpleMessage("Version")
};
}
4 changes: 4 additions & 0 deletions lib/generated/intl/messages_zh.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
// 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 @@ -25,6 +26,7 @@ class MessageLookup extends MessageLookupByLibrary {
"appName": MessageLookupByLibrary.simpleMessage("Paas 仪表盘"),
"basic": MessageLookupByLibrary.simpleMessage("基础信息"),
"brokersName": MessageLookupByLibrary.simpleMessage("Pulsar 实例"),
"byte": MessageLookupByLibrary.simpleMessage("比特"),
"cancel": MessageLookupByLibrary.simpleMessage("取消"),
"clearBacklog": MessageLookupByLibrary.simpleMessage("清理积压"),
"confirm": MessageLookupByLibrary.simpleMessage("确认"),
Expand Down Expand Up @@ -53,6 +55,7 @@ class MessageLookup extends MessageLookupByLibrary {
"searchByNamespace": MessageLookupByLibrary.simpleMessage("按命名空间名称搜索"),
"searchByTenant": MessageLookupByLibrary.simpleMessage("按租户名称搜索"),
"searchByTopic": MessageLookupByLibrary.simpleMessage("按 Topic 名称搜索"),
"second": MessageLookupByLibrary.simpleMessage("秒"),
"settings": MessageLookupByLibrary.simpleMessage("设置"),
"submit": MessageLookupByLibrary.simpleMessage("提交"),
"subscription": MessageLookupByLibrary.simpleMessage("订阅"),
Expand All @@ -63,6 +66,7 @@ class MessageLookup extends MessageLookupByLibrary {
"tenants": MessageLookupByLibrary.simpleMessage("租户列表"),
"topicName": MessageLookupByLibrary.simpleMessage("Topic 名称"),
"topics": MessageLookupByLibrary.simpleMessage("Topic 列表"),
"unit": MessageLookupByLibrary.simpleMessage("单位"),
"versionName": MessageLookupByLibrary.simpleMessage("版本")
};
}
30 changes: 30 additions & 0 deletions lib/generated/l10n.dart

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

3 changes: 3 additions & 0 deletions lib/l10n/intl_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"appName": "Paas Dashboard",
"basic": "Basic",
"brokersName": "Broker Instance",
"byte": "byte",
"cancel": "Cancel",
"clearBacklog": "Clear Backlog",
"confirm": "Confirm",
Expand Down Expand Up @@ -31,6 +32,7 @@
"searchByNamespace": "Search by Namespace Name",
"searchByTenant": "Search by Tenant Name",
"searchByTopic": "Search by Topic Name",
"second": "second",
"settings": "Settings",
"submit": "Submit",
"subscription": "subscription",
Expand All @@ -41,5 +43,6 @@
"tenants": "Tenants",
"topicName": "Topic Name",
"topics": "Topics",
"unit": "unit",
"versionName": "Version"
}
3 changes: 3 additions & 0 deletions lib/l10n/intl_zh.arb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"appName": "Paas 仪表盘",
"basic": "基础信息",
"brokersName": "Pulsar 实例",
"byte": "比特",
"cancel": "取消",
"clearBacklog": "清理积压",
"confirm": "确认",
Expand Down Expand Up @@ -31,6 +32,7 @@
"searchByNamespace": "按命名空间名称搜索",
"searchByTenant": "按租户名称搜索",
"searchByTopic": "按 Topic 名称搜索",
"second": "秒",
"settings": "设置",
"submit": "提交",
"subscription": "订阅",
Expand All @@ -41,5 +43,6 @@
"tenants": "租户列表",
"topicName": "Topic 名称",
"topics": "Topic 列表",
"unit": "单位",
"versionName": "版本"
}
2 changes: 1 addition & 1 deletion lib/ui/pulsar/screen/pulsar_namespace.dart
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class PulsarNamespaceScreenState extends State<PulsarNamespaceScreen> {
child: Scaffold(
appBar: AppBar(
title: Text(
'Pulsar ${S.of(context).tenant} ${S.of(context).tenant} ${vm.tenant} -> ${S.of(context).namespace} ${vm.namespace}'),
'Pulsar ${S.of(context).tenant} ${vm.tenant} -> ${S.of(context).namespace} ${vm.namespace}'),
bottom: TabBar(
tabs: [
Tab(text: "BacklogQuota"),
Expand Down
71 changes: 33 additions & 38 deletions lib/ui/pulsar/widget/pulsar_namespace_backlog_quota.dart
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,17 @@ class PulsarNamespaceBacklogQuotaWidgetState extends State<PulsarNamespaceBacklo
}
ExceptionUtil.processLoadException(vm, context);
ExceptionUtil.processLoadException(vm, context);
var formButton = modifyBacklogQuotaButton(context);
var limitSizeEditingController = TextEditingController(text: vm.limitSizeDisplayStr);
var limitTimeEditingController = TextEditingController(text: vm.limitTimeDisplayStr);
var policyEditingController = TextEditingController(text: vm.retentionPolicyDisplayStr);
var formButton = TextButton(
onPressed: () {
vm.limitSizeDisplayStr = limitSizeEditingController.value.text;
vm.limitTimeDisplayStr = limitTimeEditingController.value.text;
vm.retentionPolicyDisplayStr = policyEditingController.value.text;
vm.updateBacklogQuota();
},
child: Text(S.of(context).submit));
var refreshButton = TextButton(
onPressed: () {
vm.fetchBacklogQuota();
Expand All @@ -57,55 +67,40 @@ class PulsarNamespaceBacklogQuotaWidgetState extends State<PulsarNamespaceBacklo
),
Container(
height: 50,
child: ListView(
scrollDirection: Axis.horizontal,
shrinkWrap: true,
children: [
Text(
'LimitSize is ${vm.limitSizeDisplayStr}',
style: new TextStyle(fontSize: 20),
),
],
child: TextFormField(
decoration: InputDecoration(labelText: "LimitSize"),
controller: limitSizeEditingController,
),
),
Container(
child: Text("${S.of(context).unit}: ${S.of(context).byte}"),
),
Container(
height: 50,
child: ListView(
scrollDirection: Axis.horizontal,
shrinkWrap: true,
children: [
Text(
'LimitTime is ${vm.limitTimeDisplayStr}',
style: new TextStyle(fontSize: 20),
),
],
child: TextFormField(
decoration: InputDecoration(labelText: "LimitTime"),
controller: limitTimeEditingController,
),
),
Container(
child: Text("${S.of(context).unit}: ${S.of(context).second}"),
),
Container(
height: 50,
child: ListView(
scrollDirection: Axis.horizontal,
shrinkWrap: true,
children: [
Text(
'Policy is ${vm.retentionPolicyDisplayStr}',
style: new TextStyle(fontSize: 20),
),
],
child: TextFormField(
decoration: InputDecoration(labelText: "Policy"),
controller: policyEditingController,
),
),
Container(
child: SelectableText(
"Policy enum: {producer_request_hold, producer_exception, consumer_backlog_eviction}",
toolbarOptions: ToolbarOptions(
paste: true
),),
),
],
);
return body;
}

ButtonStyleButton modifyBacklogQuotaButton(BuildContext context) {
var list = [FormFieldDef('New Limit Size'), FormFieldDef('New Limit Time'), FormFieldDef('New Policy')];
return FormUtil.updateButton3("New Backlog Quota", list, context,
(limitSize, limitTime, policy) async {
final vm = Provider.of<PulsarNamespaceBacklogQuotaViewModel>(context,
listen: false);
vm.updateBacklogQuota(limitSize, limitTime, policy);
});
}
}
37 changes: 29 additions & 8 deletions lib/vm/pulsar/pulsar_namespace_backlog_quota_view_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,13 @@ class PulsarNamespaceBacklogQuotaViewModel extends BaseLoadViewModel {
return this.namespaceResp.namespace;
}

set limitSizeDisplayStr(String displayStr) {
if (displayStr == "unset") {
return;
}
this.limitSize = int.parse(displayStr);
}

String get limitSizeDisplayStr {
if (loading) {
return "loading";
Expand All @@ -54,6 +61,13 @@ class PulsarNamespaceBacklogQuotaViewModel extends BaseLoadViewModel {
return limitSize!.toString();
}

set limitTimeDisplayStr(String displayStr) {
if (displayStr == "unset") {
return;
}
this.limitTime = int.parse(displayStr);
}

String get limitTimeDisplayStr {
if (loading) {
return "loading";
Expand All @@ -64,6 +78,13 @@ class PulsarNamespaceBacklogQuotaViewModel extends BaseLoadViewModel {
return limitTime!.toString();
}

set retentionPolicyDisplayStr(String displayStr) {
if (displayStr == "unset") {
return;
}
this.retentionPolicy = displayStr;
}

String get retentionPolicyDisplayStr {
if (loading) {
return "loading";
Expand All @@ -89,16 +110,16 @@ class PulsarNamespaceBacklogQuotaViewModel extends BaseLoadViewModel {
notifyListeners();
}

Future<void> updateBacklogQuota(
String limit, String limitTime, String policy) async {
Future<void> updateBacklogQuota() async {
try {
if (limitTime == "") {
await PulsarNamespaceApi.updateBacklogQuota(
host, port, tenant, namespace, int.parse(limit), null, policy);
} else {
await PulsarNamespaceApi.updateBacklogQuota(host, port, tenant,
namespace, int.parse(limit), int.parse(limitTime), policy);
if (limitSize == null) {
return;
}
if (retentionPolicy == null) {
return;
}
await PulsarNamespaceApi.updateBacklogQuota(host, port, tenant, namespace,
limitSize!, limitTime, retentionPolicy!);
await fetchBacklogQuota();
} on Exception catch (e) {
opException = e;
Expand Down