Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
csst-dfs
csst-dfs-api-cluster
Commits
8cfd792c
Commit
8cfd792c
authored
Apr 17, 2024
by
Wei Shoulin
Browse files
C9
parent
407b231e
Changes
1
Hide whitespace changes
Inline
Side-by-side
csst_dfs_api_cluster/common/catalog.py
View file @
8cfd792c
...
@@ -6,32 +6,32 @@ import io
...
@@ -6,32 +6,32 @@ import io
from
csst_dfs_commons.models
import
Result
from
csst_dfs_commons.models
import
Result
from
csst_dfs_proto.common.ephem
import
ephem_pb2
,
ephem_pb2_grpc
from
csst_dfs_proto.common.ephem
import
ephem_pb2
,
ephem_pb2_grpc
from
.service
import
grpc_channel
from
.service
import
get_
grpc_channel
from
.utils
import
get_auth_headers
from
.utils
import
get_auth_headers
log
=
logging
.
getLogger
(
'csst'
)
log
=
logging
.
getLogger
(
'csst'
)
class
CatalogApi
(
object
):
class
CatalogApi
(
object
):
def
__init__
(
self
):
def
__init__
(
self
):
self
.
stub_class
=
ephem_pb2_grpc
.
EphemSearchSrvStub
self
.
stub
=
None
self
.
stub
=
None
@
grpc_channel
def
catalog_query
(
self
,
**
kwargs
):
def
catalog_query
(
self
,
**
kwargs
):
try
:
try
:
datas
=
io
.
BytesIO
()
with
get_grpc_channel
()
as
c
:
totalCount
=
0
self
.
stub
=
ephem_pb2_grpc
.
EphemSearchSrvStub
(
c
)
resps
=
self
.
stub
.
Search
(
ephem_pb2
.
SearchRequest
(
datas
=
io
.
BytesIO
()
conditions
=
{
k
:
str
(
v
)
for
k
,
v
in
kwargs
.
items
()
}
totalCount
=
0
),
metadata
=
get_auth_headers
())
resps
=
self
.
stub
.
Search
(
ephem_pb2
.
SearchRequest
(
for
resp
in
resps
:
conditions
=
{
k
:
str
(
v
)
for
k
,
v
in
kwargs
.
items
()
}
if
resp
.
success
:
),
metadata
=
get_auth_headers
())
datas
.
write
(
resp
.
records
)
for
resp
in
resps
:
totalCount
=
resp
.
totalCount
if
resp
.
success
:
else
:
datas
.
write
(
resp
.
records
)
return
Result
.
error
(
message
=
str
(
resp
.
error
.
detail
))
totalCount
=
resp
.
totalCount
datas
.
flush
()
else
:
records
=
pickle
.
loads
(
datas
.
getvalue
())
return
Result
.
error
(
message
=
str
(
resp
.
error
.
detail
))
datas
.
flush
()
records
=
pickle
.
loads
(
datas
.
getvalue
())
return
Result
.
ok_data
(
data
=
records
).
append
(
"totalCount"
,
totalCount
).
append
(
"columns"
,
kwargs
[
'columns'
])
return
Result
.
ok_data
(
data
=
records
).
append
(
"totalCount"
,
totalCount
).
append
(
"columns"
,
kwargs
[
'columns'
])
except
grpc
.
RpcError
as
e
:
except
grpc
.
RpcError
as
e
:
return
Result
.
error
(
message
=
"%s:%s"
%
(
e
.
code
().
value
,
e
.
details
()))
return
Result
.
error
(
message
=
"%s:%s"
%
(
e
.
code
().
value
,
e
.
details
()))
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment