通过REST API以编程方式将KJAR部署到KIE执行服务器

时间:2019-12-08 10:56:50

标签: drools kie

我想知道是否可以通过编程方式(通过API)将KJAR部署到执行服务器吗? 我可以使用以下内容构建KJAR:

        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();

并且我还可以通过REST KieServicesClient在KIE执行服务器中创建一个容器,如下所示:

        KieContainerResource kieContainerResource =
                        new KieContainerResource(containerId, new org.kie.server.api.model.ReleaseId(buildNewReleaseId()));
        kieServicesClient.createContainer(containerId, kieContainerResource);

但是当我这样做的时候,我在KIE服务器中收到一个异常,说:

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)

我的KIE服务器在docker容器中运行。我是否需要以编程方式调用Maven才能将我的KJAR部署在docker容器内的存储库中?我希望有一个API以编程方式执行此操作。还有Drools工作台是怎么做到的?

1 个答案:

答案 0 :(得分:0)

我找到了。 org.kie.soup:kie-soup-maven-integration中有一个可以像这样使用的API:

        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);
        }