1

I have a Spring web application(built in maven) with which I connect to my spark cluster(4 workers and 1 master) and to my cassandra cluster(4 nodes). The application starts, the workers communicate with the master and the cassandra cluster is also running. However when I do a PCA(spark mllib) or any other calculation(clustering, pearson, spearman) through the interface of my web-app I get the following error:

java.lang.ClassCastException: cannot assign instance of scala.collection.immutable.List$SerializationProxy to field org.apache.spark.rdd.RDD.org$apache$spark$rdd$RDD$$dependencies_ of type scala.collection.Seq in instance of org.apache.spark.rdd.MapPartitionsRDD

This error must be because of conflicting Jars between spring-boot-maven-plugin and apache spark.

This is my pom.xml:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.example</groupId>
    <artifactId>app</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>jar</packaging>

    <name>springapp</name>
    <description>Demo project for Spring Boot</description>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <java.version>1.8</java.version>
                <maven.compiler.source>1.8</maven.compiler.source>
                <maven.compiler.target>1.8</maven.compiler.target>
    </properties>

        <build>
            <plugins>
                <plugin>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-maven-plugin</artifactId>
                    <version>2.0.9.RELEASE</version>
                    <executions>
                    <execution>
                        <goals>
                            <goal>repackage</goal>
                        </goals>
                    </execution>
                </executions>
                    <configuration>
                        <requiresUnpack>
                            <dependency>
                                <groupId>org.apache.spark</groupId>
                                <artifactId>spark-core_2.11</artifactId>
                            </dependency>
                            <dependency>
                                <groupId>org.apache.spark</groupId>
                                <artifactId>spark-streaming_2.11</artifactId>
                            </dependency>

                        </requiresUnpack>
                    </configuration>
                </plugin>
              </plugins>
    </build>
        <dependencies>
            <dependency>
                <groupId>org.apache.spark</groupId>
                <artifactId>spark-mllib_2.11</artifactId>
                <version>2.4.3</version>
            </dependency>
            <dependency>
                <groupId>com.datastax.spark</groupId>
                <artifactId>spark-cassandra-connector-unshaded_2.11</artifactId>
                <version>2.4.0</version>
                <exclusions>
                    <exclusion>
                        <groupId>io.netty</groupId>
                        <artifactId>netty-all</artifactId>
                    </exclusion>
                  </exclusions>
            </dependency>
            <dependency>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-starter-thymeleaf</artifactId>
                    <version>2.0.9.RELEASE</version>
                    <exclusions>
                        <exclusion>
                          <groupId>org.springframework.boot</groupId>
                          <artifactId>spring-boot-starter-logging</artifactId>
                        </exclusion>
                      </exclusions>
            </dependency>
            <dependency>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-starter-web</artifactId>
                    <version>2.0.9.RELEASE</version>
                    <exclusions>
                        <exclusion>
                          <groupId>org.springframework.boot</groupId>
                          <artifactId>spring-boot-starter-logging</artifactId>
                        </exclusion>
                      </exclusions>
            </dependency>
            <dependency>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-starter-test</artifactId>
                    <version>2.0.9.RELEASE</version>
                    <scope>test</scope>
                    <exclusions>
                        <exclusion>
                          <groupId>org.springframework.boot</groupId>
                          <artifactId>spring-boot-starter-logging</artifactId>
                        </exclusion>
                      </exclusions>
            </dependency>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-data-cassandra</artifactId>
                <version>2.0.9.RELEASE</version>
            </dependency>
            <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-configuration-processor</artifactId>
            <version>2.0.9.RELEASE</version>
         </dependency>
         <dependency>
            <groupId>com.google.code.gson</groupId>
            <artifactId>gson</artifactId>
            <version>2.8.5</version>
        </dependency>
         <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-databind</artifactId>
            <version>2.9.8</version>
        </dependency>
        <dependency>
            <groupId>com.fasterxml.jackson.module</groupId>
            <artifactId>jackson-module-scala_2.11</artifactId>
            <version>2.9.8</version>
        </dependency>
    </dependencies>
</project>

and these are the jars of my web-app:

1 2 3 4 5

Do you see something that would cause a conflict with apache-spark 2.4.3 and should be excluded from the pom?

