-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
109 lines (83 loc) · 2.69 KB
/
main.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
from cli import CLI
from mapper import Mapper
from reducer import Reducer
from prm import PRM
from multiprocessing import Process
import time
class Main:
def __init__(self, num):
self.num = int(num)
f = open("config.txt", "r")
text = f.read()
self.ips = text.split()
self.ip = self.ips[self.num-1]
def createCLI(self):
cli = CLI(self.num);
# cli.logging(False)
cli.log('Starting Up');
# this maps the CLI looks pretty
time.sleep(1);
cli.log('Loading 3...');
time.sleep(1);
cli.log('Loading 2...');
time.sleep(1);
cli.log('Loading 1...');
time.sleep(1);
# pass details
cli.defineMapperOne(5001 + (self.num-1)*10, self.ip);
cli.defineMapperTwo(5002 + (self.num-1)*10, self.ip);
cli.defineReducer(5003 + (self.num-1)*10, self.ip);
cli.definePRM(5004 + (self.num-1)*10, self.ip);
cli.log('Enter commands below. Use ctrl+c to exit.')
boo = True
while (boo):
try:
command = raw_input('> ')
cli.handleCommand(command.split());
except KeyboardInterrupt:
boo = False;
time.sleep(1);
# exiting
cli.log('Exiting');
def createMapperOne(self):
mapperOne = Mapper(5001 + (self.num-1)*10, self.ip, 1);
mapperOne.logging(False)
mapperOne.log('Starting Up');
# execution code goes here
mapperOne.listen()
# exiting
mapperOne.log('Exiting');
def createMapperTwo(self):
mapperTwo = Mapper(5002 + (self.num-1)*10, self.ip, 2);
mapperTwo.logging(False)
mapperTwo.log('Starting Up');
# execution code goes here
mapperTwo.listen()
# exiting
mapperTwo.log('Exiting');
def createReducer(self):
reducer = Reducer(5003 + (self.num-1)*10, self.ip);
reducer.logging(False)
reducer.log('Starting Up');
# execution code goes here
reducer.listen()
# exiting
reducer.log('Exiting');
def createPRM(self):
prm = PRM(5004 + (self.num-1)*10, self.ips, self.ip, self.num);
prm.logging(False)
prm.log('Starting Up');
# execution code goes here
prm.createFlavors()
# exiting
prm.log('Exiting');
def createProcesses(self):
p1 = Process(target=self.createMapperOne);
p2 = Process(target=self.createMapperTwo);
p3 = Process(target=self.createReducer);
p4 = Process(target=self.createPRM);
p1.start();
p2.start();
p3.start();
p4.start();
self.createCLI();