Search in sources :

Example 21 with SolverInstance

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

the class OptaplannerIntegrationTest method testExecuteSolverHelper.

private void testExecuteSolverHelper(String solverID) throws Exception {
    SolverInstance solverInstance = solverClient.createSolver(CONTAINER_1_ID, solverID, SOLVER_1_CONFIG);
    assertNotNull(solverInstance);
    assertEquals(SolverInstance.SolverStatus.NOT_SOLVING, solverInstance.getStatus());
    // the following status starts the solver
    Object planningProblem = loadPlanningProblem(5, 15);
    solverClient.solvePlanningProblem(CONTAINER_1_ID, solverID, planningProblem);
    solverInstance = solverClient.getSolver(CONTAINER_1_ID, solverID);
    // solver should finish in 5 seconds, but we wait up to 15s before timing out
    final long SOLVER_STATUS_CHECK_PERIOD = 1000L;
    while (solverInstance.getStatus() == SolverInstance.SolverStatus.SOLVING) {
        solverInstance = solverClient.getSolver(CONTAINER_1_ID, solverID);
        assertNotNull(solverInstance);
        Thread.sleep(SOLVER_STATUS_CHECK_PERIOD);
    }
    assertEquals(SolverInstance.SolverStatus.NOT_SOLVING, solverInstance.getStatus());
    solverClient.disposeSolver(CONTAINER_1_ID, solverID);
}
Also used : SolverInstance(org.kie.server.api.model.instance.SolverInstance)

Example 22 with SolverInstance

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

the class OptaplannerIntegrationTest method testExecuteRealtimePlanningSolverSingleItemSubmit.

private void testExecuteRealtimePlanningSolverSingleItemSubmit(boolean daemon) throws Exception {
    SolverInstance solverInstance = solverClient.createSolver(CONTAINER_1_ID, SOLVER_1_ID, daemon ? SOLVER_1_REALTIME_DAEMON_CONFIG : SOLVER_1_REALTIME_CONFIG);
    assertNotNull(solverInstance);
    assertEquals(SolverInstance.SolverStatus.NOT_SOLVING, solverInstance.getStatus());
    final int computerCount = 5;
    final int numberOfComputersToAdd = 5;
    final Object planningProblem = loadPlanningProblem(computerCount, 15);
    solverClient.solvePlanningProblem(CONTAINER_1_ID, SOLVER_1_ID, planningProblem);
    SolverInstance solver = solverClient.getSolver(CONTAINER_1_ID, SOLVER_1_ID);
    assertEquals(SolverInstance.SolverStatus.SOLVING, solver.getStatus());
    Thread.sleep(3000);
    List computerList = null;
    for (int i = 0; i < numberOfComputersToAdd; i++) {
        ProblemFactChange<?> problemFactChange = loadAddProblemFactChange(computerCount + i);
        solverClient.addProblemFactChange(CONTAINER_1_ID, SOLVER_1_ID, problemFactChange);
        do {
            final Object bestSolution = verifySolverAndGetBestSolution();
            computerList = getCloudBalanceComputerList(bestSolution);
        } while (computerCount + i + 1 != computerList.size());
    }
    assertTrue(solverClient.isEveryProblemFactChangeProcessed(CONTAINER_1_ID, SOLVER_1_ID));
    Thread.sleep(3000);
    assertNotNull(computerList);
    for (int i = 0; i < numberOfComputersToAdd; i++) {
        ProblemFactChange<?> problemFactChange = loadDeleteProblemFactChange(computerList.get(i));
        solverClient.addProblemFactChange(CONTAINER_1_ID, SOLVER_1_ID, problemFactChange);
        do {
            final Object bestSolution = verifySolverAndGetBestSolution();
            computerList = getCloudBalanceComputerList(bestSolution);
        } while (computerCount + numberOfComputersToAdd - i - 1 != computerList.size());
    }
    assertTrue(solverClient.isEveryProblemFactChangeProcessed(CONTAINER_1_ID, SOLVER_1_ID));
    solverClient.disposeSolver(CONTAINER_1_ID, SOLVER_1_ID);
}
Also used : SolverInstance(org.kie.server.api.model.instance.SolverInstance) ArrayList(java.util.ArrayList) List(java.util.List)

