From a1c13ca32d6460da3c92ce068af4eb9838e7eb94 Mon Sep 17 00:00:00 2001 From: ZhangJian He Date: Wed, 1 Dec 2021 15:56:15 +0800 Subject: [PATCH] Rename typo APi to Api (#13) --- lib/api/pulsar/pulsar_cluster_api.dart | 4 +- lib/api/pulsar/pulsar_namespace_api.dart | 2 +- .../pulsar/pulsar_partitioned_topic_api.dart | 10 ++--- lib/api/pulsar/pulsar_sink_api.dart | 24 +++++++++++- lib/api/pulsar/pulsar_source_api.dart | 22 ++++++++++- lib/api/pulsar/pulsar_stat_api.dart | 2 +- lib/api/pulsar/pulsar_tenant_api.dart | 2 +- lib/api/pulsar/pulsar_topic_api.dart | 8 ++-- lib/module/pulsar/pulsar_sink.dart | 37 +++++++++++++++++++ lib/module/pulsar/pulsar_source.dart | 23 ++++++++++++ lib/persistent/persistent_db.dart | 6 +-- lib/persistent/persistent_memory.dart | 2 +- lib/ui/pulsar/widget/pulsar_sink_list.dart | 33 ++++++++++++++--- lib/ui/pulsar/widget/pulsar_source_list.dart | 26 ++++++++++++- lib/ui/pulsar/widget/pulsar_topic_list.dart | 4 +- lib/vm/pulsar/pulsar_cluster_view_model.dart | 2 +- lib/vm/pulsar/pulsar_instance_view_model.dart | 6 +-- .../pulsar/pulsar_namespace_view_model.dart | 6 +-- ...ar_partitioned_topic_basic_view_model.dart | 4 +- ...r_partitioned_topic_detail_view_model.dart | 2 +- ...sar_partitioned_topic_list_view_model.dart | 6 +-- ..._partitioned_topic_produce_view_model.dart | 2 +- ...itioned_topic_subscription_view_model.dart | 4 +- .../pulsar/pulsar_sink_list_view_model.dart | 24 +++++++++++- .../pulsar/pulsar_source_list_view_model.dart | 28 ++++++++++++-- lib/vm/pulsar/pulsar_tenant_view_model.dart | 6 +-- .../pulsar/pulsar_topic_list_view_model.dart | 6 +-- .../pulsar_topic_produce_view_model.dart | 2 +- .../pulsar_topic_subscription_view_model.dart | 4 +- pubspec.lock | 7 ++++ pubspec.yaml | 1 + .../pulsar/pulsar_sink_api_create_test.dart | 9 +++++ ...pulsar_topic_api_fetch_producers_test.dart | 2 +- ...ar_topic_api_fetch_subscriptions_test.dart | 2 +- 34 files changed, 266 insertions(+), 62 deletions(-) create mode 100644 test/api/pulsar/pulsar_sink_api_create_test.dart diff --git a/lib/api/pulsar/pulsar_cluster_api.dart b/lib/api/pulsar/pulsar_cluster_api.dart index 61fc863..6bb0c1f 100644 --- a/lib/api/pulsar/pulsar_cluster_api.dart +++ b/lib/api/pulsar/pulsar_cluster_api.dart @@ -6,11 +6,11 @@ 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 { +class PulsarClusterApi { static Future> cluster(String host, int port) async { String version = await getVersion(host, port); String tenantInfo = - await PulsarTenantAPi.getTenantInfo(host, port, "public"); + await PulsarTenantApi.getTenantInfo(host, port, "public"); String cluster = ((json.decode(tenantInfo) as Map)["allowedClusters"] as List)[0]; String url = 'http://$host:${port.toString()}/admin/v2/brokers/$cluster'; diff --git a/lib/api/pulsar/pulsar_namespace_api.dart b/lib/api/pulsar/pulsar_namespace_api.dart index 0377635..637b7f5 100644 --- a/lib/api/pulsar/pulsar_namespace_api.dart +++ b/lib/api/pulsar/pulsar_namespace_api.dart @@ -5,7 +5,7 @@ import 'package:http/http.dart' as http; import 'package:paas_dashboard_flutter/api/http_util.dart'; import 'package:paas_dashboard_flutter/module/pulsar/pulsar_namespace.dart'; -class PulsarNamespaceAPi { +class PulsarNamespaceApi { static Future createNamespace(String host, int port, String tenant, String namespace) async { var url = 'http://$host:${port.toString()}/admin/v2/namespaces/$tenant/$namespace'; diff --git a/lib/api/pulsar/pulsar_partitioned_topic_api.dart b/lib/api/pulsar/pulsar_partitioned_topic_api.dart index 6321d84..497aa88 100644 --- a/lib/api/pulsar/pulsar_partitioned_topic_api.dart +++ b/lib/api/pulsar/pulsar_partitioned_topic_api.dart @@ -10,7 +10,7 @@ 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 PulsarPartitionedTopicAPi { +class PulsarPartitionedTopicApi { static Future createPartitionTopic(String host, int port, String tenant, String namespace, String topic, int partitionNum) async { var url = @@ -77,7 +77,7 @@ class PulsarPartitionedTopicAPi { static Future> getSubscription(String host, int port, String tenant, String namespace, String topic) async { String data = ""; - await PulsarStatAPi.partitionedTopicStats( + await PulsarStatApi.partitionedTopicStats( host, port, tenant, namespace, topic) .then((value) => {data = value}); List respList = new List.empty(growable: true); @@ -115,7 +115,7 @@ class PulsarPartitionedTopicAPi { String namespace, String topic, String subscription) async { - String data = PulsarStatAPi.partitionedTopicStats( + String data = PulsarStatApi.partitionedTopicStats( host, port, tenant, namespace, topic) as String; Map statsMap = json.decode(data) as Map; @@ -133,7 +133,7 @@ class PulsarPartitionedTopicAPi { static Future> getProducers(String host, int port, String tenant, String namespace, String topic) async { String data = ""; - await PulsarStatAPi.partitionedTopicStats( + await PulsarStatApi.partitionedTopicStats( host, port, tenant, namespace, topic) .then((value) => {data = value}); List respList = new List.empty(growable: true); @@ -158,7 +158,7 @@ class PulsarPartitionedTopicAPi { static Future> getDetails(String host, int port, String tenant, String namespace, String topic) async { String data = ""; - await PulsarStatAPi.partitionedTopicStats( + await PulsarStatApi.partitionedTopicStats( host, port, tenant, namespace, topic) .then((value) => {data = value}); List respList = diff --git a/lib/api/pulsar/pulsar_sink_api.dart b/lib/api/pulsar/pulsar_sink_api.dart index 3f82590..1bc09e8 100644 --- a/lib/api/pulsar/pulsar_sink_api.dart +++ b/lib/api/pulsar/pulsar_sink_api.dart @@ -1,11 +1,33 @@ import 'dart:convert'; import 'dart:developer'; +import 'package:clipboard/clipboard.dart'; import 'package:http/http.dart' as http; import 'package:paas_dashboard_flutter/api/http_util.dart'; import 'package:paas_dashboard_flutter/module/pulsar/pulsar_sink.dart'; -class PulsarSinkAPi { +class PulsarSinkApi { + static Future createSink( + String host, + int port, + String tenant, + String namespace, + String sinkName, + String subName, + String inputTopic, + String sinkType, + String config) async { + String url = + 'http://$host:${port.toString()}/admin/v3/sinks/$tenant/$namespace/$sinkName'; + List inputs = [inputTopic]; + SinkConfigReq sinkConfigReq = new SinkConfigReq(tenant, namespace, sinkName, + subName, inputs, json.decode(config), "builtin://$sinkType"); + String curlCommand = "curl '$url' -F sinkConfig='" + + jsonEncode(sinkConfigReq) + + ";type=application/json'"; + await FlutterClipboard.copy(curlCommand); + } + static Future deleteSink(String host, int port, String tenant, String namespace, String sinkName) async { var url = diff --git a/lib/api/pulsar/pulsar_source_api.dart b/lib/api/pulsar/pulsar_source_api.dart index e49a4dc..7721ef6 100644 --- a/lib/api/pulsar/pulsar_source_api.dart +++ b/lib/api/pulsar/pulsar_source_api.dart @@ -1,11 +1,31 @@ import 'dart:convert'; import 'dart:developer'; +import 'package:clipboard/clipboard.dart'; import 'package:http/http.dart' as http; import 'package:paas_dashboard_flutter/api/http_util.dart'; import 'package:paas_dashboard_flutter/module/pulsar/pulsar_source.dart'; -class PulsarSourceAPi { +class PulsarSourceApi { + static Future createSource( + String host, + int port, + String tenant, + String namespace, + String sourceName, + String outputTopic, + String sourceType, + String config) async { + String url = + 'http://$host:${port.toString()}/admin/v3/sinks/$tenant/$namespace/$sourceName'; + SourceConfigReq sinkConfigReq = new SourceConfigReq(sourceName, tenant, namespace, outputTopic, + json.decode(config), "builtin://$sourceType"); + String curlCommand = "curl '$url' -F sourceConfig='" + + jsonEncode(sinkConfigReq) + + ";type=application/json'"; + await FlutterClipboard.copy(curlCommand); + } + static Future deleteSource(String host, int port, String tenant, String namespace, String sourceName) async { var url = diff --git a/lib/api/pulsar/pulsar_stat_api.dart b/lib/api/pulsar/pulsar_stat_api.dart index 9666428..dc2d8f6 100644 --- a/lib/api/pulsar/pulsar_stat_api.dart +++ b/lib/api/pulsar/pulsar_stat_api.dart @@ -3,7 +3,7 @@ import 'dart:developer'; import 'package:http/http.dart' as http; import 'package:paas_dashboard_flutter/api/http_util.dart'; -class PulsarStatAPi { +class PulsarStatApi { static Future partitionedTopicStats(String host, int port, String tenant, String namespace, String topic) async { var url = diff --git a/lib/api/pulsar/pulsar_tenant_api.dart b/lib/api/pulsar/pulsar_tenant_api.dart index f0077f8..d9d666f 100644 --- a/lib/api/pulsar/pulsar_tenant_api.dart +++ b/lib/api/pulsar/pulsar_tenant_api.dart @@ -5,7 +5,7 @@ import 'package:http/http.dart' as http; import 'package:paas_dashboard_flutter/api/http_util.dart'; import 'package:paas_dashboard_flutter/module/pulsar/pulsar_tenant.dart'; -class PulsarTenantAPi { +class PulsarTenantApi { static Future createTenant(String host, int port, String tenant) async { String tenantInfo = ""; await getTenantInfo(host, port, tenant).then((value) => tenantInfo = value); diff --git a/lib/api/pulsar/pulsar_topic_api.dart b/lib/api/pulsar/pulsar_topic_api.dart index 73a44a5..392d18d 100644 --- a/lib/api/pulsar/pulsar_topic_api.dart +++ b/lib/api/pulsar/pulsar_topic_api.dart @@ -9,7 +9,7 @@ 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 PulsarTopicApi { static Future createTopic(String host, int port, String tenant, String namespace, String topic) async { var url = @@ -57,7 +57,7 @@ class PulsarTopicAPi { static Future> getSubscription(String host, int port, String tenant, String namespace, String topic) async { String data = ""; - await PulsarStatAPi.topicStats(host, port, tenant, namespace, topic) + await PulsarStatApi.topicStats(host, port, tenant, namespace, topic) .then((value) => {data = value}); List respList = new List.empty(growable: true); Map statsMap = json.decode(data) as Map; @@ -94,7 +94,7 @@ class PulsarTopicAPi { String namespace, String topic, String subscription) async { - String data = PulsarStatAPi.topicStats(host, port, tenant, namespace, topic) + String data = PulsarStatApi.topicStats(host, port, tenant, namespace, topic) as String; Map statsMap = json.decode(data) as Map; @@ -112,7 +112,7 @@ class PulsarTopicAPi { static Future> getProducers(String host, int port, String tenant, String namespace, String topic) async { String data = ""; - await PulsarStatAPi.topicStats(host, port, tenant, namespace, topic) + await PulsarStatApi.topicStats(host, port, tenant, namespace, topic) .then((value) => {data = value}); List respList = new List.empty(growable: true); Map statsMap = json.decode(data) as Map; diff --git a/lib/module/pulsar/pulsar_sink.dart b/lib/module/pulsar/pulsar_sink.dart index 68c08a8..fe81410 100644 --- a/lib/module/pulsar/pulsar_sink.dart +++ b/lib/module/pulsar/pulsar_sink.dart @@ -1,3 +1,28 @@ +class SinkConfigReq { + final String name; + final String tenant; + final String namespace; + final String sourceSubscriptionName; + final List inputs; + final Map configs; + final String archive; + + SinkConfigReq(this.tenant, this.namespace, this.name, + this.sourceSubscriptionName, this.inputs, this.configs, this.archive); + + Map toJson() { + Map map = new Map(); + map["name"] = this.name; + map["tenant"] = this.tenant; + map["namespace"] = this.namespace; + map["sourceSubscriptionName"] = this.sourceSubscriptionName; + map["inputs"] = this.inputs; + map["configs"] = this.configs; + map["archive"] = this.archive; + return map; + } +} + class SinkResp { final String sinkName; @@ -7,3 +32,15 @@ class SinkResp { return new SinkResp(this.sinkName); } } + +class PulsarSink { + final String serviceUrl; + + PulsarSink(this.serviceUrl); + + Map toJson() { + Map map = new Map(); + map["serviceUrl"] = this.serviceUrl; + return map; + } +} diff --git a/lib/module/pulsar/pulsar_source.dart b/lib/module/pulsar/pulsar_source.dart index dcc1c77..51aa877 100644 --- a/lib/module/pulsar/pulsar_source.dart +++ b/lib/module/pulsar/pulsar_source.dart @@ -1,3 +1,26 @@ +class SourceConfigReq { + final String name; + final String tenant; + final String namespace; + final String topicName; + final Map configs; + final String archive; + + SourceConfigReq(this.name, this.tenant, this.namespace, this.topicName, + this.configs, this.archive); + + Map toJson() { + Map map = new Map(); + map["name"] = this.name; + map["tenant"] = this.tenant; + map["namespace"] = this.namespace; + map["topicName"] = this.topicName; + map["configs"] = this.configs; + map["archive"] = this.archive; + return map; + } +} + class SourceResp { final String sourceName; diff --git a/lib/persistent/persistent_db.dart b/lib/persistent/persistent_db.dart index 7568c45..7ecb01a 100644 --- a/lib/persistent/persistent_db.dart +++ b/lib/persistent/persistent_db.dart @@ -48,10 +48,10 @@ class PersistentDb implements PersistentApi { static initTable(Database db) async { log('init tables start'); await db.execute( - 'CREATE TABLE pulsar_instances(id INTEGER PRIMARY KEY, name TEXT, broker_host TEXT, broker_port INTEGER, function_host TEXT, function_port INTEGER)', + 'CREATE TABLE pulsar_instances(id INTEGER PRIMARY KEY, name TEXT, host TEXT, port INTEGER, function_host TEXT, function_port INTEGER)', ); await db.execute( - 'INSERT INTO pulsar_instances(name, host, port) VALUES ("example", "localhost", 8080)', + 'INSERT INTO pulsar_instances(name, host, port, function_host, function_port) VALUES ("example", "localhost", 8080, "localhost", 8080)', ); await db.execute( 'CREATE TABLE bookkeeper_instances(id INTEGER PRIMARY KEY, name TEXT, host TEXT, port INTEGER)', @@ -64,7 +64,7 @@ class PersistentDb implements PersistentApi { @override Future savePulsar(String name, String host, int port, String functionHost, int functionPort) async { var aux = await getInstance(); - var list = [name, host, port]; + var list = [name, host, port, functionHost, functionPort]; aux.database.execute( 'INSERT INTO pulsar_instances(name, host, port, function_host, function_port) VALUES (?, ?, ?, ?, ?)', list); diff --git a/lib/persistent/persistent_memory.dart b/lib/persistent/persistent_memory.dart index 6dac87a..8fa5486 100644 --- a/lib/persistent/persistent_memory.dart +++ b/lib/persistent/persistent_memory.dart @@ -17,7 +17,7 @@ class PersistentMemory implements PersistentApi { @override Future> pulsarInstances() async { - return [new PulsarInstancePo(0, "example", "localhost", 8080, "localhost", 6650)]; + return [new PulsarInstancePo(0, "example", "localhost", 8080, "localhost", 8080)]; } @override diff --git a/lib/ui/pulsar/widget/pulsar_sink_list.dart b/lib/ui/pulsar/widget/pulsar_sink_list.dart index 938d4ef..21bca53 100644 --- a/lib/ui/pulsar/widget/pulsar_sink_list.dart +++ b/lib/ui/pulsar/widget/pulsar_sink_list.dart @@ -4,6 +4,7 @@ import 'package:paas_dashboard_flutter/route/page_route_const.dart'; import 'package:paas_dashboard_flutter/ui/component/searchable_title.dart'; import 'package:paas_dashboard_flutter/ui/util/data_cell_util.dart'; import 'package:paas_dashboard_flutter/ui/util/exception_util.dart'; +import 'package:paas_dashboard_flutter/ui/util/form_util.dart'; import 'package:paas_dashboard_flutter/ui/util/spinner_util.dart'; import 'package:paas_dashboard_flutter/vm/pulsar/pulsar_sink_list_view_model.dart'; import 'package:provider/provider.dart'; @@ -54,10 +55,10 @@ class PulsarSinkListWidgetState extends State { }, cells: [ DataCell( - Text(item.sinkName), + Text(item.name), ), DataCellUtil.newDellDataCell(() { - vm.deleteSink(item.sinkName); + vm.deleteSink(item.name); }), ])); var topicsTable = SingleChildScrollView( @@ -69,6 +70,7 @@ class PulsarSinkListWidgetState extends State { ], source: vm), ); + var formButton = createSinkButton(context); var refreshButton = TextButton( onPressed: () { vm.fetchSinks(); @@ -81,14 +83,35 @@ class PulsarSinkListWidgetState extends State { child: ListView( scrollDirection: Axis.horizontal, shrinkWrap: true, - children: [refreshButton], + children: [formButton, refreshButton], ), ), - SearchableTitle("sink list", "search by sink name", - searchTextController), + SearchableTitle( + "sink list", "search by sink name", searchTextController), topicsTable ], ); return body; } + + ButtonStyleButton createSinkButton(BuildContext context) { + var list = [ + FormFieldDef('Sink Name'), + FormFieldDef('Sub Name'), + FormFieldDef('Input Topic'), + FormFieldDef('Sink type'), + FormFieldDef('Config') + ]; + return FormUtil.createButton5("Sink", list, context, + (sinkName, subName, inputTopic, sinkType, config) async { + final vm = Provider.of(context, listen: false); + vm.createSink(sinkName, subName, inputTopic, sinkType, config); + final scaffold = ScaffoldMessenger.of(context); + scaffold.showSnackBar( + SnackBar( + content: const Text('Dart 目前不支持复杂ContentType请求,Curl命令已复制到剪切版'), + ), + ); + }); + } } diff --git a/lib/ui/pulsar/widget/pulsar_source_list.dart b/lib/ui/pulsar/widget/pulsar_source_list.dart index 6051f0c..f06ae7f 100644 --- a/lib/ui/pulsar/widget/pulsar_source_list.dart +++ b/lib/ui/pulsar/widget/pulsar_source_list.dart @@ -3,6 +3,7 @@ import 'package:paas_dashboard_flutter/generated/l10n.dart'; import 'package:paas_dashboard_flutter/ui/component/searchable_title.dart'; import 'package:paas_dashboard_flutter/ui/util/data_cell_util.dart'; import 'package:paas_dashboard_flutter/ui/util/exception_util.dart'; +import 'package:paas_dashboard_flutter/ui/util/form_util.dart'; import 'package:paas_dashboard_flutter/ui/util/spinner_util.dart'; import 'package:paas_dashboard_flutter/vm/pulsar/pulsar_source_list_view_model.dart'; import 'package:provider/provider.dart'; @@ -62,9 +63,10 @@ class PulsarSourceListWidgetState extends State { ], source: vm), ); + var formButton = createSourceButton(context); var refreshButton = TextButton( onPressed: () { - vm.fetchTopics(); + vm.fetchSources(); }, child: Text(S.of(context).refresh)); var body = ListView( @@ -74,7 +76,7 @@ class PulsarSourceListWidgetState extends State { child: ListView( scrollDirection: Axis.horizontal, shrinkWrap: true, - children: [refreshButton], + children: [formButton, refreshButton], ), ), SearchableTitle("source list", "search by source name", @@ -84,4 +86,24 @@ class PulsarSourceListWidgetState extends State { ); return body; } + + ButtonStyleButton createSourceButton(BuildContext context) { + var list = [ + FormFieldDef('Source Name'), + FormFieldDef('Output Topic'), + FormFieldDef('Source type'), + FormFieldDef('Config') + ]; + return FormUtil.createButton4("Source", list, context, + (sourceName, outputTopic, sourceType, config) async { + final vm = Provider.of(context, listen: false); + vm.createSource(sourceName, outputTopic, sourceType, config); + final scaffold = ScaffoldMessenger.of(context); + scaffold.showSnackBar( + SnackBar( + content: const Text('Dart 目前不支持复杂ContentType请求,Curl命令已复制到剪切版'), + ), + ); + }); + } } diff --git a/lib/ui/pulsar/widget/pulsar_topic_list.dart b/lib/ui/pulsar/widget/pulsar_topic_list.dart index f6a18a9..31439ea 100644 --- a/lib/ui/pulsar/widget/pulsar_topic_list.dart +++ b/lib/ui/pulsar/widget/pulsar_topic_list.dart @@ -69,7 +69,7 @@ class PulsarTopicListWidgetState extends State { ], source: vm), ); - var formButton = createPartitionTopicButton(context); + var formButton = createTopicButton(context); var refreshButton = TextButton( onPressed: () { vm.fetchTopics(); @@ -93,7 +93,7 @@ class PulsarTopicListWidgetState extends State { return body; } - ButtonStyleButton createPartitionTopicButton(BuildContext context) { + ButtonStyleButton createTopicButton(BuildContext context) { var list = [FormFieldDef('Topic Name')]; return FormUtil.createButton1("Topic", list, context, (topic) async { final vm = Provider.of(context, listen: false); diff --git a/lib/vm/pulsar/pulsar_cluster_view_model.dart b/lib/vm/pulsar/pulsar_cluster_view_model.dart index 3d77962..39a4071 100644 --- a/lib/vm/pulsar/pulsar_cluster_view_model.dart +++ b/lib/vm/pulsar/pulsar_cluster_view_model.dart @@ -28,7 +28,7 @@ class PulsarClusterViewModel extends BaseLoadListPageViewModel { Future fetchPulsarCluster() async { try { - this.fullList = await PulsarClusterAPi.cluster(host, port); + this.fullList = await PulsarClusterApi.cluster(host, port); this.displayList = this.fullList; loadSuccess(); } on Exception catch (e) { diff --git a/lib/vm/pulsar/pulsar_instance_view_model.dart b/lib/vm/pulsar/pulsar_instance_view_model.dart index dac4e8e..a2f917a 100644 --- a/lib/vm/pulsar/pulsar_instance_view_model.dart +++ b/lib/vm/pulsar/pulsar_instance_view_model.dart @@ -41,7 +41,7 @@ class PulsarInstanceViewModel Future fetchTenants() async { try { - final results = await PulsarTenantAPi.getTenants(host, port); + final results = await PulsarTenantApi.getTenants(host, port); this.fullList = results .map((e) => PulsarTenantViewModel(pulsarInstancePo, e)) .toList(); @@ -72,7 +72,7 @@ class PulsarInstanceViewModel Future createTenant(String tenant) async { try { - await PulsarTenantAPi.createTenant(host, port, tenant); + await PulsarTenantApi.createTenant(host, port, tenant); await fetchTenants(); } on Exception catch (e) { opException = e; @@ -82,7 +82,7 @@ class PulsarInstanceViewModel Future deleteTenants(String tenant) async { try { - await PulsarTenantAPi.deleteTenant(host, port, tenant); + await PulsarTenantApi.deleteTenant(host, port, tenant); await fetchTenants(); } on Exception catch (e) { opException = e; diff --git a/lib/vm/pulsar/pulsar_namespace_view_model.dart b/lib/vm/pulsar/pulsar_namespace_view_model.dart index 349131e..63d3cca 100644 --- a/lib/vm/pulsar/pulsar_namespace_view_model.dart +++ b/lib/vm/pulsar/pulsar_namespace_view_model.dart @@ -45,7 +45,7 @@ class PulsarNamespaceViewModel Future fetchTopics() async { try { - final results = await PulsarPartitionedTopicAPi.getTopics( + final results = await PulsarPartitionedTopicApi.getTopics( host, port, tenant, namespace); this.fullList = results .map((e) => PulsarPartitionedTopicViewModel( @@ -77,7 +77,7 @@ class PulsarNamespaceViewModel Future createPartitionedTopic(String topic, int partition) async { try { - await PulsarPartitionedTopicAPi.createPartitionTopic( + await PulsarPartitionedTopicApi.createPartitionTopic( host, port, tenant, namespace, topic, partition); await fetchTopics(); } on Exception catch (e) { @@ -88,7 +88,7 @@ class PulsarNamespaceViewModel Future deletePartitionedTopic(String topic) async { try { - await PulsarPartitionedTopicAPi.deletePartitionTopic( + await PulsarPartitionedTopicApi.deletePartitionTopic( host, port, tenant, namespace, topic); await fetchTopics(); } on Exception catch (e) { diff --git a/lib/vm/pulsar/pulsar_partitioned_topic_basic_view_model.dart b/lib/vm/pulsar/pulsar_partitioned_topic_basic_view_model.dart index 0387d10..e19fbdb 100644 --- a/lib/vm/pulsar/pulsar_partitioned_topic_basic_view_model.dart +++ b/lib/vm/pulsar/pulsar_partitioned_topic_basic_view_model.dart @@ -50,7 +50,7 @@ class PulsarPartitionedTopicBasicViewModel extends BaseLoadViewModel { Future fetchPartitions() async { try { - final results = await PulsarPartitionedTopicAPi.getDetails( + final results = await PulsarPartitionedTopicApi.getDetails( host, port, tenant, namespace, topic); partitionNum = results.length.toString(); loadSuccess(); @@ -63,7 +63,7 @@ class PulsarPartitionedTopicBasicViewModel extends BaseLoadViewModel { Future modifyTopicPartition(String topic, int partition) async { try { - await PulsarPartitionedTopicAPi.modifyPartitionTopic( + await PulsarPartitionedTopicApi.modifyPartitionTopic( host, port, tenant, namespace, topic, partition); await fetchPartitions(); } on Exception catch (e) { diff --git a/lib/vm/pulsar/pulsar_partitioned_topic_detail_view_model.dart b/lib/vm/pulsar/pulsar_partitioned_topic_detail_view_model.dart index db135d9..c195fd7 100644 --- a/lib/vm/pulsar/pulsar_partitioned_topic_detail_view_model.dart +++ b/lib/vm/pulsar/pulsar_partitioned_topic_detail_view_model.dart @@ -54,7 +54,7 @@ class PulsarPartitionedTopicDetailViewModel Future fetchPartitions() async { try { - final results = await PulsarPartitionedTopicAPi.getDetails( + final results = await PulsarPartitionedTopicApi.getDetails( host, port, tenant, namespace, topic); this.fullList = results; this.displayList = this.fullList; diff --git a/lib/vm/pulsar/pulsar_partitioned_topic_list_view_model.dart b/lib/vm/pulsar/pulsar_partitioned_topic_list_view_model.dart index b8e8fd1..5c29945 100644 --- a/lib/vm/pulsar/pulsar_partitioned_topic_list_view_model.dart +++ b/lib/vm/pulsar/pulsar_partitioned_topic_list_view_model.dart @@ -45,7 +45,7 @@ class PulsarPartitionedTopicListViewModel Future fetchTopics() async { try { - final results = await PulsarPartitionedTopicAPi.getTopics( + final results = await PulsarPartitionedTopicApi.getTopics( host, port, tenant, namespace); this.fullList = results .map((e) => PulsarPartitionedTopicViewModel( @@ -77,7 +77,7 @@ class PulsarPartitionedTopicListViewModel Future createPartitionedTopic(String topic, int partition) async { try { - await PulsarPartitionedTopicAPi.createPartitionTopic( + await PulsarPartitionedTopicApi.createPartitionTopic( host, port, tenant, namespace, topic, partition); await fetchTopics(); } on Exception catch (e) { @@ -88,7 +88,7 @@ class PulsarPartitionedTopicListViewModel Future deletePartitionedTopic(String topic) async { try { - await PulsarPartitionedTopicAPi.deletePartitionTopic( + await PulsarPartitionedTopicApi.deletePartitionTopic( host, port, tenant, namespace, topic); await fetchTopics(); } on Exception catch (e) { diff --git a/lib/vm/pulsar/pulsar_partitioned_topic_produce_view_model.dart b/lib/vm/pulsar/pulsar_partitioned_topic_produce_view_model.dart index 21dbb2d..81a1056 100644 --- a/lib/vm/pulsar/pulsar_partitioned_topic_produce_view_model.dart +++ b/lib/vm/pulsar/pulsar_partitioned_topic_produce_view_model.dart @@ -54,7 +54,7 @@ class PulsarPartitionedTopicProduceViewModel Future fetchProducers() async { try { - final results = await PulsarPartitionedTopicAPi.getProducers( + final results = await PulsarPartitionedTopicApi.getProducers( host, port, tenant, namespace, topic); this.fullList = results; this.displayList = this.fullList; diff --git a/lib/vm/pulsar/pulsar_partitioned_topic_subscription_view_model.dart b/lib/vm/pulsar/pulsar_partitioned_topic_subscription_view_model.dart index 18b4713..76b6202 100644 --- a/lib/vm/pulsar/pulsar_partitioned_topic_subscription_view_model.dart +++ b/lib/vm/pulsar/pulsar_partitioned_topic_subscription_view_model.dart @@ -54,7 +54,7 @@ class PulsarPartitionedTopicSubscriptionViewModel Future fetchSubscriptions() async { try { - final results = await PulsarPartitionedTopicAPi.getSubscription( + final results = await PulsarPartitionedTopicApi.getSubscription( host, port, tenant, namespace, topic); this.fullList = results; this.displayList = this.fullList; @@ -68,7 +68,7 @@ class PulsarPartitionedTopicSubscriptionViewModel Future clearBacklog(String subscriptionName) async { try { - await PulsarPartitionedTopicAPi.clearBacklog( + await PulsarPartitionedTopicApi.clearBacklog( host, port, tenant, namespace, topic, subscriptionName); await fetchSubscriptions(); } on Exception catch (e) { diff --git a/lib/vm/pulsar/pulsar_sink_list_view_model.dart b/lib/vm/pulsar/pulsar_sink_list_view_model.dart index d39939a..457e702 100644 --- a/lib/vm/pulsar/pulsar_sink_list_view_model.dart +++ b/lib/vm/pulsar/pulsar_sink_list_view_model.dart @@ -35,6 +35,14 @@ class PulsarSinkListViewModel return this.pulsarInstancePo.port; } + String get functionHost { + return this.pulsarInstancePo.functionHost; + } + + int get functionPort { + return this.pulsarInstancePo.functionPort; + } + String get tenant { return this.tenantResp.tenant; } @@ -43,10 +51,22 @@ class PulsarSinkListViewModel return this.namespaceResp.namespace; } + Future createSink(String sinkName, String subName, String inputTopic, + String sinkType, String config) async { + try { + await PulsarSinkApi.createSink(functionHost, functionPort, tenant, + namespace, sinkName, subName, inputTopic, sinkType, config); + await fetchSinks(); + } on Exception catch (e) { + opException = e; + notifyListeners(); + } + } + Future fetchSinks() async { try { final results = - await PulsarSinkAPi.getSinkList(host, port, tenant, namespace); + await PulsarSinkApi.getSinkList(functionHost, functionPort, tenant, namespace); this.fullList = results .map((e) => PulsarSinkViewModel( pulsarInstancePo, tenantResp, namespaceResp, e)) @@ -77,7 +97,7 @@ class PulsarSinkListViewModel Future deleteSink(String name) async { try { - await PulsarSinkAPi.deleteSink(host, port, tenant, namespace, name); + await PulsarSinkApi.deleteSink(functionHost, functionPort, tenant, namespace, name); await fetchSinks(); } on Exception catch (e) { opException = e; diff --git a/lib/vm/pulsar/pulsar_source_list_view_model.dart b/lib/vm/pulsar/pulsar_source_list_view_model.dart index 8656790..79624e1 100644 --- a/lib/vm/pulsar/pulsar_source_list_view_model.dart +++ b/lib/vm/pulsar/pulsar_source_list_view_model.dart @@ -35,6 +35,14 @@ class PulsarSourceListViewModel return this.pulsarInstancePo.port; } + String get functionHost { + return this.pulsarInstancePo.functionHost; + } + + int get functionPort { + return this.pulsarInstancePo.functionPort; + } + String get tenant { return this.tenantResp.tenant; } @@ -43,10 +51,22 @@ class PulsarSourceListViewModel return this.namespaceResp.namespace; } - Future fetchTopics() async { + Future createSource(String sourceName, String outputTopic, + String sourceType, String config) async { + try { + await PulsarSourceApi.createSource(functionHost, functionPort, tenant, + namespace, sourceName, outputTopic, sourceType, config); + await fetchSources(); + } on Exception catch (e) { + opException = e; + notifyListeners(); + } + } + + Future fetchSources() async { try { final results = - await PulsarSourceAPi.getSourceList(host, port, tenant, namespace); + await PulsarSourceApi.getSourceList(functionHost, functionPort, tenant, namespace); this.fullList = results .map((e) => PulsarSourceViewModel( pulsarInstancePo, tenantResp, namespaceResp, e)) @@ -77,8 +97,8 @@ class PulsarSourceListViewModel Future deleteSource(String topic) async { try { - await PulsarSourceAPi.deleteSource(host, port, tenant, namespace, topic); - await fetchTopics(); + await PulsarSourceApi.deleteSource(functionHost, functionPort, tenant, namespace, topic); + await fetchSources(); } on Exception catch (e) { opException = e; notifyListeners(); diff --git a/lib/vm/pulsar/pulsar_tenant_view_model.dart b/lib/vm/pulsar/pulsar_tenant_view_model.dart index be2909d..71d256b 100644 --- a/lib/vm/pulsar/pulsar_tenant_view_model.dart +++ b/lib/vm/pulsar/pulsar_tenant_view_model.dart @@ -42,7 +42,7 @@ class PulsarTenantViewModel Future fetchNamespaces() async { try { final results = - await PulsarNamespaceAPi.getNamespaces(host, port, tenant); + await PulsarNamespaceApi.getNamespaces(host, port, tenant); this.fullList = results .map((e) => PulsarNamespaceViewModel(pulsarInstancePo, tenantResp, e)) .toList(); @@ -72,7 +72,7 @@ class PulsarTenantViewModel Future createNamespace(String namespace) async { try { - await PulsarNamespaceAPi.createNamespace(host, port, tenant, namespace); + await PulsarNamespaceApi.createNamespace(host, port, tenant, namespace); await fetchNamespaces(); } on Exception catch (e) { opException = e; @@ -82,7 +82,7 @@ class PulsarTenantViewModel Future deleteNamespace(String namespace) async { try { - await PulsarNamespaceAPi.deleteNamespace(host, port, tenant, namespace); + await PulsarNamespaceApi.deleteNamespace(host, port, tenant, namespace); await fetchNamespaces(); } on Exception catch (e) { opException = e; diff --git a/lib/vm/pulsar/pulsar_topic_list_view_model.dart b/lib/vm/pulsar/pulsar_topic_list_view_model.dart index 1b5d81d..5af6354 100644 --- a/lib/vm/pulsar/pulsar_topic_list_view_model.dart +++ b/lib/vm/pulsar/pulsar_topic_list_view_model.dart @@ -46,7 +46,7 @@ class PulsarTopicListViewModel Future fetchTopics() async { try { final results = - await PulsarTopicAPi.getTopics(host, port, tenant, namespace); + await PulsarTopicApi.getTopics(host, port, tenant, namespace); this.fullList = results .map((e) => PulsarTopicViewModel( pulsarInstancePo, tenantResp, namespaceResp, e)) @@ -77,7 +77,7 @@ class PulsarTopicListViewModel Future createTopic(String topic) async { try { - await PulsarTopicAPi.createTopic(host, port, tenant, namespace, topic); + await PulsarTopicApi.createTopic(host, port, tenant, namespace, topic); await fetchTopics(); } on Exception catch (e) { opException = e; @@ -87,7 +87,7 @@ class PulsarTopicListViewModel Future deleteTopic(String topic) async { try { - await PulsarTopicAPi.deleteTopic(host, port, tenant, namespace, topic); + await PulsarTopicApi.deleteTopic(host, port, tenant, namespace, topic); await fetchTopics(); } on Exception catch (e) { opException = e; diff --git a/lib/vm/pulsar/pulsar_topic_produce_view_model.dart b/lib/vm/pulsar/pulsar_topic_produce_view_model.dart index 0a6dc16..7ed61d1 100644 --- a/lib/vm/pulsar/pulsar_topic_produce_view_model.dart +++ b/lib/vm/pulsar/pulsar_topic_produce_view_model.dart @@ -50,7 +50,7 @@ class PulsarTopicProduceViewModel extends BaseLoadListViewModel { Future fetchProducers() async { try { - final results = await PulsarTopicAPi.getProducers( + final results = await PulsarTopicApi.getProducers( host, port, tenant, namespace, topic); this.fullList = results; this.displayList = this.fullList; diff --git a/lib/vm/pulsar/pulsar_topic_subscription_view_model.dart b/lib/vm/pulsar/pulsar_topic_subscription_view_model.dart index c600297..01149a8 100644 --- a/lib/vm/pulsar/pulsar_topic_subscription_view_model.dart +++ b/lib/vm/pulsar/pulsar_topic_subscription_view_model.dart @@ -54,7 +54,7 @@ class PulsarTopicSubscriptionViewModel Future fetchSubscriptions() async { try { - final results = await PulsarTopicAPi.getSubscription( + final results = await PulsarTopicApi.getSubscription( host, port, tenant, namespace, topic); this.fullList = results; this.displayList = this.fullList; @@ -68,7 +68,7 @@ class PulsarTopicSubscriptionViewModel Future clearBacklog(String subscriptionName) async { try { - await PulsarTopicAPi.clearBacklog( + await PulsarTopicApi.clearBacklog( host, port, tenant, namespace, topic, subscriptionName); await fetchSubscriptions(); } on Exception catch (e) { diff --git a/pubspec.lock b/pubspec.lock index 346fd8f..588bf71 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -29,6 +29,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "1.3.1" + clipboard: + dependency: "direct main" + description: + name: clipboard + url: "https://pub.dartlang.org" + source: hosted + version: "0.1.3" clock: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index 541bb1e..93c2ab0 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -29,6 +29,7 @@ dependencies: # Use with the CupertinoIcons class for iOS style icons. cupertino_icons: ^1.0.2 http: ^0.13.3 + clipboard: provider: ^6.0.1 sqflite: sqflite_common_ffi: diff --git a/test/api/pulsar/pulsar_sink_api_create_test.dart b/test/api/pulsar/pulsar_sink_api_create_test.dart new file mode 100644 index 0000000..cde0268 --- /dev/null +++ b/test/api/pulsar/pulsar_sink_api_create_test.dart @@ -0,0 +1,9 @@ +import 'package:flutter_test/flutter_test.dart'; +import 'package:paas_dashboard_flutter/api/pulsar/pulsar_sink_api.dart'; + +void main() { + test("test_create_sink", () async { + await PulsarSinkApi.createSink("localhost", 8080, "public", "default", + "sink_name", "sub_name", "topic", "pulsar", '{"topic":"xx"}'); + }); +} diff --git a/test/api/pulsar/pulsar_topic_api_fetch_producers_test.dart b/test/api/pulsar/pulsar_topic_api_fetch_producers_test.dart index 573a1fc..af42a9e 100644 --- a/test/api/pulsar/pulsar_topic_api_fetch_producers_test.dart +++ b/test/api/pulsar/pulsar_topic_api_fetch_producers_test.dart @@ -3,7 +3,7 @@ import 'package:paas_dashboard_flutter/api/pulsar/pulsar_topic_api.dart'; void main() { test("test_fetch_producers", () async { - var producers = await PulsarTopicAPi.getProducers("localhost", 8080, "public", "default", "test_fetch_topic"); + var producers = await PulsarTopicApi.getProducers("localhost", 8080, "public", "default", "test_fetch_topic"); print(producers); }); } diff --git a/test/api/pulsar/pulsar_topic_api_fetch_subscriptions_test.dart b/test/api/pulsar/pulsar_topic_api_fetch_subscriptions_test.dart index 0e2ae3b..20903a9 100644 --- a/test/api/pulsar/pulsar_topic_api_fetch_subscriptions_test.dart +++ b/test/api/pulsar/pulsar_topic_api_fetch_subscriptions_test.dart @@ -3,7 +3,7 @@ import 'package:paas_dashboard_flutter/api/pulsar/pulsar_topic_api.dart'; void main() { test("test_fetch_subscriptions", () async { - var subscription = await PulsarTopicAPi.getSubscription("localhost", 8080, "public", "default", "test_fetch_topic"); + var subscription = await PulsarTopicApi.getSubscription("localhost", 8080, "public", "default", "test_fetch_topic"); print(subscription); }); }