Skip to content

Commit

Permalink
Rename typo APi to Api (#13)
Browse files Browse the repository at this point in the history
  • Loading branch information
shoothzj authored Dec 1, 2021
1 parent 8dee723 commit a1c13ca
Show file tree
Hide file tree
Showing 34 changed files with 266 additions and 62 deletions.
4 changes: 2 additions & 2 deletions lib/api/pulsar/pulsar_cluster_api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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<List<ClusterResp>> 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';
Expand Down
2 changes: 1 addition & 1 deletion lib/api/pulsar/pulsar_namespace_api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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<void> createNamespace(String host, int port, String tenant, String namespace) async {
var url = 'http://$host:${port.toString()}/admin/v2/namespaces/$tenant/$namespace';
Expand Down
10 changes: 5 additions & 5 deletions lib/api/pulsar/pulsar_partitioned_topic_api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> createPartitionTopic(String host, int port,
String tenant, String namespace, String topic, int partitionNum) async {
var url =
Expand Down Expand Up @@ -77,7 +77,7 @@ class PulsarPartitionedTopicAPi {
static Future<List<SubscriptionResp>> 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<SubscriptionResp> respList = new List.empty(growable: true);
Expand Down Expand Up @@ -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;
Expand All @@ -133,7 +133,7 @@ class PulsarPartitionedTopicAPi {
static Future<List<ProducerResp>> 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<ProducerResp> respList = new List.empty(growable: true);
Expand All @@ -158,7 +158,7 @@ class PulsarPartitionedTopicAPi {
static Future<List<PulsarPartitionedTopicDetailResp>> 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<PulsarPartitionedTopicDetailResp> respList =
Expand Down
24 changes: 23 additions & 1 deletion lib/api/pulsar/pulsar_sink_api.dart
Original file line number Diff line number Diff line change
@@ -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<void> 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<String> 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<void> deleteSink(String host, int port, String tenant,
String namespace, String sinkName) async {
var url =
Expand Down
22 changes: 21 additions & 1 deletion lib/api/pulsar/pulsar_source_api.dart
Original file line number Diff line number Diff line change
@@ -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<void> 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<void> deleteSource(String host, int port, String tenant,
String namespace, String sourceName) async {
var url =
Expand Down
2 changes: 1 addition & 1 deletion lib/api/pulsar/pulsar_stat_api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> partitionedTopicStats(String host, int port,
String tenant, String namespace, String topic) async {
var url =
Expand Down
2 changes: 1 addition & 1 deletion lib/api/pulsar/pulsar_tenant_api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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<void> createTenant(String host, int port, String tenant) async {
String tenantInfo = "";
await getTenantInfo(host, port, tenant).then((value) => tenantInfo = value);
Expand Down
8 changes: 4 additions & 4 deletions lib/api/pulsar/pulsar_topic_api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> createTopic(String host, int port, String tenant,
String namespace, String topic) async {
var url =
Expand Down Expand Up @@ -57,7 +57,7 @@ class PulsarTopicAPi {
static Future<List<SubscriptionResp>> 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<SubscriptionResp> respList = new List.empty(growable: true);
Map statsMap = json.decode(data) as Map;
Expand Down Expand Up @@ -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;
Expand All @@ -112,7 +112,7 @@ class PulsarTopicAPi {
static Future<List<ProducerResp>> 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<ProducerResp> respList = new List.empty(growable: true);
Map statsMap = json.decode(data) as Map;
Expand Down
37 changes: 37 additions & 0 deletions lib/module/pulsar/pulsar_sink.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,28 @@
class SinkConfigReq {
final String name;
final String tenant;
final String namespace;
final String sourceSubscriptionName;
final List<String> 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;

Expand All @@ -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;
}
}
23 changes: 23 additions & 0 deletions lib/module/pulsar/pulsar_source.dart
Original file line number Diff line number Diff line change
@@ -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;

Expand Down
6 changes: 3 additions & 3 deletions lib/persistent/persistent_db.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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)',
Expand All @@ -64,7 +64,7 @@ class PersistentDb implements PersistentApi {
@override
Future<void> 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);
Expand Down
2 changes: 1 addition & 1 deletion lib/persistent/persistent_memory.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class PersistentMemory implements PersistentApi {

@override
Future<List<PulsarInstancePo>> pulsarInstances() async {
return [new PulsarInstancePo(0, "example", "localhost", 8080, "localhost", 6650)];
return [new PulsarInstancePo(0, "example", "localhost", 8080, "localhost", 8080)];
}

@override
Expand Down
33 changes: 28 additions & 5 deletions lib/ui/pulsar/widget/pulsar_sink_list.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -54,10 +55,10 @@ class PulsarSinkListWidgetState extends State<PulsarSinkListWidget> {
},
cells: [
DataCell(
Text(item.sinkName),
Text(item.name),
),
DataCellUtil.newDellDataCell(() {
vm.deleteSink(item.sinkName);
vm.deleteSink(item.name);
}),
]));
var topicsTable = SingleChildScrollView(
Expand All @@ -69,6 +70,7 @@ class PulsarSinkListWidgetState extends State<PulsarSinkListWidget> {
],
source: vm),
);
var formButton = createSinkButton(context);
var refreshButton = TextButton(
onPressed: () {
vm.fetchSinks();
Expand All @@ -81,14 +83,35 @@ class PulsarSinkListWidgetState extends State<PulsarSinkListWidget> {
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<PulsarSinkListViewModel>(context, listen: false);
vm.createSink(sinkName, subName, inputTopic, sinkType, config);
final scaffold = ScaffoldMessenger.of(context);
scaffold.showSnackBar(
SnackBar(
content: const Text('Dart 目前不支持复杂ContentType请求,Curl命令已复制到剪切版'),
),
);
});
}
}
Loading

0 comments on commit a1c13ca

Please sign in to comment.