Search in sources :

Example 6 with SolverInstance

use of org.kie.server.api.model.instance.SolverInstance in project droolsjbpm-integration by kiegroup.

the class SolverClientIntegrationTest method getSolverStatus.

private SolverInstance.SolverStatus getSolverStatus() {
    final Map<String, Object> parameters = new HashMap<>();
    parameters.put("containerId", CONTAINER_ID);
    parameters.put("solverId", CLOUD_BALANCE_SOLVER_ID);
    final ExecutionServerCommand executionServerCommand = new ExecutionServerCommand();
    executionServerCommand.setClient("solver");
    executionServerCommand.setOperation("getSolver");
    executionServerCommand.setParameters(parameters);
    final Object response = runOnExecutionServer(executionServerCommand);
    Assertions.assertThat(response).isNotNull();
    Assertions.assertThat(response).isInstanceOf(SolverInstance.class);
    final SolverInstance solverInstance = (SolverInstance) response;
    return solverInstance.getStatus();
}
Also used : SolverInstance(org.kie.server.api.model.instance.SolverInstance) HashMap(java.util.HashMap) ExecutionServerCommand(org.kie.camel.container.api.ExecutionServerCommand)

Example 7 with SolverInstance

use of org.kie.server.api.model.instance.SolverInstance in project droolsjbpm-integration by kiegroup.

the class OptaPlannerJmsResponseHandlerIntegrationTest method testSolverWithAsyncResponseHandler.

@Test
public void testSolverWithAsyncResponseHandler() throws Exception {
    Marshaller marshaller = MarshallerFactory.getMarshaller(new HashSet<>(extraClasses.values()), configuration.getMarshallingFormat(), client.getClassLoader());
    ResponseCallback responseCallback = new BlockingResponseCallback(marshaller);
    ResponseHandler asyncResponseHandler = new AsyncResponseHandler(responseCallback);
    solverClient.setResponseHandler(asyncResponseHandler);
    SolverInstance response = solverClient.createSolver(CONTAINER_1_ID, SOLVER_1_ID, SOLVER_1_CONFIG);
    assertThat(response).isNull();
    SolverInstance solver = responseCallback.get(SolverInstance.class);
    assertThat(solver).isNotNull();
    assertThat(solver.getContainerId()).isEqualTo(CONTAINER_1_ID);
    assertThat(solver.getSolverId()).isEqualTo(SOLVER_1_ID);
    List<SolverInstance> solverInstanceList = solverClient.getSolvers(CONTAINER_1_ID);
    assertThat(solverInstanceList).isNull();
    SolverInstanceList solverList = responseCallback.get(SolverInstanceList.class);
    assertThat(solverList).isNotNull();
    assertThat(solverList.getContainers()).isNotNull().isNotEmpty().hasSize(1);
    solver = solverList.getContainers().get(0);
    assertThat(solver.getSolverId()).isEqualTo(SOLVER_1_ID);
    assertThat(solver.getStatus()).isEqualTo(SolverInstance.SolverStatus.NOT_SOLVING);
    solverClient.solvePlanningProblem(CONTAINER_1_ID, SOLVER_1_ID, loadPlanningProblem(5, 15));
    // Make sure the service call result is consumed
    responseCallback.get(Void.class);
    response = solverClient.getSolver(CONTAINER_1_ID, SOLVER_1_ID);
    assertThat(response).isNull();
    solver = responseCallback.get(SolverInstance.class);
    assertThat(solver.getSolverId()).isEqualTo(SOLVER_1_ID);
    assertThat(solver.getStatus()).isEqualTo(SolverInstance.SolverStatus.SOLVING);
    solverClient.terminateSolverEarly(CONTAINER_1_ID, SOLVER_1_ID);
    // Make sure the service call result is consumed
    responseCallback.get(Void.class);
    response = solverClient.getSolver(CONTAINER_1_ID, SOLVER_1_ID);
    assertThat(response).isNull();
    solver = responseCallback.get(SolverInstance.class);
    assertThat(solver.getSolverId()).isEqualTo(SOLVER_1_ID);
    assertThat(solver.getStatus()).isIn(SolverInstance.SolverStatus.TERMINATING_EARLY, SolverInstance.SolverStatus.NOT_SOLVING);
    solverClient.disposeSolver(CONTAINER_1_ID, SOLVER_1_ID);
    // Make sure the service call result is consumed
    responseCallback.get(Void.class);
    solverClient.getSolvers(CONTAINER_1_ID);
    assertThat(response).isNull();
    solverList = responseCallback.get(SolverInstanceList.class);
    assertThat(solverList).isNotNull();
    assertThat(solverList.getContainers()).isNullOrEmpty();
}
Also used : SolverInstance(org.kie.server.api.model.instance.SolverInstance) Marshaller(org.kie.server.api.marshalling.Marshaller) ResponseHandler(org.kie.server.client.jms.ResponseHandler) AsyncResponseHandler(org.kie.server.client.jms.AsyncResponseHandler) RequestReplyResponseHandler(org.kie.server.client.jms.RequestReplyResponseHandler) FireAndForgetResponseHandler(org.kie.server.client.jms.FireAndForgetResponseHandler) AsyncResponseHandler(org.kie.server.client.jms.AsyncResponseHandler) BlockingResponseCallback(org.kie.server.client.jms.BlockingResponseCallback) ResponseCallback(org.kie.server.client.jms.ResponseCallback) BlockingResponseCallback(org.kie.server.client.jms.BlockingResponseCallback) SolverInstanceList(org.kie.server.api.model.instance.SolverInstanceList) OptaplannerKieServerBaseIntegrationTest(org.kie.server.integrationtests.optaplanner.OptaplannerKieServerBaseIntegrationTest) Test(org.junit.Test)

