Search in sources :

Example 61 with TextNode

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.node.TextNode in project walkmod-core by walkmod.

the class SetReaderYMLAction method doAction.

@Override
public void doAction(JsonNode node) throws Exception {
    if (node.has("chains") && (chain == null || "".equals(chain.trim()))) {
        chain = "default";
    }
    ObjectNode reader = null;
    ObjectMapper mapper = provider.getObjectMapper();
    if (chain != null && !"".equals(chain.trim())) {
        if (node.has("chains")) {
            JsonNode chainsListNode = node.get("chains");
            if (chainsListNode.isArray()) {
                Iterator<JsonNode> it = chainsListNode.iterator();
                boolean found = false;
                while (it.hasNext() && !found) {
                    JsonNode current = it.next();
                    if (current.has("name")) {
                        String name = current.get("name").asText();
                        found = name.equals(chain);
                        if (found) {
                            if (current.has("reader")) {
                                reader = (ObjectNode) current.get("reader");
                            } else {
                                reader = new ObjectNode(mapper.getNodeFactory());
                            }
                            if (type != null && !"".equals(type.trim())) {
                                reader.set("type", new TextNode(type));
                            }
                            if (path != null && !"".equals(path.trim())) {
                                reader.set("path", new TextNode(path));
                            }
                            if (params != null && !params.isEmpty()) {
                                ObjectNode paramsObject = null;
                                if (reader.has("params")) {
                                    paramsObject = (ObjectNode) reader.get("params");
                                } else {
                                    paramsObject = new ObjectNode(mapper.getNodeFactory());
                                    reader.set("params", paramsObject);
                                }
                                Set<String> keys = params.keySet();
                                for (String key : keys) {
                                    paramsObject.put(key, params.get(key).toString());
                                }
                            }
                        }
                    }
                }
            }
        }
        if (reader != null) {
            provider.write(node);
        }
    } else {
        if (!node.has("chains")) {
            ArrayNode chains = new ArrayNode(mapper.getNodeFactory());
            ObjectNode defaultChain = new ObjectNode(mapper.getNodeFactory());
            defaultChain.set("name", new TextNode("default"));
            ObjectNode readerNode = new ObjectNode(mapper.getNodeFactory());
            if (type != null && !"".equals(type.trim())) {
                readerNode.set("type", new TextNode(type));
            }
            if (path != null && !"".equals(path.trim())) {
                readerNode.set("path", new TextNode(path));
            }
            if (params != null && !params.isEmpty()) {
                ObjectNode paramsObject = new ObjectNode(mapper.getNodeFactory());
                Set<String> keys = params.keySet();
                for (String key : keys) {
                    paramsObject.put(key, params.get(key).toString());
                }
                readerNode.set("params", paramsObject);
            }
            defaultChain.set("reader", readerNode);
            if (node.has("transformations")) {
                defaultChain.set("transformations", node.get("transformations"));
            }
            chains.add(defaultChain);
            provider.write(chains);
        }
    }
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) JsonNode(com.fasterxml.jackson.databind.JsonNode) TextNode(com.fasterxml.jackson.databind.node.TextNode) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 62 with TextNode

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.node.TextNode in project walkmod-core by walkmod.

the class AbstractYMLConfigurationAction method createTransformation.

public void createTransformation(ObjectNode transformationNode, TransformationConfig transCfg) {
    String name = transCfg.getName();
    if (name != null) {
        transformationNode.set("name", new TextNode(name));
    }
    String typeName = transCfg.getType();
    if (typeName != null) {
        transformationNode.set("type", new TextNode(typeName));
    }
    String mergePolicy = transCfg.getMergePolicy();
    if (mergePolicy != null) {
        transformationNode.set("merge-policy", new TextNode(mergePolicy));
    }
    if (transCfg.isMergeable()) {
        transformationNode.set("isMergeable", BooleanNode.TRUE);
    }
    Map<String, Object> params = transCfg.getParameters();
    if (params != null && !params.isEmpty()) {
        populateParams(transformationNode, params);
    }
}
Also used : TextNode(com.fasterxml.jackson.databind.node.TextNode)

Example 63 with TextNode

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.node.TextNode in project walkmod-core by walkmod.

the class YAMLConfigurationProvider method addPluginConfig.

