Search in sources :

Example 1 with Pair

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

the class TestCoordJobGetActionsSubsetJPAExecutor method testCoordActionFilter.

// Check status filters for Coordinator actions
public void testCoordActionFilter() throws Exception {
    CoordinatorJobBean job = addRecordToCoordJobTable(CoordinatorJob.Status.RUNNING, false, false);
    // Add Coordinator action with nominal time: 2009-12-15T01:00Z
    addRecordToCoordActionTable(job.getId(), 1, CoordinatorAction.Status.RUNNING, "coord-action-get.xml", 0);
    // Add Coordinator action with nominal time: 2009-02-01T23:59Z
    addRecordToCoordActionTable(job.getId(), 2, CoordinatorAction.Status.WAITING, "coord-action-get.xml", 0);
    // Create lists for status filter to test positive filter
    Map<Pair<String, FILTER_COMPARATORS>, List<Object>> filterMap = new HashMap<Pair<String, FILTER_COMPARATORS>, List<Object>>();
    List<Object> positiveFilter = new ArrayList<Object>();
    positiveFilter.add("RUNNING");
    positiveFilter.add("KILLED");
    filterMap.put(POSITIVE_STATUS_FILTER, positiveFilter);
    List<CoordinatorActionBean> actions = _testGetActionsSubsetFilter(job.getId(), 1, filterMap, 1, 2);
    assertEquals(actions.size(), 1);
    assertEquals(actions.get(0).getActionNumber(), 1);
    // Create lists for status filter to test negative filter
    filterMap.clear();
    List<Object> negativeFilter = new ArrayList<Object>();
    negativeFilter.add("WAITING");
    negativeFilter.add("KILLED");
    filterMap.put(NEGATIVE_STATUS_FILTER, negativeFilter);
    actions = _testGetActionsSubsetFilter(job.getId(), 1, filterMap, 1, 2);
    assertEquals(actions.size(), 1);
    assertEquals(actions.get(0).getActionNumber(), 1);
    // Test Combination of include/exclude filters - no dup
    filterMap.clear();
    filterMap.put(POSITIVE_STATUS_FILTER, positiveFilter);
    filterMap.put(NEGATIVE_STATUS_FILTER, negativeFilter);
    actions = _testGetActionsSubsetFilter(job.getId(), 1, filterMap, 1, 2);
    assertEquals(actions.size(), 1);
    assertEquals(actions.get(0).getActionNumber(), 1);
    // Test Combination of include/exclude filters - dup --> no result
    filterMap.clear();
    filterMap.put(POSITIVE_STATUS_FILTER, positiveFilter);
    filterMap.put(NEGATIVE_STATUS_FILTER, positiveFilter);
    actions = _testGetActionsSubsetFilter(job.getId(), 1, filterMap, 1, 2);
    assertEquals(actions.size(), 0);
}
Also used : CoordinatorJobBean(org.apache.oozie.CoordinatorJobBean) FILTER_COMPARATORS(org.apache.oozie.CoordinatorEngine.FILTER_COMPARATORS) HashMap(java.util.HashMap) CoordinatorActionBean(org.apache.oozie.CoordinatorActionBean) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) Pair(org.apache.oozie.util.Pair)

Example 2 with Pair

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

the class CoordinatorEngine method parseJobFilter.

