Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
HadoopUtils |
|
| 1.0;1 |
1 | /* | |
2 | * Licensed to the Apache Software Foundation (ASF) under one | |
3 | * or more contributor license agreements. See the NOTICE file | |
4 | * distributed with this work for additional information | |
5 | * regarding copyright ownership. The ASF licenses this file | |
6 | * to you under the Apache License, Version 2.0 (the | |
7 | * "License"); you may not use this file except in compliance | |
8 | * with the License. You may obtain a copy of the License at | |
9 | * | |
10 | * http://www.apache.org/licenses/LICENSE-2.0 | |
11 | * | |
12 | * Unless required by applicable law or agreed to in writing, software | |
13 | * distributed under the License is distributed on an "AS IS" BASIS, | |
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
15 | * See the License for the specific language governing permissions and | |
16 | * limitations under the License. | |
17 | */ | |
18 | package org.apache.giraph.job; | |
19 | ||
20 | import org.apache.hadoop.conf.Configuration; | |
21 | import org.apache.hadoop.mapreduce.Job; | |
22 | import org.apache.hadoop.mapreduce.JobID; | |
23 | import org.apache.hadoop.mapreduce.JobContext; | |
24 | import org.apache.hadoop.mapreduce.TaskAttemptID; | |
25 | import org.apache.hadoop.mapreduce.TaskAttemptContext; | |
26 | ||
27 | /*if_not[HADOOP_NON_JOBCONTEXT_IS_INTERFACE]*/ | |
28 | import org.apache.hadoop.mapreduce.task.JobContextImpl; | |
29 | import org.apache.hadoop.mapreduce.task.TaskAttemptContextImpl; | |
30 | /*end[HADOOP_NON_JOBCONTEXT_IS_INTERFACE]*/ | |
31 | ||
32 | /** | |
33 | * Helpers for dealing with Hadoop. | |
34 | */ | |
35 | public class HadoopUtils { | |
36 | /** Don't construct */ | |
37 | 0 | private HadoopUtils() { } |
38 | ||
39 | /** | |
40 | * Create a TaskAttemptContext, supporting many Hadoops. | |
41 | * | |
42 | * @param conf Configuration | |
43 | * @param taskAttemptID TaskAttemptID to use | |
44 | * @return TaskAttemptContext | |
45 | */ | |
46 | public static TaskAttemptContext makeTaskAttemptContext(Configuration conf, | |
47 | TaskAttemptID taskAttemptID) { | |
48 | TaskAttemptContext context; | |
49 | /*if[HADOOP_NON_JOBCONTEXT_IS_INTERFACE] | |
50 | context = new TaskAttemptContext(conf, taskAttemptID); | |
51 | else[HADOOP_NON_JOBCONTEXT_IS_INTERFACE]*/ | |
52 | 0 | context = new TaskAttemptContextImpl(conf, taskAttemptID); |
53 | /*end[HADOOP_NON_JOBCONTEXT_IS_INTERFACE]*/ | |
54 | 0 | return context; |
55 | } | |
56 | ||
57 | /** | |
58 | * Create a TaskAttemptContext, supporting many Hadoops. | |
59 | * | |
60 | * @param conf Configuration | |
61 | * @param taskAttemptContext Use TaskAttemptID from this object | |
62 | * @return TaskAttemptContext | |
63 | */ | |
64 | public static TaskAttemptContext makeTaskAttemptContext(Configuration conf, | |
65 | TaskAttemptContext taskAttemptContext) { | |
66 | 0 | return makeTaskAttemptContext(conf, taskAttemptContext.getTaskAttemptID()); |
67 | } | |
68 | ||
69 | /** | |
70 | * Create a TaskAttemptContext, supporting many Hadoops. | |
71 | * | |
72 | * @param conf Configuration | |
73 | * @return TaskAttemptContext | |
74 | */ | |
75 | public static TaskAttemptContext makeTaskAttemptContext(Configuration conf) { | |
76 | 0 | return makeTaskAttemptContext(conf, new TaskAttemptID()); |
77 | } | |
78 | ||
79 | /** | |
80 | * Create a TaskAttemptContext, supporting many Hadoops. | |
81 | * | |
82 | * @return TaskAttemptContext | |
83 | */ | |
84 | public static TaskAttemptContext makeTaskAttemptContext() { | |
85 | 0 | return makeTaskAttemptContext(new Configuration()); |
86 | } | |
87 | ||
88 | /** | |
89 | * Create a JobContext, supporting many Hadoops. | |
90 | * | |
91 | * @param conf Configuration | |
92 | * @param jobID JobID to use | |
93 | * @return JobContext | |
94 | */ | |
95 | public static JobContext makeJobContext(Configuration conf, JobID jobID) { | |
96 | JobContext context; | |
97 | /*if[HADOOP_NON_JOBCONTEXT_IS_INTERFACE] | |
98 | context = new JobContext(conf, jobID); | |
99 | else[HADOOP_NON_JOBCONTEXT_IS_INTERFACE]*/ | |
100 | 0 | context = new JobContextImpl(conf, jobID); |
101 | /*end[HADOOP_NON_JOBCONTEXT_IS_INTERFACE]*/ | |
102 | 0 | return context; |
103 | } | |
104 | ||
105 | /** | |
106 | * Get Job ID from job. | |
107 | * May return null for hadoop 0.20.203 | |
108 | * @param job submitted job | |
109 | * @return JobId for submitted job. | |
110 | */ | |
111 | public static JobID getJobID(Job job) { | |
112 | /*if[HADOOP_JOB_ID_AVAILABLE] | |
113 | return job.getID(); | |
114 | else[HADOOP_JOB_ID_AVAILABLE]*/ | |
115 | 0 | return job.getJobID(); |
116 | /*end[HADOOP_JOB_ID_AVAILABLE]*/ | |
117 | } | |
118 | ||
119 | /** | |
120 | * Create a JobContext, supporting many Hadoops. | |
121 | * | |
122 | * @param conf Configuration | |
123 | * @param jobContext Use JobID from this object | |
124 | * @return JobContext | |
125 | */ | |
126 | public static JobContext makeJobContext(Configuration conf, | |
127 | JobContext jobContext) { | |
128 | 0 | return makeJobContext(conf, jobContext.getJobID()); |
129 | } | |
130 | ||
131 | /** | |
132 | * Create a JobContext, supporting many Hadoops. | |
133 | * | |
134 | * @param conf Configuration | |
135 | * @return JobContext | |
136 | */ | |
137 | public static JobContext makeJobContext(Configuration conf) { | |
138 | 0 | return makeJobContext(conf, new JobID()); |
139 | } | |
140 | ||
141 | /** | |
142 | * Create a JobContext, supporting many Hadoops. | |
143 | * | |
144 | * @return JobContext | |
145 | */ | |
146 | public static JobContext makeJobContext() { | |
147 | 0 | return makeJobContext(new Configuration()); |
148 | } | |
149 | } |