Task 4: Debugging a Remote Ruleset in Rule Studio
|
PREVIOUS
NEXT
|
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:
-
In the Rule Explorer, in the
loanvalidation-rules rule project, open the rules folder, and double-click the loanvalidation ruleflow.
The Ruleflow Editor opens.
-
In the ruleflow diagram, right-click the computation task, then click Toggle Breakpoint.
-
On the Window menu, click Show View > Other.
-
In the Show View dialog, under Debug, click Breakpoints, then click OK.
The Breakpoints view is displayed:
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:
-
On the Run menu, click Open Debug Dialog.
-
In the list of configurations in the Debug dialog, select Remote Java Applications With Rules, and then click New.
-
Change the text in the Name field to
loanvalidation-debug.
-
Enter the value
7777 or the debug port value used by the your application server in the Port field under Connection Properties.
-
In the Project field, click Browse.
-
Select the
loanvalidation-xom project, then click OK.
-
Click the Source tab.
The Source panel is displayed.
-
Clear the Use default source lookup path check box.
-
Click the Rule Source Path tab.
The Rule Source Path panel is displayed.
-
Click Add Rule Project.
-
Select the
loanvalidation-rules rule project in the dialog, then click OK.
-
Click Apply.
-
Click Debug.
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:
-
Log in to the Rule Execution Server Console.
-
In the
loanvalidationrules Ruleset View, click Test Ruleset on the menu bar.
-
In the Value column for the borrower parameter, click Edit mode and enter the following value:
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);
-
Click Visualization mode to save the value.
-
In the Value column for the loan parameter, click Edit mode and enter the following value:
loan.Loan loan = new loan.Loan(loan.DateUtil.makeDate(2005,java.util.Calendar.JUNE,1),72,100000,0.7d);
-
Enter a value for the Execution URL.
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]
-
Click Execute.
Rule Studio alerts you that the debugger has connected to the open virtual machine (VM):
-
In the Confirm Perspective Switch dialog, click Yes.
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.
To debug the ruleset:
-
In Rule Studio, on the Run menu, click Step Into.
The
initialCorporateScore rule is displayed.
-
On the Window menu, click Show View > Other > Debug > Agenda.
There are 5 rules in the agenda:
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.
-
On the Window menu, click Open Perspective > Other > Rule, then click OK.
-
In the Rule Explorer, under the
rules folder, open the computation package, and then double-click the repayment rule.
-
In the Intellirule Editor, right-click in the left margin of the line following the
then statement, and then click Toggle Breakpoint.
A breakpoint is visible in the editor:
-
On the Window menu, click Open Perspective > Other > Debug, then click OK.
-
On the Run menu, click Resume.
The debugger has stopped the execution at the breakpoint you added to the
repayment rule.
-
On the Window menu, click Show View > Variables.
-
In the Variables view, click the
rate variable.
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.
-
On the Run menu, click Resume.
-
Open the Rule Execution Server Console.
-
In the Test Ruleset View, look at the execution results.
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:
-
In Rule Studio, on the Window menu, click Open Perspective > Other > Rule, then click OK.
-
In the Rule Explorer, open the
loanvalidation-rules > rules > computation package, and then double-click the repayment rule.
-
In the Intellirule Editor, add the following lines after the last definition:
the yearly interest rate of 'the loan' is more than 0
-
On the File menu, click Save.
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:
-
In the Rule Explorer, open the
loanvalidation RuleApp project, and double-click the archive.xml file.
-
In the RuleApp Editor, click the Ruleset Archives tab.
-
Select
loanvalidationrules in the list of ruleset archives, then click Refresh.
-
Under Ruleset Properties, change the Version number from
1.0 to 1.1.
-
Click the Overview tab, then click Deploy.
-
Change the default deployment type to Replace RuleApp Version, then click Next.
-
Make sure the Create a temporary Rule Execution Server configuration option is selected.
-
Enter the URL, the login, and the password according to where you have deployed the Rule Execution Server Console, then click Finish.
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:
-
Open the Rule Execution Server Console.
-
In the Navigator pane, click RuleApps > /loanvalidation/1.0/.
The
loanvalidation RuleApp View is displayed.
You can see that the version of the ruleset is now 1.1.
-
Click
loanvalidationrules in the ruleset table.
-
In the Ruleset view, click Show Archive Content.
-
Expand the IRL folder, and then expand the
computation package.
-
Select the
repayment-brl.irl rule.
The
repayment-brl rule is displayed:
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:
-
Open a browser and enter the URL where the loan validation application was deployed.
If you use the JBoss server provided with JRules, use the following URL:
http://localhost:8080/LoanValidation
-
Click Start loan validation.
-
Leave the default borrower information.
-
Click Next Step.
-
Leave the default loan information.
-
Click Calculate loan.
The expected result is a report that validates the loan application:
|
Congratulations! You have completed this tutorial and successfully debugged a ruleset on a remote application server. |
Related Concepts
Related Tasks
Related Samples and Tutorials