Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
apache
pulsar
提交
4fa87a48
pulsar
项目概览
apache
/
pulsar
通知
129
Star
40
Fork
3
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Wiki
1
Wiki
分析
仓库
DevOps
项目成员
Pages
pulsar
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Pages
分析
分析
仓库分析
DevOps
Wiki
1
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
提交
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
4fa87a48
编写于
8月 26, 2019
作者:
Y
Yi Tang
提交者:
Sijie Guo
8月 25, 2019
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[dashboard] fix admin path (#5030)
access v1/v2 admin api by namespace name pattern
上级
ff418717
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
83 addition
and
25 deletion
+83
-25
dashboard/django/stats/urls.py
dashboard/django/stats/urls.py
+3
-3
dashboard/django/stats/views.py
dashboard/django/stats/views.py
+80
-22
未找到文件。
dashboard/django/stats/urls.py
浏览文件 @
4fa87a48
...
...
@@ -24,7 +24,7 @@ from . import views
urlpatterns
=
[
url
(
r
'^property/(?P<property_name>.+)/$'
,
views
.
property
,
name
=
'property'
),
url
(
r
'^namespace/(?P<namespace_name>.+)/$'
,
views
.
namespace
,
name
=
'namespace'
),
url
(
r
'^deleteNamespace/(?P<namespace_name>.+)$'
,
views
.
delete
N
amespace
,
name
=
'deleteNamespace'
),
url
(
r
'^deleteNamespace/(?P<namespace_name>.+)$'
,
views
.
delete
_n
amespace
,
name
=
'deleteNamespace'
),
url
(
r
'^brokers/$'
,
views
.
brokers
,
name
=
'brokers'
),
...
...
@@ -35,7 +35,7 @@ urlpatterns = [
url
(
r
'^topic/(?P<topic_name>.+)/$'
,
views
.
topic
,
name
=
'topic'
),
url
(
r
'^clusters/$'
,
views
.
clusters
,
name
=
'clusters'
),
url
(
r
'^clearSubscription/(?P<topic_name>.+)/(?P<subscription_name>.+)$'
,
views
.
clear
S
ubscription
,
name
=
'clearSubscription'
),
url
(
r
'^deleteSubscription/(?P<topic_name>.+)/(?P<subscription_name>.+)$'
,
views
.
delete
S
ubscription
,
name
=
'deleteSubscription'
),
url
(
r
'^clearSubscription/(?P<topic_name>.+)/(?P<subscription_name>.+)$'
,
views
.
clear
_s
ubscription
,
name
=
'clearSubscription'
),
url
(
r
'^deleteSubscription/(?P<topic_name>.+)/(?P<subscription_name>.+)$'
,
views
.
delete
_s
ubscription
,
name
=
'deleteSubscription'
),
url
(
r
'^messages/(?P<topic_name>.+)/(?P<subscription_name>.+)$'
,
views
.
messages
,
name
=
'messages'
),
]
dashboard/django/stats/views.py
浏览文件 @
4fa87a48
...
...
@@ -37,6 +37,68 @@ pulsar = import_utils.try_import("pulsar")
logger
=
logging
.
getLogger
(
__name__
)
class
AdminPath
:
v1
=
"/admin"
v2
=
"/admin/v2"
@
staticmethod
def
get
(
is_v2
):
return
AdminPath
.
v2
if
is_v2
else
AdminPath
.
v1
class
TopicName
:
def
__init__
(
self
,
topic_name
):
try
:
self
.
scheme
,
self
.
path
=
topic_name
.
split
(
"://"
,
1
)
except
ValueError
:
self
.
scheme
,
self
.
path
=
topic_name
.
split
(
"/"
,
1
)
self
.
namespace_path
,
self
.
name
=
self
.
path
.
rsplit
(
"/"
,
1
)
self
.
namespace
=
NamespaceName
(
self
.
namespace_path
)
def
is_v2
(
self
):
return
self
.
namespace
.
is_v2
()
def
url_name
(
self
):
return
"/"
.
join
([
self
.
scheme
,
self
.
path
])
def
full_name
(
self
):
return
"://"
.
join
([
self
.
scheme
,
self
.
path
])
def
short_name
(
self
):
return
self
.
name
def
is_global
(
self
):
return
self
.
namespace
.
is_global
()
def
admin_path
(
self
):
b
=
AdminPath
.
get
(
self
.
is_v2
())
return
settings
.
SERVICE_URL
+
b
+
"/"
+
self
.
url_name
()
class
NamespaceName
:
def
__init__
(
self
,
namespace_name
):
self
.
path
=
namespace_name
.
strip
(
"/"
)
path_parts
=
self
.
path
.
split
(
"/"
)
if
len
(
path_parts
)
==
2
:
self
.
tenant
,
self
.
namespace
=
path_parts
self
.
cluster
=
None
elif
len
(
path_parts
)
==
3
:
self
.
tenant
,
self
.
cluster
,
self
.
namespace
=
path_parts
else
:
raise
ValueError
(
"invalid namespace:"
+
namespace_name
)
def
is_v2
(
self
):
return
self
.
cluster
is
None
def
is_global
(
self
):
return
self
.
cluster
==
"global"
def
admin_path
(
self
):
b
=
AdminPath
.
get
(
self
.
is_v2
())
return
settings
.
SERVICE_URL
+
b
+
"/namespaces/"
+
self
.
path
def
get_timestamp
():
try
:
return
LatestTimestamp
.
objects
.
get
(
name
=
'latest'
).
timestamp
...
...
@@ -139,8 +201,8 @@ def namespace(request, namespace_name):
})
def
delete
N
amespace
(
request
,
namespace_name
):
url
=
settings
.
SERVICE_URL
+
'/admin/v2/namespaces/'
+
namespace_name
def
delete
_n
amespace
(
request
,
namespace_name
):
url
=
NamespaceName
(
namespace_name
).
admin_path
()
response
=
requests
.
delete
(
url
)
status
=
response
.
status_code
logger
.
debug
(
"Delete namespace "
+
namespace_name
+
" status - "
+
str
(
status
))
...
...
@@ -148,9 +210,10 @@ def deleteNamespace(request, namespace_name):
Namespace
.
objects
.
filter
(
name
=
namespace_name
,
timestamp
=
get_timestamp
()).
update
(
deleted
=
True
)
return
redirect
(
'property'
,
property_name
=
namespace_name
.
split
(
'/'
,
1
)[
0
])
def
topic
(
request
,
topic_name
):
timestamp
=
get_timestamp
()
topic_name
=
extract_topic_db_name
(
topic_name
)
topic_name
=
TopicName
(
topic_name
).
full_name
(
)
cluster_name
=
request
.
GET
.
get
(
'cluster'
)
clusters
=
[]
...
...
@@ -314,12 +377,12 @@ def clusters(request):
})
def
clear
S
ubscription
(
request
,
topic_name
,
subscription_name
):
url
=
settings
.
SERVICE_URL
+
'/admin/v2/'
+
topic_name
+
'/subscription/'
+
subscription_name
+
'/skip_all'
def
clear
_s
ubscription
(
request
,
topic_name
,
subscription_name
):
url
=
"%s/subscription/%s/skip_all"
%
(
TopicName
(
topic_name
).
admin_path
(),
subscription_name
)
response
=
requests
.
post
(
url
)
if
response
.
status_code
==
204
:
ts
=
get_timestamp
()
topic_db_name
=
extract_topic_db_name
(
topic_name
)
topic_db_name
=
TopicName
(
topic_name
).
full_name
(
)
topic
=
Topic
.
objects
.
get
(
name
=
topic_db_name
,
timestamp
=
ts
)
subscription
=
Subscription
.
objects
.
get
(
name
=
subscription_name
,
topic
=
topic
,
timestamp
=
ts
)
topic
.
backlog
=
topic
.
backlog
-
subscription
.
msgBacklog
...
...
@@ -328,13 +391,14 @@ def clearSubscription(request, topic_name, subscription_name):
subscription
.
save
(
update_fields
=
[
'msgBacklog'
])
return
redirect
(
'topic'
,
topic_name
=
topic_name
)
def
deleteSubscription
(
request
,
topic_name
,
subscription_name
):
url
=
settings
.
SERVICE_URL
+
'/admin/v2/'
+
topic_name
+
'/subscription/'
+
subscription_name
def
delete_subscription
(
request
,
topic_name
,
subscription_name
):
url
=
"%s/subscription/%s"
%
(
TopicName
(
topic_name
).
admin_path
(),
subscription_name
)
response
=
requests
.
delete
(
url
)
status
=
response
.
status_code
if
status
==
204
:
ts
=
get_timestamp
()
topic_db_name
=
extract_topic_db_name
(
topic_name
)
topic_db_name
=
TopicName
(
topic_name
).
full_name
(
)
topic
=
Topic
.
objects
.
get
(
name
=
topic_db_name
,
timestamp
=
ts
)
deleted_subscription
=
Subscription
.
objects
.
get
(
name
=
subscription_name
,
topic
=
topic
,
timestamp
=
ts
)
deleted_subscription
.
deleted
=
True
...
...
@@ -353,7 +417,8 @@ def deleteSubscription(request, topic_name, subscription_name):
def
messages
(
request
,
topic_name
,
subscription_name
):
topic_db_name
=
extract_topic_db_name
(
topic_name
)
topic_name_obj
=
TopicName
(
topic_name
)
topic_db_name
=
topic_name_obj
.
full_name
()
timestamp
=
get_timestamp
()
cluster_name
=
request
.
GET
.
get
(
'cluster'
)
...
...
@@ -371,7 +436,7 @@ def messages(request, topic_name, subscription_name):
message
=
None
message_position
=
request
.
GET
.
get
(
'message-position'
)
if
message_position
and
message_position
.
isnumeric
():
message
=
peek_message
(
topic_obj
,
subscription_name
,
message_position
)
message
=
peek_message
(
topic_
name_
obj
,
subscription_name
,
message_position
)
if
not
isinstance
(
message
,
list
):
message
=
[
message
]
...
...
@@ -485,19 +550,12 @@ def get_message_from_http_response(response):
response
.
content
)
def
peek_message
(
topic_obj
,
subscription_name
,
message_position
):
def
peek_message
(
topic_name
,
subscription_name
,
message_position
):
if
not
isinstance
(
topic_name
,
TopicName
):
topic_name
=
TopicName
(
topic_name
)
peek_url
=
"%s/subscription/%s/position/%s"
%
(
topic_
path
(
topic_obj
),
subscription_name
,
message_position
)
topic_
name
.
admin_path
(
),
subscription_name
,
message_position
)
peek_response
=
requests
.
get
(
peek_url
)
if
peek_response
.
status_code
!=
200
:
return
{
"ERROR"
:
"%s(%d)"
%
(
peek_response
.
reason
,
peek_response
.
status_code
)}
return
get_message_from_http_response
(
peek_response
)
def
topic_path
(
topic_obj
):
admin_base
=
"/admin/v2/"
if
topic_obj
.
is_v2
()
else
"/admin/"
return
settings
.
SERVICE_URL
+
admin_base
+
topic_obj
.
url_name
()
def
extract_topic_db_name
(
topic_name
):
return
'persistent://'
+
topic_name
.
split
(
'persistent/'
,
1
)[
1
]
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录