This project has retired. For details please refer to its
Attic page.
DsDirectory xref
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.hadoop.chukwa.extraction.engine.datasource;
20
21
22 import java.io.IOException;
23 import java.util.ArrayList;
24 import java.util.List;
25 import org.apache.hadoop.chukwa.inputtools.mdl.DataConfig;
26 import org.apache.hadoop.conf.Configuration;
27 import org.apache.hadoop.fs.FileStatus;
28 import org.apache.hadoop.fs.FileSystem;
29 import org.apache.hadoop.fs.Path;
30
31 public class DsDirectory {
32 private static Object lock = new Object();
33 private static DsDirectory dsDirectory = null;
34 private static final String[] emptyArray = new String[0];
35
36 private String rootFolder = null;
37 private DataConfig dataConfig = null;
38
39 private static FileSystem fs = null;
40 private static Configuration conf = null;
41
42 private DsDirectory() {
43 dataConfig = new DataConfig();
44 conf = new Configuration();
45 try {
46 fs = FileSystem.get(conf);
47 } catch (IOException e) {
48 e.printStackTrace();
49 }
50 rootFolder = dataConfig.get("chukwa.engine.dsDirectory.rootFolder");
51 if (!rootFolder.endsWith("/")) {
52 rootFolder += "/";
53 }
54 }
55
56 public static DsDirectory getInstance() {
57 synchronized (lock) {
58 if (dsDirectory == null) {
59 dsDirectory = new DsDirectory();
60 }
61 }
62 return dsDirectory;
63 }
64
65 public String[] list(String cluster) throws DataSourceException {
66 List<String> datasources = new ArrayList<String>();
67 try {
68 FileStatus[] fileStat = fs.listStatus(new Path(rootFolder + cluster));
69
70 for (FileStatus fstat : fileStat) {
71 if (fstat.isDir()) {
72 datasources.add(fstat.getPath().getName());
73 }
74 }
75 } catch (IOException e) {
76 e.printStackTrace();
77 throw new DataSourceException(e);
78 }
79 return datasources.toArray(emptyArray);
80 }
81
82 public static void main(String[] args) throws DataSourceException {
83 DsDirectory dsd = DsDirectory.getInstance();
84 String[] dss = dsd.list("unknown");
85 for (String d : dss) {
86 System.out.println(d);
87 }
88 }
89 }