Example 8 with SolverInstance

use of org.kie.server.api.model.instance.SolverInstance in project droolsjbpm-integration by kiegroup.

the class OptaplannerIntegrationTest method testTerminateEarly.

@Test
public void testTerminateEarly() throws Exception {
    solverClient.createSolver(CONTAINER_1_ID, SOLVER_1_ID, SOLVER_1_CONFIG);
    // start solver
    solverClient.solvePlanningProblem(CONTAINER_1_ID, SOLVER_1_ID, loadPlanningProblem(50, 150));
    SolverInstance instance = solverClient.getSolver(CONTAINER_1_ID, SOLVER_1_ID);
    assertEquals(SolverInstance.SolverStatus.SOLVING, instance.getStatus());
    // and then terminate it
    solverClient.terminateSolverEarly(CONTAINER_1_ID, SOLVER_1_ID);
    instance = solverClient.getSolver(CONTAINER_1_ID, SOLVER_1_ID);
    assertTrue(instance.getStatus() == SolverInstance.SolverStatus.TERMINATING_EARLY || instance.getStatus() == SolverInstance.SolverStatus.NOT_SOLVING);
    solverClient.disposeSolver(CONTAINER_1_ID, SOLVER_1_ID);
}
Also used : SolverInstance(org.kie.server.api.model.instance.SolverInstance) Test(org.junit.Test)

Example 9 with SolverInstance

use of org.kie.server.api.model.instance.SolverInstance in project droolsjbpm-integration by kiegroup.

the class OptaplannerIntegrationTest method testCreateDuplicitSolver.

@Test
public void testCreateDuplicitSolver() {
    SolverInstance solverInstance = solverClient.createSolver(CONTAINER_1_ID, SOLVER_1_ID, SOLVER_1_CONFIG);
    assertNotNull(solverInstance);
    try {
        solverClient.createSolver(CONTAINER_1_ID, SOLVER_1_ID, SOLVER_1_CONFIG);
        fail("A KieServicesException should have been thrown by now.");
    } catch (KieServicesException e) {
        KieServerAssert.assertResultContainsStringRegex(e.getMessage(), ".*Failed to create solver. Solver .* already exists for container .*");
    }
}
Also used : SolverInstance(org.kie.server.api.model.instance.SolverInstance) KieServicesException(org.kie.server.api.exception.KieServicesException) Test(org.junit.Test)

Example 10 with SolverInstance

use of org.kie.server.api.model.instance.SolverInstance in project droolsjbpm-integration by kiegroup.

the class OptaplannerIntegrationTest method verifySolverAndGetBestSolution.

private Object verifySolverAndGetBestSolution() {
    SolverInstance solver = solverClient.getSolverWithBestSolution(CONTAINER_1_ID, SOLVER_1_ID);
    assertEquals(SolverInstance.SolverStatus.SOLVING, solver.getStatus());
    Object bestSolution = solver.getBestSolution();
    assertEquals(bestSolution.getClass().getName(), CLASS_CLOUD_BALANCE);
    return bestSolution;
}
Also used : SolverInstance(org.kie.server.api.model.instance.SolverInstance)

Aggregations

SolverInstance (org.kie.server.api.model.instance.SolverInstance)26 Test (org.junit.Test)11 ServiceResponse (org.kie.server.api.model.ServiceResponse)5 ArrayList (java.util.ArrayList)4 List (java.util.List)4 ApiOperation (io.swagger.annotations.ApiOperation)3 ApiResponses (io.swagger.annotations.ApiResponses)3 HashMap (java.util.HashMap)3 Path (javax.ws.rs.Path)3 Produces (javax.ws.rs.Produces)3 Variant (javax.ws.rs.core.Variant)3 ExecutionServerCommand (org.kie.camel.container.api.ExecutionServerCommand)3 CommandScript (org.kie.server.api.commands.CommandScript)3 Header (org.kie.server.remote.rest.common.Header)3 RestUtils.buildConversationIdHeader (org.kie.server.remote.rest.common.util.RestUtils.buildConversationIdHeader)3 RestUtils.createCorrectVariant (org.kie.server.remote.rest.common.util.RestUtils.createCorrectVariant)3 RestUtils.getVariant (org.kie.server.remote.rest.common.util.RestUtils.getVariant)3 GET (javax.ws.rs.GET)2 CreateSolverCommand (org.kie.server.api.commands.optaplanner.CreateSolverCommand)2 GetSolverCommand (org.kie.server.api.commands.optaplanner.GetSolverCommand)2