Unable to execute CEP pattern in Flink dashboard v

2019-03-04 17:43发布

问题:

I have written a simple pattern like this

   Pattern<JoinedEvent, ?> pattern = Pattern.<JoinedEvent>begin("start")
            .where(new SimpleCondition<JoinedEvent>() {
     @Override
     public boolean filter(JoinedEvent streamEvent) throws Exception {

            return streamEvent.getRRInterval()>= 10 ;
                        }
             }).within(Time.milliseconds(WindowLength));

and it executes well in IntellijIdea. I am using Flink 1.3.2 both in the dashboard and in IntelliJ-Idea. While I was building Flink from source, I have seen a lot of warning messages which led me to believe that iterative condition classes have not been included in a jar as error also says ClassNotFoundException. Below is the error

Caused by: java.lang.NoClassDefFoundError: org/apache/flink/cep/pattern/conditions/IterativeCondition
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Class.java:2701)
at java.lang.Class.privateGetMethodRecursive(Class.java:3048)
at java.lang.Class.getMethod0(Class.java:3018)
at java.lang.Class.getMethod(Class.java:1784)
at 

org.apache.flink.client.program.PackagedProgram.hasMainMethod(PackagedProgram.java:492)
    ... 38 more
Caused by: java.lang.ClassNotFoundException: org.apache.flink.cep.pattern.conditions.IterativeCondition
    at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    ... 44 more

回答1:

After a whole day of my effort to solve this problem, finally, I got the solution. The problem was pretty basic, which is that Flink CEP is not a part of the binary distribution, so whenever I tried to execute pattern it gave me an error.

Solution is simple

As you can see Flink Binary does not have the cep jar.

so go to your IDE which is IntelliJ in my case and copy the required jar

Go to this location and copy paste this jar to lib folder in your binary version.

Yalaa, problem solved



回答2:

If you dont want to add dependencies manually or you have a maven or sbt project, you can simply add the dependency in the .pom file or corresponding sbt file and add the following dependencies.

Change the flink version according to your project needs.

<!-- https://mvnrepository.com/artifact/org.apache.flink/flink-cep_2.11 -->
<dependency>
  <groupId>org.apache.flink</groupId>
  <artifactId>flink-cep_2.11</artifactId>
  <version>1.3.2</version>
</dependency>


// https://mvnrepository.com/artifact/org.apache.flink/flink-cep_2.11
libraryDependencies += "org.apache.flink" % "flink-cep_2.11" % "1.3.2"