// Parses the filter string (e.g status=RUNNING;status=WAITING) and returns a list of status values
public Map<Pair<String, FILTER_COMPARATORS>, List<Object>> parseJobFilter(String filter) throws CoordinatorEngineException {
    Map<Pair<String, FILTER_COMPARATORS>, List<Object>> filterMap = new HashMap<Pair<String, FILTER_COMPARATORS>, List<Object>>();
    if (filter != null) {
        // split name value pairs
        StringTokenizer st = new StringTokenizer(filter, ";");
        while (st.hasMoreTokens()) {
            String token = st.nextToken().trim();
            Pair<String, FILTER_COMPARATORS> pair = null;
            for (FILTER_COMPARATORS comp : FILTER_COMPARATORS.values()) {
                if (token.contains(comp.getSign())) {
                    int index = token.indexOf(comp.getSign());
                    String key = token.substring(0, index);
                    String valueStr = token.substring(index + comp.getSign().length());
                    Object value;
                    if (key.equalsIgnoreCase(OozieClient.FILTER_STATUS)) {
                        value = valueStr.toUpperCase();
                        try {
                            CoordinatorAction.Status.valueOf((String) value);
                        } catch (IllegalArgumentException ex) {
                            // Check for incorrect status value
                            throw new CoordinatorEngineException(ErrorCode.E0421, filter, XLog.format("invalid status value [{0}]." + " Valid status values are: [{1}]", valueStr, StringUtils.join(CoordinatorAction.Status.values(), ", ")));
                        }
                        if (!(comp == FILTER_COMPARATORS.EQUALS || comp == FILTER_COMPARATORS.NOT_EQUALS)) {
                            throw new CoordinatorEngineException(ErrorCode.E0421, filter, XLog.format("invalid comparator [{0}] for status." + " Valid are = and !=", comp.getSign()));
                        }
                        pair = Pair.of(OozieClient.FILTER_STATUS, comp);
                    } else if (key.equalsIgnoreCase(OozieClient.FILTER_NOMINAL_TIME)) {
                        try {
                            value = new Timestamp(DateUtils.parseDateUTC(valueStr).getTime());
                        } catch (ParseException e) {
                            throw new CoordinatorEngineException(ErrorCode.E0421, filter, XLog.format("invalid nominal time [{0}]." + " Valid format: " + "[{1}]", valueStr, DateUtils.ISO8601_UTC_MASK));
                        }
                        pair = Pair.of(OozieClient.FILTER_NOMINAL_TIME, comp);
                    } else {
                        // Check for incorrect filter option
                        throw new CoordinatorEngineException(ErrorCode.E0421, filter, XLog.format("invalid filter [{0}]." + " Valid filters [{1}]", key, StringUtils.join(VALID_JOB_FILTERS, ", ")));
                    }
                    if (!filterMap.containsKey(pair)) {
                        filterMap.put(pair, new ArrayList<Object>());
                    }
                    filterMap.get(pair).add(value);
                    break;
                }
            }
            if (pair == null) {
                // token doesn't contain comparator
                throw new CoordinatorEngineException(ErrorCode.E0421, filter, "filter should be of format <key><comparator><value> pairs");
            }
        }
    }
    return filterMap;
}
Also used : HashMap(java.util.HashMap) Timestamp(java.sql.Timestamp) StringTokenizer(java.util.StringTokenizer) List(java.util.List) ArrayList(java.util.ArrayList) ParseException(java.text.ParseException) Pair(org.apache.oozie.util.Pair)

Example 3 with Pair

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

the class SchemaCheckXCommand method checkColumns.

private boolean checkColumns(DatabaseMetaData metaData, String catalog, String table, Map<String, Integer> expectedColumnTypes) throws SQLException {
    boolean problem = false;
    Map<String, Pair<Integer, String>> foundColumns = new HashMap<String, Pair<Integer, String>>();
    ResultSet rs = metaData.getColumns(catalog, null, table, null);
    while (rs.next()) {
        String colName = rs.getString("COLUMN_NAME");
        Integer dataType = rs.getInt("DATA_TYPE");
        String colDef = rs.getString("COLUMN_DEF");
        if (colName != null) {
            foundColumns.put(colName, new Pair<Integer, String>(dataType, colDef));
        }
    }
    Collection missingColumns = CollectionUtils.subtract(expectedColumnTypes.keySet(), foundColumns.keySet());
    if (!missingColumns.isEmpty()) {
        LOG.error("Found [{0}] missing columns in table [{1}]: {2}", missingColumns.size(), table, Arrays.toString(missingColumns.toArray()));
        problem = true;
    } else {
        for (Map.Entry<String, Integer> ent : expectedColumnTypes.entrySet()) {
            if (!foundColumns.get(ent.getKey()).getFirst().equals(ent.getValue())) {
                LOG.error("Expected column [{0}] in table [{1}] to have type [{2}], but found type [{3}]", ent.getKey(), table, getSQLTypeFromInt(ent.getValue()), getSQLTypeFromInt(foundColumns.get(ent.getKey()).getFirst()));
                problem = true;
            } else if (foundColumns.get(ent.getKey()).getSecond() != null) {
                LOG.error("Expected column [{0}] in table [{1}] to have default value [NULL], but found default vale [{2}]", ent.getKey(), table, foundColumns.get(ent.getKey()).getSecond());
                problem = true;
            } else {
                LOG.debug("Found column [{0}] in table [{1}] with type [{2}] and default value [NULL]", ent.getKey(), table, getSQLTypeFromInt(ent.getValue()));
            }
        }
    }
    if (!ignoreExtras) {
        Collection extraColumns = CollectionUtils.subtract(foundColumns.keySet(), expectedColumnTypes.keySet());
        if (!extraColumns.isEmpty()) {
            LOG.error("Found [{0}] extra columns in table [{1}]: {2}", extraColumns.size(), table, Arrays.toString(extraColumns.toArray()));
            problem = true;
        } else {
            LOG.debug("No extra columns found in table [{0}]", table);
        }
    }
    return problem;
}
Also used : HashMap(java.util.HashMap) ResultSet(java.sql.ResultSet) Collection(java.util.Collection) HashMap(java.util.HashMap) Map(java.util.Map) Pair(org.apache.oozie.util.Pair)

