Search in sources :

Example 56 with ELEvaluator

use of org.apache.oozie.util.ELEvaluator in project oozie by apache.

the class CoordInputLogicEvaluatorPhaseTwo method evalInput.

@Override
public CoordInputLogicEvaluatorResult evalInput(String dataSet, int min, int wait) {
    try {
        CoordPullInputDependency coordPullInputDependency = (CoordPullInputDependency) coordInputDependency;
        ELEvaluator eval = CoordELEvaluator.createLazyEvaluator(actualTime, coordAction.getNominalTime(), getInputSetEvent(dataSet), getConf());
        if (coordPullInputDependency.getUnResolvedDependency(dataSet) == null) {
            return super.evalInput(dataSet, min, wait);
        } else {
            cleanPreviousCheckData(coordPullInputDependency, dataSet);
            List<String> unresolvedList = coordPullInputDependency.getUnResolvedDependency(dataSet).getDependencies();
            for (String unresolved : unresolvedList) {
                String resolvedPath = "";
                CoordELFunctions.evalAndWrap(eval, unresolved);
                boolean isResolved = (Boolean) eval.getVariable(CoordELConstants.IS_RESOLVED);
                coordPullInputDependency.setDependencyMap(dependencyMap);
                if (eval.getVariable(CoordELConstants.RESOLVED_PATH) != null) {
                    resolvedPath = eval.getVariable(CoordELConstants.RESOLVED_PATH).toString();
                }
                if (resolvedPath != null) {
                    resolvedPath = getEvalResult(isResolved, min, wait, Arrays.asList(DependencyChecker.dependenciesAsArray(resolvedPath.toString()))).getDataSets();
                }
                log.trace(MessageFormat.format("Return data is {0}", resolvedPath));
                log.debug(MessageFormat.format("Resolved status of Data set {0} with min {1} and wait {2}  =  {3}", dataSet, min, wait, !StringUtils.isEmpty(resolvedPath)));
                if ((isInputWaitElapsed(wait) || isResolved) && !StringUtils.isEmpty(resolvedPath)) {
                    coordPullInputDependency.addResolvedList(dataSet, resolvedPath.toString());
                } else {
                    cleanPreviousCheckData(coordPullInputDependency, dataSet);
                    if (!isInputWaitElapsed(wait)) {
                        return new CoordInputLogicEvaluatorResult(CoordInputLogicEvaluatorResult.STATUS.TIMED_WAITING);
                    } else {
                        return new CoordInputLogicEvaluatorResult(CoordInputLogicEvaluatorResult.STATUS.FALSE);
                    }
                }
            }
            coordPullInputDependency.getUnResolvedDependency(dataSet).setResolved(true);
            return new CoordInputLogicEvaluatorResult(STATUS.TRUE, getListAsString(coordPullInputDependency.getUnResolvedDependency(dataSet).getResolvedList(), dataSet));
        }
    } catch (Exception e) {
        throw new RuntimeException(" event not found" + e, e);
    }
}
Also used : CoordPullInputDependency(org.apache.oozie.coord.input.dependency.CoordPullInputDependency) ELEvaluator(org.apache.oozie.util.ELEvaluator) CoordELEvaluator(org.apache.oozie.coord.CoordELEvaluator) JDOMException(org.jdom.JDOMException)

Example 57 with ELEvaluator

use of org.apache.oozie.util.ELEvaluator in project oozie by apache.

the class HCatELFunctions method ph3_coord_dataInPartitionMax.

/**
 * Used to specify the MINIMUM value of an HCat partition which is input dependency for workflow job.
 * <p> Look for two evaluator-level
 * variables <p> A) .datain.&lt;DATAIN_NAME&gt; B) .datain.&lt;DATAIN_NAME&gt;.unresolved <p> A defines the current list of
 * HCat URIs. <p> B defines whether there are any unresolved EL-function (i.e latest) <p> If there are something
 * unresolved, this function will echo back the original function <p> otherwise it sends the min partition value.
 *
 * @param dataInName : Datain name
 * @param partitionName : Specific partition name whose MIN value is wanted
 */
