与Ignite

时间:2017-09-21 10:57:35

标签: java ignite apache-zeppelin

我正在发现Apache Ignite并创建了一个类似于他们的字数例子的简单应用程序。它是将多个.txt文件中的单词串行传输到缓存中。我可以在Java应用程序的SqlFieldsQuery类的帮助下查询这些单词。

public class NodeStartup {

    public static void main(String[] args) throws IgniteException {
        // Start Server Node
        Ignition.start("config/example-ignite.xml");
    }
}

public class StreamWordsToCache {
        public static void main(String[] args) throws Exception {
            // Mark the cluster member as a Client
        Ignition.setClientMode(true);

        // Start a Client Node
        try (Ignite ignite = Ignition.start("config/example-ignite.xml")) {
            // Checks if Server nodes not found
            if (!ExamplesUtils.hasServerNodes(ignite))
                return;

            // If cache doesn't exist, create it within the cluster, otherwise use the existing one
            IgniteCache<AffinityUuid, String> theCache = ignite.getOrCreateCache(CacheConfig.wordsCache());

            // Create Streamers for the cache
            try (IgniteDataStreamer<AffinityUuid, String> theStreamer = ignite.dataStreamer(theCache.getName())) {

                //Stream words from articles
                while (true) {
                    File directory = new File("src/main/resources/");
                    if (directory.listFiles() != null) {
                        List<File> filesInDir = new ArrayList<>(Arrays.asList(directory.listFiles()));
                        for (File file : filesInDir) {
                            System.out.println("Start reading file : " + file.getName());
                            try (LineNumberReader lineNumberReader = new LineNumberReader(new FileReader(file))) {
                                for (String line = lineNumberReader.readLine(); line != null; line = lineNumberReader.readLine()) {
                                    for (String word : line.split(" "))
                                        if (!word.isEmpty() && word.matches("(?!(?:that|with|from))\\b(?<!\\b[-.])[^\\d\\W]{4,}+\\b(?![-.]\\b)"))
                                            // Stream words into Ignite
                                            // Unique key (AffinityUuid) is created for each word
                                            // AffinityUuid ensures that identical words are processed on the same cluster node
                                            // in order to process them faster
                                            theStreamer.addData(new AffinityUuid(word), word);
                                }}}}}}}}

现在我决定使用Apache Zeppelin从Ignite缓存中检索这些单词。但由于某种原因,我试图整合Zeppelin和Ignite失败了。我正在按照本教程https://apacheignite-tools.readme.io/docs/apache-zeppelin配置Ignite Interpreter,类似于他们的建议。

enter image description here 首先,我启动Ignite节点和连续将单词流转换为“单词”缓存的客户端节点。然后我试图在Zeppelin笔记中执行SQL查询并不断收到Failed to start Ignite node错误。 enter image description here enter image description here

这种行为可能是什么原因?我项目中使用的Ignite版本是2.1.0,Zeppelin二进制文件是0.7.2,是否会导致问题?或者ignite.jdbc.url属性值可能出现问题?jdbc:ignite://localhost:11211/words

1 个答案:

答案 0 :(得分:2)

您的Zeppelin版本(0.7.2)已通过Apache Ignite 1.9.0认证 因此,我认为您的问题的根本原因是Ignite的不同版本。

看起来Zeppelin的最新代码库支持Apache Ignite 2.1 https://github.com/apache/zeppelin/pull/2549

因此,您可以尝试从源代码构建Zeppelin Ignite Interpreter for Apache Zeppelin