@Override
public void addPluginConfig(final PluginConfig pluginConfig, boolean recursive) throws TransformerException {
    File cfg = new File(fileName);
    ArrayNode pluginList = null;
    JsonNode node = null;
    try {
        node = mapper.readTree(cfg);
    } catch (Exception e) {
    }
    if (node == null) {
        node = new ObjectNode(mapper.getNodeFactory());
    }
    if (recursive && node.has("modules")) {
        JsonNode aux = node.get("modules");
        if (aux.isArray()) {
            ArrayNode modules = (ArrayNode) aux;
            int max = modules.size();
            for (int i = 0; i < max; i++) {
                JsonNode module = modules.get(i);
                if (module.isTextual()) {
                    String moduleDir = module.asText();
                    try {
                        File auxFile = new File(fileName).getCanonicalFile().getParentFile();
                        YAMLConfigurationProvider child = new YAMLConfigurationProvider(auxFile.getAbsolutePath() + File.separator + moduleDir + File.separator + "walkmod.yml");
                        child.createConfig();
                        child.addPluginConfig(pluginConfig, recursive);
                    } catch (IOException e) {
                        throw new TransformerException(e);
                    }
                }
            }
        }
    } else {
        if (!node.has("plugins")) {
            pluginList = new ArrayNode(mapper.getNodeFactory());
            if (node.isObject()) {
                ObjectNode aux = (ObjectNode) node;
                aux.set("plugins", pluginList);
            } else {
                throw new TransformerException("The root element is not a JSON node");
            }
        } else {
            JsonNode aux = node.get("plugins");
            if (aux.isArray()) {
                pluginList = (ArrayNode) node.get("plugins");
            } else {
                throw new TransformerException("The plugins element is not a valid array");
            }
        }
        pluginList.add(new TextNode(pluginConfig.getGroupId() + ":" + pluginConfig.getArtifactId() + ":" + pluginConfig.getVersion()));
        write(node);
    }
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) JsonNode(com.fasterxml.jackson.databind.JsonNode) TextNode(com.fasterxml.jackson.databind.node.TextNode) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) IOException(java.io.IOException) File(java.io.File) TransformerException(javax.xml.transform.TransformerException) IOException(java.io.IOException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) ConfigurationException(org.walkmod.conf.ConfigurationException) TransformerException(javax.xml.transform.TransformerException)

Example 64 with TextNode

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.node.TextNode in project walkmod-core by walkmod.

the class AddChainYMLAction method doAction.

