이 콘텐츠는 선택한 언어로 제공되지 않습니다.
Chapter 24. Runtime commands in Red Hat Process Automation Manager
Red Hat Process Automation Manager supports runtime commands that you can send to KIE Server for asset-related operations, such as executing all rules or inserting or retracting objects in a KIE session. The full list of supported runtime commands is located in the org.drools.core.command.runtime package in your Red Hat Process Automation Manager instance.
In the KIE Server REST API, you use the global org.drools.core.command.runtime commands or the rule-specific org.drools.core.command.runtime.rule commands as the request body for POST requests to http://SERVER:PORT/kie-server/services/rest/server/containers/instances/{containerId}. For more information about using the KIE Server REST API, see Chapter 21, KIE Server REST API for KIE containers and business assets.
In the KIE Server Java client API, you can embed these commands in your Java application along with the relevant Java client. For example, for rule-related commands, you use the RuleServicesClient Java client with the embedded commands. For more information about using the KIE Server Java client API, see Chapter 22, KIE Server Java client API for KIE containers and business assets.
24.1. Sample runtime commands in Red Hat Process Automation Manager 링크 복사링크가 클립보드에 복사되었습니다!
The following are sample runtime commands that you can use with the KIE Server REST API or Java client API for asset-related operations in KIE Server:
-
BatchExecutionCommand -
InsertObjectCommand -
RetractCommand -
ModifyCommand -
GetObjectCommand -
GetObjectsCommand -
InsertElementsCommand -
FireAllRulesCommand -
StartProcessCommand -
SignalEventCommand -
CompleteWorkItemCommand -
AbortWorkItemCommand -
QueryCommand -
SetGlobalCommand -
GetGlobalCommand
For the full list of supported runtime commands, see the org.drools.core.command.runtime package in your Red Hat Process Automation Manager instance.
Each command in this section includes a REST request body example (JSON) for the KIE Server REST API and an embedded Java command example for the KIE Server Java client API. The Java examples use an object org.drools.compiler.test.Person with the fields name (String) and age (Integer).
- BatchExecutionCommand
Contains multiple commands to be executed together.
Expand Table 24.1. Command attributes Name Description Requirement commandsList of commands to be executed.
Required
lookupSets the KIE session ID on which the commands will be executed. For stateless KIE sessions, this attribute is required. For stateful KIE sessions, this attribute is optional and if not specified, the default KIE session is used.
Required for stateless KIE session, optional for stateful KIE session
NoteKIE session IDs are in the
kmodule.xmlfile of your Red Hat Process Automation Manager project. To view or add a KIE session ID in Business Central to use with thelookupcommand attribute, navigate to the relevant project in Business Central and go to project SettingsKIE bases KIE sessions. If no KIE bases exist, click Add KIE base KIE sessions to define the new KIE base and KIE sessions. Example JSON request body
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Example Java command
InsertObjectCommand insertCommand = new InsertObjectCommand(new Person("john", 25)); FireAllRulesCommand fireCommand = new FireAllRulesCommand(); BatchExecutionCommand batch = new BatchExecutionCommandImpl(Arrays.asList(insertCommand, fireCommand), "ksession1");InsertObjectCommand insertCommand = new InsertObjectCommand(new Person("john", 25)); FireAllRulesCommand fireCommand = new FireAllRulesCommand(); BatchExecutionCommand batch = new BatchExecutionCommandImpl(Arrays.asList(insertCommand, fireCommand), "ksession1");Copy to Clipboard Copied! Toggle word wrap Toggle overflow Example server response (JSON)
Copy to Clipboard Copied! Toggle word wrap Toggle overflow - InsertObjectCommand
Inserts an object into the KIE session.
Expand Table 24.2. Command attributes Name Description Requirement objectThe object to be inserted
Required
out-identifierID of the
FactHandlecreated from the object insertion and added to the execution resultsOptional
return-objectBoolean to determine whether the object must be returned in the execution results (default:
true)Optional
entry-pointEntry point for the insertion
Optional
Example JSON request body
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Example Java command
Command insertObjectCommand = CommandFactory.newInsert(new Person("john", 25), "john", false, null); ksession.execute(insertObjectCommand);Command insertObjectCommand = CommandFactory.newInsert(new Person("john", 25), "john", false, null); ksession.execute(insertObjectCommand);Copy to Clipboard Copied! Toggle word wrap Toggle overflow Example server response (JSON)
Copy to Clipboard Copied! Toggle word wrap Toggle overflow - RetractCommand
Retracts an object from the KIE session.
Expand Table 24.3. Command attributes Name Description Requirement fact-handleThe
FactHandleassociated with the object to be retractedRequired
Example JSON request body
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Example Java command: Use
FactHandleFromStringRetractCommand retractCommand = new RetractCommand(); retractCommand.setFactHandleFromString("123:234:345:456:567");RetractCommand retractCommand = new RetractCommand(); retractCommand.setFactHandleFromString("123:234:345:456:567");Copy to Clipboard Copied! Toggle word wrap Toggle overflow Example Java command: Use
FactHandlefrom inserted objectRetractCommand retractCommand = new RetractCommand(factHandle);
RetractCommand retractCommand = new RetractCommand(factHandle);Copy to Clipboard Copied! Toggle word wrap Toggle overflow Example server response (JSON)
Copy to Clipboard Copied! Toggle word wrap Toggle overflow - ModifyCommand
Modifies a previously inserted object in the KIE session.
Expand Table 24.4. Command attributes Name Description Requirement fact-handleThe
FactHandleassociated with the object to be modifiedRequired
settersList of setters for object modifications
Required
Example JSON request body
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Example Java command
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Example server response (JSON)
Copy to Clipboard Copied! Toggle word wrap Toggle overflow - GetObjectCommand
Retrieves an object from a KIE session.
Expand Table 24.5. Command attributes Name Description Requirement fact-handleThe
FactHandleassociated with the object to be retrievedRequired
out-identifierID of the
FactHandlecreated from the object insertion and added to the execution resultsOptional
Example JSON request body
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Example Java command
GetObjectCommand getObjectCommand = new GetObjectCommand(); getObjectCommand.setFactHandleFromString("123:234:345:456:567"); getObjectCommand.setOutIdentifier("john");GetObjectCommand getObjectCommand = new GetObjectCommand(); getObjectCommand.setFactHandleFromString("123:234:345:456:567"); getObjectCommand.setOutIdentifier("john");Copy to Clipboard Copied! Toggle word wrap Toggle overflow Example server response (JSON)
Copy to Clipboard Copied! Toggle word wrap Toggle overflow - GetObjectsCommand
Retrieves all objects from the KIE session as a collection.
Expand Table 24.6. Command attributes Name Description Requirement object-filterFilter for the objects returned from the KIE session
Optional
out-identifierIdentifier to be used in the execution results
Optional
Example JSON request body
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Example Java command
GetObjectsCommand getObjectsCommand = new GetObjectsCommand(); getObjectsCommand.setOutIdentifier("objects");GetObjectsCommand getObjectsCommand = new GetObjectsCommand(); getObjectsCommand.setOutIdentifier("objects");Copy to Clipboard Copied! Toggle word wrap Toggle overflow Example server response (JSON)
Copy to Clipboard Copied! Toggle word wrap Toggle overflow - InsertElementsCommand
Inserts a list of objects into the KIE session.
Expand Table 24.7. Command attributes Name Description Requirement objectsThe list of objects to be inserted into the KIE session
Required
out-identifierID of the
FactHandlecreated from the object insertion and added to the execution resultsOptional
return-objectBoolean to determine whether the object must be returned in the execution results. Default value:
true.Optional
entry-pointEntry point for the insertion
Optional
Example JSON request body
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Example Java command
List<Object> objects = new ArrayList<Object>(); objects.add(new Person("john", 25)); objects.add(new Person("sarah", 35)); Command insertElementsCommand = CommandFactory.newInsertElements(objects);List<Object> objects = new ArrayList<Object>(); objects.add(new Person("john", 25)); objects.add(new Person("sarah", 35)); Command insertElementsCommand = CommandFactory.newInsertElements(objects);Copy to Clipboard Copied! Toggle word wrap Toggle overflow Example server response (JSON)
Copy to Clipboard Copied! Toggle word wrap Toggle overflow - FireAllRulesCommand
Executes all rules in the KIE session.
Expand Table 24.8. Command attributes Name Description Requirement maxMaximum number of rules to be executed. The default is
-1and does not put any restriction on execution.Optional
out-identifierID to be used for retrieving the number of fired rules in execution results.
Optional
agenda-filterAgenda Filter to be used for rule execution.
Optional
Example JSON request body
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Example Java command
FireAllRulesCommand fireAllRulesCommand = new FireAllRulesCommand(); fireAllRulesCommand.setMax(10); fireAllRulesCommand.setOutIdentifier("firedActivations");FireAllRulesCommand fireAllRulesCommand = new FireAllRulesCommand(); fireAllRulesCommand.setMax(10); fireAllRulesCommand.setOutIdentifier("firedActivations");Copy to Clipboard Copied! Toggle word wrap Toggle overflow Example server response (JSON)
Copy to Clipboard Copied! Toggle word wrap Toggle overflow - StartProcessCommand
Starts a process using the process ID. You can also pass parameters and initial data to be inserted.
Expand Table 24.9. Command attributes Name Description Requirement processIdID of the process to be started
Required
parametersA
Map <String,Object>argument to pass parameters in the process startupOptional
dataList of objects to be inserted into the KIE session before the process startup
Optional
Example JSON request body
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Example Java command
StartProcessCommand startProcessCommand = new StartProcessCommand(); startProcessCommand.setProcessId("org.drools.task.processOne");StartProcessCommand startProcessCommand = new StartProcessCommand(); startProcessCommand.setProcessId("org.drools.task.processOne");Copy to Clipboard Copied! Toggle word wrap Toggle overflow Example server response (JSON)
Copy to Clipboard Copied! Toggle word wrap Toggle overflow - SignalEventCommand
Sends a signal event to the KIE session.
Expand Table 24.10. Command attributes Name Description Requirement event-typeType of the incoming event
Required
process-instance-idID of the process instance to be signalled
Optional
eventData of the incoming event
Optional
Example JSON request body
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Example Java command
SignalEventCommand signalEventCommand = new SignalEventCommand(); signalEventCommand.setProcessInstanceId(1001); signalEventCommand.setEventType("start"); signalEventCommand.setEvent(new Person("john", 25));SignalEventCommand signalEventCommand = new SignalEventCommand(); signalEventCommand.setProcessInstanceId(1001); signalEventCommand.setEventType("start"); signalEventCommand.setEvent(new Person("john", 25));Copy to Clipboard Copied! Toggle word wrap Toggle overflow Example server response (JSON)
Copy to Clipboard Copied! Toggle word wrap Toggle overflow - CompleteWorkItemCommand
Completes a work item in the KIE session.
Expand Table 24.11. Command attributes Name Description Requirement workItemIdID of the work item to be completed
Required
resultsResult of the work item
Optional
Example JSON request body
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Example Java command
CompleteWorkItemCommand completeWorkItemCommand = new CompleteWorkItemCommand(); completeWorkItemCommand.setWorkItemId(1001);
CompleteWorkItemCommand completeWorkItemCommand = new CompleteWorkItemCommand(); completeWorkItemCommand.setWorkItemId(1001);Copy to Clipboard Copied! Toggle word wrap Toggle overflow Example server response (JSON)
Copy to Clipboard Copied! Toggle word wrap Toggle overflow - AbortWorkItemCommand
Aborts a work item in the KIE session in the same way as
ksession.getWorkItemManager().abortWorkItem(workItemId).Expand Table 24.12. Command attributes Name Description Requirement workItemIdID of the work item to be aborted
Required
Example JSON request body
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Example Java command
AbortWorkItemCommand abortWorkItemCommand = new AbortWorkItemCommand(); abortWorkItemCommand.setWorkItemId(1001);
AbortWorkItemCommand abortWorkItemCommand = new AbortWorkItemCommand(); abortWorkItemCommand.setWorkItemId(1001);Copy to Clipboard Copied! Toggle word wrap Toggle overflow Example server response (JSON)
Copy to Clipboard Copied! Toggle word wrap Toggle overflow - QueryCommand
Executes a query defined in the KIE base.
Expand Table 24.13. Command attributes Name Description Requirement nameQuery name.
Required
out-identifierID of the query results. The query results are added in the execution results with this identifier.
Optional
argumentsList of objects to be passed as a query parameter.
Optional
Example JSON request body
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Example Java command
QueryCommand queryCommand = new QueryCommand(); queryCommand.setName("persons"); queryCommand.setOutIdentifier("persons");QueryCommand queryCommand = new QueryCommand(); queryCommand.setName("persons"); queryCommand.setOutIdentifier("persons");Copy to Clipboard Copied! Toggle word wrap Toggle overflow Example server response (JSON)
Copy to Clipboard Copied! Toggle word wrap Toggle overflow - SetGlobalCommand
Sets an object to a global state.
Expand Table 24.14. Command attributes Name Description Requirement identifierID of the global variable defined in the KIE base
Required
objectObject to be set into the global variable
Optional
outBoolean to exclude the global variable you set from the execution results
Optional
out-identifierID of the global execution result
Optional
Example JSON request body
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Example Java command
SetGlobalCommand setGlobalCommand = new SetGlobalCommand(); setGlobalCommand.setIdentifier("helper"); setGlobalCommand.setObject(new Person("kyle", 30)); setGlobalCommand.setOut(true); setGlobalCommand.setOutIdentifier("output");SetGlobalCommand setGlobalCommand = new SetGlobalCommand(); setGlobalCommand.setIdentifier("helper"); setGlobalCommand.setObject(new Person("kyle", 30)); setGlobalCommand.setOut(true); setGlobalCommand.setOutIdentifier("output");Copy to Clipboard Copied! Toggle word wrap Toggle overflow Example server response (JSON)
Copy to Clipboard Copied! Toggle word wrap Toggle overflow - GetGlobalCommand
Retrieves a previously defined global object.
Expand Table 24.15. Command attributes Name Description Requirement identifierID of the global variable defined in the KIE base
Required
out-identifierID to be used in the execution results
Optional
Example JSON request body
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Example Java command
GetGlobalCommand getGlobalCommand = new GetGlobalCommand(); getGlobalCommand.setIdentifier("helper"); getGlobalCommand.setOutIdentifier("helperOutput");GetGlobalCommand getGlobalCommand = new GetGlobalCommand(); getGlobalCommand.setIdentifier("helper"); getGlobalCommand.setOutIdentifier("helperOutput");Copy to Clipboard Copied! Toggle word wrap Toggle overflow Example server response (JSON)
Copy to Clipboard Copied! Toggle word wrap Toggle overflow