-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
34 changed files
with
1,521 additions
and
87 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
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/module/pulsar/pulsar_sink.dart'; | ||
|
||
class PulsarSinkAPi { | ||
static Future<void> 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<List<SinkResp>> 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}'); | ||
} | ||
List jsonResponse = json.decode(response.body) as List; | ||
return jsonResponse.map((name) => new SinkResp(name)).toList(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
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/module/pulsar/pulsar_source.dart'; | ||
|
||
class PulsarSourceAPi { | ||
static Future<void> 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<List<SourceResp>> 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}'); | ||
} | ||
List jsonResponse = json.decode(response.body) as List; | ||
return jsonResponse.map((name) => new SourceResp(name)).toList(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,135 @@ | ||
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/module/pulsar/pulsar_produce.dart'; | ||
import 'package:paas_dashboard_flutter/module/pulsar/pulsar_subscription.dart'; | ||
import 'package:paas_dashboard_flutter/module/pulsar/pulsar_topic.dart'; | ||
import 'package:paas_dashboard_flutter/ui/util/string_util.dart'; | ||
|
||
class PulsarTopicAPi { | ||
static Future<String> 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: <String, String>{ | ||
'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}'); | ||
} | ||
return response.body; | ||
} | ||
|
||
static Future<String> deleteTopic(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.delete(Uri.parse(url), headers: <String, String>{ | ||
'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}'); | ||
} | ||
return response.body; | ||
} | ||
|
||
static Future<List<TopicResp>> 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}'); | ||
} | ||
List jsonResponse = json.decode(response.body) as List; | ||
return jsonResponse.map((name) => new TopicResp.fromJson(name)).toList(); | ||
} | ||
|
||
static Future<List<SubscriptionResp>> getSubscription(String host, int port, | ||
String tenant, String namespace, String topic) async { | ||
String data = ""; | ||
await PulsarStatAPi.topicStats(host, port, tenant, namespace, topic) | ||
.then((value) => {data = value}); | ||
List<SubscriptionResp> respList = new List.empty(growable: true); | ||
Map statsMap = json.decode(data) as Map; | ||
if (statsMap.containsKey("subscriptions")) { | ||
Map subscriptionsMap = statsMap["subscriptions"] as Map<String, dynamic>; | ||
subscriptionsMap.forEach((key, value) { | ||
double rateOut = value["msgRateOut"]; | ||
int backlog = value["msgBacklog"]; | ||
SubscriptionResp subscriptionDetail = | ||
new SubscriptionResp(key, backlog, rateOut); | ||
respList.add(subscriptionDetail); | ||
}); | ||
} | ||
return respList; | ||
} | ||
|
||
static Future<String> 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}'); | ||
} | ||
return response.body; | ||
} | ||
|
||
static Future<String> 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; | ||
|
||
Map statsMap = json.decode(data) as Map; | ||
if (statsMap.containsKey("subscriptions")) { | ||
Map subscriptionsMap = statsMap["subscriptions"] as Map; | ||
|
||
if (subscriptionsMap.containsKey(subscription)) { | ||
Map subscriptionMap = statsMap[subscription] as Map; | ||
return subscriptionMap["msgBacklog"]; | ||
} | ||
} | ||
return ""; | ||
} | ||
|
||
static Future<List<ProducerResp>> getProducers(String host, int port, | ||
String tenant, String namespace, String topic) async { | ||
String data = ""; | ||
await PulsarStatAPi.topicStats(host, port, tenant, namespace, topic) | ||
.then((value) => {data = value}); | ||
List<ProducerResp> respList = new List.empty(growable: true); | ||
Map statsMap = json.decode(data) as Map; | ||
if (statsMap.containsKey("publishers")) { | ||
List publisherList = statsMap["publishers"] as List<dynamic>; | ||
publisherList.forEach((element) { | ||
String producerName = StringUtil.nullStr(element["producerName"]); | ||
double rateIn = element["msgRateIn"]; | ||
double throughputIn = element["msgThroughputIn"]; | ||
String clientVersion = StringUtil.nullStr(element["clientVersion"]); | ||
double averageMsgSize = element["averageMsgSize"]; | ||
String address = StringUtil.nullStr(element["address"]); | ||
ProducerResp producerResp = new ProducerResp(producerName, rateIn, | ||
throughputIn, clientVersion, averageMsgSize, address); | ||
respList.add(producerResp); | ||
}); | ||
} | ||
return respList; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
class SinkResp { | ||
final String sinkName; | ||
|
||
SinkResp(this.sinkName); | ||
|
||
SinkResp deepCopy() { | ||
return new SinkResp(this.sinkName); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
class SourceResp { | ||
final String sourceName; | ||
|
||
SourceResp(this.sourceName); | ||
|
||
SourceResp deepCopy() { | ||
return new SourceResp(this.sourceName); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.