Search in sources :

Example 11 with DagNode

use of org.apache.hudi.integ.testsuite.dag.nodes.DagNode in project hudi by apache.

the class DagUtils method convertDagToYaml.

private static void convertDagToYaml(JsonNode yamlNode, List<DagNode> dagNodes) throws IOException {
    for (DagNode dagNode : dagNodes) {
        String name = dagNode.getConfig().getOtherConfigs().getOrDefault(DeltaConfig.Config.NODE_NAME, dagNode.getName()).toString();
        ((ObjectNode) yamlNode).put(name, convertDagNodeToJsonNode(dagNode));
        if (dagNode.getChildNodes().size() > 0) {
            convertDagToYaml(yamlNode, dagNode.getChildNodes());
        }
    }
}
Also used : DagNode(org.apache.hudi.integ.testsuite.dag.nodes.DagNode) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode)

Example 12 with DagNode

use of org.apache.hudi.integ.testsuite.dag.nodes.DagNode in project hudi by apache.

the class DagUtils method convertYamlToDag.

/**
 * Converts a YAML representation to {@link WorkflowDag}.
 */
public static WorkflowDag convertYamlToDag(String yaml) throws IOException {
    int dagRounds = DEFAULT_DAG_ROUNDS;
    int intermittentDelayMins = DEFAULT_INTERMITTENT_DELAY_MINS;
    String dagName = DEFAULT_DAG_NAME;
    Map<String, DagNode> allNodes = new HashMap<>();
    final ObjectMapper yamlReader = new ObjectMapper(new YAMLFactory());
    final JsonNode jsonNode = yamlReader.readTree(yaml);
    Iterator<Entry<String, JsonNode>> itr = jsonNode.fields();
    while (itr.hasNext()) {
        Entry<String, JsonNode> dagNode = itr.next();
        String key = dagNode.getKey();
        switch(key) {
            case DAG_NAME:
                dagName = dagNode.getValue().asText();
                break;
            case DAG_ROUNDS:
                dagRounds = dagNode.getValue().asInt();
                break;
            case DAG_INTERMITTENT_DELAY_MINS:
                intermittentDelayMins = dagNode.getValue().asInt();
                break;
            case DAG_CONTENT:
                JsonNode dagContent = dagNode.getValue();
                Iterator<Entry<String, JsonNode>> contentItr = dagContent.fields();
                while (contentItr.hasNext()) {
                    Entry<String, JsonNode> dagContentNode = contentItr.next();
                    allNodes.put(dagContentNode.getKey(), convertJsonToDagNode(allNodes, dagContentNode.getKey(), dagContentNode.getValue()));
                }
                break;
            default:
                break;
        }
    }
    return new WorkflowDag(dagName, dagRounds, intermittentDelayMins, findRootNodes(allNodes));
}
Also used : DagNode(org.apache.hudi.integ.testsuite.dag.nodes.DagNode) Entry(java.util.Map.Entry) HashMap(java.util.HashMap) YAMLFactory(com.fasterxml.jackson.dataformat.yaml.YAMLFactory) JsonNode(com.fasterxml.jackson.databind.JsonNode) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Aggregations

DagNode (org.apache.hudi.integ.testsuite.dag.nodes.DagNode)12 ArrayList (java.util.ArrayList)6 InsertNode (org.apache.hudi.integ.testsuite.dag.nodes.InsertNode)5 HiveQueryNode (org.apache.hudi.integ.testsuite.dag.nodes.HiveQueryNode)3 UpsertNode (org.apache.hudi.integ.testsuite.dag.nodes.UpsertNode)3 Test (org.junit.jupiter.api.Test)3 WorkflowDag (org.apache.hudi.integ.testsuite.dag.WorkflowDag)2 HiveSyncNode (org.apache.hudi.integ.testsuite.dag.nodes.HiveSyncNode)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 YAMLFactory (com.fasterxml.jackson.dataformat.yaml.YAMLFactory)1 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Entry (java.util.Map.Entry)1 PriorityQueue (java.util.PriorityQueue)1 Future (java.util.concurrent.Future)1 Function (java.util.function.Function)1