10

I'm getting clusters by cloudera-manager-api.

I'm using Maven shade-plugin .

There is another question relating to null pointer exceptions, but this doesn't solve my particular problem. It looks like a dependency issue because if I run the app in my IDE it works fine.

When I run the self-packaged jar it fails, What dependency could I be missing?

source is below

    String host = HOST_PREFIX + args[0];
    String command = args[1];

    RootResourceV10 apiRoot = new ClouderaManagerClientBuilder()
            .withHost(host).withPort(7180)
            .withUsernamePassword(ADMIN, ADMIN).build().getRootV10();

    if (apiRoot == null) {
        System.exit(0);
    }

    ClustersResourceV10 clusterResource = apiRoot.getClustersResource();


    try {

        if (command.equals(START)) {

            System.out.println("starting..");

            ApiCommand cmd = apiRoot.getClustersResource().startCommand(
                    "cluster"
                    );
            while (cmd.isActive()) {
                cmd = apiRoot.getCommandsResource()
                        .readCommand(cmd.getId());
            }
        } else {
            System.out.println("stopping..");

            ApiCommand cmdstop = apiRoot.getClustersResource().stopCommand(
                    "cluster"
                    );
            while (cmdstop.isActive()) {
                cmdstop = apiRoot.getCommandsResource().readCommand(
                        cmdstop.getId());
            }

        }
    } catch (NullPointerException e) {
        e.printStackTrace();
    }

}