public static String ph3_coord_dataInPartitionMax(String dataInName, String partitionName) {
    ELEvaluator eval = ELEvaluator.getCurrent();
    String uris = (String) eval.getVariable(".datain." + dataInName);
    Boolean unresolved = (Boolean) eval.getVariable(".datain." + dataInName + ".unresolved");
    if (unresolved != null && unresolved.booleanValue() == true) {
        return "${coord:dataInPartitionMin('" + dataInName + "', '" + partitionName + "')}";
    }
    String maxPartition = null;
    if (uris != null) {
        String[] uriList = HCatURIParser.splitHCatUris(uris, HCAT_URI_PATTERN);
        // get the partition values list and find minimum
        try {
            // initialize minValue with first partition value
            maxPartition = new HCatURI(uriList[0]).getPartitionValue(partitionName);
            if (maxPartition == null || maxPartition.isEmpty()) {
                throw new RuntimeException("No value in data-in uri for partition key: " + partitionName);
            }
            for (int i = 1; i < uriList.length; i++) {
                String value = new HCatURI(uriList[i]).getPartitionValue(partitionName);
                if (value.compareTo(maxPartition) > 0) {
                    maxPartition = value;
                }
            }
        } catch (URISyntaxException urie) {
            throw new RuntimeException("HCat URI can't be parsed " + urie);
        }
    } else {
        XLog.getLog(HCatELFunctions.class).warn("URI is null");
        return null;
    }
    return maxPartition;
}
Also used : URISyntaxException(java.net.URISyntaxException) ELEvaluator(org.apache.oozie.util.ELEvaluator) HCatURI(org.apache.oozie.util.HCatURI)

Example 58 with ELEvaluator

use of org.apache.oozie.util.ELEvaluator in project oozie by apache.

the class HCatELFunctions method ph3_coord_dataInPartitionMin.

/**
 * Used to specify the MAXIMUM value of an HCat partition which is input dependency for workflow job.
 * <p> Look for two evaluator-level
 * variables <p> A) .datain.&lt;DATAIN_NAME&gt; B) .datain.&lt;DATAIN_NAME&gt;.unresolved <p> A defines the current list of
 * HCat URIs. <p> B defines whether there are any unresolved EL-function (i.e latest) <p> If there are something
 * unresolved, this function will echo back the original function <p> otherwise it sends the max partition value.
 *
 * @param dataInName : Datain name
 * @param partitionName : Specific partition name whose MAX value is wanted
 */
public static String ph3_coord_dataInPartitionMin(String dataInName, String partitionName) {
    ELEvaluator eval = ELEvaluator.getCurrent();
    String uris = (String) eval.getVariable(".datain." + dataInName);
    Boolean unresolved = (Boolean) eval.getVariable(".datain." + dataInName + ".unresolved");
    if (unresolved != null && unresolved.booleanValue() == true) {
        return "${coord:dataInPartitionMin('" + dataInName + "', '" + partitionName + "')}";
    }
    String minPartition = null;
    if (uris != null) {
        String[] uriList = HCatURIParser.splitHCatUris(uris, HCAT_URI_PATTERN);
        // get the partition values list and find minimum
        try {
            // initialize minValue with first partition value
            minPartition = new HCatURI(uriList[0]).getPartitionValue(partitionName);
            if (minPartition == null || minPartition.isEmpty()) {
                throw new RuntimeException("No value in data-in uri for partition key: " + partitionName);
            }
            for (int i = 1; i < uriList.length; i++) {
                String value = new HCatURI(uriList[i]).getPartitionValue(partitionName);
                if (value.compareTo(minPartition) < 0) {
                    // sticking to string comparison since some numerical date
                    // values can also contain letters e.g. 20120101T0300Z (UTC)
                    minPartition = value;
                }
            }
        } catch (URISyntaxException urie) {
            throw new RuntimeException("HCat URI can't be parsed " + urie);
        }
    } else {
        XLog.getLog(HCatELFunctions.class).warn("URI is null");
        return null;
    }
    return minPartition;
}
Also used : URISyntaxException(java.net.URISyntaxException) ELEvaluator(org.apache.oozie.util.ELEvaluator) HCatURI(org.apache.oozie.util.HCatURI)

Example 59 with ELEvaluator

use of org.apache.oozie.util.ELEvaluator in project oozie by apache.

the class HCatELFunctions method ph3_coord_dataOutPartitionValue.

