问题
I want to know if it is possible to deploy a KJAR to the execution server programmatically (via API)? I can build a KJAR using the following:
final KieServices kieServices = KieServices.Factory.get();
final KieFileSystem kieFileSystem = kieServices.newKieFileSystem();
kieFileSystem.write("src/main/resources/" + ClassUtils.convertClassNameToResourcePath(getPackageNameForRule(rule.getValue())) + "/" + rule
.getCode() + ".drl", rule.getValue());
return kieServices.newKieBuilder(kieFileSystem).buildAll().getKieModule().getReleaseId();
and I can also create a container in the KIE execution server through the REST KieServicesClient
like this:
KieContainerResource kieContainerResource =
new KieContainerResource(containerId, new org.kie.server.api.model.ReleaseId(buildNewReleaseId()));
kieServicesClient.createContainer(containerId, kieContainerResource);
but when I do so I get an exception in the KIE server saying that:
kie-server | 10:54:04,192 ERROR [org.kie.server.services.impl.KieServerImpl] (default task-2) Error creating container 'targeting' for module 'org.default:artifact:1.0.0': java.lang.RuntimeException: Cannot find KieModule: org.default:artifact:1.0.0
kie-server | at org.drools.compiler.kie.builder.impl.KieServicesImpl.newKieContainer(KieServicesImpl.java:186)
kie-server | at org.drools.compiler.kie.builder.impl.KieServicesImpl.newKieContainer(KieServicesImpl.java:176)
kie-server | at org.kie.server.services.impl.KieServerImpl.createContainer(KieServerImpl.java:275)
kie-server | at org.kie.server.remote.rest.common.resource.KieServerRestImpl.createContainer(KieServerRestImpl.java:157)
kie-server | at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
kie-server | at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
kie-server | at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
kie-server | at java.lang.reflect.Method.invoke(Method.java:498)
kie-server | at org.jboss.resteasy.core.MethodInjectorImpl.invoke(MethodInjectorImpl.java:140)
kie-server | at org.jboss.resteasy.core.ResourceMethodInvoker.internalInvokeOnTarget(ResourceMethodInvoker.java:509)
My KIE server is running in a docker container. Do I have to programmatically invoke Maven to deploy my KJAR in the repository inside the docker container? I hope there's an API to do this programmatically. Also how does the Drools Workbench do it?
回答1:
I found it. There's an API in org.kie.soup:kie-soup-maven-integration
which one can use like this:
MavenRepository repository = getMavenRepository();
if (remote) {
RemoteRepository remoteRepository = new RemoteRepository.Builder("id", "type", "url").build();
repository.deployArtifact(remoteRepository, releaseId, kjar, pom);
} else {
repository.installArtifact(releaseId, kjar, pom);
}
来源:https://stackoverflow.com/questions/59234684/deploy-a-kjar-to-kie-execution-server-programmatically-via-rest-api