@Override
public void doAction(JsonNode chainsNode) throws Exception {
    ArrayNode chainsList = null;
    ObjectMapper mapper = provider.getObjectMapper();
    if (chainsNode != null) {
        if (!chainsNode.has("chains")) {
            chainsList = new ArrayNode(mapper.getNodeFactory());
            if (chainsNode.isObject()) {
                ObjectNode aux = (ObjectNode) chainsNode;
                aux.set("chains", chainsList);
            } else {
                throw new TransformerException("The root element is not a JSON node");
            }
        } else {
            JsonNode aux = chainsNode.get("chains");
            if (aux.isArray()) {
                chainsList = (ArrayNode) chainsNode.get("chains");
            } else {
                throw new TransformerException("The plugins element is not a valid array");
            }
        }
    }
    ObjectNode chainNode = new ObjectNode(mapper.getNodeFactory());
    ReaderConfig readerCfg = chainCfg.getReaderConfig();
    if (readerCfg != null) {
        if (chainsNode == null) {
            chainsNode = new ObjectNode(mapper.getNodeFactory());
            ObjectNode aux = (ObjectNode) chainsNode;
            chainsList = new ArrayNode(mapper.getNodeFactory());
            aux.set("chains", chainsList);
        }
        ObjectNode readerNode = new ObjectNode(mapper.getNodeFactory());
        chainNode.set("reader", readerNode);
        populateWriterReader(readerNode, readerCfg.getPath(), readerCfg.getType(), readerCfg.getIncludes(), readerCfg.getExcludes(), readerCfg.getParameters());
    } else {
        provider.addDefaultReaderConfig(chainCfg);
    }
    WalkerConfig walkerCfg = chainCfg.getWalkerConfig();
    if (walkerCfg != null) {
        ObjectNode walkerNode = null;
        String type = walkerCfg.getType();
        if (type != null) {
            if (chainsNode == null) {
                chainsNode = new ObjectNode(mapper.getNodeFactory());
                ObjectNode aux = (ObjectNode) chainsNode;
                chainsList = new ArrayNode(mapper.getNodeFactory());
                aux.set("chains", chainsList);
            }
            walkerNode = new ObjectNode(mapper.getNodeFactory());
            chainNode.set("walker", walkerNode);
            walkerNode.set("type", new TextNode(type));
        }
        Map<String, Object> wparams = walkerCfg.getParams();
        if (wparams != null && !wparams.isEmpty()) {
            if (walkerNode == null) {
                if (chainsNode == null) {
                    chainsNode = new ObjectNode(mapper.getNodeFactory());
                    ObjectNode aux = (ObjectNode) chainsNode;
                    chainsList = new ArrayNode(mapper.getNodeFactory());
                    aux.set("chains", chainsList);
                }
                walkerNode = new ObjectNode(mapper.getNodeFactory());
                chainNode.set("walker", walkerNode);
            }
            populateParams(walkerNode, wparams);
        }
        String rootNamespace = walkerCfg.getRootNamespace();
        if (rootNamespace != null) {
            if (walkerNode == null) {
                if (chainsNode == null) {
                    chainsNode = new ObjectNode(mapper.getNodeFactory());
                    ObjectNode aux = (ObjectNode) chainsNode;
                    chainsList = new ArrayNode(mapper.getNodeFactory());
                    aux.set("chains", chainsList);
                }
                walkerNode = new ObjectNode(mapper.getNodeFactory());
                chainNode.set("walker", walkerNode);
            }
            walkerNode.set("root-namespace", new TextNode(rootNamespace));
        }
        List<TransformationConfig> transformationList = walkerCfg.getTransformations();
        if (transformationList != null && !transformationList.isEmpty()) {
            ArrayNode transformationListNode = new ArrayNode(mapper.getNodeFactory());
            if (walkerNode == null) {
                if (chainsNode == null) {
                    ObjectNode aux = new ObjectNode(mapper.getNodeFactory());
                    aux.set("transformations", transformationListNode);
                    chainsNode = aux;
                } else {
                    chainNode.set("transformations", transformationListNode);
                }
            } else {
                walkerNode.set("transformations", transformationListNode);
            }
            for (TransformationConfig transCfg : transformationList) {
                ObjectNode transformationNode = new ObjectNode(mapper.getNodeFactory());
                transformationListNode.add(transformationNode);
                createTransformation(transformationNode, transCfg);
            }
        }
    }
    WriterConfig writerCfg = chainCfg.getWriterConfig();
    if (writerCfg != null) {
        if (chainsNode == null) {
            chainsNode = new ObjectNode(mapper.getNodeFactory());
            ObjectNode aux = (ObjectNode) chainsNode;
            chainsList = new ArrayNode(mapper.getNodeFactory());
            aux.set("chains", chainsList);
        }
        ObjectNode writerNode = new ObjectNode(mapper.getNodeFactory());
        chainNode.set("writer", writerNode);
        populateWriterReader(writerNode, writerCfg.getPath(), writerCfg.getType(), writerCfg.getIncludes(), writerCfg.getExcludes(), writerCfg.getParams());
    } else {
        provider.addDefaultWriterConfig(chainCfg);
    }
    if (chainsList != null) {
        int beforePos = -1;
        if (before != null) {
            Iterator<JsonNode> it = chainsList.iterator();
            int i = 0;
            while (it.hasNext() && beforePos == -1) {
                JsonNode next = it.next();
                if (next.get("name").equals(before)) {
                    beforePos = i;
                }
                i++;
            }
        }
        if (beforePos == -1) {
            chainsList.add(chainNode);
        } else {
            chainsList.insert(beforePos, chainNode);
        }
    }
    if (readerCfg != null || walkerCfg != null || writerCfg != null) {
        provider.write(chainsNode);
    }
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) WalkerConfig(org.walkmod.conf.entities.WalkerConfig) TransformationConfig(org.walkmod.conf.entities.TransformationConfig) JsonNode(com.fasterxml.jackson.databind.JsonNode) TextNode(com.fasterxml.jackson.databind.node.TextNode) WriterConfig(org.walkmod.conf.entities.WriterConfig) ReaderConfig(org.walkmod.conf.entities.ReaderConfig) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) TransformerException(javax.xml.transform.TransformerException)

Example 65 with TextNode

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.node.TextNode in project walkmod-core by walkmod.

the class AddIncludesOrExcludesYMLAction method doAction.

