Search in sources :

Example 16 with SolverInstance

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

the class SolverClientIntegrationTest method cleanUpSolvers.

@After
public void cleanUpSolvers() {
    final Map<String, Object> parameters = new HashMap<>();
    parameters.put("containerId", CONTAINER_ID);
    final ExecutionServerCommand executionServerCommand = new ExecutionServerCommand();
    executionServerCommand.setClient("solver");
    executionServerCommand.setOperation("getSolvers");
    executionServerCommand.setParameters(parameters);
    final Object response = runOnExecutionServer(executionServerCommand);
    final List<SolverInstance> solverInstances = (List<SolverInstance>) response;
    for (SolverInstance solverInstance : solverInstances) {
        disposeSolver(solverInstance.getSolverId());
    }
}
Also used : SolverInstance(org.kie.server.api.model.instance.SolverInstance) HashMap(java.util.HashMap) List(java.util.List) ExecutionServerCommand(org.kie.camel.container.api.ExecutionServerCommand) After(org.junit.After)

Example 17 with SolverInstance

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

the class SolverClientIntegrationTest method testGetSolver.

@Test
public void testGetSolver() {
    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;
    Assertions.assertThat(solverInstance.getContainerId()).isEqualTo(CONTAINER_ID);
    Assertions.assertThat(solverInstance.getSolverId()).isEqualTo(CLOUD_BALANCE_SOLVER_ID);
}
Also used : SolverInstance(org.kie.server.api.model.instance.SolverInstance) HashMap(java.util.HashMap) ExecutionServerCommand(org.kie.camel.container.api.ExecutionServerCommand) Test(org.junit.Test)

Example 18 with SolverInstance

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

the class OptaPlannerJmsResponseHandlerIntegrationTest method testSolverWithFireAndForgetResponseHandler.

@Test
public void testSolverWithFireAndForgetResponseHandler() throws Exception {
    solverClient.setResponseHandler(new FireAndForgetResponseHandler());
    SolverInstance solverInstance = solverClient.createSolver(CONTAINER_1_ID, SOLVER_1_ID, SOLVER_1_CONFIG);
    assertThat(solverInstance).isNull();
    solverClient.setResponseHandler(new RequestReplyResponseHandler());
    KieServerSynchronization.waitForSolver(solverClient, CONTAINER_1_ID, SOLVER_1_ID);
    solverClient.setResponseHandler(new FireAndForgetResponseHandler());
    solverClient.solvePlanningProblem(CONTAINER_1_ID, SOLVER_1_ID, loadPlanningProblem(5, 15));
    solverClient.setResponseHandler(new RequestReplyResponseHandler());
    KieServerSynchronization.waitForSolverStatus(solverClient, CONTAINER_1_ID, SOLVER_1_ID, SolverInstance.SolverStatus.SOLVING);
    solverClient.setResponseHandler(new FireAndForgetResponseHandler());
    solverClient.terminateSolverEarly(CONTAINER_1_ID, SOLVER_1_ID);
    solverClient.setResponseHandler(new RequestReplyResponseHandler());
    KieServerSynchronization.waitForSolverStatus(solverClient, CONTAINER_1_ID, SOLVER_1_ID, SolverInstance.SolverStatus.NOT_SOLVING);
    solverClient.setResponseHandler(new FireAndForgetResponseHandler());
    solverClient.disposeSolver(CONTAINER_1_ID, SOLVER_1_ID);
    solverClient.setResponseHandler(new RequestReplyResponseHandler());
    KieServerSynchronization.waitForSolverDispose(solverClient, CONTAINER_1_ID, SOLVER_1_ID);
    List<SolverInstance> solverInstanceList = solverClient.getSolvers(CONTAINER_1_ID);
    assertThat(solverInstanceList).isNullOrEmpty();
}
Also used : SolverInstance(org.kie.server.api.model.instance.SolverInstance) FireAndForgetResponseHandler(org.kie.server.client.jms.FireAndForgetResponseHandler) RequestReplyResponseHandler(org.kie.server.client.jms.RequestReplyResponseHandler) OptaplannerKieServerBaseIntegrationTest(org.kie.server.integrationtests.optaplanner.OptaplannerKieServerBaseIntegrationTest) Test(org.junit.Test)

