Hi,
here are my notes for working with KIE server. Not terribly organised I'm afraid, but I hope they can be of some use:
Bits and pieces:
1. Find out about available repositories:
curl -H 'Accept: application/json' -H 'Content-Type: application/json' -X GET -u 'bpmsAdmin:p4ssw0rd' '
http://localhost:8080/business-central/rest/repositories' | json_xs
[
{
"name": "repository1",
"description": null,
"userName": null,
"password": null,
"requestType": null,
"gitURL": "git://repository1"
},
{
"name": "hw2Repo",
"description": null,
"userName": null,
"password": null,
"requestType": null,
"gitURL": "git://hw2Repo"
},
{
"name": "hw1Over",
"description": null,
"userName": null,
"password": null,
"requestType": null,
"gitURL": "git://hw1Over"
},
{
"name": "helloworldrepo",
"description": null,
"userName": null,
"password": null,
"requestType": null,
"gitURL": "git://helloworldrepo"
}
]
2. Explore Organizational Units (to check repository ownership)
curl -H 'Accept: application/json' -H 'Content-Type: application/json' -X GET -u 'bpmsAdmin:p4ssw0rd' '
http://localhost:8080/business-central/rest/organizationalunits' | json_xs
[
{
"owner" : "bpmsAdmin",
"repositories" : [
"helloworldrepo",
"hw1Over"
],
"defaultGroupId" : "helloworld",
"description" : null,
"name" : "helloworld"
},
{
"repositories" : [
"hw2Repo"
],
"owner" : "bpmsAdmin - optional",
"description" : null,
"name" : "hw2",
"defaultGroupId" : "hw2"
},
{
"repositories" : [
"repository1"
],
"owner" : "
exa...@jbpm.org",
"description" : null,
"name" : "example",
"defaultGroupId" : "example"
}
]
3. Extract more information about a specific repository
curl -H 'Accept: application/json' -H 'Content-Type: application/json' -X GET -u 'bpmsAdmin:p4ssw0rd' '
http://localhost:8080/business-central/rest/repositories/hw1Over' | json_xs
{
"userName" : null,
"gitURL" : "git://hw1Over",
"requestType" : null,
"name" : "hw1Over",
"description" : null,
"password" : null
}
4. Find out about projects in a repository
curl -H 'Accept: application/json' -H 'Content-Type: application/json' -X GET -u 'bpmsAdmin:p4ssw0rd' '
http://localhost:8080/business-central/rest/repositories/hw1Over/projects' | json_xs
[
{
"version" : "1.0",
"groupId" : "helloworld",
"name" : "hw1OverPrj",
"description" : "Additional Project on the helloworld:hw1Over repository"
},
{
"version" : "1.0",
"description" : "Example project based on the BRMS 6.3 Getting Started",
"name" : "brms63start",
"groupId" : "helloworld"
}
]
5. Projects can also be created using REST
From SoapUI:
EndPoint:
http://localhost:8080 Resource: /business-central/rest/repositories/{repositoryTarget}/projects
Request config: repositoryTarget/hw1Over/TEMPLATE/RESOURCE
POST
http://localhost:8080/business-central/rest/repositories/hw1Over/projects HTTP/1.1
Accept-Encoding: gzip,deflate
Content-Type: application/json
Accept: application/json
Content-Length: 64
Host: localhost:8080
Connection: Keep-Alive
User-Agent: Apache-HttpClient/4.1.1 (java 1.5)
Authorization: Basic YnBtc0FkbWluOmw0bDRrMTNzKSg=
{"name":"testProject","description": "test project description"}
or using curl
curl -H 'Accept: application/json' -H 'Content-Type: application/json' -X POST -d '{"name":"prj2","description":"description2"}' -u 'bpmsAdmin:p4ssw0rd' '
http://localhost:8080/business-central/rest/repositories/hw1Over/projects' | json_xs
{
"description" : "description2",
"projectVersion" : null,
"status" : "APPROVED",
"projectGroupId" : null,
"repositoryName" : "hw1Over",
"projectName" : "prj2",
"jobId" : "1474466800973-2"
}
6. List projects in the repository to verify creation
curl -H 'Accept: application/json' -H 'Content-Type: application/json' -X GET -u 'bpmsAdmin:p4ssw0rd' '
http://localhost:8080/business-central/rest/repositories/hw1Over/projects' | json_xs
[
{
"groupId" : "helloworld",
"name" : "hw1OverPrj",
"description" : "Additional Project on the helloworld:hw1Over repository",
"version" : "1.0"
},
{
"groupId" : "testProject",
"name" : "testProject",
"description" : "test project description",
"version" : "1.0"
},
{
"name" : "brms63start",
"groupId" : "helloworld",
"description" : "Example project based on the BRMS 6.3 Getting Started",
"version" : "1.0"
},
{
"name" : "prj2",
"groupId" : "prj2",
"version" : "1.0",
"description" : "description2"
}
]
7. Communicate with KIE server
Before beginning communication add user and properly set system properties:
./add-user.sh -a --user kieserver --password kieserver1! --role kie-server,rest-all
Typical Command/Response:
curl -i -H 'Accept: application/json' -H 'Content-Type: application/json' -X GET -u 'kieserver':kieserver1! '
http://10.0.3.151:8080/kie-server/services/rest/server/'
HTTP/1.1 200 OK
Server: Apache-Coyote/1.1
Pragma: No-cache
Cache-Control: no-cache
Expires: Thu, 01 Jan 1970 01:00:00 GMT
Set-Cookie: JSESSIONIDSSO=SYm9QpCgmMNP3JKDrxTJ63mL; Path=/; HttpOnly
Set-Cookie: JSESSIONID=+3vFmnTP3sOLHPlhj0GjTg3D; Path=/kie-server
Content-Type: application/json
Content-Length: 692
Date: Fri, 23 Sep 2016 10:04:00 GMT
{
"type" : "SUCCESS",
"result" : {
"kie-server-info" : {
"capabilities" : [
"BRM",
"BPM-UI",
"BPM",
"BRP",
"KieServer"
],
"location" : "
http://10.0.3.151:8080/kie-server/services/rest/server",
"id" : "local-server-bpm1",
"messages" : [
{
"severity" : "INFO",
"timestamp" : 1474625032068,
"content" : [
"Server KieServerInfo{serverId='local-server-bpm1', version='6.4.0.Final-redhat-3', location='
http://10.0.3.151:8080/kie-server/services/rest/server'}started successfully at Fri Sep 23 11:03:52 BST 2016"
]
}
],
"name" : "local-server-bpm1",
"version" : "6.4.0.Final-redhat-3"
}
},
"msg" : "Kie Server info"
}
8. List available KIE containers in a remote KIE Execution Server
in JSON format:
curl -i -H 'Accept: application/json' -H 'Content-Type: application/json' -X GET -u 'kieserver':kieserver1! '
http://127.0.0.1:8080/kie-server/services/rest/server/containers'
HTTP/1.1 200 OK
Server: Apache-Coyote/1.1
Pragma: No-cache
Cache-Control: no-cache
Expires: Thu, 01 Jan 1970 01:00:00 GMT
Set-Cookie: JSESSIONIDSSO=-WRQLLKyytaLqu9EzjvDuVnf; Path=/; HttpOnly
Set-Cookie: JSESSIONID=9kjPLgggGnp4C102ejqsAfJ7; Path=/kie-server
Content-Type: application/json
Content-Length: 863
Date: Fri, 23 Sep 2016 12:13:19 GMT
{
"type" : "SUCCESS",
"msg" : "List of created containers",
"result" : {
"kie-containers" : {
"kie-container" : [ {
"status" : "STARTED",
"scanner" : {
"status" : "DISPOSED",
"poll-interval" : null
},
"messages" : [ {
"severity" : "INFO",
"timestamp" : 1474632746449,
"content" : [ "Container turboContainer successfully created with module org.brms:brms63start:1.1." ]
} ],
"container-id" : "turboContainer",
"release-id" : {
"version" : "1.1",
"group-id" : "org.brms",
"artifact-id" : "brms63start"
},
"resolved-release-id" : {
"version" : "1.1",
"group-id" : "org.brms",
"artifact-id" : "brms63start"
},
"config-items" : [ ]
} ]
}
}
}
in XML format:
curl -i -X GET -u 'kieserver':kieserver1! '
http://127.0.0.1:8080/kie-server/services/rest/server/containers'
HTTP/1.1 200 OK
Server: Apache-Coyote/1.1
Pragma: No-cache
Cache-Control: no-cache
Expires: Thu, 01 Jan 1970 01:00:00 GMT
Set-Cookie: JSESSIONIDSSO=UCnvBXyPUnenCJGYKFSNk4oK; Path=/; HttpOnly
Set-Cookie: JSESSIONID=+JyHIKMSjSS-E7PpRymAq1K0; Path=/kie-server
Content-Type: application/xml
Content-Length: 984
Date: Fri, 23 Sep 2016 12:17:49 GMT
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<response type="SUCCESS" msg="List of created containers">
<kie-containers>
<kie-container container-id="turboContainer" status="STARTED">
<messages>
<content>Container turboContainer successfully created with module org.brms:brms63start:1.1.</content>
<severity>INFO</severity>
<timestamp>2016-09-23T13:12:26.449+01:00</timestamp>
</messages>
<release-id>
<artifact-id>brms63start</artifact-id>
<group-id>org.brms</group-id>
<version>1.1</version>
</release-id>
<resolved-release-id>
<artifact-id>brms63start</artifact-id>
<group-id>org.brms</group-id>
<version>1.1</version>
</resolved-release-id>
<scanner status="DISPOSED"/>
</kie-container>
</kie-containers>
</response>
9. Find out more about a specific container:
curl -i -X GET -u 'kieserver':kieserver1! '
http://127.0.0.1:8080/kie-server/services/rest/server/containers/turboContainer'
HTTP/1.1 200 OK
Server: Apache-Coyote/1.1
Pragma: No-cache
Cache-Control: no-cache
Expires: Thu, 01 Jan 1970 01:00:00 GMT
Set-Cookie: JSESSIONIDSSO=4AEBSuLCQElodeGEC6Sy6erZ; Path=/; HttpOnly
Set-Cookie: JSESSIONID=s2O1He0bThXBxYEurHjolkSO; Path=/kie-server
X-KIE-ConversationId: %27turbo-kie-server%27%3A%27turboContainer%27%3A%27org.brms%3Abrms63start%3A1.1%27%3A%2733672fec-85f3-474f-9c21-8a1c28f0ba19%27
Content-Type: application/xml
Content-Length: 876
Date: Fri, 23 Sep 2016 12:27:17 GMT
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<response type="SUCCESS" msg="Info for container turboContainer">
<kie-container container-id="turboContainer" status="STARTED">
<messages>
<content>Container turboContainer successfully created with module org.brms:brms63start:1.1.</content>
<severity>INFO</severity>
<timestamp>2016-09-23T13:12:26.449+01:00</timestamp>
</messages>
<release-id>
<artifact-id>brms63start</artifact-id>
<group-id>org.brms</group-id>
<version>1.1</version>
</release-id>
<resolved-release-id>
<artifact-id>brms63start</artifact-id>
<group-id>org.brms</group-id>
<version>1.1</version>
</resolved-release-id>
<scanner status="DISPOSED"/>
</kie-container>
</response>
10. Insert an object, fire-all-rules and get results
Refer to "BRMS Getting Started" guide for the implementation of the rule for this example.
Refer to "BPM.6.3 Development Guide - 16.5.7 /
16.5.6.3/4" for more details of the commands.
curl -X POST -H 'X-KIE-ContentType: JSON' -H 'Content-type: application/json' -u 'kieserver:kieserver1!' --data @a
http://localhost:8080/kie-server/services/rest/server/containers/instances/turboContainer Using file "a"
+----
| {
| "lookup" : "brms63KSession",
| "commands" : [
| {
| "insert" : {
| "object" : { "org.brms.brms63start.Person": { "firstName":"brainy", "lastName":"pinky", "hourlyRate":12, "wage":200 } }
| }
| },
| { "fire-all-rules" : { } }
| ]
| }
+----
results in:
{
"type" : "SUCCESS",
"msg" : "Container turboContainer successfully called.",
"result" : {
"execution-results" : {
"results" : [ ],
"facts" : [ ]
}
}
}
check in the "stdout" of the EAP/BPM.6.3 for the output of the fire-all-rules.
In this case:
14:44:14,825 INFO [stdout] (http-127.0.0.1:8080-7) Hello brainy pinky!
14:44:14,825 INFO [stdout] (http-127.0.0.1:8080-7) You seem well off, will you marry me?
11. Get a list of all objects from the current session
CAVEAT: Request must be in XSTREAM format to allow from proper deserialization of results
Note difference in HTTP headers
curl -X POST -H 'X-KIE-ContentType: XSTREAM' -H 'Content-type: application/json' -u 'kieserver:kieserver1!' -d'<batch-execution lookup="brms63KSession"><get-objects out-identifier="hive"/></batch-execution>'
http://localhost:8080/kie-server/services/rest/server/containers/instances/turboContainer <?xml version="1.0"?>
<org.kie.server.api.model.ServiceResponse>
<type>SUCCESS</type>
<msg>Container turboContainer successfully called.</msg>
<result class="execution-results">
<result identifier="hive">
<list>
<org.brms.brms63start.Person>
<firstName>brainy</firstName>
<lastName>pinky</lastName>
<hourlyRate>12</hourlyRate>
<wage>200</wage>
</org.brms.brms63start.Person>
<org.brms.brms63start.Person>
<firstName>brainy</firstName>
<lastName>pinky</lastName>
<hourlyRate>12</hourlyRate>
<wage>200</wage>
</org.brms.brms63start.Person>
<org.brms.brms63start.Person>
<firstName>brainy</firstName>
<lastName>pinky</lastName>
<hourlyRate>12</hourlyRate>
<wage>200</wage>
</org.brms.brms63start.Person>
</list>
</result>
</result>
</org.kie.server.api.model.ServiceResponse>
12. Insert an object and get its fact handle along with the result:
curl -X POST -H 'X-KIE-ContentType: JSON' -H 'Content-type: application/json' -u 'kieserver:kieserver1!' --data @a ttp://localhost:8080/kie-server/services/rest/server/containers/instances/turboContainer
Using file "a":
+----
| {
| "lookup" : "brms63KSession",
| "commands" : [
| {
| "insert" : {
| "object" : { "org.brms.brms63start.Person": { "firstName":"MARVIN", "lastName":"GoldenHeart", "hourlyRate":20, "wage":200 } },
| "out-identifier":"brainy"
| }
| },
| { "fire-all-rules" : { } }
| ]
| }
+----
Result:
{
"type" : "SUCCESS",
"result" : {
"execution-results" : {
"results" : [
{
"key" : "brainy",
"value" : {
"org.brms.brms63start.Person" : {
"wage" : 200,
"firstName" : "MARVIN",
"lastName" : "GoldenHeart",
"hourlyRate" : 20
}
}
}
],
"facts" : [
{
"key" : "brainy",
"value" : {
"org.drools.core.common.DefaultFactHandle" : {
"external-form" : "0:6:198440441:198440441:6:DEFAULT:NON_TRAIT:org.brms.brms63start.Person"
}
}
}
]
}
},
"msg" : "Container turboContainer successfully called."
}
13. Using the above fact-handle, retract the object:
curl -X POST -H 'X-KIE-ContentType: XSTREAM' -H 'Content-type: application/json' -u 'kieserver:kieserver1!' -d'<batch-execution lookup="brms63KSession"><retract fact-handle="0:6:198440441:198440441:6:DEFAULT:NON_TRAIT:org.brms.brms63start.Person"/></batch-execution>'
http://localhost:8080/kie-server/services/rest/server/containers/instances/turboContainer <?xml version="1.0"?>
<org.kie.server.api.model.ServiceResponse>
<type>SUCCESS</type>
<msg>Container turboContainer successfully called.</msg>
<result class="execution-results"/>
</org.kie.server.api.model.ServiceResponse>
14. check this out:
curl -s -X POST -H 'X-KIE-ContentType: JSON' -H 'Content-type: application/json' -u 'kieserver:kieserver1!' --data @a
http://localhost:8080/kie-server/services/rest/server/containers/instances/turboContainer | jq -r '.result["execution-results"].facts[].value["org.drools.core.common.DefaultFactHandle"]["external-form"]'
15. Compile project
curl -s -X POST -H 'Accept: application/json' -H 'Content-Type: application/json' -u 'bpmsAdmin:p4ssw0rd' '
http://localhost:8080/business-central/rest//repositories/hw1Over/projects/brms63start/maven/compile'
{
"projectName" : "brms63start",
"repositoryName" : "hw1Over",
"jobId" : "1474881688742-5",
"status" : "APPROVED"
}
16. Get status of compile job by JobId:
curl -s -X GET -H 'Accept: application/json' -H 'Content-Type: application/json' -u 'bpmsAdmin:p4ssw0rd' '
http://localhost:8080/business-central/rest/jobs/1474881688742-5'
A sample successfull response:
{
"result" : null,
"lastModified" : 1474881689437,
"status" : "SUCCESS",
"detailedResult" : [
"level:INFO, path:null, text:Build of project 'brms63start' (requested by system) completed.\n Build: SUCCESSFUL"
],
"jobId" : "1474881688742-5"
}
Given the following DRL:
package org.brms.brms63start;
rule "brms63start Rule"
when
Person ( hourlyRate * wage > 100, name : firstName, surname : lastName )
then
System.out.println( "----!" );
System.out.println( "Hello" + " " + name + " " + surname + "!" );
System.out.println( "Did you get your towel?" );
wrong
end
A sample failed response due to DRL syntax error:
{
"jobId" : "1474885110609-25",
"result" : null,
"detailedResult" : [
"level:INFO, path:null, text:Build of project 'brms63start' (requested by system) completed.\n Build: FAILURE",
"level:ERROR, path:PathImpl{uri='default://master@hw1Over/brms63start/src/main/resources/org/brms/brms63start/brms63Rule.drl', fileName='brms63Rule.drl', attrs={}}, text:Rule Compilation error Syntax error, insert \"VariableDeclarators\" to complete LocalVariableDeclaration\nSyntax error, insert \";\" to complete LocalVariableDeclarationStatement\nwrong cannot be resolved to a type"
],
"lastModified" : 1474885111023,
"status" : "FAIL"
}
A sample failed response:
{
"result" : null,
"jobId" : "1474882315812-7",
"status" : "FAIL",
"lastModified" : 1474882318853,
"detailedResult" : [
"level:ERROR, path:null, text:Deployment of unit org.brms:brms63start:1.4 failed: java.lang.RuntimeException: java.lang.IllegalStateException: Cannot find ksession, either it does not exist or there are multiple default ksession in kmodule.xml",
"artifactID:brms63start, groupId:org.brms, version:1.4"
]
}
17. Use the following sequence to check on compilation/deploy status:
curl -s -X POST -H 'Accept: application/json' -H 'Content-Type: application/json' -u 'bpmsAdmin:p4ssw0rd' '
http://localhost:8080/business-central/rest//repositories/hw1Over/projects/brms63start/maven/compile' | jq -r '.jobId' > /tmp/jobid; job=`cat /tmp/jobid`; echo $job; for i in `seq 0 10`; do echo -n '.'; sleep 1s; done; echo; curl -s -X GET -H 'Accept: application/json' -H 'Content-Type: application/json' -u 'bpmsAdmin:p4ssw0rd' "
http://localhost:8080/business-central/rest/jobs/$job" | json_pp
{
"capabilities" : [
"RULE",
"PROCESS",
"PLANNING"
],
"server-config" : {},
"server-name" : "turbo-kie-server",
"server-id" : "turbo-kie-server",
"server-instances" : [
{
"server-name" : "
turbo-ki...@127.0.0.1:8080",
"server-url" : "
http://127.0.0.1:8080/kie-server/services/rest/server",
"server-template-id" : "turbo-kie-server",
"server-instance-id" : "
turbo-ki...@127.0.0.1:8080"
}
],
"container-specs" : [
{
"configuration" : {
"RULE" : {
"org.kie.server.controller.api.model.spec.RuleConfig" : {
"pollInterval" : null,
"scannerStatus" : "STOPPED"
}
},
"PROCESS" : {
"org.kie.server.controller.api.model.spec.ProcessConfig" : {
"kbase" : "",
"ksession" : "",
"mergeMode" : "KEEP_ALL",
"runtimeStrategy" : "PER_PROCESS_INSTANCE"
}
}
},
"server-template-key" : {
"server-id" : "turbo-kie-server",
"server-name" : "turbo-kie-server"
},
"container-name" : "turboContainer",
"release-id" : {
"artifact-id" : "brms63start",
"version" : "1.27",
"group-id" : "org.brms"
},
"status" : "STARTED",
"container-id" : "turboContainer"
}
]