@Override
public void doAction(JsonNode node) throws Exception {
    if (chain == null) {
        chain = "default";
    }
    ObjectMapper mapper = provider.getObjectMapper();
    if (node.has("chains")) {
        JsonNode chains = node.get("chains");
        if (chains.isArray()) {
            ArrayNode chainsArray = (ArrayNode) chains;
            int limit = chainsArray.size();
            ObjectNode selectedChain = null;
            for (int i = 0; i < limit && selectedChain == null; i++) {
                JsonNode chainNode = chainsArray.get(i);
                if (chainNode.has("name")) {
                    if (chainNode.get("name").asText().equals(chain)) {
                        selectedChain = (ObjectNode) chainNode;
                    }
                }
            }
            if (selectedChain == null) {
                selectedChain = new ObjectNode(mapper.getNodeFactory());
                selectedChain.set("name", new TextNode(chain));
                chainsArray.add(selectedChain);
            }
            if (setToReader) {
                JsonNode reader = null;
                if (selectedChain.has("reader")) {
                    reader = selectedChain.get("reader");
                } else {
                    reader = new ObjectNode(mapper.getNodeFactory());
                    selectedChain.set("reader", reader);
                }
                setIncludesOrExcludesList((ObjectNode) reader);
            }
            if (setToWriter) {
                JsonNode reader = null;
                if (selectedChain.has("writer")) {
                    reader = selectedChain.get("writer");
                } else {
                    reader = new ObjectNode(mapper.getNodeFactory());
                    selectedChain.set("writer", reader);
                }
                setIncludesOrExcludesList((ObjectNode) reader);
            }
        }
    } else {
        ObjectNode root = (ObjectNode) node;
        if (node.has("transformations")) {
            JsonNode transformations = node.get("transformations");
            root.remove("transformations");
            ObjectNode chainNode = new ObjectNode(mapper.getNodeFactory());
            chainNode.set("name", new TextNode("default"));
            chainNode.set("transformations", transformations);
            ArrayNode chains = new ArrayNode(mapper.getNodeFactory());
            chains.add(chainNode);
            if (!chain.equals("default")) {
                chainNode = new ObjectNode(mapper.getNodeFactory());
                chainNode.set("name", new TextNode(chain));
                chains.add(chainNode);
            }
            ObjectNode reader = new ObjectNode(mapper.getNodeFactory());
            setIncludesOrExcludesList(reader);
            chainNode.set("reader", reader);
            ObjectNode writer = new ObjectNode(mapper.getNodeFactory());
            setIncludesOrExcludesList(writer);
            chainNode.set("writer", writer);
            root.set("chains", chains);
        } else if (!node.has("modules")) {
            ObjectNode chainNode = new ObjectNode(mapper.getNodeFactory());
            chainNode.set("name", new TextNode("default"));
            ArrayNode chains = new ArrayNode(mapper.getNodeFactory());
            chains.add(chainNode);
            ObjectNode reader = new ObjectNode(mapper.getNodeFactory());
            setIncludesOrExcludesList(reader);
            chainNode.set("reader", reader);
            ObjectNode writer = new ObjectNode(mapper.getNodeFactory());
            setIncludesOrExcludesList(writer);
            chainNode.set("writer", writer);
            root.set("chains", chains);
        }
    }
    provider.write(node);
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) JsonNode(com.fasterxml.jackson.databind.JsonNode) TextNode(com.fasterxml.jackson.databind.node.TextNode) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Aggregations

TextNode (com.fasterxml.jackson.databind.node.TextNode)140 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)48 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)37 Test (org.junit.Test)37 JsonNode (com.fasterxml.jackson.databind.JsonNode)34 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)16 IntNode (com.fasterxml.jackson.databind.node.IntNode)16 ArrayList (java.util.ArrayList)16 Test (org.junit.jupiter.api.Test)15 MockScheduler (org.apache.kafka.common.utils.MockScheduler)14 MockTime (org.apache.kafka.common.utils.MockTime)14 ExpectedTaskBuilder (org.apache.kafka.trogdor.common.ExpectedTasks.ExpectedTaskBuilder)14 ExpectedTasks (org.apache.kafka.trogdor.common.ExpectedTasks)13 DoubleNode (com.fasterxml.jackson.databind.node.DoubleNode)12 WorkerRunning (org.apache.kafka.trogdor.rest.WorkerRunning)12 TreeNode (com.fasterxml.jackson.core.TreeNode)11 HashMap (java.util.HashMap)11 List (java.util.List)11 NoOpTaskSpec (org.apache.kafka.trogdor.task.NoOpTaskSpec)11 Map (java.util.Map)10