You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@oozie.apache.org by an...@apache.org on 2011/12/10 05:15:18 UTC
svn commit: r1212728 - in /incubator/oozie/trunk/core/src:
main/java/org/apache/oozie/action/hadoop/ main/resources/
test/java/org/apache/oozie/action/hadoop/
Author: angeloh
Date: Sat Dec 10 04:15:17 2011
New Revision: 1212728
URL: http://svn.apache.org/viewvc?rev=1212728&view=rev
Log:
OOZIE-588 Oozie to allow drill down to hadoop job's details [Virag Kothari via angeloh]
Added:
incubator/oozie/trunk/core/src/main/java/org/apache/oozie/action/hadoop/OoziePigStats.java
Modified:
incubator/oozie/trunk/core/src/main/java/org/apache/oozie/action/hadoop/JavaActionExecutor.java
incubator/oozie/trunk/core/src/main/java/org/apache/oozie/action/hadoop/LauncherMapper.java
incubator/oozie/trunk/core/src/main/java/org/apache/oozie/action/hadoop/PigActionExecutor.java
incubator/oozie/trunk/core/src/main/java/org/apache/oozie/action/hadoop/PigMain.java
incubator/oozie/trunk/core/src/main/resources/oozie-default.xml
incubator/oozie/trunk/core/src/test/java/org/apache/oozie/action/hadoop/PigTestCase.java
incubator/oozie/trunk/core/src/test/java/org/apache/oozie/action/hadoop/TestJavaActionExecutor.java
incubator/oozie/trunk/core/src/test/java/org/apache/oozie/action/hadoop/TestPigActionExecutor.java
incubator/oozie/trunk/core/src/test/java/org/apache/oozie/action/hadoop/TestPigMain.java
Modified: incubator/oozie/trunk/core/src/main/java/org/apache/oozie/action/hadoop/JavaActionExecutor.java
URL: http://svn.apache.org/viewvc/incubator/oozie/trunk/core/src/main/java/org/apache/oozie/action/hadoop/JavaActionExecutor.java?rev=1212728&r1=1212727&r2=1212728&view=diff
==============================================================================
--- incubator/oozie/trunk/core/src/main/java/org/apache/oozie/action/hadoop/JavaActionExecutor.java (original)
+++ incubator/oozie/trunk/core/src/main/java/org/apache/oozie/action/hadoop/JavaActionExecutor.java Sat Dec 10 04:15:17 2011
@@ -6,9 +6,9 @@
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -27,6 +27,7 @@ import java.io.InputStreamReader;
import java.io.StringReader;
import java.net.ConnectException;
import java.net.URI;
+import java.net.URISyntaxException;
import java.net.UnknownHostException;
import java.util.ArrayList;
import java.util.HashMap;
@@ -76,10 +77,11 @@ public class JavaActionExecutor extends
private static final String HADOOP_UGI = "hadoop.job.ugi";
private static final String HADOOP_JOB_TRACKER = "mapred.job.tracker";
private static final String HADOOP_NAME_NODE = "fs.default.name";
-
+ public static final int MAX_EXTERNAL_STATS_SIZE_DEFAULT = Integer.MAX_VALUE;
private static final Set<String> DISALLOWED_PROPERTIES = new HashSet<String>();
-
+ public final static String MAX_EXTERNAL_STATS_SIZE = "oozie.external.stats.max.size";
private static int maxActionOutputLen;
+ private static int maxExternalStatsSize;
private static final String SUCCEEDED = "SUCCEEDED";
private static final String KILLED = "KILLED";
@@ -115,6 +117,8 @@ public class JavaActionExecutor extends
classes.add(LauncherSecurityManager.class);
classes.add(LauncherException.class);
classes.add(LauncherMainException.class);
+ classes.add(ActionStats.class);
+ classes.add(ActionType.class);
return classes;
}
@@ -122,6 +126,9 @@ public class JavaActionExecutor extends
public void initActionType() {
super.initActionType();
maxActionOutputLen = getOozieConf().getInt(CallbackServlet.CONF_MAX_DATA_LEN, 2 * 1024);
+ //Get the limit for the maximum allowed size of action stats
+ maxExternalStatsSize = getOozieConf().getInt(JavaActionExecutor.MAX_EXTERNAL_STATS_SIZE, MAX_EXTERNAL_STATS_SIZE_DEFAULT);
+ maxExternalStatsSize = (maxExternalStatsSize == -1) ? Integer.MAX_VALUE : maxExternalStatsSize;
try {
List<Class> classes = getLauncherClasses();
Class[] launcherClasses = classes.toArray(new Class[classes.size()]);
@@ -146,6 +153,15 @@ public class JavaActionExecutor extends
}
}
+ /**
+ * Get the maximum allowed size of stats
+ *
+ * @return maximum size of stats
+ */
+ public static int getMaxExternalStatsSize() {
+ return maxExternalStatsSize;
+ }
+
void checkForDisallowedProps(Configuration conf, String confName) throws ActionExecutorException {
for (String prop : DISALLOWED_PROPERTIES) {
if (conf.get(prop) != null) {
@@ -416,7 +432,7 @@ public class JavaActionExecutor extends
// Oozie sharelib (for the action)
addActionShareLib(context, actionXml, appPath, conf);
- }
+ }
protected String getLauncherMain(Configuration launcherConf, Element actionXml) {
Namespace ns = actionXml.getNamespace();
@@ -471,6 +487,7 @@ public class JavaActionExecutor extends
LauncherMapper.setupMainClass(launcherJobConf, getLauncherMain(launcherConf, actionXml));
LauncherMapper.setupMaxOutputData(launcherJobConf, maxActionOutputLen);
+ LauncherMapper.setupMaxExternalStatsSize(launcherJobConf, maxExternalStatsSize);
Namespace ns = actionXml.getNamespace();
List<Element> list = actionXml.getChildren("arg", ns);
@@ -882,18 +899,7 @@ public class JavaActionExecutor extends
XLog.getLog(getClass()).info(XLog.STD, "action completed, external ID [{0}]",
action.getExternalId());
if (runningJob.isSuccessful() && LauncherMapper.isMainSuccessful(runningJob)) {
- Properties props = null;
- if (getCaptureOutput(action)) {
- props = new Properties();
- if (LauncherMapper.hasOutputData(runningJob)) {
- Path actionOutput = LauncherMapper.getOutputDataPath(context.getActionDir());
- InputStream is = actionFs.open(actionOutput);
- BufferedReader reader = new BufferedReader(new InputStreamReader(is));
- props = PropertiesUtils.readProperties(reader, maxActionOutputLen);
- reader.close();
- }
- }
- context.setExecutionData(SUCCEEDED, props);
+ getActionData(actionFs, runningJob, action, context);
XLog.getLog(getClass()).info(XLog.STD, "action produced output");
}
else {
@@ -964,6 +970,32 @@ public class JavaActionExecutor extends
}
}
+ /**
+ * Get the output data of an action. Subclasses should override this method
+ * to get action specific output data.
+ *
+ * @param actionFs the FileSystem object
+ * @param runningJob the runningJob
+ * @param action the Workflow action
+ * @param context executor context
+ *
+ */
+ protected void getActionData(FileSystem actionFs, RunningJob runningJob, WorkflowAction action, Context context)
+ throws HadoopAccessorException, JDOMException, IOException, URISyntaxException {
+ Properties props = null;
+ if (getCaptureOutput(action)) {
+ props = new Properties();
+ if (LauncherMapper.hasOutputData(runningJob)) {
+ Path actionOutput = LauncherMapper.getOutputDataPath(context.getActionDir());
+ InputStream is = actionFs.open(actionOutput);
+ BufferedReader reader = new BufferedReader(new InputStreamReader(is));
+ props = PropertiesUtils.readProperties(reader, maxActionOutputLen);
+ reader.close();
+ }
+ }
+ context.setExecutionData(SUCCEEDED, props);
+ }
+
protected boolean getCaptureOutput(WorkflowAction action) throws JDOMException {
Element eConf = XmlUtils.parseXml(action.getConf());
Namespace ns = eConf.getNamespace();
Modified: incubator/oozie/trunk/core/src/main/java/org/apache/oozie/action/hadoop/LauncherMapper.java
URL: http://svn.apache.org/viewvc/incubator/oozie/trunk/core/src/main/java/org/apache/oozie/action/hadoop/LauncherMapper.java?rev=1212728&r1=1212727&r2=1212728&view=diff
==============================================================================
--- incubator/oozie/trunk/core/src/main/java/org/apache/oozie/action/hadoop/LauncherMapper.java (original)
+++ incubator/oozie/trunk/core/src/main/java/org/apache/oozie/action/hadoop/LauncherMapper.java Sat Dec 10 04:15:17 2011
@@ -6,9 +6,9 @@
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -58,10 +58,12 @@ public class LauncherMapper<K1, V1, K2,
private static final String CONF_OOZIE_ACTION_MAIN_ARG_COUNT = "oozie.action.main.arg.count";
private static final String CONF_OOZIE_ACTION_MAIN_ARG_PREFIX = "oozie.action.main.arg.";
private static final String CONF_OOZIE_ACTION_MAX_OUTPUT_DATA = "oozie.action.max.output.data";
+ private static final String CONF_OOZIE_EXTERNAL_STATS_MAX_SIZE = "oozie.external.stats.max.size";
private static final String COUNTER_GROUP = "oozie.launcher";
private static final String COUNTER_DO_ID_SWAP = "oozie.do.id.swap";
private static final String COUNTER_OUTPUT_DATA = "oozie.output.data";
+ private static final String COUNTER_STATS_DATA = "oozie.stats.data";
private static final String COUNTER_LAUNCHER_ERROR = "oozie.launcher.error";
private static final String OOZIE_JOB_ID = "oozie.job.id";
@@ -70,8 +72,14 @@ public class LauncherMapper<K1, V1, K2,
private static final String OOZIE_ACTION_DIR_PATH = "oozie.action.dir.path";
private static final String OOZIE_ACTION_RECOVERY_ID = "oozie.action.recovery.id";
+ public static final String ACTION_PREFIX = "oozie.action.";
+ public static final String EXTERNAL_CHILD_IDS = ACTION_PREFIX + "externalChildIDs.properties";
+ public static final String EXTERNAL_ACTION_STATS = ACTION_PREFIX + "stats.properties";
+
static final String ACTION_CONF_XML = "action.xml";
private static final String ACTION_OUTPUT_PROPS = "output.properties";
+ private static final String ACTION_STATS_PROPS = "stats.properties";
+ private static final String ACTION_EXTERNAL_CHILD_IDS_PROPS = "externalChildIds.properties";
private static final String ACTION_NEW_ID_PROPS = "newId.properties";
private static final String ACTION_ERROR_PROPS = "error.properties";
@@ -151,6 +159,16 @@ public class LauncherMapper<K1, V1, K2,
}
/**
+ * Set the maximum value of stats data
+ *
+ * @param launcherConf the oozie launcher configuration
+ * @param maxStatsData the maximum allowed size of stats data
+ */
+ public static void setupMaxExternalStatsSize(Configuration launcherConf, int maxStatsData){
+ launcherConf.setInt(CONF_OOZIE_EXTERNAL_STATS_MAX_SIZE, maxStatsData);
+ }
+
+ /**
* @param launcherConf
* @param jobId
* @param actionId
@@ -225,6 +243,25 @@ public class LauncherMapper<K1, V1, K2,
}
/**
+ * Check whether runningJob has stats data or not
+ *
+ * @param runningJob the runningJob
+ * @return returns whether the running Job has stats data or not
+ * @throws IOException
+ */
+ public static boolean hasStatsData(RunningJob runningJob) throws IOException{
+ boolean output = false;
+ Counters counters = runningJob.getCounters();
+ if (counters != null) {
+ Counters.Group group = counters.getGroup(COUNTER_GROUP);
+ if (group != null) {
+ output = group.getCounter(COUNTER_STATS_DATA) == 1;
+ }
+ }
+ return output;
+ }
+
+ /**
* @param runningJob
* @return
* @throws IOException
@@ -289,6 +326,26 @@ public class LauncherMapper<K1, V1, K2,
return new Path(actionDir, ACTION_OUTPUT_PROPS);
}
+ /**
+ * Get the location of stats file
+ *
+ * @param actionDir the action directory
+ * @return the hdfs location of the file
+ */
+ public static Path getActionStatsDataPath(Path actionDir){
+ return new Path(actionDir, ACTION_STATS_PROPS);
+ }
+
+ /**
+ * Get the location of external Child IDs file
+ *
+ * @param actionDir the action directory
+ * @return the hdfs location of the file
+ */
+ public static Path getExternalChildIDsDataPath(Path actionDir){
+ return new Path(actionDir, ACTION_EXTERNAL_CHILD_IDS_PROPS);
+ }
+
public static Path getErrorPath(Path actionDir) {
return new Path(actionDir, ACTION_ERROR_PROPS);
}
@@ -306,6 +363,7 @@ public class LauncherMapper<K1, V1, K2,
public LauncherMapper() {
}
+ @Override
public void configure(JobConf jobConf) {
System.out.println();
System.out.println("Oozie Launcher starts");
@@ -321,6 +379,7 @@ public class LauncherMapper<K1, V1, K2,
}
}
+ @Override
public void map(K1 key, V1 value, OutputCollector<K2, V2> collector, Reporter reporter) throws IOException {
try {
if (configFailure) {
@@ -395,7 +454,7 @@ public class LauncherMapper<K1, V1, K2,
}
catch (InvocationTargetException ex) {
if (LauncherMainException.class.isInstance(ex.getCause())) {
- errorMessage = msgPrefix + "exit code [" +((LauncherMainException)ex.getCause()).getErrorCode()
+ errorMessage = msgPrefix + "exit code [" +((LauncherMainException)ex.getCause()).getErrorCode()
+ "]";
errorCause = null;
}
@@ -425,8 +484,9 @@ public class LauncherMapper<K1, V1, K2,
}
if (errorMessage == null) {
File outputData = new File(System.getProperty("oozie.action.output.properties"));
+ FileSystem fs = FileSystem.get(getJobConf());
if (outputData.exists()) {
- FileSystem fs = FileSystem.get(getJobConf());
+
fs.copyFromLocalFile(new Path(outputData.toString()), new Path(actionDir,
ACTION_OUTPUT_PROPS));
reporter.incrCounter(COUNTER_GROUP, COUNTER_OUTPUT_DATA, 1);
@@ -447,6 +507,8 @@ public class LauncherMapper<K1, V1, K2,
System.out.println("=======================");
System.out.println();
}
+ handleActionStatsData(fs, reporter);
+ handleExternalChildIDs(fs, reporter);
File newId = new File(System.getProperty("oozie.action.newId.properties"));
if (newId.exists()) {
Properties props = new Properties();
@@ -454,7 +516,7 @@ public class LauncherMapper<K1, V1, K2,
if (props.getProperty("id") == null) {
throw new IllegalStateException("ID swap file does not have [id] property");
}
- FileSystem fs = FileSystem.get(getJobConf());
+ fs = FileSystem.get(getJobConf());
fs.copyFromLocalFile(new Path(newId.toString()), new Path(actionDir, ACTION_NEW_ID_PROPS));
reporter.incrCounter(COUNTER_GROUP, COUNTER_DO_ID_SWAP, 1);
@@ -498,6 +560,7 @@ public class LauncherMapper<K1, V1, K2,
}
}
+ @Override
public void close() throws IOException {
System.out.println();
System.out.println("Oozie Launcher ends");
@@ -508,6 +571,35 @@ public class LauncherMapper<K1, V1, K2,
return jobConf;
}
+ private void handleActionStatsData(FileSystem fs, Reporter reporter) throws IOException, LauncherException{
+ File actionStatsData = new File(System.getProperty(EXTERNAL_ACTION_STATS));
+ // If stats are stored by the action, then stats file should exist
+ if (actionStatsData.exists()) {
+ int statsMaxOutputData = getJobConf().getInt(CONF_OOZIE_EXTERNAL_STATS_MAX_SIZE,
+ Integer.MAX_VALUE);
+ reporter.incrCounter(COUNTER_GROUP, COUNTER_STATS_DATA, 1);
+ // fail the launcher if size of stats is greater than the maximum allowed size
+ if (actionStatsData.length() > statsMaxOutputData) {
+ String msg = MessageFormat.format("Output stats size [{0}] exceeds maximum [{1}]",
+ actionStatsData.length(), statsMaxOutputData);
+ failLauncher(0, msg, null);
+ }
+ // copy the stats file to hdfs path which can be accessed by Oozie server
+ fs.copyFromLocalFile(new Path(actionStatsData.toString()), new Path(actionDir,
+ ACTION_STATS_PROPS));
+ }
+ }
+
+ private void handleExternalChildIDs(FileSystem fs, Reporter reporter) throws IOException {
+ File externalChildIDs = new File(System.getProperty(EXTERNAL_CHILD_IDS));
+ // if external ChildIDs are stored by the action, then the file should exist
+ if (externalChildIDs.exists()) {
+ // copy the externalChildIDs file to hdfs path which can be accessed by Oozie server
+ fs.copyFromLocalFile(new Path(externalChildIDs.toString()), new Path(actionDir,
+ ACTION_EXTERNAL_CHILD_IDS_PROPS));
+ }
+ }
+
private void setupMainConfiguration() throws IOException {
FileSystem fs = FileSystem.get(getJobConf());
fs.copyToLocalFile(new Path(getJobConf().get(OOZIE_ACTION_DIR_PATH), ACTION_CONF_XML), new Path(new File(
@@ -518,6 +610,8 @@ public class LauncherMapper<K1, V1, K2,
System.setProperty("oozie.action.id", getJobConf().get(OOZIE_ACTION_ID));
System.setProperty("oozie.action.conf.xml", new File(ACTION_CONF_XML).getAbsolutePath());
System.setProperty("oozie.action.output.properties", new File(ACTION_OUTPUT_PROPS).getAbsolutePath());
+ System.setProperty(EXTERNAL_ACTION_STATS, new File(ACTION_STATS_PROPS).getAbsolutePath());
+ System.setProperty(EXTERNAL_CHILD_IDS, new File(ACTION_EXTERNAL_CHILD_IDS_PROPS).getAbsolutePath());
System.setProperty("oozie.action.newId.properties", new File(ACTION_NEW_ID_PROPS).getAbsolutePath());
}
@@ -544,6 +638,7 @@ public class LauncherMapper<K1, V1, K2,
this.reporter = reporter;
}
+ @Override
public void run() {
System.out.println("Heart beat");
reporter.progress();
Added: incubator/oozie/trunk/core/src/main/java/org/apache/oozie/action/hadoop/OoziePigStats.java
URL: http://svn.apache.org/viewvc/incubator/oozie/trunk/core/src/main/java/org/apache/oozie/action/hadoop/OoziePigStats.java?rev=1212728&view=auto
==============================================================================
--- incubator/oozie/trunk/core/src/main/java/org/apache/oozie/action/hadoop/OoziePigStats.java (added)
+++ incubator/oozie/trunk/core/src/main/java/org/apache/oozie/action/hadoop/OoziePigStats.java Sat Dec 10 04:15:17 2011
@@ -0,0 +1,160 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.oozie.action.hadoop;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.hadoop.mapred.Counters;
+import org.apache.hadoop.mapred.Counters.Counter;
+import org.apache.oozie.util.ParamChecker;
+import org.apache.pig.tools.pigstats.JobStats;
+import org.apache.pig.tools.pigstats.PigStats;
+import org.apache.pig.tools.pigstats.PigStatsUtil;
+import org.json.simple.JSONObject;
+
+/**
+ * Class to collect the Pig statistics for a Pig action
+ *
+ */
+public class OoziePigStats extends ActionStats {
+ PigStats pigStats = null;
+
+ public OoziePigStats(PigStats pigStats) {
+ this.currentActionType = ActionType.PIG;
+ this.pigStats = pigStats;
+ }
+
+ /**
+ * The PigStats API is used to collect the statistics and the result is returned as a JSON String.
+ *
+ * @return a JSON string
+ */
+ @SuppressWarnings("unchecked")
+ @Override
+ public String toJSON() {
+ JSONObject pigStatsGroup = new JSONObject();
+ pigStatsGroup.put("ACTION_TYPE", getCurrentActionType().toString());
+
+ // pig summary related counters
+ pigStatsGroup.put("BYTES_WRITTEN", Long.toString(pigStats.getBytesWritten()));
+ pigStatsGroup.put("DURATION", Long.toString(pigStats.getDuration()));
+ pigStatsGroup.put("ERROR_CODE", Long.toString(pigStats.getErrorCode()));
+ pigStatsGroup.put("ERROR_MESSAGE", pigStats.getErrorMessage());
+ pigStatsGroup.put("FEATURES", pigStats.getFeatures());
+ pigStatsGroup.put("HADOOP_VERSION", pigStats.getHadoopVersion());
+ pigStatsGroup.put("NUMBER_JOBS", Long.toString(pigStats.getNumberJobs()));
+ pigStatsGroup.put("PIG_VERSION", pigStats.getPigVersion());
+ pigStatsGroup.put("PROACTIVE_SPILL_COUNT_OBJECTS", Long.toString(pigStats.getProactiveSpillCountObjects()));
+ pigStatsGroup.put("PROACTIVE_SPILL_COUNT_RECORDS", Long.toString(pigStats.getProactiveSpillCountRecords()));
+ pigStatsGroup.put("RECORD_WRITTEN", Long.toString(pigStats.getRecordWritten()));
+ pigStatsGroup.put("RETURN_CODE", Long.toString(pigStats.getReturnCode()));
+ pigStatsGroup.put("SCRIPT_ID", pigStats.getScriptId());
+ pigStatsGroup.put("SMM_SPILL_COUNT", Long.toString(pigStats.getSMMSpillCount()));
+
+ PigStats.JobGraph jobGraph = pigStats.getJobGraph();
+ StringBuffer sb = new StringBuffer();
+ String separator = ",";
+
+ for (JobStats jobStats : jobGraph) {
+ // Get all the HadoopIds and put them as comma separated string for JOB_GRAPH
+ String hadoopId = jobStats.getJobId();
+ if (sb.length() > 0) {
+ sb.append(separator);
+ }
+ sb.append(hadoopId);
+ // Hadoop Counters for pig created MR job
+ pigStatsGroup.put(hadoopId, toJSONFromJobStats(jobStats));
+ }
+ pigStatsGroup.put("JOB_GRAPH", sb.toString());
+ return pigStatsGroup.toJSONString();
+ }
+
+ // MR job related counters
+ @SuppressWarnings("unchecked")
+ private static JSONObject toJSONFromJobStats(JobStats jobStats) {
+ JSONObject jobStatsGroup = new JSONObject();
+
+ // hadoop counters
+ jobStatsGroup.put(PigStatsUtil.HDFS_BYTES_WRITTEN, Long.toString(jobStats.getHdfsBytesWritten()));
+ jobStatsGroup.put(PigStatsUtil.MAP_INPUT_RECORDS, Long.toString(jobStats.getMapInputRecords()));
+ jobStatsGroup.put(PigStatsUtil.MAP_OUTPUT_RECORDS, Long.toString(jobStats.getMapOutputRecords()));
+ jobStatsGroup.put(PigStatsUtil.REDUCE_INPUT_RECORDS, Long.toString(jobStats.getReduceInputRecords()));
+ jobStatsGroup.put(PigStatsUtil.REDUCE_OUTPUT_RECORDS, Long.toString(jobStats.getReduceOutputRecords()));
+ // currently returns null; pig bug
+ jobStatsGroup.put("HADOOP_COUNTERS", toJSONFromCounters(jobStats.getHadoopCounters()));
+
+ // pig generated hadoop counters and other stats
+ jobStatsGroup.put("Alias", jobStats.getAlias());
+ jobStatsGroup.put("AVG_MAP_TIME", Long.toString(jobStats.getAvgMapTime()));
+ jobStatsGroup.put("AVG_REDUCE_TIME", Long.toString(jobStats.getAvgREduceTime()));
+ jobStatsGroup.put("BYTES_WRITTEN", Long.toString(jobStats.getBytesWritten()));
+ jobStatsGroup.put("ERROR_MESSAGE", jobStats.getErrorMessage());
+ jobStatsGroup.put("FEATURE", jobStats.getFeature());
+ jobStatsGroup.put("JOB_ID", jobStats.getJobId());
+ jobStatsGroup.put("MAX_MAP_TIME", Long.toString(jobStats.getMaxMapTime()));
+ jobStatsGroup.put("MIN_MAP_TIME", Long.toString(jobStats.getMinMapTime()));
+ jobStatsGroup.put("MAX_REDUCE_TIME", Long.toString(jobStats.getMaxReduceTime()));
+ jobStatsGroup.put("MIN_REDUCE_TIME", Long.toString(jobStats.getMinReduceTime()));
+ jobStatsGroup.put("NUMBER_MAPS", Long.toString(jobStats.getNumberMaps()));
+ jobStatsGroup.put("NUMBER_REDUCES", Long.toString(jobStats.getNumberReduces()));
+ jobStatsGroup.put("PROACTIVE_SPILL_COUNT_OBJECTS", Long.toString(jobStats.getProactiveSpillCountObjects()));
+ jobStatsGroup.put("PROACTIVE_SPILL_COUNT_RECS", Long.toString(jobStats.getProactiveSpillCountRecs()));
+ jobStatsGroup.put("RECORD_WRITTEN", Long.toString(jobStats.getRecordWrittern()));
+ jobStatsGroup.put("SMMS_SPILL_COUNT", Long.toString(jobStats.getSMMSpillCount()));
+ jobStatsGroup.put("MULTI_STORE_COUNTERS", toJSONFromMultiStoreCounters(jobStats.getMultiStoreCounters()));
+
+ return jobStatsGroup;
+
+ }
+
+ // multistorecounters to JSON
+ @SuppressWarnings("unchecked")
+ private static JSONObject toJSONFromMultiStoreCounters(Map<String, Long> map) {
+ JSONObject group = new JSONObject();
+ for (String cName : map.keySet()) {
+ group.put(cName, map.get(cName));
+ }
+ return group;
+
+ }
+
+ // hadoop counters to JSON
+ @SuppressWarnings("unchecked")
+ private static JSONObject toJSONFromCounters(Counters counters) {
+ if (counters == null) {
+ return null;
+ }
+
+ JSONObject groups = new JSONObject();
+ for (String gName : counters.getGroupNames()) {
+ JSONObject group = new JSONObject();
+ for (Counter counter : counters.getGroup(gName)) {
+ String cName = counter.getName();
+ Long cValue = counter.getValue();
+ group.put(cName, Long.toString(cValue));
+ }
+ groups.put(gName, group);
+ }
+ return groups;
+
+ }
+
+}
Modified: incubator/oozie/trunk/core/src/main/java/org/apache/oozie/action/hadoop/PigActionExecutor.java
URL: http://svn.apache.org/viewvc/incubator/oozie/trunk/core/src/main/java/org/apache/oozie/action/hadoop/PigActionExecutor.java?rev=1212728&r1=1212727&r2=1212728&view=diff
==============================================================================
--- incubator/oozie/trunk/core/src/main/java/org/apache/oozie/action/hadoop/PigActionExecutor.java (original)
+++ incubator/oozie/trunk/core/src/main/java/org/apache/oozie/action/hadoop/PigActionExecutor.java Sat Dec 10 04:15:17 2011
@@ -6,9 +6,9 @@
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -21,9 +21,13 @@ import org.apache.hadoop.conf.Configurat
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.FSDataOutputStream;
import org.apache.hadoop.fs.Path;
+import org.apache.hadoop.mapred.RunningJob;
import org.apache.oozie.action.ActionExecutorException;
import org.apache.oozie.client.XOozieClient;
import org.apache.oozie.client.WorkflowAction;
+import org.apache.oozie.service.HadoopAccessorException;
+import org.apache.oozie.util.ClassUtils;
+import org.apache.oozie.util.IOUtils;
import org.apache.oozie.util.XLog;
import org.apache.oozie.util.XmlUtils;
import org.jdom.Element;
@@ -31,7 +35,11 @@ import org.jdom.Namespace;
import org.jdom.JDOMException;
import org.mortbay.log.Log;
+import java.io.BufferedReader;
import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.net.URISyntaxException;
import java.util.List;
public class PigActionExecutor extends JavaActionExecutor {
@@ -40,18 +48,23 @@ public class PigActionExecutor extends J
super("pig");
}
+ @Override
protected List<Class> getLauncherClasses() {
List<Class> classes = super.getLauncherClasses();
classes.add(LauncherMain.class);
classes.add(MapReduceMain.class);
classes.add(PigMain.class);
+ classes.add(OoziePigStats.class);
return classes;
}
+
+ @Override
protected String getLauncherMain(Configuration launcherConf, Element actionXml) {
return launcherConf.get(LauncherMapper.CONF_OOZIE_ACTION_MAIN_CLASS, PigMain.class.getName());
}
+ @Override
void injectActionCallback(Context context, Configuration launcherConf) {
}
@@ -99,6 +112,7 @@ public class PigActionExecutor extends J
return conf;
}
+ @Override
@SuppressWarnings("unchecked")
Configuration setupActionConf(Configuration actionConf, Context context, Element actionXml, Path appPath)
throws ActionExecutorException {
@@ -125,8 +139,65 @@ public class PigActionExecutor extends J
return actionConf;
}
+ @Override
protected boolean getCaptureOutput(WorkflowAction action) throws JDOMException {
- return true;
+ return false;
+ }
+
+ /**
+ * Get the stats and external child IDs for a pig job
+ *
+ * @param actionFs the FileSystem object
+ * @param runningJob the runningJob
+ * @param action the Workflow action
+ * @param context executor context
+ *
+ */
+ @Override
+ protected void getActionData(FileSystem actionFs, RunningJob runningJob, WorkflowAction action, Context context) throws HadoopAccessorException, JDOMException, IOException, URISyntaxException{
+ super.getActionData(actionFs, runningJob, action, context);
+ String stats = getStats(context, actionFs);
+ context.setExecutionStats(stats);
+ String externalChildIDs = getExternalChildIDs(context, actionFs);
+ context.setExternalChildIDs(externalChildIDs);
+ }
+
+ private String getStats(Context context, FileSystem actionFs) throws IOException, HadoopAccessorException,
+ URISyntaxException {
+ Path actionOutput = LauncherMapper.getActionStatsDataPath(context.getActionDir());
+ String stats = null;
+ if (actionFs.exists(actionOutput)) {
+ stats = getDataFromPath(actionOutput, actionFs);
+
+ }
+ return stats;
+ }
+
+ private String getExternalChildIDs(Context context, FileSystem actionFs) throws IOException,
+ HadoopAccessorException, URISyntaxException {
+ Path actionOutput = LauncherMapper.getExternalChildIDsDataPath(context.getActionDir());
+ String externalIDs = null;
+ if (actionFs.exists(actionOutput)) {
+ externalIDs = getDataFromPath(actionOutput, actionFs);
+ }
+ return externalIDs;
+ }
+
+ private static String getDataFromPath(Path actionOutput, FileSystem actionFs) throws IOException{
+ BufferedReader reader = null;
+ String data = null;
+ try {
+ InputStream is = actionFs.open(actionOutput);
+ reader = new BufferedReader(new InputStreamReader(is));
+ data = IOUtils.getReaderAsString(reader, -1);
+
+ }
+ finally {
+ if (reader != null) {
+ reader.close();
+ }
+ }
+ return data;
}
/**
@@ -136,6 +207,7 @@ public class PigActionExecutor extends J
* @param actionXml the action XML.
* @return the action sharelib post fix, this implementation returns <code>pig</code>.
*/
+ @Override
protected String getShareLibPostFix(Context context, Element actionXml) {
return "pig";
}
Modified: incubator/oozie/trunk/core/src/main/java/org/apache/oozie/action/hadoop/PigMain.java
URL: http://svn.apache.org/viewvc/incubator/oozie/trunk/core/src/main/java/org/apache/oozie/action/hadoop/PigMain.java?rev=1212728&r1=1212727&r2=1212728&view=diff
==============================================================================
--- incubator/oozie/trunk/core/src/main/java/org/apache/oozie/action/hadoop/PigMain.java (original)
+++ incubator/oozie/trunk/core/src/main/java/org/apache/oozie/action/hadoop/PigMain.java Sat Dec 10 04:15:17 2011
@@ -19,11 +19,14 @@ package org.apache.oozie.action.hadoop;
import org.apache.pig.Main;
import org.apache.pig.PigRunner;
+import org.apache.pig.tools.pigstats.JobStats;
import org.apache.pig.tools.pigstats.PigStats;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
+import java.io.BufferedWriter;
import java.io.FileNotFoundException;
+import java.io.FileWriter;
import java.io.OutputStream;
import java.io.FileOutputStream;
import java.io.BufferedReader;
@@ -41,6 +44,11 @@ import java.net.URL;
public class PigMain extends LauncherMain {
private static final Set<String> DISALLOWED_PIG_OPTIONS = new HashSet<String>();
+ public static final String ACTION_PREFIX = "oozie.action.";
+ public static final String EXTERNAL_CHILD_IDS = ACTION_PREFIX + "externalChildIDs.properties";
+ public static final String EXTERNAL_ACTION_STATS = ACTION_PREFIX + "stats.properties";
+ public static final String EXTERNAL_STATS_WRITE = ACTION_PREFIX + "external.stats.write";
+ public static final int STRING_BUFFER_SIZE = 100;
static {
DISALLOWED_PIG_OPTIONS.add("-4");
@@ -202,26 +210,29 @@ public class PigMain extends LauncherMai
System.out.flush();
System.out.println();
- runPigJob(new String[] { "-version" }, null, true);
+ runPigJob(new String[] { "-version" }, null, true, false);
System.out.println();
System.out.flush();
-
- runPigJob(arguments.toArray(new String[arguments.size()]), pigLog, false);
+ boolean hasStats = Boolean.parseBoolean(actionConf.get(EXTERNAL_STATS_WRITE));
+ runPigJob(arguments.toArray(new String[arguments.size()]), pigLog, false, hasStats);
System.out.println();
System.out.println("<<< Invocation of Pig command completed <<<");
System.out.println();
- // harvesting and recording Hadoop Job IDs
- Properties jobIds = getHadoopJobIds(logFile);
- File file = new File(System.getProperty("oozie.action.output.properties"));
- os = new FileOutputStream(file);
- jobIds.store(os, "");
- os.close();
- System.out.println(" Hadoop Job IDs executed by Pig: " + jobIds.getProperty("hadoopJobs"));
- System.out.println();
+ // For embedded python or for version of pig lower than 0.8, pig stats are not supported.
+ // So retrieving hadoop Ids here
+ File file = new File(System.getProperty(EXTERNAL_CHILD_IDS));
+ if (!file.exists()) {
+ String jobIds = getHadoopJobIds(logFile);
+ writeExternalData(jobIds, file);
+ System.out.println(" Hadoop Job IDs executed by Pig: " + jobIds);
+ System.out.println();
+ }
}
+
+
private void handleError(String pigLog) throws Exception {
System.err.println();
System.err.println("Pig logfile dump:");
@@ -247,9 +258,10 @@ public class PigMain extends LauncherMai
* @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
*/
- protected void runPigJob(String[] args, String pigLog, boolean resetSecurityManager) throws Exception {
+ protected void runPigJob(String[] args, String pigLog, boolean resetSecurityManager, boolean retrieveStats) throws Exception {
// running as from the command line
boolean pigRunnerExists = true;
Class klass;
@@ -271,6 +283,34 @@ public class PigMain extends LauncherMai
}
throw new LauncherMainException(PigRunner.ReturnCode.FAILURE);
}
+ else {
+ // If pig command is ran with just the "version" option, then
+ // return
+ if (resetSecurityManager) {
+ return;
+ }
+ String jobIds = getHadoopJobIds(stats);
+ if (jobIds != null) {
+ System.out.println(" Hadoop Job IDs executed by Pig: " + jobIds);
+ File f = new File(System.getProperty(EXTERNAL_CHILD_IDS));
+ writeExternalData(jobIds, f);
+ }
+ // Retrieve stats only if user has specified in workflow
+ // 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);
+ }
+ }
}
else {
try {
@@ -295,6 +335,20 @@ public class PigMain extends LauncherMai
}
}
+ // write external data(stats, hadoopIds) to the file which will be read by the LauncherMapper
+ private static void writeExternalData(String data, File f) throws IOException {
+ BufferedWriter out = null;
+ try {
+ out = new BufferedWriter(new FileWriter(f));
+ out.write(data);
+ }
+ finally {
+ if (out != null) {
+ out.close();
+ }
+ }
+ }
+
public static void setPigScript(Configuration conf, String script, String[] params, String[] args) {
conf.set("oozie.pig.script", script);
MapReduceMain.setStrings(conf, "oozie.pig.params", params);
@@ -303,35 +357,67 @@ public class PigMain extends LauncherMai
private static final String JOB_ID_LOG_PREFIX = "HadoopJobId: ";
- protected Properties getHadoopJobIds(String logFile) throws IOException {
- int jobCount = 0;
- Properties props = new Properties();
- StringBuffer sb = new StringBuffer(100);
+ /**
+ * Get Hadoop Ids by parsing the log file
+ *
+ * @param logFile the pig log file
+ * @return comma-separated String
+ */
+ protected String getHadoopJobIds(String logFile) throws IOException {
+ StringBuilder sb = new StringBuilder(STRING_BUFFER_SIZE);
if (new File(logFile).exists() == false) {
System.err.println("pig log file: " + logFile + " not present. Therefore no Hadoop jobids found");
- props.setProperty("hadoopJobs", "");
+ return sb.toString();
}
- else {
- BufferedReader br = new BufferedReader(new FileReader(logFile));
- String line = br.readLine();
- String separator = "";
- while (line != null) {
- if (line.contains(JOB_ID_LOG_PREFIX)) {
- int jobIdStarts = line.indexOf(JOB_ID_LOG_PREFIX) + JOB_ID_LOG_PREFIX.length();
- String jobId = line.substring(jobIdStarts);
- int jobIdEnds = jobId.indexOf(" ");
- if (jobIdEnds > -1) {
- jobId = jobId.substring(0, jobId.indexOf(" "));
- }
- sb.append(separator).append(jobId);
- separator = ",";
+ BufferedReader br = new BufferedReader(new FileReader(logFile));
+ String line = br.readLine();
+ String separator = ",";
+ while (line != null) {
+ if (line.contains(JOB_ID_LOG_PREFIX)) {
+ int jobIdStarts = line.indexOf(JOB_ID_LOG_PREFIX) + JOB_ID_LOG_PREFIX.length();
+ String jobId = line.substring(jobIdStarts);
+ int jobIdEnds = jobId.indexOf(" ");
+ if (jobIdEnds > -1) {
+ jobId = jobId.substring(0, jobId.indexOf(" "));
+ }
+ if (sb.length() > 0) {
+ sb.append(separator);
+ }
+ sb.append(jobId);
+ }
+ line = br.readLine();
+ }
+ br.close();
+ return sb.toString();
+ }
+
+
+ /**
+ * 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 = ",";
+ // Collect Hadoop Ids through JobGraph API of Pig and store them as
+ // comma separated string
+ try {
+ PigStats.JobGraph jobGraph = pigStats.getJobGraph();
+ for (JobStats jobStats : jobGraph) {
+ String hadoopJobId = jobStats.getJobId();
+ if (sb.length() > 0) {
+ sb.append(separator);
}
- line = br.readLine();
+ sb.append(hadoopJobId);
}
- br.close();
- props.setProperty("hadoopJobs", sb.toString());
}
- return props;
+ // Return null if Pig API's are not supported
+ catch (UnsupportedOperationException uoe) {
+ return null;
+ }
+ return sb.toString();
}
}
Modified: incubator/oozie/trunk/core/src/main/resources/oozie-default.xml
URL: http://svn.apache.org/viewvc/incubator/oozie/trunk/core/src/main/resources/oozie-default.xml?rev=1212728&r1=1212727&r2=1212728&view=diff
==============================================================================
--- incubator/oozie/trunk/core/src/main/resources/oozie-default.xml (original)
+++ incubator/oozie/trunk/core/src/main/resources/oozie-default.xml Sat Dec 10 04:15:17 2011
@@ -1099,6 +1099,16 @@
</description>
</property>
+ <!-- External stats-->
+
+ <property>
+ <name>oozie.external.stats.max.size</name>
+ <value>-1</value>
+ <description>
+ Max size in bytes for action stats. -1 means infinite value.
+ </description>
+ </property>
+
<!-- JobCommand -->
<property>
Modified: incubator/oozie/trunk/core/src/test/java/org/apache/oozie/action/hadoop/PigTestCase.java
URL: http://svn.apache.org/viewvc/incubator/oozie/trunk/core/src/test/java/org/apache/oozie/action/hadoop/PigTestCase.java?rev=1212728&r1=1212727&r2=1212728&view=diff
==============================================================================
--- incubator/oozie/trunk/core/src/test/java/org/apache/oozie/action/hadoop/PigTestCase.java (original)
+++ incubator/oozie/trunk/core/src/test/java/org/apache/oozie/action/hadoop/PigTestCase.java Sat Dec 10 04:15:17 2011
@@ -35,14 +35,18 @@ import com.google.common.primitives.Bool
public abstract class PigTestCase extends XFsTestCase implements Callable<Void> {
protected static String pigScript;
+ protected static boolean writeStats;
private static String commonPigScript = "set job.name 'test'\n" +
"set debug on\n" +
"A = load '$IN' using PigStorage(':');\n" +
"B = foreach A generate $0 as id;\n" +
"store B into '$OUT' USING PigStorage();";
+
+
public void testPigScript() throws Exception {
pigScript = commonPigScript;
+ writeStats = true;
DoAs.call(getTestUser(), this);
}
@@ -78,6 +82,8 @@ public abstract class PigTestCase extend
+ "\noutput = " + "'"+outputDir.toUri().getPath()+"'"
+ "\nQ = P.bind({'IN':input, 'OUT':output})"
+ "\nQ.runSingle()";
+
+ writeStats = false;
DoAs.call(getTestUser(), this);
}
Modified: incubator/oozie/trunk/core/src/test/java/org/apache/oozie/action/hadoop/TestJavaActionExecutor.java
URL: http://svn.apache.org/viewvc/incubator/oozie/trunk/core/src/test/java/org/apache/oozie/action/hadoop/TestJavaActionExecutor.java?rev=1212728&r1=1212727&r2=1212728&view=diff
==============================================================================
--- incubator/oozie/trunk/core/src/test/java/org/apache/oozie/action/hadoop/TestJavaActionExecutor.java (original)
+++ incubator/oozie/trunk/core/src/test/java/org/apache/oozie/action/hadoop/TestJavaActionExecutor.java Sat Dec 10 04:15:17 2011
@@ -6,9 +6,9 @@
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -89,6 +89,8 @@ public class TestJavaActionExecutor exte
classes.add(LauncherSecurityManager.class);
classes.add(LauncherException.class);
classes.add(LauncherMainException.class);
+ classes.add(ActionStats.class);
+ classes.add(ActionType.class);
assertEquals(classes, ae.getLauncherClasses());
Configuration conf = new XConfiguration();
@@ -349,6 +351,7 @@ public class TestJavaActionExecutor exte
Context context = createContext(actionXml);
final RunningJob runningJob = submitAction(context);
waitFor(60 * 1000, new Predicate() {
+ @Override
public boolean evaluate() throws Exception {
return runningJob.isComplete();
}
@@ -374,6 +377,7 @@ public class TestJavaActionExecutor exte
Context context = createContext(actionXml);
final RunningJob runningJob = submitAction(context);
waitFor(60 * 1000, new Predicate() {
+ @Override
public boolean evaluate() throws Exception {
return runningJob.isComplete();
}
@@ -404,6 +408,7 @@ public class TestJavaActionExecutor exte
Context context = createContext(actionXml);
final RunningJob runningJob = submitAction(context);
waitFor(60 * 1000, new Predicate() {
+ @Override
public boolean evaluate() throws Exception {
return runningJob.isComplete();
}
@@ -440,6 +445,7 @@ public class TestJavaActionExecutor exte
ActionExecutor ae = new JavaActionExecutor();
assertFalse(ae.isCompleted(context.getAction().getExternalStatus()));
waitFor(60 * 1000, new Predicate() {
+ @Override
public boolean evaluate() throws Exception {
return runningJob.isComplete();
}
@@ -464,6 +470,7 @@ public class TestJavaActionExecutor exte
Context context = createContext(actionXml);
final RunningJob runningJob = submitAction(context);
waitFor(60 * 1000, new Predicate() {
+ @Override
public boolean evaluate() throws Exception {
return runningJob.isComplete();
}
@@ -490,6 +497,7 @@ public class TestJavaActionExecutor exte
Context context = createContext(actionXml);
final RunningJob runningJob = submitAction(context);
waitFor(60 * 1000, new Predicate() {
+ @Override
public boolean evaluate() throws Exception {
return runningJob.isComplete();
}
@@ -518,6 +526,7 @@ public class TestJavaActionExecutor exte
Context context = createContext(actionXml);
final RunningJob runningJob = submitAction(context);
waitFor(60 * 1000, new Predicate() {
+ @Override
public boolean evaluate() throws Exception {
return runningJob.isComplete();
}
@@ -550,6 +559,7 @@ public class TestJavaActionExecutor exte
assertTrue(ae.isCompleted(context.getAction().getExternalStatus()));
waitFor(60 * 1000, new Predicate() {
+ @Override
public boolean evaluate() throws Exception {
return runningJob.isComplete();
}
@@ -569,6 +579,7 @@ public class TestJavaActionExecutor exte
String launcherId = context.getAction().getExternalId();
waitFor(60 * 1000, new Predicate() {
+ @Override
public boolean evaluate() throws Exception {
JavaActionExecutor ae = new JavaActionExecutor();
Configuration conf = ae.createBaseHadoopConf(context, XmlUtils.parseXml(actionXml));
@@ -582,6 +593,7 @@ public class TestJavaActionExecutor exte
assertEquals(launcherId, context.getAction().getExternalId());
waitFor(60 * 1000, new Predicate() {
+ @Override
public boolean evaluate() throws Exception {
return runningJob2.isComplete();
}
@@ -683,6 +695,7 @@ public class TestJavaActionExecutor exte
Context context = createContext(actionXml);
final RunningJob runningJob = submitAction(context);
waitFor(60 * 1000, new Predicate() {
+ @Override
public boolean evaluate() throws Exception {
return runningJob.isComplete();
}
Modified: incubator/oozie/trunk/core/src/test/java/org/apache/oozie/action/hadoop/TestPigActionExecutor.java
URL: http://svn.apache.org/viewvc/incubator/oozie/trunk/core/src/test/java/org/apache/oozie/action/hadoop/TestPigActionExecutor.java?rev=1212728&r1=1212727&r2=1212728&view=diff
==============================================================================
--- incubator/oozie/trunk/core/src/test/java/org/apache/oozie/action/hadoop/TestPigActionExecutor.java (original)
+++ incubator/oozie/trunk/core/src/test/java/org/apache/oozie/action/hadoop/TestPigActionExecutor.java Sat Dec 10 04:15:17 2011
@@ -6,9 +6,9 @@
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -37,8 +37,10 @@ import org.apache.oozie.util.IOUtils;
import org.apache.oozie.util.ClassUtils;
import org.apache.pig.Main;
import org.jdom.Element;
+import org.json.simple.JSONValue;
import java.io.File;
+import java.io.IOException;
import java.io.OutputStream;
import java.io.InputStream;
import java.io.FileInputStream;
@@ -47,12 +49,29 @@ import java.io.OutputStreamWriter;
import java.io.StringReader;
import java.util.ArrayList;
import java.util.List;
+import java.util.Map;
import java.util.Properties;
import jline.ConsoleReaderInputStream;
public class TestPigActionExecutor extends ActionExecutorTestCase {
+ private static final String PIG_SCRIPT = "set job.name 'test'\n" + "set debug on\n" +
+ "A = load '$IN' using PigStorage(':');\n" +
+ "B = foreach A generate $0 as id;\n" +
+ "store B into '$OUT' USING PigStorage();\n";
+
+ private static final String ERROR_PIG_SCRIPT = "set job.name 'test'\n" + "set debug on\n" +
+ "A = load '$IN' using PigStorage(':');\n" +
+ "ERROR @#$@#$;\n";
+
+ private static final String UDF_PIG_SCRIPT = "register udf.jar\n" +
+ "set job.name 'test'\n" + "set debug on\n" +
+ "A = load '$IN' using PigStorage(':');\n" +
+ "B = foreach A generate" +
+ " org.apache.oozie.action.hadoop.UDFTester($0) as id;\n" +
+ "store B into '$OUT' USING PigStorage();\n";
+
@Override
protected void setSystemProps() {
super.setSystemProps();
@@ -77,12 +96,14 @@ public class TestPigActionExecutor exten
classes.add(LauncherSecurityManager.class);
classes.add(LauncherException.class);
classes.add(LauncherMainException.class);
+ classes.add(ActionStats.class);
+ classes.add(ActionType.class);
classes.add(LauncherMain.class);
classes.add(MapReduceMain.class);
classes.add(PigMain.class);
+ classes.add(OoziePigStats.class);
assertEquals(classes, ae.getLauncherClasses());
-
Element actionXml = XmlUtils.parseXml("<pig>" +
"<job-tracker>" + getJobTrackerUri() + "</job-tracker>" +
"<name-node>" + getNameNodeUri() + "</name-node>" +
@@ -126,7 +147,6 @@ public class TestPigActionExecutor exten
os = fs.create(new Path(getAppPath(), jLineJar));
IOUtils.copyStream(is, os);
-
XConfiguration protoConf = new XConfiguration();
protoConf.set(WorkflowAppService.HADOOP_USER, getTestUser());
protoConf.set(WorkflowAppService.HADOOP_UGI, getTestUser() + "," + getTestGroup());
@@ -179,18 +199,13 @@ public class TestPigActionExecutor exten
Context context = createContext(actionXml);
final RunningJob launcherJob = submitAction(context);
String launcherId = context.getAction().getExternalId();
- waitFor(180 * 1000, new Predicate() {
- public boolean evaluate() throws Exception {
- return launcherJob.isComplete();
- }
- });
- Thread.sleep(2000);
+ evaluateLauncherJob(launcherJob);
assertTrue(launcherJob.isSuccessful());
Thread.sleep(2000);
assertFalse(LauncherMapper.hasIdSwap(launcherJob));
if (checkForSuccess) {
- assertTrue(LauncherMapper.hasOutputData(launcherJob));
+ assertTrue(LauncherMapper.hasStatsData(launcherJob));
}
PigActionExecutor ae = new PigActionExecutor();
@@ -199,11 +214,8 @@ public class TestPigActionExecutor exten
assertTrue(launcherId.equals(context.getAction().getExternalId()));
if (checkForSuccess) {
assertEquals("SUCCEEDED", context.getAction().getExternalStatus());
- assertNotNull(context.getAction().getData());
- Properties outputData = new Properties();
- outputData.load(new StringReader(context.getAction().getData()));
- assertTrue(outputData.containsKey("hadoopJobs"));
- assertNotSame("", outputData.getProperty("hadoopJobs"));
+ assertNull(context.getAction().getData());
+
}
else {
assertEquals("FAILED/KILLED", context.getAction().getExternalStatus());
@@ -217,54 +229,148 @@ public class TestPigActionExecutor exten
}
}
- private static final String PIG_SCRIPT = "set job.name 'test'\n" + "set debug on\n" +
- "A = load '$IN' using PigStorage(':');\n" +
- "B = foreach A generate $0 as id;\n" +
- "store B into '$OUT' USING PigStorage();\n";
+ /*
+ * Test the stats retrieved from a Pig job
+ */
+ public void testExecutionStats() throws Exception {
+ // Set the action xml with the option for retrieving stats to true
+ String actionXml = setPigActionXml(PIG_SCRIPT, true);
+ Context context = createContext(actionXml);
+ final RunningJob launcherJob = submitAction(context);
+ evaluateLauncherJob(launcherJob);
+ assertTrue(launcherJob.isSuccessful());
+ assertTrue(LauncherMapper.hasStatsData(launcherJob));
- protected XConfiguration getPigConfig() {
- XConfiguration conf = new XConfiguration();
- conf.set("oozie.pig.log.level", "INFO");
- return conf;
+ PigActionExecutor ae = new PigActionExecutor();
+ WorkflowAction wfAction = context.getAction();
+ ae.check(context, wfAction);
+ ae.end(context, wfAction);
+
+ assertEquals("SUCCEEDED", wfAction.getExternalStatus());
+ String stats = wfAction.getStats();
+ assertNotNull(stats);
+ // check for some of the expected key values in the stats
+ Map m = (Map)JSONValue.parse(stats);
+ // check for expected 1st level JSON keys
+ assertTrue(m.containsKey("PIG_VERSION"));
+
+ String expectedChildIDs = wfAction.getExternalChildIDs();
+ String[] childIDs = expectedChildIDs.split(",");
+ assertTrue(m.containsKey(childIDs[0]));
+
+ Map q = (Map)m.get(childIDs[0]);
+ // check for expected 2nd level JSON keys
+ assertTrue(q.containsKey("HADOOP_COUNTERS"));
}
- public void testPig() throws Exception {
- FileSystem fs = getFileSystem();
- Path script = new Path(getAppPath(), "script.pig");
- Writer w = new OutputStreamWriter(fs.create(script));
- w.write(PIG_SCRIPT);
- w.close();
+ /*
+ * Test the Hadoop IDs obtained from the Pig job
+ */
+ public void testExternalChildIds() throws Exception {
+ // Set the action xml with the option for retrieving stats to false
+ String actionXml = setPigActionXml(PIG_SCRIPT, false);
+ Context context = createContext(actionXml);
+ final RunningJob launcherJob = submitAction(context);
+ evaluateLauncherJob(launcherJob);
+ assertTrue(launcherJob.isSuccessful());
- Path inputDir = new Path(getFsTestCaseDir(), "input");
- Path outputDir = new Path(getFsTestCaseDir(), "output");
+ PigActionExecutor ae = new PigActionExecutor();
+ WorkflowAction wfAction = context.getAction();
+ ae.check(context, wfAction);
+ ae.end(context, wfAction);
+
+ assertEquals("SUCCEEDED", wfAction.getExternalStatus());
+ String externalIds = wfAction.getExternalChildIDs();
+ assertNotNull(externalIds);
+ assertNotSame("", externalIds);
+ // check for the expected prefix of hadoop jobIDs
+ assertTrue(externalIds.contains("job_"));
- w = new OutputStreamWriter(fs.create(new Path(inputDir, "data.txt")));
- w.write("dummy\n");
- w.write("dummy\n");
- w.close();
+ }
- String actionXml = "<pig>" +
- "<job-tracker>" + getJobTrackerUri() + "</job-tracker>" +
- "<name-node>" + getNameNodeUri() + "</name-node>" +
- getPigConfig().toXmlString(false) +
- "<script>" + script.getName() + "</script>" +
- "<param>IN=" + inputDir.toUri().getPath() + "</param>" +
- "<param>OUT=" + outputDir.toUri().getPath() + "</param>" +
- "</pig>";
- _testSubmit(actionXml, true);
+ /*
+ * Test the stats after setting the maximum allowed size of stats to a small
+ * value
+ */
+ public void testExecutionStatsWithMaxStatsSizeLimit() throws Exception {
+ // Set a very small value for max size of stats
+ setSystemProperty(JavaActionExecutor.MAX_EXTERNAL_STATS_SIZE, new String("1"));
+ new Services().init();
+ // Set the action xml with the option for retrieving stats to true
+ String actionXml = setPigActionXml(PIG_SCRIPT, true);
+ Context context = createContext(actionXml);
+ final RunningJob launcherJob = submitAction(context);
+ evaluateLauncherJob(launcherJob);
+ assertTrue(launcherJob.isSuccessful());
+
+ PigActionExecutor ae = new PigActionExecutor();
+ WorkflowAction wfAction = context.getAction();
+ ae.check(context, wfAction);
+ ae.end(context, wfAction);
+
+ // action should fail as the size of pig stats will always be greater
+ // than 1 byte
+ assertEquals("FAILED/KILLED", wfAction.getExternalStatus());
+ assertNull(wfAction.getStats());
}
- private static final String ERROR_PIG_SCRIPT = "set job.name 'test'\n" + "set debug on\n" +
- "A = load '$IN' using PigStorage(':');\n" +
- "ERROR @#$@#$;\n";
+ /*
+ * Test the stats with retrieve stats option set to false
+ */
+ public void testExecutionStatsWithRetrieveStatsFalse() throws Exception {
+ // Set the action xml with the option for retrieving stats to false
+ String actionXml = setPigActionXml(PIG_SCRIPT, false);
+ Context context = createContext(actionXml);
+ final RunningJob launcherJob = submitAction(context);
+ evaluateLauncherJob(launcherJob);
+ assertTrue(launcherJob.isSuccessful());
+ assertFalse(LauncherMapper.hasStatsData(launcherJob));
+
+ PigActionExecutor ae = new PigActionExecutor();
+ WorkflowAction wfAction = context.getAction();
+ ae.check(context, wfAction);
+ ae.end(context, wfAction);
+
+ assertEquals("SUCCEEDED", wfAction.getExternalStatus());
+ assertNotNull(wfAction.getExternalChildIDs());
+ }
+
+ private void evaluateLauncherJob(final RunningJob launcherJob) throws Exception{
+ waitFor(180 * 1000, new Predicate() {
+ @Override
+ public boolean evaluate() throws Exception {
+ return launcherJob.isComplete();
+ }
+ });
+ Thread.sleep(2000);
+ }
+
+ protected XConfiguration setPigConfig(boolean writeStats) {
+ XConfiguration conf = new XConfiguration();
+ conf.set("oozie.pig.log.level", "INFO");
+ conf.set(PigMain.EXTERNAL_STATS_WRITE, String.valueOf(writeStats));
+ return conf;
+ }
+
+ public void testPig() throws Exception {
+ // Set the action xml with the option for retrieving stats to true
+ String actionXml = setPigActionXml(PIG_SCRIPT, true);
+ _testSubmit(actionXml, true);
+ }
public void testPigError() throws Exception {
+ // Set the action xml with the option for retrieving stats to true
+ String actionXml = setPigActionXml(ERROR_PIG_SCRIPT, true);
+ _testSubmit(actionXml, false);
+ }
+
+ private String setPigActionXml(String pigScript, boolean writeStats) throws IOException{
FileSystem fs = getFileSystem();
Path script = new Path(getAppPath(), "script.pig");
Writer w = new OutputStreamWriter(fs.create(script));
- w.write(ERROR_PIG_SCRIPT);
+ w.write(pigScript);
w.close();
Path inputDir = new Path(getFsTestCaseDir(), "input");
@@ -278,20 +384,14 @@ public class TestPigActionExecutor exten
String actionXml = "<pig>" +
"<job-tracker>" + getJobTrackerUri() + "</job-tracker>" +
"<name-node>" + getNameNodeUri() + "</name-node>" +
- getPigConfig().toXmlString(false) +
+ setPigConfig(writeStats).toXmlString(false) +
"<script>" + script.getName() + "</script>" +
"<param>IN=" + inputDir.toUri().getPath() + "</param>" +
"<param>OUT=" + outputDir.toUri().getPath() + "</param>" +
"</pig>";
- _testSubmit(actionXml, false);
- }
- private static final String UDF_PIG_SCRIPT = "register udf.jar\n" +
- "set job.name 'test'\n" + "set debug on\n" +
- "A = load '$IN' using PigStorage(':');\n" +
- "B = foreach A generate" +
- " org.apache.oozie.action.hadoop.UDFTester($0) as id;\n" +
- "store B into '$OUT' USING PigStorage();\n";
+ return actionXml;
+ }
public void testUdfPig() throws Exception {
FileSystem fs = getFileSystem();
@@ -302,7 +402,6 @@ public class TestPigActionExecutor exten
OutputStream os = getFileSystem().create(udfJar);
IOUtils.copyStream(is, os);
-
Path script = new Path(getAppPath(), "script.pig");
Writer w = new OutputStreamWriter(fs.create(script));
w.write(UDF_PIG_SCRIPT);
@@ -319,7 +418,7 @@ public class TestPigActionExecutor exten
String actionXml = "<pig>" +
"<job-tracker>" + getJobTrackerUri() + "</job-tracker>" +
"<name-node>" + getNameNodeUri() + "</name-node>" +
- getPigConfig().toXmlString(false) +
+ setPigConfig(true).toXmlString(false) +
"<script>" + script.getName() + "</script>" +
"<param>IN=" + inputDir.toUri().getPath() + "</param>" +
"<param>OUT=" + outputDir.toUri().getPath() + "</param>" +
Modified: incubator/oozie/trunk/core/src/test/java/org/apache/oozie/action/hadoop/TestPigMain.java
URL: http://svn.apache.org/viewvc/incubator/oozie/trunk/core/src/test/java/org/apache/oozie/action/hadoop/TestPigMain.java?rev=1212728&r1=1212727&r2=1212728&view=diff
==============================================================================
--- incubator/oozie/trunk/core/src/test/java/org/apache/oozie/action/hadoop/TestPigMain.java (original)
+++ incubator/oozie/trunk/core/src/test/java/org/apache/oozie/action/hadoop/TestPigMain.java Sat Dec 10 04:15:17 2011
@@ -24,6 +24,7 @@ import org.apache.oozie.util.XConfigurat
import org.apache.oozie.util.ClassUtils;
import org.apache.oozie.util.IOUtils;
import org.apache.pig.Main;
+import org.json.simple.JSONValue;
import java.io.File;
import java.io.FileInputStream;
@@ -34,6 +35,7 @@ import java.io.OutputStreamWriter;
import java.io.Writer;
import java.io.FileWriter;
import java.io.FileReader;
+import java.util.Map;
import java.util.Properties;
import java.net.URL;
@@ -90,6 +92,10 @@ public class TestPigMain extends PigTest
jobConf.setInt("mapred.reduce.max.attempts", 1);
jobConf.set("mapred.job.tracker", getJobTrackerUri());
jobConf.set("fs.default.name", getNameNodeUri());
+
+ // option to specify whether stats should be stored or not
+ jobConf.set("oozie.action.external.stats.write", Boolean.toString(writeStats));
+
injectKerberosInfo(jobConf);
DistributedCache.addFileToClassPath(new Path(pigJar.toUri().getPath()), getFileSystem().getConf());
@@ -103,11 +109,15 @@ public class TestPigMain extends PigTest
jobConf.writeXml(os);
os.close();
- File outputDataFile = new File(getTestCaseDir(), "outputdata.properties");
+ File statsDataFile = new File(getTestCaseDir(), "statsdata.properties");
+
+ File hadoopIdsFile = new File(getTestCaseDir(), "hadoopIds.properties");
setSystemProperty("oozie.launcher.job.id", "" + System.currentTimeMillis());
setSystemProperty("oozie.action.conf.xml", actionXml.getAbsolutePath());
- setSystemProperty("oozie.action.output.properties", outputDataFile.getAbsolutePath());
+ setSystemProperty("oozie.action.stats.properties", statsDataFile.getAbsolutePath());
+ setSystemProperty("oozie.action.externalChildIDs.properties", hadoopIdsFile.getAbsolutePath());
+
URL url = Thread.currentThread().getContextClassLoader().getResource("PigMain.txt");
File classPathDir = new File(url.getPath()).getParentFile();
@@ -141,12 +151,21 @@ public class TestPigMain extends PigTest
System.setProperty("user.name", user);
}
- assertTrue(outputDataFile.exists());
- props = new Properties();
- props.load(new FileReader(outputDataFile));
- assertTrue(props.containsKey("hadoopJobs"));
- assertNotSame("", props.getProperty("hadoopJobs"));
-
+ // Stats should be stored only if option to write stats is set to true
+ if (writeStats) {
+ assertTrue(statsDataFile.exists());
+ String stats = IOUtils.getReaderAsString(new FileReader(statsDataFile), -1);
+ // check for some of the expected key values in the stats
+ Map m = (Map) JSONValue.parse(stats);
+ // check for expected 1st level JSON keys
+ assertTrue(m.containsKey("PIG_VERSION"));
+ } else {
+ assertFalse(statsDataFile.exists());
+ }
+ // HadoopIds should always be stored
+ assertTrue(hadoopIdsFile.exists());
+ String externalChildIds = IOUtils.getReaderAsString(new FileReader(hadoopIdsFile), -1);
+ assertTrue(externalChildIds.contains("job_"));
return null;
}