Des0lat0r
  • 482
  • 3
  • 18
  • Why do you conclude that this is the cause? – Thorbjørn Ravn Andersen Sep 19 '19 at 15:43
  • I have made an example of PCA with just using spark 2.4.3 and cassandra(no spring interface) and if I run it on my cluster(java -jar app-0.0.1-SNAPSHOT.jar) it works! But if I add spring-boot-maven-plugin I get this error. I have tried many and different approaches I came across. In this [post](https://stackoverflow.com/questions/57412125/how-to-fix-classcastexception-cannot-assign-instance-of-works-local-but-not) I am explaining it with more details. Thanks a lot for your answer! – Des0lat0r Sep 19 '19 at 16:18
  • Please if you think that this is not because of conflicting jars, let me know! I ave spent too much time on this! – Des0lat0r Sep 19 '19 at 19:25
  • I have no idea. These ClassCastExceptions are typically caused by trying to cast an object created by one classloader to a class provided by a different classloader which will always fail by definition. – Thorbjørn Ravn Andersen Sep 23 '19 at 15:07
  • Solved it! I had to change plugin from spring-boot-maven-plugin to maven-shade-plugin. Maybe you are right. – Des0lat0r Sep 24 '19 at 09:52
  • Eh, that is an interesting change. Are you absolutely certain you know what you are doing? – Thorbjørn Ravn Andersen Sep 24 '19 at 13:05
  • 1
    Don't do this. Reword your question to become better. I would actually suggest writing your finding up as an answer. – Thorbjørn Ravn Andersen Sep 25 '19 at 12:22
  • Sorry for this outlook but it seems I still cann't post any answer. – Des0lat0r Sep 25 '19 at 12:28
  • Really sorry for this, I guess I need some good feedback in order to be able to post an answer again. Thank you for your time! – Des0lat0r Sep 25 '19 at 12:31
  • Earn some more reputation then. It will make your life on SO much easier. – Thorbjørn Ravn Andersen Sep 25 '19 at 12:31
  • Infinite thanks @ThorbjørnRavnAndersen !!! Posted it correctly as an answer! – Des0lat0r Sep 25 '19 at 12:35

1 Answers1

1

Solved! I just had to change plugin. Maybe there was a conflict between jars.

This is what I had:

            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <version>2.0.9.RELEASE</version>
                <executions>
                <execution>
                    <goals>
                        <goal>repackage</goal>
                    </goals>
                </execution>
            </executions>
                <configuration>
                    <requiresUnpack>
                        <dependency>
                            <groupId>org.apache.spark</groupId>
                            <artifactId>spark-core_2.11</artifactId>
                        </dependency>
                        <dependency>
                            <groupId>org.apache.spark</groupId>
                            <artifactId>spark-streaming_2.11</artifactId>
                        </dependency>

                    </requiresUnpack>
                </configuration>
            </plugin>

and I replaced it with:

<plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>3.8.0</version>
        <configuration>
            <source>1.8</source>
            <target>1.8</target>
        </configuration>
    </plugin>

and

<plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-shade-plugin</artifactId>
        <version>2.4.1</version>
        <dependencies>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <version>2.0.9.RELEASE</version>
            </dependency>
        </dependencies>
        <configuration>
            <keepDependenciesWithProvidedScope>true</keepDependenciesWithProvidedScope>
            <createDependencyReducedPom>true</createDependencyReducedPom>
            <filters>
                <filter>
                    <artifact>*:*</artifact>
                    <excludes>
                        <exclude>META-INF/*.SF</exclude>
                        <exclude>META-INF/*.DSA</exclude>
                        <exclude>META-INF/*.RSA</exclude>
                    </excludes>
                </filter>
            </filters>
        </configuration>
        <executions>
            <execution>
                <phase>package</phase>
                <goals>
                    <goal>shade</goal>
                </goals>
                <configuration>
                    <transformers>
                        <transformer
                            implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
                            <resource>META-INF/spring.handlers</resource>
                        </transformer>
                        <transformer
                            implementation="org.springframework.boot.maven.PropertiesMergingResourceTransformer">
                            <resource>META-INF/spring.factories</resource>
                        </transformer>
                        <transformer
                            implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
                            <resource>META-INF/spring.schemas</resource>
                        </transformer>
                        <transformer
                            implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer" />
                        <transformer
                            implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                            <mainClass>com.example.app.Mtbapp1</mainClass>
                        </transformer>
                    </transformers>
                </configuration>
            </execution>
        </executions>
    </plugin>
Des0lat0r
  • 482
  • 3
  • 18