Skip to content

Commit

Permalink
fix https schema bug (#100)
Browse files Browse the repository at this point in the history
  • Loading branch information
shoothzj authored Dec 5, 2022
1 parent 5c049e6 commit 8d80bbf
Show file tree
Hide file tree
Showing 10 changed files with 75 additions and 137 deletions.
10 changes: 3 additions & 7 deletions lib/api/pulsar/pulsar_cluster_api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ class PulsarClusterApi {
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 =
tlsContext.enableTls ? HttpUtil.https : '${HttpUtil.http}$host:${port.toString()}/admin/v2/brokers/$cluster';
String url = '${tlsContext.getSchema()}$host:${port.toString()}/admin/v2/brokers/$cluster';
final brokersResponse = await HttpUtil.getClient(tlsContext, SERVER.PULSAR, id).get<String>(url);
if (HttpUtil.abnormal(brokersResponse.statusCode!)) {
log('ErrorCode is ${brokersResponse.statusCode}, body is ${brokersResponse.data}');
Expand All @@ -43,8 +42,7 @@ class PulsarClusterApi {
}

static Future<String> 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';
String url = '${tlsContext.getSchema()}$host:${port.toString()}/admin/v2/brokers/version';
final versionResponse = await HttpUtil.getClient(tlsContext, SERVER.PULSAR, id)
.get<String>(url, options: Options(responseType: ResponseType.json));
if (HttpUtil.abnormal(versionResponse.statusCode!)) {
Expand All @@ -55,9 +53,7 @@ class PulsarClusterApi {
}

static Future<String> 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';
String url = '${tlsContext.getSchema()}$host:${port.toString()}/admin/v2/brokers/leaderBroker';
final leaderBrokerResponse = await HttpUtil.getClient(tlsContext, SERVER.PULSAR, id).get<String>(url);
if (HttpUtil.abnormal(leaderBrokerResponse.statusCode!)) {
log('ErrorCode is ${leaderBrokerResponse.statusCode}, body is ${leaderBrokerResponse.data}');
Expand Down
4 changes: 1 addition & 3 deletions lib/api/pulsar/pulsar_lookup_api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,7 @@ import 'package:paas_dashboard_flutter/api/tls_context.dart';
class PulsarLookupApi {
static Future<String> lookupTopic(
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()}/lookup/v2/topic/persistent/$tenant/$namespace/$topic';
var url = '${tlsContext.getSchema()}$host:${port.toString()}/lookup/v2/topic/persistent/$tenant/$namespace/$topic';
var response = await HttpUtil.getClient(tlsContext, SERVER.PULSAR, id).get<String>(url);
if (HttpUtil.abnormal(response.statusCode!)) {
log('ErrorCode is ${response.statusCode}, body is ${response.data}');
Expand Down
78 changes: 27 additions & 51 deletions lib/api/pulsar/pulsar_namespace_api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,7 @@ import 'package:paas_dashboard_flutter/module/pulsar/pulsar_namespace.dart';
class PulsarNamespaceApi {
static Future<void> 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 url = '${tlsContext.getSchema()}$host:${port.toString()}/admin/v2/namespaces/$tenant/$namespace';
var response = await HttpUtil.getClient(tlsContext, SERVER.PULSAR, id).put<String>(url);
if (HttpUtil.abnormal(response.statusCode!)) {
log('ErrorCode is ${response.statusCode}, body is ${response.data}');
Expand All @@ -41,9 +39,7 @@ class PulsarNamespaceApi {

static Future<void> 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 url = '${tlsContext.getSchema()}$host:${port.toString()}/admin/v2/namespaces/$tenant/$namespace';
var response = await HttpUtil.getClient(tlsContext, SERVER.PULSAR, id).delete<String>(url);
if (HttpUtil.abnormal(response.statusCode!)) {
log('ErrorCode is ${response.statusCode}, body is ${response.data}');
Expand All @@ -54,9 +50,7 @@ class PulsarNamespaceApi {
static Future<List<NamespaceResp>> getNamespaces(
int id, String host, int port, TlsContext tlsContext, String tenant) async {
try {
var url = tlsContext.enableTls
? HttpUtil.https
: '${HttpUtil.http}$host:${port.toString()}/admin/v2/namespaces/$tenant';
var url = '${tlsContext.getSchema()}$host:${port.toString()}/admin/v2/namespaces/$tenant';
var response = await HttpUtil.getClient(tlsContext, SERVER.PULSAR, id).get<String>(url);
if (HttpUtil.abnormal(response.statusCode!)) {
log('ErrorCode is ${response.statusCode}, body is ${response.data}');
Expand All @@ -72,9 +66,7 @@ class PulsarNamespaceApi {
static Future<RetentionResp> getRetention(
int id, String host, int port, TlsContext tlsContext, String tenant, String namespace) async {
try {
String url = tlsContext.enableTls
? HttpUtil.https
: '${HttpUtil.http}$host:${port.toString()}/admin/v2/namespaces/$tenant/$namespace/retention';
String url = '${tlsContext.getSchema()}$host:${port.toString()}/admin/v2/namespaces/$tenant/$namespace/retention';
var response = await HttpUtil.getClient(tlsContext, SERVER.PULSAR, id).get<String>(url);
if (HttpUtil.abnormal(response.statusCode!)) {
log('ErrorCode is ${response.statusCode}, body is ${response.data}');
Expand All @@ -92,9 +84,7 @@ class PulsarNamespaceApi {

static Future<void> setRetention(int id, String host, int port, TlsContext tlsContext, String tenant,
String namespace, int retentionTimeInMinutes, int retentionSizeInMB) async {
String url = tlsContext.enableTls
? HttpUtil.https
: '${HttpUtil.http}$host:${port.toString()}/admin/v2/namespaces/$tenant/$namespace/retention';
String url = '${tlsContext.getSchema()}$host:${port.toString()}/admin/v2/namespaces/$tenant/$namespace/retention';
RetentionResp retentionResp = RetentionResp(retentionTimeInMinutes, retentionSizeInMB);
var response = await HttpUtil.getClient(tlsContext, SERVER.PULSAR, id).post(url, data: json.encode(retentionResp));
if (HttpUtil.abnormal(response.statusCode!)) {
Expand All @@ -106,9 +96,8 @@ class PulsarNamespaceApi {
static Future<BacklogQuotaResp> getBacklogQuota(
int id, String host, int port, TlsContext tlsContext, String tenant, String namespace) async {
try {
String url = tlsContext.enableTls
? HttpUtil.https
: '${HttpUtil.http}$host:${port.toString()}/admin/v2/namespaces/$tenant/$namespace/backlogQuotaMap';
String url =
'${tlsContext.getSchema()}$host:${port.toString()}/admin/v2/namespaces/$tenant/$namespace/backlogQuotaMap';
var response = await HttpUtil.getClient(tlsContext, SERVER.PULSAR, id).get<String>(url);
if (HttpUtil.abnormal(response.statusCode!)) {
log('ErrorCode is ${response.statusCode}, body is ${response.data}');
Expand All @@ -127,9 +116,8 @@ class PulsarNamespaceApi {

static Future<void> 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';
String url =
'${tlsContext.getSchema()}$host:${port.toString()}/admin/v2/namespaces/$tenant/$namespace/backlogQuota';
BacklogQuotaReq backlogQuotaReq = BacklogQuotaReq(limit, limitTime, policy);
var response =
await HttpUtil.getClient(tlsContext, SERVER.PULSAR, id).post(url, data: json.encode(backlogQuotaReq));
Expand All @@ -142,9 +130,7 @@ class PulsarNamespaceApi {
static Future<PolicyResp> getPolicy(
int id, String host, int port, TlsContext tlsContext, String tenant, String namespace) async {
try {
String url = tlsContext.enableTls
? HttpUtil.https
: '${HttpUtil.http}$host:${port.toString()}/admin/v2/namespaces/$tenant/$namespace';
String url = '${tlsContext.getSchema()}$host:${port.toString()}/admin/v2/namespaces/$tenant/$namespace';
var response = await HttpUtil.getClient(tlsContext, SERVER.PULSAR, id).get<String>(url);
if (HttpUtil.abnormal(response.statusCode!)) {
log('ErrorCode is ${response.statusCode}, body is ${response.data}');
Expand All @@ -159,9 +145,8 @@ class PulsarNamespaceApi {

static Future<void> 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';
String url =
'${tlsContext.getSchema()}$host:${port.toString()}/admin/v2/namespaces/$tenant/$namespace/autoTopicCreation';
TopicAutoCreateReq topicAutoCreateReq = TopicAutoCreateReq(allowAutoTopicCreation, topicType, defaultNumPartitions);
var response =
await HttpUtil.getClient(tlsContext, SERVER.PULSAR, id).post(url, data: json.encode(topicAutoCreateReq));
Expand All @@ -173,9 +158,7 @@ class PulsarNamespaceApi {

static Future<void> 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';
String url = '${tlsContext.getSchema()}$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}');
Expand All @@ -185,9 +168,8 @@ class PulsarNamespaceApi {

static Future<void> 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';
String url =
'${tlsContext.getSchema()}$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!)) {
Expand All @@ -198,9 +180,8 @@ class PulsarNamespaceApi {

static Future<void> 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';
String url =
'${tlsContext.getSchema()}$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!)) {
Expand All @@ -211,9 +192,8 @@ class PulsarNamespaceApi {

static Future<void> 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';
String url =
'${tlsContext.getSchema()}$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!)) {
Expand All @@ -224,9 +204,8 @@ class PulsarNamespaceApi {

static Future<void> 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';
String url =
'${tlsContext.getSchema()}$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!)) {
Expand All @@ -237,9 +216,8 @@ class PulsarNamespaceApi {

static Future<void> 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';
String url =
'${tlsContext.getSchema()}$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!)) {
Expand All @@ -250,9 +228,8 @@ class PulsarNamespaceApi {

static Future<void> 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';
String url =
'${tlsContext.getSchema()}$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!)) {
Expand All @@ -263,9 +240,8 @@ class PulsarNamespaceApi {

static Future<void> 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';
String url =
'${tlsContext.getSchema()}$host:${port.toString()}/admin/v2/namespaces/$tenant/$namespace/maxTopicsPerNamespace';
var response = await HttpUtil.getClient(tlsContext, SERVER.PULSAR, id)
.post(url, data: maxTopicsPerNamespace.toString(), options: Options(contentType: ContentType.json.toString()));
if (HttpUtil.abnormal(response.statusCode!)) {
Expand Down
29 changes: 11 additions & 18 deletions lib/api/pulsar/pulsar_partitioned_topic_api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,8 @@ import 'package:paas_dashboard_flutter/ui/util/string_util.dart';
class PulsarPartitionedTopicApi {
static Future<String> 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 url =
'${tlsContext.getSchema()}$host:${port.toString()}/admin/v2/persistent/$tenant/$namespace/$topic/partitions';
var response =
await HttpUtil.getClient(tlsContext, SERVER.PULSAR, id).put<String>(url, data: partitionNum.toString());
if (HttpUtil.abnormal(response.statusCode!)) {
Expand All @@ -50,9 +49,8 @@ class PulsarPartitionedTopicApi {

static Future<String> 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 url =
'${tlsContext.getSchema()}$host:${port.toString()}/admin/v2/persistent/$tenant/$namespace/$topic/partitions?force=$force';
var response = await HttpUtil.getClient(tlsContext, SERVER.PULSAR, id).delete<String>(url);
if (HttpUtil.abnormal(response.statusCode!)) {
log('ErrorCode is ${response.statusCode}, body is ${response.data}');
Expand All @@ -63,9 +61,8 @@ class PulsarPartitionedTopicApi {

static Future<String> 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 url =
'${tlsContext.getSchema()}$host:${port.toString()}/admin/v2/persistent/$tenant/$namespace/$topic/partitions';
var response =
await HttpUtil.getClient(tlsContext, SERVER.PULSAR, id).post<String>(url, data: partitionNum.toString());
if (HttpUtil.abnormal(response.statusCode!)) {
Expand All @@ -77,9 +74,8 @@ class PulsarPartitionedTopicApi {

static Future<String> createMissPartitionTopic(
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/createMissedPartitions';
var url =
'${tlsContext.getSchema()}$host:${port.toString()}/admin/v2/persistent/$tenant/$namespace/$topic/createMissedPartitions';
var response = await HttpUtil.getClient(tlsContext, SERVER.PULSAR, id).post<String>(url);
if (HttpUtil.abnormal(response.statusCode!)) {
log('ErrorCode is ${response.statusCode}, body is ${response.data}');
Expand Down Expand Up @@ -127,9 +123,8 @@ class PulsarPartitionedTopicApi {

static Future<String> 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 url =
'${tlsContext.getSchema()}$host:${port.toString()}/admin/v2/persistent/$tenant/$namespace/$topic/subscription/$subscription/skip_all';
var response = await HttpUtil.getClient(tlsContext, SERVER.PULSAR, id).post<String>(url);
if (HttpUtil.abnormal(response.statusCode!)) {
log('ErrorCode is ${response.statusCode}, body is ${response.data}');
Expand Down Expand Up @@ -297,9 +292,7 @@ class PulsarPartitionedTopicApi {
List<ProducerMessage> messageList = List.empty(growable: true);
messageList.add(producerMessage);
PublishMessagesReq messagesReq = PublishMessagesReq(PulsarConst.defaultProducerName, messageList);
var url = tlsContext.enableTls
? HttpUtil.https
: '${HttpUtil.http}$host:${port.toString()}/topics/persistent/$tenant/$namespace/$topic/';
var url = '${tlsContext.getSchema()}$host:${port.toString()}/topics/persistent/$tenant/$namespace/$topic/';
var response =
await HttpUtil.getClient(tlsContext, SERVER.PULSAR, id).post<String>(url, data: json.encode(messagesReq));
if (HttpUtil.abnormal(response.statusCode!)) {
Expand Down
Loading

0 comments on commit 8d80bbf

Please sign in to comment.