Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
CIRCLE3
/
balancer
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
76bb9cab
authored
May 17, 2023
by
Karsa Zoltán István
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
linter
parent
b53e8296
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
20 additions
and
7 deletions
+20
-7
main.py
+6
-3
pyproject.toml
+4
-0
sredis/sredis.py
+9
-3
stresstest/main.py
+1
-1
No files found.
main.py
View file @
76bb9cab
...
@@ -8,8 +8,8 @@ from sredis.sredis import (
...
@@ -8,8 +8,8 @@ from sredis.sredis import (
add_datacenter
,
add_datacenter
,
set_token
,
set_token
,
create_superpuser
,
create_superpuser
,
get_rtokens
,
get_rtokens
,
reset
reset
,
)
)
import
logging
import
logging
import
requests
import
requests
...
@@ -60,7 +60,9 @@ def proxy_get(
...
@@ -60,7 +60,9 @@ def proxy_get(
def
proxy_delete
(
def
proxy_delete
(
server_path
:
str
=
"/"
,
username
=
Depends
(
get_current_user
),
datacenter
:
str
=
""
server_path
:
str
=
"/"
,
username
=
Depends
(
get_current_user
),
datacenter
:
str
=
""
):
):
return
proxy_datacenters
(
server_path
,
username
,
method
=
"DELETE"
,
datacenter
=
datacenter
)
return
proxy_datacenters
(
server_path
,
username
,
method
=
"DELETE"
,
datacenter
=
datacenter
)
@app.post
(
"/lb/rr/{server_path:path}"
)
@app.post
(
"/lb/rr/{server_path:path}"
)
...
@@ -89,6 +91,7 @@ def set_tokens(tokens: List[Token] = None, username=Depends(get_current_user)):
...
@@ -89,6 +91,7 @@ def set_tokens(tokens: List[Token] = None, username=Depends(get_current_user)):
set_token
(
username
,
str
(
token
.
datacenter
),
str
(
token
.
token
))
set_token
(
username
,
str
(
token
.
datacenter
),
str
(
token
.
token
))
return
tokens
return
tokens
@app.get
(
"/tokens/"
)
@app.get
(
"/tokens/"
)
def
get_tokens
(
username
=
Depends
(
get_current_user
)):
def
get_tokens
(
username
=
Depends
(
get_current_user
)):
return
get_rtokens
(
username
=
username
)
return
get_rtokens
(
username
=
username
)
pyproject.toml
View file @
76bb9cab
...
@@ -29,6 +29,10 @@ help = "Start the microservice on port 6973"
...
@@ -29,6 +29,10 @@ help = "Start the microservice on port 6973"
shell
=
"poetry run uvicorn main:app --host 0.0.0.0 --port 8080 --workers 8 --log-level critical"
shell
=
"poetry run uvicorn main:app --host 0.0.0.0 --port 8080 --workers 8 --log-level critical"
help
=
"Start the prod deployment"
help
=
"Start the prod deployment"
[tool.poe.tasks.stress]
shell
=
"poetry run uvicorn main:app --host 0.0.0.0 --port 6973 --workers 4"
help
=
"Start the prod deployment"
[tool.poe.tasks.lint]
[tool.poe.tasks.lint]
shell
=
"poetry run black . && poetry run ruff --fix . "
shell
=
"poetry run black . && poetry run ruff --fix . "
help
=
"Lint the most important parts of the microservice with black"
help
=
"Lint the most important parts of the microservice with black"
...
...
sredis/sredis.py
View file @
76bb9cab
...
@@ -9,12 +9,13 @@ import random
...
@@ -9,12 +9,13 @@ import random
r
=
redis
.
Redis
(
host
=
"localhost"
,
port
=
6379
,
db
=
0
,
decode_responses
=
True
)
r
=
redis
.
Redis
(
host
=
"localhost"
,
port
=
6379
,
db
=
0
,
decode_responses
=
True
)
def
reset
():
def
reset
():
print
(
"Reset OK"
)
print
(
"Reset OK"
)
r
.
set
(
"datacenters_cnt"
,
1
)
r
.
set
(
"datacenters_cnt"
,
1
)
all_keys
=
r
.
hgetall
(
"datacenters_hash"
)
all_keys
=
r
.
hgetall
(
"datacenters_hash"
)
if
all_keys
.
keys
():
if
all_keys
.
keys
():
r
.
hdel
(
"datacenters_hash"
,
*
list
(
all_keys
.
keys
()))
r
.
hdel
(
"datacenters_hash"
,
*
list
(
all_keys
.
keys
()))
r
.
delete
(
"rrlist"
)
r
.
delete
(
"rrlist"
)
pipe
=
r
.
pipeline
()
pipe
=
r
.
pipeline
()
...
@@ -22,6 +23,7 @@ def reset():
...
@@ -22,6 +23,7 @@ def reset():
pipe
.
rpush
(
"rrlist"
,
dc
)
pipe
.
rpush
(
"rrlist"
,
dc
)
pipe
.
execute
()
pipe
.
execute
()
def
add_datacenter
(
datacenter
:
str
):
def
add_datacenter
(
datacenter
:
str
):
cnt
=
int
(
r
.
get
(
"datacenters_cnt"
))
cnt
=
int
(
r
.
get
(
"datacenters_cnt"
))
r
.
hset
(
"datacenters_hash"
,
cnt
,
datacenter
)
r
.
hset
(
"datacenters_hash"
,
cnt
,
datacenter
)
...
@@ -29,6 +31,7 @@ def add_datacenter(datacenter: str):
...
@@ -29,6 +31,7 @@ def add_datacenter(datacenter: str):
r
.
set
(
"roundrobin_cnt"
,
1
)
r
.
set
(
"roundrobin_cnt"
,
1
)
r
.
rpush
(
"rrlist"
,
datacenter
)
r
.
rpush
(
"rrlist"
,
datacenter
)
def
rr_get
():
def
rr_get
():
rr
=
r
.
rpoplpush
(
"rrlist"
,
"rrlist"
)
rr
=
r
.
rpoplpush
(
"rrlist"
,
"rrlist"
)
return
rr
return
rr
...
@@ -43,19 +46,22 @@ def wr_get(centers: DataCenterSchema):
...
@@ -43,19 +46,22 @@ def wr_get(centers: DataCenterSchema):
def
set_token
(
username
:
str
,
datacenter
:
str
,
token
:
str
):
def
set_token
(
username
:
str
,
datacenter
:
str
,
token
:
str
):
r
.
hset
(
f
"tokens:{username}"
,
datacenter
,
token
)
r
.
hset
(
f
"tokens:{username}"
,
datacenter
,
token
)
def
get_rtoken
(
username
:
str
,
datacenter
:
str
):
def
get_rtoken
(
username
:
str
,
datacenter
:
str
):
return
r
.
hget
(
f
"tokens:{username}"
,
datacenter
)
return
r
.
hget
(
f
"tokens:{username}"
,
datacenter
)
def
get_rtokens
(
username
:
str
):
def
get_rtokens
(
username
:
str
):
center_ids
=
list
(
r
.
hgetall
(
"datacenters_hash"
)
.
keys
())
center_ids
=
list
(
r
.
hgetall
(
"datacenters_hash"
)
.
keys
())
tokens
=
[]
tokens
=
[]
for
id
in
center_ids
:
for
id
in
center_ids
:
token
=
{
}
token
=
{
}
token
[
"datacenter"
]
=
r
.
hget
(
"datacenters_hash"
,
id
)
token
[
"datacenter"
]
=
r
.
hget
(
"datacenters_hash"
,
id
)
token
[
"token"
]
=
get_rtoken
(
username
=
username
,
datacenter
=
token
[
"datacenter"
])
token
[
"token"
]
=
get_rtoken
(
username
=
username
,
datacenter
=
token
[
"datacenter"
])
tokens
.
insert
(
0
,
token
)
tokens
.
insert
(
0
,
token
)
return
tokens
return
tokens
def
get_datacenter_token
(
username
:
str
,
datacenter
:
str
):
def
get_datacenter_token
(
username
:
str
,
datacenter
:
str
):
return
str
(
r
.
hget
(
f
"tokens:{username}"
,
datacenter
))
return
str
(
r
.
hget
(
f
"tokens:{username}"
,
datacenter
))
...
...
stresstest/main.py
View file @
76bb9cab
...
@@ -21,7 +21,7 @@ class PerformanceTests(TaskSet):
...
@@ -21,7 +21,7 @@ class PerformanceTests(TaskSet):
@task
(
2
)
@task
(
2
)
def
testRRLoadBalancerVMAll
(
self
):
def
testRRLoadBalancerVMAll
(
self
):
self
.
client
.
get
(
"/lb/dashboard/acpi/vm"
)
self
.
client
.
get
(
"/lb/dashboard/acpi/vm"
)
class
WebsiteUser
(
HttpUser
):
class
WebsiteUser
(
HttpUser
):
...
...
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