use of org.apache.oozie.coord.CoordinatorJobException in project oozie by apache.
the class CoordSubmitXCommand method readDefinition.
/**
* Read coordinator definition.
*
* @param appPath application path.
* @return coordinator definition.
* @throws CoordinatorJobException thrown if the definition could not be read.
*/
protected String readDefinition(String appPath) throws CoordinatorJobException {
String user = ParamChecker.notEmpty(conf.get(OozieClient.USER_NAME), OozieClient.USER_NAME);
// Configuration confHadoop = CoordUtils.getHadoopConf(conf);
try {
URI uri = new URI(appPath);
LOG.debug("user =" + user);
HadoopAccessorService has = Services.get().get(HadoopAccessorService.class);
Configuration fsConf = has.createConfiguration(uri.getAuthority());
FileSystem fs = has.createFileSystem(user, uri, fsConf);
Path appDefPath = null;
// app path could be a directory
Path path = new Path(uri.getPath());
// check file exists for dataset include file, app xml already checked
if (!fs.exists(path)) {
throw new URISyntaxException(path.toString(), "path not existed : " + path.toString());
}
if (!fs.isFile(path)) {
appDefPath = new Path(path, COORDINATOR_XML_FILE);
} else {
appDefPath = path;
}
Reader reader = new InputStreamReader(fs.open(appDefPath));
StringWriter writer = new StringWriter();
IOUtils.copyCharStream(reader, writer);
return writer.toString();
} catch (IOException ex) {
LOG.warn("IOException :" + XmlUtils.prettyPrint(conf), ex);
throw new CoordinatorJobException(ErrorCode.E1001, ex.getMessage(), ex);
} catch (URISyntaxException ex) {
LOG.warn("URISyException :" + ex.getMessage());
throw new CoordinatorJobException(ErrorCode.E1002, appPath, ex.getMessage(), ex);
} catch (HadoopAccessorException ex) {
throw new CoordinatorJobException(ex);
} catch (Exception ex) {
LOG.warn("Exception :", ex);
throw new CoordinatorJobException(ErrorCode.E1001, ex.getMessage(), ex);
}
}
use of org.apache.oozie.coord.CoordinatorJobException in project oozie by apache.
the class CoordSubmitXCommand method checkMultipleTimeInstances.
/*
* Check against multiple data instance values inside a single <instance> <start-instance> or <end-instance> tag
* If found, the job is not submitted and user is informed to correct the error,
* instead of defaulting to the first instance value in the list
*/
private void checkMultipleTimeInstances(Element eCoordJob, String eventType, String dataType) throws CoordinatorJobException {
Element eventsSpec, dataSpec, instance;
List<Element> instanceSpecList;
Namespace ns = eCoordJob.getNamespace();
String instanceValue;
eventsSpec = eCoordJob.getChild(eventType, ns);
if (eventsSpec != null) {
dataSpec = eventsSpec.getChild(dataType, ns);
if (dataSpec != null) {
// In case of input-events, there can be multiple child <instance> datasets.
// Iterating to ensure none of them have errors
instanceSpecList = dataSpec.getChildren("instance", ns);
Iterator instanceIter = instanceSpecList.iterator();
while (instanceIter.hasNext()) {
instance = ((Element) instanceIter.next());
if (instance.getContentSize() == 0) {
// empty string or whitespace
throw new CoordinatorJobException(ErrorCode.E1021, "<instance> tag within " + eventType + " is empty!");
}
instanceValue = instance.getContent(0).toString();
boolean isInvalid = false;
try {
isInvalid = evalAction.checkForExistence(instanceValue, ",");
} catch (Exception e) {
handleELParseException(eventType, dataType, instanceValue);
}
if (isInvalid) {
// reaching this block implies instance is not empty i.e. length > 0
handleExpresionWithMultipleInstances(eventType, dataType, instanceValue);
}
}
// In case of input-events, there can be multiple child <start-instance> datasets.
// Iterating to ensure none of them have errors
instanceSpecList = dataSpec.getChildren("start-instance", ns);
instanceIter = instanceSpecList.iterator();
while (instanceIter.hasNext()) {
instance = ((Element) instanceIter.next());
if (instance.getContentSize() == 0) {
// empty string or whitespace
throw new CoordinatorJobException(ErrorCode.E1021, "<start-instance> tag within " + eventType + " is empty!");
}
instanceValue = instance.getContent(0).toString();
boolean isInvalid = false;
try {
isInvalid = evalAction.checkForExistence(instanceValue, ",");
} catch (Exception e) {
handleELParseException(eventType, dataType, instanceValue);
}
if (isInvalid) {
// reaching this block implies start instance is not empty i.e. length > 0
handleExpresionWithStartMultipleInstances(eventType, dataType, instanceValue);
}
}
// In case of input-events, there can be multiple child <end-instance> datasets.
// Iterating to ensure none of them have errors
instanceSpecList = dataSpec.getChildren("end-instance", ns);
instanceIter = instanceSpecList.iterator();
while (instanceIter.hasNext()) {
instance = ((Element) instanceIter.next());
if (instance.getContentSize() == 0) {
// empty string or whitespace
throw new CoordinatorJobException(ErrorCode.E1021, "<end-instance> tag within " + eventType + " is empty!");
}
instanceValue = instance.getContent(0).toString();
boolean isInvalid = false;
try {
isInvalid = evalAction.checkForExistence(instanceValue, ",");
} catch (Exception e) {
handleELParseException(eventType, dataType, instanceValue);
}
if (isInvalid) {
// reaching this block implies instance is not empty i.e. length > 0
handleExpresionWithMultipleEndInstances(eventType, dataType, instanceValue);
}
}
}
}
}
use of org.apache.oozie.coord.CoordinatorJobException in project oozie by apache.
the class CoordSubmitXCommand method submitJob.
protected String submitJob() throws CommandException {
String jobId = null;
InstrumentUtils.incrJobCounter(getName(), 1, getInstrumentation());
boolean exceptionOccured = false;
try {
mergeDefaultConfig();
String appXml = readAndValidateXml();
coordJob.setOrigJobXml(appXml);
LOG.debug("jobXml after initial validation " + XmlUtils.prettyPrint(appXml).toString());
Element eXml = XmlUtils.parseXml(appXml);
String appNamespace = readAppNamespace(eXml);
coordJob.setAppNamespace(appNamespace);
ParameterVerifier.verifyParameters(conf, eXml);
appXml = XmlUtils.removeComments(appXml);
initEvaluators();
Element eJob = basicResolveAndIncludeDS(appXml, conf, coordJob);
validateCoordinatorJob();
// checking if the coordinator application data input/output events
// specify multiple data instance values in erroneous manner
checkMultipleTimeInstances(eJob, COORD_INPUT_EVENTS, COORD_INPUT_EVENTS_DATA_IN);
checkMultipleTimeInstances(eJob, COORD_OUTPUT_EVENTS, COORD_OUTPUT_EVENTS_DATA_OUT);
LOG.debug("jobXml after all validation " + XmlUtils.prettyPrint(eJob).toString());
jobId = storeToDB(appXml, eJob, coordJob);
// log job info for coordinator job
LogUtils.setLogInfo(coordJob);
if (!dryrun) {
queueMaterializeTransitionXCommand(jobId);
} else {
return getDryRun(coordJob);
}
} catch (JDOMException jex) {
exceptionOccured = true;
LOG.warn("ERROR: ", jex);
throw new CommandException(ErrorCode.E0700, jex.getMessage(), jex);
} catch (CoordinatorJobException cex) {
exceptionOccured = true;
LOG.warn("ERROR: ", cex);
throw new CommandException(cex);
} catch (ParameterVerifierException pex) {
exceptionOccured = true;
LOG.warn("ERROR: ", pex);
throw new CommandException(pex);
} catch (IllegalArgumentException iex) {
exceptionOccured = true;
LOG.warn("ERROR: ", iex);
throw new CommandException(ErrorCode.E1003, iex.getMessage(), iex);
} catch (Exception ex) {
exceptionOccured = true;
LOG.warn("ERROR: ", ex);
throw new CommandException(ErrorCode.E0803, ex.getMessage(), ex);
} finally {
if (exceptionOccured) {
if (coordJob.getId() == null || coordJob.getId().equalsIgnoreCase("")) {
coordJob.setStatus(CoordinatorJob.Status.FAILED);
coordJob.resetPending();
}
}
}
return jobId;
}
use of org.apache.oozie.coord.CoordinatorJobException in project oozie by apache.
the class CoordSubmitXCommand method checkInitialInstance.
/*
* this method checks if the initial-instance specified for a particular
is not a date earlier than the oozie server default Jan 01, 1970 00:00Z UTC
*/
private void checkInitialInstance(String val) throws CoordinatorJobException, IllegalArgumentException {
Date initialInstance, givenInstance;
try {
initialInstance = DateUtils.parseDateUTC("1970-01-01T00:00Z");
givenInstance = DateUtils.parseDateOozieTZ(val);
} catch (Exception e) {
throw new IllegalArgumentException("Unable to parse dataset initial-instance string '" + val + "' to Date object. ", e);
}
if (givenInstance.compareTo(initialInstance) < 0) {
throw new CoordinatorJobException(ErrorCode.E1021, "Dataset initial-instance " + val + " is earlier than the default initial instance " + DateUtils.formatDateOozieTZ(initialInstance));
}
}
use of org.apache.oozie.coord.CoordinatorJobException in project oozie by apache.
the class CoordSubmitXCommand method includeOneDSFile.
/**
* Include one dataset file.
*
* @param incDSFile : Include data set filename.
* @param dsList :List of dataset names to verify the duplicate.
* @param allDataSets : Element that includes all dataset definitions.
* @param dsNameSpace : Data set name space
* @throws CoordinatorJobException thrown if failed to include one dataset file
*/
@SuppressWarnings("unchecked")
private void includeOneDSFile(String incDSFile, List<String> dsList, Element allDataSets, Namespace dsNameSpace) throws CoordinatorJobException {
Element tmpDataSets = null;
try {
String dsXml = readDefinition(incDSFile);
LOG.debug("DSFILE :" + incDSFile + "\n" + dsXml);
tmpDataSets = XmlUtils.parseXml(dsXml);
} catch (JDOMException e) {
LOG.warn("Error parsing included dataset [{0}]. Message [{1}]", incDSFile, e.getMessage());
throw new CoordinatorJobException(ErrorCode.E0700, e.getMessage());
}
resolveDataSets(tmpDataSets.getChildren("dataset"));
for (Element e : (List<Element>) tmpDataSets.getChildren("dataset")) {
String dsName = e.getAttributeValue("name");
if (dsList.contains(dsName)) {
throw new RuntimeException("Duplicate Dataset " + dsName);
}
dsList.add(dsName);
Element tmp = (Element) e.clone();
// TODO: Don't like to over-write the external/include DS's namespace
tmp.setNamespace(dsNameSpace);
tmp.getChild("uri-template").setNamespace(dsNameSpace);
if (e.getChild("done-flag") != null) {
tmp.getChild("done-flag").setNamespace(dsNameSpace);
}
allDataSets.addContent(tmp);
}
// nested include
for (Element includeElem : (List<Element>) tmpDataSets.getChildren("include", tmpDataSets.getNamespace())) {
String incFile = includeElem.getTextTrim();
includeOneDSFile(incFile, dsList, allDataSets, dsNameSpace);
}
}
Aggregations