Example 4 with Pair

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

the class CoordSLAChangeXCommand method executeSlaCommand.

@Override
protected boolean executeSlaCommand() throws ServiceException, CommandException {
    try {
        List<Pair<String, Map<String, String>>> idSlaDefinitionList = new ArrayList<Pair<String, Map<String, String>>>();
        List<CoordinatorActionBean> coordinatorActionBeanList = getNotTerminatedActions();
        Configuration conf = getJobConf();
        for (CoordinatorActionBean coordAction : coordinatorActionBeanList) {
            Map<String, String> slaDefinitionMap = new HashMap<String, String>(newParams);
            for (String key : slaDefinitionMap.keySet()) {
                Element eAction = XmlUtils.parseXml(coordAction.getActionXml().toString());
                ELEvaluator evalSla = CoordELEvaluator.createSLAEvaluator(eAction, coordAction, conf);
                String updateValue = CoordELFunctions.evalAndWrap(evalSla, slaDefinitionMap.get(key));
                slaDefinitionMap.put(key, updateValue);
            }
            idSlaDefinitionList.add(new Pair<String, Map<String, String>>(coordAction.getId(), slaDefinitionMap));
        }
        return Services.get().get(SLAService.class).changeDefinition(idSlaDefinitionList);
    } catch (Exception e) {
        throw new CommandException(ErrorCode.E1027, e.getMessage(), e);
    }
}
Also used : Configuration(org.apache.hadoop.conf.Configuration) SLAService(org.apache.oozie.sla.service.SLAService) CoordinatorActionBean(org.apache.oozie.CoordinatorActionBean) HashMap(java.util.HashMap) Element(org.jdom.Element) ArrayList(java.util.ArrayList) CommandException(org.apache.oozie.command.CommandException) JPAExecutorException(org.apache.oozie.executor.jpa.JPAExecutorException) ServiceException(org.apache.oozie.service.ServiceException) CommandException(org.apache.oozie.command.CommandException) PreconditionException(org.apache.oozie.command.PreconditionException) ELEvaluator(org.apache.oozie.util.ELEvaluator) CoordELEvaluator(org.apache.oozie.coord.CoordELEvaluator) HashMap(java.util.HashMap) Map(java.util.Map) Pair(org.apache.oozie.util.Pair)

Example 5 with Pair

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

the class CoordCommandUtils method materializeInputDataEvents.