/**
 * Used to specify the HCat partition's value defining output for workflow job.<p> Look for two evaluator-level
 * variables <p> A) .dataout.&lt;DATAOUT_NAME&gt; B) .dataout.&lt;DATAOUT_NAME&gt;.unresolved <p> A defines the current list of
 * HCat URIs. <p> B defines whether there are any unresolved EL-function (i.e latest) <p> If there are something
 * unresolved, this function will echo back the original function <p> otherwise it sends the partition value.
 *
 * @param dataOutName : Dataout name
 * @param partitionName : Specific partition name whose value is wanted
 */
public static String ph3_coord_dataOutPartitionValue(String dataOutName, String partitionName) {
    ELEvaluator eval = ELEvaluator.getCurrent();
    String uri = (String) eval.getVariable(".dataout." + dataOutName);
    Boolean unresolved = (Boolean) eval.getVariable(".dataout." + dataOutName + ".unresolved");
    if (unresolved != null && unresolved.booleanValue() == true) {
        return "${coord:dataOutPartitionValue('" + dataOutName + "', '" + partitionName + "')}";
    }
    try {
        HCatURI hcatUri = new HCatURI(uri);
        return hcatUri.getPartitionValue(partitionName);
    } catch (URISyntaxException urie) {
        XLog.getLog(HCatELFunctions.class).warn("Exception with uriTemplate [{0}]. Reason [{1}]: ", uri, urie);
        throw new RuntimeException("HCat URI can't be parsed " + urie);
    }
}
Also used : URISyntaxException(java.net.URISyntaxException) ELEvaluator(org.apache.oozie.util.ELEvaluator) HCatURI(org.apache.oozie.util.HCatURI)

Example 60 with ELEvaluator

use of org.apache.oozie.util.ELEvaluator in project oozie by apache.

the class HCatELFunctions method ph3_coord_dataInPartitionFilter.

/**
 * Used to specify the HCat partition filter which is input dependency for workflow job.<p> Look for two evaluator-level
 * variables <p> A) .datain.&lt;DATAIN_NAME&gt; B) .datain.&lt;DATAIN_NAME&gt;.unresolved <p> A defines the current list of
 * HCat URIs. <p> B defines whether there are any unresolved EL-function (i.e latest) <p> If there are something
 * unresolved, this function will echo back the original function <p> otherwise it sends the partition filter.
 *
 * @param dataInName : Datain name
 * @param type : for action type - pig, MR or hive
 */
public static String ph3_coord_dataInPartitionFilter(String dataInName, String type) {
    ELEvaluator eval = ELEvaluator.getCurrent();
    String uris = (String) eval.getVariable(".datain." + dataInName);
    Boolean unresolved = (Boolean) eval.getVariable(".datain." + dataInName + ".unresolved");
    if (unresolved != null && unresolved.booleanValue() == true) {
        return "${coord:dataInPartitionFilter('" + dataInName + "', '" + type + "')}";
    }
    return createPartitionFilter(uris, type);
}
Also used : ELEvaluator(org.apache.oozie.util.ELEvaluator)

Aggregations

ELEvaluator (org.apache.oozie.util.ELEvaluator)72 Element (org.jdom.Element)16 ELService (org.apache.oozie.service.ELService)15 XConfiguration (org.apache.oozie.util.XConfiguration)15 Configuration (org.apache.hadoop.conf.Configuration)13 WorkflowJobBean (org.apache.oozie.WorkflowJobBean)11 URISyntaxException (java.net.URISyntaxException)9 WorkflowActionBean (org.apache.oozie.WorkflowActionBean)9 CoordELEvaluator (org.apache.oozie.coord.CoordELEvaluator)8 EndNodeDef (org.apache.oozie.workflow.lite.EndNodeDef)7 LiteWorkflowApp (org.apache.oozie.workflow.lite.LiteWorkflowApp)7 LiteWorkflowInstance (org.apache.oozie.workflow.lite.LiteWorkflowInstance)7 StartNodeDef (org.apache.oozie.workflow.lite.StartNodeDef)7 CommandException (org.apache.oozie.command.CommandException)6 IOException (java.io.IOException)5 StringReader (java.io.StringReader)5 URI (java.net.URI)5 Date (java.util.Date)5 Map (java.util.Map)5 HCatURI (org.apache.oozie.util.HCatURI)5