-
Notifications
You must be signed in to change notification settings - Fork 15
/
send_job.py
36 lines (30 loc) · 1009 Bytes
/
send_job.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import click, json
from socket import *
# Configure command line options
DEFAULT_PORT_NUM = 6000
@click.option("--port_number", "-p", "port_number",
default=DEFAULT_PORT_NUM,
help="The port the master is listening on, default " + str(DEFAULT_PORT_NUM))
def main(port_number=DEFAULT_PORT_NUM):
# Temp job to send to master.
# Values can (and should!) be changed
job_dict = {
"message_type": "new_master_job",
"input_directory": "./input",
"output_directory": "./output",
"mapper_executable": "./map",
"reducer_executable": "./reduce",
"num_mappers": 4,
"num_reducers": 2
}
message = json.dumps(job_dict)
# Send the data to the port that master is on
try:
sock = socket(AF_INET, SOCK_STREAM)
sock.connect(("localhost", port_number))
sock.sendall(str.encode(message))
sock.close()
except error:
print("Failed to send job to master.")
if __name__ == "__main__":
main()