Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
cse550
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Winston Jodjana
cse550
Commits
142589c9
Commit
142589c9
authored
2 years ago
by
WinJ
Browse files
Options
Downloads
Patches
Plain Diff
add config files
parent
e6913fd4
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
assignment2/README.txt
+10
-2
10 additions, 2 deletions
assignment2/README.txt
assignment2/client.py
+20
-13
20 additions, 13 deletions
assignment2/client.py
assignment2/main.py
+15
-14
15 additions, 14 deletions
assignment2/main.py
with
45 additions
and
29 deletions
assignment2/README.txt
+
10
−
2
View file @
142589c9
...
...
@@ -27,8 +27,16 @@ Write-up
Communication is reliable, no atmost-once or atleast-once issues
- How to compile, deploy and run your implementation
Spawn the paxos group (replace n with number of nodes): python3 main.py n
Start the client and execute commands: python3 client.py localhost 9000
Config file to indicate the addresses of the paxos group: config.json
Spawn the paxos group based on the config file:
python3 main.py
Start the client and send commands to a random paxos server based on the config file:
python3 client.py
lock 1
lock 2
unlock 1
...
exit
- Any issues or scenarios explicitly not considered
If a client send a message and it gets dropped, we assume it was lost and won't be executed as clients won't resend messages
...
...
This diff is collapsed.
Click to expand it.
assignment2/client.py
+
20
−
13
View file @
142589c9
import
json
import
pickle
import
random
import
socket
import
sys
...
...
@@ -6,27 +8,32 @@ from message import * # Can change this after testing done
if
__name__
==
"
__main__
"
:
# create a UDP socket
HOST
,
PORT
=
"
localhost
"
,
8000
# TODO: Uncomment below for multiple nodes paxos
with
open
(
"
config.json
"
,
encoding
=
'
utf-8
'
)
as
f
:
json_dict
=
json
.
loads
(
f
.
read
())
server_addresses
=
json_dict
[
"
servers
"
]
server_addresses
=
[(
server_addresses
[
i
],
int
(
server_addresses
[
i
+
1
]))
for
i
in
range
(
0
,
len
(
server_addresses
),
2
)]
serv_addresses
=
((
HOST
,
8000
),
(
HOST
,
8001
))
sock
=
socket
.
socket
(
socket
.
AF_INET
,
socket
.
SOCK_DGRAM
)
sock
.
bind
((
'
localhost
'
,
0
))
address
=
sock
.
getsockname
()
print
(
"
Starting client {0}
"
.
format
(
address
),
file
=
sys
.
stderr
)
input_str
=
input
(
"
Enter a command (e.g. lock 2 / unlock 2 / exit):
"
)
# Input would be "lock 2" / "unlock 1", etc or "exit"
sock
.
bind
((
sys
.
argv
[
1
],
int
(
sys
.
argv
[
2
])))
client_addr
=
sock
.
getsockname
()
print
(
f
"
Starting client
{
client_addr
}
"
,
file
=
sys
.
stderr
)
prompt_str
=
"
Enter a command (e.g. lock 2 / unlock 2 / exit):
"
input_str
=
input
(
prompt_str
)
# Input would be "lock 2" / "unlock 1", etc or "exit"
try
:
while
input_str
!=
"
exit
"
:
lock
,
val
=
input_str
.
split
(
"
"
,
2
)
paxos_req
=
PaxosRequest
(
address
,
LockCommand
(
lock
,
val
))
paxos_req
=
PaxosRequest
(
client_addr
,
LockCommand
(
lock
,
val
))
data
=
pickle
.
dumps
(
paxos_req
)
print
(
f
"
Sending lock command
{
paxos_req
}
"
,
file
=
sys
.
stderr
)
# send request to server
for
serv_addr
in
serv_addresses
:
sock
.
sendto
(
data
,
serv_addr
)
random
.
seed
(
4
)
# TODO: comment to do randomness
server_address
=
random
.
choice
(
server_addresses
)
print
(
f
"
Sending command
{
paxos_req
}
to
{
server_address
}
"
,
file
=
sys
.
stderr
)
# send request to random server
sock
.
sendto
(
data
,
server_address
)
# receive data back from the server
res
=
pickle
.
loads
(
sock
.
recv
(
1024
))
...
...
@@ -38,7 +45,7 @@ if __name__ == "__main__":
else
:
print
(
"
Command failed to run
"
,
file
=
sys
.
stderr
)
input_str
=
input
(
"
\n
Enter a command:
"
)
input_str
=
input
(
prompt_str
)
finally
:
# Close socket
sock
.
close
()
This diff is collapsed.
Click to expand it.
assignment2/main.py
+
15
−
14
View file @
142589c9
...
...
@@ -9,18 +9,19 @@ if __name__ == "__main__":
with
open
(
"
config.json
"
,
encoding
=
'
utf-8
'
)
as
f
:
json_dict
=
json
.
loads
(
f
.
read
())
addresses
=
json_dict
[
"
servers
"
]
try
:
for
i
in
range
(
0
,
len
(
addresses
),
2
):
paxos_host
=
addresses
[
i
]
paxos_port
=
addresses
[
i
+
1
]
proc
=
subprocess
.
Popen
([
"
python3
"
,
"
paxos.py
"
,
paxos_host
,
paxos_port
]
+
addresses
)
processes
.
append
(
proc
)
# Needed to sleep forever here until ctrl-c so we go into "finally" and kill processes
while
True
:
time
.
sleep
(
10
)
finally
:
for
proc
in
processes
:
# proc.send_signal(signal.SIGINT)
proc
.
kill
()
\ No newline at end of file
addresses
=
json_dict
[
"
servers
"
]
try
:
for
i
in
range
(
0
,
len
(
addresses
),
2
):
paxos_host
=
addresses
[
i
]
paxos_port
=
addresses
[
i
+
1
]
proc
=
subprocess
.
Popen
([
"
python3
"
,
"
paxos.py
"
,
paxos_host
,
paxos_port
]
+
addresses
)
processes
.
append
(
proc
)
# Needed to sleep forever here until ctrl-c so we go into "finally" and kill processes
while
True
:
time
.
sleep
(
10
)
finally
:
for
proc
in
processes
:
# proc.send_signal(signal.SIGINT)
proc
.
kill
()
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
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!
Save comment
Cancel
Please
register
or
sign in
to comment