Database Reference
In-Depth Information
public class
MissingTemperatureFields
extends
Configured
implements
Tool
{
@Override
public
int
run
(
String
[]
args
)
throws
Exception
{
if
(
args
.
length
!=
1
) {
JobBuilder
.
printUsage
(
this
,
"<job ID>"
);
return
-
1
;
}
String jobID
=
args
[
0
];
Cluster cluster
=
new
Cluster
(
getConf
());
Job job
=
cluster
.
getJob
(
JobID
.
forName
(
jobID
));
if
(
job
==
null
) {
System
.
err
.
printf
(
"No job with ID %s found.\n"
,
jobID
);
return
-
1
;
}
if
(!
job
.
isComplete
()) {
System
.
err
.
printf
(
"Job %s is not complete.\n"
,
jobID
);
return
-
1
;
}
Counters counters
=
job
.
getCounters
();
long
missing
=
counters
.
findCounter
(
MaxTemperatureWithCounters
.
Temperature
.
MISSING
).
getValue
();
long
total
=
counters
.
findCounter
(
TaskCounter
.
MAP_INPUT_RECORDS
).
getValue
();
System
.
out
.
printf
(
"Records with missing temperature fields:
%.2f%%\n"
,
100.0
*
missing
/
total
);
return
0
;
}
public static
void
main
(
String
[]
args
)
throws
Exception
{
int
exitCode
=
ToolRunner
.
run
(
new
MissingTemperatureFields
(),
args
);
System
.
exit
(
exitCode
);
}
}
First we retrieve a
Job
object from a
Cluster
by calling the
getJob()
method with
the job ID. We check whether there is actually a job with the given ID by checking if it is
null
. There may not be, either because the ID was incorrectly specified or because the
job is no longer in the job history.