Search in sources :

Example 1 with CoordinatorJobException

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);
    }
}
Also used : Path(org.apache.hadoop.fs.Path) Configuration(org.apache.hadoop.conf.Configuration) XConfiguration(org.apache.oozie.util.XConfiguration) InputStreamReader(java.io.InputStreamReader) HadoopAccessorException(org.apache.oozie.service.HadoopAccessorException) Reader(java.io.Reader) InputStreamReader(java.io.InputStreamReader) StringReader(java.io.StringReader) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException) URI(java.net.URI) HadoopAccessorService(org.apache.oozie.service.HadoopAccessorService) CoordinatorJobException(org.apache.oozie.coord.CoordinatorJobException) JPAExecutorException(org.apache.oozie.executor.jpa.JPAExecutorException) URISyntaxException(java.net.URISyntaxException) JDOMException(org.jdom.JDOMException) HadoopAccessorException(org.apache.oozie.service.HadoopAccessorException) CommandException(org.apache.oozie.command.CommandException) SAXException(org.xml.sax.SAXException) IOException(java.io.IOException) ParameterVerifierException(org.apache.oozie.util.ParameterVerifierException) CoordinatorJobException(org.apache.oozie.coord.CoordinatorJobException) StringWriter(java.io.StringWriter) FileSystem(org.apache.hadoop.fs.FileSystem)

Example 2 with CoordinatorJobException

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);
                }
            }
        }
    }
}
Also used : CoordinatorJobException(org.apache.oozie.coord.CoordinatorJobException) Element(org.jdom.Element) Iterator(java.util.Iterator) Namespace(org.jdom.Namespace) CoordinatorJobException(org.apache.oozie.coord.CoordinatorJobException) JPAExecutorException(org.apache.oozie.executor.jpa.JPAExecutorException) URISyntaxException(java.net.URISyntaxException) JDOMException(org.jdom.JDOMException) HadoopAccessorException(org.apache.oozie.service.HadoopAccessorException) CommandException(org.apache.oozie.command.CommandException) SAXException(org.xml.sax.SAXException) IOException(java.io.IOException) ParameterVerifierException(org.apache.oozie.util.ParameterVerifierException)

Example 3 with CoordinatorJobException

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;
}
Also used : CoordinatorJobException(org.apache.oozie.coord.CoordinatorJobException) Element(org.jdom.Element) CommandException(org.apache.oozie.command.CommandException) JDOMException(org.jdom.JDOMException) ParameterVerifierException(org.apache.oozie.util.ParameterVerifierException) CoordinatorJobException(org.apache.oozie.coord.CoordinatorJobException) JPAExecutorException(org.apache.oozie.executor.jpa.JPAExecutorException) URISyntaxException(java.net.URISyntaxException) JDOMException(org.jdom.JDOMException) HadoopAccessorException(org.apache.oozie.service.HadoopAccessorException) CommandException(org.apache.oozie.command.CommandException) SAXException(org.xml.sax.SAXException) IOException(java.io.IOException) ParameterVerifierException(org.apache.oozie.util.ParameterVerifierException)

Example 4 with CoordinatorJobException

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));
    }
}
Also used : CoordinatorJobException(org.apache.oozie.coord.CoordinatorJobException) Date(java.util.Date) CoordinatorJobException(org.apache.oozie.coord.CoordinatorJobException) JPAExecutorException(org.apache.oozie.executor.jpa.JPAExecutorException) URISyntaxException(java.net.URISyntaxException) JDOMException(org.jdom.JDOMException) HadoopAccessorException(org.apache.oozie.service.HadoopAccessorException) CommandException(org.apache.oozie.command.CommandException) SAXException(org.xml.sax.SAXException) IOException(java.io.IOException) ParameterVerifierException(org.apache.oozie.util.ParameterVerifierException)

Example 5 with CoordinatorJobException

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);
    }
}
Also used : CoordinatorJobException(org.apache.oozie.coord.CoordinatorJobException) Element(org.jdom.Element) List(java.util.List) ArrayList(java.util.ArrayList) JDOMException(org.jdom.JDOMException)

Aggregations

CoordinatorJobException (org.apache.oozie.coord.CoordinatorJobException)10 IOException (java.io.IOException)9 JDOMException (org.jdom.JDOMException)9 URISyntaxException (java.net.URISyntaxException)8 CommandException (org.apache.oozie.command.CommandException)8 SAXException (org.xml.sax.SAXException)7 JPAExecutorException (org.apache.oozie.executor.jpa.JPAExecutorException)6 HadoopAccessorException (org.apache.oozie.service.HadoopAccessorException)6 ParameterVerifierException (org.apache.oozie.util.ParameterVerifierException)6 Element (org.jdom.Element)5 StringReader (java.io.StringReader)2 ParseException (java.text.ParseException)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 URIHandlerException (org.apache.oozie.dependency.URIHandlerException)2 Attribute (org.jdom.Attribute)2 InputStreamReader (java.io.InputStreamReader)1 Reader (java.io.Reader)1 StringWriter (java.io.StringWriter)1 URI (java.net.URI)1