1

I'm very new in the debugging the code cloned from the Github. However, till now, I have done below :

  • cloned the repo to my local machine (git clone ) as well as using "sourcetree" software.
  • built the code (mvn clean install)
  • able to import the maven project in IDE (Ecliplse, InteliiJ)
  • After the build completed I'm able to start the application (eg: start.sh) in the target/bin directory which has been created after the build
  • Logged into the application's UI succesfully

Questions: - Now, at this moment I am not sure what is the main class file for aplication and from where and which .java file I shall attach the breakpoint - Once attached the breakpoint how shall I debug it while traversing through the UI.

Can someone please give me a pointer. Thanks in advance! Eg: I'm testing all this on "Apache/NiFi-Registry" project. ref: https://github.com/apache/nifi-registry

OneCricketeer
  • 179,855
  • 19
  • 132
  • 245
Newbie
  • 356
  • 2
  • 9
  • 1
    Main class: https://github.com/apache/nifi-registry/blob/master/nifi-registry-runtime/src/main/java/org/apache/nifi/registry/NiFiRegistry.java#L147 You might use differential code coverage to find out which code is used for which feature. – howlger Aug 25 '18 at 17:14
  • @howlger Thanks! I got the main class but didn't get much about differential code coverage? Shall I start by adding a breakpoint in main class only right? – Newbie Aug 25 '18 at 18:23
  • I'm not able to find the startup script that would allow you to define the remote debugging port. – OneCricketeer Aug 25 '18 at 20:43

1 Answers1

2

You're going to need to edit this line in the nifi-registry.sh script to enable remote debugging

run_nifi_registry_cmd="'${JAVA}' -cp '${BOOTSTRAP_CLASSPATH}' -Xms12m -Xmx24m ${BOOTSTRAP_DIR_PARAMS} org.apache.nifi.registry.bootstrap.RunNiFiRegistry $@"

Is it just me, or is that memory footprint really small?


For example, in Kafka, there is this section of the startup script

# Set Debug options if enabled
if [ "x$KAFKA_DEBUG" != "x" ]; then

    # Use default ports
    DEFAULT_JAVA_DEBUG_PORT="5005"

    if [ -z "$JAVA_DEBUG_PORT" ]; then
        JAVA_DEBUG_PORT="$DEFAULT_JAVA_DEBUG_PORT"
    fi

    # Use the defaults if JAVA_DEBUG_OPTS was not set
    DEFAULT_JAVA_DEBUG_OPTS="-agentlib:jdwp=transport=dt_socket,server=y,suspend=${DEBUG_SUSPEND_FLAG:-n},address=$JAVA_DEBUG_PORT"
    if [ -z "$JAVA_DEBUG_OPTS" ]; then
        JAVA_DEBUG_OPTS="$DEFAULT_JAVA_DEBUG_OPTS"
    fi

    echo "Enabling Java debug options: $JAVA_DEBUG_OPTS"
    KAFKA_OPTS="$JAVA_DEBUG_OPTS $KAFKA_OPTS"
fi

Then it runs eventually ${JAVA} ... ${KAFKA_OPTS}, and if you stop Kafka server and start it with

export KAFKA_DEBUG=y; kafka-server-start ...

Then you can attach a remote debugger on port 5005 by default


I understand you're using NiFi Registry, not Kafka, but basically, you need to add arguments to the JVM and reboot it. You can't just attach to the running Registry and walk through the source code.

Remote debugging a Java application

OneCricketeer
  • 179,855
  • 19
  • 132
  • 245
  • 1
    I have opened [NIFI-5556](https://issues.apache.org/jira/browse/NIFI-5556) to add a similar feature to Apache NiFi & NiFi Registry. Thanks for this answer. – Andy Aug 27 '18 at 15:55