Optaplanner REST API 解决问题

Optaplanner REST API solve issue

我们在 Wildfly 10.0.0 上使用 Optaplanner 7.0.0 最终工作台和 KIE 服务器以及 optacloud 示例。

到目前为止,我们已经将容器部署到远程执行服务器并使用 RESTful API.

为该容器创建了求解器

KIE 服务器提供的求解器详细信息是:

<org.kie.server.api.model.instance.SolverInstanceList>
    <solvers>
        <solver-instance>
            <container-id>test</container-id>
            <solver-id>testsolver</solver-id>
            <solver-config-file>optacloud/optacloud/cloudSolverConfig.solver.xml</solver-config-file>
            <status>NOT_SOLVING</status>
            <score />
         </solver-instance>
    </solvers>
</org.kie.server.api.model.instance.SolverInstanceList>

我们收到来自 wildfly 的 405 Method Not Allowed 响应,响应内容如下 URL:

http://xxx.xxx.xxx.xxx:8080/kie-server-7.0.0.Final-ee7/services/rest/server/containers/test/solvers/testsolver/

这个 URL 结构是否正确,还是我们遗漏了什么?

我们正在发布以下数据:

<solver-instance>
  <status>SOLVING</status>
  <planning-problem class="optacloud.optacloud.CloudSolution">
    <computerList>
      <optacloud.optacloud.Computer>
        <cpuPower>10</cpuPower>
        <memory>4</memory>
        <networkBandwidth>100</networkBandwidth>
        <cost>1000</cost>
      </optacloud.optacloud.Computer>
      <optacloud.optacloud.Computer>
        <cpuPower>20</cpuPower>
        <memory>8</memory>
        <networkBandwidth>100</networkBandwidth>
        <cost>3000</cost>
      </optacloud.optacloud.Computer>
    </computerList>
    <processList>
      <optacloud.optacloud.Process>
        <requiredCpuPower>1</requiredCpuPower>
        <requiredMemory>7</requiredMemory>
        <requiredNetworkBandwidth>1</requiredNetworkBandwidth>
      </optacloud.optacloud.Process>
    </processList>
  </planning-problem>
</solver-instance>

与以下 headers:

Content-Type: application/xml
X-KIE-ContentType: xstream

KIE 服务器 API 在 7 系列中发生了变化,提交解决方案负载中不再需要 <solver-instance> 包装器。

您需要将 POST 发送到 http://${kie-server}/services/rest/server/containers/${container_id}/solvers/${solver_id}/state/solving,其中有效载荷只是一个规划问题(解决方案)对象: <planning-problem class="optacloud.optacloud.CloudSolution">...</planning-problem>.

请参阅快速入门 https://github.com/kiegroup/kie-docs/blob/master/docs/optaplanner-wb-es-docs/src/main/asciidoc/Workbench/Quickstart/Quickstart-section.adoc#submit-solution,其中包含以新方式提交规划问题的示例。

新的API概述:

注册求解器: PUT http://${kie-server}/services/rest/server/containers/${container_id}/solvers/${solver_id}

提交解决方案: POST http://${kie-server}/services/rest/server/containers/${container_id}/solvers/${solver_id}/state/solving

获得最佳解决方案: 获取 http://${kie-server}/services/rest/server/containers/${container_id}/solvers/${solver_id}/bestsolution

终止求解器: POST http://${kie-server}/services/rest/server/containers/${container_id}/solvers/${solver_id}/state/terminating-early

配置求解器: 删除 http://${kie-server}/services/rest/server/containers/${container_id}/solvers/${solver_id}