Revision 48800
Added by Claudio Atzori over 6 years ago
HadoopUtils.java | ||
---|---|---|
1 | 1 |
package eu.dnetlib.data.hadoop.utils; |
2 | 2 |
|
3 |
import java.util.Map.Entry; |
|
4 |
import java.util.Set; |
|
5 |
|
|
6 |
import org.apache.hadoop.hbase.HColumnDescriptor; |
|
7 |
import org.apache.hadoop.hbase.HTableDescriptor; |
|
8 |
|
|
9 |
import com.google.common.base.Function; |
|
10 |
import com.google.common.base.Predicate; |
|
11 |
|
|
12 | 3 |
import eu.dnetlib.data.hadoop.HadoopJob; |
13 |
import eu.dnetlib.data.hadoop.config.ClusterName; |
|
14 | 4 |
import eu.dnetlib.data.hadoop.rmi.HadoopJobDescriptor; |
15 | 5 |
import eu.dnetlib.data.hadoop.rmi.HadoopServiceException; |
6 |
import org.apache.commons.logging.Log; |
|
7 |
import org.apache.commons.logging.LogFactory; |
|
16 | 8 |
|
17 | 9 |
public class HadoopUtils { |
18 | 10 |
|
19 |
public static Function<HTableDescriptor, String> tableName() { |
|
20 |
return new Function<HTableDescriptor, String>() { |
|
11 |
private static final Log log = LogFactory.getLog(HadoopUtils.class); |
|
21 | 12 |
|
22 |
@Override |
|
23 |
public String apply(final HTableDescriptor d) { |
|
24 |
return d.getNameAsString(); |
|
13 |
public static java.util.function.Function<HadoopJob, HadoopJobDescriptor> asDescriptor() { |
|
14 |
return d -> { |
|
15 |
try { |
|
16 |
return d.asDescriptor(); |
|
17 |
} catch (HadoopServiceException e) { |
|
18 |
log.warn(e); |
|
19 |
return null; |
|
25 | 20 |
} |
26 | 21 |
}; |
27 | 22 |
} |
28 | 23 |
|
29 |
public static Function<HColumnDescriptor, String> columnName() { |
|
30 |
return new Function<HColumnDescriptor, String>() { |
|
31 |
|
|
32 |
@Override |
|
33 |
public String apply(final HColumnDescriptor d) { |
|
34 |
return d.getNameAsString(); |
|
35 |
} |
|
36 |
}; |
|
37 |
} |
|
38 |
|
|
39 |
public static Predicate<String> columnPredicate(final Set<String> cols) { |
|
40 |
return new HadoopUtils().getSetPredicate(cols); |
|
41 |
} |
|
42 |
|
|
43 |
public SetPredicate getSetPredicate(final Set<String> set) { |
|
44 |
return new SetPredicate(set); |
|
45 |
} |
|
46 |
|
|
47 |
class SetPredicate implements Predicate<String> { |
|
48 |
|
|
49 |
private final Set<String> set; |
|
50 |
|
|
51 |
public SetPredicate(final Set<String> set) { |
|
52 |
this.set = set; |
|
53 |
} |
|
54 |
|
|
55 |
@Override |
|
56 |
public boolean apply(final String s) { |
|
57 |
return !set.contains(s); |
|
58 |
} |
|
59 |
} |
|
60 |
|
|
61 |
public static Function<Entry<String, HadoopJob>, HadoopJobDescriptor> hadoopJobDescriptor() { |
|
62 |
return new Function<Entry<String, HadoopJob>, HadoopJobDescriptor>() { |
|
63 |
|
|
64 |
@Override |
|
65 |
public HadoopJobDescriptor apply(final Entry<String, HadoopJob> e) { |
|
66 |
try { |
|
67 |
return e.getValue().asDescriptor(); |
|
68 |
} catch (HadoopServiceException e1) { |
|
69 |
return null; |
|
70 |
} |
|
71 |
} |
|
72 |
}; |
|
73 |
} |
|
74 |
|
|
75 |
public static Predicate<HadoopJob> filterByCluster(final ClusterName clusterName) { |
|
76 |
return new Predicate<HadoopJob>() { |
|
77 |
|
|
78 |
@Override |
|
79 |
public boolean apply(final HadoopJob job) { |
|
80 |
return job.getClusterName().equals(clusterName); |
|
81 |
} |
|
82 |
|
|
83 |
}; |
|
84 |
} |
|
85 |
|
|
86 | 24 |
} |
Also available in: Unified diff
more logging in the oozie job monitor procedure that tries to fetch the job report. More java8 refactorings