diff --git a/lib/api/http_util.dart b/lib/api/http_util.dart index 01e0556..1370c16 100644 --- a/lib/api/http_util.dart +++ b/lib/api/http_util.dart @@ -17,7 +17,54 @@ // under the License. // +import 'dart:collection'; +import 'dart:io'; + +import 'package:dio/adapter.dart'; +import 'package:dio/dio.dart'; +import 'package:paas_dashboard_flutter/api/tls_context.dart'; + class HttpUtil { + static final String http = "http://"; + static final String https = "https://"; + static const int CONNECT_TIMEOUT = 10000; + static const int RECEIVE_TIMEOUT = 10000; + static Map> clients = {}; + + static Dio getClient(TlsContext tlsContext, SERVER service, int id) { + clients.putIfAbsent(service, () => new HashMap.identity()); + clients[service]!.putIfAbsent(id, () => createClient(tlsContext)); + return clients[service]![id]!; + } + + static Dio createClient(TlsContext tlsContext) { + BaseOptions options = BaseOptions( + connectTimeout: CONNECT_TIMEOUT, + receiveTimeout: RECEIVE_TIMEOUT, + ); + Dio client = new Dio(options); + if (!tlsContext.enableTls) { + return client; + } + SecurityContext context = SecurityContext(); + if (tlsContext.clientKeyPassword.isNotEmpty) { + context.usePrivateKey(tlsContext.clientKeyFile, password: tlsContext.clientKeyPassword); + } else { + context.usePrivateKey(tlsContext.clientKeyFile); + } + context.useCertificateChain(tlsContext.clientCertFile); + context.setTrustedCertificates(tlsContext.caFile); + + (client.httpClientAdapter as DefaultHttpClientAdapter).onHttpClientCreate = (client) { + HttpClient httpClient = new HttpClient(context: context); + httpClient.badCertificateCallback = (X509Certificate cert, String host, int port) { + return true; + }; + return httpClient; + }; + return client; + } + static bool abnormal(int code) { return code < 200 || code >= 300; } @@ -26,3 +73,8 @@ class HttpUtil { return code >= 200 && code < 300; } } + +enum SERVER { + PULSAR, + PULSAR_FUNCTION, +} diff --git a/lib/api/pulsar/pulsar_cluster_api.dart b/lib/api/pulsar/pulsar_cluster_api.dart index ac04ca3..b5b9ab9 100644 --- a/lib/api/pulsar/pulsar_cluster_api.dart +++ b/lib/api/pulsar/pulsar_cluster_api.dart @@ -20,43 +20,49 @@ import 'dart:convert'; import 'dart:developer'; -import 'package:http/http.dart' as http; +import 'package:dio/dio.dart'; 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/api/tls_context.dart'; import 'package:paas_dashboard_flutter/module/pulsar/pulsar_cluster.dart'; class PulsarClusterApi { - static Future> cluster(String host, int port) async { - String version = await getVersion(host, port); - String tenantInfo = await PulsarTenantApi.getTenantInfo(host, port, "public"); + static Future> cluster(int id, String host, int port, TlsContext tlsContext) async { + String version = await getVersion(id, host, port, tlsContext); + String tenantInfo = await PulsarTenantApi.getTenantInfo(id, host, port, "public", tlsContext); String cluster = ((json.decode(tenantInfo) as Map)["allowedClusters"] as List)[0]; - String url = 'http://$host:${port.toString()}/admin/v2/brokers/$cluster'; - final brokersResponse = await http.get(Uri.parse(url)); - if (HttpUtil.abnormal(brokersResponse.statusCode)) { - log('ErrorCode is ${brokersResponse.statusCode}, body is ${brokersResponse.body}'); - throw Exception('ErrorCode is ${brokersResponse.statusCode}, body is ${brokersResponse.body}'); + String url = + tlsContext.enableTls ? HttpUtil.https : HttpUtil.http + '$host:${port.toString()}/admin/v2/brokers/$cluster'; + final brokersResponse = await HttpUtil.getClient(tlsContext, SERVER.PULSAR, id).get(url); + if (HttpUtil.abnormal(brokersResponse.statusCode!)) { + log('ErrorCode is ${brokersResponse.statusCode}, body is ${brokersResponse.data}'); + throw Exception('ErrorCode is ${brokersResponse.statusCode}, body is ${brokersResponse.data}'); } - List brokers = json.decode(brokersResponse.body) as List; + List brokers = json.decode(brokersResponse.data!) as List; return brokers.map((e) => ClusterResp(e, version)).toList(); } - static Future getVersion(String host, int port) async { - String url = 'http://$host:${port.toString()}/admin/v2/brokers/version'; - final versionResponse = await http.get(Uri.parse(url)); - if (HttpUtil.abnormal(versionResponse.statusCode)) { - log('ErrorCode is ${versionResponse.statusCode}, body is ${versionResponse.body}'); - throw Exception('ErrorCode is ${versionResponse.statusCode}, body is ${versionResponse.body}'); + static Future getVersion(int id, String host, int port, TlsContext tlsContext) async { + String url = + tlsContext.enableTls ? HttpUtil.https : HttpUtil.http + '$host:${port.toString()}/admin/v2/brokers/version'; + final versionResponse = await HttpUtil.getClient(tlsContext, SERVER.PULSAR, id) + .get(url, options: new Options(responseType: ResponseType.json)); + if (HttpUtil.abnormal(versionResponse.statusCode!)) { + log('ErrorCode is ${versionResponse.statusCode}, body is ${versionResponse.data}'); + throw Exception('ErrorCode is ${versionResponse.statusCode}, body is ${versionResponse.data}'); } - return versionResponse.body; + return versionResponse.data!; } - static Future getLeader(String host, int port) async { - String url = 'http://$host:${port.toString()}/admin/v2/brokers/leaderBroker'; - final leaderBrokerResponse = await http.get(Uri.parse(url)); - if (HttpUtil.abnormal(leaderBrokerResponse.statusCode)) { - log('ErrorCode is ${leaderBrokerResponse.statusCode}, body is ${leaderBrokerResponse.body}'); - throw Exception('ErrorCode is ${leaderBrokerResponse.statusCode}, body is ${leaderBrokerResponse.body}'); + static Future getLeader(int id, String host, int port, TlsContext tlsContext) async { + String url = tlsContext.enableTls + ? HttpUtil.https + : HttpUtil.http + '$host:${port.toString()}/admin/v2/brokers/leaderBroker'; + final leaderBrokerResponse = await HttpUtil.getClient(tlsContext, SERVER.PULSAR, id).get(url); + if (HttpUtil.abnormal(leaderBrokerResponse.statusCode!)) { + log('ErrorCode is ${leaderBrokerResponse.statusCode}, body is ${leaderBrokerResponse.data}'); + throw Exception('ErrorCode is ${leaderBrokerResponse.statusCode}, body is ${leaderBrokerResponse.data}'); } - return json.decode(leaderBrokerResponse.body)["serviceUrl"]; + return json.decode(leaderBrokerResponse.data!)["serviceUrl"]; } } diff --git a/lib/api/pulsar/pulsar_namespace_api.dart b/lib/api/pulsar/pulsar_namespace_api.dart index 1005ca4..ce05992 100644 --- a/lib/api/pulsar/pulsar_namespace_api.dart +++ b/lib/api/pulsar/pulsar_namespace_api.dart @@ -19,51 +19,62 @@ import 'dart:convert'; import 'dart:developer'; +import 'dart:io'; -import 'package:http/http.dart' as http; +import 'package:dio/dio.dart'; import 'package:paas_dashboard_flutter/api/http_util.dart'; +import 'package:paas_dashboard_flutter/api/tls_context.dart'; import 'package:paas_dashboard_flutter/module/pulsar/pulsar_namespace.dart'; 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'; - final response = await http.put(Uri.parse(url)); - if (HttpUtil.abnormal(response.statusCode)) { - log('ErrorCode is ${response.statusCode}, body is ${response.body}'); - throw Exception('ErrorCode is ${response.statusCode}, body is ${response.body}'); + static Future createNamespace( + int id, String host, int port, TlsContext tlsContext, String tenant, String namespace) async { + var url = tlsContext.enableTls + ? HttpUtil.https + : HttpUtil.http + '$host:${port.toString()}/admin/v2/namespaces/$tenant/$namespace'; + var response = await HttpUtil.getClient(tlsContext, SERVER.PULSAR, id).put(url); + if (HttpUtil.abnormal(response.statusCode!)) { + log('ErrorCode is ${response.statusCode}, body is ${response.data}'); + throw Exception('ErrorCode is ${response.statusCode}, body is ${response.data}'); } } - static Future deleteNamespace(String host, int port, String tenant, String namespace) async { - var url = 'http://$host:${port.toString()}/admin/v2/namespaces/$tenant/$namespace'; - final response = await http.delete(Uri.parse(url)); - if (HttpUtil.abnormal(response.statusCode)) { - log('ErrorCode is ${response.statusCode}, body is ${response.body}'); - throw Exception('ErrorCode is ${response.statusCode}, body is ${response.body}'); + static Future deleteNamespace( + int id, String host, int port, TlsContext tlsContext, String tenant, String namespace) async { + var url = tlsContext.enableTls + ? HttpUtil.https + : HttpUtil.http + '$host:${port.toString()}/admin/v2/namespaces/$tenant/$namespace'; + var response = await HttpUtil.getClient(tlsContext, SERVER.PULSAR, id).delete(url); + if (HttpUtil.abnormal(response.statusCode!)) { + log('ErrorCode is ${response.statusCode}, body is ${response.data}'); + throw Exception('ErrorCode is ${response.statusCode}, body is ${response.data}'); } } - static Future> getNamespaces(String host, int port, String tenant) async { - var url = 'http://$host:${port.toString()}/admin/v2/namespaces/$tenant'; - final response = await http.get(Uri.parse(url)); - if (HttpUtil.abnormal(response.statusCode)) { - log('ErrorCode is ${response.statusCode}, body is ${response.body}'); - throw Exception('ErrorCode is ${response.statusCode}, body is ${response.body}'); + static Future> getNamespaces( + int id, String host, int port, TlsContext tlsContext, String tenant) async { + var url = + tlsContext.enableTls ? HttpUtil.https : HttpUtil.http + '$host:${port.toString()}/admin/v2/namespaces/$tenant'; + var response = await HttpUtil.getClient(tlsContext, SERVER.PULSAR, id).get(url); + if (HttpUtil.abnormal(response.statusCode!)) { + log('ErrorCode is ${response.statusCode}, body is ${response.data}'); + throw Exception('ErrorCode is ${response.statusCode}, body is ${response.data}'); } - List jsonResponse = json.decode(response.body) as List; + List jsonResponse = json.decode(response.data!) as List; return jsonResponse.map((name) => new NamespaceResp.fromJson(name)).toList(); } - static Future getBacklogQuota(String host, int port, String tenant, String namespace) async { - String url = 'http://$host:${port.toString()}/admin/v2/namespaces/$tenant/$namespace/backlogQuotaMap'; - var response = await http.get(Uri.parse(url), headers: { - 'Content-Type': 'application/json; charset=UTF-8', - }); - if (HttpUtil.abnormal(response.statusCode)) { - log('ErrorCode is ${response.statusCode}, body is ${response.body}'); - throw Exception('ErrorCode is ${response.statusCode}, body is ${response.body}'); - } - Map jsonResponse = json.decode(response.body) as Map; + static Future getBacklogQuota( + int id, String host, int port, TlsContext tlsContext, String tenant, String namespace) async { + String url = tlsContext.enableTls + ? HttpUtil.https + : HttpUtil.http + '$host:${port.toString()}/admin/v2/namespaces/$tenant/$namespace/backlogQuotaMap'; + var response = await HttpUtil.getClient(tlsContext, SERVER.PULSAR, id).get(url); + if (HttpUtil.abnormal(response.statusCode!)) { + log('ErrorCode is ${response.statusCode}, body is ${response.data}'); + throw Exception('ErrorCode is ${response.statusCode}, body is ${response.data}'); + } + Map jsonResponse = json.decode(response.data!) as Map; var destinationStorageResp = jsonResponse["destination_storage"]; if (destinationStorageResp == null) { return new BacklogQuotaResp(null, null, null); @@ -71,159 +82,151 @@ class PulsarNamespaceApi { return BacklogQuotaResp.fromJson(destinationStorageResp); } - static Future updateBacklogQuota( - String host, int port, String tenant, String namespace, int limit, int? limitTime, String policy) async { - String url = 'http://$host:${port.toString()}/admin/v2/namespaces/$tenant/$namespace/backlogQuota'; + static Future updateBacklogQuota(int id, String host, int port, TlsContext tlsContext, String tenant, + String namespace, int limit, int? limitTime, String policy) async { + String url = tlsContext.enableTls + ? HttpUtil.https + : HttpUtil.http + '$host:${port.toString()}/admin/v2/namespaces/$tenant/$namespace/backlogQuota'; BacklogQuotaReq backlogQuotaReq = new BacklogQuotaReq(limit, limitTime, policy); - var response = await http.post(Uri.parse(url), - headers: { - 'Content-Type': 'application/json; charset=UTF-8', - }, - body: json.encode(backlogQuotaReq)); - if (HttpUtil.abnormal(response.statusCode)) { - log('ErrorCode is ${response.statusCode}, body is ${response.body}'); - throw Exception('ErrorCode is ${response.statusCode}, body is ${response.body}'); + var response = + await HttpUtil.getClient(tlsContext, SERVER.PULSAR, id).post(url, data: json.encode(backlogQuotaReq)); + if (HttpUtil.abnormal(response.statusCode!)) { + log('ErrorCode is ${response.statusCode}, body is ${response.data}'); + throw Exception('ErrorCode is ${response.statusCode}, body is ${response.data}'); } } - static Future getPolicy(String host, int port, String tenant, String namespace) async { - String url = 'http://$host:${port.toString()}/admin/v2/namespaces/$tenant/$namespace'; - var response = - await http.get(Uri.parse(url), headers: {'Content-Type': 'application/json; charset=utf-8'}); - if (HttpUtil.abnormal(response.statusCode)) { - log('ErrorCode is ${response.statusCode}, body is ${response.body}'); - throw Exception('ErrorCode is ${response.statusCode}, body is ${response.body}'); - } - Map jsonResponse = json.decode(response.body) as Map; + static Future getPolicy( + int id, String host, int port, TlsContext tlsContext, String tenant, String namespace) async { + String url = tlsContext.enableTls + ? HttpUtil.https + : HttpUtil.http + '$host:${port.toString()}/admin/v2/namespaces/$tenant/$namespace'; + var response = await HttpUtil.getClient(tlsContext, SERVER.PULSAR, id).get(url); + if (HttpUtil.abnormal(response.statusCode!)) { + log('ErrorCode is ${response.statusCode}, body is ${response.data}'); + throw Exception('ErrorCode is ${response.statusCode}, body is ${response.data}'); + } + Map jsonResponse = json.decode(response.data!) as Map; return PolicyResp.fromJson(jsonResponse); } - static Future setAutoTopicCreation(String host, int port, String tenant, String namespace, - bool? allowAutoTopicCreation, String? topicType, int? defaultNumPartitions) async { - String url = 'http://$host:${port.toString()}/admin/v2/namespaces/$tenant/$namespace/autoTopicCreation'; + static Future setAutoTopicCreation(int id, String host, int port, TlsContext tlsContext, String tenant, + String namespace, bool? allowAutoTopicCreation, String? topicType, int? defaultNumPartitions) async { + String url = tlsContext.enableTls + ? HttpUtil.https + : HttpUtil.http + '$host:${port.toString()}/admin/v2/namespaces/$tenant/$namespace/autoTopicCreation'; TopicAutoCreateReq topicAutoCreateReq = new TopicAutoCreateReq(allowAutoTopicCreation, topicType, defaultNumPartitions); - var response = await http.post(Uri.parse(url), - headers: { - 'Content-Type': 'application/json; charset=UTF-8', - }, - body: json.encode(topicAutoCreateReq)); - if (HttpUtil.abnormal(response.statusCode)) { - log('ErrorCode is ${response.statusCode}, body is ${response.body}'); - throw Exception('ErrorCode is ${response.statusCode}, body is ${response.body}'); + var response = + await HttpUtil.getClient(tlsContext, SERVER.PULSAR, id).post(url, data: json.encode(topicAutoCreateReq)); + if (HttpUtil.abnormal(response.statusCode!)) { + log('ErrorCode is ${response.statusCode}, body is ${response.data}'); + throw Exception('ErrorCode is ${response.statusCode}, body is ${response.data}'); } } - static Future setMessageTTLSecond( - String host, int port, String tenant, String namespace, int? messageTTLSecond) async { - String url = 'http://$host:${port.toString()}/admin/v2/namespaces/$tenant/$namespace/messageTTL'; - var response = await http.post(Uri.parse(url), - headers: { - 'Content-Type': 'application/json; charset=UTF-8', - }, - body: messageTTLSecond.toString()); - if (HttpUtil.abnormal(response.statusCode)) { - log('ErrorCode is ${response.statusCode}, body is ${response.body}'); - throw Exception('ErrorCode is ${response.statusCode}, body is ${response.body}'); + static Future setMessageTTLSecond(int id, String host, int port, TlsContext tlsContext, String tenant, + String namespace, int? messageTTLSecond) async { + String url = tlsContext.enableTls + ? HttpUtil.https + : HttpUtil.http + '$host:${port.toString()}/admin/v2/namespaces/$tenant/$namespace/messageTTL'; + var response = await HttpUtil.getClient(tlsContext, SERVER.PULSAR, id).post(url, data: messageTTLSecond.toString()); + if (HttpUtil.abnormal(response.statusCode!)) { + log('ErrorCode is ${response.statusCode}, body is ${response.data}'); + throw Exception('ErrorCode is ${response.statusCode}, body is ${response.data}'); } } - static Future setMaxProducersPerTopic( - String host, int port, String tenant, String namespace, int? maxProducersPerTopic) async { - String url = 'http://$host:${port.toString()}/admin/v2/namespaces/$tenant/$namespace/maxProducersPerTopic'; - var response = await http.post(Uri.parse(url), - headers: { - 'Content-Type': 'application/json; charset=UTF-8', - }, - body: maxProducersPerTopic.toString()); - if (HttpUtil.abnormal(response.statusCode)) { - log('ErrorCode is ${response.statusCode}, body is ${response.body}'); - throw Exception('ErrorCode is ${response.statusCode}, body is ${response.body}'); + static Future setMaxProducersPerTopic(int id, String host, int port, TlsContext tlsContext, String tenant, + String namespace, int? maxProducersPerTopic) async { + String url = tlsContext.enableTls + ? HttpUtil.https + : HttpUtil.http + '$host:${port.toString()}/admin/v2/namespaces/$tenant/$namespace/maxProducersPerTopic'; + var response = + await HttpUtil.getClient(tlsContext, SERVER.PULSAR, id).post(url, data: maxProducersPerTopic.toString()); + if (HttpUtil.abnormal(response.statusCode!)) { + log('ErrorCode is ${response.statusCode}, body is ${response.data}'); + throw Exception('ErrorCode is ${response.statusCode}, body is ${response.data}'); } } - static Future setMaxConsumersPerTopic( - String host, int port, String tenant, String namespace, int? maxConsumersPerTopic) async { - String url = 'http://$host:${port.toString()}/admin/v2/namespaces/$tenant/$namespace/maxConsumersPerTopic'; - var response = await http.post(Uri.parse(url), - headers: { - 'Content-Type': 'application/json; charset=UTF-8', - }, - body: maxConsumersPerTopic.toString()); - if (HttpUtil.abnormal(response.statusCode)) { - log('ErrorCode is ${response.statusCode}, body is ${response.body}'); - throw Exception('ErrorCode is ${response.statusCode}, body is ${response.body}'); + static Future setMaxConsumersPerTopic(int id, String host, int port, TlsContext tlsContext, String tenant, + String namespace, int? maxConsumersPerTopic) async { + String url = tlsContext.enableTls + ? HttpUtil.https + : HttpUtil.http + '$host:${port.toString()}/admin/v2/namespaces/$tenant/$namespace/maxConsumersPerTopic'; + var response = + await HttpUtil.getClient(tlsContext, SERVER.PULSAR, id).post(url, data: maxConsumersPerTopic.toString()); + if (HttpUtil.abnormal(response.statusCode!)) { + log('ErrorCode is ${response.statusCode}, body is ${response.data}'); + throw Exception('ErrorCode is ${response.statusCode}, body is ${response.data}'); } } - static Future setMaxConsumersPerSubscription( - String host, int port, String tenant, String namespace, int? maxConsumersPerSubscription) async { - String url = 'http://$host:${port.toString()}/admin/v2/namespaces/$tenant/$namespace/maxConsumersPerSubscription'; - var response = await http.post(Uri.parse(url), - headers: { - 'Content-Type': 'application/json; charset=UTF-8', - }, - body: maxConsumersPerSubscription.toString()); - if (HttpUtil.abnormal(response.statusCode)) { - log('ErrorCode is ${response.statusCode}, body is ${response.body}'); - throw Exception('ErrorCode is ${response.statusCode}, body is ${response.body}'); + static Future setMaxConsumersPerSubscription(int id, String host, int port, TlsContext tlsContext, + String tenant, String namespace, int? maxConsumersPerSubscription) async { + String url = tlsContext.enableTls + ? HttpUtil.https + : HttpUtil.http + '$host:${port.toString()}/admin/v2/namespaces/$tenant/$namespace/maxConsumersPerSubscription'; + var response = + await HttpUtil.getClient(tlsContext, SERVER.PULSAR, id).post(url, data: maxConsumersPerSubscription.toString()); + if (HttpUtil.abnormal(response.statusCode!)) { + log('ErrorCode is ${response.statusCode}, body is ${response.data}'); + throw Exception('ErrorCode is ${response.statusCode}, body is ${response.data}'); } } - static Future setMaxUnackedMessagesPerConsumer( - String host, int port, String tenant, String namespace, int? maxUnackedMessagesPerConsumer) async { - String url = 'http://$host:${port.toString()}/admin/v2/namespaces/$tenant/$namespace/maxUnackedMessagesPerConsumer'; - var response = await http.post(Uri.parse(url), - headers: { - 'Content-Type': 'application/json; charset=UTF-8', - }, - body: maxUnackedMessagesPerConsumer.toString()); - if (HttpUtil.abnormal(response.statusCode)) { - log('ErrorCode is ${response.statusCode}, body is ${response.body}'); - throw Exception('ErrorCode is ${response.statusCode}, body is ${response.body}'); + static Future setMaxUnackedMessagesPerConsumer(int id, String host, int port, TlsContext tlsContext, + String tenant, String namespace, int? maxUnackedMessagesPerConsumer) async { + String url = tlsContext.enableTls + ? HttpUtil.https + : HttpUtil.http + + '$host:${port.toString()}/admin/v2/namespaces/$tenant/$namespace/maxUnackedMessagesPerConsumer'; + var response = await HttpUtil.getClient(tlsContext, SERVER.PULSAR, id) + .post(url, data: maxUnackedMessagesPerConsumer.toString()); + if (HttpUtil.abnormal(response.statusCode!)) { + log('ErrorCode is ${response.statusCode}, body is ${response.data}'); + throw Exception('ErrorCode is ${response.statusCode}, body is ${response.data}'); } } - static Future setMaxUnackedMessagesPerSubscription( - String host, int port, String tenant, String namespace, int? maxUnackedMessagesPerSubscription) async { - String url = - 'http://$host:${port.toString()}/admin/v2/namespaces/$tenant/$namespace/maxUnackedMessagesPerSubscription'; - var response = await http.post(Uri.parse(url), - headers: { - 'Content-Type': 'application/json; charset=UTF-8', - }, - body: maxUnackedMessagesPerSubscription.toString()); - if (HttpUtil.abnormal(response.statusCode)) { - log('ErrorCode is ${response.statusCode}, body is ${response.body}'); - throw Exception('ErrorCode is ${response.statusCode}, body is ${response.body}'); + static Future setMaxUnackedMessagesPerSubscription(int id, String host, int port, TlsContext tlsContext, + String tenant, String namespace, int? maxUnackedMessagesPerSubscription) async { + String url = tlsContext.enableTls + ? HttpUtil.https + : HttpUtil.http + + '$host:${port.toString()}/admin/v2/namespaces/$tenant/$namespace/maxUnackedMessagesPerSubscription'; + var response = await HttpUtil.getClient(tlsContext, SERVER.PULSAR, id) + .post(url, data: maxUnackedMessagesPerSubscription.toString()); + if (HttpUtil.abnormal(response.statusCode!)) { + log('ErrorCode is ${response.statusCode}, body is ${response.data}'); + throw Exception('ErrorCode is ${response.statusCode}, body is ${response.data}'); } } - static Future setMaxSubscriptionsPerTopic( - String host, int port, String tenant, String namespace, int? maxSubscriptionsPerTopic) async { - String url = 'http://$host:${port.toString()}/admin/v2/namespaces/$tenant/$namespace/maxSubscriptionsPerTopic'; - var response = await http.post(Uri.parse(url), - headers: { - 'Content-Type': 'application/json; charset=UTF-8', - }, - body: maxSubscriptionsPerTopic.toString()); - if (HttpUtil.abnormal(response.statusCode)) { - log('ErrorCode is ${response.statusCode}, body is ${response.body}'); - throw Exception('ErrorCode is ${response.statusCode}, body is ${response.body}'); + static Future setMaxSubscriptionsPerTopic(int id, String host, int port, TlsContext tlsContext, String tenant, + String namespace, int? maxSubscriptionsPerTopic) async { + String url = tlsContext.enableTls + ? HttpUtil.https + : HttpUtil.http + '$host:${port.toString()}/admin/v2/namespaces/$tenant/$namespace/maxSubscriptionsPerTopic'; + var response = + await HttpUtil.getClient(tlsContext, SERVER.PULSAR, id).post(url, data: maxSubscriptionsPerTopic.toString()); + if (HttpUtil.abnormal(response.statusCode!)) { + log('ErrorCode is ${response.statusCode}, body is ${response.data}'); + throw Exception('ErrorCode is ${response.statusCode}, body is ${response.data}'); } } - static Future setMaxTopicsPerNamespace( - String host, int port, String tenant, String namespace, int? maxTopicsPerNamespace) async { - String url = 'http://$host:${port.toString()}/admin/v2/namespaces/$tenant/$namespace/maxTopicsPerNamespace'; - var response = await http.post(Uri.parse(url), - headers: { - 'Content-Type': 'application/json; charset=UTF-8', - }, - body: maxTopicsPerNamespace.toString()); - if (HttpUtil.abnormal(response.statusCode)) { - log('ErrorCode is ${response.statusCode}, body is ${response.body}'); - throw Exception('ErrorCode is ${response.statusCode}, body is ${response.body}'); + static Future setMaxTopicsPerNamespace(int id, String host, int port, TlsContext tlsContext, String tenant, + String namespace, int? maxTopicsPerNamespace) async { + String url = tlsContext.enableTls + ? HttpUtil.https + : HttpUtil.http + '$host:${port.toString()}/admin/v2/namespaces/$tenant/$namespace/maxTopicsPerNamespace'; + var response = await HttpUtil.getClient(tlsContext, SERVER.PULSAR, id).post(url, + data: maxTopicsPerNamespace.toString(), options: new Options(contentType: ContentType.json.toString())); + if (HttpUtil.abnormal(response.statusCode!)) { + log('ErrorCode is ${response.statusCode}, body is ${response.data}'); + throw Exception('ErrorCode is ${response.statusCode}, body is ${response.data}'); } } } diff --git a/lib/api/pulsar/pulsar_partitioned_topic_api.dart b/lib/api/pulsar/pulsar_partitioned_topic_api.dart index b46e48c..6bb9d64 100644 --- a/lib/api/pulsar/pulsar_partitioned_topic_api.dart +++ b/lib/api/pulsar/pulsar_partitioned_topic_api.dart @@ -20,9 +20,9 @@ import 'dart:convert'; 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/api/tls_context.dart'; import 'package:paas_dashboard_flutter/module/pulsar/const.dart'; import 'package:paas_dashboard_flutter/module/pulsar/pulsar_consume.dart'; import 'package:paas_dashboard_flutter/module/pulsar/pulsar_partitioned_topic_base.dart'; @@ -34,64 +34,67 @@ import 'package:paas_dashboard_flutter/module/pulsar/pulsar_topic.dart'; import 'package:paas_dashboard_flutter/ui/util/string_util.dart'; class PulsarPartitionedTopicApi { - static Future createPartitionTopic( - String host, int port, String tenant, String namespace, String topic, int partitionNum) async { - var url = 'http://$host:${port.toString()}/admin/v2/persistent/$tenant/$namespace/$topic/partitions'; - var response = await http.put(Uri.parse(url), - headers: { - 'Content-Type': 'application/json; charset=UTF-8', - }, - body: partitionNum.toString()); - if (HttpUtil.abnormal(response.statusCode)) { - log('ErrorCode is ${response.statusCode}, body is ${response.body}'); - throw Exception('ErrorCode is ${response.statusCode}, body is ${response.body}'); + static Future createPartitionTopic(int id, String host, int port, TlsContext tlsContext, String tenant, + String namespace, String topic, int partitionNum) async { + var url = tlsContext.enableTls + ? HttpUtil.https + : HttpUtil.http + '$host:${port.toString()}/admin/v2/persistent/$tenant/$namespace/$topic/partitions'; + var response = + await HttpUtil.getClient(tlsContext, SERVER.PULSAR, id).put(url, data: partitionNum.toString()); + if (HttpUtil.abnormal(response.statusCode!)) { + log('ErrorCode is ${response.statusCode}, body is ${response.data}'); + throw Exception('ErrorCode is ${response.statusCode}, body is ${response.data}'); } - return response.body; + return response.data!; } - static Future deletePartitionTopic( - String host, int port, String tenant, String namespace, String topic, bool force) async { - var url = 'http://$host:${port.toString()}/admin/v2/persistent/$tenant/$namespace/$topic/partitions?force=$force'; - var response = await http.delete(Uri.parse(url), headers: { - 'Content-Type': 'application/json; charset=UTF-8', - }); - if (HttpUtil.abnormal(response.statusCode)) { - log('ErrorCode is ${response.statusCode}, body is ${response.body}'); - throw Exception('ErrorCode is ${response.statusCode}, body is ${response.body}'); + static Future deletePartitionTopic(int id, String host, int port, TlsContext tlsContext, String tenant, + String namespace, String topic, bool force) async { + var url = tlsContext.enableTls + ? HttpUtil.https + : HttpUtil.http + + '$host:${port.toString()}/admin/v2/persistent/$tenant/$namespace/$topic/partitions?force=$force'; + var response = await HttpUtil.getClient(tlsContext, SERVER.PULSAR, id).delete(url); + if (HttpUtil.abnormal(response.statusCode!)) { + log('ErrorCode is ${response.statusCode}, body is ${response.data}'); + throw Exception('ErrorCode is ${response.statusCode}, body is ${response.data}'); } - return response.body; + return response.data!; } - static Future modifyPartitionTopic( - String host, int port, String tenant, String namespace, String topic, int partitionNum) async { - var url = 'http://$host:${port.toString()}/admin/v2/persistent/$tenant/$namespace/$topic/partitions'; - var response = await http.post(Uri.parse(url), - headers: { - 'Content-Type': 'application/json; charset=UTF-8', - }, - body: partitionNum.toString()); - if (HttpUtil.abnormal(response.statusCode)) { - log('ErrorCode is ${response.statusCode}, body is ${response.body}'); - throw Exception('ErrorCode is ${response.statusCode}, body is ${response.body}'); + static Future modifyPartitionTopic(int id, String host, int port, TlsContext tlsContext, String tenant, + String namespace, String topic, int partitionNum) async { + var url = tlsContext.enableTls + ? HttpUtil.https + : HttpUtil.http + '$host:${port.toString()}/admin/v2/persistent/$tenant/$namespace/$topic/partitions'; + var response = + await HttpUtil.getClient(tlsContext, SERVER.PULSAR, id).post(url, data: partitionNum.toString()); + if (HttpUtil.abnormal(response.statusCode!)) { + log('ErrorCode is ${response.statusCode}, body is ${response.data}'); + throw Exception('ErrorCode is ${response.statusCode}, body is ${response.data}'); } - return response.body; + return response.data!; } - static Future> getTopics(String host, int port, String tenant, String namespace) async { - var url = 'http://$host:${port.toString()}/admin/v2/persistent/$tenant/$namespace/partitioned'; - final response = await http.get(Uri.parse(url)); - if (HttpUtil.abnormal(response.statusCode)) { - log('ErrorCode is ${response.statusCode}, body is ${response.body}'); - throw Exception('ErrorCode is ${response.statusCode}, body is ${response.body}'); + static Future> getTopics( + int id, String host, int port, TlsContext tlsContext, String tenant, String namespace) async { + var url = tlsContext.enableTls + ? HttpUtil.https + : HttpUtil.http + '$host:${port.toString()}/admin/v2/persistent/$tenant/$namespace/partitioned'; + var response = await HttpUtil.getClient(tlsContext, SERVER.PULSAR, id).get(url); + if (HttpUtil.abnormal(response.statusCode!)) { + log('ErrorCode is ${response.statusCode}, body is ${response.data}'); + throw Exception('ErrorCode is ${response.statusCode}, body is ${response.data}'); } - List jsonResponse = json.decode(response.body) as List; + List jsonResponse = json.decode(response.data!) as List; return jsonResponse.map((name) => new TopicResp.fromJson(name)).toList(); } static Future> getSubscription( - String host, int port, String tenant, String namespace, String topic) async { + int id, String host, int port, TlsContext tlsContext, String tenant, String namespace, String topic) async { String data = ""; - await PulsarStatApi.partitionedTopicStats(host, port, tenant, namespace, topic).then((value) => {data = value}); + await PulsarStatApi.partitionedTopicStats(id, host, port, tlsContext, tenant, namespace, topic) + .then((value) => {data = value}); List respList = new List.empty(growable: true); Map statsMap = json.decode(data) as Map; if (statsMap.containsKey("subscriptions")) { @@ -106,21 +109,23 @@ class PulsarPartitionedTopicApi { return respList; } - static Future clearBacklog( - String host, int port, String tenant, String namespace, String topic, String subscription) async { - var url = - 'http://$host:${port.toString()}/admin/v2/persistent/$tenant/$namespace/$topic/subscription/$subscription/skip_all'; - final response = await http.post(Uri.parse(url)); - if (HttpUtil.abnormal(response.statusCode)) { - log('ErrorCode is ${response.statusCode}, body is ${response.body}'); - throw Exception('ErrorCode is ${response.statusCode}, body is ${response.body}'); + static Future clearBacklog(int id, String host, int port, TlsContext tlsContext, String tenant, + String namespace, String topic, String subscription) async { + var url = tlsContext.enableTls + ? HttpUtil.https + : HttpUtil.http + + '$host:${port.toString()}/admin/v2/persistent/$tenant/$namespace/$topic/subscription/$subscription/skip_all'; + var response = await HttpUtil.getClient(tlsContext, SERVER.PULSAR, id).post(url); + if (HttpUtil.abnormal(response.statusCode!)) { + log('ErrorCode is ${response.statusCode}, body is ${response.data}'); + throw Exception('ErrorCode is ${response.statusCode}, body is ${response.data}'); } - return response.body; + return response.data!; } - static Future getSubscriptionBacklog( - String host, int port, String tenant, String namespace, String topic, String subscription) async { - String data = PulsarStatApi.partitionedTopicStats(host, port, tenant, namespace, topic) as String; + static Future getSubscriptionBacklog(int id, String host, int port, TlsContext tlsContext, String tenant, + String namespace, String topic, String subscription) async { + String data = PulsarStatApi.partitionedTopicStats(id, host, port, tlsContext, tenant, namespace, topic) as String; Map statsMap = json.decode(data) as Map; if (statsMap.containsKey("subscriptions")) { @@ -135,9 +140,10 @@ class PulsarPartitionedTopicApi { } static Future> getConsumers( - String host, int port, String tenant, String namespace, String topic) async { + int id, String host, int port, TlsContext tlsContext, String tenant, String namespace, String topic) async { String data = ""; - await PulsarStatApi.partitionedTopicStats(host, port, tenant, namespace, topic).then((value) => {data = value}); + await PulsarStatApi.partitionedTopicStats(id, host, port, tlsContext, tenant, namespace, topic) + .then((value) => {data = value}); List respList = new List.empty(growable: true); Map statsMap = json.decode(data) as Map; if (statsMap.containsKey("subscriptions")) { @@ -191,9 +197,10 @@ class PulsarPartitionedTopicApi { } static Future> getProducers( - String host, int port, String tenant, String namespace, String topic) async { + int id, String host, int port, TlsContext tlsContext, String tenant, String namespace, String topic) async { String data = ""; - await PulsarStatApi.partitionedTopicStats(host, port, tenant, namespace, topic).then((value) => {data = value}); + await PulsarStatApi.partitionedTopicStats(id, host, port, tlsContext, tenant, namespace, topic) + .then((value) => {data = value}); List respList = new List.empty(growable: true); Map statsMap = json.decode(data) as Map; if (statsMap.containsKey("publishers")) { @@ -214,9 +221,10 @@ class PulsarPartitionedTopicApi { } static Future> getDetails( - String host, int port, String tenant, String namespace, String topic) async { + int id, String host, int port, TlsContext tlsContext, String tenant, String namespace, String topic) async { String data = ""; - await PulsarStatApi.partitionedTopicStats(host, port, tenant, namespace, topic).then((value) => {data = value}); + await PulsarStatApi.partitionedTopicStats(id, host, port, tlsContext, tenant, namespace, topic) + .then((value) => {data = value}); List respList = new List.empty(growable: true); Map statsMap = json.decode(data) as Map; if (statsMap.containsKey("partitions")) { @@ -231,9 +239,10 @@ class PulsarPartitionedTopicApi { } static Future getBase( - String host, int port, String tenant, String namespace, String topic) async { + int id, String host, int port, TlsContext tlsContext, String tenant, String namespace, String topic) async { String data = ""; - await PulsarStatApi.partitionedTopicStats(host, port, tenant, namespace, topic).then((value) => {data = value}); + await PulsarStatApi.partitionedTopicStats(id, host, port, tlsContext, tenant, namespace, topic) + .then((value) => {data = value}); Map statsMap = json.decode(data) as Map; String topicName = topic; @@ -267,21 +276,20 @@ class PulsarPartitionedTopicApi { topicName, partitionNum, msgRateIn, msgRateOut, msgInCounter, msgOutCounter, storageSize); } - static Future sendMsgToPartitionTopic( - String host, int port, String tenant, String namespace, String topic, String key, String value) async { + static Future sendMsgToPartitionTopic(int id, String host, int port, TlsContext tlsContext, String tenant, + String namespace, String topic, String key, String value) async { ProducerMessage producerMessage = new ProducerMessage(key, value); List messageList = new List.empty(growable: true); messageList.add(producerMessage); PublishMessagesReq messagesReq = new PublishMessagesReq(PulsarConst.defaultProducerName, messageList); - var url = 'http://$host:${port.toString()}/topics/persistent/$tenant/$namespace/$topic/'; - var response = await http.post(Uri.parse(url), - headers: { - 'Content-Type': 'application/json; charset=UTF-8', - }, - body: json.encode(messagesReq)); - if (HttpUtil.abnormal(response.statusCode)) { - log('ErrorCode is ${response.statusCode}, body is ${response.body}'); - return "send msg failed, " + response.body; + var url = tlsContext.enableTls + ? HttpUtil.https + : HttpUtil.http + '$host:${port.toString()}/topics/persistent/$tenant/$namespace/$topic/'; + var response = + await HttpUtil.getClient(tlsContext, SERVER.PULSAR, id).post(url, data: json.encode(messagesReq)); + if (HttpUtil.abnormal(response.statusCode!)) { + log('ErrorCode is ${response.statusCode}, body is ${response.data}'); + return "send msg failed, " + response.data!; } return "send msg success"; } diff --git a/lib/api/pulsar/pulsar_sink_api.dart b/lib/api/pulsar/pulsar_sink_api.dart index 632a024..211c141 100644 --- a/lib/api/pulsar/pulsar_sink_api.dart +++ b/lib/api/pulsar/pulsar_sink_api.dart @@ -21,14 +21,16 @@ 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/api/tls_context.dart'; import 'package:paas_dashboard_flutter/module/pulsar/pulsar_sink.dart'; 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'; + static Future createSink(int id, String host, int port, TlsContext tlsContext, String tenant, String namespace, + String sinkName, String subName, String inputTopic, String sinkType, String config) async { + String url = tlsContext.enableTls + ? HttpUtil.https + : HttpUtil.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"); @@ -36,34 +38,43 @@ class PulsarSinkApi { await FlutterClipboard.copy(curlCommand); } - static Future deleteSink(String host, int port, String tenant, String namespace, String sinkName) async { - var url = 'http://$host:${port.toString()}/admin/v3/sinks/$tenant/$namespace/$sinkName'; - final response = await http.delete(Uri.parse(url)); - if (HttpUtil.abnormal(response.statusCode)) { - log('ErrorCode is ${response.statusCode}, body is ${response.body}'); - throw Exception('ErrorCode is ${response.statusCode}, body is ${response.body}'); + static Future deleteSink( + int id, String host, int port, TlsContext tlsContext, String tenant, String namespace, String sinkName) async { + var url = tlsContext.enableTls + ? HttpUtil.https + : HttpUtil.http + '$host:${port.toString()}/admin/v3/sinks/$tenant/$namespace/$sinkName'; + var response = await HttpUtil.getClient(tlsContext, SERVER.PULSAR_FUNCTION, id).delete(url); + if (HttpUtil.abnormal(response.statusCode!)) { + log('ErrorCode is ${response.statusCode}, body is ${response.data}'); + throw Exception('ErrorCode is ${response.statusCode}, body is ${response.data}'); } } - static Future> getSinkList(String host, int port, String tenant, String namespace) async { - var url = 'http://$host:${port.toString()}/admin/v3/sinks/$tenant/$namespace'; - final response = await http.get(Uri.parse(url)); - if (HttpUtil.abnormal(response.statusCode)) { - log('ErrorCode is ${response.statusCode}, body is ${response.body}'); - throw Exception('ErrorCode is ${response.statusCode}, body is ${response.body}'); + static Future> getSinkList( + int id, String host, int port, TlsContext tlsContext, String tenant, String namespace) async { + var url = tlsContext.enableTls + ? HttpUtil.https + : HttpUtil.http + '$host:${port.toString()}/admin/v3/sinks/$tenant/$namespace'; + var response = await HttpUtil.getClient(tlsContext, SERVER.PULSAR_FUNCTION, id).get(url); + if (HttpUtil.abnormal(response.statusCode!)) { + log('ErrorCode is ${response.statusCode}, body is ${response.data}'); + throw Exception('ErrorCode is ${response.statusCode}, body is ${response.data}'); } - List jsonResponse = json.decode(response.body) as List; + List jsonResponse = json.decode(response.data!) as List; return jsonResponse.map((name) => new SinkResp(name)).toList(); } - static Future getSink(String host, int port, String tenant, String namespace, String sinkName) async { - var url = 'http://$host:${port.toString()}/admin/v3/sinks/$tenant/$namespace/$sinkName'; - final response = await http.get(Uri.parse(url)); - if (HttpUtil.abnormal(response.statusCode)) { - log('ErrorCode is ${response.statusCode}, body is ${response.body}'); - throw Exception('ErrorCode is ${response.statusCode}, body is ${response.body}'); + static Future getSink( + int id, String host, int port, TlsContext tlsContext, String tenant, String namespace, String sinkName) async { + var url = tlsContext.enableTls + ? HttpUtil.https + : HttpUtil.http + '$host:${port.toString()}/admin/v3/sinks/$tenant/$namespace/$sinkName'; + var response = await HttpUtil.getClient(tlsContext, SERVER.PULSAR_FUNCTION, id).get(url); + if (HttpUtil.abnormal(response.statusCode!)) { + log('ErrorCode is ${response.statusCode}, body is ${response.data}'); + throw Exception('ErrorCode is ${response.statusCode}, body is ${response.data}'); } - Map jsonResponse = json.decode(response.body) as Map; + Map jsonResponse = json.decode(response.data!) as Map; return SinkConfigResp.fromJson(jsonResponse); } } diff --git a/lib/api/pulsar/pulsar_source_api.dart b/lib/api/pulsar/pulsar_source_api.dart index 07dc1ca..7bfb195 100644 --- a/lib/api/pulsar/pulsar_source_api.dart +++ b/lib/api/pulsar/pulsar_source_api.dart @@ -21,49 +21,59 @@ 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/api/tls_context.dart'; import 'package:paas_dashboard_flutter/module/pulsar/pulsar_source.dart'; 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'; + static Future createSource(int id, String host, int port, TlsContext tlsContext, String tenant, + String namespace, String sourceName, String outputTopic, String sourceType, String config) async { + String url = tlsContext.enableTls + ? HttpUtil.https + : HttpUtil.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 = 'http://$host:${port.toString()}/admin/v3/sources/$tenant/$namespace/$sourceName'; - final response = await http.delete(Uri.parse(url)); - if (HttpUtil.abnormal(response.statusCode)) { - log('ErrorCode is ${response.statusCode}, body is ${response.body}'); - throw Exception('ErrorCode is ${response.statusCode}, body is ${response.body}'); + static Future deleteSource( + int id, String host, int port, TlsContext tlsContext, String tenant, String namespace, String sourceName) async { + var url = tlsContext.enableTls + ? HttpUtil.https + : HttpUtil.http + '$host:${port.toString()}/admin/v3/sources/$tenant/$namespace/$sourceName'; + var response = await HttpUtil.getClient(tlsContext, SERVER.PULSAR_FUNCTION, id).delete(url); + if (HttpUtil.abnormal(response.statusCode!)) { + log('ErrorCode is ${response.statusCode}, body is ${response.data}'); + throw Exception('ErrorCode is ${response.statusCode}, body is ${response.data}'); } } - static Future> getSourceList(String host, int port, String tenant, String namespace) async { - var url = 'http://$host:${port.toString()}/admin/v3/sources/$tenant/$namespace'; - final response = await http.get(Uri.parse(url)); - if (HttpUtil.abnormal(response.statusCode)) { - log('ErrorCode is ${response.statusCode}, body is ${response.body}'); - throw Exception('ErrorCode is ${response.statusCode}, body is ${response.body}'); + static Future> getSourceList( + int id, String host, int port, TlsContext tlsContext, String tenant, String namespace) async { + var url = tlsContext.enableTls + ? HttpUtil.https + : HttpUtil.http + '$host:${port.toString()}/admin/v3/sources/$tenant/$namespace'; + var response = await HttpUtil.getClient(tlsContext, SERVER.PULSAR_FUNCTION, id).get(url); + if (HttpUtil.abnormal(response.statusCode!)) { + log('ErrorCode is ${response.statusCode}, body is ${response.data}'); + throw Exception('ErrorCode is ${response.statusCode}, body is ${response.data}'); } - List jsonResponse = json.decode(response.body) as List; + List jsonResponse = json.decode(response.data!) as List; return jsonResponse.map((name) => new SourceResp(name)).toList(); } static Future getSource( - String host, int port, String tenant, String namespace, String sourceName) async { - var url = 'http://$host:${port.toString()}/admin/v3/sources/$tenant/$namespace/$sourceName'; - final response = await http.get(Uri.parse(url)); - if (HttpUtil.abnormal(response.statusCode)) { - log('ErrorCode is ${response.statusCode}, body is ${response.body}'); - throw Exception('ErrorCode is ${response.statusCode}, body is ${response.body}'); + int id, String host, int port, TlsContext tlsContext, String tenant, String namespace, String sourceName) async { + var url = tlsContext.enableTls + ? HttpUtil.https + : HttpUtil.http + '$host:${port.toString()}/admin/v3/sources/$tenant/$namespace/$sourceName'; + var response = await HttpUtil.getClient(tlsContext, SERVER.PULSAR_FUNCTION, id).get(url); + if (HttpUtil.abnormal(response.statusCode!)) { + log('ErrorCode is ${response.statusCode}, body is ${response.data}'); + throw Exception('ErrorCode is ${response.statusCode}, body is ${response.data}'); } - Map jsonResponse = json.decode(response.body) as Map; + Map jsonResponse = json.decode(response.data!) as Map; return SourceConfigResp.fromJson(jsonResponse); } } diff --git a/lib/api/pulsar/pulsar_stat_api.dart b/lib/api/pulsar/pulsar_stat_api.dart index b480d0c..71da18c 100644 --- a/lib/api/pulsar/pulsar_stat_api.dart +++ b/lib/api/pulsar/pulsar_stat_api.dart @@ -19,28 +19,33 @@ 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/tls_context.dart'; class PulsarStatApi { static Future partitionedTopicStats( - String host, int port, String tenant, String namespace, String topic) async { - var url = 'http://$host:${port.toString()}/admin/v2/persistent/$tenant/$namespace/$topic/partitioned-stats'; - final response = await http.get(Uri.parse(url)); - if (HttpUtil.abnormal(response.statusCode)) { - log('ErrorCode is ${response.statusCode}, body is ${response.body}'); - throw Exception('ErrorCode is ${response.statusCode}, body is ${response.body}'); + int id, String host, int port, TlsContext tlsContext, String tenant, String namespace, String topic) async { + var url = tlsContext.enableTls + ? HttpUtil.https + : HttpUtil.http + '$host:${port.toString()}/admin/v2/persistent/$tenant/$namespace/$topic/partitioned-stats'; + var response = await HttpUtil.getClient(tlsContext, SERVER.PULSAR, id).get(url); + if (HttpUtil.abnormal(response.statusCode!)) { + log('ErrorCode is ${response.statusCode}, body is ${response.data}'); + throw Exception('ErrorCode is ${response.statusCode}, body is ${response.data}'); } - return response.body; + return response.data!; } - static Future topicStats(String host, int port, String tenant, String namespace, String topic) async { - var url = 'http://$host:${port.toString()}/admin/v2/persistent/$tenant/$namespace/$topic/stats'; - final response = await http.get(Uri.parse(url)); - if (HttpUtil.abnormal(response.statusCode)) { - log('ErrorCode is ${response.statusCode}, body is ${response.body}'); - throw Exception('ErrorCode is ${response.statusCode}, body is ${response.body}'); + static Future topicStats( + int id, String host, int port, TlsContext tlsContext, String tenant, String namespace, String topic) async { + var url = tlsContext.enableTls + ? HttpUtil.https + : HttpUtil.http + '$host:${port.toString()}/admin/v2/persistent/$tenant/$namespace/$topic/stats'; + var response = await HttpUtil.getClient(tlsContext, SERVER.PULSAR, id).get(url); + if (HttpUtil.abnormal(response.statusCode!)) { + log('ErrorCode is ${response.statusCode}, body is ${response.data}'); + throw Exception('ErrorCode is ${response.statusCode}, body is ${response.data}'); } - return response.body; + return response.data!; } } diff --git a/lib/api/pulsar/pulsar_tenant_api.dart b/lib/api/pulsar/pulsar_tenant_api.dart index b800540..cc611dc 100644 --- a/lib/api/pulsar/pulsar_tenant_api.dart +++ b/lib/api/pulsar/pulsar_tenant_api.dart @@ -20,53 +20,52 @@ import 'dart:convert'; 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/tls_context.dart'; import 'package:paas_dashboard_flutter/module/pulsar/pulsar_tenant.dart'; class PulsarTenantApi { - static Future createTenant(String host, int port, String tenant) async { + static Future createTenant(int id, String host, int port, TlsContext tlsContext, String tenant) async { String tenantInfo = ""; - await getTenantInfo(host, port, tenant).then((value) => tenantInfo = value); - var url = 'http://$host:${port.toString()}/admin/v2/tenants/$tenant'; - final response = await http.put(Uri.parse(url), - headers: { - 'Content-Type': 'application/json; charset=UTF-8', - }, - body: tenantInfo); - if (HttpUtil.abnormal(response.statusCode)) { - log('ErrorCode is ${response.statusCode}, body is ${response.body}'); - throw Exception('ErrorCode is ${response.statusCode}, body is ${response.body}'); + await getTenantInfo(id, host, port, tenant, tlsContext).then((value) => tenantInfo = value); + var url = + tlsContext.enableTls ? HttpUtil.https : HttpUtil.http + '$host:${port.toString()}/admin/v2/tenants/$tenant'; + var response = await HttpUtil.getClient(tlsContext, SERVER.PULSAR, id).put(url, data: tenantInfo); + if (HttpUtil.abnormal(response.statusCode!)) { + log('ErrorCode is ${response.statusCode}, body is ${response.data}'); + throw Exception('ErrorCode is ${response.statusCode}, body is ${response.data}'); } } - static Future deleteTenant(String host, int port, String tenant) async { - var url = 'http://$host:${port.toString()}/admin/v2/tenants/$tenant'; - final response = await http.delete(Uri.parse(url)); - if (HttpUtil.abnormal(response.statusCode)) { - log('ErrorCode is ${response.statusCode}, body is ${response.body}'); - throw Exception('ErrorCode is ${response.statusCode}, body is ${response.body}'); + static Future deleteTenant(int id, String host, int port, TlsContext tlsContext, String tenant) async { + var url = + tlsContext.enableTls ? HttpUtil.https : HttpUtil.http + '$host:${port.toString()}/admin/v2/tenants/$tenant'; + var response = await HttpUtil.getClient(tlsContext, SERVER.PULSAR, id).delete(url); + if (HttpUtil.abnormal(response.statusCode!)) { + log('ErrorCode is ${response.statusCode}, body is ${response.data}'); + throw Exception('ErrorCode is ${response.statusCode}, body is ${response.data}'); } } - static Future> getTenants(String host, int port) async { - var url = 'http://$host:${port.toString()}/admin/v2/tenants'; - final response = await http.get(Uri.parse(url)); - if (HttpUtil.abnormal(response.statusCode)) { - log('ErrorCode is ${response.statusCode}, body is ${response.body}'); - throw Exception('ErrorCode is ${response.statusCode}, body is ${response.body}'); + static Future> getTenants(int id, String host, int port, TlsContext tlsContext) async { + var url = tlsContext.enableTls ? HttpUtil.https : HttpUtil.http + '$host:${port.toString()}/admin/v2/tenants'; + var response = await HttpUtil.getClient(tlsContext, SERVER.PULSAR, id).get(url); + if (HttpUtil.abnormal(response.statusCode!)) { + log('ErrorCode is ${response.statusCode}, body is ${response.data}'); + throw Exception('ErrorCode is ${response.statusCode}, body is ${response.data}'); } - List jsonResponse = json.decode(response.body) as List; + List jsonResponse = json.decode(response.data!) as List; return jsonResponse.map((name) => new TenantResp.fromJson(name)).toList(); } - static Future getTenantInfo(String host, int port, String tenant) async { - var url = 'http://$host:${port.toString()}/admin/v2/tenants/public'; - final response = await http.get(Uri.parse(url)); - if (HttpUtil.abnormal(response.statusCode)) { - log('ErrorCode is ${response.statusCode}, body is ${response.body}'); - throw Exception('ErrorCode is ${response.statusCode}, body is ${response.body}'); + static Future getTenantInfo(int id, String host, int port, String tenant, TlsContext tlsContext) async { + var url = + tlsContext.enableTls ? HttpUtil.https : HttpUtil.http + '$host:${port.toString()}/admin/v2/tenants/public'; + var response = await HttpUtil.getClient(tlsContext, SERVER.PULSAR, id).get(url); + if (HttpUtil.abnormal(response.statusCode!)) { + log('ErrorCode is ${response.statusCode}, body is ${response.data}'); + throw Exception('ErrorCode is ${response.statusCode}, body is ${response.data}'); } - return response.body; + return response.data!; } } diff --git a/lib/api/pulsar/pulsar_topic_api.dart b/lib/api/pulsar/pulsar_topic_api.dart index b048223..acb5152 100644 --- a/lib/api/pulsar/pulsar_topic_api.dart +++ b/lib/api/pulsar/pulsar_topic_api.dart @@ -20,9 +20,9 @@ import 'dart:convert'; 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/api/tls_context.dart'; import 'package:paas_dashboard_flutter/module/pulsar/const.dart'; import 'package:paas_dashboard_flutter/module/pulsar/pulsar_consume.dart'; import 'package:paas_dashboard_flutter/module/pulsar/pulsar_produce.dart'; @@ -33,46 +33,51 @@ import 'package:paas_dashboard_flutter/module/pulsar/pulsar_topic_base.dart'; import 'package:paas_dashboard_flutter/ui/util/string_util.dart'; class PulsarTopicApi { - static Future createTopic(String host, int port, String tenant, String namespace, String topic) async { - var url = 'http://$host:${port.toString()}/admin/v2/persistent/$tenant/$namespace/$topic'; - var response = await http.put(Uri.parse(url), headers: { - 'Content-Type': 'application/json; charset=UTF-8', - }); - if (HttpUtil.abnormal(response.statusCode)) { - log('ErrorCode is ${response.statusCode}, body is ${response.body}'); - throw Exception('ErrorCode is ${response.statusCode}, body is ${response.body}'); + static Future createTopic( + int id, String host, int port, TlsContext tlsContext, String tenant, String namespace, String topic) async { + var url = tlsContext.enableTls + ? HttpUtil.https + : HttpUtil.http + '$host:${port.toString()}/admin/v2/persistent/$tenant/$namespace/$topic'; + var response = await HttpUtil.getClient(tlsContext, SERVER.PULSAR, id).put(url); + if (HttpUtil.abnormal(response.statusCode!)) { + log('ErrorCode is ${response.statusCode}, body is ${response.data}'); + throw Exception('ErrorCode is ${response.statusCode}, body is ${response.data}'); } - return response.body; + return response.data!; } - static Future deleteTopic( - String host, int port, String tenant, String namespace, String topic, bool force) async { - var url = 'http://$host:${port.toString()}/admin/v2/persistent/$tenant/$namespace/$topic?force=$force'; - var response = await http.delete(Uri.parse(url), headers: { - 'Content-Type': 'application/json; charset=UTF-8', - }); - if (HttpUtil.abnormal(response.statusCode)) { - log('ErrorCode is ${response.statusCode}, body is ${response.body}'); - throw Exception('ErrorCode is ${response.statusCode}, body is ${response.body}'); + static Future deleteTopic(int id, String host, int port, TlsContext tlsContext, String tenant, + String namespace, String topic, bool force) async { + var url = tlsContext.enableTls + ? HttpUtil.https + : HttpUtil.http + '$host:${port.toString()}/admin/v2/persistent/$tenant/$namespace/$topic?force=$force'; + var response = await HttpUtil.getClient(tlsContext, SERVER.PULSAR, id).delete(url); + if (HttpUtil.abnormal(response.statusCode!)) { + log('ErrorCode is ${response.statusCode}, body is ${response.data}'); + throw Exception('ErrorCode is ${response.statusCode}, body is ${response.data}'); } - return response.body; + return response.data!; } - static Future> getTopics(String host, int port, String tenant, String namespace) async { - var url = 'http://$host:${port.toString()}/admin/v2/persistent/$tenant/$namespace'; - final response = await http.get(Uri.parse(url)); - if (HttpUtil.abnormal(response.statusCode)) { - log('ErrorCode is ${response.statusCode}, body is ${response.body}'); - throw Exception('ErrorCode is ${response.statusCode}, body is ${response.body}'); + static Future> getTopics( + int id, String host, int port, TlsContext tlsContext, String tenant, String namespace) async { + var url = tlsContext.enableTls + ? HttpUtil.https + : HttpUtil.http + '$host:${port.toString()}/admin/v2/persistent/$tenant/$namespace'; + var response = await HttpUtil.getClient(tlsContext, SERVER.PULSAR, id).get(url); + if (HttpUtil.abnormal(response.statusCode!)) { + log('ErrorCode is ${response.statusCode}, body is ${response.data}'); + throw Exception('ErrorCode is ${response.statusCode}, body is ${response.data}'); } - List jsonResponse = json.decode(response.body) as List; + List jsonResponse = json.decode(response.data!) as List; return jsonResponse.map((name) => new TopicResp.fromJson(name)).toList(); } static Future> getSubscription( - String host, int port, String tenant, String namespace, String topic) async { + int id, String host, int port, TlsContext tlsContext, String tenant, String namespace, String topic) async { String data = ""; - await PulsarStatApi.topicStats(host, port, tenant, namespace, topic).then((value) => {data = value}); + await PulsarStatApi.topicStats(id, host, port, tlsContext, tenant, namespace, topic) + .then((value) => {data = value}); List respList = new List.empty(growable: true); Map statsMap = json.decode(data) as Map; if (statsMap.containsKey("subscriptions")) { @@ -87,48 +92,50 @@ class PulsarTopicApi { return respList; } - static Future fetchConsumerMessage( - String host, int port, String tenant, String namespace, String topic, String ledgerId, String entryId) async { - var url = - 'http://$host:${port.toString()}/admin/v2/persistent/$tenant/$namespace/$topic/ledger/$ledgerId/entry/$entryId'; - var response = await http.get(Uri.parse(url), headers: { - 'Content-Type': 'application/json; charset=UTF-8', - }); - if (HttpUtil.abnormal(response.statusCode)) { - log('ErrorCode is ${response.statusCode}, body is ${response.body}'); + static Future fetchConsumerMessage(int id, String host, int port, TlsContext tlsContext, String tenant, + String namespace, String topic, String ledgerId, String entryId) async { + var url = tlsContext.enableTls + ? HttpUtil.https + : HttpUtil.http + + '$host:${port.toString()}/admin/v2/persistent/$tenant/$namespace/$topic/ledger/$ledgerId/entry/$entryId'; + var response = await HttpUtil.getClient(tlsContext, SERVER.PULSAR, id).get(url); + if (HttpUtil.abnormal(response.statusCode!)) { + log('ErrorCode is ${response.statusCode}, body is ${response.data}'); return ""; } - return response.body; + return response.data!; } - static Future fetchMessageId( - String host, int port, String tenant, String namespace, String topic, String timestamp) async { - var url = 'http://$host:${port.toString()}/admin/v2/persistent/$tenant/$namespace/$topic/messageid/$timestamp'; - var response = await http.get(Uri.parse(url), headers: { - 'Content-Type': 'application/json; charset=UTF-8', - }); - if (HttpUtil.abnormal(response.statusCode)) { - log('ErrorCode is ${response.statusCode}, body is ${response.body}'); + static Future fetchMessageId(int id, String host, int port, TlsContext tlsContext, String tenant, + String namespace, String topic, String timestamp) async { + var url = tlsContext.enableTls + ? HttpUtil.https + : HttpUtil.http + '$host:${port.toString()}/admin/v2/persistent/$tenant/$namespace/$topic/messageid/$timestamp'; + var response = await HttpUtil.getClient(tlsContext, SERVER.PULSAR, id).get(url); + if (HttpUtil.abnormal(response.statusCode!)) { + log('ErrorCode is ${response.statusCode}, body is ${response.data}'); return ""; } - return response.body; + return response.data!; } - static Future clearBacklog( - String host, int port, String tenant, String namespace, String topic, String subscription) async { - var url = - 'http://$host:${port.toString()}/admin/v2/persistent/$tenant/$namespace/$topic/subscription/$subscription/skip_all'; - final response = await http.post(Uri.parse(url)); - if (HttpUtil.abnormal(response.statusCode)) { - log('ErrorCode is ${response.statusCode}, body is ${response.body}'); - throw Exception('ErrorCode is ${response.statusCode}, body is ${response.body}'); + static Future clearBacklog(int id, String host, int port, TlsContext tlsContext, String tenant, + String namespace, String topic, String subscription) async { + var url = tlsContext.enableTls + ? HttpUtil.https + : HttpUtil.http + + '$host:${port.toString()}/admin/v2/persistent/$tenant/$namespace/$topic/subscription/$subscription/skip_all'; + var response = await HttpUtil.getClient(tlsContext, SERVER.PULSAR, id).post(url); + if (HttpUtil.abnormal(response.statusCode!)) { + log('ErrorCode is ${response.statusCode}, body is ${response.data}'); + throw Exception('ErrorCode is ${response.statusCode}, body is ${response.data}'); } - return response.body; + return response.data!; } - static Future getSubscriptionBacklog( - String host, int port, String tenant, String namespace, String topic, String subscription) async { - String data = PulsarStatApi.topicStats(host, port, tenant, namespace, topic) as String; + static Future getSubscriptionBacklog(int id, String host, int port, TlsContext tlsContext, String tenant, + String namespace, String topic, String subscription) async { + String data = PulsarStatApi.topicStats(id, host, port, tlsContext, tenant, namespace, topic) as String; Map statsMap = json.decode(data) as Map; if (statsMap.containsKey("subscriptions")) { @@ -143,9 +150,10 @@ class PulsarTopicApi { } static Future> getConsumers( - String host, int port, String tenant, String namespace, String topic) async { + int id, String host, int port, TlsContext tlsContext, String tenant, String namespace, String topic) async { String data = ""; - await PulsarStatApi.topicStats(host, port, tenant, namespace, topic).then((value) => {data = value}); + await PulsarStatApi.topicStats(id, host, port, tlsContext, tenant, namespace, topic) + .then((value) => {data = value}); List respList = new List.empty(growable: true); Map statsMap = json.decode(data) as Map; if (statsMap.containsKey("subscriptions")) { @@ -199,9 +207,10 @@ class PulsarTopicApi { } static Future> getProducers( - String host, int port, String tenant, String namespace, String topic) async { + int id, String host, int port, TlsContext tlsContext, String tenant, String namespace, String topic) async { String data = ""; - await PulsarStatApi.topicStats(host, port, tenant, namespace, topic).then((value) => {data = value}); + await PulsarStatApi.topicStats(id, host, port, tlsContext, tenant, namespace, topic) + .then((value) => {data = value}); List respList = new List.empty(growable: true); Map statsMap = json.decode(data) as Map; if (statsMap.containsKey("publishers")) { @@ -222,9 +231,10 @@ class PulsarTopicApi { } static Future getBase( - String host, int port, String tenant, String namespace, String topic) async { + int id, String host, int port, TlsContext tlsContext, String tenant, String namespace, String topic) async { String data = ""; - await PulsarStatApi.topicStats(host, port, tenant, namespace, topic).then((value) => {data = value}); + await PulsarStatApi.topicStats(id, host, port, tlsContext, tenant, namespace, topic) + .then((value) => {data = value}); Map statsMap = json.decode(data) as Map; String topicName = topic; @@ -258,21 +268,20 @@ class PulsarTopicApi { topicName, partitionNum, msgRateIn, msgRateOut, msgInCounter, msgOutCounter, storageSize); } - static Future sendMsg( - String host, int port, String tenant, String namespace, String topic, String partition, key, value) async { + static Future sendMsg(int id, String host, int port, TlsContext tlsContext, String tenant, String namespace, + String topic, String partition, key, value) async { ProducerMessage producerMessage = new ProducerMessage(key, value); List messageList = new List.empty(growable: true); messageList.add(producerMessage); PublishMessagesReq messagesReq = new PublishMessagesReq(PulsarConst.defaultProducerName, messageList); - var url = 'http://$host:${port.toString()}/topics/persistent/$tenant/$namespace/$topic/partitions/$partition'; - var response = await http.post(Uri.parse(url), - headers: { - 'Content-Type': 'application/json; charset=UTF-8', - }, - body: json.encode(messagesReq)); - if (HttpUtil.abnormal(response.statusCode)) { - log('ErrorCode is ${response.statusCode}, body is ${response.body}'); - return "send msg failed, " + response.body; + var url = tlsContext.enableTls + ? HttpUtil.https + : HttpUtil.http + '$host:${port.toString()}/topics/persistent/$tenant/$namespace/$topic/partitions/$partition'; + var response = + await HttpUtil.getClient(tlsContext, SERVER.PULSAR, id).post(url, data: json.encode(messagesReq)); + if (HttpUtil.abnormal(response.statusCode!)) { + log('ErrorCode is ${response.statusCode}, body is ${response.data}'); + return "send msg failed, " + response.data!; } return "send msg success"; } diff --git a/lib/api/tls_context.dart b/lib/api/tls_context.dart new file mode 100644 index 0000000..638bb6e --- /dev/null +++ b/lib/api/tls_context.dart @@ -0,0 +1,34 @@ +// +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. +// + +class TlsContext { + static const int ENABLE_TLS = 1; + static const int DIS_ENABLE_TLS = 0; + final bool enableTls; + final String caFile; + final String clientCertFile; + final String clientKeyFile; + final String clientKeyPassword; + + TlsContext(this.enableTls, this.caFile, this.clientCertFile, this.clientKeyFile, this.clientKeyPassword); + + TlsContext deepCopy() { + return new TlsContext(enableTls, caFile, clientCertFile, clientKeyFile, clientKeyPassword); + } +} diff --git a/lib/module/pulsar/const.dart b/lib/module/pulsar/const.dart index f4de104..35a55c0 100644 --- a/lib/module/pulsar/const.dart +++ b/lib/module/pulsar/const.dart @@ -17,9 +17,17 @@ // under the License. // +import 'package:paas_dashboard_flutter/api/tls_context.dart'; + class PulsarConst { static const String defaultHost = "localhost"; static const int defaultBrokerPort = 8080; static const int defaultFunctionPort = 6650; + static const int defaultEnableTls = TlsContext.DIS_ENABLE_TLS; + static const int defaultFunctionEnableTls = TlsContext.DIS_ENABLE_TLS; + static const String defaultCaFile = ""; + static const String defaultClientCertFile = ""; + static const String defaultClientKeyFile = ""; + static const String defaultClientKeyPassword = ""; static const String defaultProducerName = "flutter-dashboard-producer"; } diff --git a/lib/open/open_api_pulsar.dart b/lib/open/open_api_pulsar.dart index 23bec68..731caca 100644 --- a/lib/open/open_api_pulsar.dart +++ b/lib/open/open_api_pulsar.dart @@ -26,7 +26,8 @@ class OpenApiPulsar { if (pulsarInstance == null) { throw ArgumentError("pulsar instance not exist"); } - var list = await PulsarPartitionedTopicApi.getTopics(pulsarInstance.host, pulsarInstance.port, tenant, namespace); + var list = await PulsarPartitionedTopicApi.getTopics(pulsarInstance.id, pulsarInstance.host, pulsarInstance.port, + pulsarInstance.createTlsContext(), tenant, namespace); return list.length; } } diff --git a/lib/persistent/persistent.dart b/lib/persistent/persistent.dart index 30ce174..065d33d 100644 --- a/lib/persistent/persistent.dart +++ b/lib/persistent/persistent.dart @@ -32,6 +32,23 @@ import 'package:paas_dashboard_flutter/persistent/po/redis_instance_po.dart'; import 'package:paas_dashboard_flutter/persistent/po/sql_instance_po.dart'; import 'package:paas_dashboard_flutter/persistent/po/zk_instance_po.dart'; +class PulsarFormDto { + late int id; + late String name = ""; + late String host = ""; + late int port = 8080; + late String functionHost = ""; + late int functionPort = 6650; + late bool enableTls = false; + late bool functionEnableTls = false; + late String caFile = ""; + late String clientCertFile = ""; + late String clientKeyFile = ""; + late String clientKeyPassword = ""; + + PulsarFormDto(); +} + class Persistent { static PersistentApi? api; @@ -46,8 +63,37 @@ class Persistent { return api!; } - static Future savePulsar(String name, String host, int port, String functionHost, int functionPort) async { - return (await getApi()).savePulsar(name, host, port, functionHost, functionPort); + static Future savePulsar( + String name, + String host, + int port, + String functionHost, + int functionPort, + bool enableTls, + bool functionEnableTls, + String caFile, + String clientCertFile, + String clientKeyFile, + String clientKeyPassword) async { + return (await getApi()).savePulsar(name, host, port, functionHost, functionPort, enableTls, functionEnableTls, + caFile, clientCertFile, clientKeyFile, clientKeyPassword); + } + + static Future updatePulsar( + int id, + String name, + String host, + int port, + String functionHost, + int functionPort, + bool enableTls, + bool functionEnableTls, + String caFile, + String clientCertFile, + String clientKeyFile, + String clientKeyPassword) async { + return (await getApi()).updatePulsar(id, name, host, port, functionHost, functionPort, enableTls, functionEnableTls, + caFile, clientCertFile, clientKeyFile, clientKeyPassword); } static Future deletePulsar(int id) async { diff --git a/lib/persistent/persistent_api.dart b/lib/persistent/persistent_api.dart index cc65d93..53034b4 100644 --- a/lib/persistent/persistent_api.dart +++ b/lib/persistent/persistent_api.dart @@ -29,7 +29,22 @@ import 'package:paas_dashboard_flutter/persistent/po/sql_instance_po.dart'; import 'package:paas_dashboard_flutter/persistent/po/zk_instance_po.dart'; abstract class PersistentApi { - Future savePulsar(String name, String host, int port, String functionHost, int functionPort); + Future savePulsar(String name, String host, int port, String functionHost, int functionPort, bool enableTls, + bool functionEnableTls, String caFile, String clientCertFile, String clientKeyFile, String clientKeyPassword); + + Future updatePulsar( + int id, + String name, + String host, + int port, + String functionHost, + int functionPort, + bool enableTls, + bool functionEnableTls, + String caFile, + String clientCertFile, + String clientKeyFile, + String clientKeyPassword); Future deletePulsar(int id); diff --git a/lib/persistent/persistent_db.dart b/lib/persistent/persistent_db.dart index 18088e9..ad9dd31 100644 --- a/lib/persistent/persistent_db.dart +++ b/lib/persistent/persistent_db.dart @@ -20,6 +20,7 @@ import 'dart:developer'; import 'dart:io'; +import 'package:paas_dashboard_flutter/api/tls_context.dart'; import 'package:paas_dashboard_flutter/module/bk/const.dart'; import 'package:paas_dashboard_flutter/module/mongo/const.dart'; import 'package:paas_dashboard_flutter/module/mysql/const.dart'; @@ -81,10 +82,11 @@ 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, host TEXT, 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, enable_tls INTEGER, function_enable_tls INTEGER, ca_file TEXT, client_cert_file TEXT, client_key_file TEXT, client_key_password TEXT)', ); await db.execute( - 'INSERT INTO pulsar_instances(name, host, port, function_host, function_port) VALUES ("example", "${PulsarConst.defaultHost}", ${PulsarConst.defaultBrokerPort}, "${PulsarConst.defaultHost}", ${PulsarConst.defaultFunctionPort})', + 'INSERT INTO pulsar_instances(name, host, port, function_host, function_port, enable_tls, function_enable_tls, ca_file, client_cert_file, client_key_file, client_key_password) VALUES ' + '("example", "${PulsarConst.defaultHost}", ${PulsarConst.defaultBrokerPort}, "${PulsarConst.defaultHost}", ${PulsarConst.defaultFunctionPort}, ${PulsarConst.defaultEnableTls}, ${PulsarConst.defaultFunctionEnableTls}, "${PulsarConst.defaultCaFile}", "${PulsarConst.defaultClientCertFile}", "${PulsarConst.defaultClientCertFile}", "${PulsarConst.defaultClientKeyPassword}")', ); await db.execute( 'CREATE TABLE bookkeeper_instances(id INTEGER PRIMARY KEY, name TEXT, host TEXT, port INTEGER)', @@ -132,11 +134,70 @@ 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, functionHost, functionPort]; + Future savePulsar( + String name, + String host, + int port, + String functionHost, + int functionPort, + bool enableTls, + bool functionEnableTls, + String caFile, + String clientCertFile, + String clientKeyFile, + String clientKeyPassword) async { + var aux = await getInstance(); + var list = [ + name, + host, + port, + functionHost, + functionPort, + enableTls ? TlsContext.ENABLE_TLS : TlsContext.DIS_ENABLE_TLS, + functionEnableTls ? TlsContext.ENABLE_TLS : TlsContext.DIS_ENABLE_TLS, + caFile, + clientCertFile, + clientKeyFile, + clientKeyPassword + ]; + aux.database.execute( + 'INSERT INTO pulsar_instances(name, host, port, function_host, function_port, enable_tls, function_enable_tls, ca_file, client_cert_file, client_key_file, client_key_password) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)', + list); + } + + @override + Future updatePulsar( + int id, + String name, + String host, + int port, + String functionHost, + int functionPort, + bool enableTls, + bool functionEnableTls, + String caFile, + String clientCertFile, + String clientKeyFile, + String clientKeyPassword) async { + var aux = await getInstance(); + // var map = {"name": name, "host": host, "port": port, "function_host": functionHost, "function_port": functionPort, "enable_tls" enableTls ? TlsContext.ENABLE_TLS : TlsContext.DIS_ENABLE_TLS, "ca_file": caFile, "client_cert_file": clientCertFile, "client_key_file": clientKeyFile, "client_key_password": clientKeyPassword}; + var list = [ + name, + host, + port, + functionHost, + functionPort, + enableTls ? TlsContext.ENABLE_TLS : TlsContext.DIS_ENABLE_TLS, + functionEnableTls ? TlsContext.ENABLE_TLS : TlsContext.DIS_ENABLE_TLS, + caFile, + clientCertFile, + clientKeyFile, + clientKeyPassword, + id + ]; aux.database.execute( - 'INSERT INTO pulsar_instances(name, host, port, function_host, function_port) VALUES (?, ?, ?, ?, ?)', list); + 'UPDATE pulsar_instances set name=?, host=?, port=?, function_host=?, function_port=?, enable_tls=?, function_enable_tls=?, ca_file=?, client_cert_file=?, client_key_file=?, client_key_password=? where id=?', + list); } @override @@ -152,7 +213,18 @@ class PersistentDb implements PersistentApi { return List.generate(maps.length, (i) { var aux = maps[i]; return PulsarInstancePo( - aux['id'], aux['name'], aux['host'], aux['port'], aux['function_host'], aux['function_port']); + aux['id'], + aux['name'], + aux['host'], + aux['port'], + aux['function_host'], + aux['function_port'], + aux['enable_tls'] == TlsContext.ENABLE_TLS, + aux['function_enable_tls'] == TlsContext.ENABLE_TLS, + aux['ca_file'], + aux['client_cert_file'], + aux['client_key_file'], + aux['client_key_password']); }); } @@ -165,8 +237,19 @@ class PersistentDb implements PersistentApi { return null; } var current = maps[0]; - return PulsarInstancePo(current['id'], current['name'], current['host'], current['port'], current['function_host'], - current['function_port']); + return PulsarInstancePo( + current['id'], + current['name'], + current['host'], + current['port'], + current['function_host'], + current['function_port'], + current['enable_tls'] == TlsContext.ENABLE_TLS, + current['function_enable_tls'] == TlsContext.ENABLE_TLS, + current['ca_file'], + current['client_cert_file'], + current['client_key_file'], + current['client_key_password']); } @override diff --git a/lib/persistent/persistent_memory.dart b/lib/persistent/persistent_memory.dart index b64bda1..5d07473 100644 --- a/lib/persistent/persistent_memory.dart +++ b/lib/persistent/persistent_memory.dart @@ -37,7 +37,8 @@ import 'package:paas_dashboard_flutter/persistent/po/zk_instance_po.dart'; class PersistentMemory implements PersistentApi { @override - Future savePulsar(String name, String host, int port, String functionHost, int functionPort) { + Future savePulsar(String name, String host, int port, String functionHost, int functionPort, bool enableTls, + bool functionEnableTls, String caFile, String clientCertFile, String clientKeyFile, String clientKeyPassword) { // TODO: implement savePulsar throw UnimplementedError(); } @@ -51,8 +52,19 @@ class PersistentMemory implements PersistentApi { @override Future> pulsarInstances() async { return [ - new PulsarInstancePo(0, "example", PulsarConst.defaultHost, PulsarConst.defaultBrokerPort, - PulsarConst.defaultHost, PulsarConst.defaultFunctionPort) + new PulsarInstancePo( + 0, + "example", + PulsarConst.defaultHost, + PulsarConst.defaultBrokerPort, + PulsarConst.defaultHost, + PulsarConst.defaultFunctionPort, + PulsarConst.defaultEnableTls == 1, + PulsarConst.defaultFunctionEnableTls == 1, + PulsarConst.defaultCaFile, + PulsarConst.defaultClientCertFile, + PulsarConst.defaultClientKeyFile, + PulsarConst.defaultClientKeyPassword) ]; } @@ -61,8 +73,19 @@ class PersistentMemory implements PersistentApi { if (name != "example") { return null; } - return new PulsarInstancePo(0, "example", PulsarConst.defaultHost, PulsarConst.defaultBrokerPort, - PulsarConst.defaultHost, PulsarConst.defaultFunctionPort); + return new PulsarInstancePo( + 0, + "example", + PulsarConst.defaultHost, + PulsarConst.defaultBrokerPort, + PulsarConst.defaultHost, + PulsarConst.defaultFunctionPort, + PulsarConst.defaultEnableTls == 1, + PulsarConst.defaultFunctionEnableTls == 1, + PulsarConst.defaultCaFile, + PulsarConst.defaultClientCertFile, + PulsarConst.defaultClientKeyFile, + PulsarConst.defaultClientKeyPassword); } @override @@ -262,4 +285,22 @@ class PersistentMemory implements PersistentApi { } return new RedisInstancePo(0, "example", RedisConst.defaultIp, RedisConst.defaultPort, RedisConst.defaultPassword); } + + @override + Future updatePulsar( + int id, + String name, + String host, + int port, + String functionHost, + int functionPort, + bool enableTls, + bool functionEnableTls, + String caFile, + String clientCertFile, + String clientKeyFile, + String clientKeyPassword) { + // TODO: implement updatePulsar + throw UnimplementedError(); + } } diff --git a/lib/persistent/po/pulsar_instance_po.dart b/lib/persistent/po/pulsar_instance_po.dart index 9feba02..7b5cc25 100644 --- a/lib/persistent/po/pulsar_instance_po.dart +++ b/lib/persistent/po/pulsar_instance_po.dart @@ -17,6 +17,8 @@ // under the License. // +import 'package:paas_dashboard_flutter/api/tls_context.dart'; + class PulsarInstancePo { final int id; final String name; @@ -24,11 +26,28 @@ class PulsarInstancePo { final int port; final String functionHost; final int functionPort; + final bool enableTls; + final bool functionEnableTls; + final String caFile; + final String clientCertFile; + final String clientKeyFile; + final String clientKeyPassword; - PulsarInstancePo(this.id, this.name, this.host, this.port, this.functionHost, this.functionPort); + PulsarInstancePo(this.id, this.name, this.host, this.port, this.functionHost, this.functionPort, this.enableTls, + this.functionEnableTls, this.caFile, this.clientCertFile, this.clientKeyFile, this.clientKeyPassword); PulsarInstancePo deepCopy() { - return new PulsarInstancePo(id, name, host, port, functionHost, functionPort); + return new PulsarInstancePo(id, name, host, port, functionHost, functionPort, enableTls, functionEnableTls, caFile, + clientCertFile, clientKeyFile, clientKeyPassword); + } + + TlsContext createTlsContext() { + return new TlsContext(this.enableTls, this.caFile, this.clientCertFile, this.clientKeyFile, this.clientKeyPassword); + } + + TlsContext createFunctionTlsContext() { + return new TlsContext( + this.functionEnableTls, this.caFile, this.clientCertFile, this.clientKeyFile, this.clientKeyPassword); } Map toMap() { @@ -38,16 +57,34 @@ class PulsarInstancePo { 'host': host, 'port': port, 'function_host': functionHost, - 'function_port': functionPort, + 'enable_tls': enableTls, + 'function_enable_tls': functionEnableTls, + 'ca_file': caFile, + 'client_cert_file': clientCertFile, + 'client_key_file': clientKeyFile, + 'client_key_password': clientKeyPassword, }; } static List fieldList() { - return ['id', 'name', 'host', 'port', 'function_host', 'function_port']; + return [ + 'id', + 'name', + 'host', + 'port', + 'function_host', + 'function_port', + 'enable_tls', + 'function_enable_tls', + 'ca_file', + 'client_cert_file', + 'client_key_file', + 'client_key_password' + ]; } @override String toString() { - return 'PulsarInstance{id: $id, name: $name, host: $host, port: $port, functionHost: $functionHost, functionPort: $functionPort}'; + return 'PulsarInstance{id: $id, name: $name, host: $host, port: $port, functionHost: $functionHost, functionPort: $functionPort, enableTls: $enableTls, functionEnableTls: $functionEnableTls, caFile: $caFile, clientCertFile: $clientCertFile, clientKeyFile: $clientKeyFile, clientKeyPassword: $clientKeyPassword}'; } } diff --git a/lib/ui/pulsar/pulsar_form_state.dart b/lib/ui/pulsar/pulsar_form_state.dart new file mode 100644 index 0000000..b80bb49 --- /dev/null +++ b/lib/ui/pulsar/pulsar_form_state.dart @@ -0,0 +1,262 @@ +// +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. +// + +import 'package:file_picker/file_picker.dart'; +import 'package:flutter/material.dart'; +import 'package:paas_dashboard_flutter/generated/l10n.dart'; +import 'package:paas_dashboard_flutter/persistent/persistent.dart'; +import 'package:paas_dashboard_flutter/ui/util/form_util.dart'; + +class PulsarForm extends StatefulWidget { + final Function(PulsarFormDto) callback; + final PulsarFormDto? formDto; + + PulsarForm(this.callback, this.formDto); + + @override + State createState() { + return new __PulsarFormState(callback, formDto); + } +} + +class __PulsarFormState extends State { + Function(PulsarFormDto) callback; + PulsarFormDto? formDto; + bool certDisplay = true; //true: don't display + bool create = true; + + __PulsarFormState(this.callback, this.formDto); + + @override + void initState() { + super.initState(); + create = formDto == null; + } + + @override + Widget build(BuildContext context) { + if (!create) { + return IconButton( + onPressed: () { + pulsarFormDialog(); + }, + icon: Icon(Icons.edit), + ); + } else { + return TextButton( + onPressed: () { + pulsarFormDialog(); + }, + child: Text('Create Pulsar Instance')); + } + } + + pulsarFormDialog() { + if (formDto == null) { + formDto = new PulsarFormDto(); + } + certDisplay = !(formDto!.enableTls || formDto!.functionEnableTls); + var formFieldDefList = [ + 'Instance Name', + 'Host', + 'Port', + 'Function Host', + 'Function Port', + ]; + Map formFieldDefValues = { + "Instance Name": formDto!.name, + "Host": formDto!.host, + "Port": formDto!.port.toString(), + "Function Host": formDto!.functionHost, + "Function Port": formDto!.functionPort.toString(), + }; + var editControllerList = formFieldDefList.map((e) => TextEditingController(text: formFieldDefValues[e])).toList(); + List formFieldsList = List.generate( + formFieldDefList.length, + (index) => TextFormField( + decoration: InputDecoration(labelText: formFieldDefList[index]), + controller: editControllerList[index], + )); + showDialog( + context: context, + builder: (BuildContext context) { + return StatefulBuilder( + builder: (BuildContext context, void Function(void Function()) setState) { + List children = new List.from(formFieldsList); + Switch tlsSwitch = new Switch( + value: formDto!.enableTls, + onChanged: (value) { + setState(() { + formDto!.enableTls = value; + certDisplay = !(formDto!.enableTls || formDto!.functionEnableTls); + }); + }); + Row tlsRow = new Row( + children: [ + new Text( + "Enable Tls: ", + style: new TextStyle(color: Colors.blue), + ), + tlsSwitch + ], + ); + Switch functionTlsSwitch = new Switch( + value: formDto!.functionEnableTls, + onChanged: (value) { + setState(() { + formDto!.functionEnableTls = value; + certDisplay = !(formDto!.enableTls || formDto!.functionEnableTls); + }); + }); + Row functionTlsRow = new Row( + children: [ + new Text( + "Function Enable Tls: ", + style: new TextStyle(color: Colors.blue), + ), + functionTlsSwitch + ], + ); + + TextEditingController caFieldController = new TextEditingController(text: formDto!.caFile); + TextFormField caField = new TextFormField( + decoration: InputDecoration(labelText: "CA File"), + controller: caFieldController, + ); + TextButton caPickerButton = new TextButton( + onPressed: () async { + FilePickerResult? caPicker = await FilePicker.platform + .pickFiles(type: FileType.custom, allowedExtensions: ['pem', 'crt'], allowMultiple: false); + if (caPicker != null) { + setState(() { + formDto!.caFile = caPicker.paths[0]!; + }); + } + }, + child: Text(S.of(context).import), + ); + Row caRow = new Row( + children: [new Expanded(child: caField), caPickerButton], + ); + Offstage caStage = new Offstage( + offstage: certDisplay, + child: caRow, + ); + + TextEditingController clientCertFieldController = new TextEditingController(text: formDto!.clientCertFile); + TextFormField clientCertField = new TextFormField( + decoration: InputDecoration(labelText: "Client Cert File"), + controller: clientCertFieldController, + ); + TextButton clientCertPickerButton = new TextButton( + onPressed: () async { + FilePickerResult? caPicker = await FilePicker.platform + .pickFiles(type: FileType.custom, allowedExtensions: ['pem', 'crt'], allowMultiple: false); + if (caPicker != null) { + setState(() { + formDto!.clientCertFile = caPicker.paths[0]!; + }); + } + }, + child: Text(S.of(context).import), + ); + Row clientCertRow = new Row( + children: [new Expanded(child: clientCertField), clientCertPickerButton], + ); + Offstage clientCertStage = new Offstage( + offstage: certDisplay, + child: clientCertRow, + ); + + TextEditingController clientKeyFieldController = new TextEditingController(text: formDto!.clientKeyFile); + TextFormField clientKeyField = new TextFormField( + decoration: InputDecoration(labelText: "Client Key File"), + controller: clientKeyFieldController, + ); + TextButton clientKeyPickerButton = new TextButton( + onPressed: () async { + FilePickerResult? clientKeyPicker = await FilePicker.platform + .pickFiles(type: FileType.custom, allowedExtensions: ['pem', 'crt'], allowMultiple: false); + if (clientKeyPicker != null) { + setState(() { + formDto!.clientKeyFile = clientKeyPicker.paths[0]!; + }); + } + }, + child: Text(S.of(context).import), + ); + Row clientKeyRow = new Row( + children: [new Expanded(child: clientKeyField), clientKeyPickerButton], + ); + Offstage clientKeyStage = new Offstage( + offstage: certDisplay, + child: clientKeyRow, + ); + + TextEditingController clientKeyPasswordController = + new TextEditingController(text: formDto!.clientKeyPassword); + TextFormField clientKeyPasswordField = new TextFormField( + decoration: InputDecoration(labelText: "Client Key Password"), + controller: clientKeyPasswordController, + ); + Offstage clientKeyPasswordStage = new Offstage( + offstage: certDisplay, + child: clientKeyPasswordField, + ); + + children.add(tlsRow); + children.add(functionTlsRow); + children.add(caStage); + children.add(clientCertStage); + children.add(clientKeyStage); + children.add(clientKeyPasswordStage); + + return AlertDialog( + scrollable: true, + title: Text("Create Pulsar Instance Form"), + content: Form(child: Column(children: children)), + actions: [ + ElevatedButton( + child: Text(FormUtil.CREATE), + onPressed: () { + List list = editControllerList.map((e) => e.value.text).toList(); + formDto!.name = list[0]; + formDto!.host = list[1]; + formDto!.port = int.parse(list[2]); + formDto!.functionHost = list[3]; + formDto!.functionPort = int.parse(list[4]); + formDto!.clientKeyPassword = clientKeyPasswordController.value.text; + callback(formDto!); + Navigator.of(context).pop(); + }, + ), + ElevatedButton( + child: Text(FormUtil.CANCEL), + onPressed: () { + Navigator.of(context).pop(); + }, + ) + ], + ); + }, + ); + }, + ); + } +} diff --git a/lib/ui/pulsar/pulsar_page.dart b/lib/ui/pulsar/pulsar_page.dart index 5c149b5..530440c 100644 --- a/lib/ui/pulsar/pulsar_page.dart +++ b/lib/ui/pulsar/pulsar_page.dart @@ -19,12 +19,14 @@ import 'package:flutter/material.dart'; import 'package:paas_dashboard_flutter/generated/l10n.dart'; +import 'package:paas_dashboard_flutter/persistent/persistent.dart'; +import 'package:paas_dashboard_flutter/persistent/po/pulsar_instance_po.dart'; import 'package:paas_dashboard_flutter/route/page_route_const.dart'; +import 'package:paas_dashboard_flutter/ui/pulsar/pulsar_form_state.dart'; import 'package:paas_dashboard_flutter/ui/util/data_cell_util.dart'; import 'package:paas_dashboard_flutter/ui/util/form_util.dart'; import 'package:paas_dashboard_flutter/vm/pulsar/pulsar_instance_list_view_model.dart'; import 'package:provider/provider.dart'; -import 'package:paas_dashboard_flutter/persistent/po/pulsar_instance_po.dart'; class PulsarPage extends StatefulWidget { @override @@ -43,36 +45,57 @@ class _PulsarPageState extends State { @override Widget build(BuildContext context) { final vm = Provider.of(context); + var datatable = DataTable( + showCheckboxColumn: false, + columns: [ + DataColumn(label: Text('Id')), + DataColumn(label: Text('Name')), + DataColumn(label: Text('Host')), + DataColumn(label: Text('Port')), + DataColumn(label: Text('FunctionHost')), + DataColumn(label: Text('FunctionPort')), + DataColumn(label: Text('EnableTls')), + DataColumn(label: Text('Function EnableTLS')), + DataColumn(label: Text('Ca File')), + DataColumn(label: Text('Client Certificate File')), + DataColumn(label: Text('Client Key File')), + DataColumn(label: Text('Client Key Password')), + DataColumn(label: Text('Modify instance')), + ], + rows: vm.instances + .map((itemRow) => DataRow( + onSelectChanged: (bool? selected) { + Navigator.pushNamed(context, PageRouteConst.PulsarInstance, arguments: itemRow.deepCopy()); + }, + cells: [ + DataCell(Text(itemRow.id.toString())), + DataCell(Text(itemRow.name)), + DataCell(Text(itemRow.host)), + DataCell(Text(itemRow.port.toString())), + DataCell(Text(itemRow.functionHost)), + DataCell(Text(itemRow.functionPort.toString())), + DataCell(Text(itemRow.enableTls.toString())), + DataCell(Text(itemRow.functionEnableTls.toString())), + DataCell(Text(itemRow.caFile.toString())), + DataCell(Text(itemRow.clientCertFile.toString())), + DataCell(Text(itemRow.clientKeyFile.toString())), + DataCell(Text(itemRow.clientKeyPassword.toString())), + DataCell(Row( + children: [ + updateInstanceButton(context, itemRow.toPulsarFormDto()), + DataCellUtil.newDelDataButton(() { + vm.deletePulsar(itemRow.id); + }) + ], + )) + ])) + .toList(), + ); var tableView = SingleChildScrollView( - child: DataTable( - showCheckboxColumn: false, - columns: [ - DataColumn(label: Text('Id')), - DataColumn(label: Text('Name')), - DataColumn(label: Text('Host')), - DataColumn(label: Text('Port')), - DataColumn(label: Text('FunctionHost')), - DataColumn(label: Text('FunctionPort')), - DataColumn(label: Text('Delete instance')), - ], - rows: vm.instances - .map((itemRow) => DataRow( - onSelectChanged: (bool? selected) { - Navigator.pushNamed(context, PageRouteConst.PulsarInstance, arguments: itemRow.deepCopy()); - }, - cells: [ - DataCell(Text(itemRow.id.toString())), - DataCell(Text(itemRow.name)), - DataCell(Text(itemRow.host)), - DataCell(Text(itemRow.port.toString())), - DataCell(Text(itemRow.functionHost)), - DataCell(Text(itemRow.functionPort.toString())), - DataCellUtil.newDelDataCell(() { - vm.deletePulsar(itemRow.id); - }), - ])) - .toList(), - ), + physics: ScrollPhysics(), + primary: true, + scrollDirection: Axis.horizontal, + child: datatable, ); var formButton = createInstanceButton(context); var refreshButton = TextButton( @@ -83,8 +106,15 @@ class _PulsarPageState extends State { var exportButton = FormUtil.createExportButton(PulsarInstancePo.fieldList().toList(), vm.instances.map((e) => e.pulsarInstancePo.toMap().values.toList()).toList(), context); var importButton = FormUtil.createImportButton( - PulsarInstancePo.fieldList(), context, (data) => vm.createPulsar(data[1], data[2], data[3], data[4], data[5])); + PulsarInstancePo.fieldList(), + context, + (data) => vm.createPulsar( + data[1], data[2], data[3], data[4], data[5], data[6], data[7], data[8], data[9], data[10], data[11])); + var body = ListView( + physics: NeverScrollableScrollPhysics(), + shrinkWrap: true, + controller: ScrollController(), children: [ Container( height: 50, @@ -97,9 +127,10 @@ class _PulsarPageState extends State { Center( child: Text('Pulsar Instance List'), ), - tableView + Scrollbar(radius: Radius.circular(10), thickness: 10, child: tableView) ], ); + return Scaffold( appBar: AppBar( title: Text('Pulsar Dashboard'), @@ -107,17 +138,40 @@ class _PulsarPageState extends State { body: body); } - ButtonStyleButton createInstanceButton(BuildContext context) { + Widget updateInstanceButton(BuildContext context, PulsarFormDto formDto) { + final vm = Provider.of(context, listen: false); + return new PulsarForm((formDto) { + vm.updatePulsar( + formDto.id, + formDto.name, + formDto.host, + formDto.port, + formDto.functionHost, + formDto.functionPort, + formDto.enableTls, + formDto.functionEnableTls, + formDto.caFile, + formDto.clientCertFile, + formDto.clientKeyFile, + formDto.clientKeyPassword); + }, formDto); + } + + Widget createInstanceButton(BuildContext context) { final vm = Provider.of(context, listen: false); - var list = [ - FormFieldDef('Instance Name'), - FormFieldDef('Host'), - FormFieldDef('Port'), - FormFieldDef('Function Host'), - FormFieldDef('Function Port'), - ]; - return FormUtil.createButton5("Pulsar Instance", list, context, (name, host, port, functionHost, functionPort) { - vm.createPulsar(name, host, int.parse(port), functionHost, int.parse(functionPort)); - }); + return new PulsarForm((formDto) { + vm.createPulsar( + formDto.name, + formDto.host, + formDto.port, + formDto.functionHost, + formDto.functionPort, + formDto.enableTls, + formDto.functionEnableTls, + formDto.caFile, + formDto.clientCertFile, + formDto.clientKeyFile, + formDto.clientKeyPassword); + }, null); } } diff --git a/lib/ui/util/data_cell_util.dart b/lib/ui/util/data_cell_util.dart index 05a21fa..46d1f57 100644 --- a/lib/ui/util/data_cell_util.dart +++ b/lib/ui/util/data_cell_util.dart @@ -26,6 +26,10 @@ class DataCellUtil { return DataCell(DeleteButton(voidCallback)); } + static DeleteButton newDelDataButton(VoidCallback voidCallback) { + return DeleteButton(voidCallback); + } + static DataCell newForceDelDataCell(Function(bool) callback) { return DataCell(ForceDeleteButton(callback)); } diff --git a/lib/vm/pulsar/pulsar_cluster_view_model.dart b/lib/vm/pulsar/pulsar_cluster_view_model.dart index 35222e3..7cbb73f 100644 --- a/lib/vm/pulsar/pulsar_cluster_view_model.dart +++ b/lib/vm/pulsar/pulsar_cluster_view_model.dart @@ -18,6 +18,7 @@ // import 'package:paas_dashboard_flutter/api/pulsar/pulsar_cluster_api.dart'; +import 'package:paas_dashboard_flutter/api/tls_context.dart'; import 'package:paas_dashboard_flutter/module/pulsar/pulsar_cluster.dart'; import 'package:paas_dashboard_flutter/persistent/po/pulsar_instance_po.dart'; import 'package:paas_dashboard_flutter/vm/base_load_list_page_view_model.dart'; @@ -47,7 +48,9 @@ class PulsarClusterViewModel extends BaseLoadListPageViewModel { Future fetchPulsarCluster() async { try { - this.fullList = await PulsarClusterApi.cluster(host, port); + TlsContext tlsContext = new TlsContext(pulsarInstancePo.enableTls, pulsarInstancePo.caFile, + pulsarInstancePo.clientCertFile, pulsarInstancePo.clientKeyFile, pulsarInstancePo.clientKeyPassword); + this.fullList = await PulsarClusterApi.cluster(id, host, port, tlsContext); this.displayList = this.fullList; loadSuccess(); } on Exception catch (e) { diff --git a/lib/vm/pulsar/pulsar_instance_list_view_model.dart b/lib/vm/pulsar/pulsar_instance_list_view_model.dart index cae4781..d4f5e9a 100644 --- a/lib/vm/pulsar/pulsar_instance_list_view_model.dart +++ b/lib/vm/pulsar/pulsar_instance_list_view_model.dart @@ -30,8 +30,38 @@ class PulsarInstanceListViewModel extends ChangeNotifier { notifyListeners(); } - Future createPulsar(String name, String host, int port, String functionHost, int functionPort) async { - Persistent.savePulsar(name, host, port, functionHost, functionPort); + Future createPulsar( + String name, + String host, + int port, + String functionHost, + int functionPort, + bool enableTls, + bool functionEnableTls, + String caFile, + String clientCertFile, + String clientKeyFile, + String clientKeyPassword) async { + Persistent.savePulsar(name, host, port, functionHost, functionPort, enableTls, functionEnableTls, caFile, + clientCertFile, clientKeyFile, clientKeyPassword); + fetchPulsarInstances(); + } + + Future updatePulsar( + int id, + String name, + String host, + int port, + String functionHost, + int functionPort, + bool enableTls, + bool functionEnableTls, + String caFile, + String clientCertFile, + String clientKeyFile, + String clientKeyPassword) async { + Persistent.updatePulsar(id, name, host, port, functionHost, functionPort, enableTls, functionEnableTls, caFile, + clientCertFile, clientKeyFile, clientKeyPassword); fetchPulsarInstances(); } diff --git a/lib/vm/pulsar/pulsar_instance_view_model.dart b/lib/vm/pulsar/pulsar_instance_view_model.dart index eec7350..b0b7ae0 100644 --- a/lib/vm/pulsar/pulsar_instance_view_model.dart +++ b/lib/vm/pulsar/pulsar_instance_view_model.dart @@ -20,6 +20,7 @@ import 'dart:developer'; import 'package:paas_dashboard_flutter/api/pulsar/pulsar_tenant_api.dart'; +import 'package:paas_dashboard_flutter/persistent/persistent.dart'; import 'package:paas_dashboard_flutter/persistent/po/pulsar_instance_po.dart'; import 'package:paas_dashboard_flutter/vm/base_load_list_page_view_model.dart'; import 'package:paas_dashboard_flutter/vm/pulsar/pulsar_tenant_view_model.dart'; @@ -57,9 +58,50 @@ class PulsarInstanceViewModel extends BaseLoadListPageViewModel fetchTenants() async { try { - final results = await PulsarTenantApi.getTenants(host, port); + final results = await PulsarTenantApi.getTenants(id, host, port, pulsarInstancePo.createTlsContext()); this.fullList = results.map((e) => PulsarTenantViewModel(pulsarInstancePo, e)).toList(); this.displayList = this.fullList; loadSuccess(); @@ -85,7 +127,7 @@ class PulsarInstanceViewModel extends BaseLoadListPageViewModel createTenant(String tenant) async { try { - await PulsarTenantApi.createTenant(host, port, tenant); + await PulsarTenantApi.createTenant(id, host, port, pulsarInstancePo.createTlsContext(), tenant); await fetchTenants(); } on Exception catch (e) { opException = e; @@ -95,7 +137,7 @@ class PulsarInstanceViewModel extends BaseLoadListPageViewModel deleteTenants(String tenant) async { try { - await PulsarTenantApi.deleteTenant(host, port, tenant); + await PulsarTenantApi.deleteTenant(id, host, port, pulsarInstancePo.createTlsContext(), tenant); await fetchTenants(); } on Exception catch (e) { opException = e; diff --git a/lib/vm/pulsar/pulsar_namespace_backlog_quota_view_model.dart b/lib/vm/pulsar/pulsar_namespace_backlog_quota_view_model.dart index 5f7098d..f2c12e3 100644 --- a/lib/vm/pulsar/pulsar_namespace_backlog_quota_view_model.dart +++ b/lib/vm/pulsar/pulsar_namespace_backlog_quota_view_model.dart @@ -115,7 +115,8 @@ class PulsarNamespaceBacklogQuotaViewModel extends BaseLoadViewModel { Future fetchBacklogQuota() async { try { - final BacklogQuotaResp resp = await PulsarNamespaceApi.getBacklogQuota(host, port, tenant, namespace); + final BacklogQuotaResp resp = await PulsarNamespaceApi.getBacklogQuota( + id, host, port, pulsarInstancePo.createTlsContext(), tenant, namespace); this.limitSize = resp.limitSize; this.limitTime = resp.limitTime; this.retentionPolicy = resp.policy; @@ -135,8 +136,8 @@ class PulsarNamespaceBacklogQuotaViewModel extends BaseLoadViewModel { if (retentionPolicy == null) { return; } - await PulsarNamespaceApi.updateBacklogQuota( - host, port, tenant, namespace, limitSize!, limitTime, retentionPolicy!); + await PulsarNamespaceApi.updateBacklogQuota(id, host, port, pulsarInstancePo.createTlsContext(), tenant, + namespace, limitSize!, limitTime, retentionPolicy!); await fetchBacklogQuota(); } on Exception catch (e) { opException = e; diff --git a/lib/vm/pulsar/pulsar_namespace_policies_view_model.dart b/lib/vm/pulsar/pulsar_namespace_policies_view_model.dart index e353bc5..47d4004 100644 --- a/lib/vm/pulsar/pulsar_namespace_policies_view_model.dart +++ b/lib/vm/pulsar/pulsar_namespace_policies_view_model.dart @@ -50,7 +50,8 @@ class PulsarNamespacePoliciesViewModel extends BaseLoadViewModel { Future fetchPolicy() async { try { - final PolicyResp resp = await PulsarNamespaceApi.getPolicy(host, port, tenant, namespace); + final PolicyResp resp = + await PulsarNamespaceApi.getPolicy(id, host, port, pulsarInstancePo.createTlsContext(), tenant, namespace); this.isAllowAutoTopicCreation = resp.isAllowAutoTopicCreation; this.messageTTLInSeconds = resp.messageTTLInSeconds; this.maxProducersPerTopic = resp.maxProducersPerTopic; @@ -166,8 +167,8 @@ class PulsarNamespacePoliciesViewModel extends BaseLoadViewModel { if (defaultNumPartitions == null) { return; } - await PulsarNamespaceApi.setAutoTopicCreation( - host, port, tenant, namespace, isAllowAutoTopicCreation, topicType, defaultNumPartitions); + await PulsarNamespaceApi.setAutoTopicCreation(id, host, port, pulsarInstancePo.createTlsContext(), tenant, + namespace, isAllowAutoTopicCreation, topicType, defaultNumPartitions); await fetchPolicy(); } on Exception catch (e) { opException = e; @@ -180,7 +181,8 @@ class PulsarNamespacePoliciesViewModel extends BaseLoadViewModel { if (messageTTLInSeconds == null) { return; } - await PulsarNamespaceApi.setMessageTTLSecond(host, port, tenant, namespace, messageTTLInSeconds); + await PulsarNamespaceApi.setMessageTTLSecond( + id, host, port, pulsarInstancePo.createTlsContext(), tenant, namespace, messageTTLInSeconds); await fetchPolicy(); } on Exception catch (e) { opException = e; @@ -193,7 +195,8 @@ class PulsarNamespacePoliciesViewModel extends BaseLoadViewModel { if (maxProducersPerTopic == null) { return; } - await PulsarNamespaceApi.setMaxProducersPerTopic(host, port, tenant, namespace, maxProducersPerTopic); + await PulsarNamespaceApi.setMaxProducersPerTopic( + id, host, port, pulsarInstancePo.createTlsContext(), tenant, namespace, maxProducersPerTopic); await fetchPolicy(); } on Exception catch (e) { opException = e; @@ -206,7 +209,8 @@ class PulsarNamespacePoliciesViewModel extends BaseLoadViewModel { if (maxConsumersPerTopic == null) { return; } - await PulsarNamespaceApi.setMaxConsumersPerTopic(host, port, tenant, namespace, maxConsumersPerTopic); + await PulsarNamespaceApi.setMaxConsumersPerTopic( + id, host, port, pulsarInstancePo.createTlsContext(), tenant, namespace, maxConsumersPerTopic); await fetchPolicy(); } on Exception catch (e) { opException = e; @@ -220,7 +224,7 @@ class PulsarNamespacePoliciesViewModel extends BaseLoadViewModel { return; } await PulsarNamespaceApi.setMaxConsumersPerSubscription( - host, port, tenant, namespace, maxConsumersPerSubscription); + id, host, port, pulsarInstancePo.createTlsContext(), tenant, namespace, maxConsumersPerSubscription); await fetchPolicy(); } on Exception catch (e) { opException = e; @@ -234,7 +238,7 @@ class PulsarNamespacePoliciesViewModel extends BaseLoadViewModel { return; } await PulsarNamespaceApi.setMaxUnackedMessagesPerConsumer( - host, port, tenant, namespace, maxUnackedMessagesPerConsumer); + id, host, port, pulsarInstancePo.createTlsContext(), tenant, namespace, maxUnackedMessagesPerConsumer); await fetchPolicy(); } on Exception catch (e) { opException = e; @@ -248,7 +252,7 @@ class PulsarNamespacePoliciesViewModel extends BaseLoadViewModel { return; } await PulsarNamespaceApi.setMaxUnackedMessagesPerSubscription( - host, port, tenant, namespace, maxUnackedMessagesPerSubscription); + id, host, port, pulsarInstancePo.createTlsContext(), tenant, namespace, maxUnackedMessagesPerSubscription); await fetchPolicy(); } on Exception catch (e) { opException = e; @@ -261,7 +265,8 @@ class PulsarNamespacePoliciesViewModel extends BaseLoadViewModel { if (maxSubscriptionsPerTopic == null) { return; } - await PulsarNamespaceApi.setMaxSubscriptionsPerTopic(host, port, tenant, namespace, maxSubscriptionsPerTopic); + await PulsarNamespaceApi.setMaxSubscriptionsPerTopic( + id, host, port, pulsarInstancePo.createTlsContext(), tenant, namespace, maxSubscriptionsPerTopic); await fetchPolicy(); } on Exception catch (e) { opException = e; @@ -274,7 +279,8 @@ class PulsarNamespacePoliciesViewModel extends BaseLoadViewModel { if (maxTopicsPerNamespace == null) { return; } - await PulsarNamespaceApi.setMaxTopicsPerNamespace(host, port, tenant, namespace, maxTopicsPerNamespace); + await PulsarNamespaceApi.setMaxTopicsPerNamespace( + id, host, port, pulsarInstancePo.createTlsContext(), tenant, namespace, maxTopicsPerNamespace); await fetchPolicy(); } 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 71746a3..f9e5659 100644 --- a/lib/vm/pulsar/pulsar_namespace_view_model.dart +++ b/lib/vm/pulsar/pulsar_namespace_view_model.dart @@ -61,7 +61,8 @@ class PulsarNamespaceViewModel extends BaseLoadListPageViewModel fetchTopics() async { try { - final results = await PulsarPartitionedTopicApi.getTopics(host, port, tenant, namespace); + final results = await PulsarPartitionedTopicApi.getTopics( + id, host, port, pulsarInstancePo.createTlsContext(), tenant, namespace); this.fullList = results.map((e) => PulsarPartitionedTopicViewModel(pulsarInstancePo, tenantResp, namespaceResp, e)).toList(); this.displayList = this.fullList; @@ -87,7 +88,8 @@ class PulsarNamespaceViewModel extends BaseLoadListPageViewModel createPartitionedTopic(String topic, int partition) async { try { - await PulsarPartitionedTopicApi.createPartitionTopic(host, port, tenant, namespace, topic, partition); + await PulsarPartitionedTopicApi.createPartitionTopic( + id, host, port, pulsarInstancePo.createTlsContext(), tenant, namespace, topic, partition); await fetchTopics(); } on Exception catch (e) { opException = e; @@ -97,7 +99,8 @@ class PulsarNamespaceViewModel extends BaseLoadListPageViewModel deletePartitionedTopic(String topic) async { try { - await PulsarPartitionedTopicApi.deletePartitionTopic(host, port, tenant, namespace, topic, false); + await PulsarPartitionedTopicApi.deletePartitionTopic( + id, host, port, pulsarInstancePo.createTlsContext(), tenant, namespace, topic, false); await fetchTopics(); } on Exception catch (e) { opException = 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 4ec3931..3276582 100644 --- a/lib/vm/pulsar/pulsar_partitioned_topic_basic_view_model.dart +++ b/lib/vm/pulsar/pulsar_partitioned_topic_basic_view_model.dart @@ -73,7 +73,8 @@ class PulsarPartitionedTopicBasicViewModel extends BaseLoadViewModel { Future fetchPartitions() async { try { - final results = await PulsarPartitionedTopicApi.getBase(host, port, tenant, namespace, topic); + final results = await PulsarPartitionedTopicApi.getBase( + id, host, port, pulsarInstancePo.createTlsContext(), tenant, namespace, topic); partitionNum = results.partitionNum.toString(); msgRateIn = results.msgRateIn; msgRateOut = results.msgRateOut; @@ -90,7 +91,8 @@ class PulsarPartitionedTopicBasicViewModel extends BaseLoadViewModel { Future modifyTopicPartition(String topic, int partition) async { try { - await PulsarPartitionedTopicApi.modifyPartitionTopic(host, port, tenant, namespace, topic, partition); + await PulsarPartitionedTopicApi.modifyPartitionTopic( + id, host, port, pulsarInstancePo.createTlsContext(), tenant, namespace, topic, partition); await fetchPartitions(); } on Exception catch (e) { opException = e; diff --git a/lib/vm/pulsar/pulsar_partitioned_topic_consumer_view_model.dart b/lib/vm/pulsar/pulsar_partitioned_topic_consumer_view_model.dart index ae46935..72316ef 100644 --- a/lib/vm/pulsar/pulsar_partitioned_topic_consumer_view_model.dart +++ b/lib/vm/pulsar/pulsar_partitioned_topic_consumer_view_model.dart @@ -68,7 +68,8 @@ class PulsarPartitionedTopicConsumerViewModel extends BaseLoadListViewModel fetchConsumers() async { try { - final results = await PulsarPartitionedTopicApi.getConsumers(host, port, tenant, namespace, topic); + final results = await PulsarPartitionedTopicApi.getConsumers( + id, host, port, pulsarInstancePo.createTlsContext(), tenant, namespace, topic); this.fullList = results; this.displayList = this.fullList; loadSuccess(); 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 b664bd7..4bb81f8 100644 --- a/lib/vm/pulsar/pulsar_partitioned_topic_detail_view_model.dart +++ b/lib/vm/pulsar/pulsar_partitioned_topic_detail_view_model.dart @@ -68,7 +68,8 @@ class PulsarPartitionedTopicDetailViewModel extends BaseLoadListViewModel fetchPartitions() async { try { - final results = await PulsarPartitionedTopicApi.getDetails(host, port, tenant, namespace, topic); + final results = await PulsarPartitionedTopicApi.getDetails( + id, host, port, pulsarInstancePo.createTlsContext(), tenant, namespace, topic); this.fullList = results; this.displayList = this.fullList; loadSuccess(); 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 08a619b..b23d3a0 100644 --- a/lib/vm/pulsar/pulsar_partitioned_topic_list_view_model.dart +++ b/lib/vm/pulsar/pulsar_partitioned_topic_list_view_model.dart @@ -62,7 +62,8 @@ class PulsarPartitionedTopicListViewModel extends BaseLoadListPageViewModel fetchTopics() async { try { - final results = await PulsarPartitionedTopicApi.getTopics(host, port, tenant, namespace); + final results = await PulsarPartitionedTopicApi.getTopics( + id, host, port, pulsarInstancePo.createTlsContext(), tenant, namespace); this.fullList = results.map((e) => PulsarPartitionedTopicViewModel(pulsarInstancePo, tenantResp, namespaceResp, e)).toList(); this.displayList = this.fullList; @@ -88,7 +89,8 @@ class PulsarPartitionedTopicListViewModel extends BaseLoadListPageViewModel createPartitionedTopic(String topic, int partition) async { try { - await PulsarPartitionedTopicApi.createPartitionTopic(host, port, tenant, namespace, topic, partition); + await PulsarPartitionedTopicApi.createPartitionTopic( + id, host, port, pulsarInstancePo.createTlsContext(), tenant, namespace, topic, partition); await fetchTopics(); } on Exception catch (e) { opException = e; @@ -98,7 +100,8 @@ class PulsarPartitionedTopicListViewModel extends BaseLoadListPageViewModel deletePartitionedTopic(String topic, bool force) async { try { - await PulsarPartitionedTopicApi.deletePartitionTopic(host, port, tenant, namespace, topic, force); + await PulsarPartitionedTopicApi.deletePartitionTopic( + id, host, port, pulsarInstancePo.createTlsContext(), tenant, namespace, topic, force); await fetchTopics(); } on Exception catch (e) { opException = 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 1b7f6da..41a476d 100644 --- a/lib/vm/pulsar/pulsar_partitioned_topic_produce_view_model.dart +++ b/lib/vm/pulsar/pulsar_partitioned_topic_produce_view_model.dart @@ -65,6 +65,7 @@ class PulsarPartitionedTopicProduceViewModel extends BaseLoadListViewModel { } Future sendMsg(key, value) { - return PulsarPartitionedTopicApi.sendMsgToPartitionTopic(host, port, tenant, namespace, topic, key, value); + return PulsarPartitionedTopicApi.sendMsgToPartitionTopic( + id, host, port, pulsarInstancePo.createTlsContext(), tenant, namespace, topic, key, value); } } diff --git a/lib/vm/pulsar/pulsar_partitioned_topic_producer_view_model.dart b/lib/vm/pulsar/pulsar_partitioned_topic_producer_view_model.dart index e4c126a..c0360e3 100644 --- a/lib/vm/pulsar/pulsar_partitioned_topic_producer_view_model.dart +++ b/lib/vm/pulsar/pulsar_partitioned_topic_producer_view_model.dart @@ -67,7 +67,8 @@ class PulsarPartitionedTopicProducerViewModel extends BaseLoadListViewModel fetchProducers() async { try { - final results = await PulsarPartitionedTopicApi.getProducers(host, port, tenant, namespace, topic); + final results = await PulsarPartitionedTopicApi.getProducers( + id, host, port, pulsarInstancePo.createTlsContext(), tenant, namespace, topic); this.fullList = results; this.displayList = this.fullList; loadSuccess(); 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 b2143c8..b820953 100644 --- a/lib/vm/pulsar/pulsar_partitioned_topic_subscription_view_model.dart +++ b/lib/vm/pulsar/pulsar_partitioned_topic_subscription_view_model.dart @@ -69,7 +69,8 @@ class PulsarPartitionedTopicSubscriptionViewModel extends BaseLoadListViewModel< Future fetchSubscriptions() async { try { - final results = await PulsarPartitionedTopicApi.getSubscription(host, port, tenant, namespace, topic); + final results = await PulsarPartitionedTopicApi.getSubscription( + id, host, port, pulsarInstancePo.createTlsContext(), tenant, namespace, topic); this.fullList = results; this.displayList = this.fullList; loadSuccess(); @@ -82,7 +83,8 @@ class PulsarPartitionedTopicSubscriptionViewModel extends BaseLoadListViewModel< Future clearBacklog(String subscriptionName) async { try { - await PulsarPartitionedTopicApi.clearBacklog(host, port, tenant, namespace, topic, subscriptionName); + await PulsarPartitionedTopicApi.clearBacklog( + id, host, port, pulsarInstancePo.createTlsContext(), tenant, namespace, topic, subscriptionName); await fetchSubscriptions(); } on Exception catch (e) { opException = e; diff --git a/lib/vm/pulsar/pulsar_sink_basic_view_model.dart b/lib/vm/pulsar/pulsar_sink_basic_view_model.dart index 7aed685..c969e3f 100644 --- a/lib/vm/pulsar/pulsar_sink_basic_view_model.dart +++ b/lib/vm/pulsar/pulsar_sink_basic_view_model.dart @@ -70,7 +70,8 @@ class PulsarSinkBasicViewModel extends BaseLoadViewModel { Future fetch() async { try { - final SinkConfigResp sinkConfigResp = await PulsarSinkApi.getSink(host, port, tenant, namespace, sinkName); + final SinkConfigResp sinkConfigResp = await PulsarSinkApi.getSink( + id, host, port, pulsarInstancePo.createFunctionTlsContext(), tenant, namespace, sinkName); this.inputs = sinkConfigResp.inputs; this.configs = sinkConfigResp.configs; this.archive = sinkConfigResp.archive; diff --git a/lib/vm/pulsar/pulsar_sink_list_view_model.dart b/lib/vm/pulsar/pulsar_sink_list_view_model.dart index 6f60a14..bc57464 100644 --- a/lib/vm/pulsar/pulsar_sink_list_view_model.dart +++ b/lib/vm/pulsar/pulsar_sink_list_view_model.dart @@ -69,8 +69,8 @@ class PulsarSinkListViewModel extends BaseLoadListPageViewModel 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 PulsarSinkApi.createSink(id, functionHost, functionPort, pulsarInstancePo.createFunctionTlsContext(), + tenant, namespace, sinkName, subName, inputTopic, sinkType, config); await fetchSinks(); } on Exception catch (e) { opException = e; @@ -80,7 +80,8 @@ class PulsarSinkListViewModel extends BaseLoadListPageViewModel fetchSinks() async { try { - final results = await PulsarSinkApi.getSinkList(functionHost, functionPort, tenant, namespace); + final results = await PulsarSinkApi.getSinkList( + id, functionHost, functionPort, pulsarInstancePo.createFunctionTlsContext(), tenant, namespace); this.fullList = results.map((e) => PulsarSinkViewModel(pulsarInstancePo, tenantResp, namespaceResp, e)).toList(); this.displayList = this.fullList; loadSuccess(); @@ -105,7 +106,8 @@ class PulsarSinkListViewModel extends BaseLoadListPageViewModel deleteSink(String name) async { try { - await PulsarSinkApi.deleteSink(functionHost, functionPort, tenant, namespace, name); + await PulsarSinkApi.deleteSink( + id, functionHost, functionPort, pulsarInstancePo.createFunctionTlsContext(), tenant, namespace, name); await fetchSinks(); } on Exception catch (e) { opException = e; diff --git a/lib/vm/pulsar/pulsar_source_basic_view_model.dart b/lib/vm/pulsar/pulsar_source_basic_view_model.dart index 6dca04f..3c90f1d 100644 --- a/lib/vm/pulsar/pulsar_source_basic_view_model.dart +++ b/lib/vm/pulsar/pulsar_source_basic_view_model.dart @@ -70,8 +70,8 @@ class PulsarSourceBasicViewModel extends BaseLoadViewModel { Future fetch() async { try { - final SourceConfigResp sourceConfigResp = - await PulsarSourceApi.getSource(host, port, tenant, namespace, sourceName); + final SourceConfigResp sourceConfigResp = await PulsarSourceApi.getSource( + id, host, port, pulsarInstancePo.createFunctionTlsContext(), tenant, namespace, sourceName); this.topicName = sourceConfigResp.topicName; this.configs = sourceConfigResp.configs; this.archive = sourceConfigResp.archive; diff --git a/lib/vm/pulsar/pulsar_source_list_view_model.dart b/lib/vm/pulsar/pulsar_source_list_view_model.dart index a9d5f53..159f2df 100644 --- a/lib/vm/pulsar/pulsar_source_list_view_model.dart +++ b/lib/vm/pulsar/pulsar_source_list_view_model.dart @@ -69,8 +69,8 @@ class PulsarSourceListViewModel extends BaseLoadListPageViewModel createSource(String sourceName, String outputTopic, String sourceType, String config) async { try { - await PulsarSourceApi.createSource( - functionHost, functionPort, tenant, namespace, sourceName, outputTopic, sourceType, config); + await PulsarSourceApi.createSource(id, functionHost, functionPort, pulsarInstancePo.createFunctionTlsContext(), + tenant, namespace, sourceName, outputTopic, sourceType, config); await fetchSources(); } on Exception catch (e) { opException = e; @@ -80,7 +80,8 @@ class PulsarSourceListViewModel extends BaseLoadListPageViewModel fetchSources() async { try { - final results = await PulsarSourceApi.getSourceList(functionHost, functionPort, tenant, namespace); + final results = await PulsarSourceApi.getSourceList( + id, functionHost, functionPort, pulsarInstancePo.createFunctionTlsContext(), tenant, namespace); this.fullList = results.map((e) => PulsarSourceViewModel(pulsarInstancePo, tenantResp, namespaceResp, e)).toList(); this.displayList = this.fullList; @@ -106,7 +107,8 @@ class PulsarSourceListViewModel extends BaseLoadListPageViewModel deleteSource(String topic) async { try { - await PulsarSourceApi.deleteSource(functionHost, functionPort, tenant, namespace, topic); + await PulsarSourceApi.deleteSource( + id, functionHost, functionPort, pulsarInstancePo.createFunctionTlsContext(), tenant, namespace, topic); await fetchSources(); } on Exception catch (e) { opException = e; diff --git a/lib/vm/pulsar/pulsar_tenant_view_model.dart b/lib/vm/pulsar/pulsar_tenant_view_model.dart index 62a1de5..46f1d5c 100644 --- a/lib/vm/pulsar/pulsar_tenant_view_model.dart +++ b/lib/vm/pulsar/pulsar_tenant_view_model.dart @@ -58,7 +58,8 @@ class PulsarTenantViewModel extends BaseLoadListPageViewModel fetchNamespaces() async { try { - final results = await PulsarNamespaceApi.getNamespaces(host, port, tenant); + final results = + await PulsarNamespaceApi.getNamespaces(id, host, port, pulsarInstancePo.createTlsContext(), tenant); this.fullList = results.map((e) => PulsarNamespaceViewModel(pulsarInstancePo, tenantResp, e)).toList(); this.displayList = this.fullList; loadSuccess(); @@ -83,7 +84,7 @@ class PulsarTenantViewModel extends BaseLoadListPageViewModel createNamespace(String namespace) async { try { - await PulsarNamespaceApi.createNamespace(host, port, tenant, namespace); + await PulsarNamespaceApi.createNamespace(id, host, port, pulsarInstancePo.createTlsContext(), tenant, namespace); await fetchNamespaces(); } on Exception catch (e) { opException = e; @@ -93,7 +94,7 @@ class PulsarTenantViewModel extends BaseLoadListPageViewModel deleteNamespace(String namespace) async { try { - await PulsarNamespaceApi.deleteNamespace(host, port, tenant, namespace); + await PulsarNamespaceApi.deleteNamespace(id, host, port, pulsarInstancePo.createTlsContext(), tenant, namespace); await fetchNamespaces(); } on Exception catch (e) { opException = e; diff --git a/lib/vm/pulsar/pulsar_topic_basic_view_model.dart b/lib/vm/pulsar/pulsar_topic_basic_view_model.dart index 9586676..37ca99b 100644 --- a/lib/vm/pulsar/pulsar_topic_basic_view_model.dart +++ b/lib/vm/pulsar/pulsar_topic_basic_view_model.dart @@ -72,7 +72,8 @@ class PulsarTopicBasicViewModel extends BaseLoadViewModel { Future fetchPartitions() async { try { - final results = await PulsarTopicApi.getBase(host, port, tenant, namespace, topic); + final results = + await PulsarTopicApi.getBase(id, host, port, pulsarInstancePo.createTlsContext(), tenant, namespace, topic); msgRateIn = results.msgRateIn; msgRateOut = results.msgRateOut; msgInCounter = results.msgInCounter; diff --git a/lib/vm/pulsar/pulsar_topic_consume_view_model.dart b/lib/vm/pulsar/pulsar_topic_consume_view_model.dart index fd42df1..4ade495 100644 --- a/lib/vm/pulsar/pulsar_topic_consume_view_model.dart +++ b/lib/vm/pulsar/pulsar_topic_consume_view_model.dart @@ -71,16 +71,16 @@ class PulsarTopicConsumeViewModel extends BaseLoadListViewModel { message = ""; messageList = []; if (messageIdArr.length == 2) { - data = await PulsarTopicApi.fetchConsumerMessage( - host, port, tenant, namespace, topic, messageIdArr[0], messageIdArr[1]); + data = await PulsarTopicApi.fetchConsumerMessage(id, host, port, pulsarInstancePo.createTlsContext(), tenant, + namespace, topic, messageIdArr[0], messageIdArr[1]); this.message = data.substring(data.indexOf("@") + 1); } if (messageIdArr.length == 3) { var startEntryId = int.parse(messageIdArr[1]); var endEntryId = int.parse(messageIdArr[2]); for (int i = startEntryId; i <= endEntryId; i++) { - data = await PulsarTopicApi.fetchConsumerMessage( - host, port, tenant, namespace, topic, messageIdArr[0], i.toString()); + data = await PulsarTopicApi.fetchConsumerMessage(id, host, port, pulsarInstancePo.createTlsContext(), tenant, + namespace, topic, messageIdArr[0], i.toString()); Message message = new Message(i.toString(), data.substring(data.indexOf("@") + 1)); messageList.add(message); } @@ -99,7 +99,8 @@ class PulsarTopicConsumeViewModel extends BaseLoadListViewModel { return null; } String data; - data = await PulsarTopicApi.fetchMessageId(host, port, tenant, namespace, topic, timestamp); + data = await PulsarTopicApi.fetchMessageId( + id, host, port, pulsarInstancePo.createTlsContext(), tenant, namespace, topic, timestamp); this.messageId = data; loadSuccess(); } on Exception catch (e) { diff --git a/lib/vm/pulsar/pulsar_topic_consumer_view_model.dart b/lib/vm/pulsar/pulsar_topic_consumer_view_model.dart index 1f5dc16..0a1e710 100644 --- a/lib/vm/pulsar/pulsar_topic_consumer_view_model.dart +++ b/lib/vm/pulsar/pulsar_topic_consumer_view_model.dart @@ -68,7 +68,8 @@ class PulsarTopicConsumerViewModel extends BaseLoadListViewModel { Future fetchConsumers() async { try { - final results = await PulsarTopicApi.getConsumers(host, port, tenant, namespace, topic); + final results = await PulsarTopicApi.getConsumers( + id, host, port, pulsarInstancePo.createTlsContext(), tenant, namespace, topic); this.fullList = results; this.displayList = this.fullList; loadSuccess(); diff --git a/lib/vm/pulsar/pulsar_topic_list_view_model.dart b/lib/vm/pulsar/pulsar_topic_list_view_model.dart index 903f72f..04f22be 100644 --- a/lib/vm/pulsar/pulsar_topic_list_view_model.dart +++ b/lib/vm/pulsar/pulsar_topic_list_view_model.dart @@ -61,7 +61,8 @@ class PulsarTopicListViewModel extends BaseLoadListPageViewModel fetchTopics() async { try { - final results = await PulsarTopicApi.getTopics(host, port, tenant, namespace); + final results = + await PulsarTopicApi.getTopics(id, host, port, pulsarInstancePo.createTlsContext(), tenant, namespace); this.fullList = results.map((e) => PulsarTopicViewModel(pulsarInstancePo, tenantResp, namespaceResp, e)).toList(); this.displayList = this.fullList; loadSuccess(); @@ -86,7 +87,7 @@ class PulsarTopicListViewModel extends BaseLoadListPageViewModel createTopic(String topic) async { try { - await PulsarTopicApi.createTopic(host, port, tenant, namespace, topic); + await PulsarTopicApi.createTopic(id, host, port, pulsarInstancePo.createTlsContext(), tenant, namespace, topic); await fetchTopics(); } on Exception catch (e) { opException = e; @@ -96,7 +97,8 @@ class PulsarTopicListViewModel extends BaseLoadListPageViewModel deleteTopic(String topic, bool force) async { try { - await PulsarTopicApi.deleteTopic(host, port, tenant, namespace, topic, force); + await PulsarTopicApi.deleteTopic( + id, host, port, pulsarInstancePo.createTlsContext(), tenant, namespace, topic, force); 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 05f416f..cc03c53 100644 --- a/lib/vm/pulsar/pulsar_topic_produce_view_model.dart +++ b/lib/vm/pulsar/pulsar_topic_produce_view_model.dart @@ -65,7 +65,8 @@ class PulsarTopicProduceViewModel extends BaseLoadListViewModel { } Future sendMsg(key, value) { - return PulsarTopicApi.sendMsg(host, port, tenant, namespace, getTopic(), getPartition(), key, value); + return PulsarTopicApi.sendMsg( + id, host, port, pulsarInstancePo.createTlsContext(), tenant, namespace, getTopic(), getPartition(), key, value); } String getTopic() { diff --git a/lib/vm/pulsar/pulsar_topic_producer_view_model.dart b/lib/vm/pulsar/pulsar_topic_producer_view_model.dart index 15acfbd..21848d2 100644 --- a/lib/vm/pulsar/pulsar_topic_producer_view_model.dart +++ b/lib/vm/pulsar/pulsar_topic_producer_view_model.dart @@ -68,7 +68,8 @@ class PulsarTopicProducerViewModel extends BaseLoadListViewModel { Future fetchProducers() async { try { - final results = await PulsarTopicApi.getProducers(host, port, tenant, namespace, topic); + final results = await PulsarTopicApi.getProducers( + id, host, port, pulsarInstancePo.createTlsContext(), tenant, namespace, topic); this.fullList = results; this.displayList = this.fullList; loadSuccess(); diff --git a/lib/vm/pulsar/pulsar_topic_subscription_view_model.dart b/lib/vm/pulsar/pulsar_topic_subscription_view_model.dart index 19f4245..761a6cd 100644 --- a/lib/vm/pulsar/pulsar_topic_subscription_view_model.dart +++ b/lib/vm/pulsar/pulsar_topic_subscription_view_model.dart @@ -68,7 +68,8 @@ class PulsarTopicSubscriptionViewModel extends BaseLoadListViewModel fetchSubscriptions() async { try { - final results = await PulsarTopicApi.getSubscription(host, port, tenant, namespace, topic); + final results = await PulsarTopicApi.getSubscription( + id, host, port, pulsarInstancePo.createTlsContext(), tenant, namespace, topic); this.fullList = results; this.displayList = this.fullList; loadSuccess(); @@ -81,7 +82,8 @@ class PulsarTopicSubscriptionViewModel extends BaseLoadListViewModel clearBacklog(String subscriptionName) async { try { - await PulsarTopicApi.clearBacklog(host, port, tenant, namespace, topic, subscriptionName); + await PulsarTopicApi.clearBacklog( + id, host, port, pulsarInstancePo.createTlsContext(), tenant, namespace, topic, subscriptionName); await fetchSubscriptions(); } on Exception catch (e) { opException = e; diff --git a/pubspec.lock b/pubspec.lock index 1bce0ee..6dd6aba 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -5,161 +5,189 @@ packages: dependency: transitive description: name: _fe_analyzer_shared - url: "https://pub.dartlang.org" + url: "https://pub.flutter-io.cn" source: hosted version: "22.0.0" analyzer: dependency: transitive description: name: analyzer - url: "https://pub.dartlang.org" + url: "https://pub.flutter-io.cn" source: hosted version: "1.7.2" + archive: + dependency: transitive + description: + name: archive + url: "https://pub.flutter-io.cn" + source: hosted + version: "3.3.0" + args: + dependency: transitive + description: + name: args + url: "https://pub.flutter-io.cn" + source: hosted + version: "2.3.0" async: dependency: transitive description: name: async - url: "https://pub.dartlang.org" + url: "https://pub.flutter-io.cn" source: hosted version: "2.8.2" basic_utils: dependency: transitive description: name: basic_utils - url: "https://pub.dartlang.org" + url: "https://pub.flutter-io.cn" source: hosted version: "3.9.4" boolean_selector: dependency: transitive description: name: boolean_selector - url: "https://pub.dartlang.org" + url: "https://pub.flutter-io.cn" source: hosted version: "2.1.0" bson: dependency: transitive description: name: bson - url: "https://pub.dartlang.org" + url: "https://pub.flutter-io.cn" source: hosted version: "1.0.4" buffer: dependency: transitive description: name: buffer - url: "https://pub.dartlang.org" + url: "https://pub.flutter-io.cn" source: hosted version: "1.1.1" characters: dependency: transitive description: name: characters - url: "https://pub.dartlang.org" + url: "https://pub.flutter-io.cn" source: hosted version: "1.2.0" charcode: dependency: transitive description: name: charcode - url: "https://pub.dartlang.org" + url: "https://pub.flutter-io.cn" source: hosted version: "1.3.1" cli_util: dependency: transitive description: name: cli_util - url: "https://pub.dartlang.org" + url: "https://pub.flutter-io.cn" source: hosted version: "0.3.5" clipboard: dependency: "direct main" description: name: clipboard - url: "https://pub.dartlang.org" + url: "https://pub.flutter-io.cn" source: hosted version: "0.1.3" clock: dependency: transitive description: name: clock - url: "https://pub.dartlang.org" + url: "https://pub.flutter-io.cn" source: hosted version: "1.1.0" collection: dependency: transitive description: name: collection - url: "https://pub.dartlang.org" + url: "https://pub.flutter-io.cn" source: hosted version: "1.15.0" convert: dependency: transitive description: name: convert - url: "https://pub.dartlang.org" + url: "https://pub.flutter-io.cn" source: hosted version: "3.0.1" crypto: dependency: transitive description: name: crypto - url: "https://pub.dartlang.org" + url: "https://pub.flutter-io.cn" source: hosted version: "3.0.1" csv: dependency: "direct main" description: name: csv - url: "https://pub.dartlang.org" + url: "https://pub.flutter-io.cn" source: hosted version: "5.0.1" cupertino_icons: dependency: "direct main" description: name: cupertino_icons - url: "https://pub.dartlang.org" + url: "https://pub.flutter-io.cn" source: hosted version: "1.0.4" dart_eval: dependency: "direct main" description: name: dart_eval - url: "https://pub.dartlang.org" + url: "https://pub.flutter-io.cn" source: hosted version: "0.0.4" + dart_style: + dependency: transitive + description: + name: dart_style + url: "https://pub.flutter-io.cn" + source: hosted + version: "2.1.1" + dio: + dependency: "direct main" + description: + name: dio + url: "https://pub.flutter-io.cn" + source: hosted + version: "4.0.6" fake_async: dependency: transitive description: name: fake_async - url: "https://pub.dartlang.org" + url: "https://pub.flutter-io.cn" source: hosted version: "1.2.0" ffi: dependency: transitive description: name: ffi - url: "https://pub.dartlang.org" + url: "https://pub.flutter-io.cn" source: hosted version: "1.1.2" file: dependency: transitive description: name: file - url: "https://pub.dartlang.org" + url: "https://pub.flutter-io.cn" source: hosted version: "6.1.2" file_picker: dependency: "direct main" description: name: file_picker - url: "https://pub.dartlang.org" + url: "https://pub.flutter-io.cn" source: hosted - version: "4.4.0" + version: "4.5.1" fixnum: dependency: transitive description: name: fixnum - url: "https://pub.dartlang.org" + url: "https://pub.flutter-io.cn" source: hosted version: "1.0.0" flutter: @@ -171,7 +199,7 @@ packages: dependency: "direct main" description: name: flutter_datetime_picker - url: "https://pub.dartlang.org" + url: "https://pub.flutter-io.cn" source: hosted version: "1.5.1" flutter_localizations: @@ -183,7 +211,7 @@ packages: dependency: transitive description: name: flutter_plugin_android_lifecycle - url: "https://pub.dartlang.org" + url: "https://pub.flutter-io.cn" source: hosted version: "2.0.5" flutter_test: @@ -200,175 +228,189 @@ packages: dependency: transitive description: name: glob - url: "https://pub.dartlang.org" + url: "https://pub.flutter-io.cn" source: hosted version: "2.0.2" http: dependency: "direct main" description: name: http - url: "https://pub.dartlang.org" + url: "https://pub.flutter-io.cn" source: hosted version: "0.13.4" http_parser: dependency: transitive description: name: http_parser - url: "https://pub.dartlang.org" + url: "https://pub.flutter-io.cn" source: hosted version: "4.0.0" intl: dependency: transitive description: name: intl - url: "https://pub.dartlang.org" + url: "https://pub.flutter-io.cn" source: hosted version: "0.17.0" + intl_utils: + dependency: "direct main" + description: + name: intl_utils + url: "https://pub.flutter-io.cn" + source: hosted + version: "2.4.0" js: dependency: transitive description: name: js - url: "https://pub.dartlang.org" + url: "https://pub.flutter-io.cn" source: hosted version: "0.6.3" json_annotation: dependency: transitive description: name: json_annotation - url: "https://pub.dartlang.org" + url: "https://pub.flutter-io.cn" source: hosted version: "4.4.0" logging: dependency: transitive description: name: logging - url: "https://pub.dartlang.org" + url: "https://pub.flutter-io.cn" source: hosted version: "1.0.2" matcher: dependency: transitive description: name: matcher - url: "https://pub.dartlang.org" + url: "https://pub.flutter-io.cn" source: hosted version: "0.12.11" meta: dependency: transitive description: name: meta - url: "https://pub.dartlang.org" + url: "https://pub.flutter-io.cn" source: hosted version: "1.7.0" mongo_dart: dependency: "direct main" description: name: mongo_dart - url: "https://pub.dartlang.org" + url: "https://pub.flutter-io.cn" source: hosted version: "0.7.4" mongo_dart_query: dependency: transitive description: name: mongo_dart_query - url: "https://pub.dartlang.org" + url: "https://pub.flutter-io.cn" source: hosted version: "1.0.2" mysql1: dependency: "direct main" description: name: mysql1 - url: "https://pub.dartlang.org" + url: "https://pub.flutter-io.cn" source: hosted version: "0.19.2" nested: dependency: transitive description: name: nested - url: "https://pub.dartlang.org" + url: "https://pub.flutter-io.cn" source: hosted version: "1.0.0" package_config: dependency: transitive description: name: package_config - url: "https://pub.dartlang.org" + url: "https://pub.flutter-io.cn" source: hosted version: "2.0.2" path: dependency: "direct main" description: name: path - url: "https://pub.dartlang.org" + url: "https://pub.flutter-io.cn" source: hosted version: "1.8.0" pedantic: dependency: transitive description: name: pedantic - url: "https://pub.dartlang.org" + url: "https://pub.flutter-io.cn" source: hosted version: "1.11.1" + petitparser: + dependency: transitive + description: + name: petitparser + url: "https://pub.flutter-io.cn" + source: hosted + version: "4.4.0" plugin_platform_interface: dependency: transitive description: name: plugin_platform_interface - url: "https://pub.dartlang.org" + url: "https://pub.flutter-io.cn" source: hosted version: "2.1.2" pointycastle: dependency: transitive description: name: pointycastle - url: "https://pub.dartlang.org" + url: "https://pub.flutter-io.cn" source: hosted - version: "3.5.1" + version: "3.5.2" pool: dependency: transitive description: name: pool - url: "https://pub.dartlang.org" + url: "https://pub.flutter-io.cn" source: hosted version: "1.5.0" provider: dependency: "direct main" description: name: provider - url: "https://pub.dartlang.org" + url: "https://pub.flutter-io.cn" source: hosted version: "6.0.2" pub_semver: dependency: transitive description: name: pub_semver - url: "https://pub.dartlang.org" + url: "https://pub.flutter-io.cn" source: hosted - version: "2.1.0" + version: "2.1.1" rational: dependency: transitive description: name: rational - url: "https://pub.dartlang.org" + url: "https://pub.flutter-io.cn" source: hosted version: "1.2.1" redis: dependency: "direct main" description: name: redis - url: "https://pub.dartlang.org" + url: "https://pub.flutter-io.cn" source: hosted version: "2.2.0" sasl_scram: dependency: transitive description: name: sasl_scram - url: "https://pub.dartlang.org" + url: "https://pub.flutter-io.cn" source: hosted version: "0.1.0" saslprep: dependency: transitive description: name: saslprep - url: "https://pub.dartlang.org" + url: "https://pub.flutter-io.cn" source: hosted version: "1.0.2" sky_engine: @@ -380,142 +422,149 @@ packages: dependency: transitive description: name: source_span - url: "https://pub.dartlang.org" + url: "https://pub.flutter-io.cn" source: hosted version: "1.8.1" sprintf: dependency: "direct main" description: name: sprintf - url: "https://pub.dartlang.org" + url: "https://pub.flutter-io.cn" source: hosted version: "6.0.0" sqflite: dependency: "direct main" description: name: sqflite - url: "https://pub.dartlang.org" + url: "https://pub.flutter-io.cn" source: hosted version: "2.0.2" sqflite_common: dependency: transitive description: name: sqflite_common - url: "https://pub.dartlang.org" + url: "https://pub.flutter-io.cn" source: hosted version: "2.2.0" sqflite_common_ffi: dependency: "direct main" description: name: sqflite_common_ffi - url: "https://pub.dartlang.org" + url: "https://pub.flutter-io.cn" source: hosted version: "2.1.0+2" sqlite3: dependency: transitive description: name: sqlite3 - url: "https://pub.dartlang.org" + url: "https://pub.flutter-io.cn" source: hosted version: "1.5.1" stack_trace: dependency: transitive description: name: stack_trace - url: "https://pub.dartlang.org" + url: "https://pub.flutter-io.cn" source: hosted version: "1.10.0" stream_channel: dependency: transitive description: name: stream_channel - url: "https://pub.dartlang.org" + url: "https://pub.flutter-io.cn" source: hosted version: "2.1.0" string_scanner: dependency: transitive description: name: string_scanner - url: "https://pub.dartlang.org" + url: "https://pub.flutter-io.cn" source: hosted version: "1.1.0" synchronized: dependency: transitive description: name: synchronized - url: "https://pub.dartlang.org" + url: "https://pub.flutter-io.cn" source: hosted - version: "3.0.0" + version: "3.0.0+2" term_glyph: dependency: transitive description: name: term_glyph - url: "https://pub.dartlang.org" + url: "https://pub.flutter-io.cn" source: hosted version: "1.2.0" test_api: dependency: transitive description: name: test_api - url: "https://pub.dartlang.org" + url: "https://pub.flutter-io.cn" source: hosted version: "0.4.3" typed_data: dependency: transitive description: name: typed_data - url: "https://pub.dartlang.org" + url: "https://pub.flutter-io.cn" source: hosted version: "1.3.0" unorm_dart: dependency: transitive description: name: unorm_dart - url: "https://pub.dartlang.org" + url: "https://pub.flutter-io.cn" source: hosted version: "0.2.0" uuid: dependency: transitive description: name: uuid - url: "https://pub.dartlang.org" + url: "https://pub.flutter-io.cn" source: hosted version: "3.0.6" vector_math: dependency: transitive description: name: vector_math - url: "https://pub.dartlang.org" + url: "https://pub.flutter-io.cn" source: hosted version: "2.1.1" vy_string_utils: dependency: transitive description: name: vy_string_utils - url: "https://pub.dartlang.org" + url: "https://pub.flutter-io.cn" source: hosted version: "0.4.3" watcher: dependency: transitive description: name: watcher - url: "https://pub.dartlang.org" + url: "https://pub.flutter-io.cn" source: hosted version: "1.0.1" + win32: + dependency: transitive + description: + name: win32 + url: "https://pub.flutter-io.cn" + source: hosted + version: "2.5.1" window_size: dependency: "direct main" description: path: "plugins/window_size" ref: HEAD - resolved-ref: "89c350f787e1d7bff12b3517e5671146211ee70e" - url: "git://github.com/google/flutter-desktop-embedding.git" + resolved-ref: "5c51870ced62a00e809ba4b81a846a052d241c9f" + url: "https://github.com/google/flutter-desktop-embedding.git" source: git version: "0.1.0" yaml: dependency: transitive description: name: yaml - url: "https://pub.dartlang.org" + url: "https://pub.flutter-io.cn" source: hosted version: "3.1.0" sdks: diff --git a/pubspec.yaml b/pubspec.yaml index 2229c0f..0624e96 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -57,6 +57,7 @@ dependencies: path: plugins/window_size # paas http: ^0.13.4 + dio: ^4.0.6 mongo_dart: ^0.7.4 mysql1: ^0.19.2 redis: ^2.2.0 diff --git a/test/api/pulsar/pulsar_sink_api_create_test.dart b/test/api/pulsar/pulsar_sink_api_create_test.dart index 9ed4122..f4eb32b 100644 --- a/test/api/pulsar/pulsar_sink_api_create_test.dart +++ b/test/api/pulsar/pulsar_sink_api_create_test.dart @@ -1,10 +1,21 @@ import 'package:flutter_test/flutter_test.dart'; import 'package:paas_dashboard_flutter/api/pulsar/pulsar_sink_api.dart'; +import 'package:paas_dashboard_flutter/api/tls_context.dart'; import 'package:paas_dashboard_flutter/module/pulsar/const.dart'; void main() { test("test_create_sink", () async { - await PulsarSinkApi.createSink(PulsarConst.defaultHost, PulsarConst.defaultFunctionPort, "public", "default", - "sink_name", "sub_name", "topic", "pulsar", '{"topic":"xx"}'); + await PulsarSinkApi.createSink( + 1, + PulsarConst.defaultHost, + PulsarConst.defaultFunctionPort, + new TlsContext(false, "", "", "", ""), + "public", + "default", + "sink_name", + "sub_name", + "topic", + "pulsar", + '{"topic":"xx"}'); }); } diff --git a/test/api/pulsar/pulsar_sink_api_query_test.dart b/test/api/pulsar/pulsar_sink_api_query_test.dart index f31b9b5..fa8315c 100644 --- a/test/api/pulsar/pulsar_sink_api_query_test.dart +++ b/test/api/pulsar/pulsar_sink_api_query_test.dart @@ -1,11 +1,12 @@ import 'package:flutter_test/flutter_test.dart'; import 'package:paas_dashboard_flutter/api/pulsar/pulsar_sink_api.dart'; +import 'package:paas_dashboard_flutter/api/tls_context.dart'; import 'package:paas_dashboard_flutter/module/pulsar/const.dart'; void main() { test("test_create_sink", () async { - var list = - await PulsarSinkApi.getSinkList(PulsarConst.defaultHost, PulsarConst.defaultFunctionPort, "public", "default"); + var list = await PulsarSinkApi.getSinkList(1, PulsarConst.defaultHost, PulsarConst.defaultFunctionPort, + new TlsContext(false, "", "", "", ""), "public", "default"); print(list); }); } 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 b941d69..569132f 100644 --- a/test/api/pulsar/pulsar_topic_api_fetch_producers_test.dart +++ b/test/api/pulsar/pulsar_topic_api_fetch_producers_test.dart @@ -1,11 +1,12 @@ import 'package:flutter_test/flutter_test.dart'; import 'package:paas_dashboard_flutter/api/pulsar/pulsar_topic_api.dart'; +import 'package:paas_dashboard_flutter/api/tls_context.dart'; import 'package:paas_dashboard_flutter/module/pulsar/const.dart'; void main() { test("test_fetch_producers", () async { - var producers = await PulsarTopicApi.getProducers( - PulsarConst.defaultHost, PulsarConst.defaultBrokerPort, "public", "default", "test_fetch_topic"); + var producers = await PulsarTopicApi.getProducers(1, PulsarConst.defaultHost, PulsarConst.defaultBrokerPort, + new TlsContext(false, "", "", "", ""), "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 89c81d1..7e25210 100644 --- a/test/api/pulsar/pulsar_topic_api_fetch_subscriptions_test.dart +++ b/test/api/pulsar/pulsar_topic_api_fetch_subscriptions_test.dart @@ -1,11 +1,12 @@ import 'package:flutter_test/flutter_test.dart'; import 'package:paas_dashboard_flutter/api/pulsar/pulsar_topic_api.dart'; +import 'package:paas_dashboard_flutter/api/tls_context.dart'; import 'package:paas_dashboard_flutter/module/pulsar/const.dart'; void main() { test("test_fetch_subscriptions", () async { - var subscription = await PulsarTopicApi.getSubscription( - PulsarConst.defaultHost, PulsarConst.defaultBrokerPort, "public", "default", "test_fetch_topic"); + var subscription = await PulsarTopicApi.getSubscription(1, PulsarConst.defaultHost, PulsarConst.defaultBrokerPort, + new TlsContext(false, "", "", "", ""), "public", "default", "test_fetch_topic"); print(subscription); }); }