-
Notifications
You must be signed in to change notification settings - Fork 0
/
Cluster.py
51 lines (39 loc) · 1.45 KB
/
Cluster.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
'''
Created on Jan 10, 2015
@author: niuzhaojie
'''
from FSSchedulerNode import FSSchedulerNode
from Resource import Resource
import Configuration
class Cluster(object):
'''
classdocs
'''
def __init__(self, numOfNodes, load = 0.0):
'''
Constructor
'''
self._nodeList = []
self._nodeDict = {}
self._fileList = {}
for i in range(numOfNodes):
node = FSSchedulerNode(i, Resource(Configuration.NODE_MEMORY * (1 - load),
Configuration.NODE_CPU * (1 - load),
Configuration.NODE_DISK_BANDWIDTH * (1 - load),
Configuration.NODE_NETWORK_BANDWIDTH * (1 - load)))
self._nodeList.append(node)
self._nodeDict[node.getNodeID()] = node
def uploadFile(self, file):
self._fileList[file.getFileName()] = file
# assign blocks to cluster in round-robin way
i = 0
for block in file.getBlockList():
self._nodeList[i].uploadFileBlock(block)
block.assignToNode(self._nodeList[i])
i = (i + 1) % len(self._nodeList)
def getFile(self, filename):
return self._fileList.get(filename)
def getAllNodes(self):
return self._nodeList
def getClusterSize(self):
return len(self._nodeList)