ILOG JRules User Guide > Running and Debugging > Getting Started > Tutorial: Debugging a Remote Rule Execution Server Application > Task 4: Debugging a Remote Ruleset in Rule Studio

This task describes how to debug a ruleset, deploy the corrected ruleset and test the execution of the corrected ruleset.

The corrected rule project is provided in <InstallDir>/executionserver/tutorials/resdebugging/task4.

Step 1: Adding a Breakpoint in the Computation Task

You add breakpoints in the computation task using Rule Studio.

To add a breakpoint in the computation task:

  1. In the Rule Explorer, in the loanvalidation-rules rule project, open the rules folder, and double-click the loanvalidation ruleflow.
  2. The Ruleflow Editor opens.
    images/computationtask.png
  3. In the ruleflow diagram, right-click the computation task, then click Toggle Breakpoint.
  4. On the Window menu, click Show View > Other.
  5. In the Show View dialog, under Debug, click Breakpoints, then click OK.
  6. The Breakpoints view is displayed:
    images/breakpointview.png

Step 2: Creating a Remote Java Application With Rules Launch Configuration

You create a launch configuration using the Open Debug Dialog.

To create a remote Java application with a rules launch configuration:

  1. On the Run menu, click Open Debug Dialog.
  2. In the list of configurations in the Debug dialog, select Remote Java Applications With Rules, and then click New.
  3. Change the text in the Name field to loanvalidation-debug.
  4. Enter the value 7777 or the debug port value used by the your application server in the Port field under Connection Properties.
  5. In the Project field, click Browse.
  6. Select the loanvalidation-xom project, then click OK.
  7. images/loanvalidconfig.png
  8. Click the Source tab.
  9. The Source panel is displayed.
  10. Clear the Use default source lookup path check box.
  11. Click the Rule Source Path tab.
  12. The Rule Source Path panel is displayed.
  13. Click Add Rule Project.
  14. Select the loanvalidation-rules rule project in the dialog, then click OK.
  15. images/loanvalidconfigIRL.png
  16. Click Apply.
  17. Click Debug.
  18. Wait for the debugger to connect and the server to start.

Step 3: Executing the Ruleset Using the SSP Client

You can execute the ruleset using an SSP client. You can do this from the Rule Execution Server Console.