Error message is below {

java.lang.NullPointerException
        at org.apache.cxf.jaxrs.client.AbstractClient.setupOutInterceptorChain(AbstractClient.java:850)
        at org.apache.cxf.jaxrs.client.AbstractClient.createMessage(AbstractClient.java:900)
        at org.apache.cxf.jaxrs.client.ClientProxyImpl.doChainedInvocation(ClientProxyImpl.java:522)
        at org.apache.cxf.jaxrs.client.ClientProxyImpl.invoke(ClientProxyImpl.java:206)
        at com.sun.proxy.$Proxy23.startCommand(Unknown Source)
        at com.worksap.company.cloudera.cluster.manage.ClusterManager.main(ClusterManager.java:48)

pom.xml is below

<?xml version="1.0" encoding="UTF-8"?>
<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>jp.co.ltd</groupId>
    <artifactId>cluster-manager</artifactId>
    <version>1.0.0-SNAPSHOT</version>
    <packaging>jar</packaging>

    <repositories>
        <repository>
            <id>cdh.repo</id>
            <url>https://repository.cloudera.com/artifactory/cloudera-repos</url>
            <name>Cloudera Repository</name>
        </repository>
    </repositories>

    <properties>
        <cxf.version>2.7.5</cxf.version>
        <guava.version>14.0</guava.version>
        <jackson2.version>2.1.0</jackson2.version>
        <joda.version>2.1</joda.version>
        <junit.version>4.11</junit.version>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <test.redirectToFile>true</test.redirectToFile>
        <privateClassPath>com.cloudera.api.shaded</privateClassPath>
    </properties>

    <dependencies>
        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-databind</artifactId>
            <version>2.2.0</version>
        </dependency>
        <dependency>
            <groupId>com.cloudera.api</groupId>
            <artifactId>cloudera-manager-api</artifactId>
            <version>5.4.0</version>
        </dependency>
        <dependency>
            <groupId>org.apache.cxf</groupId>
            <artifactId>cxf-rt-transports-http</artifactId>
            <version>${cxf.version}</version>
        </dependency>
        <dependency>
            <groupId>org.apache.cxf</groupId>
            <artifactId>cxf-rt-frontend-jaxrs</artifactId>
            <version>${cxf.version}</version>
        </dependency>
        <dependency>    
            <groupId>commons-lang</groupId>
            <artifactId>commons-lang</artifactId>
            <version>2.6</version>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-api</artifactId>
            <version>1.7.8</version>
        </dependency>
        <dependency>
            <groupId>log4j</groupId>
            <artifactId>log4j</artifactId>
            <version>1.2.17</version>
        </dependency>

    </dependencies>
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-shade-plugin</artifactId>
                <version>2.1</version>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>shade</goal>
                        </goals>
                        <configuration>
                            <minimizeJar>false</minimizeJar>
                            <createDependencyReducedPom>false</createDependencyReducedPom>
                            <transformers>
                                <transformer
                                    implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
                                    <resource>META-INF/spring.handlers</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.ManifestResourceTransformer">
                                    <mainClass>com.worksap.company.sample.spark.batch.SparkSample</mainClass>
                                </transformer>
                            </transformers>
                            <shadedArtifactAttached>true</shadedArtifactAttached>
                            <shadedClassifierName>jar-with-dependencies</shadedClassifierName>
                            <configuration>
                                <filters>
                                    <filter>
                                        <artifact>*:*</artifact>
                                        <excludes>
                                            <exclude>META-INF/*.SF</exclude>
                                            <exclude>META-INF/*.DSA</exclude>
                                            <exclude>META-INF/*.RSA</exclude>
                                        </excludes>
                                    </filter>
                                </filters>
                                <!-- Additional configuration. -->
                            </configuration>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <artifactId>maven-assembly-plugin</artifactId>
                <version>2.5.2</version>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.2</version>
                <configuration>
                    <source>1.6</source>
                    <target>1.6</target>
                    <compilerArguments>
                        <extdirs>lib</extdirs>
                    </compilerArguments>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>
Community
  • 1
  • 1
uipiki
  • 109
  • 1
  • 3
  • Are you using Eclipse or IntelliJ (or possibly Netbeans) ? – Tim Biegeleisen Jul 01 '15 at 08:42
  • 1
    A NullPointerException is the result of you trying to get a value from a variable which was not defined. Problems with dependencies usually result in code that will not be compiled, or an error like ClassNotFoundException – Danielson Jul 01 '15 at 08:43
  • Can you point to where the error occurs? By, if possible, clicking on (ClusterManager.java:48) <-- which line is that? – Danielson Jul 01 '15 at 08:44
  • If you really do have a dependency issue you can compare the classpath used by the IDE against the dependencies listed in your POM. Anything which the former has but the latter does _not_ have is a candidate for the root cause. – Tim Biegeleisen Jul 01 '15 at 08:45
  • @Rajesh I would think then must be because of `START`, since command cannot be null, because if args[1] did not exist, Uipiki should get an IndexOutOfBoundException first – Danielson Jul 01 '15 at 08:53
  • @Danielson > Can you point to where the error occurs? By, if possible, clicking on (ClusterManager.java:48) <-- which line is that? That is below 'ApiCommand cmd = apiRoot.getClustersResource().startCommand( "cluster" );' – uipiki Jul 01 '15 at 09:00
  • can you assign 'apiRoot.getClustersResource()' as variable (instead of calling its result directly), and see print its value (i.e. see if it is null). Likewise with apiRoot... Perhaps something goes wrong there, you haven't called it before... – Danielson Jul 01 '15 at 09:07
  • I implements below `ClustersResourceV10 cr = apiRoot.getClustersResource(); System.out.println("clusterResource1 :" + cr.toString()); System.out.println("clusterResource2 :" + cr.getServicesResource("cluster")); System.out.println("clusterResource3 :" + cr.startCommand("cluster"));` Results is below `clusterResource1 :org.apache.cxf.jaxrs.client.ClientProxyImpl@190cc39e; clusterResource2 :org.apache.cxf.jaxrs.client.ClientProxyImpl@48b1b469; java.lang.NullPointerException; at org.apache.cxf.jaxrs.client.AbstractClient.setupOutInterceptorChain(AbstractClient.java:850)` – uipiki Jul 01 '15 at 10:22

1 Answers1

22

I ran into the same issue and found this solution:

https://cxf.apache.org/docs/bundling-cxf-into-single-jar-with-maven-shade-plugin.html

CXF uses bus-extensions.txt files to connect modules, they must be included in the jar. So add this to your transformers section:

<transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
  <resource>META-INF/cxf/bus-extensions.txt</resource>
</transformer>
lmsurprenant
  • 1,723
  • 2
  • 14
  • 28
Stephan
  • 4,395
  • 3
  • 26
  • 49
  • 1
    Whilst this may theoretically answer the question, [it would be preferable](//meta.stackoverflow.com/q/8259) to include the essential parts of the answer here, and provide the link for reference. – NathanOliver Nov 13 '15 at 16:15
  • 1
    Perfect. I was facing the same issue and this worked like a charm !! – V_Singh Aug 13 '16 at 00:05
  • There can be several "tranformers" sections in your pom. I had to make sure it was in the shade section. – markthegrea Feb 05 '19 at 19:59