1 '''
2 Created on Aug 11, 2010
3
4 @author: dwmclary
5 '''
6 import networkx as nx
7 from .. hdmc import hdfs
9 '''
10 Provides graph handles in Hadoop MapReduce
11 '''
12
13
14 - def __init__(self, G = None, graph_handle=None):
15 '''
16 Constructor
17 '''
18
19 if G != None:
20 self.G = G
21
22 if graph_handle != None:
23 self.graph_handle = graph_handle
24
27
29 if undirected:
30 self.G = nx.read_adjlist(filename).to_undirected()
31 else:
32 self.G = nx.read_adjlist(filename)
33 self.graph_handle = filename
34
36 if filename:
37 nx.write_adjlist(self.G.to_directed(), filename)
38 self.graph_handle = filename
39 hdfs.mkdir(filename)
40 hdfs.copyToHDFS(filename, filename+"/page_rank")
41
42 hdfs.copyToHDFS(filename, filename+"/degree")
43 else:
44 if self.graph_handle:
45 nx.write_adjlist(self.G.to_directed(), self.graph_handle)
46
49
51 listing = hdfs.ls(self.graph_handle)["stdout"].split("\n")
52 found = False
53 disk_tail = self.graph_handle.split("/")[-1]
54 for line in listing:
55 hdfs_tail = line.split("/")[-1]
56 if disk_tail == hdfs_tail:
57 found = True
58 break
59 return found
60