To execute the ruleset using an SSP client:

  1. Log in to the Rule Execution Server Console.
  2. In the loanvalidationrules Ruleset View, click Test Ruleset on the menu bar.
  3. In the Value column for the borrower parameter, click Edit mode and enter the following value:
  4. import loan.*;
    loan.Borrower borrower = new loan.Borrower("John","Doe",loan.DateUtil.makeDate(1968,java.util.Calendar.MAY,12),"123456789");
    borrower.setZipCode("91320");
    borrower.setCreditScore(600);
    borrower.setYearlyIncome(100000);
  5. Click Visualization mode to save the value.
  6. In the Value column for the loan parameter, click Edit mode and enter the following value:
  7. import loan.*;
    loan.Loan loan = new loan.Loan(loan.DateUtil.makeDate(2005,java.util.Calendar.JUNE,1),72,100000,0.7d);
  8. Enter a value for the Execution URL.
  9. The default URLs for the deployed EAR file are as follows:
    - WebSphere: [http://localhost:9080/LoanValidationTest]
    - WebLogic: [http://localhost:7001/LoanValidationTest]
    - JBoss: [http://localhost:8080/LoanValidationTest]
    - Oracle: [http://localhost:8888/LoanValidationTest]
    - SunAS 82: [http://localhost:8080/LoanValidationTest]
  10. Click Execute.
  11. Rule Studio alerts you that the debugger has connected to the open virtual machine (VM):
    images/debugswitch.png
  12. In the Confirm Perspective Switch dialog, click Yes.
  13. Eclipse opens the Debug perspective. You are now ready to perform remote debugging in Rule Studio.

Step 4: Debugging the Ruleset in Rule Studio

The debugger will have stopped the execution in the ruleflow at the breakpoint you added to the computation task earlier.

images/debugstoptask.png

To debug the ruleset:

  1. In Rule Studio, on the Run menu, click Step Into.
  2. The initialCorporateScore rule is displayed.
    images/corporatescore.png
  3. On the Window menu, click Show View > Other > Debug > Agenda.
  4. images/debugstepinto.png
    There are 5 rules in the agenda:
    initCorporateScore
    neverBankruptcy
    salary2Score_5
    repayment
    rate_5
    The repayment rule is before the rate_5 rule in the agenda. This is not the desired order because the repayment calculation uses the rate values.
  5. On the Window menu, click Open Perspective > Other > Rule, then click OK.
  6. In the Rule Explorer, under the rules folder, open the computation package, and then double-click the repayment rule.
  7. In the Intellirule Editor, right-click in the left margin of the line following the then statement, and then click Toggle Breakpoint.
  8. A breakpoint is visible in the editor:
    images/repaymentbreakpoint.png
  9. On the Window menu, click Open Perspective > Other > Debug, then click OK.
  10. On the Run menu, click Resume.
  11. The debugger has stopped the execution at the breakpoint you added to the repayment rule.
    images/repayment.png
  12. On the Window menu, click Show View > Variables.
  13. In the Variables view, click the rate variable.
  14. images/variablesview.png
    The loan repayment is calculated at the following line in the repayment rule:
    loan.monthlyRepayment = loan.LoanUtil.getMonthlyRepayment((double)(amount), duration, rate);
    The value is calculated using the rate variable value, which is set to 0.0. The rate value has not been computed yet because of the order of the rules in the agenda.
    The rate rule is after the repayment rule in the agenda because it has the same priority, and there is currently no way to ensure the order in which these two rules are fired.
  15. On the Run menu, click Resume.
  16. Open the Rule Execution Server Console.
  17. In the Test Ruleset View, look at the execution results.
  18. images/executiontrace.png
    In the list of rules fired you can see that indeed the replayment rule was executed before the rate_5 rule.

Step 5: Correcting the Bug in the Ruleset

You can change the order in which rules are fired. In this step, you correct the bug in the ruleset by changing the rule order so that the rate rule is fired before the repayment rule.

To change the rule order:

  1. In Rule Studio, on the Window menu, click Open Perspective > Other > Rule, then click OK.
  2. In the Rule Explorer, open the loanvalidation-rules > rules > computation package, and then double-click the repayment rule.
  3. In the Intellirule Editor, add the following lines after the last definition:
if
   the yearly interest rate of 'the loan' is more than 0
  1. On the File menu, click Save.
  2. images/repayment_update.png

Step 6: Deploying the Corrected Ruleset to Rule Execution Server

Having corrected the ruleset, you now need to deploy the corrected ruleset to Rule Execution Server.

To deploy the corrected ruleset:

  1. In the Rule Explorer, open the loanvalidation RuleApp project, and double-click the archive.xml file.
  2. In the RuleApp Editor, click the Ruleset Archives tab.
  3. Select loanvalidationrules in the list of ruleset archives, then click Refresh.
  4. Under Ruleset Properties, change the Version number from 1.0 to 1.1.
  5. images/ruleapp_version.png
  6. Click the Overview tab, then click Deploy.
  7. Change the default deployment type to Replace RuleApp Version, then click Next.
  8. images/replace_ruleapp.png
  9. Make sure the Create a temporary Rule Execution Server configuration option is selected.
  10. Enter the URL, the login, and the password according to where you have deployed the Rule Execution Server Console, then click Finish.
  11. You should receive the following message in the Console:
    The "loanvalidation" RuleApp project was successfully deployed on the "temporaryServer" configuration.

Step 7: Verifying the RuleApp Update in the Rule Execution Server Console

You now need to check the updated RuleApp. You do this in the Rule Execution Server Console.

To verify the RuleApp update:

  1. Open the Rule Execution Server Console.
  2. In the Navigator pane, click RuleApps > /loanvalidation/1.0/.
  3. The loanvalidation RuleApp View is displayed.
    images/ruleapp_update.png
    You can see that the version of the ruleset is now 1.1.
  4. Click loanvalidationrules in the ruleset table.
  5. In the Ruleset view, click Show Archive Content.
  6. Expand the IRL folder, and then expand the computation package.
  7. Select the repayment-brl.irl rule.
  8. The repayment-brl rule is displayed:
    images/repaymentirl.png
    The following two lines:
    if
       the yearly interest rate of 'the loan' is more than 0
    have been translated into the following line:
    evaluate (loan.yearlyInterestRate > (double)(0));

The ruleset has been updated.

Step 8: Verifying that the Application is Corrected

To check that the application has been corrected, you can execute the loan validation application a second time.

To execute the loan validation application:

  1. Open a browser and enter the URL where the loan validation application was deployed.
  2. If you use the JBoss server provided with JRules, use the following URL:
http://localhost:8080/LoanValidation
  1. Click Start loan validation.
  2. Leave the default borrower information.
  3. Click Next Step.
  4. Leave the default loan information.
  5. Click Calculate loan.
  6. The expected result is a report that validates the loan application:
    images/correctedresult.png

Congratulations!  
Congratulations! You have completed this tutorial and successfully debugged a ruleset on a remote application server. 

Related Concepts

Tutorial Scenario
Task 1: Deploying the Loan Validation Application

Related Tasks

Creating a Debugger Launch Configuration
Debugging

Related Samples and Tutorials

Tutorial: Debugging a Ruleset