Example 19 with SolverInstance

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

the class OptaplannerIntegrationTest method testGetSolverState.

@Test
public void testGetSolverState() {
    SolverInstance solverInstance = solverClient.createSolver(CONTAINER_1_ID, SOLVER_1_ID, SOLVER_1_CONFIG);
    assertNotNull(solverInstance);
    solverInstance = solverClient.getSolver(CONTAINER_1_ID, SOLVER_1_ID);
    assertNotNull(solverInstance);
    assertEquals(CONTAINER_1_ID, solverInstance.getContainerId());
    assertEquals(SOLVER_1_CONFIG, solverInstance.getSolverConfigFile());
    assertEquals(SOLVER_1_ID, solverInstance.getSolverId());
    assertEquals(SolverInstance.getSolverInstanceKey(CONTAINER_1_ID, SOLVER_1_ID), solverInstance.getSolverInstanceKey());
    assertEquals(SolverInstance.SolverStatus.NOT_SOLVING, solverInstance.getStatus());
    assertNotNull(solverInstance.getScoreWrapper());
    assertNull(solverInstance.getScoreWrapper().toScore());
}
Also used : SolverInstance(org.kie.server.api.model.instance.SolverInstance) Test(org.junit.Test)

Example 20 with SolverInstance

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

the class OptaplannerIntegrationTest method testGetBestSolution.

@Test(timeout = 60000)
public void testGetBestSolution() throws Exception {
    SolverInstance solverInstance = solverClient.createSolver(CONTAINER_1_ID, SOLVER_1_ID, SOLVER_1_CONFIG);
    // Start the solver
    Object planningProblem = loadPlanningProblem(10, 30);
    solverClient.solvePlanningProblem(CONTAINER_1_ID, SOLVER_1_ID, planningProblem);
    Object solution = null;
    HardSoftScore score = null;
    // The test timeout will interrupt this thread if it takes too long
    while (!Thread.currentThread().isInterrupted()) {
        solverInstance = solverClient.getSolverWithBestSolution(CONTAINER_1_ID, SOLVER_1_ID);
        assertNotNull(solverInstance);
        solution = solverInstance.getBestSolution();
        ScoreWrapper scoreWrapper = solverInstance.getScoreWrapper();
        assertNotNull(scoreWrapper);
        if (scoreWrapper.toScore() != null) {
            assertEquals(HardSoftScore.class, scoreWrapper.getScoreClass());
            score = (HardSoftScore) scoreWrapper.toScore();
        }
        // Wait until the solver finished initializing the solution
        if (solution != null && score != null && score.isSolutionInitialized()) {
            break;
        }
        Thread.sleep(1000);
    }
    assertNotNull(score);
    assertTrue(score.isSolutionInitialized());
    assertTrue(score.getHardScore() <= 0);
    // A soft score of 0 is impossible because we'll always need at least 1 computer
    assertTrue(score.getSoftScore() < 0);
    List<?> computerList = (List<?>) KieServerReflections.valueOf(solution, "computerList");
    assertEquals(10, computerList.size());
    List<?> processList = (List<?>) KieServerReflections.valueOf(solution, "processList");
    assertEquals(30, processList.size());
    for (Object process : processList) {
        Object computer = KieServerReflections.valueOf(process, "computer");
        assertNotNull(computer);
        // TODO: Change to identity comparation after @XmlID is implemented
        assertTrue(computerList.contains(computer));
    }
    solverClient.disposeSolver(CONTAINER_1_ID, SOLVER_1_ID);
}
Also used : SolverInstance(org.kie.server.api.model.instance.SolverInstance) ScoreWrapper(org.kie.server.api.model.instance.ScoreWrapper) ArrayList(java.util.ArrayList) List(java.util.List) HardSoftScore(org.optaplanner.core.api.score.buildin.hardsoft.HardSoftScore) Test(org.junit.Test)

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