public static void materializeInputDataEvents(List<Element> events, SyncCoordAction appInst, Configuration conf, CoordinatorActionBean actionBean, boolean isInputLogicSpecified) throws Exception {
    if (events == null) {
        return;
    }
    CoordInputDependency coordPullInputDependency = CoordInputDependencyFactory.createPullInputDependencies(isInputLogicSpecified);
    CoordInputDependency coordPushInputDependency = CoordInputDependencyFactory.createPushInputDependencies(isInputLogicSpecified);
    List<Pair<String, String>> unresolvedList = new ArrayList<Pair<String, String>>();
    URIHandlerService uriService = Services.get().get(URIHandlerService.class);
    for (Element event : events) {
        StringBuilder instances = new StringBuilder();
        ELEvaluator eval = CoordELEvaluator.createInstancesELEvaluator(event, appInst, conf);
        // Handle list of instance tag
        resolveInstances(event, instances, appInst, conf, eval);
        // Handle start-instance and end-instance
        resolveInstanceRange(event, instances, appInst, conf, eval);
        // Separate out the unresolved instances
        String resolvedList = separateResolvedAndUnresolved(event, instances);
        String name = event.getAttribute("name").getValue();
        if (!resolvedList.isEmpty()) {
            Element uri = event.getChild("dataset", event.getNamespace()).getChild("uri-template", event.getNamespace());
            String uriTemplate = uri.getText();
            URI baseURI = uriService.getAuthorityWithScheme(uriTemplate);
            URIHandler handler = uriService.getURIHandler(baseURI);
            List<CoordInputInstance> inputInstanceList = new ArrayList<CoordInputInstance>();
            for (String inputInstance : resolvedList.split("#")) {
                inputInstanceList.add(new CoordInputInstance(inputInstance, false));
            }
            if (handler.getDependencyType(baseURI).equals(DependencyType.PULL)) {
                coordPullInputDependency.addInputInstanceList(name, inputInstanceList);
            } else {
                coordPushInputDependency.addInputInstanceList(name, inputInstanceList);
            }
        }
        String tmpUnresolved = event.getChildTextTrim(UNRESOLVED_INSTANCES_TAG, event.getNamespace());
        if (tmpUnresolved != null) {
            unresolvedList.add(new Pair<String, String>(name, tmpUnresolved));
        }
    }
    for (Pair<String, String> unresolvedDataset : unresolvedList) {
        coordPullInputDependency.addUnResolvedList(unresolvedDataset.getFirst(), unresolvedDataset.getSecond());
    }
    actionBean.setPullInputDependencies(coordPullInputDependency);
    actionBean.setPushInputDependencies(coordPushInputDependency);
    actionBean.setMissingDependencies(coordPullInputDependency.serialize());
    actionBean.setPushMissingDependencies(coordPushInputDependency.serialize());
}
Also used : Element(org.jdom.Element) ArrayList(java.util.ArrayList) URI(java.net.URI) URIHandlerService(org.apache.oozie.service.URIHandlerService) URIHandler(org.apache.oozie.dependency.URIHandler) CoordInputInstance(org.apache.oozie.coord.input.dependency.CoordInputInstance) CoordELEvaluator(org.apache.oozie.coord.CoordELEvaluator) ELEvaluator(org.apache.oozie.util.ELEvaluator) CoordInputDependency(org.apache.oozie.coord.input.dependency.CoordInputDependency) Pair(org.apache.oozie.util.Pair)

Aggregations

Pair (org.apache.oozie.util.Pair)16 ArrayList (java.util.ArrayList)9 HashMap (java.util.HashMap)8 CoordinatorActionBean (org.apache.oozie.CoordinatorActionBean)6 ActionDependency (org.apache.oozie.dependency.ActionDependency)6 List (java.util.List)5 Map (java.util.Map)5 Configuration (org.apache.hadoop.conf.Configuration)5 Date (java.util.Date)4 XConfiguration (org.apache.oozie.util.XConfiguration)4 File (java.io.File)3 FileWriter (java.io.FileWriter)3 Reader (java.io.Reader)3 Writer (java.io.Writer)3 CoordinatorJobBean (org.apache.oozie.CoordinatorJobBean)3 CommandException (org.apache.oozie.command.CommandException)3 JPAService (org.apache.oozie.service.JPAService)3 SLAService (org.apache.oozie.sla.service.SLAService)3 CoordinatorEngine (org.apache.oozie.CoordinatorEngine)2 FILTER_COMPARATORS (org.apache.oozie.CoordinatorEngine.FILTER_COMPARATORS)2