Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
S
service-registry
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Odysseus
service-registry
Commits
f64083c2
Commit
f64083c2
authored
Feb 27, 2024
by
luxq
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ajust code
parent
89640375
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
133 additions
and
29 deletions
+133
-29
apigateway.go
query/apigateway.go
+5
-0
backend.go
query/backend.go
+5
-0
interface.go
query/interface.go
+8
-5
nm.go
query/nm.go
+54
-22
schedule.go
query/schedule.go
+5
-0
worker.go
query/worker.go
+56
-2
No files found.
query/apigateway.go
View file @
f64083c2
...
@@ -17,6 +17,11 @@ func (g GatewayInfo) TimeStamp() int64 {
...
@@ -17,6 +17,11 @@ func (g GatewayInfo) TimeStamp() int64 {
return
g
.
Timestamp
return
g
.
Timestamp
}
}
func
(
g
GatewayInfo
)
Message
()
json
.
RawMessage
{
d
,
_
:=
json
.
Marshal
(
g
)
return
d
}
type
gatewayQuery
struct
{
type
gatewayQuery
struct
{
rdb
*
redis
.
Client
rdb
*
redis
.
Client
service
common
.
ServiceType
service
common
.
ServiceType
...
...
query/backend.go
View file @
f64083c2
...
@@ -17,6 +17,11 @@ func (g BackendInfo) TimeStamp() int64 {
...
@@ -17,6 +17,11 @@ func (g BackendInfo) TimeStamp() int64 {
return
g
.
Timestamp
return
g
.
Timestamp
}
}
func
(
g
BackendInfo
)
Message
()
json
.
RawMessage
{
d
,
_
:=
json
.
Marshal
(
g
)
return
d
}
type
backendQuery
struct
{
type
backendQuery
struct
{
rdb
*
redis
.
Client
rdb
*
redis
.
Client
service
common
.
ServiceType
service
common
.
ServiceType
...
...
query/interface.go
View file @
f64083c2
package
query
package
query
import
"encoding/json"
type
ServiceQuery
interface
{
type
ServiceQuery
interface
{
ModuleName
()
string
ModuleName
()
string
List
()
([]
string
,
error
)
List
()
([]
string
,
error
)
ServiceInfo
(
serviceid
string
)
(
string
,
error
)
ServiceInfo
(
serviceid
string
)
(
string
,
error
)
}
}
type
TimeSortable
interface
{
type
ServiceInfo
interface
{
TimeStamp
()
int64
TimeStamp
()
int64
Message
()
json
.
RawMessage
}
}
type
TimeSortableSlice
[]
TimeSortable
type
ServiceInfoList
[]
ServiceInfo
func
(
s
TimeSortableSlice
)
Len
()
int
{
func
(
s
ServiceInfoList
)
Len
()
int
{
return
len
(
s
)
return
len
(
s
)
}
}
func
(
s
TimeSortableSlice
)
Swap
(
i
,
j
int
)
{
func
(
s
ServiceInfoList
)
Swap
(
i
,
j
int
)
{
s
[
i
],
s
[
j
]
=
s
[
j
],
s
[
i
]
s
[
i
],
s
[
j
]
=
s
[
j
],
s
[
i
]
}
}
func
(
s
TimeSortableSlice
)
Less
(
i
,
j
int
)
bool
{
func
(
s
ServiceInfoList
)
Less
(
i
,
j
int
)
bool
{
return
s
[
i
]
.
TimeStamp
()
<
s
[
j
]
.
TimeStamp
()
return
s
[
i
]
.
TimeStamp
()
<
s
[
j
]
.
TimeStamp
()
}
}
query/nm.go
View file @
f64083c2
...
@@ -6,6 +6,7 @@ import (
...
@@ -6,6 +6,7 @@ import (
"fmt"
"fmt"
"github.com/odysseus/service-registry/common"
"github.com/odysseus/service-registry/common"
"github.com/redis/go-redis/v9"
"github.com/redis/go-redis/v9"
"sort"
)
)
type
NodeManagerInfo
struct
{
type
NodeManagerInfo
struct
{
...
@@ -17,6 +18,11 @@ func (g NodeManagerInfo) TimeStamp() int64 {
...
@@ -17,6 +18,11 @@ func (g NodeManagerInfo) TimeStamp() int64 {
return
g
.
Timestamp
return
g
.
Timestamp
}
}
func
(
g
NodeManagerInfo
)
Message
()
json
.
RawMessage
{
d
,
_
:=
json
.
Marshal
(
g
)
return
d
}
type
nodeManagerQuery
struct
{
type
nodeManagerQuery
struct
{
rdb
*
redis
.
Client
rdb
*
redis
.
Client
service
common
.
ServiceType
service
common
.
ServiceType
...
@@ -34,54 +40,80 @@ func (g nodeManagerQuery) ModuleName() string {
...
@@ -34,54 +40,80 @@ func (g nodeManagerQuery) ModuleName() string {
}
}
func
(
g
nodeManagerQuery
)
List
()
([]
string
,
error
)
{
func
(
g
nodeManagerQuery
)
List
()
([]
string
,
error
)
{
all
,
err
:=
getAll
Nm
(
g
.
rdb
,
g
.
service
)
all
,
err
:=
getAll
(
g
.
rdb
,
g
.
service
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
sort
.
Sort
(
ServiceInfoList
(
all
))
var
res
[]
string
var
res
[]
string
for
_
,
v
:=
range
all
{
for
_
,
v
:=
range
all
{
d
,
_
:=
json
.
Marshal
(
v
)
res
=
append
(
res
,
string
(
v
.
Message
()))
res
=
append
(
res
,
string
(
d
))
}
}
return
res
,
nil
return
res
,
nil
}
}
func
(
g
nodeManagerQuery
)
ServiceInfo
(
serviceid
string
)
(
string
,
error
)
{
func
(
g
nodeManagerQuery
)
ServiceInfo
(
serviceid
string
)
(
string
,
error
)
{
info
,
err
:=
getOneNm
(
g
.
rdb
,
g
.
service
,
serviceid
)
info
,
err
:=
getOne
(
g
.
rdb
,
g
.
service
,
serviceid
)
if
err
!=
nil
{
return
""
,
err
}
d
,
err
:=
json
.
Marshal
(
info
)
if
err
!=
nil
{
if
err
!=
nil
{
return
""
,
err
return
""
,
err
}
}
return
string
(
info
.
Message
()),
nil
}
return
string
(
d
),
nil
func
parseInfo
(
stype
common
.
ServiceType
,
res
*
redis
.
MapStringStringCmd
)
ServiceInfo
{
var
ret
ServiceInfo
switch
stype
{
case
common
.
SERVICE_NODE_MANAGER
:
var
info
NodeManagerInfo
if
err
:=
res
.
Scan
(
&
info
);
err
!=
nil
{
return
nil
}
ret
=
info
case
common
.
SERVICE_API_GATEWAY
:
var
info
GatewayInfo
if
err
:=
res
.
Scan
(
&
info
);
err
!=
nil
{
return
nil
}
ret
=
info
case
common
.
SERVICE_BACKEND
:
var
info
BackendInfo
if
err
:=
res
.
Scan
(
&
info
);
err
!=
nil
{
return
nil
}
ret
=
info
case
common
.
SERVICE_SCHEDULER
:
var
info
SchedulerInfo
if
err
:=
res
.
Scan
(
&
info
);
err
!=
nil
{
return
nil
}
ret
=
info
case
common
.
SERVICE_WORKER
:
var
info
WorkerInfo
if
err
:=
res
.
Scan
(
&
info
);
err
!=
nil
{
return
nil
}
ret
=
info
}
return
ret
}
}
func
getAll
Nm
(
rdb
*
redis
.
Client
,
serviceType
common
.
ServiceType
)
([]
NodeManagerInfo
,
error
)
{
func
getAll
(
rdb
*
redis
.
Client
,
serviceType
common
.
ServiceType
)
(
ServiceInfoList
,
error
)
{
keys
,
err
:=
rdb
.
Keys
(
context
.
Background
(),
common
.
GetServiceKeyPrefix
(
serviceType
)
+
"*"
)
.
Result
()
keys
,
err
:=
rdb
.
Keys
(
context
.
Background
(),
common
.
GetServiceKeyPrefix
(
serviceType
)
+
"*"
)
.
Result
()
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
var
nmInfos
[]
NodeManager
Info
var
list
[]
Service
Info
for
_
,
key
:=
range
keys
{
for
_
,
key
:=
range
keys
{
res
:=
rdb
.
HGetAll
(
context
.
Background
(),
key
)
res
:=
rdb
.
HGetAll
(
context
.
Background
(),
key
)
var
info
NodeManagerInfo
if
info
:=
parseInfo
(
serviceType
,
res
);
info
!=
nil
{
if
err
:=
res
.
Scan
(
&
info
);
err
!=
nil
{
list
=
append
(
list
,
info
)
continue
}
}
nmInfos
=
append
(
nmInfos
,
info
)
}
}
return
nmInfos
,
nil
return
list
,
nil
}
}
func
getOne
Nm
(
rdb
*
redis
.
Client
,
serviceType
common
.
ServiceType
,
endpoint
string
)
(
NodeManager
Info
,
error
)
{
func
getOne
(
rdb
*
redis
.
Client
,
serviceType
common
.
ServiceType
,
endpoint
string
)
(
Service
Info
,
error
)
{
k
:=
fmt
.
Sprintf
(
"%s%s"
,
common
.
GetServiceKeyPrefix
(
serviceType
),
endpoint
)
k
:=
fmt
.
Sprintf
(
"%s%s"
,
common
.
GetServiceKeyPrefix
(
serviceType
),
endpoint
)
res
:=
rdb
.
HGetAll
(
context
.
Background
(),
k
)
res
:=
rdb
.
HGetAll
(
context
.
Background
(),
k
)
var
info
NodeManagerInfo
return
parseInfo
(
serviceType
,
res
),
nil
if
err
:=
res
.
Scan
(
&
info
);
err
!=
nil
{
return
NodeManagerInfo
{},
err
}
return
info
,
nil
}
}
query/schedule.go
View file @
f64083c2
...
@@ -17,6 +17,11 @@ func (g SchedulerInfo) TimeStamp() int64 {
...
@@ -17,6 +17,11 @@ func (g SchedulerInfo) TimeStamp() int64 {
return
g
.
Timestamp
return
g
.
Timestamp
}
}
func
(
g
SchedulerInfo
)
Message
()
json
.
RawMessage
{
d
,
_
:=
json
.
Marshal
(
g
)
return
d
}
type
schedulerQuery
struct
{
type
schedulerQuery
struct
{
rdb
*
redis
.
Client
rdb
*
redis
.
Client
service
common
.
ServiceType
service
common
.
ServiceType
...
...
query/worker.go
View file @
f64083c2
package
query
package
query
import
(
import
(
"context"
"encoding/json"
"fmt"
"github.com/odysseus/service-registry/common"
"github.com/odysseus/service-registry/common"
"github.com/redis/go-redis/v9"
"github.com/redis/go-redis/v9"
)
)
type
WorkerInfo
struct
{
type
WorkerInfo
struct
{
Timestamp
int64
`json:"timestamp"`
Timestamp
int64
`json:"timestamp"`
HearBeat
int64
`json:"heartbeat"`
ActiveNM
[]
string
`json:"active_nm"`
ActiveNM
[]
string
`json:"active_nm"`
MinerAddress
string
`json:"miner_address"`
MinerAddress
string
`json:"miner_address"`
BenefitAddress
string
`json:"benefit_address"`
BenefitAddress
string
`json:"benefit_address"`
...
@@ -18,6 +22,11 @@ func (g WorkerInfo) TimeStamp() int64 {
...
@@ -18,6 +22,11 @@ func (g WorkerInfo) TimeStamp() int64 {
return
g
.
Timestamp
return
g
.
Timestamp
}
}
func
(
g
WorkerInfo
)
Message
()
json
.
RawMessage
{
d
,
_
:=
json
.
Marshal
(
g
)
return
d
}
type
workerQuery
struct
{
type
workerQuery
struct
{
rdb
*
redis
.
Client
rdb
*
redis
.
Client
service
common
.
ServiceType
service
common
.
ServiceType
...
@@ -35,9 +44,54 @@ func (g workerQuery) ModuleName() string {
...
@@ -35,9 +44,54 @@ func (g workerQuery) ModuleName() string {
}
}
func
(
g
workerQuery
)
List
()
([]
string
,
error
)
{
func
(
g
workerQuery
)
List
()
([]
string
,
error
)
{
return
[]
string
{},
nil
all
,
err
:=
getAllWorker
(
g
.
rdb
,
g
.
service
)
if
err
!=
nil
{
return
nil
,
err
}
var
res
[]
string
for
_
,
v
:=
range
all
{
d
,
_
:=
json
.
Marshal
(
v
)
res
=
append
(
res
,
string
(
d
))
}
return
res
,
nil
}
}
func
(
g
workerQuery
)
ServiceInfo
(
serviceid
string
)
(
string
,
error
)
{
func
(
g
workerQuery
)
ServiceInfo
(
serviceid
string
)
(
string
,
error
)
{
return
""
,
nil
info
,
err
:=
getOneWorker
(
g
.
rdb
,
g
.
service
,
serviceid
)
if
err
!=
nil
{
return
""
,
err
}
d
,
err
:=
json
.
Marshal
(
info
)
if
err
!=
nil
{
return
""
,
err
}
return
string
(
d
),
nil
}
func
getAllWorker
(
rdb
*
redis
.
Client
,
serviceType
common
.
ServiceType
)
([]
WorkerInfo
,
error
)
{
keys
,
err
:=
rdb
.
Keys
(
context
.
Background
(),
common
.
GetServiceKeyPrefix
(
serviceType
)
+
"*"
)
.
Result
()
if
err
!=
nil
{
return
nil
,
err
}
var
nmInfos
[]
WorkerInfo
for
_
,
key
:=
range
keys
{
res
:=
rdb
.
HGetAll
(
context
.
Background
(),
key
)
var
info
WorkerInfo
if
err
:=
res
.
Scan
(
&
info
);
err
!=
nil
{
continue
}
nmInfos
=
append
(
nmInfos
,
info
)
}
return
nmInfos
,
nil
}
func
getOneWorker
(
rdb
*
redis
.
Client
,
serviceType
common
.
ServiceType
,
endpoint
string
)
(
WorkerInfo
,
error
)
{
k
:=
fmt
.
Sprintf
(
"%s%s"
,
common
.
GetServiceKeyPrefix
(
serviceType
),
endpoint
)
res
:=
rdb
.
HGetAll
(
context
.
Background
(),
k
)
var
info
WorkerInfo
if
err
:=
res
.
Scan
(
&
info
);
err
!=
nil
{
return
WorkerInfo
{},
err
}
return
info
,
nil
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a 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