use of org.apache.pig.tools.pigstats.PigStats in project oozie by apache.
the class PigMain method runPigJob.
/**
* Runs the pig script using PigRunner. Embedded pig within python is also supported.
*
* @param args pig command line arguments
* @param pigLog pig log file
* @param resetSecurityManager specify if need to reset security manager
* @param retrieveStats specify if stats are to be retrieved
* @throws Exception in case of error during Pig execution
*/
protected void runPigJob(String[] args, String pigLog, boolean resetSecurityManager, boolean retrieveStats) throws Exception {
PigStats stats = PigRunner.run(args, null);
String jobIds = getHadoopJobIds(stats);
if (jobIds != null && !jobIds.isEmpty()) {
System.out.println("Hadoop Job IDs executed by Pig: " + jobIds);
File f = new File(System.getProperty(EXTERNAL_CHILD_IDS));
writeExternalData(jobIds, f);
}
if (!stats.isSuccessful()) {
if (pigLog != null) {
handleError(pigLog);
}
throw new LauncherMainException(PigRunner.ReturnCode.FAILURE);
} else {
// return
if (resetSecurityManager) {
return;
}
// configuration
if (retrieveStats) {
ActionStats pigStats;
String JSONString;
try {
pigStats = new OoziePigStats(stats);
JSONString = pigStats.toJSON();
} catch (UnsupportedOperationException uoe) {
throw new UnsupportedOperationException("Pig stats are not supported for this type of operation", uoe);
}
File f = new File(System.getProperty(EXTERNAL_ACTION_STATS));
writeExternalData(JSONString, f);
}
}
}
use of org.apache.pig.tools.pigstats.PigStats in project oozie by apache.
the class PigMain method getHadoopJobIds.
/**
* Get Hadoop Ids through PigStats API
*
* @param pigStats stats object obtained through PigStats API
* @return comma-separated String
*/
protected String getHadoopJobIds(PigStats pigStats) {
StringBuilder sb = new StringBuilder(STRING_BUFFER_SIZE);
String separator = ",";
// comma separated string
try {
PigStats.JobGraph jobGraph = pigStats.getJobGraph();
for (JobStats jobStats : jobGraph) {
String hadoopJobId = jobStats.getJobId();
if (StringUtils.isEmpty(hadoopJobId) || hadoopJobId.trim().equalsIgnoreCase("NULL")) {
continue;
}
if (sb.length() > 0) {
sb.append(separator);
}
sb.append(hadoopJobId);
}
}// Return null if Pig API's are not supported
catch (UnsupportedOperationException uoe) {
return null;
}
return sb.toString();
}
use of org.apache.pig.tools.pigstats.PigStats in project oozie by apache.
the class PigTestCase method resetPigStats.
/**
* PigStats is a singleton, so it gets persisted between unit tests that run different Pig jobs that run PigMain. Unfortunetly,
* there isn't a clean way to reset it. Pig v 0.9 has a set method which we can pass null to in order to reset the PigStats.
* However, this was changed in Pig v 0.13 to the start method. In either case, they're both package private, so we have to use
* reflection to find the existing method for whichever version of Pig we're using and make it public.
*
* This should be called when tearing down any unit test that runs PigMain.
*
* @throws Exception
*/
static void resetPigStats() throws Exception {
Method m = null;
try {
System.out.println("Attempting to reset PigStats via 'set' method");
m = PigStats.class.getDeclaredMethod("set", PigStats.class);
} catch (NoSuchMethodException e1) {
try {
System.out.println("Attempting to reset PigStats via 'start' method");
m = PigStats.class.getDeclaredMethod("start", PigStats.class);
} catch (NoSuchMethodException e2) {
System.out.println("WARNING: Unable to reset PigStats. This may cause test failures.");
}
}
if (m != null) {
m.setAccessible(true);
m.invoke(null, (PigStats) null);
}
}
Aggregations