Example 23 with SolverInstance

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

the class SolverServicesClientImpl method getSolver.

@Override
public SolverInstance getSolver(String containerId, String solverId) {
    checkMandatoryParameter("ContainerID", containerId);
    checkMandatoryParameter("SolverId", solverId);
    if (config.isRest()) {
        String uri = getURI(containerId, solverId);
        return makeHttpGetRequestAndCreateCustomResponse(uri, SolverInstance.class);
    } else {
        CommandScript script = new CommandScript(Collections.singletonList(new GetSolverCommand(containerId, solverId)));
        ServiceResponse<SolverInstance> response = (ServiceResponse<SolverInstance>) executeJmsCommand(script, GetSolverCommand.class.getName(), KieServerConstants.CAPABILITY_BRP, containerId).getResponses().get(0);
        throwExceptionOnFailure(response);
        if (shouldReturnWithNullResponse(response)) {
            return null;
        }
        return response.getResult();
    }
}
Also used : SolverInstance(org.kie.server.api.model.instance.SolverInstance) GetSolverCommand(org.kie.server.api.commands.optaplanner.GetSolverCommand) ServiceResponse(org.kie.server.api.model.ServiceResponse) CommandScript(org.kie.server.api.commands.CommandScript)

Example 24 with SolverInstance

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

the class SolverServicesClientImpl method getSolverWithBestSolution.

@Override
public SolverInstance getSolverWithBestSolution(String containerId, String solverId) {
    checkMandatoryParameter("ContainerID", containerId);
    checkMandatoryParameter("SolverId", solverId);
    if (config.isRest()) {
        String uri = getURI(containerId, solverId) + "/" + RestURI.SOLVER_BEST_SOLUTION;
        return makeHttpGetRequestAndCreateCustomResponse(uri, SolverInstance.class);
    } else {
        CommandScript script = new CommandScript(Collections.singletonList(new GetSolverWithBestSolutionCommand(containerId, solverId)));
        ServiceResponse<SolverInstance> response = (ServiceResponse<SolverInstance>) executeJmsCommand(script, GetSolverWithBestSolutionCommand.class.getName(), KieServerConstants.CAPABILITY_BRP, containerId).getResponses().get(0);
        throwExceptionOnFailure(response);
        if (shouldReturnWithNullResponse(response)) {
            return null;
        }
        return response.getResult();
    }
}
Also used : SolverInstance(org.kie.server.api.model.instance.SolverInstance) ServiceResponse(org.kie.server.api.model.ServiceResponse) CommandScript(org.kie.server.api.commands.CommandScript) GetSolverWithBestSolutionCommand(org.kie.server.api.commands.optaplanner.GetSolverWithBestSolutionCommand)

Example 25 with SolverInstance

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

the class SolverServicesClientImpl method createSolver.

@Override
public SolverInstance createSolver(String containerId, String solverId, String configFile) {
    checkMandatoryParameter("ContainerId", containerId);
    checkMandatoryParameter("SolverId", solverId);
    checkMandatoryParameter("ConfigFile", configFile);
    if (config.isRest()) {
        String uri = getURI(containerId, solverId);
        SolverInstance instance = new SolverInstance();
        instance.setSolverConfigFile(configFile);
        instance.setContainerId(containerId);
        instance.setSolverId(solverId);
        return makeHttpPutRequestAndCreateCustomResponse(uri, instance, SolverInstance.class, Collections.emptyMap());
    } else {
        CommandScript script = new CommandScript(Collections.singletonList(new CreateSolverCommand(containerId, solverId, configFile)));
        ServiceResponse<SolverInstance> response = (ServiceResponse<SolverInstance>) executeJmsCommand(script, CreateSolverCommand.class.getName(), KieServerConstants.CAPABILITY_BRP, containerId).getResponses().get(0);
        throwExceptionOnFailure(response);
        if (shouldReturnWithNullResponse(response)) {
            return null;
        }
        return response.getResult();
    }
}
Also used : SolverInstance(org.kie.server.api.model.instance.SolverInstance) ServiceResponse(org.kie.server.api.model.ServiceResponse) CommandScript(org.kie.server.api.commands.CommandScript) CreateSolverCommand(org.kie.server.api.commands.optaplanner.CreateSolverCommand)

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